Skip to content

Commit ed95296

Browse files
committed
CC3XX: Add config switches for Chacha20/Poly1305 and CCM
Add configuration switches for Chacha20/Poly1305 and CCM in the CC3XX driver. For the time being they're still hooked to the mbed TLS config file but will have to adapted to the config strategy when that is finalised (and likely to move to PSA_WANT_* mechanism). Move the GCM ones from the internal layer to the interface. Signed-off-by: Antonio de Angelis <[email protected]> Change-Id: Ib8620d8cbf8ddb3981bb975ffc93c7b62f8a5aa7
1 parent 2c66335 commit ed95296

File tree

4 files changed

+191
-114
lines changed

4 files changed

+191
-114
lines changed

lib/ext/cryptocell-312-runtime/codesafe/src/psa_driver_api/cc3xx.h

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@
7171
* By default this is kept enabled. At the moment affects only the RSA utils
7272
*/
7373
#define CC3XX_CONFIG_SUPPORT_RSA
74+
75+
/*!
76+
* Used to enable support for the Chacha20 algorithm in the interface layer.
77+
* By default it's kept enabled
78+
*/
79+
#define CC3XX_CONFIG_SUPPORT_CHACHA20
80+
81+
/*!
82+
* Used to enable support for the Poly1305 algorithm in the interface layer.
83+
* by default it's kept enabled. Note that there isn't a separate interface
84+
* to exercise the Poly1305 algorithm other than through the combination with
85+
* Chacha20 in an AEAD scheme.
86+
*/
87+
#define CC3XX_CONFIG_SUPPORT_CHACHA20_POLY1305
7488
#endif /* __DOXYGEN_ONLY__ */
7589

7690
#include "cc3xx_psa_cipher.h"

lib/ext/cryptocell-312-runtime/codesafe/src/psa_driver_api/src/cc3xx_internal_gcm.c

+1-58
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,6 @@
2020
#include "cc3xx_internal_gcm.h"
2121
#include "psa/crypto.h"
2222

23-
/* FixMe: Currently, some parts of the low-level driver are
24-
* are not built at all based on the mbed TLS configuration,
25-
* hence they can't be called from the interface code.
26-
* Eventually, the low level driver should be made
27-
* independent of the mbed TLS configuration and the
28-
* interface layer should be the only part that should
29-
* be configured through defines
30-
*/
31-
#if !defined(MBEDTLS_CONFIG_FILE)
32-
#include "mbedtls/config.h"
33-
#else
34-
#include MBEDTLS_CONFIG_FILE
35-
#endif
36-
37-
/* FixMe: Temporary way of bridging mbed TLS based configuration
38-
* with specific driver configuration defines
39-
*/
40-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
41-
#define CC3XX_CONFIG_SUPPORT_GCM
42-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
43-
#ifndef MBEDTLS_GCM_C
44-
#undef CC3XX_CONFIG_SUPPORT_GCM
45-
#endif
46-
4723
/*! AES GCM data in maximal size in bytes. */
4824
#define CC3XX_GCM_DATA_IN_MAX_SIZE_BYTES 0xFFFF // (64KB - 1)
4925
/*! AES GCM IV maximal size in bytes. */
@@ -69,7 +45,6 @@
6945
/*! AES GCM Tag size: 16 bytes. */
7046
#define CC3XX_GCM_TAG_SIZE_16_BYTES 16
7147

72-
#ifdef CC3XX_CONFIG_SUPPORT_GCM
7348
static psa_status_t gcm_setkey(
7449
AesGcmContext_t *ctx,
7550
const uint8_t *key,
@@ -548,7 +523,6 @@ static psa_status_t gcm_crypt_and_tag(
548523

549524
return status;
550525
}
551-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
552526

553527
/** \defgroup internal_gcm Internal GCM functions
554528
*
@@ -566,7 +540,6 @@ psa_status_t cc3xx_gcm_encrypt(
566540
{
567541
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
568542

569-
#ifdef CC3XX_CONFIG_SUPPORT_GCM
570543
psa_key_type_t key_type = psa_get_key_type(attributes);
571544
psa_key_bits_t key_bits = psa_get_key_bits(attributes);
572545
psa_algorithm_t key_alg = psa_get_key_algorithm(attributes);
@@ -587,7 +560,6 @@ psa_status_t cc3xx_gcm_encrypt(
587560
CRYPTO_DIRECTION_ENCRYPT, attributes, key_buffer, key_buffer_size, alg,
588561
nonce, nonce_length, additional_data, additional_data_length, tag,
589562
tag_length, plaintext, plaintext_length, ciphertext, ciphertext_length);
590-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
591563

592564
return status;
593565
}
@@ -602,7 +574,6 @@ psa_status_t cc3xx_gcm_decrypt(
602574
{
603575
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
604576

605-
#ifdef CC3XX_CONFIG_SUPPORT_GCM
606577
uint8_t local_tag_buffer[PSA_AEAD_TAG_MAX_SIZE];
607578

608579
psa_key_type_t key_type = psa_get_key_type(attributes);
@@ -625,7 +596,7 @@ psa_status_t cc3xx_gcm_decrypt(
625596
nonce, nonce_length, additional_data, additional_data_length,
626597
local_tag_buffer, tag_length, ciphertext, ciphertext_length_without_tag,
627598
plaintext, plaintext_length);
628-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
599+
629600
return status;
630601
}
631602

@@ -654,23 +625,15 @@ psa_status_t cc3xx_gcm_setkey_enc(
654625
const uint8_t *key,
655626
size_t key_bits)
656627
{
657-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
658-
return PSA_ERROR_NOT_SUPPORTED;
659-
#else
660628
return gcm_setkey(ctx, key, key_bits, CRYPTO_DIRECTION_ENCRYPT);
661-
#endif
662629
}
663630

664631
psa_status_t cc3xx_gcm_setkey_dec(
665632
AesGcmContext_t *ctx,
666633
const uint8_t *key,
667634
size_t key_bits)
668635
{
669-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
670-
return PSA_ERROR_NOT_SUPPORTED;
671-
#else
672636
return gcm_setkey(ctx, key, key_bits, CRYPTO_DIRECTION_DECRYPT);
673-
#endif
674637
}
675638

676639
psa_status_t cc3xx_gcm_set_nonce(
@@ -679,9 +642,6 @@ psa_status_t cc3xx_gcm_set_nonce(
679642
size_t nonce_size,
680643
size_t tag_size)
681644
{
682-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
683-
return PSA_ERROR_NOT_SUPPORTED;
684-
#else
685645
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED;
686646

687647
if (NULL == ctx || NULL == nonce) {
@@ -719,17 +679,13 @@ psa_status_t cc3xx_gcm_set_nonce(
719679
ctx->tagSize = tag_size;
720680

721681
return PSA_SUCCESS;
722-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
723682
}
724683

725684
psa_status_t cc3xx_gcm_set_lengths(
726685
AesGcmContext_t *ctx,
727686
size_t aadSize,
728687
size_t dataSize)
729688
{
730-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
731-
return PSA_ERROR_NOT_SUPPORTED;
732-
#else
733689
if (NULL == ctx) {
734690
CC_PAL_LOG_ERR("ctx cannot be NULL\n");
735691
return PSA_ERROR_INVALID_ARGUMENT;
@@ -744,17 +700,13 @@ psa_status_t cc3xx_gcm_set_lengths(
744700
ctx->dataSize = dataSize;
745701

746702
return PSA_SUCCESS;
747-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
748703
}
749704

750705
psa_status_t cc3xx_gcm_update_ad(
751706
AesGcmContext_t *ctx,
752707
const uint8_t *aad,
753708
size_t aad_size)
754709
{
755-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
756-
return PSA_ERROR_NOT_SUPPORTED;
757-
#else
758710
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED;
759711

760712
if (NULL == ctx || NULL == aad) {
@@ -769,7 +721,6 @@ psa_status_t cc3xx_gcm_update_ad(
769721
}
770722

771723
return PSA_SUCCESS;
772-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
773724
}
774725

775726
psa_status_t cc3xx_gcm_update(
@@ -778,9 +729,6 @@ psa_status_t cc3xx_gcm_update(
778729
const uint8_t *input,
779730
uint8_t *output)
780731
{
781-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
782-
return PSA_ERROR_NOT_SUPPORTED;
783-
#else
784732
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED;
785733

786734
if (NULL == ctx || NULL == input || NULL == output) {
@@ -801,7 +749,6 @@ psa_status_t cc3xx_gcm_update(
801749
}
802750

803751
return PSA_SUCCESS;
804-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
805752
}
806753

807754
psa_status_t cc3xx_gcm_finish(
@@ -810,9 +757,6 @@ psa_status_t cc3xx_gcm_finish(
810757
size_t tag_size,
811758
size_t *tag_len)
812759
{
813-
#ifndef CC3XX_CONFIG_SUPPORT_GCM
814-
return PSA_ERROR_NOT_SUPPORTED;
815-
#else
816760
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED;
817761

818762
*tag_len = 0;
@@ -831,6 +775,5 @@ psa_status_t cc3xx_gcm_finish(
831775
*tag_len = ctx->tagSize;
832776

833777
return PSA_SUCCESS;
834-
#endif /* CC3XX_CONFIG_SUPPORT_GCM */
835778
}
836779
/** @} */ // end of internal_gcm

0 commit comments

Comments
 (0)