Skip to content
Open
14 changes: 14 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

## Behavioral Changes

* **Behavioral change (ECIES no longer takes its device from the key)**:
`wc_ecc_encrypt()`, `wc_ecc_encrypt_ex()` and `wc_ecc_decrypt()` used to read
the crypto callback device from `privKey->devId`. They now read it only from
the `ecEncCtx`, set with the new `wc_ecc_ctx_set_dev_id()`. A context that
was never given a device, or a NULL context, runs ECIES in software, even
when the key was opened with a device. This covers the whole-operation
callback and the KDF, cipher and MAC steps of the software path. ECDH is
not affected and still uses the key's device. Callers that relied on the
key's device for ECIES must call `wc_ecc_ctx_set_dev_id()` on each context.

* **Behavioral change (`wc_PufReadSram` health tests the raw SRAM readout)**:
the raw readout is now health tested before the context accepts it, and a
readout that cannot be SRAM power-on noise is rejected with `PUF_READ_E`
Expand Down Expand Up @@ -189,6 +199,10 @@

## New Features

* Added `wc_ecc_ctx_set_dev_id()` and `wc_ecc_ctx_get_dev_id()` (WOLF_CRYPTO_CB
builds) to pick the crypto callback device an ECIES context runs on. The
value is kept across `wc_ecc_ctx_reset()`.

* Added Argon2 (RFC 9106) password hashing with all three variants - Argon2d, Argon2i and Argon2id - via `--enable-argon2`. Only version 0x13 is implemented. Provides the one-shot `wc_Argon2()`/`wc_Argon2_ex()` and a reusable context API (`wc_Argon2Init`/`wc_Argon2SetParams`/`wc_Argon2DeriveTag`/`wc_Argon2Free`, plus `wc_Argon2New`/`wc_Argon2Delete` unless `WC_NO_CONSTRUCTORS`) that allocates the memory block array once for applications deriving many tags. `--enable-argon2-threads` fills the segments of a slice in parallel, which does not change the derived tag: the one-shot functions use a thread per lane, and the context API takes a count from `wc_Argon2SetThreads()`. by @SparkiDev

## Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
#define USE_CERT_BUFFERS_256
#define BENCH_EMBEDDED

/* Adds a second set of ECIES benchmark rows, tagged -kdf, set up the way the
* ASU needs (KDF salt and info, no MAC salt). Without it the only ECIES rows
* are the salt-exchange ones, which the port always turns down, so the
* benchmark would show no ECIES number that reaches the hardware. */
#define WC_BENCH_ECIES_KDF

/* Uncomment for a build with only wolfCrypt (no TLS layer). */
/* #define WOLFCRYPT_ONLY */

Expand Down
84 changes: 84 additions & 0 deletions doc/dox_comments/header_files/ecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,11 @@ void wc_ecc_ctx_free(ecEncCtx* ctx);
// do more secure communication
\endcode

\note The device id set with wc_ecc_ctx_set_dev_id() (WOLF_CRYPTO_CB
builds) is kept across the reset, like the heap hint.

\sa wc_ecc_ctx_new
\sa wc_ecc_ctx_set_dev_id
*/

int wc_ecc_ctx_reset(ecEncCtx* ctx, WC_RNG* rng); /* reset for use again w/o alloc/free */
Expand Down Expand Up @@ -1888,6 +1892,71 @@ int wc_ecc_ctx_reset(ecEncCtx* ctx, WC_RNG* rng); /* reset for use again w/o al
int wc_ecc_ctx_set_algo(ecEncCtx* ctx, byte encAlgo, byte kdfAlgo,
byte macAlgo);

/*!
\ingroup ECC

\brief This function picks the device that ECIES operations using this
context run on. Only available when WOLF_CRYPTO_CB is defined. A context
starts at INVALID_DEVID, meaning software: ECIES does not copy the
device from the private key, so this must be called for a crypto
callback to be reached. The value is used both for the whole-operation
ECIES callback and for the AES/HMAC steps of the software path. The KDF
step always runs in software.
Passing a NULL context to wc_ecc_encrypt() or wc_ecc_decrypt() always
means software. When WOLF_CRYPTO_CB_FIND is defined, an unset device id
still goes through the registered finder, as it does for every other
wolfCrypt operation. The setting is kept across wc_ecc_ctx_reset().

\return 0 Returned upon successfully setting the device id.
\return BAD_FUNC_ARG Returned if the given context is NULL.

\param ctx pointer to the ecEncCtx for which to set the device id
\param devId device id to use, or INVALID_DEVID for software

_Example_
\code
ecEncCtx* ctx = wc_ecc_ctx_new(REQ_RESP_CLIENT, &rng);
if (wc_ecc_ctx_set_dev_id(ctx, myDevId) != 0) {
// error setting device id
}
\endcode

\sa wc_ecc_ctx_get_dev_id
\sa wc_ecc_ctx_new
\sa wc_ecc_ctx_reset
*/

int wc_ecc_ctx_set_dev_id(ecEncCtx* ctx, int devId);

/*!
\ingroup ECC

\brief This function reads back the device id set with
wc_ecc_ctx_set_dev_id(). Crypto callback code can use it to learn which
device it was called for. Only available when WOLF_CRYPTO_CB is defined.
A context that was never given a device reads back INVALID_DEVID.

\return 0 Returned upon successfully reading the device id.
\return BAD_FUNC_ARG Returned if the given context or output pointer
is NULL.

\param ctx pointer to the ecEncCtx to read the device id from
\param devId pointer that receives the device id

_Example_
\code
int devId;
if (wc_ecc_ctx_get_dev_id(ctx, &devId) != 0) {
// error reading device id
}
\endcode

\sa wc_ecc_ctx_set_dev_id
\sa wc_ecc_ctx_new
*/

int wc_ecc_ctx_get_dev_id(ecEncCtx* ctx, int* devId);

/*!
\ingroup ECC

Expand Down Expand Up @@ -2088,8 +2157,13 @@ int wc_ecc_ctx_set_info(ecEncCtx* ctx, const byte* info, int sz);
}
\endcode

\note The device this runs on comes from the context
(wc_ecc_ctx_set_dev_id), not from privKey->devId. A NULL context, or one
that was never given a device, runs in software.

\sa wc_ecc_encrypt_ex
\sa wc_ecc_decrypt
\sa wc_ecc_ctx_set_dev_id
*/

int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
Expand Down Expand Up @@ -2165,8 +2239,13 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
\endcode

\note The device this runs on comes from the context
(wc_ecc_ctx_set_dev_id), not from privKey->devId. A NULL context, or one
that was never given a device, runs in software.

\sa wc_ecc_encrypt
\sa wc_ecc_decrypt
\sa wc_ecc_ctx_set_dev_id
*/

int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
Expand Down Expand Up @@ -2236,8 +2315,13 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
\endcode

\note The device this runs on comes from the context
(wc_ecc_ctx_set_dev_id), not from privKey->devId. A NULL context, or one
that was never given a device, runs in software.

\sa wc_ecc_encrypt
\sa wc_ecc_encrypt_ex
\sa wc_ecc_ctx_set_dev_id
*/

int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
Expand Down
Loading
Loading