Skip to content

Commit 4e64cb5

Browse files
committed
TA100: Microchip Trust Anchor support RSA/ECC
1 parent 8741805 commit 4e64cb5

17 files changed

Lines changed: 987 additions & 177 deletions

File tree

configure.ac

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,15 +2967,41 @@ AC_ARG_WITH([maxq10xx],
29672967
]
29682968
)
29692969

2970+
AC_ARG_ENABLE([microchip],
2971+
[AS_HELP_STRING([--enable-microchip],[Enable wolfSSL support for microchip/atmel 508/608/100 (default: disabled)])],
2972+
[ ENABLED_ATMEL=$enableval ],
2973+
[ ENABLED_ATMEL=no ]
2974+
)
2975+
2976+
if test "$ENABLED_ATMEL" != "no"
2977+
then
2978+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_MICROCHIP"
2979+
2980+
for v in `echo $ENABLED_ATMEL | tr "," " "`
2981+
do
2982+
case $v in
2983+
508)
2984+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ATECC508A"
2985+
;;
2986+
2987+
608)
2988+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ATECC608A"
2989+
;;
2990+
2991+
100)
2992+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_MICROCHIP_TA100 -DMICROCHIP_DEV_TYPE=TA100"
2993+
;;
2994+
esac
2995+
done
2996+
fi
29702997
# Microchip/Atmel CryptoAuthLib
29712998
ENABLED_CRYPTOAUTHLIB="no"
29722999
trylibatcadir=""
29733000
AC_ARG_WITH([cryptoauthlib],
2974-
[AS_HELP_STRING([--with-cryptoauthlib=PATH],[PATH to CryptoAuthLib install (default /usr/)])],
3001+
[AS_HELP_STRING([--with-cryptoauthlib=PATH],[PATH to CryptoAuthLib install (default /usr)])],
29753002
[
29763003
AC_MSG_CHECKING([for cryptoauthlib])
2977-
CPPFLAGS="$CPPFLAGS -DWOLFSSL_ATECC508A"
2978-
LIBS="$LIBS -lcryptoauth"
3004+
LIBS="$LIBS -lcryptoauth -lwolfssl -lpthread -lrt"
29793005
29803006
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cryptoauthlib.h>]], [[ atcab_init(0); ]])],[ libatca_linked=yes ],[ libatca_linked=no ])
29813007
@@ -2987,25 +3013,23 @@ AC_ARG_WITH([cryptoauthlib],
29873013
trylibatcadir="/usr"
29883014
fi
29893015
2990-
LDFLAGS="$LDFLAGS -L$trylibatcadir/lib"
2991-
CPPFLAGS="$CPPFLAGS -I$trylibatcadir/lib"
2992-
2993-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <cryptoauthlib.h>]], [[ atcab_init(0); ]])],[ libatca_linked=yes ],[ libatca_linked=no ])
2994-
2995-
if test "x$libatca_linked" = "xno" ; then
2996-
AC_MSG_ERROR([cryptoauthlib isn't found.
2997-
If it's already installed, specify its path using --with-cryptoauthlib=/dir/])
3016+
if test "$host_cpu" = "aarch64" ; then
3017+
LIB_SUFFIX="/aarch64-linux-gnu"
3018+
else
3019+
LIB_SUFFIX=""
29983020
fi
29993021
3000-
AM_LDFLAGS="$AM_LDFLAGS -L$trylibatcadir/lib"
3001-
AM_CFLAGS="$AM_CFLAGS -I$trylibatcadir/lib"
3022+
LDFLAGS="$LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3023+
CPPFLAGS="$CPPFLAGS -I$trylibatcadir/include/cryptoauthlib"
3024+
AM_LDFLAGS="$AM_LDFLAGS -L$trylibatcadir/lib$LIB_SUFFIX"
3025+
AM_CFLAGS="$AM_CFLAGS -I$trylibatcadir/include/cryptoauthlib"
3026+
30023027
AC_MSG_RESULT([yes])
30033028
else
30043029
AC_MSG_RESULT([yes])
30053030
fi
30063031
30073032
ENABLED_CRYPTOAUTHLIB="yes"
3008-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ATECC508A"
30093033
]
30103034
)
30113035

src/pk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10901,6 +10901,7 @@ int wolfSSL_EC_POINT_set_affine_coordinates_GFp(const WOLFSSL_EC_GROUP* group,
1090110901
}
1090210902

1090310903
#if !defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A) && \
10904+
!defined(WOLFSSL_MICROCHIP_TA100) && \
1090410905
!defined(HAVE_SELFTEST) && !defined(WOLFSSL_SP_MATH) && \
1090510906
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
1090610907
/* Add two points on the same together.

tests/api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39919,7 +39919,6 @@ static int test_wolfSSL_EVP_PKEY_hkdf(void)
3991939919
0x2F, 0xA5, 0xE3, 0x4E, 0xF1, 0xF4, 0x87, 0x3E, 0xA6, 0xC7, 0x88, 0x45,
3992039920
0xD7, 0xE2, 0x15, 0xBC, 0xB8, 0x10, 0xEF, 0x6C, 0x4D, 0x7A
3992139921
};
39922-
3992339922
ExpectNotNull((ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, NULL)));
3992439923
ExpectIntEQ(EVP_PKEY_derive_init(ctx), WOLFSSL_SUCCESS);
3992539924
/* NULL ctx. */

tests/api/test_ecc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,8 @@ int test_wc_ecc_pointFns(void)
13681368
EXPECT_DECLS;
13691369
#if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT) && \
13701370
!defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
1371-
!defined(WOLFSSL_ATECC608A) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
1371+
!defined(WOLFSSL_ATECC608A) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
1372+
!defined(WOLFSSL_MICROCHIP_TA100)
13721373
ecc_key key;
13731374
WC_RNG rng;
13741375
int ret;
@@ -1473,7 +1474,8 @@ int test_wc_ecc_shared_secret_ssh(void)
14731474
#if defined(HAVE_ECC) && defined(HAVE_ECC_DHE) && \
14741475
!defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
14751476
!defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
1476-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
1477+
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
1478+
!defined(WOLFSSL_MICROCHIP_TA100)
14771479
ecc_key key;
14781480
ecc_key key2;
14791481
WC_RNG rng;
@@ -1518,7 +1520,7 @@ int test_wc_ecc_shared_secret_ssh(void)
15181520
ExpectIntEQ(wc_ecc_set_rng(&key, &rng), 0);
15191521
#endif
15201522

1521-
ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, &key2.pubkey, secret,
1523+
ExpectIntEQ(wc_ecc_shared_secret_ssh(&key, key2.pubkey, secret,
15221524
&secretLen), 0);
15231525
/* Pass in bad args. */
15241526
ExpectIntEQ(wc_ecc_shared_secret_ssh(NULL, &key2.pubkey, secret,
@@ -1553,7 +1555,8 @@ int test_wc_ecc_verify_hash_ex(void)
15531555
EXPECT_DECLS;
15541556
#if defined(HAVE_ECC) && defined(HAVE_ECC_SIGN) && defined(WOLFSSL_PUBLIC_MP) \
15551557
&& !defined(WC_NO_RNG) && !defined(WOLFSSL_ATECC508A) && \
1556-
!defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC)
1558+
!defined(WOLFSSL_ATECC608A) && !defined(WOLFSSL_KCAPI_ECC) && \
1559+
!defined(WOLFSSL_MICROCHIP_TA100)
15571560
ecc_key key;
15581561
WC_RNG rng;
15591562
int ret;
@@ -1647,6 +1650,7 @@ int test_wc_ecc_mulmod(void)
16471650
EXPECT_DECLS;
16481651
#if defined(HAVE_ECC) && !defined(WC_NO_RNG) && \
16491652
!(defined(WOLFSSL_ATECC508A) || defined(WOLFSSL_ATECC608A) || \
1653+
defined(WOLFSSL_MICROCHIP_TA100) || \
16501654
defined(WOLFSSL_VALIDATE_ECC_IMPORT)) && \
16511655
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
16521656
ecc_key key1;

wolfcrypt/benchmark/benchmark.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ static WC_INLINE void bench_append_memory_info(char* buffer, size_t size,
819819
#define TEST_STRING "Everyone gets Friday off."
820820
#define TEST_STRING_SZ 25
821821

822-
823822
/* Bit values for each algorithm that is able to be benchmarked.
824823
* Common grouping of algorithms also.
825824
* Each algorithm has a unique value for its type e.g. cipher.
@@ -2078,7 +2077,8 @@ static const char* bench_result_words2[][6] = {
20782077
static volatile int g_threadCount;
20792078
#endif
20802079

2081-
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID)
2080+
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_CAAM) || defined(WC_USE_DEVID) || \
2081+
defined(WOLFSSL_MICROCHIP_TA100)
20822082
#ifndef NO_HW_BENCH
20832083
#define BENCH_DEVID
20842084
#endif
@@ -9987,8 +9987,12 @@ static void bench_rsa_helper(int useDeviceID,
99879987
1, &times, ntimes, &pending)) {
99889988
#if !defined(WOLFSSL_RSA_VERIFY_INLINE) && \
99899989
!defined(WOLFSSL_RSA_PUBLIC_ONLY)
9990-
ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
9990+
#if defined(WOLFSSL_MICROCHIP_TA100)
9991+
ret = wc_RsaSSL_Verify(message, len, enc[i], rsaKeySz/8, rsaKey[i]);
9992+
#else
9993+
ret = wc_RsaSSL_Verify(enc[i], idx, out[i],
99919994
rsaKeySz/8, rsaKey[i]);
9995+
#endif
99929996
#elif defined(USE_CERT_BUFFERS_2048)
99939997
XMEMCPY(enc[i], rsa_2048_sig, sizeof(rsa_2048_sig));
99949998
idx = sizeof(rsa_2048_sig);
@@ -10124,6 +10128,13 @@ void bench_rsa(int useDeviceID)
1012410128
#else
1012510129
/* Note: To benchmark public only define WOLFSSL_PUBLIC_MP */
1012610130
rsaKeySz = 0;
10131+
#endif
10132+
#if defined(WOLFSSL_MICROCHIP_TA100)
10133+
/* Create new keys since you cannot import a private key to TA100 */
10134+
ret = wc_MakeRsaKey(rsaKey[i], rsaKeySz, WC_RSA_EXPONENT, &gRng);
10135+
if (ret) {
10136+
goto exit;
10137+
}
1012710138
#endif
1012810139
}
1012910140

@@ -12106,6 +12117,9 @@ void bench_ecc(int useDeviceID, int curveId)
1210612117
if ((ret = wc_ecc_init_ex(genKey[i], HEAP_HINT, deviceID)) < 0) {
1210712118
goto exit;
1210812119
}
12120+
#if defined(WOLFSSL_MICROCHIP_TA100)
12121+
genKey[i]->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE_ALICE);
12122+
#endif
1210912123
ret = wc_ecc_make_key_ex(&gRng, keySize, genKey[i], curveId);
1211012124
#ifdef WOLFSSL_ASYNC_CRYPT
1211112125
ret = wc_AsyncWait(ret, &genKey[i]->asyncDev, WC_ASYNC_FLAG_NONE);
@@ -12118,6 +12132,9 @@ void bench_ecc(int useDeviceID, int curveId)
1211812132
if ((ret = wc_ecc_init_ex(genKey2[i], HEAP_HINT, deviceID)) < 0) {
1211912133
goto exit;
1212012134
}
12135+
#if defined(WOLFSSL_MICROCHIP_TA100)
12136+
genKey2[i]->slot = atmel_ecc_alloc(ATMEL_SLOT_ECDHE_BOB);
12137+
#endif
1212112138
if ((ret = wc_ecc_make_key_ex(&gRng, keySize, genKey2[i],
1212212139
curveId)) > 0) {
1212312140
goto exit;
@@ -12314,7 +12331,10 @@ void bench_ecc(int useDeviceID, int curveId)
1231412331
WC_FREE_ARRAY(sig, BENCH_MAX_PENDING, HEAP_HINT);
1231512332
WC_FREE_ARRAY(digest, BENCH_MAX_PENDING, HEAP_HINT);
1231612333
#endif
12317-
12334+
#if defined(WOLFSSL_MICROCHIP_TA100)
12335+
atmel_ecc_free(ATMEL_SLOT_ECDHE_ALICE);
12336+
atmel_ecc_free(ATMEL_SLOT_ECDHE_BOB);
12337+
#endif
1231812338
(void)useDeviceID;
1231912339
(void)pending;
1232012340
(void)x;

wolfcrypt/src/aes.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
6969
#if defined(WOLFSSL_SE050) && defined(WOLFSSL_SE050_CRYPT)
7070
#include <wolfssl/wolfcrypt/port/nxp/se050_port.h>
7171
#endif
72-
73-
#if defined(WOLFSSL_AES_SIV)
72+
#ifdef WOLFSSL_MICROCHIP_TA100
73+
#include <wolfssl/wolfcrypt/port/atmel/atmel.h>
74+
#endif
75+
#ifdef WOLFSSL_AES_SIV
7476
#include <wolfssl/wolfcrypt/cmac.h>
75-
#endif /* WOLFSSL_AES_SIV */
77+
#endif
7678

7779
#if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
7880
#include <wolfssl/wolfcrypt/port/psa/psa.h>
@@ -4978,7 +4980,13 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
49784980
return ret;
49794981
}
49804982
#endif
4981-
4983+
#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
4984+
ret = wc_Microchip_aes_set_key(aes, userKey, keylen, iv, dir);
4985+
if (ret == 0) {
4986+
ret = wc_AesSetIV(aes, iv);
4987+
}
4988+
return ret;
4989+
#endif
49824990
XMEMCPY(aes->key, userKey, keylen);
49834991

49844992
#ifndef WC_AES_BITSLICED
@@ -9453,7 +9461,13 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
94539461
authTag, authTagSz,
94549462
authIn, authInSz);
94559463
#endif
9456-
9464+
#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
9465+
return wc_Microchip_AesGcmEncrypt(
9466+
aes, out, in, sz,
9467+
iv, ivSz,
9468+
authTag, authTagSz,
9469+
authIn, authInSz);
9470+
#endif
94579471
#ifdef STM32_CRYPTO_AES_GCM
94589472
return wc_AesGcmEncrypt_STM32(
94599473
aes, out, in, sz, iv, ivSz,
@@ -10137,6 +10151,11 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
1013710151
authTag, authTagSz, authIn, authInSz);
1013810152

1013910153
#endif
10154+
#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
10155+
return wc_Microchip_AesGcmDecrypt(
10156+
aes, out, in, sz, iv, ivSz,
10157+
authTag, authTagSz, authIn, authInSz);
10158+
#endif
1014010159

1014110160
#ifdef STM32_CRYPTO_AES_GCM
1014210161
/* The STM standard peripheral library API's doesn't support partial blocks */
@@ -13038,7 +13057,9 @@ void wc_AesFree(Aes* aes)
1303813057
se050_aes_free(aes);
1303913058
}
1304013059
#endif
13041-
13060+
#if defined(WOLFSSL_MICROCHIP_TA100) && defined(WOLFSSL_MICROCHIP_AESGCM)
13061+
wc_Microchip_aes_free(aes);
13062+
#endif
1304213063
#if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
1304313064
wc_psa_aes_free(aes);
1304413065
#endif

0 commit comments

Comments
 (0)