Skip to content

Algo examples - #610

Open
aidankeefe2022 wants to merge 16 commits into
wolfSSL:masterfrom
aidankeefe2022:algo_examples
Open

Algo examples#610
aidankeefe2022 wants to merge 16 commits into
wolfSSL:masterfrom
aidankeefe2022:algo_examples

Conversation

@aidankeefe2022

@aidankeefe2022 aidankeefe2022 commented Jul 29, 2026

Copy link
Copy Markdown
Member

New Examples

  • SLH-DSA
  • SM2/SM3/SM4
  • Blake2b/Blake2s
  • KDF
  • HPKE seal/open example
  • SRP-6a SHA-256 example
  • ECCSI + SAKKE example

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:

/* --- Thing is happening --- *
{
      Thing happens
}
/* ---Thing is happening --- */

anhu and others added 15 commits July 29, 2026 13:38
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.
@aidankeefe2022 aidankeefe2022 self-assigned this Jul 29, 2026
@aidankeefe2022
aidankeefe2022 marked this pull request as ready for review July 30, 2026 16:30

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pq/slh_dsa/slh_dsa.c Outdated
Comment thread hash/blake2/blake2-keyed-mac.c
Comment thread pk/srp/srp_sha256.c
@dgarske
dgarske self-requested a review August 6, 2026 22:43

@dgarske dgarske left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the 15 new binaries to .gitignore,

Comment thread pq/slh_dsa/slh_dsa.c
ret = wc_SlhDsaKey_Init(&pubKey, param, NULL, INVALID_DEVID);
if (ret != 0) goto exit;
/* - only have pub key - */
wc_SlhDsaKey_ImportPublic(&pubKey, pub, pubLen);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid if (0) dead code here??

Comment thread pq/slh_dsa/slh_dsa.c
WC_RNG rng;
int rngInit = 0;
byte* sig = NULL;
byte pub[64];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix all spelling errors for dirived_ -> derived_


#if defined(WOLFCRYPT_HAVE_ECCSI) && defined(WOLFCRYPT_HAVE_SAKKE)

#define SSV_SZ 16

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crypto/siphash/Makefile
CFLAGS=-Wall -I$(WOLFSSL_INSTALL_DIR)/include
LIBS=-L$(WOLFSSL_INSTALL_DIR)/lib -lwolfssl -lm

siphash-mac: siphash-mac.o

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also wipe sharedSecretValue values for Alice and Bob.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants