Skip to content

Commit 7a0b2da

Browse files
committed
Addressed copilot's comments
1 parent 665e137 commit 7a0b2da

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
@@ -449,13 +449,13 @@ int atmel_ecc_alloc(int slotType)
449449
break;
450450
#endif
451451
case ATMEL_SLOT_ECDHE_ALICE:
452-
/* not reserved in mSlotList, so return */
452+
/* reserve the fixed slot through the common allocation path */
453453
slotId = ATECC_SLOT_ECDHE_PRIV_ALICE;
454-
goto exit;
454+
break;
455455
case ATMEL_SLOT_ECDHE_BOB:
456-
/* not reserved in mSlotList, so return */
456+
/* reserve the fixed slot through the common allocation path */
457457
slotId = ATECC_SLOT_ECDHE_PRIV_BOB;
458-
goto exit;
458+
break;
459459
case ATMEL_SLOT_ANY:
460460
for (i=0; i < ATECC_MAX_SLOT; i++) {
461461
/* Find free slotId */
@@ -473,8 +473,7 @@ int atmel_ecc_alloc(int slotType)
473473
}
474474

475475
/* is slot available */
476-
if (mSlotList[slotId] != ATECC_INVALID_SLOT &&
477-
mSlotList[slotId] != slotId ) {
476+
if (mSlotList[slotId] != ATECC_INVALID_SLOT) {
478477
slotId = ATECC_INVALID_SLOT;
479478
}
480479
else {
@@ -882,13 +881,20 @@ int wc_Microchip_rsa_create_key(struct RsaKey* key, int size, long e)
882881
{
883882
ATCA_STATUS ret;
884883
ta_element_attributes_t rKeyA, uKeyA;
885-
size_t uKey_len = TA_KEY_TYPE_RSA2048_SIZE;
884+
size_t uKey_len = WOLFSSL_TA_KEY_TYPE_RSA_SIZE;
886885

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

890896
/* Private key for signing AND decryption */
891-
ret = talib_handle_init_private_key(&rKeyA, TA_KEY_TYPE_RSA2048,
897+
ret = talib_handle_init_private_key(&rKeyA, WOLFSSL_TA_KEY_TYPE_RSA,
892898
TA_ALG_MODE_RSA_SSA_PSS, TA_PROP_SIGN_INT_EXT_DIGEST,
893899
TA_PROP_KEY_AGREEMENT_OUT_BUFF);
894900
if (ret != ATCA_SUCCESS)
@@ -901,7 +907,7 @@ int wc_Microchip_rsa_create_key(struct RsaKey* key, int size, long e)
901907
return WC_HW_E;
902908

903909
/* Public key - use 0, 0 for encryption support! */
904-
ret = talib_handle_init_public_key(&uKeyA, TA_KEY_TYPE_RSA2048,
910+
ret = talib_handle_init_public_key(&uKeyA, WOLFSSL_TA_KEY_TYPE_RSA,
905911
TA_ALG_MODE_RSA_SSA_PSS, 0, 0);
906912
if (ret != ATCA_SUCCESS)
907913
return WC_HW_E;
@@ -940,7 +946,7 @@ int wc_Microchip_rsa_encrypt(const byte* in, word32 inLen, byte* out,
940946
printf("outLen: %u\n", outLen);
941947
printf("out: %p\n", out);
942948
#endif
943-
/* Use the 2048-specific function */
949+
/* The current wolfSSL TA100 backend uses the RSA-2048 RSAEnc path. */
944950
ret = talib_rsaenc_encrypt2048(atcab_get_device(), key->uKeyH,
945951
(uint16_t)inLen, in,
946952
(uint16_t)outLen, out);
@@ -953,7 +959,7 @@ int wc_Microchip_rsa_decrypt(const byte* in, word32 inLen, byte* out,
953959
{
954960
int ret;
955961

956-
962+
/* The current wolfSSL TA100 backend uses the RSA-2048 RSAEnc path. */
957963
ret = talib_rsaenc_decrypt2048(atcab_get_device(), key->rKeyH,
958964
(uint16_t)inLen, in,
959965
(uint16_t)outLen, out);
@@ -1308,7 +1314,7 @@ int atcatls_create_key_cb(WOLFSSL* ssl, ecc_key* key, unsigned int keySz,
13081314
return WC_HW_WAIT_E;
13091315

13101316
/* generate new ephemeral key on device */
1311-
ret = atmel_ecc_create_key(MAP_TO_HANDLE(slotId), ecc_curve, peerKey);
1317+
ret = atmel_ecc_create_key(slotId, ecc_curve, peerKey);
13121318

13131319
/* load generated ECC508A public key into key, used by wolfSSL */
13141320
if (ret == 0) {
@@ -1385,8 +1391,7 @@ int atcatls_create_pms_cb(WOLFSSL* ssl, ecc_key* otherKey,
13851391
tmpKey.slot = slotId;
13861392

13871393
/* generate new ephemeral key on device */
1388-
ret = atmel_ecc_create_key(MAP_TO_HANDLE(slotId), otherKey->dp->id,
1389-
peerKey);
1394+
ret = atmel_ecc_create_key(slotId, otherKey->dp->id, peerKey);
13901395
if (ret != ATCA_SUCCESS) {
13911396
atmel_ecc_free(slotId);
13921397
goto exit;
@@ -1661,6 +1666,7 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
16611666
#endif
16621667

16631668
int ret = 0;
1669+
ATCA_STATUS status;
16641670
size_t signerCertSize = ATCATLS_SIGNER_CERT_MAX_SIZE;
16651671
size_t deviceCertSize = ATCATLS_DEVICE_CERT_MAX_SIZE;
16661672
uint8_t certBuffer[ATCATLS_CERT_BUFF_MAX_SIZE];
@@ -1670,7 +1676,6 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
16701676
#endif
16711677

16721678
#ifdef WOLFSSL_ATECC_TNGTLS
1673-
ATCA_STATUS status;
16741679
ret = tng_atcacert_max_signer_cert_size(&signerCertSize);
16751680
if (ret != ATCACERT_E_SUCCESS) {
16761681
#ifdef WOLFSSL_ATECC_DEBUG
@@ -1780,7 +1785,6 @@ static int atcatls_set_certificates(WOLFSSL_CTX *ctx)
17801785
return ret;
17811786
}
17821787
#endif /* ATCA_TFLEX_SUPPORT */
1783-
#endif /* ATCA_TFLEX_SUPPORT */
17841788

17851789
int atcatls_set_callbacks(WOLFSSL_CTX* ctx)
17861790
{
@@ -1919,11 +1923,12 @@ int wc_Microchip_aes_set_key(Aes* aes, const byte* key, word32 keylen,
19191923
status = talib_aes_gcm_keyload(atcab_get_device(), aes->key_id, 0);
19201924
CHECK_STATUS(status);
19211925

1922-
/* Test if data zone is locked */
1926+
/* Provisioning must lock setup explicitly; do not lock it as a side
1927+
* effect of loading an AES key. */
19231928
status = talib_is_setup_locked(atcab_get_device(), &is_locked);
1929+
CHECK_STATUS(status);
19241930
if (!is_locked) {
1925-
status = talib_lock_setup(atcab_get_device());
1926-
CHECK_STATUS(status);
1931+
return WC_HW_E;
19271932
}
19281933

19291934
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)