Use fewer bits for key_bitlen

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman 2023-06-24 11:14:34 +01:00
parent 9282d4f13a
commit 6c6c84212e
2 changed files with 89 additions and 86 deletions

View file

@ -290,7 +290,7 @@ typedef struct mbedtls_cipher_info_t {
* default length for variable sized ciphers.
* Includes parity bits for ciphers like DES.
*/
uint16_t MBEDTLS_PRIVATE(key_bitlen);
uint8_t MBEDTLS_PRIVATE(key_bitlen) : 4;
/** IV or nonce size, in Bytes.
* For ciphers that accept variable IV sizes,
@ -309,6 +309,9 @@ typedef struct mbedtls_cipher_info_t {
} mbedtls_cipher_info_t;
/* This is used to more compactly represent the key_bitlen field above. It is for internal use only. */
#define MBEDTLS_KEY_BITLEN_SHIFT 6
/**
* Generic cipher context.
*/
@ -479,7 +482,7 @@ static inline size_t mbedtls_cipher_info_get_key_bitlen(
if (info == NULL) {
return 0;
} else {
return info->MBEDTLS_PRIVATE(key_bitlen);
return info->MBEDTLS_PRIVATE(key_bitlen) << MBEDTLS_KEY_BITLEN_SHIFT;
}
}
@ -788,7 +791,7 @@ static inline int mbedtls_cipher_get_key_bitlen(
return MBEDTLS_KEY_LENGTH_NONE;
}
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen);
return (int) ctx->MBEDTLS_PRIVATE(cipher_info)->MBEDTLS_PRIVATE(key_bitlen) << MBEDTLS_KEY_BITLEN_SHIFT;
}
/**