Skip to content

Commit

Permalink
add suport public key generation from private key dilithium2 - 5
Browse files Browse the repository at this point in the history
add suport public key generation from private key dilithium2 - 5

Signed-off-by: mraksoll4 <[email protected]>
  • Loading branch information
mraksoll4 committed Dec 31, 2024
1 parent 1c9ba0d commit e72bd9e
Show file tree
Hide file tree
Showing 31 changed files with 767 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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
55 changes: 53 additions & 2 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) {
}

/*************************************************
* Name: crypto_sign_keypair from fixed seed.
* Name: crypto_sign_keypair_from_fseed
*
* Description: Generates public and private key.
* 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)
**************************************************/
Expand Down Expand Up @@ -151,6 +157,51 @@ int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed
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
3 changes: 3 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium2_aarch64/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ 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
2 changes: 2 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ 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
55 changes: 53 additions & 2 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) {
}

/*************************************************
* Name: crypto_sign_keypair from fixed seed.
* Name: crypto_sign_keypair_from_fseed
*
* Description: Generates public and private key.
* 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)
**************************************************/
Expand Down Expand Up @@ -151,6 +157,51 @@ int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed
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
3 changes: 3 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium3_aarch64/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ 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
2 changes: 2 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium5_aarch64/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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
56 changes: 54 additions & 2 deletions src/sig/dilithium/oldpqclean_dilithium5_aarch64/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ int crypto_sign_keypair(uint8_t *pk, uint8_t *sk) {
}

/*************************************************
* Name: crypto_sign_keypair from fixed seed.
* Name: crypto_sign_keypair_from_fseed
*
* Description: Generates public and private key.
* 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)
**************************************************/
Expand Down Expand Up @@ -151,6 +157,52 @@ int crypto_sign_keypair_from_fseed(uint8_t *pk, uint8_t *sk, const uint8_t *seed
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
3 changes: 3 additions & 0 deletions src/sig/dilithium/oldpqclean_dilithium5_aarch64/sign.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ 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
12 changes: 12 additions & 0 deletions src/sig/dilithium/pqcrystals-dilithium_dilithium2_avx2/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ int pqcrystals_dilithium2_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

int pqcrystals_dilithium2_avx2_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *sk);
Expand All @@ -40,6 +42,8 @@ int pqcrystals_dilithium2aes_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

int pqcrystals_dilithium2aes_avx2_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *sk);
Expand Down Expand Up @@ -68,6 +72,8 @@ int pqcrystals_dilithium3_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

int pqcrystals_dilithium3_avx2_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *sk);
Expand All @@ -92,6 +98,8 @@ int pqcrystals_dilithium3aes_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

int pqcrystals_dilithium3aes_avx2_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *sk);
Expand Down Expand Up @@ -120,6 +128,8 @@ int pqcrystals_dilithium5_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

int pqcrystals_dilithium5_avx2_signature(uint8_t *sig, size_t *siglen,
const uint8_t *m, size_t mlen,
const uint8_t *sk);
Expand All @@ -144,6 +154,8 @@ int pqcrystals_dilithium5aes_avx2_keypair(uint8_t *pk, uint8_t *sk);

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

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

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

0 comments on commit e72bd9e

Please sign in to comment.