Skip to content

Commit e077b08

Browse files
committed
Add AES-GCM DEM, CryptoCb support, and devId threading to ECIES
Add AES-GCM (128/256) as an ECIES DEM next to the AES-CBC/CTR+HMAC modes. Only the encryption key comes from the KDF; the mac salt is bound as GCM AAD and the 16-byte tag replaces the HMAC. The GCM DEM honors all three IV build modes, and default fixed-nonce GCM is gated behind the new WOLFSSL_ECIES_STATIC_GCM_NONCE opt-in. Adds ECIES CryptoCb encrypt/decrypt, the WOLF_CRYPTO_CB ctx getters, devId/heap threading into the DEM primitives, and test/benchmark/CI coverage.
1 parent 5d0da8e commit e077b08

11 files changed

Lines changed: 1559 additions & 85 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,21 @@ jobs:
266266
{"name": "cryptocb-aesgcm-setkey-free", "minutes": 2.1,
267267
"configure": ["--enable-cryptocb", "--enable-aesgcm",
268268
"CPPFLAGS=-DWOLF_CRYPTO_CB_AES_SETKEY -DWOLF_CRYPTO_CB_FREE"]},
269+
{"name": "ecies-sec1-gcm-static-nonce", "minutes": 2.0,
270+
"comment": "ECIES with the AES-GCM DEM in the default SEC1 IV mode; WOLFSSL_ECIES_STATIC_GCM_NONCE opts into the fixed-nonce GCM path so the GCM KAT/round-trip and cryptocb tests run.",
271+
"configure": ["--enable-eccencrypt", "--enable-aesgcm", "--enable-aesctr",
272+
"--enable-x963kdf", "--enable-cryptocb", "--enable-keygen",
273+
"CPPFLAGS=-DWOLFSSL_ECIES_STATIC_GCM_NONCE"]},
274+
{"name": "ecies-geniv-gcm-static-nonce", "minutes": 2.0,
275+
"comment": "Same ECIES-GCM coverage in the WOLFSSL_ECIES_GEN_IV mode (random embedded nonce).",
276+
"configure": ["--enable-eccencrypt=geniv", "--enable-aesgcm", "--enable-aesctr",
277+
"--enable-x963kdf", "--enable-cryptocb", "--enable-keygen",
278+
"CPPFLAGS=-DWOLFSSL_ECIES_STATIC_GCM_NONCE"]},
279+
{"name": "ecies-old-gcm-static-nonce", "minutes": 2.0,
280+
"comment": "Same ECIES-GCM coverage in the legacy WOLFSSL_ECIES_OLD mode (KDF-derived nonce, no ephemeral pubkey prepended).",
281+
"configure": ["--enable-eccencrypt=old", "--enable-aesgcm", "--enable-aesctr",
282+
"--enable-x963kdf", "--enable-cryptocb", "--enable-keygen",
283+
"CPPFLAGS=-DWOLFSSL_ECIES_STATIC_GCM_NONCE"]},
269284
{"name": "opensslextra-x509small", "minutes": 2.0,
270285
"configure": ["--enable-opensslextra=x509small"]},
271286
{"name": "cryptocb-keygen-find", "minutes": 2.0,

doc/dox_comments/header_files/ecc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,6 +2025,11 @@ int wc_ecc_ctx_set_info(ecEncCtx* ctx, const byte* info, int sz);
20252025
\param ctx Optional: pointer to an ecEncCtx object specifying different
20262026
encryption algorithms to use
20272027
2028+
\note Selecting an AES-GCM DEM algorithm (ecAES_128_GCM, ecAES_256_GCM) in
2029+
the default IV mode requires the WOLFSSL_ECIES_STATIC_GCM_NONCE build macro;
2030+
otherwise this function returns NOT_COMPILED_IN. See wc_ecc_encrypt_ex for
2031+
the full rationale.
2032+
20282033
_Example_
20292034
\code
20302035
byte msg[] = { initialize with msg to encrypt. Ensure padded to block size };
@@ -2072,6 +2077,9 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
20722077
small to store the encrypted ciphertext
20732078
\return MEMORY_E Returned if there is an error allocating memory
20742079
for the shared secret key
2080+
\return NOT_COMPILED_IN Returned if an AES-GCM DEM algorithm
2081+
(ecAES_128_GCM or ecAES_256_GCM) is requested in the default IV mode
2082+
without the WOLFSSL_ECIES_STATIC_GCM_NONCE build macro defined
20752083
20762084
\param privKey pointer to the ecc_key object containing the
20772085
private key to use for encryption
@@ -2088,6 +2096,16 @@ int wc_ecc_encrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
20882096
encryption algorithms to use
20892097
\param compressed Public key field is to be output in compressed format.
20902098
2099+
\note The AES-GCM DEM algorithms (ecAES_128_GCM, ecAES_256_GCM) in the
2100+
default IV mode use a fixed all-zero GCM nonce. That is safe only because
2101+
ECIES derives a fresh symmetric key from a fresh ephemeral key on every
2102+
encryption, so the (key, nonce) pair never repeats; reusing the ephemeral
2103+
key is catastrophic for AES-GCM. For that reason the fixed-nonce GCM DEM is
2104+
off by default and must be enabled with the WOLFSSL_ECIES_STATIC_GCM_NONCE
2105+
build macro, otherwise this function returns NOT_COMPILED_IN for a GCM
2106+
algorithm. The macro is not needed with WOLFSSL_ECIES_GEN_IV (random
2107+
per-message nonce) or WOLFSSL_ECIES_OLD (nonce derived from the KDF output).
2108+
20912109
_Example_
20922110
\code
20932111
byte msg[] = { initialize with msg to encrypt. Ensure padded to block size };
@@ -2136,6 +2154,9 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
21362154
small to store the decrypted plaintext
21372155
\return MEMORY_E Returned if there is an error allocating memory
21382156
for the shared secret key
2157+
\return NOT_COMPILED_IN Returned if an AES-GCM DEM algorithm
2158+
(ecAES_128_GCM or ecAES_256_GCM) is requested in the default IV mode
2159+
without the WOLFSSL_ECIES_STATIC_GCM_NONCE build macro defined
21392160
21402161
\param privKey pointer to the ecc_key object containing the private
21412162
key to use for decryption
@@ -2150,6 +2171,11 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
21502171
\param ctx Optional: pointer to an ecEncCtx object specifying
21512172
different decryption algorithms to use
21522173
2174+
\note Selecting an AES-GCM DEM algorithm (ecAES_128_GCM, ecAES_256_GCM) in
2175+
the default IV mode requires the WOLFSSL_ECIES_STATIC_GCM_NONCE build macro;
2176+
otherwise this function returns NOT_COMPILED_IN. See wc_ecc_encrypt_ex for
2177+
the full rationale.
2178+
21532179
_Example_
21542180
\code
21552181
byte cipher[] = { initialize with

0 commit comments

Comments
 (0)