Algo examples - #610
Conversation
Key generation, signing and verification for all SHAKE and SHA2 parameter sets, with corrupted-signature rejection.
wolfCrypt-level ShangMi examples: SM3 hash (GB/T 32905 known answer), SM4-GCM with tamper detection, SM2 sign/verify including the ZA digest step, and SM2 ECDH. Requires the wolfSSL/wolfsm overlay.
Incremental hashing checked against the RFC 7693 known-answer vectors, plus BLAKE2b's native keyed mode used as a MAC.
SipHash-2-4 one-shot 64/128-bit MACs and the incremental API, checked against the reference implementation's test vector.
HKDF (RFC 5869), PBKDF2 (RFC 2898) and scrypt (RFC 7914), each verified against its RFC known-answer test vector.
One KEM encapsulation protecting an ordered message sequence via wc_HpkeInitSealContext()/wc_HpkeContextSealBase() and the open equivalents, with out-of-order rejection.
Full exchange (enrollment through mutual proof verification) using SHA-256 and the RFC 5054 2048-bit group.
Identity-based key exchange per RFC 6507-6509: KMS provisions user key material, ECCSI signs the SAKKE-encapsulated SSV, receiver verifies and derives the shared secret.
Add check entries for slh_dsa, blake2, siphash, kdf and mikey-sakke; extend the crypto, pq and pk profiles with their configure flags. crypto/sm is a documented skip: it needs the wolfsm overlay patched into the wolfSSL tree before configure.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #610
Scan targets checked: wolfssl-examples-bugs, wolfssl-examples-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Findings are non-blocking.
dgarske
left a comment
There was a problem hiding this comment.
Add the 15 new binaries to .gitignore,
| ret = wc_SlhDsaKey_Init(&pubKey, param, NULL, INVALID_DEVID); | ||
| if (ret != 0) goto exit; | ||
| /* - only have pub key - */ | ||
| wc_SlhDsaKey_ImportPublic(&pubKey, pub, pubLen); |
There was a problem hiding this comment.
Why was the return code not captured in this example?
| path: crypto/sm | ||
| mode: skip | ||
| reason: >- | ||
| SM2/SM3/SM4 live in the separate wolfSSL/wolfsm overlay, which must be |
There was a problem hiding this comment.
Let's make the test clone it and test it. Thanks
| /* - Get Sender Public Validation Token - */ | ||
|
|
||
| /* - Verify the Message - */ | ||
| ret = wc_HashEccsiId(&Bob.publicKeyEccsi, WC_HASH_TYPE_SHA256, |
There was a problem hiding this comment.
MIKEY-SAKKE Message struct omits the length fields the receiver needs, so Bob reaches for the sender's compile-time constants
Recommendation: Add senderIdSz and ssvSz to Message and have Bob read both from there, and bound the memcpy into Message.senderId against sizeof(Message.senderId).
| /* - Get Sender Public Validation Token - */ | ||
| ret = wc_DecodeEccsiPvtFromSig(&Bob.publicKeyEccsi, | ||
| Message.signature, Message.signatureSz, senderPvt); | ||
| if (ret != 0) {printf("Could not Decode Pvt."); goto BobFail;} |
There was a problem hiding this comment.
Make sure printfs have \n. I really don't like the squashed single line. If its too verbose use a macro or local static function to help.
| /* - Get The Shared secret value out of the Message - */ | ||
|
|
||
| /* - Error - */ | ||
| if (0) { |
There was a problem hiding this comment.
Can we avoid if (0) dead code here??
| WC_RNG rng; | ||
| int rngInit = 0; | ||
| byte* sig = NULL; | ||
| byte pub[64]; |
There was a problem hiding this comment.
Use WC_SLHDSA_MAX_PUB_LEN from wc_slhdsa.h instead of the literal 64.
| int secretSigningKeyInit; | ||
| ecc_point* publicValidationToken; | ||
| ecc_point* receiverSecretKey; | ||
| byte dirived_sharedSecretValue[SSV_SZ]; /* plaintext SSV (Bob's copy) */ |
There was a problem hiding this comment.
Fix all spelling errors for dirived_ -> derived_
|
|
||
| #if defined(WOLFCRYPT_HAVE_ECCSI) && defined(WOLFCRYPT_HAVE_SAKKE) | ||
|
|
||
| #define SSV_SZ 16 |
There was a problem hiding this comment.
AUTH_SZ 257, ECCSI_SIG_SZ 129, ECCSI_PUB_KEY_SZ (32 * 2) and SAKKE_PUB_KEY_SZ (128 * 2) are all hand-derived from the parameter sets. I verified each against wolfSSL: 257 = 1 + 2128 for the SAKKE 1024-bit encapsulated point, 129 = 432+1 which is exactly what wc_SignEccsiHash() bounds-checks, and the two raw public-key sizes match what wc_ExportEccsiPublicKey/wc_ExportSakkePublicKey require with raw=1. So all four are correct today. But sakke.h exports wc_GetSakkeAuthSize(SakkeKey* key, word16* authSz) for precisely the first of these, and using it would make the example self-describing and immune to a parameter-set change.
Recommendation: Use wc_GetSakkeAuthSize() to set Message.authSz, and add a short comment next to the remaining constants noting which parameter set they are derived from.
| CFLAGS=-Wall -I$(WOLFSSL_INSTALL_DIR)/include | ||
| LIBS=-L$(WOLFSSL_INSTALL_DIR)/lib -lwolfssl -lm | ||
|
|
||
| siphash-mac: siphash-mac.o |
There was a problem hiding this comment.
Recommendation: Add all: targets to crypto/siphash/Makefile and pk/mikey-sakke/Makefile and list all in .PHONY, matching the other Makefiles in this PR.
| if (ret != 0) | ||
| printf("error %d: %s\n", ret, wc_GetErrorString(ret)); | ||
|
|
||
| if (Bob.receiverSecretKey != NULL) |
There was a problem hiding this comment.
Let's also wipe sharedSecretValue values for Alice and Bob.
New Examples
Revisions on the AI generated examples
Changed the peer to peer/ client server examples to represent the different actors as structs ie. Alice struct and Bob struct to show how data moves and what information is used for each task.
Also added comments to spell out each step using boxing style for the more complex examples
Example: