Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .github/actions/setup-wolfssl/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ inputs:
description: 'extra CFLAGS for this profile'
required: false
default: ''
overlay:
description: >-
source overlay to install into the wolfSSL tree before configure, as
"name@branchOrTag" or if you want just the latest on master of a repo
just set "name" (currently only supports "wolfsm"). Some algorithm
families ship outside the wolfSSL repo and cannot be reached by any
configure flag alone, so the patch has to happen here -- this is the
only step that holds the wolfSSL source tree.
required: false
default: ''

outputs:
sha256:
Expand Down Expand Up @@ -50,7 +60,11 @@ runs:
id: cfg
shell: bash
run: |
printf '%s|%s' '${{ inputs.flags }}' '${{ inputs.cflags }}' \
# overlay is in the hash: an SM build and a plain build of the same ref
# and flags are different libraries, and sharing a key would serve one
# for the other.
printf '%s|%s|%s' '${{ inputs.flags }}' '${{ inputs.cflags }}' \
'${{ inputs.overlay }}' \
| sha256sum | cut -c1-16 | sed 's/^/hash=/' >> "$GITHUB_OUTPUT"

# Key on the image, not runner.os: a binary built against a newer glibc must
Expand Down Expand Up @@ -81,6 +95,32 @@ runs:
git init -q
git fetch -q --depth 1 https://github.com/wolfSSL/wolfssl.git ${{ steps.resolve.outputs.sha }}
git checkout -q FETCH_HEAD

# Before autogen, not after: install.sh drops sources and m4 into the
# tree, and configure only grows --enable-sm2/sm3/sm4-* once they are
# there.
overlay='${{ inputs.overlay }}'
if [ -n "$overlay" ]; then
repoName="${overlay%%@*}"
if [ "$overlay" = "$repoName" ]; then
# default to latest on master
branchOrTag="HEAD"
else
branchOrTag="${overlay#*@}"
fi
case "$repoName" in
wolfsm) url=https://github.com/wolfSSL/wolfsm.git ;;
# add more cases here as they come up!
*) echo "unknown overlay '$repoName'"; exit 1 ;;
esac
rm -rf "/tmp/$repoName" && mkdir -p "/tmp/$repoName"
git -C "/tmp/$repoName" init -q
git -C "/tmp/$repoName" fetch -q --depth 1 "$url" "$branchOrTag"
git -C "/tmp/$repoName" checkout -q FETCH_HEAD
echo "installing $repoName@$branchOrTag into the wolfSSL tree"
( cd "/tmp/$repoName" && ./install.sh /tmp/wolfssl )
fi

./autogen.sh
# We need the library, not wolfSSL's own examples and test suite. Those
# also fail to build under some profiles (the `tls` profile died on
Expand Down
50 changes: 46 additions & 4 deletions .github/examples-manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,33 @@ profiles:
flags: "--enable-opensslall --enable-opensslextra --enable-static --enable-shared"

crypto:
# union of crypto/*: 3des, aes, aes-modes, camellia, ascon, keywrap, pkcs12
# union of crypto/* and hash/*: 3des, aes, aes-modes, camellia, ascon,
# keywrap, kdf, pkcs12, siphash, blake2
flags: >-
--enable-pwdbased --enable-des3 --enable-camellia --enable-ascon
--enable-experimental --enable-aesgcm-stream --enable-aesccm --enable-aesctr
--enable-aescfb --enable-aesofb --enable-aeseax --enable-aessiv
--enable-aesxts --enable-aeskeywrap --enable-keygen --enable-certgen
--enable-certext --enable-pkcs12 --enable-static --enable-shared
--enable-certext --enable-pkcs12 --enable-blake2 --enable-blake2s
--enable-siphash --enable-hkdf --enable-scrypt
--enable-static --enable-shared
# aes-cts and aes-ecb have no configure flag: without these defines both
# compile to a stub main() that prints "not compiled in" and returns 0.
# WC_RNG_SEED_CB likewise has no --enable of its own (only opensslextra and
# the FIPS paths set it), and aes/rdseed exits 1 with "requires __x86_64__
# and WC_RNG_SEED_CB" without it.
cflags: "-DWOLFSSL_AES_CTS -DHAVE_AES_ECB -DWC_RNG_SEED_CB"

sm:
# crypto/sm/README: SM2/SM3/SM4 ship in the wolfSSL/wolfsm overlay, not in
# wolfSSL itself, so these --enable flags do not exist until install.sh has
# run against the source tree. setup-wolfssl applies the overlay before
# autogen; nothing in an example's own build can reach that far back.
# Bare name means latest on wolfsm's master: the repo publishes no tags and
# has no other branch, so there is nothing to pin to short of a raw commit.
overlay: wolfsm
flags: "--enable-sm2 --enable-sm3 --enable-sm4-gcm --enable-static --enable-shared"

certgen:
flags: >-
--enable-certgen --enable-certreq --enable-certext --enable-keygen
Expand All @@ -87,7 +100,7 @@ profiles:
flags: >-
--enable-ecc --enable-ed25519 --enable-ed448 --enable-curve25519
--enable-curve448 --enable-keygen --enable-rsapss --enable-srp --enable-hpke
--enable-aesgcm --enable-static --enable-shared
--enable-aesgcm --enable-eccsi --enable-sakke --enable-static --enable-shared
# WOLFSSL_RSA_KEY_CHECK has no configure option: pk/rsa-kg calls
# wc_CheckRsaKey, which rsa.c only defines under that macro.
cflags: "-DWOLFSSL_PUBLIC_MP -DUSE_CERT_BUFFERS_2048 -DWOLFSSL_ECDSA_DETERMINISTIC_K -DWOLFSSL_RSA_KEY_CHECK"
Expand Down Expand Up @@ -146,7 +159,7 @@ profiles:
# so without it the client dies on "failed to set the requested group".
flags: >-
--enable-mlkem --enable-dilithium --enable-lms --enable-xmss
--enable-extra-pqc-hybrids
--enable-extra-pqc-hybrids --enable-slhdsa=yes,sha2
--enable-experimental --enable-tls13 --enable-static --enable-shared

acert:
Expand Down Expand Up @@ -345,6 +358,11 @@ examples:
# openssl dgst, so these assert the algorithm is right, not just that it ran.
# input.txt is tracked -- if it changes on purpose, recompute these.

- id: hash-blake2
path: hash/blake2
profile: crypto
mode: check

- id: embedded
path: embedded
profile: default
Expand Down Expand Up @@ -405,6 +423,11 @@ examples:
profile: crypto
mode: check

- id: crypto-kdf
path: crypto/kdf
profile: crypto
mode: check

- id: crypto-keywrap
path: crypto/keywrap
profile: crypto
Expand All @@ -415,6 +438,16 @@ examples:
profile: crypto
mode: check

- id: crypto-siphash
path: crypto/siphash
profile: crypto
mode: check

- id: crypto-sm
path: crypto/sm
profile: sm
mode: check

- id: signature
path: signature
profile: default
Expand Down Expand Up @@ -590,6 +623,11 @@ examples:
profile: pq
mode: check

- id: pq-slh-dsa
path: pq/slh_dsa
profile: pq
mode: check

- id: pq-stateful-hash-sig
path: pq/stateful_hash_sig
profile: pq
Expand Down Expand Up @@ -742,6 +780,10 @@ examples:
path: pk/hpke
profile: pk
mode: check
- id: pk-mikey-sakke
path: pk/mikey-sakke
profile: pk
mode: check
- id: pk-rsa-kg
path: pk/rsa-kg
profile: pk
Expand Down
16 changes: 16 additions & 0 deletions .github/scripts/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def load(path=MANIFEST):

def validate(data):
profiles = data.get("profiles") or {}
# Matches the `overlay` input of .github/actions/setup-wolfssl: either a
# bare repo name (latest on master) or "name@branchOrTagOrCommit". The
# action resolves the name to a URL, so an unknown one fails there, not here.
for name, p in profiles.items():
overlay = (p or {}).get("overlay")
if overlay and not re.fullmatch(r"[a-z0-9-]+(@[^\s@]+)?", overlay):
sys.exit(
f"manifest: profile '{name}': overlay must be 'name' or "
f"'name@branchOrTagOrCommit', got '{overlay}'"
)
seen = set()
for e in data.get("examples") or []:
for key in ("id", "path"):
Expand Down Expand Up @@ -309,6 +319,9 @@ def cmd_matrix(data, refs, tier, shas=None):
"wolfssl_sha": pinned.get(ref, ref),
"flags": " ".join(p.get("flags", "").split()),
"cflags": p.get("cflags", ""),
# a source overlay the profile needs patched into the wolfSSL
# tree before configure (setup-wolfssl applies it)
"overlay": p.get("overlay", ""),
"deps": " ".join(e.get("deps") or []),
}
)
Expand All @@ -335,6 +348,7 @@ def cmd_wolfssl_matrix(data, refs, tier, shas=None):
"wolfssl_sha": pinned.get(ref, ref),
"flags": " ".join(data["profiles"][name].get("flags", "").split()),
"cflags": data["profiles"][name].get("cflags", ""),
"overlay": data["profiles"][name].get("overlay", ""),
}
for name in profiles
for ref in refs
Expand All @@ -355,6 +369,7 @@ def cmd_wolfssl_matrix(data, refs, tier, shas=None):
data["profiles"][e["profile"]].get("flags", "").split()
),
"cflags": data["profiles"][e["profile"]].get("cflags", ""),
"overlay": data["profiles"][e["profile"]].get("overlay", ""),
}
)
print(json.dumps(out))
Expand Down Expand Up @@ -393,6 +408,7 @@ def cmd_profiles(data):
"profile": name,
"flags": data["profiles"][name].get("flags", "").strip(),
"cflags": data["profiles"][name].get("cflags", ""),
"overlay": data["profiles"][name].get("overlay", ""),
}
for name in sorted(used)
]
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
ref: ${{ matrix.wolfssl_sha }}
flags: ${{ matrix.flags }}
cflags: ${{ matrix.cflags }}
overlay: ${{ matrix.overlay }}

# One job per example, so a red tile names the example that broke.
examples:
Expand Down Expand Up @@ -138,6 +139,7 @@ jobs:
ref: ${{ matrix.wolfssl_sha }}
flags: ${{ matrix.flags }}
cflags: ${{ matrix.cflags }}
overlay: ${{ matrix.overlay }}

# Probe the exact netns invocation: --map-root-user is the part that fails
- name: Enable unprivileged user namespaces
Expand Down
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,20 @@ pq/ml_kem/ml_kem

# openssl ocsp -index writes this beside the index when it is missing
ocsp/stapling/responder-certs/index.txt.attr

# algorithm example executables
crypto/kdf/hkdf
crypto/kdf/pbkdf2
crypto/kdf/scrypt-kdf
crypto/siphash/siphash-mac
crypto/sm/sm2-ecdh
crypto/sm/sm2-sign-verify
crypto/sm/sm3-hash
crypto/sm/sm4-gcm-encrypt
hash/blake2/blake2-keyed-mac
hash/blake2/blake2b-hash
hash/blake2/blake2s-hash
pk/hpke/hpke_context
pk/mikey-sakke/mikey-sakke
pk/srp/srp_sha256
pq/slh_dsa/slh_dsa_test
26 changes: 26 additions & 0 deletions crypto/kdf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CC=gcc
WOLFSSL_INSTALL_DIR=/usr/local
CFLAGS=-Wall -I$(WOLFSSL_INSTALL_DIR)/include
LIBS=-L$(WOLFSSL_INSTALL_DIR)/lib -lwolfssl -lm

all: hkdf pbkdf2 scrypt-kdf

hkdf: hkdf.o
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

pbkdf2: pbkdf2.o
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

scrypt-kdf: scrypt-kdf.o
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean all check

clean:
rm -f *.o hkdf pbkdf2 scrypt-kdf

check: all
out=$$(./hkdf) && printf '%s' "$$out" | grep -q 'matches RFC 5869 Test Case 1'
out=$$(./pbkdf2) && printf '%s' "$$out" | grep -q 'matches RFC 7914 test vector'
out=$$(./scrypt-kdf) && printf '%s' "$$out" | grep -q 'matches RFC 7914 test vector'
@echo "PASS: crypto-kdf checks"
34 changes: 34 additions & 0 deletions crypto/kdf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# wolfSSL KDF Examples

Demonstrates the main wolfCrypt key derivation functions, each verified
against its RFC known-answer test vector.

* `hkdf.c` - HKDF (RFC 5869): extract-then-expand derivation from existing
keying material, shown both as separate `wc_HKDF_Extract()` /
`wc_HKDF_Expand()` steps and as the one-shot `wc_HKDF()`.
* `pbkdf2.c` - PBKDF2 (RFC 2898) via `wc_PBKDF2()`: deriving keys from
passwords with a salt and an iteration work factor.
* `scrypt-kdf.c` - scrypt (RFC 7914) via `wc_scrypt()`: memory-hard
password-based derivation for stronger resistance to GPU/ASIC attacks.

Use HKDF when the input is already a high-entropy secret (e.g. a DH shared
secret); use PBKDF2 or scrypt when the input is a password.

## Building wolfSSL

```
./configure --enable-hkdf --enable-scrypt
make
sudo make install
```

PBKDF2 is enabled by default (disabled only by `NO_PWDBASED`).

## Building and running the examples

```
make
./hkdf
./pbkdf2
./scrypt-kdf
```
Loading
Loading