[crypto] replace enum constants with constexpr (#6845)

This commit is contained in:
Abtin Keshavarzian
2021-07-28 10:26:29 -07:00
committed by Jonathan Hui
parent a5a6fba922
commit 2b2eac703d
5 changed files with 20 additions and 39 deletions
+4 -7
View File
@@ -59,18 +59,15 @@ namespace Crypto {
class AesCcm class AesCcm
{ {
public: public:
enum static constexpr uint8_t kMinTagLength = 4; ///< Minimum tag length (in bytes).
{ static constexpr uint8_t kMaxTagLength = AesEcb::kBlockSize; ///< Maximum tag length (in bytes).
kMinTagLength = 4, ///< Minimum tag length (in bytes). static constexpr uint8_t kNonceSize = 13; ///< Size of IEEE 802.15.4 Nonce (in bytes).
kMaxTagLength = AesEcb::kBlockSize, ///< Maximum tag length (in bytes).
kNonceSize = 13, ///< Size of IEEE 802.15.4 Nonce (in bytes).
};
/** /**
* This enumeration type represent the encryption vs decryption mode. * This enumeration type represent the encryption vs decryption mode.
* *
*/ */
enum Mode enum Mode : uint8_t
{ {
kEncrypt, // Encryption mode. kEncrypt, // Encryption mode.
kDecrypt, // Decryption mode. kDecrypt, // Decryption mode.
+1 -4
View File
@@ -55,10 +55,7 @@ namespace Crypto {
class AesEcb class AesEcb
{ {
public: public:
enum static constexpr uint8_t kBlockSize = 16; ///< AES-128 block size (bytes).
{
kBlockSize = 16, ///< AES-128 block size (bytes).
};
/** /**
* Constructor to initialize the mbedtls_aes_context. * Constructor to initialize the mbedtls_aes_context.
+13 -20
View File
@@ -64,15 +64,13 @@ namespace Ecdsa {
class P256 class P256
{ {
public: public:
enum : uint16_t static constexpr uint16_t kFieldBitLength = 256; ///< Prime field bit length used by the P-256 curve.
{
kFieldBitLength = 256, ///< Prime field bit length used by the P-256 curve.
};
enum : uint8_t /**
{ * Max bytes in binary representation of an MPI (multi-precision int).
kMpiSize = kFieldBitLength / 8, ///< Max bytes in binary representation of an MPI (multi-precision int). *
}; */
static constexpr uint8_t kMpiSize = kFieldBitLength / 8;
class PublicKey; class PublicKey;
class KeyPair; class KeyPair;
@@ -91,10 +89,7 @@ public:
friend class PublicKey; friend class PublicKey;
public: public:
enum : uint8_t static constexpr uint8_t kSize = 2 * kMpiSize; ///< Signature size in bytes (two times the curve MPI size).
{
kSize = 2 * kMpiSize, ///< Size of the signature in bytes (two times the curve MPI size).
};
/** /**
* This method returns the signature as a byte array. * This method returns the signature as a byte array.
@@ -128,10 +123,11 @@ public:
class KeyPair class KeyPair
{ {
public: public:
enum : uint8_t /**
{ * Max buffer size (in bytes) for representing the key-pair in DER format.
kMaxDerSize = 125, ///< Max buffer size (in bytes) for representing the key-pair in DER format. *
}; */
static constexpr uint8_t kMaxDerSize = 125;
/** /**
* This constructor initializes a `KeyPair` as empty (no key). * This constructor initializes a `KeyPair` as empty (no key).
@@ -237,10 +233,7 @@ public:
friend class KeyPair; friend class KeyPair;
public: public:
enum static constexpr uint8_t kSize = kMpiSize * 2; ///< Size of the public key in bytes.
{
kSize = kMpiSize * 2, ///< Size of the public key in bytes.
};
/** /**
* This method gets the pointer to the buffer containing the public key (as an uncompressed curve point). * This method gets the pointer to the buffer containing the public key (as an uncompressed curve point).
+1 -4
View File
@@ -50,10 +50,7 @@ namespace Pbkdf2 {
* *
*/ */
enum : uint16_t constexpr uint16_t kMaxSaltLength = 30; ///< Max SALT length: salt prefix (6) + extended panid (8) + network name (16)
{
kMaxSaltLength = 30, ///< Max SALT length: salt prefix (6) + extended panid (8) + network name (16)
};
/** /**
* This function performs PKCS#5 PBKDF2 using CMAC (AES-CMAC-PRF-128). * This function performs PKCS#5 PBKDF2 using CMAC (AES-CMAC-PRF-128).
+1 -4
View File
@@ -73,10 +73,7 @@ public:
class Hash : public otCryptoSha256Hash, public Clearable<Hash>, public Equatable<Hash> class Hash : public otCryptoSha256Hash, public Clearable<Hash>, public Equatable<Hash>
{ {
public: public:
enum : uint8_t static const uint8_t kSize = OT_CRYPTO_SHA256_HASH_SIZE; ///< SHA-256 hash size (bytes)
{
kSize = OT_CRYPTO_SHA256_HASH_SIZE, ///< SHA-256 hash size (bytes)
};
/** /**
* This method returns a pointer to a byte array containing the hash value. * This method returns a pointer to a byte array containing the hash value.