Skip to content

Commit b0b189f

Browse files
Add missing compilation guards for GCM and CCM
Add missing compilation guards that broke the build if either GCM or CCM was not defined. Add missing guards on test cases that require GCM or CBC. The build and tests now pass for any subset of {MBEDTLS_CCM_C, MBEDTLS_GCM_C}. There are still unused variables warnings if neither is defined.
1 parent 0e9ff85 commit b0b189f

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

library/psa_crypto.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,7 +3146,7 @@ static void psa_aead_abort( aead_operation_t *operation )
31463146
mbedtls_ccm_free( &operation->ctx.ccm );
31473147
break;
31483148
#endif /* MBEDTLS_CCM_C */
3149-
#if defined(MBEDTLS_CCM_C)
3149+
#if defined(MBEDTLS_GCM_C)
31503150
case PSA_ALG_GCM:
31513151
mbedtls_gcm_free( &operation->ctx.gcm );
31523152
break;
@@ -3259,6 +3259,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
32593259
}
32603260
tag = ciphertext + plaintext_length;
32613261

3262+
#if defined(MBEDTLS_GCM_C)
32623263
if( operation.core_alg == PSA_ALG_GCM )
32633264
{
32643265
status = mbedtls_to_psa_error(
@@ -3270,7 +3271,10 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
32703271
plaintext, ciphertext,
32713272
operation.tag_length, tag ) );
32723273
}
3273-
else if( operation.core_alg == PSA_ALG_CCM )
3274+
else
3275+
#endif /* MBEDTLS_GCM_C */
3276+
#if defined(MBEDTLS_CCM_C)
3277+
if( operation.core_alg == PSA_ALG_CCM )
32743278
{
32753279
status = mbedtls_to_psa_error(
32763280
mbedtls_ccm_encrypt_and_tag( &operation.ctx.ccm,
@@ -3282,6 +3286,7 @@ psa_status_t psa_aead_encrypt( psa_key_slot_t key,
32823286
tag, operation.tag_length ) );
32833287
}
32843288
else
3289+
#endif /* MBEDTLS_CCM_C */
32853290
{
32863291
return( PSA_ERROR_NOT_SUPPORTED );
32873292
}
@@ -3339,6 +3344,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
33393344
if( status != PSA_SUCCESS )
33403345
return( status );
33413346

3347+
#if defined(MBEDTLS_GCM_C)
33423348
if( operation.core_alg == PSA_ALG_GCM )
33433349
{
33443350
status = psa_aead_unpadded_locate_tag( operation.tag_length,
@@ -3356,7 +3362,10 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
33563362
tag, operation.tag_length,
33573363
ciphertext, plaintext ) );
33583364
}
3359-
else if( operation.core_alg == PSA_ALG_CCM )
3365+
else
3366+
#endif /* MBEDTLS_GCM_C */
3367+
#if defined(MBEDTLS_CCM_C)
3368+
if( operation.core_alg == PSA_ALG_CCM )
33603369
{
33613370
status = psa_aead_unpadded_locate_tag( operation.tag_length,
33623371
ciphertext, ciphertext_length,
@@ -3374,6 +3383,7 @@ psa_status_t psa_aead_decrypt( psa_key_slot_t key,
33743383
tag, operation.tag_length ) );
33753384
}
33763385
else
3386+
#endif /* MBEDTLS_CCM_C */
33773387
{
33783388
return( PSA_ERROR_NOT_SUPPORTED );
33793389
}

tests/suites/test_suite_psa_crypto.data

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,19 +1770,19 @@ depends_on:MBEDTLS_AES_C:MBEDTLS_CIPHER_MODE_CTR
17701770
generate_key:PSA_KEY_TYPE_AES:128:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CTR:PSA_SUCCESS
17711771

17721772
PSA generate key: AES, 128 bits, GCM
1773-
depends_on:MBEDTLS_AES_C
1773+
depends_on:MBEDTLS_AES_C:MBEDTLS_GCM_C
17741774
generate_key:PSA_KEY_TYPE_AES:128:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_GCM:PSA_SUCCESS
17751775

17761776
PSA generate key: DES, 64 bits, CBC-nopad
1777-
depends_on:MBEDTLS_DES_C
1777+
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
17781778
generate_key:PSA_KEY_TYPE_DES:64:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CBC_NO_PADDING:PSA_SUCCESS
17791779

17801780
PSA generate key: DES, 128 bits, CBC-nopad
1781-
depends_on:MBEDTLS_DES_C
1781+
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
17821782
generate_key:PSA_KEY_TYPE_DES:128:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CBC_NO_PADDING:PSA_SUCCESS
17831783

17841784
PSA generate key: DES, 192 bits, CBC-nopad
1785-
depends_on:MBEDTLS_DES_C
1785+
depends_on:MBEDTLS_DES_C:MBEDTLS_CIPHER_MODE_CBC
17861786
generate_key:PSA_KEY_TYPE_DES:192:PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT:PSA_ALG_CBC_NO_PADDING:PSA_SUCCESS
17871787

17881788
PSA generate key: invalid key size: AES, 64 bits

0 commit comments

Comments
 (0)