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
98 changes: 49 additions & 49 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,54 +126,54 @@ jobs:
./example_sig
working-directory: ${{ env.RANDOM_BUILD_DIR }}

fuzzbuildcheck:
name: Check that code passes a basic fuzzing build
# needs: [workflowcheck, stylecheck, upstreamcheck]
needs: [workflowcheck, stylecheck]
runs-on: ubuntu-latest
container: openquantumsafe/ci-ubuntu-latest:latest
env:
SIG_NAME: ml_dsa_44
CC: clang
CXX: clang++
CFLAGS: -fsanitize=fuzzer-no-link,address
LDFLAGS: -fsanitize=address
steps:
- name: Create random build folder
run: tmp_build=$(mktemp -d) && echo "RANDOM_BUILD_DIR=$tmp_build" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
- name: Configure
run: |
cmake \
-B ${{ env.RANDOM_BUILD_DIR }} \
-GNinja \
-DOQS_STRICT_WARNINGS=ON \
-DOQS_BUILD_FUZZ_TESTS=ON \
-DOQS_MINIMAL_BUILD="SIG_$SIG_NAME" \
--warn-uninitialized . > config.log 2>&1 && \
cat config.log && \
cmake -LA -N . && \
! (grep -i "uninitialized variable" config.log)
- name: Build code
run: ninja fuzz_test_sig
working-directory: ${{ env.RANDOM_BUILD_DIR }}
# fuzzbuildcheck:
# name: Check that code passes a basic fuzzing build
# # needs: [workflowcheck, stylecheck, upstreamcheck]
# needs: [workflowcheck, stylecheck]
# runs-on: ubuntu-latest
# container: openquantumsafe/ci-ubuntu-latest:latest
# env:
# SIG_NAME: ml_dsa_44
# CC: clang
# CXX: clang++
# CFLAGS: -fsanitize=fuzzer-no-link,address
# LDFLAGS: -fsanitize=address
# steps:
# - name: Create random build folder
# run: tmp_build=$(mktemp -d) && echo "RANDOM_BUILD_DIR=$tmp_build" >> $GITHUB_ENV
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
# - name: Configure
# run: |
# cmake \
# -B ${{ env.RANDOM_BUILD_DIR }} \
# -GNinja \
# -DOQS_STRICT_WARNINGS=ON \
# -DOQS_BUILD_FUZZ_TESTS=ON \
# -DOQS_MINIMAL_BUILD="SIG_$SIG_NAME" \
# --warn-uninitialized . > config.log 2>&1 && \
# cat config.log && \
# cmake -LA -N . && \
# ! (grep -i "uninitialized variable" config.log)
# - name: Build code
# run: ninja fuzz_test_sig
# working-directory: ${{ env.RANDOM_BUILD_DIR }}

- name: Short fuzz check (30s)
run: ./tests/fuzz_test_sig -max_total_time=30
working-directory: ${{ env.RANDOM_BUILD_DIR }}
# - name: Short fuzz check (30s)
# run: ./tests/fuzz_test_sig -max_total_time=30
# working-directory: ${{ env.RANDOM_BUILD_DIR }}

nixflakecheck:
name: Check that Nix flake has correct syntax and can build
needs: [workflowcheck]
runs-on: ubuntu-latest
steps:
- uses: DeterminateSystems/nix-installer-action@90bb610b90bf290cad97484ba341453bd1cbefea # v19
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
- name: Check devShell
run: nix develop --command echo
- name: Check flake syntax
run: nix flake check --no-build # check for accurate syntax
- name: Check that the flake builds
run: nix build # check that the build runs
# nixflakecheck:
# name: Check that Nix flake has correct syntax and can build
# needs: [workflowcheck]
# runs-on: ubuntu-latest
# steps:
# - uses: DeterminateSystems/nix-installer-action@90bb610b90bf290cad97484ba341453bd1cbefea # v19
# - name: Checkout code
# uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # pin@v4
# - name: Check devShell
# run: nix develop --command echo
# - name: Check flake syntax
# run: nix flake check --no-build # check for accurate syntax
# - name: Check that the flake builds
# run: nix build # check that the build runs
26 changes: 13 additions & 13 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ jobs:
# needs: basic-checks
# uses: ./.github/workflows/platforms.yml

code-coverage:
needs: basic-checks
uses: ./.github/workflows/code-coverage.yml
secrets: inherit

scorecard:
needs: basic-checks
uses: ./.github/workflows/supplychain.yml
secrets: inherit
permissions:
contents: read
id-token: write
security-events: write
# code-coverage:
# needs: basic-checks
# uses: ./.github/workflows/code-coverage.yml
# secrets: inherit

# scorecard:
# needs: basic-checks
# uses: ./.github/workflows/supplychain.yml
# secrets: inherit
# permissions:
# contents: read
# id-token: write
# security-events: write
15 changes: 15 additions & 0 deletions src/sig/falcon/pqclean_falcon-1024_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
int PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk);

/*
* Generate a new key pair using a provided seed. Public key goes into pk[], private key in sk[].
* Key sizes are exact (in bytes):
* public (pk): PQCLEAN_FALCON1024_AARCH64_CRYPTO_PUBLICKEYBYTES
* private (sk): PQCLEAN_FALCON1024_AARCH64_CRYPTO_SECRETKEYBYTES
*
* seed: seed for deterministic key generation. If NULL, uses random seed.
* Caller must ensure seed points to at least 32 bytes.
* seed_len: length of the seed in bytes. Must be between 32 and 64.

* Return value: 0 on success, -1 on error.
*/
int PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair_from_seed(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len);

/*
* Compute a signature on a provided message (m, mlen), with a given
* private key (sk). Signature is written in sig[], with length written
Expand Down
52 changes: 43 additions & 9 deletions src/sig/falcon/pqclean_falcon-1024_aarch64/pqclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,48 @@
* (signature length is 1+len(value), not counting the nonce)
*/

/* see api.h */
int
PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk) {
/*
* Internal helper function that performs the actual key generation and encoding.
* Logic extracted from the original PQClean PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair
* function.
* seed: seed for deterministic key generation. If NULL, uses random seed.
* Caller must ensure seed points to at least 32 bytes.
* seed_len: length of the seed in bytes. Must be between 32 and 64.
*/
static int
do_keypair(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len) {
union {
uint8_t b[28 * FALCON_N];
uint64_t dummy_u64;
fpr dummy_fpr;
} tmp;
int8_t f[FALCON_N], g[FALCON_N], F[FALCON_N];
uint16_t h[FALCON_N];
unsigned char seed[48];
inner_shake256_context rng;
size_t u, v;

/*
* Generate key pair.
*/
randombytes(seed, sizeof seed);
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed, sizeof seed);
inner_shake256_flip(&rng);
if (seed != NULL) {
// Validate seed length - accept 32 to 64 bytes - throws error otherwise
if (seed_len < 32 || seed_len > 64) {
return -1;
}
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed, seed_len);
inner_shake256_flip(&rng);
} else {
// Fallback to random seed if NULL (Original API)
unsigned char seed_buffer[48];
randombytes(seed_buffer, sizeof seed_buffer);
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed_buffer, sizeof seed_buffer);
inner_shake256_flip(&rng);
}

// Generate keypair using the initialized RNG
PQCLEAN_FALCON1024_AARCH64_keygen(&rng, f, g, F, NULL, h, FALCON_LOGN, tmp.b);
inner_shake256_ctx_release(&rng);

Expand Down Expand Up @@ -108,6 +128,20 @@ PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(
return 0;
}

/* see api.h */
int
PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair_from_seed(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len) {
return do_keypair(pk, sk, seed, seed_len);
}

/* see api.h */
int
PQCLEAN_FALCON1024_AARCH64_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk) {
return do_keypair(pk, sk, NULL, 0);
}

/*
* Compute the signature. nonce[] receives the nonce and must have length
* NONCELEN bytes. sigbuf[] receives the signature value (without nonce
Expand Down
15 changes: 15 additions & 0 deletions src/sig/falcon/pqclean_falcon-1024_avx2/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
int PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk);

/*
* Generate a new key pair using a provided seed. Public key goes into pk[], private key in sk[].
* Key sizes are exact (in bytes):
* public (pk): PQCLEAN_FALCON1024_AVX2_CRYPTO_PUBLICKEYBYTES
* private (sk): PQCLEAN_FALCON1024_AVX2_CRYPTO_SECRETKEYBYTES
*
* seed: seed for deterministic key generation. If NULL, uses random seed.
* Caller must ensure seed points to at least 32 bytes.
* seed_len: length of the seed in bytes. Must be between 32 and 64.

* Return value: 0 on success, -1 on error.
*/
int PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair_from_seed(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len);

/*
* Compute a signature on a provided message (m, mlen), with a given
* private key (sk). Signature is written in sig[], with length written
Expand Down
52 changes: 43 additions & 9 deletions src/sig/falcon/pqclean_falcon-1024_avx2/pqclean.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,48 @@
* (signature length is 1+len(value), not counting the nonce)
*/

/* see api.h */
int
PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk) {
/*
* Internal helper function that performs the actual key generation and encoding.
* Logic extracted from the original PQClean PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair
* function.
* seed: seed for deterministic key generation. If NULL, uses random seed.
* Caller must ensure seed points to at least 32 bytes.
* seed_len: length of the seed in bytes. Must be between 32 and 64.
*/
static int
do_keypair(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len) {
union {
uint8_t b[FALCON_KEYGEN_TEMP_10];
uint64_t dummy_u64;
fpr dummy_fpr;
} tmp;
int8_t f[1024], g[1024], F[1024];
uint16_t h[1024];
unsigned char seed[48];
inner_shake256_context rng;
size_t u, v;

/*
* Generate key pair.
*/
randombytes(seed, sizeof seed);
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed, sizeof seed);
inner_shake256_flip(&rng);
if (seed != NULL) {
// Validate seed length - accept 32 to 64 bytes - throws error otherwise
if (seed_len < 32 || seed_len > 64) {
return -1;
}
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed, seed_len);
inner_shake256_flip(&rng);
} else {
// Fallback to random seed if NULL (Original API)
unsigned char seed_buffer[48];
randombytes(seed_buffer, sizeof seed_buffer);
inner_shake256_init(&rng);
inner_shake256_inject(&rng, seed_buffer, sizeof seed_buffer);
inner_shake256_flip(&rng);
}

// Generate keypair using the initialized RNG
PQCLEAN_FALCON1024_AVX2_keygen(&rng, f, g, F, NULL, h, 10, tmp.b);
inner_shake256_ctx_release(&rng);

Expand Down Expand Up @@ -108,6 +128,20 @@ PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair(
return 0;
}

/* see api.h */
int
PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair_from_seed(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len) {
return do_keypair(pk, sk, seed, seed_len);
}

/* see api.h */
int
PQCLEAN_FALCON1024_AVX2_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk) {
return do_keypair(pk, sk, NULL, 0);
}

/*
* Compute the signature. nonce[] receives the nonce and must have length
* NONCELEN bytes. sigbuf[] receives the signature value (without nonce
Expand Down
15 changes: 15 additions & 0 deletions src/sig/falcon/pqclean_falcon-1024_clean/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
int PQCLEAN_FALCON1024_CLEAN_crypto_sign_keypair(
uint8_t *pk, uint8_t *sk);

/*
* Generate a new key pair using a provided seed. Public key goes into pk[], private key in sk[].
* Key sizes are exact (in bytes):
* public (pk): PQCLEAN_FALCON1024_CLEAN_CRYPTO_PUBLICKEYBYTES
* private (sk): PQCLEAN_FALCON1024_CLEAN_CRYPTO_SECRETKEYBYTES
*
* seed: seed for deterministic key generation. If NULL, uses random seed.
* Caller must ensure seed points to at least 32 bytes.
* seed_len: length of the seed in bytes. Must be between 32 and 64.

* Return value: 0 on success, -1 on error.
*/
int PQCLEAN_FALCON1024_CLEAN_crypto_sign_keypair_from_seed(
uint8_t *pk, uint8_t *sk, const uint8_t *seed, size_t seed_len);

/*
* Compute a signature on a provided message (m, mlen), with a given
* private key (sk). Signature is written in sig[], with length written
Expand Down
Loading