From 1f8bd54c5aaf6a682a92b244bca21585070c9b81 Mon Sep 17 00:00:00 2001 From: avc <avc@debian> Date: Tue, 17 Apr 2018 20:05:11 +0300 Subject: [PATCH] added with tests --- crypto/dap_enc_key.c | 12 ++++++++++++ crypto/dap_enc_key.h | 1 - crypto/dap_enc_sidh16.c | 10 +++++----- crypto/dap_enc_sidh16.h | 18 +++++++++++++++++- crypto/liboqs/kex/kex.h | 9 ++++++--- crypto/liboqs/kex_sidh_cln16/SIDH.h | 3 ++- crypto/liboqs/kex_sidh_cln16/SIDH_internal.h | 2 +- crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h | 6 ++++-- 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/crypto/dap_enc_key.c b/crypto/dap_enc_key.c index 498cf8b17b..8336daeb0f 100644 --- a/crypto/dap_enc_key.c +++ b/crypto/dap_enc_key.c @@ -25,6 +25,7 @@ #include "dap_enc_aes.h" #include "dap_enc_newhope.h" +#include "dap_enc_sidh16.h" #include "dap_enc_key.h" @@ -67,6 +68,17 @@ struct dap_enc_key_callbacks{ .new_from_data_callback = dap_enc_newhope_key_new_from_data, .key_public_raw_callback = dap_enc_newhope_key_public_raw, .new_from_data_public_callback = dap_enc_newhope_key_new_from_data_public + }, + + [DAP_ENC_KEY_TYPE_SIDH_CLN16]={ + .name = "SIDHCLN16", + .size_max = 64, + .enc = dap_enc_sidh16_encode, + .dec = dap_enc_sidh16_decode, + .new_callback = NULL, + .delete_callback = NULL, + .new_generate_callback = dap_enc_sidh16_key_new_generate, + .new_from_data_callback = dap_enc_sidh16_key_new_from_data } }; diff --git a/crypto/dap_enc_key.h b/crypto/dap_enc_key.h index 739d2a1dd6..449265b4c0 100644 --- a/crypto/dap_enc_key.h +++ b/crypto/dap_enc_key.h @@ -105,7 +105,6 @@ typedef struct dap_enc_key{ dap_enc_callback_dataop_t enc; dap_enc_callback_dataop_t dec; dap_enc_callback_t delete_callback; - void * _inheritor; } dap_enc_key_t; diff --git a/crypto/dap_enc_sidh16.c b/crypto/dap_enc_sidh16.c index 8a8305bd02..e9f56af21c 100644 --- a/crypto/dap_enc_sidh16.c +++ b/crypto/dap_enc_sidh16.c @@ -5,12 +5,12 @@ #include <string.h> #include <stdbool.h> -#include "dap_common.h" #include "dap_enc_sidh16.h" -#include "kex_sidh_cln16.h" #include "dap_enc_key.h" -#include "SIDH.h" +#include <../libdap/core/dap_common.h> +#include <../libdap/crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h> +#include <../libdap/crypto/liboqs/kex_sidh_cln16/SIDH.h> static const char *P751 = "p751"; static const char *CompressedP751 = "compressedp751"; @@ -44,7 +44,7 @@ dap_enc_key_t *dap_enc_sidh16_key_new_generate(struct dap_enc_key *a_key, size_t oqs_sidh_cln16_curve_free(curveIsogeny); return NULL; } - k->data ; + k->data; k->data_size; k->type = DAP_ENC_KEY_TYPE_SIDH_CLN16; k->last_used_timestamp; @@ -139,7 +139,7 @@ size_t dap_enc_sidh16_encode(struct dap_enc_key *a_key, const void *a_in, size_t // int OQS_KEX_sidh_cln16_bob(OQS_KEX *k, const uint8_t *alice_msg, const size_t alice_msg_len, uint8_t **bob_msg, size_t *bob_msg_len, uint8_t **key, size_t *key_len) size_t dap_enc_sidh16_decode(struct dap_enc_key *a_key, const void *a_in, size_t a_in_size, void *a_out) { - int ret; + size_t ret; dap_enc_sidh16_key_t *sidh_a_key = DAP_ENC_SIDH16_KEY(a_key); uint8_t *bob_priv = NULL; // non-compressed public key diff --git a/crypto/dap_enc_sidh16.h b/crypto/dap_enc_sidh16.h index 606780b124..169cea09bd 100644 --- a/crypto/dap_enc_sidh16.h +++ b/crypto/dap_enc_sidh16.h @@ -10,19 +10,35 @@ #include "dap_common.h" #include "dap_enc_key.h" +#include <../libdap/crypto/liboqs/kex_sidh_cln16/SIDH.h> +#include <../libdap/crypto/liboqs/kex/kex.h> + -#include "SIDH.h" struct dap_enc_key; +extern bool dap_sidh16_CurveIsogenyStruct_isnull(PCurveIsogenyStruct pCurveIsogeny); + typedef struct dap_enc_sidh16_key{ OQS_RAND *rand; void * user_curveIsogeny; unsigned int alice_msg_len; unsigned int bob_msg_len; unsigned int key_len; + uint16_t estimated_classical_security; + uint16_t estimated_quantum_security; } dap_enc_sidh16_key_t; +struct dapenc_testcase { + enum OQS_KEX_alg_name alg_name; + unsigned char *seed; + size_t seed_len; + char *named_parameters; + char *id; + int run; + int iter; +}; + #define DAP_ENC_SIDH16_KEY(a) ((dap_enc_sidh16_key_t *)((a)->_inheritor)) dap_enc_key_t *dap_enc_sidh16_key_new_generate(struct dap_enc_key* a_key, size_t a_size); // new diff --git a/crypto/liboqs/kex/kex.h b/crypto/liboqs/kex/kex.h index 0decdf874b..ea8948ae13 100644 --- a/crypto/liboqs/kex/kex.h +++ b/crypto/liboqs/kex/kex.h @@ -9,10 +9,13 @@ #include <stddef.h> #include <stdint.h> -#include <oqs/rand.h> +//#include <oqs/rand.h> +#include <../libdap/crypto/liboqs/crypto/rand/rand.h> + #if !defined(WINDOWS) -#include <oqs/config.h> +//#include <oqs/config.h> +#include <../libdap/crypto/liboqs/config.h> #endif enum OQS_KEX_alg_name { @@ -93,7 +96,7 @@ typedef struct OQS_KEX { * @param alice_msg_len Alice's message length * @return 1 on success, or 0 on failure */ - int (*alice_0)(OQS_KEX *k, void **alive_priv, uint8_t **alice_msg, size_t *alice_msg_len); + int (*alice_0)(OQS_KEX *k, void **alice_priv, uint8_t **alice_msg, size_t *alice_msg_len); /** * Pointer to a function for shared key generation by Bob. diff --git a/crypto/liboqs/kex_sidh_cln16/SIDH.h b/crypto/liboqs/kex_sidh_cln16/SIDH.h index 762ea99b60..5f0ba90b91 100644 --- a/crypto/liboqs/kex_sidh_cln16/SIDH.h +++ b/crypto/liboqs/kex_sidh_cln16/SIDH.h @@ -17,7 +17,8 @@ extern "C" { #endif -#include <oqs/rand.h> +//#include <../libdap/crypto/rand.h> //<oqs/rand.h> +#include <../libdap/crypto/liboqs/crypto/rand/rand.h> #include <stdint.h> #include <stdbool.h> #include <stddef.h> diff --git a/crypto/liboqs/kex_sidh_cln16/SIDH_internal.h b/crypto/liboqs/kex_sidh_cln16/SIDH_internal.h index 82a4a101b9..97fdde84c3 100644 --- a/crypto/liboqs/kex_sidh_cln16/SIDH_internal.h +++ b/crypto/liboqs/kex_sidh_cln16/SIDH_internal.h @@ -23,7 +23,7 @@ extern "C" { #define UNUSED __attribute__((unused)) #endif -#include "SIDH.h" +#include <../libdap/crypto/liboqs/kex_sidh_cln16/SIDH.h> // Basic constants diff --git a/crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h b/crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h index 4409db7a6f..15385d6f9a 100644 --- a/crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h +++ b/crypto/liboqs/kex_sidh_cln16/kex_sidh_cln16.h @@ -9,8 +9,10 @@ #include <stddef.h> #include <stdint.h> -#include <oqs/kex.h> -#include <oqs/rand.h> +//#include <oqs/kex.h> +#include <../libdap/crypto/liboqs/kex/kex.h> +//#include <oqs/rand.h> +#include <../libdap/crypto/liboqs/crypto/rand/rand.h> OQS_KEX *OQS_KEX_sidh_cln16_new(OQS_RAND *rand, const char *named_parameters); -- GitLab