[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
{
public:
enum
{
kMinTagLength = 4, ///< Minimum tag length (in bytes).
kMaxTagLength = AesEcb::kBlockSize, ///< Maximum tag length (in bytes).
kNonceSize = 13, ///< Size of IEEE 802.15.4 Nonce (in bytes).
};
static constexpr uint8_t kMinTagLength = 4; ///< Minimum tag length (in bytes).
static constexpr uint8_t kMaxTagLength = AesEcb::kBlockSize; ///< Maximum tag length (in bytes).
static constexpr uint8_t kNonceSize = 13; ///< Size of IEEE 802.15.4 Nonce (in bytes).
/**
* This enumeration type represent the encryption vs decryption mode.
*
*/
enum Mode
enum Mode : uint8_t
{
kEncrypt, // Encryption mode.
kDecrypt, // Decryption mode.
+1 -4
View File
@@ -55,10 +55,7 @@ namespace Crypto {
class AesEcb
{
public:
enum
{
kBlockSize = 16, ///< AES-128 block size (bytes).
};
static constexpr uint8_t kBlockSize = 16; ///< AES-128 block size (bytes).
/**
* Constructor to initialize the mbedtls_aes_context.
+13 -20
View File
@@ -64,15 +64,13 @@ namespace Ecdsa {
class P256
{
public:
enum : uint16_t
{
kFieldBitLength = 256, ///< Prime field bit length used by the P-256 curve.
};
static constexpr uint16_t kFieldBitLength = 256; ///< Prime field bit length used by the P-256 curve.
enum : uint8_t
{
kMpiSize = kFieldBitLength / 8, ///< Max bytes in binary representation of an MPI (multi-precision int).
};
/**
* Max bytes in binary representation of an MPI (multi-precision int).
*
*/
static constexpr uint8_t kMpiSize = kFieldBitLength / 8;
class PublicKey;
class KeyPair;
@@ -91,10 +89,7 @@ public:
friend class PublicKey;
public:
enum : uint8_t
{
kSize = 2 * kMpiSize, ///< Size of the signature in bytes (two times the curve MPI size).
};
static constexpr uint8_t kSize = 2 * kMpiSize; ///< Signature size in bytes (two times the curve MPI size).
/**
* This method returns the signature as a byte array.
@@ -128,10 +123,11 @@ public:
class KeyPair
{
public:
enum : uint8_t
{
kMaxDerSize = 125, ///< Max buffer size (in bytes) for representing the key-pair in DER format.
};
/**
* 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).
@@ -237,10 +233,7 @@ public:
friend class KeyPair;
public:
enum
{
kSize = kMpiSize * 2, ///< Size of the public key in bytes.
};
static constexpr uint8_t 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).
+1 -4
View File
@@ -50,10 +50,7 @@ namespace Pbkdf2 {
*
*/
enum : uint16_t
{
kMaxSaltLength = 30, ///< Max SALT length: salt prefix (6) + extended panid (8) + network name (16)
};
constexpr uint16_t 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).
+1 -4
View File
@@ -73,10 +73,7 @@ public:
class Hash : public otCryptoSha256Hash, public Clearable<Hash>, public Equatable<Hash>
{
public:
enum : uint8_t
{
kSize = OT_CRYPTO_SHA256_HASH_SIZE, ///< SHA-256 hash size (bytes)
};
static const uint8_t kSize = OT_CRYPTO_SHA256_HASH_SIZE; ///< SHA-256 hash size (bytes)
/**
* This method returns a pointer to a byte array containing the hash value.