Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion embedded/ti-c2000-f28p55x/Header/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,16 @@ extern "C" {
#define NO_HMAC
#endif

/* SRAM PUF (BCH fuzzy extractor). Enabled with --define=WOLF_PUF (PUF=1
* build, which also turns on HKDF). WOLFSSL_PUF_TEST lets the test inject a
* synthetic SRAM image with wc_PufSetTestData(). */
#ifdef WOLF_PUF
#undef WOLFSSL_PUF
#define WOLFSSL_PUF
#undef WOLFSSL_PUF_TEST
#define WOLFSSL_PUF_TEST
#endif

/* ChaCha20-Poly1305 AEAD (RFC 8439). Enabled with --define=WOLF_CHACHA. */
#ifdef WOLF_CHACHA
#undef HAVE_CHACHA
Expand Down Expand Up @@ -619,9 +629,12 @@ extern long my_time(long* t);
* Hash-DRBG. This exercises the real DRBG code path (what a production build
* with a TRNG would use) and lets random_test pass - but the seed is NOT
* random, so this is DEV/TEST ONLY and MUST NOT be shipped. Build with
* ENTROPY=1 for the real source. */
* ENTROPY=1 for the real source. random.c refuses the test seed unless
* WOLFSSL_ACCEPT_WEAK_ENTROPY acknowledges it. */
#undef WOLFSSL_GENSEED_FORTEST
#define WOLFSSL_GENSEED_FORTEST
#undef WOLFSSL_ACCEPT_WEAK_ENTROPY
#define WOLFSSL_ACCEPT_WEAK_ENTROPY
#endif

/* Run every self-test to completion and report each, so macro_test (a 16-bit
Expand Down
20 changes: 19 additions & 1 deletion embedded/ti-c2000-f28p55x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ ifeq ($(X448),1)
$(WOLFROOT)/wolfcrypt/src/ge_448.c
endif

# PUF=1 adds the SRAM PUF (BCH fuzzy extractor + HKDF key derivation) on a
# synthetic SRAM image (WOLFSSL_PUF_TEST). PUF_T selects the BCH profile
# (7, 10, 13 or 15) and PUF_CW the codeword count; both default to the library
# defaults. Implies HKDF=1.
PUF ?= 0
ifeq ($(PUF),1)
override HKDF := 1
CFLAGS += --define=WOLF_PUF
ifneq ($(PUF_T),)
CFLAGS += --define=WC_PUF_BCH_T=$(PUF_T)
endif
ifneq ($(PUF_CW),)
CFLAGS += --define=WC_PUF_NUM_CODEWORDS=$(PUF_CW)
endif
WC_SRCS += \
$(WOLFROOT)/wolfcrypt/src/puf.c
endif

# HKDF=1 adds HMAC + HKDF (RFC 2104 / RFC 5869) on top of the SHA-2/3 hashes.
HKDF ?= 0
ifeq ($(HKDF),1)
Expand Down Expand Up @@ -384,7 +402,7 @@ ifeq ($(SHA2)$(SHA3),11)
$(error SHA2=1 and SHA3=1 are separate images - build them one at a time)
endif
SHA_EXAMPLE_CONFLICTS := ECC MLKEM FASTVERIFY SECUREBOOT PRECOMPA MLDSA AES \
X25519 X448 HKDF CHACHA AESEXTRA HWAES RSA SHA1 RSASIGN DH SIGN BENCH \
X25519 X448 HKDF PUF CHACHA AESEXTRA HWAES RSA SHA1 RSASIGN DH SIGN BENCH \
MEMPROF ENTROPY ENTROPY_PROBE
ifneq ($(strip $(foreach t,$(SHA_EXAMPLE_CONFLICTS),$(filter-out 0,$($(t))))),)
$(error SHA2=1 / SHA3=1 are standalone images - build them without other toggles)
Expand Down
2 changes: 2 additions & 0 deletions embedded/ti-c2000-f28p55x/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The default build runs a KAT suite plus `wolfcrypt_test` and (optionally) `bench
- ML-KEM-768 (FIPS 203) keygen/encap/decap round-trip (`MLKEM=1`)
- AES-128/192/256 CBC/CTR/CFB/GCM (`AES=1`); AES-CMAC, AES-CCM, AES-GMAC (`AESEXTRA=1`); hardware-accelerated AES-ECB/CBC/CTR on the on-chip AESA block (`HWAES=1`)
- HMAC-SHA256 + HKDF (`HKDF=1`)
- SRAM PUF fuzzy extractor (BCH + HKDF) on a synthetic SRAM image: enroll, reconstruct with up to `t` bit flips per codeword, reject at `t+1` (`PUF=1`)
- ChaCha20-Poly1305 AEAD + Poly1305 (`CHACHA=1`)
- X25519 + Ed25519 (`X25519=1`)
- ECDSA + ECDH over SECP256R1 via SP math (`ECC=1`)
Expand Down Expand Up @@ -99,6 +100,7 @@ Each is `make <NAME>=1` (default 0 unless noted), additive on top of the default
| `HWAES=1` | Offload AES-ECB/CBC/CTR to the on-chip AESA accelerator via crypto callbacks (implies the AES core). See "Hardware AES" below |
| `X25519=1` | Curve25519 (X25519) + Ed25519 |
| `HKDF=1` | HMAC + HKDF (RFC 2104 / RFC 5869) |
| `PUF=1` | SRAM PUF fuzzy extractor on a synthetic SRAM image (implies `HKDF=1`). `PUF_T=7\|10\|13\|15` selects the BCH profile and `PUF_CW=<n>` the codeword count. The C28x boot ROM zeroes all RAM at power-on, so the part has no physical SRAM PUF source |
| `CHACHA=1` | ChaCha20-Poly1305 AEAD (RFC 8439) |
| `ENTROPY=1` | Real oscillator-jitter entropy source (DCC/INTOSC vs PLL) in place of the dev-only test seed. See "RNG and entropy" below |
| `ENTROPY_PROBE=1` | Raw entropy characterization image: dumps unconditioned samples over SCI for host analysis, runs no crypto |
Expand Down
120 changes: 120 additions & 0 deletions embedded/ti-c2000-f28p55x/Source/wolf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#include <wolfssl/wolfcrypt/hmac.h>
#include <wolfssl/wolfcrypt/kdf.h>
#endif
#ifdef WOLF_PUF
#include <wolfssl/wolfcrypt/puf.h>
#include <wolfssl/wolfcrypt/hash.h>
#endif
#ifdef WOLF_CHACHA
#include <wolfssl/wolfcrypt/chacha20_poly1305.h>
#endif
Expand Down Expand Up @@ -2472,6 +2476,117 @@ static void wolf_hkdf_test(void)
}
#endif /* WOLF_HKDF */

#ifdef WOLF_PUF
/* Large PUF state lives in .ebss, not on the 16-bit-SP stack. */
static wc_PufCtx puf_ctx;
static byte puf_img[WC_PUF_RAW_BYTES];
static byte puf_helper[WC_PUF_HELPER_BYTES];

static void puf_hex(const char* name, const byte* b, int len)
{
int i;
printf("%s: ", name);
for (i = 0; i < len; i++)
printf("%02x", (unsigned)(b[i] & 0xFF));
printf("\r\n");
}

/* Flip 'count' bits, 7 apart, in each 128-bit block of the raw image. */
static void puf_flip(byte* img, int count)
{
int blk, i;
for (blk = 0; blk < WC_PUF_NUM_CODEWORDS; blk++) {
for (i = 0; i < count; i++) {
long bitPos = ((long)blk * 128) + (i * 7);
img[bitPos / 8] ^= (byte)(1 << (7 - (int)(bitPos % 8)));
}
}
}

/* Reconstruct from a raw image; 0 only when identity and key both come out. */
static int puf_recon(const byte* img, byte* id, byte* key)
{
static const char info[] = "wolfPUF-c28x";
int r = wc_PufInit(&puf_ctx);
if (r == 0) r = wc_PufSetTestData(&puf_ctx, img, WC_PUF_RAW_BYTES);
if (r == 0) r = wc_PufReadSram(&puf_ctx, img, WC_PUF_RAW_BYTES);
if (r == 0) r = wc_PufReconstruct(&puf_ctx, puf_helper,
(word32)sizeof(puf_helper));
if (r == 0) r = wc_PufGetIdentity(&puf_ctx, id, WC_PUF_ID_SZ);
if (r == 0) r = wc_PufDeriveKey(&puf_ctx, (const byte*)info,
(word32)(sizeof(info) - 1), key,
WC_PUF_KEY_SZ);
return r;
}

/* Synthetic-SRAM PUF: enroll, then reconstruct clean, at t flips per codeword
* (must match) and at t+1 flips (must not reproduce the enrolled identity).
* The identity, key and helper digest are printed so a host run of the same
* image can be compared octet for octet. */
static void wolf_puf_test(void)
{
static const char info[] = "wolfPUF-c28x";
byte id0[WC_PUF_ID_SZ], key0[WC_PUF_KEY_SZ];
byte id1[WC_PUF_ID_SZ], key1[WC_PUF_KEY_SZ];
byte dig[32];
int m, n, k, t, cw, r;
word32 i;
double tEnroll = 0.0, tRecon;

r = wc_PufGetParams(&m, &n, &k, &t, &cw);
printf("PUF params: BCH(%d,%d,t=%d) codewords=%d raw=%d helper=%d\r\n",
n, k, t, cw, (int)WC_PUF_RAW_BYTES, (int)WC_PUF_HELPER_BYTES);

for (i = 0; i < (word32)WC_PUF_RAW_BYTES; i++)
puf_img[i] = (byte)(((i * 167UL + 13UL) ^ (i << 3)) & 0xFF);

if (r == 0) r = wc_PufInit(&puf_ctx);
if (r == 0) r = wc_PufSetTestData(&puf_ctx, puf_img, WC_PUF_RAW_BYTES);
if (r == 0) r = wc_PufReadSram(&puf_ctx, puf_img, WC_PUF_RAW_BYTES);
if (r == 0) {
(void)current_time(1);
r = wc_PufEnroll(&puf_ctx);
tEnroll = current_time(0);
}
if (r == 0) r = wc_PufGetHelperData(&puf_ctx, puf_helper,
(word32)sizeof(puf_helper));
if (r == 0) r = wc_PufGetIdentity(&puf_ctx, id0, sizeof(id0));
if (r == 0) r = wc_PufDeriveKey(&puf_ctx, (const byte*)info,
(word32)(sizeof(info) - 1), key0,
sizeof(key0));
if (r == 0) r = wc_Sha256Hash(puf_helper, (word32)sizeof(puf_helper), dig);
printf("PUF enroll: %s (r=%d, %.2f ms)\r\n", (r == 0) ? "PASS" : "FAIL",
r, tEnroll * 1000.0);
if (r != 0)
return;
puf_hex("PUF identity", id0, (int)sizeof(id0));
puf_hex("PUF key", key0, (int)sizeof(key0));
puf_hex("PUF helper sha256", dig, (int)sizeof(dig));

(void)current_time(1);
r = puf_recon(puf_img, id1, key1);
tRecon = current_time(0);
printf("PUF reconstruct (clean): %s (r=%d, %.2f ms incl. key derivation)"
"\r\n", (r == 0 && XMEMCMP(id0, id1, sizeof(id0)) == 0 &&
XMEMCMP(key0, key1, sizeof(key0)) == 0) ? "PASS" : "FAIL", r,
tRecon * 1000.0);

puf_flip(puf_img, t);
r = puf_recon(puf_img, id1, key1);
printf("PUF reconstruct (t flips): %s (r=%d)\r\n",
(r == 0 && XMEMCMP(id0, id1, sizeof(id0)) == 0 &&
XMEMCMP(key0, key1, sizeof(key0)) == 0) ? "PASS" : "FAIL", r);
puf_flip(puf_img, t);

puf_flip(puf_img, t + 1);
r = puf_recon(puf_img, id1, key1);
printf("PUF reject (t+1 flips): %s (r=%d)\r\n",
(r != 0 || XMEMCMP(id0, id1, sizeof(id0)) != 0) ? "PASS" : "FAIL", r);

wc_PufZeroize(&puf_ctx);
}
#endif /* WOLF_PUF */

#ifdef WOLF_CHACHA
static void wolf_poly1305_test(void)
{
Expand Down Expand Up @@ -2930,6 +3045,11 @@ int main(void)
wolf_hkdf_test();
#endif /* WOLF_HKDF */

#ifdef WOLF_PUF
printf("\r\n--- SRAM PUF (synthetic SRAM) ---\r\n");
wolf_puf_test();
#endif /* WOLF_PUF */

#ifdef WOLF_CHACHA
printf("\r\n--- ChaCha20-Poly1305 AEAD (RFC 8439) ---\r\n");
wolf_poly1305_test();
Expand Down
Loading