99 \ingroup PUF
1010
1111 \brief Initialize a wc_PufCtx structure, zeroing all fields.
12- Must be called before any other PUF operations.
12+ Hardware PUF (WOLFSSL_HWPUF) may turn on power/clock and reset the
13+ peripheral. Must be called before any other PUF operations.
1314
1415 \return 0 on success
1516 \return BAD_FUNC_ARG if ctx is NULL
2223 ret = wc_PufInit(&ctx);
2324 \endcode
2425
26+ \sa wc_PufDeinit
2527 \sa wc_PufReadSram
2628 \sa wc_PufEnroll
2729 \sa wc_PufZeroize
2830*/
2931int wc_PufInit (wc_PufCtx * ctx );
3032
33+ /*!
34+ \ingroup PUF
35+
36+ \brief Deinitialize a wc_PufCtx structure, zeroing all fields.
37+ Hardware PUF (WOLFSSL_HWPUF) may turn off power/clock and reset the
38+ peripheral.
39+
40+ \return 0 on success
41+ \return BAD_FUNC_ARG if ctx is NULL
42+
43+ \param ctx pointer to wc_PufCtx structure to initialize
44+
45+ _Example_
46+ \code
47+ wc_PufCtx ctx;
48+ ret = wc_PufDeinit(&ctx);
49+ \endcode
50+
51+ \sa wc_PufInit
52+ \sa wc_PufReadSram
53+ \sa wc_PufEnroll
54+ \sa wc_PufZeroize
55+ */
56+ int wc_PufDeinit (wc_PufCtx * ctx );
57+
3158/*!
3259 \ingroup PUF
3360
3461 \brief Read raw SRAM data into the PUF context. The sramAddr should
3562 point to a NOLOAD linker section to preserve the power-on state.
63+ This function is valid for software PUF (WOLFSSL_PUF), but invalid for
64+ hardware PUF (WOLFSSL_HWPUF)
3665
3766 \return 0 on success
3867 \return BAD_FUNC_ARG if ctx or sramAddr is NULL
@@ -58,9 +87,14 @@ int wc_PufReadSram(wc_PufCtx* ctx, const byte* sramAddr, word32 sramSz);
5887/*!
5988 \ingroup PUF
6089
61- \brief Perform PUF enrollment. Encodes raw SRAM using BCH(127,64,t=10)
90+ \brief Perform PUF enrollment.
91+ For software PUF (WOLFSSL_PUF), encodes raw SRAM using BCH(127,64,t=10)
6292 and generates public helper data. After enrollment the context is ready
6393 for key derivation and identity retrieval.
94+ For hardware PUF (WOLFSSL_HWPUF), encodes raw SRAM using a proprietary
95+ method and generates an Activation Code. After enrollment, device must
96+ go through a deinit/init/reconstruct cycle, before device is ready for
97+ key generation/derivation. There is no helperData for hardware puf.
6498
6599 \return 0 on success
66100 \return BAD_FUNC_ARG if ctx is NULL
@@ -76,16 +110,21 @@ int wc_PufReadSram(wc_PufCtx* ctx, const byte* sramAddr, word32 sramSz);
76110
77111 \sa wc_PufReadSram
78112 \sa wc_PufReconstruct
113+ \sa wc_PufGenerateKey
79114 \sa wc_PufDeriveKey
80115*/
81116int wc_PufEnroll (wc_PufCtx * ctx );
82117
83118/*!
84119 \ingroup PUF
85120
86- \brief Reconstruct stable PUF bits from noisy SRAM using stored helper
87- data. BCH error correction (t=10) corrects up to 10 bit flips per
88- 127-bit codeword.
121+ \brief Performs reconstruction (starts puf) with data from enrollment.
122+ For software PUF (WOLFSSL_PUF), reconstructs stable PUF bits from noisy
123+ SRAM using stored helper data. BCH error correction (t=10) corrects up to
124+ 10 bit flips per 127-bit codeword.
125+ For hardware PUF (WOLFSSL_HWPUF), starts PUF peripheral with an activation
126+ code, which is stored internally in RAM during a previous enrollment, or
127+ is stored in flash in a known location. helperData is ignored for hw puf.
89128
90129 \return 0 on success
91130 \return BAD_FUNC_ARG if ctx or helperData is NULL
@@ -110,18 +149,58 @@ int wc_PufReconstruct(wc_PufCtx* ctx, const byte* helperData, word32 helperSz);
110149/*!
111150 \ingroup PUF
112151
113- \brief Derive a cryptographic key from PUF stable bits using HKDF.
152+ \brief Generates a key and returns a key code (WOLFSSL_HWPUF only).
153+ The key code can be later used to derive the key.
154+ This function is invalid for software PUF (WOLFSSL_PUF).
155+
156+ \return 0 on success
157+ \return BAD_FUNC_ARG if ctx or kcBuf is NULL, or keyIdx/keySz/kcBufSz is bad
158+ \return PUF_GENERATE_KEY_E if PUF not ready or key generation fails
159+
160+ \param ctx pointer to wc_PufCtx (must be enrolled or reconstructed)
161+ \param keyIdx key index 0 to 15. If 0, when derived, will be sent directly
162+ to hardware bus (never exposed in ram)
163+ \param keySz size of key in bytes, 16, 24, 32 are valid
164+ \param kcBuf key code output buffer
165+ \param kcBufSz size of key code output buffer
166+
167+ _Example_
168+ \code
169+ byte key[32];
170+ const byte info[] = "my-app-key";
171+ wc_PufDeriveKey(&ctx, info, sizeof(info), key, sizeof(key));
172+ \endcode
173+
174+ \sa wc_PufEnroll
175+ \sa wc_PufReconstruct
176+ \sa wc_PufGetIdentity
177+ \sa wc_PufDeriveKey
178+ */
179+ int wc_PufGenerateKey (wc_PufCtx * ctx , byte keyIdx , word32 keySz ,
180+ byte * kcBuf , word32 kcBufSz );
181+
182+ /*!
183+ \ingroup PUF
184+
185+ \brief Derive a cryptographic key
186+ For software PUF (WOLFSSL_PUF), derives key from stable bits using HKDF.
114187 Uses SHA-256 by default, or SHA3-256 when WC_PUF_SHA3 is defined.
115188 The info parameter provides domain separation for multiple keys.
116189 Requires HAVE_HKDF.
190+ For hardware PUF (WOLFSSL_HWPUF), derives key from the key code previously
191+ generated. If the key was originally generated with key index 0, then the
192+ derived key is sent directly to the hardware bus, and key buffer will be
193+ zeroed.
117194
118195 \return 0 on success
119196 \return BAD_FUNC_ARG if ctx or key is NULL, or keySz is 0
120- \return PUF_DERIVE_KEY_E if PUF not ready or HKDF fails
197+ \return PUF_DERIVE_KEY_E if PUF not ready or key derivation fails
121198
122199 \param ctx pointer to wc_PufCtx (must be enrolled or reconstructed)
123- \param info optional context info for domain separation (may be NULL;
124- when NULL, infoSz is treated as 0)
200+ \param info For software PUF (WOLFSSL_PUF), this is optional context info
201+ for domain separation (may be NULL; when NULL, infoSz is treated as 0).
202+ For hardware PUF (WOLFSSL_HWPUF), this is the key code returned when the
203+ key was generated.
125204 \param infoSz size of info in bytes
126205 \param key output buffer for derived key
127206 \param keySz desired key size in bytes
@@ -135,6 +214,7 @@ int wc_PufReconstruct(wc_PufCtx* ctx, const byte* helperData, word32 helperSz);
135214
136215 \sa wc_PufEnroll
137216 \sa wc_PufReconstruct
217+ \sa wc_PufGenerateKey
138218 \sa wc_PufGetIdentity
139219*/
140220int wc_PufDeriveKey (wc_PufCtx * ctx , const byte * info , word32 infoSz ,
@@ -145,6 +225,8 @@ int wc_PufDeriveKey(wc_PufCtx* ctx, const byte* info, word32 infoSz,
145225
146226 \brief Retrieve the device identity hash (SHA-256 or SHA3-256 of stable
147227 bits). Deterministic for a given device.
228+ This function is valid for software PUF (WOLFSSL_PUF), but invalid for
229+ hardware PUF (WOLFSSL_HWPUF).
148230
149231 \return 0 on success
150232 \return BAD_FUNC_ARG if ctx or id is NULL
@@ -191,6 +273,8 @@ int wc_PufZeroize(wc_PufCtx* ctx);
191273
192274 \brief Inject synthetic SRAM test data for testing without hardware.
193275 Only available when WOLFSSL_PUF_TEST is defined.
276+ This function is valid for software PUF (WOLFSSL_PUF), but invalid for
277+ hardware PUF (WOLFSSL_HWPUF).
194278
195279 \return 0 on success
196280 \return BAD_FUNC_ARG if ctx or data is NULL
0 commit comments