Skip to content

Commit

Permalink
rebase to the open-quantum-safe master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
feventura committed Oct 5, 2023
1 parent 4846d78 commit b045a38
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 127 deletions.
3 changes: 3 additions & 0 deletions oqsprov/oqs_encode_key2any.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ static int oqsx_pki_priv_to_der(const void *vxkey, unsigned char **pder)
# define dilithium3_ed25519_evp_type 0
# define dilithium3_ed25519_input_type "dilithium3_ed25519"
# define dilithium3_ed25519_pem_type "dilithium3_ed25519"
# define dilithium3_pss_evp_type 0
# define dilithium3_pss_input_type "dilithium3_pss"
# define dilithium3_pss_pem_type "dilithium3_pss"
# define dilithium5_bp384_evp_type 0
# define dilithium5_bp384_input_type "dilithium5_bp384"
# define dilithium5_bp384_pem_type "dilithium5_bp384"
Expand Down
88 changes: 66 additions & 22 deletions oqsprov/oqs_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,112 +862,156 @@ static void *rsa3072_sphincsshake128fsimple_gen_init(void *provctx,

static void *dilithium3_rsa3072_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3, "dilithium3_rsa3072", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3,
"dilithium3_rsa3072", KEY_TYPE_CMP_SIG, NULL, 128, 23);
}

static void *dilithium3_rsa3072_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_3, "dilithium3_rsa3072", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_3,
"dilithium3_rsa3072", KEY_TYPE_CMP_SIG, 128, 23);
}

static void *dilithium3_p256_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3, "dilithium3_p256", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3,
"dilithium3_p256", KEY_TYPE_CMP_SIG, NULL, 128, 24);
}

static void *dilithium3_p256_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_3, "dilithium3_p256", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_3,
"dilithium3_p256", KEY_TYPE_CMP_SIG, 128, 24);
}

static void *falcon512_p256_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512, "falcon512_p256", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512,
"falcon512_p256", KEY_TYPE_CMP_SIG, NULL, 128, 25);
}

static void *falcon512_p256_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_falcon_512, "falcon512_p256", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_falcon_512,
"falcon512_p256", KEY_TYPE_CMP_SIG, 128, 25);
}

static void *dilithium5_p384_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5, "dilithium5_p384", KEY_TYPE_CMP_SIG, NULL, 192);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5,
"dilithium5_p384", KEY_TYPE_CMP_SIG, NULL, 192, 26);
}

static void *dilithium5_p384_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_5, "dilithium5_p384", KEY_TYPE_CMP_SIG, 192);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_5,
"dilithium5_p384", KEY_TYPE_CMP_SIG, 192, 26);
}

static void *dilithium3_bp256_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3, "dilithium3_bp256", KEY_TYPE_CMP_SIG, NULL, 256);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3,
"dilithium3_bp256", KEY_TYPE_CMP_SIG, NULL, 256, 27);
}

static void *dilithium3_bp256_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_3, "dilithium3_bp256", KEY_TYPE_CMP_SIG, 256);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_3,
"dilithium3_bp256", KEY_TYPE_CMP_SIG, 256, 27);
}

static void *dilithium3_ed25519_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3, "dilithium3_ed25519", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3,
"dilithium3_ed25519", KEY_TYPE_CMP_SIG, NULL, 128, 28);
}

static void *dilithium3_ed25519_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_3, "dilithium3_ed25519", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_3,
"dilithium3_ed25519", KEY_TYPE_CMP_SIG, 128, 28);
}

static void *dilithium5_bp384_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5, "dilithium5_bp384", KEY_TYPE_CMP_SIG, NULL, 384);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5,
"dilithium5_bp384", KEY_TYPE_CMP_SIG, NULL, 384, 29);
}

static void *dilithium5_bp384_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_5, "dilithium5_bp384", KEY_TYPE_CMP_SIG, 384);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_5,
"dilithium5_bp384", KEY_TYPE_CMP_SIG, 384, 29);
}

static void *dilithium5_ed448_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5, "dilithium5_ed448", KEY_TYPE_CMP_SIG, NULL, 192);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_5,
"dilithium5_ed448", KEY_TYPE_CMP_SIG, NULL, 192, 30);
}

static void *dilithium5_ed448_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_5, "dilithium5_ed448", KEY_TYPE_CMP_SIG, 192);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_5,
"dilithium5_ed448", KEY_TYPE_CMP_SIG, 192, 30);
}

static void *falcon512_bp256_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512, "falcon512_bp256", KEY_TYPE_CMP_SIG, NULL, 256);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512,
"falcon512_bp256", KEY_TYPE_CMP_SIG, NULL, 256, 31);
}

static void *falcon512_bp256_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_falcon_512, "falcon512_bp256", KEY_TYPE_CMP_SIG, 256);
return oqsx_gen_init
(provctx, selection, OQS_SIG_alg_falcon_512,
"falcon512_bp256", KEY_TYPE_CMP_SIG, 256, 31);
}

static void *falcon512_ed25519_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512, "falcon512_ed25519", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_falcon_512,
"falcon512_ed25519", KEY_TYPE_CMP_SIG, NULL, 128, 32);
}

static void *falcon512_ed25519_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_falcon_512, "falcon512_ed25519", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_falcon_512,
"falcon512_ed25519", KEY_TYPE_CMP_SIG, 128, 32);
}

static void *dilithium3_pss_new_key(void *provctx)
{
return oqsx_key_new(PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3, "dilithium3_pss", KEY_TYPE_CMP_SIG, NULL, 128);
return oqsx_key_new(
PROV_OQS_LIBCTX_OF(provctx), OQS_SIG_alg_dilithium_3,
"dilithium3_pss", KEY_TYPE_CMP_SIG, NULL, 128, 33);
}

static void *dilithium3_pss_gen_init(void *provctx, int selection)
{
return oqsx_gen_init(provctx, selection, OQS_SIG_alg_dilithium_3, "dilithium3_pss", KEY_TYPE_CMP_SIG, 128);
return oqsx_gen_init(
provctx, selection, OQS_SIG_alg_dilithium_3,
"dilithium3_pss", KEY_TYPE_CMP_SIG, 128, 33);
}

///// OQS_TEMPLATE_FRAGMENT_KEYMGMT_CONSTRUCTORS_END
Expand Down
9 changes: 1 addition & 8 deletions oqsprov/oqs_prov.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,10 @@ struct oqsx_key_st {
#endif
char *propq;
OQSX_KEY_TYPE keytype;
OQSX_PROVIDER_CTX oqsx_provider_ctx;
OQSX_PROVIDER_CTX *oqsx_provider_ctx;
#ifdef USE_ENCODING_LIB
OQSX_ENCODING_CTX oqsx_encoding_ctx;
#endif
OQSX_PROVIDER_CTX oqsx_provider_ctx_cmp;
EVP_PKEY** cmp_classical_pkey;
EVP_PKEY *classical_pkey; // for hybrid sigs
const OQSX_EVP_INFO *evp_info;
Expand Down Expand Up @@ -202,12 +201,6 @@ struct SignatureModel{

typedef struct SignatureModel CompositeSignature;

char* get_oqsname(int nid);
char* get_cmpname(int nid, int index);
int get_qntcmp(int nid);
int get_keytype(int nid);
char* get_oqsname_fromtls(char* oqsname);

/* Register given NID with tlsname in OSSL3 registry */
int oqs_set_nid(char *tlsname, int nid);

Expand Down
2 changes: 1 addition & 1 deletion oqsprov/oqs_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ static int oqs_sig_verify(void *vpoqs_sigctx, const unsigned char *sig,
if (OQS_SIG_verify(oqs_key, tbs, tbslen, sig + index,
siglen - classical_sig_len,
oqsxkey->comp_pubkey[oqsxkey->numkeys-1])
!= OQS_SUCCESS) {
!= OQS_SUCCESS)
{
ERR_raise(ERR_LIB_USER, OQSPROV_R_VERIFY_ERROR);
goto endverify;
Expand Down
10 changes: 0 additions & 10 deletions oqsprov/oqsencoders.inc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium3_rsa3072", dilithium3_rsa3072, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium3_rsa3072", dilithium3_rsa3072),
ENCODER_w_structure("dilithium3_p256", dilithium3_p256, der,
PrivateKeyInfo),
ENCODER_w_structure("dilithium3_p256", dilithium3_p256, pem,
Expand All @@ -160,7 +159,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium3_p256", dilithium3_p256, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium3_p256", dilithium3_p256),
ENCODER_w_structure("dilithium3_bp256", dilithium3_bp256, der,
PrivateKeyInfo),
ENCODER_w_structure("dilithium3_bp256", dilithium3_bp256, pem,
Expand All @@ -173,7 +171,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium3_bp256", dilithium3_bp256, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium3_bp256", dilithium3_bp256),
ENCODER_w_structure("dilithium3_ed25519", dilithium3_ed25519, der,
PrivateKeyInfo),
ENCODER_w_structure("dilithium3_ed25519", dilithium3_ed25519, pem,
Expand All @@ -198,7 +195,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium3_pss", dilithium3_pss, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium3_pss", dilithium3_pss),

#endif
#ifdef OQS_ENABLE_SIG_dilithium_5
Expand Down Expand Up @@ -234,7 +230,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium5_p384", dilithium5_p384, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium5_p384", dilithium5_p384),
ENCODER_w_structure("dilithium5_bp384", dilithium5_bp384, der,
PrivateKeyInfo),
ENCODER_w_structure("dilithium5_bp384", dilithium5_bp384, pem,
Expand All @@ -247,7 +242,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("dilithium5_bp384", dilithium5_bp384, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("dilithium5_bp384", dilithium5_bp384),
ENCODER_w_structure("dilithium5_ed448", dilithium5_ed448, der,
PrivateKeyInfo),
ENCODER_w_structure("dilithium5_ed448", dilithium5_ed448, pem,
Expand Down Expand Up @@ -279,7 +273,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("p256_falcon512", p256_falcon512, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("p256_falcon512", p256_falcon512),
ENCODER_w_structure("rsa3072_falcon512", rsa3072_falcon512, der,
PrivateKeyInfo),
ENCODER_w_structure("rsa3072_falcon512", rsa3072_falcon512, pem,
Expand All @@ -292,7 +285,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("rsa3072_falcon512", rsa3072_falcon512, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("rsa3072_falcon512", rsa3072_falcon512),
ENCODER_w_structure("falcon512_p256", falcon512_p256, der,
PrivateKeyInfo),
ENCODER_w_structure("falcon512_p256", falcon512_p256, pem,
Expand All @@ -305,7 +297,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("falcon512_p256", falcon512_p256, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("falcon512_p256", falcon512_p256),
ENCODER_w_structure("falcon512_bp256", falcon512_bp256, der,
PrivateKeyInfo),
ENCODER_w_structure("falcon512_bp256", falcon512_bp256, pem,
Expand All @@ -318,7 +309,6 @@ ENCODER_w_structure("dilithium2", dilithium2, der, PrivateKeyInfo),
SubjectPublicKeyInfo),
ENCODER_w_structure("falcon512_bp256", falcon512_bp256, pem,
SubjectPublicKeyInfo),
ENCODER_TEXT("falcon512_bp256", falcon512_bp256),
ENCODER_w_structure("falcon512_ed25519", falcon512_ed25519, der,
PrivateKeyInfo),
ENCODER_w_structure("falcon512_ed25519", falcon512_ed25519, pem,
Expand Down
Loading

0 comments on commit b045a38

Please sign in to comment.