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
26 changes: 8 additions & 18 deletions BIBLIOGRAPHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ source code and documentation.
- National Institute of Standards and Technology
* URL: https://csrc.nist.gov/projects/cryptographic-module-validation-program/fips-140-3-ig-announcements
* Referenced from:
- [examples/bring_your_own_fips202/mldsa_native/src/config.h](examples/bring_your_own_fips202/mldsa_native/src/config.h)
- [examples/bring_your_own_fips202/mldsa_native/src/sign.c](examples/bring_your_own_fips202/mldsa_native/src/sign.c)
- [examples/monolithic_build/config_44.h](examples/monolithic_build/config_44.h)
- [examples/monolithic_build/config_65.h](examples/monolithic_build/config_65.h)
- [examples/monolithic_build/config_87.h](examples/monolithic_build/config_87.h)
- [examples/monolithic_build_multilevel/multilevel_config.h](examples/monolithic_build_multilevel/multilevel_config.h)
- [integration/liboqs/config_aarch64.h](integration/liboqs/config_aarch64.h)
- [integration/liboqs/config_c.h](integration/liboqs/config_c.h)
- [integration/liboqs/config_x86_64.h](integration/liboqs/config_x86_64.h)
Expand Down Expand Up @@ -47,16 +49,10 @@ source code and documentation.
* URL: https://csrc.nist.gov/pubs/fips/204/final
* Referenced from:
- [README.md](README.md)
- [examples/bring_your_own_fips202/mldsa_native/mldsa_native.h](examples/bring_your_own_fips202/mldsa_native/mldsa_native.h)
- [examples/bring_your_own_fips202/mldsa_native/src/config.h](examples/bring_your_own_fips202/mldsa_native/src/config.h)
- [examples/bring_your_own_fips202/mldsa_native/src/ct.h](examples/bring_your_own_fips202/mldsa_native/src/ct.h)
- [examples/bring_your_own_fips202/mldsa_native/src/ntt.h](examples/bring_your_own_fips202/mldsa_native/src/ntt.h)
- [examples/bring_your_own_fips202/mldsa_native/src/poly.c](examples/bring_your_own_fips202/mldsa_native/src/poly.c)
- [examples/bring_your_own_fips202/mldsa_native/src/poly_kl.c](examples/bring_your_own_fips202/mldsa_native/src/poly_kl.c)
- [examples/bring_your_own_fips202/mldsa_native/src/polyvec.c](examples/bring_your_own_fips202/mldsa_native/src/polyvec.c)
- [examples/bring_your_own_fips202/mldsa_native/src/rounding.h](examples/bring_your_own_fips202/mldsa_native/src/rounding.h)
- [examples/bring_your_own_fips202/mldsa_native/src/sign.c](examples/bring_your_own_fips202/mldsa_native/src/sign.c)
- [examples/bring_your_own_fips202/mldsa_native/src/sign.h](examples/bring_your_own_fips202/mldsa_native/src/sign.h)
- [examples/monolithic_build/config_44.h](examples/monolithic_build/config_44.h)
- [examples/monolithic_build/config_65.h](examples/monolithic_build/config_65.h)
- [examples/monolithic_build/config_87.h](examples/monolithic_build/config_87.h)
- [examples/monolithic_build_multilevel/multilevel_config.h](examples/monolithic_build_multilevel/multilevel_config.h)
- [mldsa/mldsa_native.h](mldsa/mldsa_native.h)
- [mldsa/src/config.h](mldsa/src/config.h)
- [mldsa/src/ct.h](mldsa/src/ct.h)
Expand Down Expand Up @@ -159,9 +155,6 @@ source code and documentation.
* URL: https://github.com/pq-crystals/dilithium/tree/master/ref
* Referenced from:
- [README.md](README.md)
- [examples/bring_your_own_fips202/mldsa_native/src/ntt.c](examples/bring_your_own_fips202/mldsa_native/src/ntt.c)
- [examples/bring_your_own_fips202/mldsa_native/src/poly.c](examples/bring_your_own_fips202/mldsa_native/src/poly.c)
- [examples/bring_your_own_fips202/mldsa_native/src/poly_kl.c](examples/bring_your_own_fips202/mldsa_native/src/poly_kl.c)
- [mldsa/src/ntt.c](mldsa/src/ntt.c)
- [mldsa/src/poly.c](mldsa/src/poly.c)
- [mldsa/src/poly_kl.c](mldsa/src/poly_kl.c)
Expand Down Expand Up @@ -237,7 +230,6 @@ source code and documentation.
- Damien Stehlé
* URL: https://pq-crystals.org/dilithium/data/dilithium-specification-round3-20210208.pdf
* Referenced from:
- [examples/bring_your_own_fips202/mldsa_native/src/sign.c](examples/bring_your_own_fips202/mldsa_native/src/sign.c)
- [mldsa/src/sign.c](mldsa/src/sign.c)

### `SLOTHY_Paper`
Expand All @@ -263,7 +255,6 @@ source code and documentation.
- Tung Chou
* URL: https://lib.mceliece.org/
* Referenced from:
- [examples/bring_your_own_fips202/mldsa_native/src/ct.h](examples/bring_your_own_fips202/mldsa_native/src/ct.h)
- [mldsa/src/ct.h](mldsa/src/ct.h)

### `m1cycles`
Expand Down Expand Up @@ -296,7 +287,6 @@ source code and documentation.
- Daniel J. Bernstein
* URL: https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/hqbtIGFKIpU/m/H14H0wOlBgAJ
* Referenced from:
- [examples/bring_your_own_fips202/mldsa_native/src/ct.h](examples/bring_your_own_fips202/mldsa_native/src/ct.h)
- [mldsa/src/ct.h](mldsa/src/ct.h)

### `supercop`
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,7 @@ run_size: \
clean:
-$(RM) -rf *.gcno *.gcda *.lcov *.o *.so
-$(RM) -rf $(BUILD_DIR)
-make clean -C examples/bring_your_own_fips202 >/dev/null
-make clean -C examples/basic >/dev/null
-make clean -C examples/monolithic_build >/dev/null
-make clean -C examples/monolithic_build_multilevel >/dev/null
8 changes: 4 additions & 4 deletions examples/basic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ endif
# Alternatively, you can compile the 'monobuild' source file mldsa_native.c.
# See examples/monolithic_build for that.
MLD_SOURCE=$(wildcard \
mldsa_native/mldsa/*.c \
mldsa_native/mldsa/**/*.c \
mldsa_native/mldsa/**/**/*.c \
mldsa_native/mldsa/**/**/**/*.c)
mldsa_native/mldsa/src/*.c \
mldsa_native/mldsa/src/**/*.c \
mldsa_native/mldsa/src/**/**/*.c \
mldsa_native/mldsa/src/**/**/**/*.c)

INC=-Imldsa_native/mldsa/

Expand Down
6 changes: 3 additions & 3 deletions examples/basic/expected_signatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* The PCT modifies the PRNG state, so the KAT tests don't work.
* We run KAT tests only for disabled PCT. */
#if !defined(MLD_CONFIG_KEYGEN_PCT)
#if MLD_CONFIG_PARAMETER_SET == 44
#if MLD_CONFIG_API_PARAMETER_SET == 44
const uint8_t expected_signature[] = {
0x27, 0x5e, 0xbe, 0x2d, 0x23, 0x1a, 0x76, 0xc5, 0xd9, 0x77, 0xcb, 0x62,
0x25, 0x04, 0xdb, 0x23, 0x31, 0xa9, 0xa8, 0xcd, 0xbc, 0xde, 0xf2, 0x20,
Expand Down Expand Up @@ -219,7 +219,7 @@ const uint8_t expected_signature[] = {
0x1f, 0x24, 0x38, 0x41, 0x45, 0x54, 0x5f, 0x69, 0x85, 0x8d, 0x93, 0x9e,
0xc5, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x16, 0x25, 0x32, 0x42};
#elif MLD_CONFIG_PARAMETER_SET == 65
#elif MLD_CONFIG_API_PARAMETER_SET == 65
const uint8_t expected_signature[] = {
0x8b, 0x6f, 0x79, 0x00, 0xcc, 0x79, 0x57, 0xee, 0x16, 0x86, 0x87, 0xd5,
0xcf, 0xb6, 0x90, 0x2c, 0xc6, 0x30, 0xeb, 0x8d, 0x39, 0xae, 0x9b, 0xf1,
Expand Down Expand Up @@ -497,7 +497,7 @@ const uint8_t expected_signature[] = {
0xdf, 0x0e, 0x1a, 0x20, 0x50, 0xf5, 0x02, 0x21, 0x30, 0x35, 0x3c, 0x60,
0x71, 0xad, 0xd0, 0xe3, 0xed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x10, 0x17, 0x1d, 0x22, 0x2d};
#elif MLD_CONFIG_PARAMETER_SET == 87
#elif MLD_CONFIG_API_PARAMETER_SET == 87
const uint8_t expected_signature[] = {
0xdf, 0xe6, 0xe1, 0xa5, 0x20, 0xc1, 0xac, 0x98, 0x55, 0x2c, 0xf2, 0x13,
0x65, 0x42, 0xe2, 0xb0, 0x77, 0x5f, 0x15, 0x00, 0x8f, 0x14, 0x48, 0xa1,
Expand Down
31 changes: 17 additions & 14 deletions examples/basic/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
} \
} while (0)

#define TEST_MSG \
"This is a test message for ML-DSA digital signature algorithm!"
#define TEST_MSG_LEN (sizeof(TEST_MSG) - 1)

int main(void)
{
const char *test_msg =
"This is a test message for ML-DSA digital signature algorithm!";
const char test_msg[] = TEST_MSG;
const char *test_ctx = "test_context_123";
size_t msglen = strlen(test_msg);
size_t ctxlen = strlen(test_ctx);

uint8_t pk[CRYPTO_PUBLICKEYBYTES];
uint8_t sk[CRYPTO_SECRETKEYBYTES];
uint8_t sig[CRYPTO_BYTES];
uint8_t sm[msglen + CRYPTO_BYTES]; /* signed message buffer */
uint8_t m2[msglen]; /* recovered message buffer */
uint8_t sm[TEST_MSG_LEN + CRYPTO_BYTES]; /* signed message buffer */
uint8_t m2[TEST_MSG_LEN + CRYPTO_BYTES]; /* recovered message buffer */
size_t siglen;
size_t smlen;
size_t mlen;
Expand All @@ -67,21 +69,22 @@ int main(void)
printf("Signing message... ");

/* Alice signs the message */
CHECK(crypto_sign_signature(sig, &siglen, (const uint8_t *)test_msg, msglen,
(const uint8_t *)test_ctx, ctxlen, sk) == 0);
CHECK(crypto_sign_signature(sig, &siglen, (const uint8_t *)test_msg,
TEST_MSG_LEN, (const uint8_t *)test_ctx, ctxlen,
sk) == 0);

printf("DONE\n");
printf("Verifying signature... ");

/* Bob verifies Alice's signature */
CHECK(crypto_sign_verify(sig, siglen, (const uint8_t *)test_msg, msglen,
CHECK(crypto_sign_verify(sig, siglen, (const uint8_t *)test_msg, TEST_MSG_LEN,
(const uint8_t *)test_ctx, ctxlen, pk) == 0);

printf("DONE\n");
printf("Creating signed message... ");

/* Alternative API: Create a signed message (signature + message combined) */
CHECK(crypto_sign(sm, &smlen, (const uint8_t *)test_msg, msglen,
CHECK(crypto_sign(sm, &smlen, (const uint8_t *)test_msg, TEST_MSG_LEN,
(const uint8_t *)test_ctx, ctxlen, sk) == 0);

printf("DONE\n");
Expand All @@ -95,8 +98,8 @@ int main(void)
printf("Compare messages... ");

/* Verify the recovered message matches the original */
CHECK(mlen == msglen);
CHECK(memcmp(test_msg, m2, msglen) == 0);
CHECK(mlen == TEST_MSG_LEN);
CHECK(memcmp(test_msg, m2, TEST_MSG_LEN) == 0);

printf("DONE\n\n");

Expand All @@ -105,9 +108,9 @@ int main(void)
printf("Public key size: %d bytes\n", CRYPTO_PUBLICKEYBYTES);
printf("Secret key size: %d bytes\n", CRYPTO_SECRETKEYBYTES);
printf("Signature size: %d bytes\n", CRYPTO_BYTES);
printf("Message length: %zu bytes\n", msglen);
printf("Signature length: %zu bytes\n", siglen);
printf("Signed msg length: %zu bytes\n", smlen);
printf("Message length: %lu bytes\n", TEST_MSG_LEN);
printf("Signature length: %lu bytes\n", (unsigned long)siglen);
printf("Signed msg length: %lu bytes\n", (unsigned long)smlen);

#if !defined(MLD_CONFIG_KEYGEN_PCT)
/* Check against expected signature to make sure that
Expand Down
31 changes: 17 additions & 14 deletions examples/bring_your_own_fips202/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@
} \
} while (0)

#define TEST_MSG \
"This is a test message for ML-DSA digital signature algorithm!"
#define TEST_MSG_LEN (sizeof(TEST_MSG) - 1)

int main(void)
{
const char *test_msg =
"This is a test message for ML-DSA digital signature algorithm!";
const char test_msg[] = TEST_MSG;
const char *test_ctx = "test_context_123";
size_t msglen = strlen(test_msg);
size_t ctxlen = strlen(test_ctx);

uint8_t pk[CRYPTO_PUBLICKEYBYTES];
uint8_t sk[CRYPTO_SECRETKEYBYTES];
uint8_t sig[CRYPTO_BYTES];
uint8_t sm[msglen + CRYPTO_BYTES]; /* signed message buffer */
uint8_t m2[msglen]; /* recovered message buffer */
uint8_t sm[TEST_MSG_LEN + CRYPTO_BYTES]; /* signed message buffer */
uint8_t m2[TEST_MSG_LEN + CRYPTO_BYTES]; /* recovered message buffer */
size_t siglen;
size_t smlen;
size_t mlen;
Expand All @@ -68,21 +70,22 @@ int main(void)
printf("Signing message... ");

/* Alice signs the message */
CHECK(crypto_sign_signature(sig, &siglen, (const uint8_t *)test_msg, msglen,
(const uint8_t *)test_ctx, ctxlen, sk) == 0);
CHECK(crypto_sign_signature(sig, &siglen, (const uint8_t *)test_msg,
TEST_MSG_LEN, (const uint8_t *)test_ctx, ctxlen,
sk) == 0);

printf("DONE\n");
printf("Verifying signature... ");

/* Bob verifies Alice's signature */
CHECK(crypto_sign_verify(sig, siglen, (const uint8_t *)test_msg, msglen,
CHECK(crypto_sign_verify(sig, siglen, (const uint8_t *)test_msg, TEST_MSG_LEN,
(const uint8_t *)test_ctx, ctxlen, pk) == 0);

printf("DONE\n");
printf("Creating signed message... ");

/* Alternative API: Create a signed message (signature + message combined) */
CHECK(crypto_sign(sm, &smlen, (const uint8_t *)test_msg, msglen,
CHECK(crypto_sign(sm, &smlen, (const uint8_t *)test_msg, TEST_MSG_LEN,
(const uint8_t *)test_ctx, ctxlen, sk) == 0);

printf("DONE\n");
Expand All @@ -96,8 +99,8 @@ int main(void)
printf("Compare messages... ");

/* Verify the recovered message matches the original */
CHECK(mlen == msglen);
CHECK(memcmp(test_msg, m2, msglen) == 0);
CHECK(mlen == TEST_MSG_LEN);
CHECK(memcmp(test_msg, m2, TEST_MSG_LEN) == 0);

printf("DONE\n\n");

Expand All @@ -106,9 +109,9 @@ int main(void)
printf("Public key size: %d bytes\n", CRYPTO_PUBLICKEYBYTES);
printf("Secret key size: %d bytes\n", CRYPTO_SECRETKEYBYTES);
printf("Signature size: %d bytes\n", CRYPTO_BYTES);
printf("Message length: %zu bytes\n", msglen);
printf("Signature length: %zu bytes\n", siglen);
printf("Signed msg length: %zu bytes\n", smlen);
printf("Message length: %lu bytes\n", TEST_MSG_LEN);
printf("Signature length: %lu bytes\n", (unsigned long)siglen);
printf("Signed msg length: %lu bytes\n", (unsigned long)smlen);

#if !defined(MLD_CONFIG_KEYGEN_PCT)
/* Check against expected signature to make sure that
Expand Down
3 changes: 3 additions & 0 deletions examples/monolithic_build/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT

build
Loading