Skip to content

Commit 7b53960

Browse files
committed
Addressed copilot's comments
1 parent b2f812e commit 7b53960

7 files changed

Lines changed: 52 additions & 36 deletions

File tree

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,9 @@ AC_ARG_WITH([cryptoauthlib],
30133013
[with_cryptoauthlib=no])
30143014

30153015
AS_IF([test "x$with_cryptoauthlib" != "xno"], [
3016+
AS_IF([test "x$ENABLED_ATMEL" = "xno"], [
3017+
AC_MSG_ERROR([--with-cryptoauthlib requires --enable-microchip=<devices>.])
3018+
])
30163019
AC_MSG_CHECKING([for CryptoAuthLib])
30173020
30183021
libdir=""
@@ -3029,7 +3032,6 @@ AS_IF([test "x$with_cryptoauthlib" != "xno"], [
30293032
PKG_CHECK_MODULES([CRYPTOAUTHLIB], [cryptoauthlib], [
30303033
CPPFLAGS="$CRYPTOAUTHLIB_CFLAGS $CPPFLAGS"
30313034
CFLAGS="$CRYPTOAUTHLIB_CFLAGS $CFLAGS"
3032-
LDFLAGS="$CRYPTOAUTHLIB_LIBS $LDFLAGS"
30333035
LIBS="$CRYPTOAUTHLIB_LIBS $LIBS"
30343036
cryptoauthlib_found="pkg-config"
30353037
], [:])

wolfcrypt/src/ecc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ ECC Curve Sizes:
287287
!defined(WOLFSSL_MICROCHIP_TA100) && \
288288
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_SILABS_SE_ACCEL) && \
289289
!defined(WOLFSSL_KCAPI_ECC) && !defined(WOLFSSL_SE050) && \
290+
!defined(WOLFSSL_STM32_PKA) && !defined(WOLFSSL_PSOC6_CRYPTO) && \
290291
!defined(WOLFSSL_XILINX_CRYPT_VERSAL)
291292
#undef HAVE_ECC_VERIFY_HELPER
292293
#define HAVE_ECC_VERIFY_HELPER
@@ -9341,9 +9342,10 @@ int wc_ecc_verify_hash_ex(mp_int *r, mp_int *s, const byte* hash,
93419342
#else
93429343
int err;
93439344
word32 keySz = 0;
9344-
#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
9345-
defined(WOLFSSL_MICROCHIP_TA100)
9345+
#if defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A)
93469346
byte sigRS[ATECC_KEY_SIZE*2];
9347+
#elif defined(WOLFSSL_MICROCHIP_TA100)
9348+
byte sigRS[ECC_MAX_CRYPTO_HW_SIZE*2];
93479349
#elif defined(WOLFSSL_CRYPTOCELL)
93489350
byte sigRS[ECC_MAX_CRYPTO_HW_SIZE*2];
93499351
CRYS_ECDSA_VerifyUserContext_t sigCtxTemp;

wolfcrypt/src/port/atmel/README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ Supported Features:
119119
RSA 2048 keygen/sign/verify
120120
ECC-P256 keygen/sign/verify/shared secret
121121

122-
WOLFSSL_MICROCHIP_AESGCM can be used to enable AES-GCM but
123-
AESGCM support is not yet available for TA100 in both
124-
cryptauthlib-v3.3.3_397871.zip and cryptauthlib-v3.6.0_443271.zip.
122+
WOLFSSL_MICROCHIP_AESGCM can be used to enable AES-GCM for TA100 when
123+
building against CryptoAuthLib v3.6.0_443271 or later. AES-GCM is not
124+
supported for TA100 with cryptauthlib-v3.3.3_397871.zip.
125+
126+
Current TA100 AES-GCM limitations:
127+
- IV size must be 12 bytes.
128+
- Authentication tag size must be 16 bytes for hardware decrypt, with
129+
shorter tags only supported for zero-length decrypt validation.
130+
- The combined AAD + payload size per hardware operation is limited to 996
131+
bytes.
125132

126133

127134
```

wolfcrypt/src/port/atmel/atmel.c

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int ateccx08a_cfg_initialized = 0;
147147
.devtype = MICROCHIP_DEV_TYPE,
148148
.atcai2c = {
149149
#ifdef ATCA_ENABLE_DEPRECATED
150-
.slave_addressus = 1,
150+
.slave_address = 1,
151151
#else
152152
.address = ATECC_I2C_ADDR,
153153
#endif
@@ -451,13 +451,13 @@ int atmel_ecc_alloc(int slotType)
451451
break;
452452
#endif
453453
case ATMEL_SLOT_ECDHE_ALICE:
454-
/* not reserved in mSlotList, so return */
454+
/* reserve the fixed slot through the common allocation path */
455455
slotId = ATECC_SLOT_ECDHE_PRIV_ALICE;
456-
goto exit;
456+
break;
457457
case ATMEL_SLOT_ECDHE_BOB:
458-
/* not reserved in mSlotList, so return */
458+
/* reserve the fixed slot through the common allocation path */
459459
slotId = ATECC_SLOT_ECDHE_PRIV_BOB;
460-
goto exit;
460+
break;
461461
case ATMEL_SLOT_ANY:
462462
for (i=0; i < ATECC_MAX_SLOT; i++) {
463463
/* Find free slotId */
@@ -475,8 +475,7 @@ int atmel_ecc_alloc(int slotType)
475475
}
476476

477477
/* is slot available */
478-
if (mSlotList[slotId] != ATECC_INVALID_SLOT &&
479-
mSlotList[slotId] != slotId ) {
478+
if (mSlotList[slotId] != ATECC_INVALID_SLOT) {
480479
slotId = ATECC_INVALID_SLOT;
481480
}
482481
else {
@@ -884,13 +883,20 @@ int wc_Microchip_rsa_create_key(struct RsaKey* key, int size, long e)
884883
{
885884
ATCA_STATUS ret;
886885
ta_element_attributes_t rKeyA, uKeyA;
887-
size_t uKey_len = TA_KEY_TYPE_RSA2048_SIZE;
886+
size_t uKey_len = WOLFSSL_TA_KEY_TYPE_RSA_SIZE;
888887

889-
(void)size;
890-
(void)e;
888+
if (key == NULL) {
889+
return BAD_FUNC_ARG;
890+
}
891+
if (size != (int)(WOLFSSL_TA_KEY_TYPE_RSA_SIZE * 8U)) {
892+
return BAD_FUNC_ARG;
893+
}
894+
if (e != 0 && e != WC_RSA_EXPONENT) {
895+
return BAD_FUNC_ARG;
896+
}
891897

892898
/* Private key for signing AND decryption */
893-
ret = talib_handle_init_private_key(&rKeyA, TA_KEY_TYPE_RSA2048,
899+
ret = talib_handle_init_private_key(&rKeyA, WOLFSSL_TA_KEY_TYPE_RSA,
894900
TA_ALG_MODE_RSA_SSA_PSS, TA_PROP_SIGN_INT_EXT_DIGEST,
895901
TA_PROP_KEY_AGREEMENT_OUT_BUFF);
896902
if (ret != ATCA_SUCCESS)
@@ -903,7 +909,7 @@ int wc_Microchip_rsa_create_key(struct RsaKey* key, int size, long e)
903909
return WC_HW_E;
904910

905911
/* Public key - use 0, 0 for encryption support! */
906-
ret = talib_handle_init_public_key(&uKeyA, TA_KEY_TYPE_RSA2048,
912+
ret = talib_handle_init_public_key(&uKeyA, WOLFSSL_TA_KEY_TYPE_RSA,
907913
TA_ALG_MODE_RSA_SSA_PSS, 0, 0);
908914
if (ret != ATCA_SUCCESS)
909915
return WC_HW_E;
@@ -942,7 +948,7 @@ int wc_Microchip_rsa_encrypt(const byte* in, word32 inLen, byte* out,
942948
printf("outLen: %u\n", outLen);
943949
printf("out: %p\n", out);
944950
#endif
945-
/* Use the 2048-specific function */
951+
/* The current wolfSSL TA100 backend uses the RSA-2048 RSAEnc path. */
946952
ret = talib_rsaenc_encrypt2048(atcab_get_device(), key->uKeyH,
947953
(uint16_t)inLen, in,
948954
(uint16_t)outLen, out);
@@ -955,7 +961,7 @@ int wc_Microchip_rsa_decrypt(const byte* in, word32 inLen, byte* out,
955961
{
956962
int ret;
957963

958-
964+
/* The current wolfSSL TA100 backend uses the RSA-2048 RSAEnc path. */
959965
ret = talib_rsaenc_decrypt2048(atcab_get_device(), key->rKeyH,
960966
(uint16_t)inLen, in,
961967
(uint16_t)outLen, out);
@@ -1310,7 +1316,7 @@ int atcatls_create_key_cb(WOLFSSL* ssl, ecc_key* key, unsigned int keySz,
13101316
return WC_HW_WAIT_E;
13111317

13121318
/* generate new ephemeral key on device */
1313-
ret = atmel_ecc_create_key(MAP_TO_HANDLE(slotId), ecc_curve, peerKey);
1319+
ret = atmel_ecc_create_key(slotId, ecc_curve, peerKey);
13141320

13151321
/* load generated ECC508A public key into key, used by wolfSSL */
13161322
if (ret == 0) {
@@ -1387,8 +1393,7 @@ int atcatls_create_pms_cb(WOLFSSL* ssl, ecc_key* otherKey,
13871393
tmpKey.slot = slotId;
13881394

13891395
/* generate new ephemeral key on device */
1390-
ret = atmel_ecc_create_key(MAP_TO_HANDLE(slotId), otherKey->dp->id,
1391-
peerKey);
1396+
ret = atmel_ecc_create_key(slotId, otherKey->dp->id, peerKey);
13921397
if (ret != ATCA_SUCCESS) {
13931398
atmel_ecc_free(slotId);
13941399
goto exit;
@@ -1663,6 +1668,7 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
16631668
#endif
16641669

16651670
int ret = 0;
1671+
ATCA_STATUS status;
16661672
size_t signerCertSize = ATCATLS_SIGNER_CERT_MAX_SIZE;
16671673
size_t deviceCertSize = ATCATLS_DEVICE_CERT_MAX_SIZE;
16681674
uint8_t certBuffer[ATCATLS_CERT_BUFF_MAX_SIZE];
@@ -1672,7 +1678,6 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
16721678
#endif
16731679

16741680
#ifdef WOLFSSL_ATECC_TNGTLS
1675-
ATCA_STATUS status;
16761681
ret = tng_atcacert_max_signer_cert_size(&signerCertSize);
16771682
if (ret != ATCACERT_E_SUCCESS) {
16781683
#ifdef WOLFSSL_ATECC_DEBUG
@@ -1782,7 +1787,6 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
17821787
return ret;
17831788
}
17841789
#endif /* ATCA_TFLEX_SUPPORT */
1785-
#endif /* ATCA_TFLEX_SUPPORT */
17861790

17871791
int atcatls_set_callbacks(WOLFSSL_CTX* ctx)
17881792
{
@@ -1921,11 +1925,12 @@ int wc_Microchip_aes_set_key(Aes* aes, const byte* key, word32 keylen,
19211925
status = talib_aes_gcm_keyload(atcab_get_device(), aes->key_id, 0);
19221926
CHECK_STATUS(status);
19231927

1924-
/* Test if data zone is locked */
1928+
/* Provisioning must lock setup explicitly; do not lock it as a side
1929+
* effect of loading an AES key. */
19251930
status = talib_is_setup_locked(atcab_get_device(), &is_locked);
1931+
CHECK_STATUS(status);
19261932
if (!is_locked) {
1927-
status = talib_lock_setup(atcab_get_device());
1928-
CHECK_STATUS(status);
1933+
return WC_HW_E;
19291934
}
19301935

19311936
return atmel_ecc_translate_err(status);

wolfcrypt/src/signature.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,11 @@ int wc_SignatureGetSize(enum wc_SignatureType sig_type,
128128
#if defined(WOLFSSL_MICROCHIP_TA100)
129129
if (sig_len <= 0) {
130130
const RsaKey* r = (const RsaKey*)key;
131-
/* TA100 handles imply a 2048-bit RSA key. */
131+
/* TA100 stores hardware-backed RSA public keys outside
132+
* the software mp_int fields, so use the backend's fixed
133+
* public-key buffer size when handles are present. */
132134
if (r->rKeyH != 0 || r->uKeyH != 0) {
133-
sig_len = 256;
135+
sig_len = WOLFSSL_TA_KEY_TYPE_RSA_SIZE;
134136
}
135137
}
136138
#endif

wolfssl/wolfcrypt/port/atmel/atmel.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,13 @@ WOLFSSL_LOCAL int wc_Microchip_rsa_encrypt(const byte* in, word32 inLen,
182182
WOLFSSL_LOCAL int wc_Microchip_rsa_decrypt(const byte* in, word32 inLen,
183183
byte* out, word32 outLen, RsaKey* key);
184184

185+
/* CryptoAuthLib defines larger TA100 RSA key types too, but the current
186+
* wolfSSL TA100 backend only wires up the RSAEnc path for RSA-2048. */
185187
#ifndef WOLFSSL_SP_NO_2048
186188
#define WOLFSSL_TA_KEY_TYPE_RSA TA_KEY_TYPE_RSA2048
187189
#define WOLFSSL_TA_KEY_TYPE_RSA_SIZE TA_KEY_TYPE_RSA2048_SIZE
188-
#elif !defined(WOLFSSL_SP_NO_3072)
189-
#define WOLFSSL_TA_KEY_TYPE_RSA TA_KEY_TYPE_RSA3072
190-
#define WOLFSSL_TA_KEY_TYPE_RSA_SIZE TA_KEY_TYPE_RSA3072_SIZE
191190
#else
192-
#error Microchip requires enabling 2048 or 3072 RSA.
191+
#error Current wolfSSL TA100 RSA backend requires 2048-bit RSA support.
193192
#endif
194193

195194
#endif /* NO_RSA */

wolfssl/wolfcrypt/rsa.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ struct RsaKey {
226226
#if defined(WOLFSSL_MICROCHIP_TA100)
227227
uint16_t rKeyH; /* private key handle */
228228
uint16_t uKeyH; /* public key handle */
229-
byte uKey[TA_KEY_TYPE_RSA2048_SIZE]; /* public key */
229+
byte uKey[WOLFSSL_TA_KEY_TYPE_RSA_SIZE]; /* public key */
230230
#endif
231231
#ifdef WOLF_CRYPTO_CB
232232
void* devCtx;
@@ -517,4 +517,3 @@ WOLFSSL_API int wc_RsaPrivateKeyDecodeRaw(const byte* n, word32 nSz,
517517

518518
#endif /* NO_RSA */
519519
#endif /* WOLF_CRYPT_RSA_H */
520-

0 commit comments

Comments
 (0)