Skip to content
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

Exendend api and modification for allow generate keypair from fixed seed for some sig algos. #2027

Closed
Closed
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
4 changes: 4 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

int PQCLEAN_DILITHIUM2_AARCH64_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

int PQCLEAN_DILITHIUM2_AARCH64_crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed);

int PQCLEAN_DILITHIUM2_AARCH64_crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk);

int PQCLEAN_DILITHIUM2_AARCH64_crypto_sign_signature(
uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen, const uint8_t *sk);
Expand Down
107 changes: 107 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,113 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) {
return 0;
}

/*************************************************
* Name: crypto_sign_keypair_from_fseed
*
* Description: Generates public and private key from fixed seed.
*
* Arguments: - uint8_t *pk: pointer to output public key (allocated
* array of CRYPTO_PUBLICKEYBYTES bytes)
* - uint8_t *sk: pointer to output private key (allocated
* array of CRYPTO_SECRETKEYBYTES bytes)
* - const uint8_t *seed: Pointer to the input fixed seed.
* Must point to an array of SEEDBYTES bytes.
* The seed provides deterministic randomness
* for key generation and must be unique and
* securely generated for each keypair to
* ensure security.
*
* Returns 0 (success)
**************************************************/
int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed) {
uint8_t seedbuf[2 * SEEDBYTES + CRHBYTES];
uint8_t tr[SEEDBYTES];
const uint8_t *rho, *rhoprime, *key;
polyvecl mat[K];
polyvecl s1, s1hat;
polyveck s2, t1, t0;

/* Use fixed seed for randomness for rho, rhoprime and key */
shake256(seedbuf, 2*SEEDBYTES + CRHBYTES, seed, SEEDBYTES);
rho = seedbuf;
rhoprime = rho + SEEDBYTES;
key = rhoprime + CRHBYTES;

/* Expand matrix */
polyvec_matrix_expand(mat, rho);

/* Sample short vectors s1 and s2 */
polyvecl_uniform_eta(&s1, rhoprime, 0);
polyveck_uniform_eta(&s2, rhoprime, L);

/* Matrix-vector multiplication */
s1hat = s1;
polyvecl_ntt(&s1hat);
polyvec_matrix_pointwise_montgomery(&t1, mat, &s1hat);
polyveck_reduce(&t1);
polyveck_invntt_tomont(&t1);

/* Add error vector s2 */
polyveck_add(&t1, &t1, &s2);

/* Extract t1 and write public key */
polyveck_caddq(&t1);
polyveck_power2round(&t1, &t0, &t1);
pack_pk(pk, rho, &t1);

/* Compute H(rho, t1) and write secret key */
shake256(tr, SEEDBYTES, pk, CRYPTO_PUBLICKEYBYTES);
pack_sk(sk, rho, tr, key, &t0, &s1, &s2);

return 0;
}

/*************************************************
* Name: crypto_sign_pubkey_from_privkey
*
* Description: Generates public key from exist private key.
*
* Arguments: - uint8_t *pk: pointer to output public key (allocated
* array of CRYPTO_PUBLICKEYBYTES bytes)
* - const uint8_t *sk: pointer to the input private key (points
* to a read-only array of CRYPTO_SECRETKEYBYTES bytes)
*
* Returns 0 (success)
**************************************************/
int crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk) {
uint8_t rho[SEEDBYTES];
uint8_t tr[SEEDBYTES];
uint8_t key[SEEDBYTES];
polyvecl s1, s1hat;
polyveck s2, t0, t1;
polyvecl mat[K];

/* unpack privat key */
unpack_sk(rho, tr, key, &t0, &s1, &s2, sk);

/* Expand matrix */
polyvec_matrix_expand(mat, rho);

/* Matrix-vector multiplication */
s1hat = s1;
polyvecl_ntt(&s1hat);
polyvec_matrix_pointwise_montgomery(&t1, mat, &s1hat);
polyveck_reduce(&t1);
polyveck_invntt_tomont(&t1);

/* Add error vector s2 */
polyveck_add(&t1, &t1, &s2);

/* Extract t1 */
polyveck_caddq(&t1);
polyveck_power2round(&t1, &t0, &t1);

/* Pack public key */
pack_pk(pk, rho, &t1);

return 0;
}

/*************************************************
* Name: crypto_sign_signature
*
Expand Down
6 changes: 6 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ void challenge(poly *c, const uint8_t seed[SEEDBYTES]);
#define crypto_sign_keypair DILITHIUM_NAMESPACE(crypto_sign_keypair)
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_keypair_from_fseed DILITHIUM_NAMESPACE(keypair_from_fseed)
int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed);

#define crypto_sign_pubkey_from_privkey DILITHIUM_NAMESPACE(pubkey_from_privkey)
int crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk);

#define crypto_sign_signature DILITHIUM_NAMESPACE(crypto_sign_signature)
int crypto_sign_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
Expand Down
4 changes: 4 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

int PQCLEAN_DILITHIUM3_AARCH64_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

int PQCLEAN_DILITHIUM3_AARCH64_crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed);

int PQCLEAN_DILITHIUM3_AARCH64_crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk);

int PQCLEAN_DILITHIUM3_AARCH64_crypto_sign_signature(
uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen, const uint8_t *sk);
Expand Down
107 changes: 107 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,113 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) {
return 0;
}

/*************************************************
* Name: crypto_sign_keypair_from_fseed
*
* Description: Generates public and private key from fixed seed.
*
* Arguments: - uint8_t *pk: pointer to output public key (allocated
* array of CRYPTO_PUBLICKEYBYTES bytes)
* - uint8_t *sk: pointer to output private key (allocated
* array of CRYPTO_SECRETKEYBYTES bytes)
* - const uint8_t *seed: Pointer to the input fixed seed.
* Must point to an array of SEEDBYTES bytes.
* The seed provides deterministic randomness
* for key generation and must be unique and
* securely generated for each keypair to
* ensure security.
*
* Returns 0 (success)
**************************************************/
int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed) {
uint8_t seedbuf[2 * SEEDBYTES + CRHBYTES];
uint8_t tr[SEEDBYTES];
const uint8_t *rho, *rhoprime, *key;
polyvecl mat[K];
polyvecl s1, s1hat;
polyveck s2, t1, t0;

/* Use fixed seed for randomness for rho, rhoprime and key */
shake256(seedbuf, 2*SEEDBYTES + CRHBYTES, seed, SEEDBYTES);
rho = seedbuf;
rhoprime = rho + SEEDBYTES;
key = rhoprime + CRHBYTES;

/* Expand matrix */
polyvec_matrix_expand(mat, rho);

/* Sample short vectors s1 and s2 */
polyvecl_uniform_eta(&s1, rhoprime, 0);
polyveck_uniform_eta(&s2, rhoprime, L);

/* Matrix-vector multiplication */
s1hat = s1;
polyvecl_ntt(&s1hat);
polyvec_matrix_pointwise_montgomery(&t1, mat, &s1hat);
polyveck_reduce(&t1);
polyveck_invntt_tomont(&t1);

/* Add error vector s2 */
polyveck_add(&t1, &t1, &s2);

/* Extract t1 and write public key */
polyveck_caddq(&t1);
polyveck_power2round(&t1, &t0, &t1);
pack_pk(pk, rho, &t1);

/* Compute H(rho, t1) and write secret key */
shake256(tr, SEEDBYTES, pk, CRYPTO_PUBLICKEYBYTES);
pack_sk(sk, rho, tr, key, &t0, &s1, &s2);

return 0;
}

/*************************************************
* Name: crypto_sign_pubkey_from_privkey
*
* Description: Generates public key from exist private key.
*
* Arguments: - uint8_t *pk: pointer to output public key (allocated
* array of CRYPTO_PUBLICKEYBYTES bytes)
* - const uint8_t *sk: pointer to the input private key (points
* to a read-only array of CRYPTO_SECRETKEYBYTES bytes)
*
* Returns 0 (success)
**************************************************/
int crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk) {
uint8_t rho[SEEDBYTES];
uint8_t tr[SEEDBYTES];
uint8_t key[SEEDBYTES];
polyvecl s1, s1hat;
polyveck s2, t0, t1;
polyvecl mat[K];

/* unpack privat key */
unpack_sk(rho, tr, key, &t0, &s1, &s2, sk);

/* Expand matrix */
polyvec_matrix_expand(mat, rho);

/* Matrix-vector multiplication */
s1hat = s1;
polyvecl_ntt(&s1hat);
polyvec_matrix_pointwise_montgomery(&t1, mat, &s1hat);
polyveck_reduce(&t1);
polyveck_invntt_tomont(&t1);

/* Add error vector s2 */
polyveck_add(&t1, &t1, &s2);

/* Extract t1 */
polyveck_caddq(&t1);
polyveck_power2round(&t1, &t0, &t1);

/* Pack public key */
pack_pk(pk, rho, &t1);

return 0;
}

/*************************************************
* Name: crypto_sign_signature
*
Expand Down
6 changes: 6 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ void challenge(poly *c, const uint8_t seed[SEEDBYTES]);
#define crypto_sign_keypair DILITHIUM_NAMESPACE(crypto_sign_keypair)
int crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

#define crypto_sign_keypair_from_fseed DILITHIUM_NAMESPACE(keypair_from_fseed)
int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed);

#define crypto_sign_pubkey_from_privkey DILITHIUM_NAMESPACE(pubkey_from_privkey)
int crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk);

#define crypto_sign_signature DILITHIUM_NAMESPACE(crypto_sign_signature)
int crypto_sign_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
Expand Down
4 changes: 4 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium5_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@

int PQCLEAN_DILITHIUM5_AARCH64_crypto_sign_keypair(uint8_t *pk, uint8_t *sk);

int PQCLEAN_DILITHIUM5_AARCH64_crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed);

int PQCLEAN_DILITHIUM5_AARCH64_crypto_sign_pubkey_from_privkey(uint8_t *pk, const uint8_t *sk);

int PQCLEAN_DILITHIUM5_AARCH64_crypto_sign_signature(
uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen, const uint8_t *sk);
Expand Down
Loading