20
20
#include "cc3xx_internal_gcm.h"
21
21
#include "psa/crypto.h"
22
22
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
-
47
23
/*! AES GCM data in maximal size in bytes. */
48
24
#define CC3XX_GCM_DATA_IN_MAX_SIZE_BYTES 0xFFFF // (64KB - 1)
49
25
/*! AES GCM IV maximal size in bytes. */
69
45
/*! AES GCM Tag size: 16 bytes. */
70
46
#define CC3XX_GCM_TAG_SIZE_16_BYTES 16
71
47
72
- #ifdef CC3XX_CONFIG_SUPPORT_GCM
73
48
static psa_status_t gcm_setkey (
74
49
AesGcmContext_t * ctx ,
75
50
const uint8_t * key ,
@@ -548,7 +523,6 @@ static psa_status_t gcm_crypt_and_tag(
548
523
549
524
return status ;
550
525
}
551
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
552
526
553
527
/** \defgroup internal_gcm Internal GCM functions
554
528
*
@@ -566,7 +540,6 @@ psa_status_t cc3xx_gcm_encrypt(
566
540
{
567
541
psa_status_t status = PSA_ERROR_NOT_SUPPORTED ;
568
542
569
- #ifdef CC3XX_CONFIG_SUPPORT_GCM
570
543
psa_key_type_t key_type = psa_get_key_type (attributes );
571
544
psa_key_bits_t key_bits = psa_get_key_bits (attributes );
572
545
psa_algorithm_t key_alg = psa_get_key_algorithm (attributes );
@@ -587,7 +560,6 @@ psa_status_t cc3xx_gcm_encrypt(
587
560
CRYPTO_DIRECTION_ENCRYPT , attributes , key_buffer , key_buffer_size , alg ,
588
561
nonce , nonce_length , additional_data , additional_data_length , tag ,
589
562
tag_length , plaintext , plaintext_length , ciphertext , ciphertext_length );
590
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
591
563
592
564
return status ;
593
565
}
@@ -602,7 +574,6 @@ psa_status_t cc3xx_gcm_decrypt(
602
574
{
603
575
psa_status_t status = PSA_ERROR_NOT_SUPPORTED ;
604
576
605
- #ifdef CC3XX_CONFIG_SUPPORT_GCM
606
577
uint8_t local_tag_buffer [PSA_AEAD_TAG_MAX_SIZE ];
607
578
608
579
psa_key_type_t key_type = psa_get_key_type (attributes );
@@ -625,7 +596,7 @@ psa_status_t cc3xx_gcm_decrypt(
625
596
nonce , nonce_length , additional_data , additional_data_length ,
626
597
local_tag_buffer , tag_length , ciphertext , ciphertext_length_without_tag ,
627
598
plaintext , plaintext_length );
628
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
599
+
629
600
return status ;
630
601
}
631
602
@@ -654,23 +625,15 @@ psa_status_t cc3xx_gcm_setkey_enc(
654
625
const uint8_t * key ,
655
626
size_t key_bits )
656
627
{
657
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
658
- return PSA_ERROR_NOT_SUPPORTED ;
659
- #else
660
628
return gcm_setkey (ctx , key , key_bits , CRYPTO_DIRECTION_ENCRYPT );
661
- #endif
662
629
}
663
630
664
631
psa_status_t cc3xx_gcm_setkey_dec (
665
632
AesGcmContext_t * ctx ,
666
633
const uint8_t * key ,
667
634
size_t key_bits )
668
635
{
669
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
670
- return PSA_ERROR_NOT_SUPPORTED ;
671
- #else
672
636
return gcm_setkey (ctx , key , key_bits , CRYPTO_DIRECTION_DECRYPT );
673
- #endif
674
637
}
675
638
676
639
psa_status_t cc3xx_gcm_set_nonce (
@@ -679,9 +642,6 @@ psa_status_t cc3xx_gcm_set_nonce(
679
642
size_t nonce_size ,
680
643
size_t tag_size )
681
644
{
682
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
683
- return PSA_ERROR_NOT_SUPPORTED ;
684
- #else
685
645
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED ;
686
646
687
647
if (NULL == ctx || NULL == nonce ) {
@@ -719,17 +679,13 @@ psa_status_t cc3xx_gcm_set_nonce(
719
679
ctx -> tagSize = tag_size ;
720
680
721
681
return PSA_SUCCESS ;
722
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
723
682
}
724
683
725
684
psa_status_t cc3xx_gcm_set_lengths (
726
685
AesGcmContext_t * ctx ,
727
686
size_t aadSize ,
728
687
size_t dataSize )
729
688
{
730
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
731
- return PSA_ERROR_NOT_SUPPORTED ;
732
- #else
733
689
if (NULL == ctx ) {
734
690
CC_PAL_LOG_ERR ("ctx cannot be NULL\n" );
735
691
return PSA_ERROR_INVALID_ARGUMENT ;
@@ -744,17 +700,13 @@ psa_status_t cc3xx_gcm_set_lengths(
744
700
ctx -> dataSize = dataSize ;
745
701
746
702
return PSA_SUCCESS ;
747
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
748
703
}
749
704
750
705
psa_status_t cc3xx_gcm_update_ad (
751
706
AesGcmContext_t * ctx ,
752
707
const uint8_t * aad ,
753
708
size_t aad_size )
754
709
{
755
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
756
- return PSA_ERROR_NOT_SUPPORTED ;
757
- #else
758
710
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED ;
759
711
760
712
if (NULL == ctx || NULL == aad ) {
@@ -769,7 +721,6 @@ psa_status_t cc3xx_gcm_update_ad(
769
721
}
770
722
771
723
return PSA_SUCCESS ;
772
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
773
724
}
774
725
775
726
psa_status_t cc3xx_gcm_update (
@@ -778,9 +729,6 @@ psa_status_t cc3xx_gcm_update(
778
729
const uint8_t * input ,
779
730
uint8_t * output )
780
731
{
781
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
782
- return PSA_ERROR_NOT_SUPPORTED ;
783
- #else
784
732
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED ;
785
733
786
734
if (NULL == ctx || NULL == input || NULL == output ) {
@@ -801,7 +749,6 @@ psa_status_t cc3xx_gcm_update(
801
749
}
802
750
803
751
return PSA_SUCCESS ;
804
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
805
752
}
806
753
807
754
psa_status_t cc3xx_gcm_finish (
@@ -810,9 +757,6 @@ psa_status_t cc3xx_gcm_finish(
810
757
size_t tag_size ,
811
758
size_t * tag_len )
812
759
{
813
- #ifndef CC3XX_CONFIG_SUPPORT_GCM
814
- return PSA_ERROR_NOT_SUPPORTED ;
815
- #else
816
760
psa_status_t ret = PSA_ERROR_CORRUPTION_DETECTED ;
817
761
818
762
* tag_len = 0 ;
@@ -831,6 +775,5 @@ psa_status_t cc3xx_gcm_finish(
831
775
* tag_len = ctx -> tagSize ;
832
776
833
777
return PSA_SUCCESS ;
834
- #endif /* CC3XX_CONFIG_SUPPORT_GCM */
835
778
}
836
779
/** @} */ // end of internal_gcm
0 commit comments