Use separate MBEDTLS_MODE for the CCM*.

Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
Mateusz Starzyk 2021-10-27 10:42:31 +02:00
parent 61a8b2daf2
commit 4cb9739038
4 changed files with 122 additions and 4 deletions

View file

@ -140,9 +140,15 @@ typedef enum {
MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */ MBEDTLS_CIPHER_AES_128_CCM, /**< AES cipher with 128-bit CCM mode. */
MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */ MBEDTLS_CIPHER_AES_192_CCM, /**< AES cipher with 192-bit CCM mode. */
MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */ MBEDTLS_CIPHER_AES_256_CCM, /**< AES cipher with 256-bit CCM mode. */
MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, /**< AES cipher with 128-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, /**< AES cipher with 192-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, /**< AES cipher with 256-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_CAMELLIA_128_CCM, /**< Camellia cipher with 128-bit CCM mode. */ MBEDTLS_CIPHER_CAMELLIA_128_CCM, /**< Camellia cipher with 128-bit CCM mode. */
MBEDTLS_CIPHER_CAMELLIA_192_CCM, /**< Camellia cipher with 192-bit CCM mode. */ MBEDTLS_CIPHER_CAMELLIA_192_CCM, /**< Camellia cipher with 192-bit CCM mode. */
MBEDTLS_CIPHER_CAMELLIA_256_CCM, /**< Camellia cipher with 256-bit CCM mode. */ MBEDTLS_CIPHER_CAMELLIA_256_CCM, /**< Camellia cipher with 256-bit CCM mode. */
MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, /**< Camellia cipher with 128-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, /**< Camellia cipher with 192-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, /**< Camellia cipher with 256-bit CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_ARIA_128_ECB, /**< Aria cipher with 128-bit key and ECB mode. */ MBEDTLS_CIPHER_ARIA_128_ECB, /**< Aria cipher with 128-bit key and ECB mode. */
MBEDTLS_CIPHER_ARIA_192_ECB, /**< Aria cipher with 192-bit key and ECB mode. */ MBEDTLS_CIPHER_ARIA_192_ECB, /**< Aria cipher with 192-bit key and ECB mode. */
MBEDTLS_CIPHER_ARIA_256_ECB, /**< Aria cipher with 256-bit key and ECB mode. */ MBEDTLS_CIPHER_ARIA_256_ECB, /**< Aria cipher with 256-bit key and ECB mode. */
@ -161,6 +167,9 @@ typedef enum {
MBEDTLS_CIPHER_ARIA_128_CCM, /**< Aria cipher with 128-bit key and CCM mode. */ MBEDTLS_CIPHER_ARIA_128_CCM, /**< Aria cipher with 128-bit key and CCM mode. */
MBEDTLS_CIPHER_ARIA_192_CCM, /**< Aria cipher with 192-bit key and CCM mode. */ MBEDTLS_CIPHER_ARIA_192_CCM, /**< Aria cipher with 192-bit key and CCM mode. */
MBEDTLS_CIPHER_ARIA_256_CCM, /**< Aria cipher with 256-bit key and CCM mode. */ MBEDTLS_CIPHER_ARIA_256_CCM, /**< Aria cipher with 256-bit key and CCM mode. */
MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, /**< Aria cipher with 128-bit key and CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, /**< Aria cipher with 192-bit key and CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, /**< Aria cipher with 256-bit key and CCM_STAR_NO_TAG mode. */
MBEDTLS_CIPHER_AES_128_OFB, /**< AES 128-bit cipher in OFB mode. */ MBEDTLS_CIPHER_AES_128_OFB, /**< AES 128-bit cipher in OFB mode. */
MBEDTLS_CIPHER_AES_192_OFB, /**< AES 192-bit cipher in OFB mode. */ MBEDTLS_CIPHER_AES_192_OFB, /**< AES 192-bit cipher in OFB mode. */
MBEDTLS_CIPHER_AES_256_OFB, /**< AES 256-bit cipher in OFB mode. */ MBEDTLS_CIPHER_AES_256_OFB, /**< AES 256-bit cipher in OFB mode. */
@ -187,6 +196,7 @@ typedef enum {
MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */ MBEDTLS_MODE_GCM, /**< The GCM cipher mode. */
MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */ MBEDTLS_MODE_STREAM, /**< The stream cipher mode. */
MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */ MBEDTLS_MODE_CCM, /**< The CCM cipher mode. */
MBEDTLS_MODE_CCM_STAR_NO_TAG, /**< The CCM*-no-tag cipher mode. */
MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */ MBEDTLS_MODE_XTS, /**< The XTS cipher mode. */
MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */ MBEDTLS_MODE_CHACHAPOLY, /**< The ChaCha-Poly cipher mode. */
MBEDTLS_MODE_KW, /**< The SP800-38F KW mode */ MBEDTLS_MODE_KW, /**< The SP800-38F KW mode */

View file

@ -425,7 +425,7 @@ int mbedtls_cipher_set_iv( mbedtls_cipher_context_t *ctx,
#endif #endif
#if defined(MBEDTLS_CCM_C) #if defined(MBEDTLS_CCM_C)
if( MBEDTLS_MODE_CCM == ctx->cipher_info->mode ) if( MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode )
{ {
int set_lengths_result; int set_lengths_result;
int ccm_star_mode; int ccm_star_mode;
@ -586,7 +586,7 @@ int mbedtls_cipher_update( mbedtls_cipher_context_t *ctx, const unsigned char *i
#endif #endif
#if defined(MBEDTLS_CCM_C) #if defined(MBEDTLS_CCM_C)
if( ctx->cipher_info->mode == MBEDTLS_MODE_CCM ) if( ctx->cipher_info->mode == MBEDTLS_MODE_CCM_STAR_NO_TAG )
{ {
return( mbedtls_ccm_update( (mbedtls_ccm_context *) ctx->cipher_ctx, return( mbedtls_ccm_update( (mbedtls_ccm_context *) ctx->cipher_ctx,
input, ilen, input, ilen,
@ -981,7 +981,7 @@ int mbedtls_cipher_finish( mbedtls_cipher_context_t *ctx,
MBEDTLS_MODE_OFB == ctx->cipher_info->mode || MBEDTLS_MODE_OFB == ctx->cipher_info->mode ||
MBEDTLS_MODE_CTR == ctx->cipher_info->mode || MBEDTLS_MODE_CTR == ctx->cipher_info->mode ||
MBEDTLS_MODE_GCM == ctx->cipher_info->mode || MBEDTLS_MODE_GCM == ctx->cipher_info->mode ||
MBEDTLS_MODE_CCM == ctx->cipher_info->mode || MBEDTLS_MODE_CCM_STAR_NO_TAG == ctx->cipher_info->mode ||
MBEDTLS_MODE_XTS == ctx->cipher_info->mode || MBEDTLS_MODE_XTS == ctx->cipher_info->mode ||
MBEDTLS_MODE_STREAM == ctx->cipher_info->mode ) MBEDTLS_MODE_STREAM == ctx->cipher_info->mode )
{ {

View file

@ -639,6 +639,39 @@ static const mbedtls_cipher_info_t aes_256_ccm_info = {
16, 16,
&ccm_aes_info &ccm_aes_info
}; };
static const mbedtls_cipher_info_t aes_128_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
128,
"AES-128-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aes_info
};
static const mbedtls_cipher_info_t aes_192_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
192,
"AES-192-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aes_info
};
static const mbedtls_cipher_info_t aes_256_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
256,
"AES-256-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aes_info
};
#endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_CCM_C */
#endif /* MBEDTLS_AES_C */ #endif /* MBEDTLS_AES_C */
@ -1014,6 +1047,39 @@ static const mbedtls_cipher_info_t camellia_256_ccm_info = {
16, 16,
&ccm_camellia_info &ccm_camellia_info
}; };
static const mbedtls_cipher_info_t camellia_128_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
128,
"CAMELLIA-128-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_camellia_info
};
static const mbedtls_cipher_info_t camellia_192_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
192,
"CAMELLIA-192-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_camellia_info
};
static const mbedtls_cipher_info_t camellia_256_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
256,
"CAMELLIA-256-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_camellia_info
};
#endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_CCM_C */
#endif /* MBEDTLS_CAMELLIA_C */ #endif /* MBEDTLS_CAMELLIA_C */
@ -1390,6 +1456,39 @@ static const mbedtls_cipher_info_t aria_256_ccm_info = {
16, 16,
&ccm_aria_info &ccm_aria_info
}; };
static const mbedtls_cipher_info_t aria_128_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
128,
"ARIA-128-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aria_info
};
static const mbedtls_cipher_info_t aria_192_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
192,
"ARIA-192-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aria_info
};
static const mbedtls_cipher_info_t aria_256_ccm_star_no_tag_info = {
MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG,
MBEDTLS_MODE_CCM_STAR_NO_TAG,
256,
"ARIA-256-CCM*-NO-TAG",
12,
MBEDTLS_CIPHER_VARIABLE_IV_LEN,
16,
&ccm_aria_info
};
#endif /* MBEDTLS_CCM_C */ #endif /* MBEDTLS_CCM_C */
#endif /* MBEDTLS_ARIA_C */ #endif /* MBEDTLS_ARIA_C */
@ -2055,6 +2154,9 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
{ MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info }, { MBEDTLS_CIPHER_AES_128_CCM, &aes_128_ccm_info },
{ MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info }, { MBEDTLS_CIPHER_AES_192_CCM, &aes_192_ccm_info },
{ MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info }, { MBEDTLS_CIPHER_AES_256_CCM, &aes_256_ccm_info },
{ MBEDTLS_CIPHER_AES_128_CCM_STAR_NO_TAG, &aes_128_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_AES_192_CCM_STAR_NO_TAG, &aes_192_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_AES_256_CCM_STAR_NO_TAG, &aes_256_ccm_star_no_tag_info },
#endif #endif
#endif /* MBEDTLS_AES_C */ #endif /* MBEDTLS_AES_C */
@ -2086,6 +2188,9 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
{ MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info }, { MBEDTLS_CIPHER_CAMELLIA_128_CCM, &camellia_128_ccm_info },
{ MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info }, { MBEDTLS_CIPHER_CAMELLIA_192_CCM, &camellia_192_ccm_info },
{ MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info }, { MBEDTLS_CIPHER_CAMELLIA_256_CCM, &camellia_256_ccm_info },
{ MBEDTLS_CIPHER_CAMELLIA_128_CCM_STAR_NO_TAG, &camellia_128_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_CAMELLIA_192_CCM_STAR_NO_TAG, &camellia_192_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_CAMELLIA_256_CCM_STAR_NO_TAG, &camellia_256_ccm_star_no_tag_info },
#endif #endif
#endif /* MBEDTLS_CAMELLIA_C */ #endif /* MBEDTLS_CAMELLIA_C */
@ -2117,6 +2222,9 @@ const mbedtls_cipher_definition_t mbedtls_cipher_definitions[] =
{ MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info }, { MBEDTLS_CIPHER_ARIA_128_CCM, &aria_128_ccm_info },
{ MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info }, { MBEDTLS_CIPHER_ARIA_192_CCM, &aria_192_ccm_info },
{ MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info }, { MBEDTLS_CIPHER_ARIA_256_CCM, &aria_256_ccm_info },
{ MBEDTLS_CIPHER_ARIA_128_CCM_STAR_NO_TAG, &aria_128_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_ARIA_192_CCM_STAR_NO_TAG, &aria_192_ccm_star_no_tag_info },
{ MBEDTLS_CIPHER_ARIA_256_CCM_STAR_NO_TAG, &aria_256_ccm_star_no_tag_info },
#endif #endif
#endif /* MBEDTLS_ARIA_C */ #endif /* MBEDTLS_ARIA_C */

View file

@ -93,7 +93,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_psa(
mode = MBEDTLS_MODE_CBC; mode = MBEDTLS_MODE_CBC;
break; break;
case PSA_ALG_CCM_STAR_NO_TAG: case PSA_ALG_CCM_STAR_NO_TAG:
mode = MBEDTLS_MODE_CCM; mode = MBEDTLS_MODE_CCM_STAR_NO_TAG;
break; break;
case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, 0 ): case PSA_ALG_AEAD_WITH_SHORTENED_TAG( PSA_ALG_CCM, 0 ):
mode = MBEDTLS_MODE_CCM; mode = MBEDTLS_MODE_CCM;