Tom Joseph | d08b523 | 2017-01-24 18:15:39 +0530 | [diff] [blame^] | 1 | #pragma once |
| 2 | |
| 3 | #include <openssl/sha.h> |
| 4 | #include <array> |
| 5 | #include <vector> |
| 6 | |
| 7 | namespace cipher |
| 8 | { |
| 9 | |
| 10 | namespace crypt |
| 11 | { |
| 12 | |
| 13 | using buffer = std::vector<uint8_t>; |
| 14 | using key = std::array<uint8_t, SHA_DIGEST_LENGTH>; |
| 15 | |
| 16 | /** |
| 17 | * @enum Confidentiality Algorithms |
| 18 | * |
| 19 | * The Confidentiality Algorithm Number specifies the encryption/decryption |
| 20 | * algorithm field that is used for encrypted payload data under the session. |
| 21 | * The ‘encrypted’ bit in the payload type field being set identifies packets |
| 22 | * with payloads that include data that is encrypted per this specification. |
| 23 | * When payload data is encrypted, there may be additional “Confidentiality |
| 24 | * Header” and/or “Confidentiality Trailer” fields that are included within the |
| 25 | * payload. The size and definition of those fields is specific to the |
| 26 | * particular confidentiality algorithm. |
| 27 | */ |
| 28 | enum class Algorithms : uint8_t |
| 29 | { |
| 30 | NONE, /**< No encryption (mandatory option) */ |
| 31 | AES_CBC_128, /**< AES-CBC-128 Algorithm (mandatory option) */ |
| 32 | xRC4_128, /**< xRC4-128 Algorithm (optional option) */ |
| 33 | xRC4_40, /**< xRC4-40 Algorithm (optional option) */ |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * @class Interface |
| 38 | * |
| 39 | * Interface is the base class for the Confidentiality Algorithms. |
| 40 | */ |
| 41 | class Interface |
| 42 | { |
| 43 | public: |
| 44 | /** |
| 45 | * @brief Constructor for Interface |
| 46 | * |
| 47 | * @param[in] - Session Integrity key to generate K2 |
| 48 | * @param[in] - Additional keying material to generate K2 |
| 49 | */ |
| 50 | explicit Interface(const buffer& sik, const key& addKey); |
| 51 | |
| 52 | Interface() = delete; |
| 53 | virtual ~Interface() = default; |
| 54 | Interface(const Interface&) = default; |
| 55 | Interface& operator=(const Interface&) = default; |
| 56 | Interface(Interface&&) = default; |
| 57 | Interface& operator=(Interface&&) = default; |
| 58 | |
| 59 | /** |
| 60 | * @brief Decrypt the incoming payload |
| 61 | * |
| 62 | * @param[in] packet - Incoming IPMI packet |
| 63 | * @param[in] sessHeaderLen - Length of the IPMI Session Header |
| 64 | * @param[in] payloadLen - Length of the encrypted IPMI payload |
| 65 | * |
| 66 | * @return decrypted payload if the operation is successful |
| 67 | */ |
| 68 | virtual buffer decryptPayload( |
| 69 | const buffer& packet, |
| 70 | const size_t sessHeaderLen, |
| 71 | const size_t payloadLen) const = 0; |
| 72 | |
| 73 | /** |
| 74 | * @brief Encrypt the outgoing payload |
| 75 | * |
| 76 | * @param[in] payload - plain payload for the outgoing IPMI packet |
| 77 | * |
| 78 | * @return encrypted payload if the operation is successful |
| 79 | * |
| 80 | */ |
| 81 | virtual buffer encryptPayload(buffer& payload) const = 0; |
| 82 | |
| 83 | protected: |
| 84 | |
| 85 | /** @brief K2 is the key used for encrypting data */ |
| 86 | key k2; |
| 87 | }; |
| 88 | |
| 89 | }// namespace crypt |
| 90 | |
| 91 | }// namespace cipher |
| 92 | |