Skip to content

Commit

Permalink
Rerun generate.sh
Browse files Browse the repository at this point in the history
Signed-off-by: Spencer Wilson <[email protected]>
  • Loading branch information
SWilson4 committed Sep 26, 2024
1 parent 894d65d commit 54dc4e5
Show file tree
Hide file tree
Showing 23 changed files with 3,961 additions and 2,990 deletions.
195 changes: 104 additions & 91 deletions oqsprov/oqs_decode_der2key.c

Large diffs are not rendered by default.

1,076 changes: 556 additions & 520 deletions oqsprov/oqs_encode_key2any.c

Large diffs are not rendered by default.

26 changes: 16 additions & 10 deletions oqsprov/oqs_endecoder_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

#include "oqs_endecoder_local.h"

OSSL_FUNC_keymgmt_new_fn *oqs_prov_get_keymgmt_new(const OSSL_DISPATCH *fns) {
OSSL_FUNC_keymgmt_new_fn *oqs_prov_get_keymgmt_new(const OSSL_DISPATCH *fns)
{
/* Pilfer the keymgmt dispatch table */
for (; fns->function_id != 0; fns++)
if (fns->function_id == OSSL_FUNC_KEYMGMT_NEW)
Expand All @@ -23,7 +24,8 @@ OSSL_FUNC_keymgmt_new_fn *oqs_prov_get_keymgmt_new(const OSSL_DISPATCH *fns) {
return NULL;
}

OSSL_FUNC_keymgmt_free_fn *oqs_prov_get_keymgmt_free(const OSSL_DISPATCH *fns) {
OSSL_FUNC_keymgmt_free_fn *oqs_prov_get_keymgmt_free(const OSSL_DISPATCH *fns)
{
/* Pilfer the keymgmt dispatch table */
for (; fns->function_id != 0; fns++)
if (fns->function_id == OSSL_FUNC_KEYMGMT_FREE)
Expand All @@ -33,7 +35,8 @@ OSSL_FUNC_keymgmt_free_fn *oqs_prov_get_keymgmt_free(const OSSL_DISPATCH *fns) {
}

OSSL_FUNC_keymgmt_import_fn *
oqs_prov_get_keymgmt_import(const OSSL_DISPATCH *fns) {
oqs_prov_get_keymgmt_import(const OSSL_DISPATCH *fns)
{
/* Pilfer the keymgmt dispatch table */
for (; fns->function_id != 0; fns++)
if (fns->function_id == OSSL_FUNC_KEYMGMT_IMPORT)
Expand All @@ -43,7 +46,8 @@ oqs_prov_get_keymgmt_import(const OSSL_DISPATCH *fns) {
}

OSSL_FUNC_keymgmt_export_fn *
oqs_prov_get_keymgmt_export(const OSSL_DISPATCH *fns) {
oqs_prov_get_keymgmt_export(const OSSL_DISPATCH *fns)
{
/* Pilfer the keymgmt dispatch table */
for (; fns->function_id != 0; fns++)
if (fns->function_id == OSSL_FUNC_KEYMGMT_EXPORT)
Expand All @@ -53,24 +57,26 @@ oqs_prov_get_keymgmt_export(const OSSL_DISPATCH *fns) {
}

void *oqs_prov_import_key(const OSSL_DISPATCH *fns, void *provctx,
int selection, const OSSL_PARAM params[]) {
int selection, const OSSL_PARAM params[])
{
OSSL_FUNC_keymgmt_new_fn *kmgmt_new = oqs_prov_get_keymgmt_new(fns);
OSSL_FUNC_keymgmt_free_fn *kmgmt_free = oqs_prov_get_keymgmt_free(fns);
OSSL_FUNC_keymgmt_import_fn *kmgmt_import =
oqs_prov_get_keymgmt_import(fns);
OSSL_FUNC_keymgmt_import_fn *kmgmt_import
= oqs_prov_get_keymgmt_import(fns);
void *key = NULL;

if (kmgmt_new != NULL && kmgmt_import != NULL && kmgmt_free != NULL) {
if ((key = kmgmt_new(provctx)) == NULL ||
!kmgmt_import(key, selection, params)) {
if ((key = kmgmt_new(provctx)) == NULL
|| !kmgmt_import(key, selection, params)) {
kmgmt_free(key);
key = NULL;
}
}
return key;
}

void oqs_prov_free_key(const OSSL_DISPATCH *fns, void *key) {
void oqs_prov_free_key(const OSSL_DISPATCH *fns, void *key)
{
OSSL_FUNC_keymgmt_free_fn *kmgmt_free = oqs_prov_get_keymgmt_free(fns);

if (kmgmt_free != NULL)
Expand Down
18 changes: 11 additions & 7 deletions oqsprov/oqs_hyb_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static OSSL_FUNC_kem_decapsulate_fn oqs_hyb_kem_decaps;

static int oqs_evp_kem_encaps_keyslot(void *vpkemctx, unsigned char *ct,
size_t *ctlen, unsigned char *secret,
size_t *secretlen, int keyslot) {
size_t *secretlen, int keyslot)
{
int ret = OQS_SUCCESS, ret2 = 0;

const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
Expand Down Expand Up @@ -90,7 +91,8 @@ static int oqs_evp_kem_encaps_keyslot(void *vpkemctx, unsigned char *ct,
static int oqs_evp_kem_decaps_keyslot(void *vpkemctx, unsigned char *secret,
size_t *secretlen,
const unsigned char *ct, size_t ctlen,
int keyslot) {
int keyslot)
{
OQS_KEM_PRINTF("OQS KEM provider called: oqs_hyb_kem_decaps\n");

int ret = OQS_SUCCESS, ret2 = 0;
Expand Down Expand Up @@ -150,7 +152,8 @@ static int oqs_evp_kem_decaps_keyslot(void *vpkemctx, unsigned char *secret,
/// Hybrid KEM functions

static int oqs_hyb_kem_encaps(void *vpkemctx, unsigned char *ct, size_t *ctlen,
unsigned char *secret, size_t *secretlen) {
unsigned char *secret, size_t *secretlen)
{
int ret = OQS_SUCCESS;
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQSX_KEY *oqsx_key = pkemctx->kem;
Expand All @@ -162,9 +165,9 @@ static int oqs_hyb_kem_encaps(void *vpkemctx, unsigned char *ct, size_t *ctlen,
&secretLenClassical,
oqsx_key->reverse_share ? 1 : 0);
ON_ERR_SET_GOTO(ret <= 0, ret, OQS_ERROR, err);
ret =
oqs_qs_kem_encaps_keyslot(vpkemctx, NULL, &ctLenPQ, NULL, &secretLenPQ,
oqsx_key->reverse_share ? 0 : 1);
ret = oqs_qs_kem_encaps_keyslot(vpkemctx, NULL, &ctLenPQ, NULL,
&secretLenPQ,
oqsx_key->reverse_share ? 0 : 1);
ON_ERR_SET_GOTO(ret <= 0, ret, OQS_ERROR, err);

*ctlen = ctLenClassical + ctLenPQ;
Expand Down Expand Up @@ -208,7 +211,8 @@ static int oqs_hyb_kem_encaps(void *vpkemctx, unsigned char *ct, size_t *ctlen,

static int oqs_hyb_kem_decaps(void *vpkemctx, unsigned char *secret,
size_t *secretlen, const unsigned char *ct,
size_t ctlen) {
size_t ctlen)
{
int ret = OQS_SUCCESS;
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQSX_KEY *oqsx_key = pkemctx->kem;
Expand Down
70 changes: 40 additions & 30 deletions oqsprov/oqs_kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
#include "oqs_prov.h"

#ifdef NDEBUG
#define OQS_KEM_PRINTF(a)
#define OQS_KEM_PRINTF2(a, b)
#define OQS_KEM_PRINTF3(a, b, c)
# define OQS_KEM_PRINTF(a)
# define OQS_KEM_PRINTF2(a, b)
# define OQS_KEM_PRINTF3(a, b, c)
#else
#define OQS_KEM_PRINTF(a) \
if (getenv("OQSKEM")) \
printf(a)
#define OQS_KEM_PRINTF2(a, b) \
if (getenv("OQSKEM")) \
printf(a, b)
#define OQS_KEM_PRINTF3(a, b, c) \
if (getenv("OQSKEM")) \
printf(a, b, c)
# define OQS_KEM_PRINTF(a) \
if (getenv("OQSKEM")) \
printf(a)
# define OQS_KEM_PRINTF2(a, b) \
if (getenv("OQSKEM")) \
printf(a, b)
# define OQS_KEM_PRINTF3(a, b, c) \
if (getenv("OQSKEM")) \
printf(a, b, c)
#endif // NDEBUG

static OSSL_FUNC_kem_newctx_fn oqs_kem_newctx;
Expand All @@ -51,7 +51,8 @@ typedef struct {

/// Common KEM functions

static void *oqs_kem_newctx(void *provctx) {
static void *oqs_kem_newctx(void *provctx)
{
PROV_OQSKEM_CTX *pkemctx = OPENSSL_zalloc(sizeof(PROV_OQSKEM_CTX));

OQS_KEM_PRINTF("OQS KEM provider called: newctx\n");
Expand All @@ -63,16 +64,17 @@ static void *oqs_kem_newctx(void *provctx) {
return pkemctx;
}

static void oqs_kem_freectx(void *vpkemctx) {
static void oqs_kem_freectx(void *vpkemctx)
{
PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;

OQS_KEM_PRINTF("OQS KEM provider called: freectx\n");
oqsx_key_free(pkemctx->kem);
OPENSSL_free(pkemctx);
}

static int oqs_kem_decapsencaps_init(void *vpkemctx, void *vkem,
int operation) {
static int oqs_kem_decapsencaps_init(void *vpkemctx, void *vkem, int operation)
{
PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;

OQS_KEM_PRINTF3("OQS KEM provider called: _init : New: %p; old: %p \n",
Expand All @@ -86,13 +88,15 @@ static int oqs_kem_decapsencaps_init(void *vpkemctx, void *vkem,
}

static int oqs_kem_encaps_init(void *vpkemctx, void *vkem,
const OSSL_PARAM params[]) {
const OSSL_PARAM params[])
{
OQS_KEM_PRINTF("OQS KEM provider called: encaps_init\n");
return oqs_kem_decapsencaps_init(vpkemctx, vkem, EVP_PKEY_OP_ENCAPSULATE);
}

static int oqs_kem_decaps_init(void *vpkemctx, void *vkem,
const OSSL_PARAM params[]) {
const OSSL_PARAM params[])
{
OQS_KEM_PRINTF("OQS KEM provider called: decaps_init\n");
return oqs_kem_decapsencaps_init(vpkemctx, vkem, EVP_PKEY_OP_DECAPSULATE);
}
Expand All @@ -101,7 +105,8 @@ static int oqs_kem_decaps_init(void *vpkemctx, void *vkem,

static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out,
size_t *outlen, unsigned char *secret,
size_t *secretlen, int keyslot) {
size_t *secretlen, int keyslot)
{
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQS_KEM *kem_ctx = NULL;

Expand All @@ -112,8 +117,8 @@ static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out,
}

kem_ctx = pkemctx->kem->oqsx_provider_ctx.oqsx_qs_ctx.kem;
if (pkemctx->kem->comp_pubkey == NULL ||
pkemctx->kem->comp_pubkey[keyslot] == NULL) {
if (pkemctx->kem->comp_pubkey == NULL
|| pkemctx->kem->comp_pubkey[keyslot] == NULL) {
OQS_KEM_PRINTF("OQS Warning: public key is NULL\n");
return -1;
}
Expand Down Expand Up @@ -145,13 +150,15 @@ static int oqs_qs_kem_encaps_keyslot(void *vpkemctx, unsigned char *out,
*outlen = kem_ctx->length_ciphertext;
*secretlen = kem_ctx->length_shared_secret;

return OQS_SUCCESS == OQS_KEM_encaps(kem_ctx, out, secret,
pkemctx->kem->comp_pubkey[keyslot]);
return OQS_SUCCESS
== OQS_KEM_encaps(kem_ctx, out, secret,
pkemctx->kem->comp_pubkey[keyslot]);
}

static int oqs_qs_kem_decaps_keyslot(void *vpkemctx, unsigned char *out,
size_t *outlen, const unsigned char *in,
size_t inlen, int keyslot) {
size_t inlen, int keyslot)
{
const PROV_OQSKEM_CTX *pkemctx = (PROV_OQSKEM_CTX *)vpkemctx;
const OQS_KEM *kem_ctx = NULL;

Expand All @@ -161,8 +168,8 @@ static int oqs_qs_kem_decaps_keyslot(void *vpkemctx, unsigned char *out,
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) {
if (pkemctx->kem->comp_privkey == NULL
|| pkemctx->kem->comp_privkey[keyslot] == NULL) {
OQS_KEM_PRINTF("OQS Warning: private key is NULL\n");
return -1;
}
Expand Down Expand Up @@ -192,18 +199,21 @@ static int oqs_qs_kem_decaps_keyslot(void *vpkemctx, unsigned char *out,
}
*outlen = kem_ctx->length_shared_secret;

return OQS_SUCCESS == OQS_KEM_decaps(kem_ctx, out, in,
pkemctx->kem->comp_privkey[keyslot]);
return OQS_SUCCESS
== OQS_KEM_decaps(kem_ctx, out, in,
pkemctx->kem->comp_privkey[keyslot]);
}

static int oqs_qs_kem_encaps(void *vpkemctx, unsigned char *out, size_t *outlen,
unsigned char *secret, size_t *secretlen) {
unsigned char *secret, size_t *secretlen)
{
return oqs_qs_kem_encaps_keyslot(vpkemctx, out, outlen, secret, secretlen,
0);
}

static int oqs_qs_kem_decaps(void *vpkemctx, unsigned char *out, size_t *outlen,
const unsigned char *in, size_t inlen) {
const unsigned char *in, size_t inlen)
{
return oqs_qs_kem_decaps_keyslot(vpkemctx, out, outlen, in, inlen, 0);
}

Expand Down
Loading

0 comments on commit 54dc4e5

Please sign in to comment.