Repository navigation
Add ML-KEM and ML-DSA crypto callback (cryptocb) examples #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| CC = gcc | ||
|
|
||
| WOLFSSL_INSTALL_DIR = /usr/local | ||
|
|
||
| WOLFSSL_CFLAGS = -Wextra -Werror -Wall -I$(WOLFSSL_INSTALL_DIR)/include | ||
| WOLFSSL_LIBS = -L$(WOLFSSL_INSTALL_DIR)/lib -lm -lwolfssl | ||
|
|
||
| DEBUG_FLAGS = -g -DDEBUG | ||
|
|
||
| all: ml_dsa_cryptocb | ||
|
|
||
| ml_dsa_cryptocb: ml_dsa_cryptocb.c | ||
| $(CC) -o $@ $^ $(WOLFSSL_CFLAGS) $(WOLFSSL_LIBS) $(DEBUG_FLAGS) | ||
|
|
||
| .PHONY: clean all check | ||
|
|
||
| clean: | ||
| rm -f *.o ml_dsa_cryptocb | ||
|
|
||
| check: ml_dsa_cryptocb | ||
| out=$$(./ml_dsa_cryptocb) && printf '%s' "$$out" | grep -q 'via crypto callback' | ||
| @echo "PASS: pq-ml-dsa-cryptocb checks" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Description | ||
|
|
||
| ML-DSA key generation, signing and verification routed through the wolfCrypt | ||
| crypto callback (cryptocb) interface. wolfSSL dispatches the signature | ||
| operations under `WC_ALGO_TYPE_PK` to a registered callback, which selects | ||
| ML-DSA with `WC_PQC_SIG_TYPE_MLDSA`. | ||
|
|
||
| The callback handles three operation types: | ||
|
|
||
| - `WC_PK_TYPE_PQC_SIG_KEYGEN` (`info->pk.pqc_sig_kg`) - generate a key pair. | ||
| - `WC_PK_TYPE_PQC_SIG_SIGN` (`info->pk.pqc_sign`) - sign a message. | ||
| - `WC_PK_TYPE_PQC_SIG_VERIFY` (`info->pk.pqc_verify`) - verify a signature. | ||
|
|
||
| The example signs and verifies with an empty context (FIPS 204 pure signing); | ||
| a pre-hash request falls back to software. The callback delegates back to the | ||
| wolfCrypt software implementation so it runs without hardware. A real device | ||
| replaces each case body with its own calls and keeps the private key on-chip. | ||
| It is registered with `wc_CryptoCb_RegisterDevice()`; for TLS, associate it | ||
| with a context using `wolfSSL_CTX_SetDevId()`. | ||
|
|
||
| Requires wolfSSL built with: | ||
|
|
||
| ```sh | ||
| $ ./autogen.sh | ||
| $ ./configure --enable-cryptocb --enable-dilithium | ||
| $ make | ||
| $ sudo make install | ||
| $ sudo ldconfig | ||
| ``` | ||
|
|
||
| Build the example: | ||
|
|
||
| ```sh | ||
| $ make | ||
| ``` | ||
|
|
||
| # Usage | ||
|
|
||
| ``` | ||
| $ ./ml_dsa_cryptocb | ||
| ``` | ||
|
|
||
| The ML-DSA key is initialized with a callback device id, so key generation, | ||
| signing and verification all dispatch to the callback. The program prints the | ||
| per-operation callback counts and confirms the signature verified. | ||
|
|
||
| # Related examples | ||
|
|
||
| - `pq/ml_kem_cryptocb` / `pq/tls_cryptocb` - the ML-KEM key-exchange counterpart, | ||
| standalone and in TLS 1.3. | ||
| - `pq/ml_dsa` - the same ML-DSA sign/verify in software, without a crypto callback. | ||
| - `ccb_vaultic` - a real secure-element crypto callback (SealSQ VaultIC). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.