Skip to content

Commit a95ef66

Browse files
committed
Add ATECC608 CI tests
Also fix issues found with ATECC608
1 parent 71a8a55 commit a95ef66

4 files changed

Lines changed: 102 additions & 11 deletions

File tree

.github/workflows/atecc608-sim.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: ATECC608 simulator test
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
# Build the ATECC608 software simulator (https://github.com/wolfSSL/simulators,
16+
# ATECC608Sim/ subdirectory), build wolfSSL against cryptoauthlib + the
17+
# simulator's TCP HAL, and run the wolfCrypt ATECC608 test binary against the
18+
# simulator.
19+
#
20+
# The simulator's own Dockerfile.wolfcrypt clones a pinned wolfSSL release.
21+
# We patch it to COPY the PR checkout instead so CI reflects the PR's source.
22+
# We also strip the inline test.c patch RUN block: those guard fixes now live
23+
# upstream in this tree, so re-applying them would fail with "patch target not
24+
# found". The remaining sed-based patches in the Dockerfile (atmel.c XMEMSET
25+
# swap and atmel_set_slot_allocator visibility) are no-ops on pre-patched
26+
# source and their grep validations still pass, so we leave them alone.
27+
28+
env:
29+
SIMULATORS_REF: 773fe70
30+
31+
jobs:
32+
atecc608_sim:
33+
name: wolfCrypt against ATECC608 simulator
34+
if: github.repository_owner == 'wolfssl'
35+
runs-on: ubuntu-24.04
36+
timeout-minutes: 30
37+
steps:
38+
- name: Checkout wolfSSL (PR source)
39+
uses: actions/checkout@v4
40+
with:
41+
path: wolfssl-src
42+
43+
- name: Clone ATECC608 simulator
44+
run: |
45+
git clone https://github.com/wolfSSL/simulators simulators
46+
cd simulators && git checkout "$SIMULATORS_REF"
47+
48+
- name: Stage PR wolfSSL into simulator build context
49+
run: mv wolfssl-src simulators/ATECC608Sim/wolfssl
50+
51+
- name: Patch Dockerfile to use PR wolfSSL and drop redundant test.c patches
52+
working-directory: simulators/ATECC608Sim
53+
run: |
54+
# Replace the (multi-line) `RUN git clone ... wolfssl.git /app/wolfssl`
55+
# with a COPY of the PR checkout so CI tests the PR's source.
56+
sed -i '/^RUN git clone --branch v5\.9\.1-stable/,/wolfssl\.git \/app\/wolfssl$/c\
57+
COPY wolfssl /app/wolfssl' Dockerfile.wolfcrypt
58+
# Fail fast if the pattern drifted upstream -- better a clear error
59+
# than a CI run that silently tests a stale release.
60+
grep -q '^ *COPY wolfssl /app/wolfssl$' Dockerfile.wolfcrypt
61+
! grep -q 'git clone .*wolfssl\.git' Dockerfile.wolfcrypt
62+
63+
# Strip the inline test.c patch RUN block -- those guard fixes now
64+
# live upstream in this tree.
65+
sed -i "/^RUN python3 - <<'PY'$/,/^PY$/d" Dockerfile.wolfcrypt
66+
! grep -q "RUN python3 - <<'PY'" Dockerfile.wolfcrypt
67+
68+
- uses: docker/setup-buildx-action@v3
69+
70+
- name: Build wolfCrypt-ATECC608 test image
71+
uses: docker/build-push-action@v5
72+
with:
73+
context: simulators/ATECC608Sim
74+
file: simulators/ATECC608Sim/Dockerfile.wolfcrypt
75+
push: false
76+
load: true
77+
tags: wolfssl-atecc608-sim:ci
78+
cache-from: type=gha
79+
cache-to: type=gha,mode=max
80+
81+
- name: Run wolfCrypt tests against simulator
82+
run: docker run --rm wolfssl-atecc608-sim:ci

wolfcrypt/src/port/atmel/atmel.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ int wolfCrypt_ATECC_SetConfig(ATCAIfaceCfg* cfg)
193193
return -1;
194194
}
195195

196-
/* copy configuration into our local struct */
197-
XMEMSET(&cfg_ateccx08a_i2c_pi, 0, sizeof(cfg_ateccx08a_i2c_pi));
196+
/* Copy whole struct so non-I2C interface unions (e.g. atcacustom function
197+
* pointers when iface_type == ATCA_CUSTOM_IFACE) survive. The field-by-
198+
* field assignments below then refresh the I2C-specific fields. */
199+
XMEMCPY(&cfg_ateccx08a_i2c_pi, cfg, sizeof(cfg_ateccx08a_i2c_pi));
198200
cfg_ateccx08a_i2c_pi.iface_type = cfg->iface_type;
199201
cfg_ateccx08a_i2c_pi.devtype = cfg->devtype;
200202
#ifdef ATCA_ENABLE_DEPRECATED
@@ -232,7 +234,7 @@ int atmel_ecc_translate_err(int status)
232234
}
233235

234236
/* Function to set the slotId allocator and deallocator */
235-
int atmel_set_slot_allocator(atmel_slot_alloc_cb alloc,
237+
WOLFSSL_API int atmel_set_slot_allocator(atmel_slot_alloc_cb alloc,
236238
atmel_slot_dealloc_cb dealloc)
237239
{
238240
#ifndef SINGLE_THREADED

wolfcrypt/test/test.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36936,7 +36936,8 @@ static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
3693636936
#endif
3693736937

3693836938
#if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
36939-
!defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
36939+
!defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG) && \
36940+
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
3694036941
ret = ecc_test_key_decode(rng, keySize);
3694136942
if (ret < 0) {
3694236943
if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
@@ -36949,7 +36950,8 @@ static wc_test_ret_t ecc_test_curve(WC_RNG* rng, int keySize, int curve_id)
3694936950
}
3695036951
#endif
3695136952

36952-
#if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG)
36953+
#if defined(HAVE_ECC_KEY_EXPORT) && !defined(NO_ASN_CRYPT) && !defined(WC_NO_RNG) && \
36954+
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
3695336955
ret = ecc_test_key_gen(rng, keySize);
3695436956
if (ret < 0) {
3695536957
if (ret == WC_NO_ERR_TRACE(ECC_CURVE_OID_E)) {
@@ -37399,7 +37401,8 @@ static wc_test_ret_t ecc_exp_imp_test(ecc_key* key)
3739937401
#endif /* HAVE_ECC_KEY_IMPORT && HAVE_ECC_KEY_EXPORT */
3740037402

3740137403
#if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
37402-
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
37404+
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
37405+
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
3740337406
static wc_test_ret_t ecc_mulmod_test(ecc_key* key1)
3740437407
{
3740537408
wc_test_ret_t ret;
@@ -37581,8 +37584,10 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
3758137584
#endif
3758237585
TEST_SLEEP();
3758337586

37584-
#if defined(HAVE_ECC_DHE) && !defined(WOLFSSL_CRYPTOCELL) && \
37585-
!defined(WOLF_CRYPTO_CB_ONLY_ECC)
37587+
#if defined(HAVE_ECC_DHE) && !defined(WC_NO_RNG) && \
37588+
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLFSSL_ATECC508A) && \
37589+
!defined(WOLFSSL_ATECC608A) && !defined(PLUTON_CRYPTO_ECC) && \
37590+
!defined(WOLFSSL_CRYPTOCELL)
3758637591
ret = ecc_ssh_test(key, rng);
3758737592
if (ret < 0)
3758837593
goto done;
@@ -37627,13 +37632,15 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
3762737632
goto done;
3762837633
}
3762937634

37630-
#if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)
37635+
#if defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT) && \
37636+
!defined(WOLFSSL_ATECC508A) && !defined(WOLFSSL_ATECC608A)
3763137637
ret = ecc_exp_imp_test(key);
3763237638
if (ret < 0)
3763337639
goto done;
3763437640
#endif
3763537641
#if defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT) && \
37636-
!defined(WOLFSSL_CRYPTOCELL)
37642+
!defined(WOLFSSL_CRYPTOCELL) && !defined(WOLFSSL_ATECC508A) && \
37643+
!defined(WOLFSSL_ATECC608A)
3763737644
ret = ecc_mulmod_test(key);
3763837645
if (ret < 0)
3763937646
goto done;

wolfssl/wolfcrypt/port/atmel/atmel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void atmel_ecc_free(int slotId);
100100

101101
typedef int (*atmel_slot_alloc_cb)(int);
102102
typedef void (*atmel_slot_dealloc_cb)(int);
103-
int atmel_set_slot_allocator(atmel_slot_alloc_cb alloc,
103+
WOLFSSL_API int atmel_set_slot_allocator(atmel_slot_alloc_cb alloc,
104104
atmel_slot_dealloc_cb dealloc);
105105

106106
int atmel_ecc_translate_err(int status);

0 commit comments

Comments
 (0)