Skip to content

Commit

Permalink
Merge branch 'main' into mb-disabletempoids
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Baentsch <[email protected]>
  • Loading branch information
baentsch authored Sep 23, 2024
2 parents f0fe7d1 + 0312c00 commit c4f6eac
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
11 changes: 10 additions & 1 deletion oqsprov/oqs_encode_key2any.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,19 @@ static int oqsx_pki_priv_to_der(const void *vxkey, unsigned char **pder) {
OPENSSL_malloc(oqsxkey->numkeys * sizeof(unsigned char *));
size_t *templen = OPENSSL_malloc(oqsxkey->numkeys * sizeof(size_t));
PKCS8_PRIV_KEY_INFO *p8inf_internal = NULL;
sk = sk_ASN1_TYPE_new_null();
int i;

if ((sk = sk_ASN1_TYPE_new_null()) == NULL)
if (!sk || !templen || !aType || !aString || !temp) {
OPENSSL_free(aType);
OPENSSL_free(aString);
OPENSSL_free(temp);
OPENSSL_free(templen);
if (sk) {
sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
}
return -1;
}

for (i = 0; i < oqsxkey->numkeys; i++) {
aType[i] = ASN1_TYPE_new();
Expand Down
28 changes: 14 additions & 14 deletions oqsprov/oqs_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,20 @@ static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out,
size_t *outlen, unsigned char *secret,
size_t *secretlen, int keyslot) {
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQS_KEM *kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem;
const OQS_KEM *kem_ctx = NULL;

OQS_KEM_PRINTF("OQS KEM provider called: encaps\n");
if (pkemctx->kem == NULL) {
OQS_KEM_PRINTF("OQS Warning: OQS_KEM not initialized\n");
return -1;
}

kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem;
if (pkemctx->kem->comp_pubkey == NULL ||
pkemctx->kem->comp_pubkey[keyslot] == NULL) {
OQS_KEM_PRINTF("OQS Warning: public key is NULL\n");
return -1;
}
if (out == NULL || secret == NULL) {
if (outlen != NULL) {
*outlen = kem_ctx->length_ciphertext;
}
if (secretlen != NULL) {
*secretlen = kem_ctx->length_shared_secret;
}
OQS_KEM_PRINTF3("KEM returning lengths %ld and %ld\n",
kem_ctx->length_ciphertext,
kem_ctx->length_shared_secret);
return 1;
}
if (outlen == NULL) {
OQS_KEM_PRINTF("OQS Warning: outlen is NULL\n");
return -1;
Expand All @@ -135,6 +125,15 @@ static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out,
OQS_KEM_PRINTF("OQS Warning: secretlen is NULL\n");
return -1;
}
if (out == NULL || secret == NULL) {
*outlen = kem_ctx->length_ciphertext;
*secretlen = kem_ctx->length_shared_secret;
OQS_KEM_PRINTF3("KEM returning lengths %ld and %ld\n",
kem_ctx->length_ciphertext,
kem_ctx->length_shared_secret);
return 1;
}

if (*outlen < kem_ctx->length_ciphertext) {
OQS_KEM_PRINTF("OQS Warning: out buffer too small\n");
return -1;
Expand All @@ -154,13 +153,14 @@ static int oqs_qs_kem_decaps_keyslot(void *vpkemctx, unsigned char *out,
size_t *outlen, const unsigned char *in,
size_t inlen, int keyslot) {
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQS_KEM *kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem;
const OQS_KEM *kem_ctx = NULL;

OQS_KEM_PRINTF("OQS KEM provider called: decaps\n");
if (pkemctx->kem == NULL) {
OQS_KEM_PRINTF("OQS Warning: OQS_KEM not initialized\n");
return -1;
}
kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem;
if (pkemctx->kem->comp_privkey == NULL ||
pkemctx->kem->comp_privkey[keyslot] == NULL) {
OQS_KEM_PRINTF("OQS Warning: private key is NULL\n");
Expand Down
2 changes: 1 addition & 1 deletion oqsprov/oqs_kmgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static int oqsx_get_hybrid_params(OQSX_KEY *key, OSSL_PARAM params[]) {
DECODE_UINT32(classical_privkey_len, key->privkey);
}

if (key->comp_pubkey[1] != NULL) {
if (key->comp_pubkey && key->comp_pubkey[1] != NULL) {
pq_pubkey = key->comp_pubkey[1];
pq_pubkey_len = key->pubkeylen - classical_pubkey_len - SIZE_OF_UINT32;
}
Expand Down
1 change: 1 addition & 0 deletions oqsprov/oqsprov.c
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,7 @@ int OQS_PROVIDER_ENTRYPOINT_NAME(const OSSL_CORE_HANDLE *handle,

// insert all OIDs to the global objects list
for (i = 0; i < OQS_OID_CNT; i += 2) {

if (oqs_oid_alg_list[i] == NULL) {
OQS_PROV_PRINTF2("OQS PROV: Warning: No OID registered for %s\n",
oqs_oid_alg_list[i + 1]);
Expand Down
10 changes: 6 additions & 4 deletions oqsprov/oqsprov_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1497,10 +1497,12 @@ OQSX_KEY *oqsx_key_new(OSSL_LIB_CTX *libctx, char *oqs_name, char *tls_name,
if (ret->lock)
CRYPTO_THREAD_lock_free(ret->lock);
#endif
OPENSSL_free(ret->tls_name);
OPENSSL_free(ret->propq);
OPENSSL_free(ret->comp_privkey);
OPENSSL_free(ret->comp_pubkey);
if (ret) {
OPENSSL_free(ret->tls_name);
OPENSSL_free(ret->propq);
OPENSSL_free(ret->comp_privkey);
OPENSSL_free(ret->comp_pubkey);
}
OPENSSL_free(ret);
return NULL;
}
Expand Down
2 changes: 2 additions & 0 deletions test/oqs_test_evp_pkey_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ int main(int argc, char **argv) {
fprintf(stderr, cRED " No signature algorithms found" cNORM "\n");
ERR_print_errors_fp(stderr);
++errcnt;
goto next_alg;
}

for (; algs->algorithm_names != NULL; ++algs) {
Expand All @@ -550,6 +551,7 @@ int main(int argc, char **argv) {
}
}

next_alg:
algs = OSSL_PROVIDER_query_operation(oqs_provider, OSSL_OP_KEM,
&query_nocache);
if (!algs) {
Expand Down

0 comments on commit c4f6eac

Please sign in to comment.