From: Andreas Steffen Date: Fri, 7 Mar 2014 14:43:42 +0000 (+0100) Subject: Refactored ntru_param_sets X-Git-Tag: 5.1.3dr1~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7befce8c3f3621a556a41e862b7212425904fdbd;p=thirdparty%2Fstrongswan.git Refactored ntru_param_sets --- diff --git a/src/libstrongswan/plugins/ntru/Makefile.am b/src/libstrongswan/plugins/ntru/Makefile.am index b33cbc8c9b..d5bf8b9f7a 100644 --- a/src/libstrongswan/plugins/ntru/Makefile.am +++ b/src/libstrongswan/plugins/ntru/Makefile.am @@ -15,6 +15,7 @@ libstrongswan_ntru_la_SOURCES = \ ntru_drbg.h ntru_drbg.c \ ntru_ke.h ntru_ke.c \ ntru_mgf1.h ntru_mgf1.c \ + ntru_param_set.h ntru_param_set.c \ ntru_poly.h ntru_poly.c \ ntru_trits.h ntru_trits.c \ ntru_crypto/ntru_crypto.h \ @@ -23,8 +24,6 @@ libstrongswan_ntru_la_SOURCES = \ ntru_crypto/ntru_crypto_ntru_encrypt.c \ ntru_crypto/ntru_crypto_ntru_encrypt_key.h \ ntru_crypto/ntru_crypto_ntru_encrypt_key.c \ - ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.h \ - ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.c \ ntru_crypto/ntru_crypto_ntru_poly.h \ ntru_crypto/ntru_crypto_ntru_poly.c diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto.h b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto.h index 72f47035e0..677b6d0ad0 100644 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto.h +++ b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto.h @@ -36,6 +36,7 @@ #include +#include "ntru_param_set.h" #include "ntru_drbg.h" #if !defined( NTRUCALL ) @@ -51,28 +52,6 @@ #endif #endif /* NTRUCALL */ -/* parameter set ID list */ - -typedef enum _NTRU_ENCRYPT_PARAM_SET_ID { - NTRU_EES401EP1, - NTRU_EES449EP1, - NTRU_EES677EP1, - NTRU_EES1087EP2, - NTRU_EES541EP1, - NTRU_EES613EP1, - NTRU_EES887EP1, - NTRU_EES1171EP1, - NTRU_EES659EP1, - NTRU_EES761EP1, - NTRU_EES1087EP1, - NTRU_EES1499EP1, - NTRU_EES401EP2, - NTRU_EES439EP1, - NTRU_EES593EP1, - NTRU_EES743EP1, -} NTRU_ENCRYPT_PARAM_SET_ID; - - /* error codes */ #define NTRU_OK 0 @@ -219,7 +198,7 @@ ntru_crypto_ntru_decrypt( NTRUCALL ntru_crypto_ntru_encrypt_keygen( ntru_drbg_t *drbg, /* in - handle of DRBG */ - NTRU_ENCRYPT_PARAM_SET_ID param_set_id, /* in - parameter set ID */ + ntru_param_set_id_t param_set_id, /* in - parameter set ID */ uint16_t *pubkey_blob_len, /* in/out - no. of octets in pubkey_blob, addr for no. of octets diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt.c b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt.c index dba81915af..8ebcf2c3f4 100644 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt.c +++ b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt.c @@ -36,11 +36,11 @@ #include #include #include "ntru_crypto.h" -#include "ntru_crypto_ntru_encrypt_param_sets.h" #include "ntru_crypto_ntru_encrypt_key.h" #include "ntru_crypto_ntru_convert.h" #include "ntru_crypto_ntru_poly.h" -# + +#include "ntru_param_set.h" #include "ntru_trits.h" #include "ntru_poly.h" @@ -87,7 +87,7 @@ ntru_crypto_ntru_encrypt( no. of octets in ciphertext */ uint8_t *ct) /* out - address for ciphertext */ { - NTRU_ENCRYPT_PARAM_SET *params = NULL; + ntru_param_set_t *params = NULL; uint8_t const *pubkey_packed = NULL; uint8_t pubkey_pack_type = 0x00; uint16_t packed_ct_len; @@ -216,7 +216,7 @@ ntru_crypto_ntru_encrypt( { /* form sData (OID || m || b || hTrunc) */ - memcpy(ptr, params->OID, 3); + memcpy(ptr, params->oid, 3); ptr += 3; memcpy(ptr, pt, pt_len); ptr += pt_len; @@ -411,7 +411,7 @@ ntru_crypto_ntru_decrypt( no. of octets in plaintext */ uint8_t *pt) /* out - address for plaintext */ { - NTRU_ENCRYPT_PARAM_SET *params = NULL; + ntru_param_set_t *params = NULL; uint8_t const *privkey_packed = NULL; uint8_t const *pubkey_packed = NULL; uint8_t privkey_pack_type = 0x00; @@ -691,7 +691,7 @@ ntru_crypto_ntru_decrypt( /* form sData (OID || m || b || hTrunc) */ ptr = tmp_buf; - memcpy(ptr, params->OID, 3); + memcpy(ptr, params->oid, 3); ptr += 3; memcpy(ptr, m_buf, cm_len); ptr += cm_len; @@ -803,7 +803,7 @@ ntru_crypto_ntru_decrypt( uint32_t ntru_crypto_ntru_encrypt_keygen( ntru_drbg_t *drbg, /* in - handle of DRBG */ - NTRU_ENCRYPT_PARAM_SET_ID param_set_id, /* in - parameter set ID */ + ntru_param_set_id_t param_set_id, /* in - parameter set ID */ uint16_t *pubkey_blob_len, /* in/out - no. of octets in pubkey_blob, addr for no. of octets @@ -817,7 +817,7 @@ ntru_crypto_ntru_encrypt_keygen( uint8_t *privkey_blob) /* out - address for private key blob */ { - NTRU_ENCRYPT_PARAM_SET *params = NULL; + ntru_param_set_t *params = NULL; uint16_t public_key_blob_len; uint16_t private_key_blob_len; uint8_t pubkey_pack_type; @@ -840,22 +840,20 @@ ntru_crypto_ntru_encrypt_keygen( ntru_poly_t *g_poly = NULL; uint16_t *F_indices; - /* get a pointer to the parameter-set parameters */ - - if ((params = ntru_encrypt_get_params_with_id(param_set_id)) == NULL) + /* get a pointer to the parameter-set parameters */ + params = ntru_param_set_get_by_id(param_set_id); + if (!params) { return NTRU_INVALID_PARAMETER_SET; } /* check for bad parameters */ - if (!pubkey_blob_len || !privkey_blob_len) { return NTRU_BAD_PARAMETER; } /* get public and private key packing types and blob lengths */ - ntru_crypto_ntru_encrypt_key_get_blob_params(params, &pubkey_pack_type, &public_key_blob_len, &privkey_pack_type, diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.c b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.c index 90baaadf31..dec6bbc8ef 100644 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.c +++ b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.c @@ -60,7 +60,7 @@ ntru_crypto_ntru_encrypt_key_parse( packing type */ uint8_t *privkey_pack_type, /* out - addr for privkey packing type */ - NTRU_ENCRYPT_PARAM_SET **params, /* out - addr for ptr to + ntru_param_set_t **params, /* out - addr for ptr to parameter set */ uint8_t const **pubkey, /* out - addr for ptr to packed pubkey */ @@ -69,14 +69,7 @@ ntru_crypto_ntru_encrypt_key_parse( { uint8_t tag; - assert(key_blob_len); - assert(key_blob); - assert(pubkey_pack_type); - assert(params); - assert(pubkey); - /* parse key blob based on tag */ - tag = key_blob[0]; switch (tag) { case NTRU_ENCRYPT_PUBKEY_TAG: @@ -110,7 +103,7 @@ ntru_crypto_ntru_encrypt_key_parse( */ { - NTRU_ENCRYPT_PARAM_SET *p = NULL; + ntru_param_set_t *p = NULL; uint16_t pubkey_packed_len; /* check OID length and minimum blob length for tag and OID */ @@ -118,10 +111,12 @@ ntru_crypto_ntru_encrypt_key_parse( if ((key_blob_len < 5) || (key_blob[1] != 3)) return FALSE; - /* get a pointer to the parameter set corresponding to the OID */ - - if ((p = ntru_encrypt_get_params_with_OID(key_blob + 2)) == NULL) - return FALSE; + /* get a pointer to the parameter set corresponding to the OID */ + p = ntru_param_set_get_by_oid(key_blob + 2); + if (!p) + { + return FALSE; + } /* check blob length and assign pointers to blob fields */ @@ -203,7 +198,7 @@ ntru_crypto_ntru_encrypt_key_parse( void ntru_crypto_ntru_encrypt_key_get_blob_params( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint8_t *pubkey_pack_type, /* out - addr for pubkey @@ -260,7 +255,7 @@ ntru_crypto_ntru_encrypt_key_get_blob_params( void ntru_crypto_ntru_encrypt_key_create_pubkey_blob( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint16_t const *pubkey, /* in - pointer to the @@ -278,9 +273,9 @@ ntru_crypto_ntru_encrypt_key_create_pubkey_blob( switch (pubkey_pack_type) { case NTRU_ENCRYPT_KEY_PACKED_COEFFICIENTS: *pubkey_blob++ = NTRU_ENCRYPT_PUBKEY_TAG; - *pubkey_blob++ = (uint8_t)sizeof(params->OID); - memcpy(pubkey_blob, params->OID, sizeof(params->OID)); - pubkey_blob += sizeof(params->OID); + *pubkey_blob++ = (uint8_t)sizeof(params->oid); + memcpy(pubkey_blob, params->oid, sizeof(params->oid)); + pubkey_blob += sizeof(params->oid); ntru_elements_2_octets(params->N, pubkey, params->q_bits, pubkey_blob); break; @@ -297,7 +292,7 @@ ntru_crypto_ntru_encrypt_key_create_pubkey_blob( void ntru_crypto_ntru_encrypt_key_create_privkey_blob( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint16_t const *pubkey, /* in - pointer to the @@ -324,9 +319,9 @@ ntru_crypto_ntru_encrypt_key_create_privkey_blob( /* format header and packed public key */ *privkey_blob++ = NTRU_ENCRYPT_PRIVKEY_DEFAULT_TAG; - *privkey_blob++ = (uint8_t)sizeof(params->OID); - memcpy(privkey_blob, params->OID, sizeof(params->OID)); - privkey_blob += sizeof(params->OID); + *privkey_blob++ = (uint8_t)sizeof(params->oid); + memcpy(privkey_blob, params->oid, sizeof(params->oid)); + privkey_blob += sizeof(params->oid); ntru_elements_2_octets(params->N, pubkey, params->q_bits, privkey_blob); privkey_blob += (params->N * params->q_bits + 7) >> 3; diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.h b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.h index 6734f2a4cd..c38c3fc27d 100644 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.h +++ b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_key.h @@ -27,8 +27,8 @@ #define NTRU_CRYPTO_NTRU_ENCRYPT_KEY_H #include "ntru_crypto_ntru_convert.h" -#include "ntru_crypto_ntru_encrypt_param_sets.h" +#include "ntru_param_set.h" /* key-blob definitions */ @@ -68,7 +68,7 @@ ntru_crypto_ntru_encrypt_key_parse( packing type */ uint8_t *privkey_pack_type, /* out - addr for privkey packing type */ - NTRU_ENCRYPT_PARAM_SET **params, /* out - addr for ptr to + ntru_param_set_t **params, /* out - addr for ptr to parameter set */ uint8_t const **pubkey, /* out - addr for ptr to packed pubkey */ @@ -87,7 +87,7 @@ ntru_crypto_ntru_encrypt_key_parse( extern void ntru_crypto_ntru_encrypt_key_get_blob_params( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint8_t *pubkey_pack_type, /* out - addr for pubkey @@ -109,7 +109,7 @@ ntru_crypto_ntru_encrypt_key_get_blob_params( extern void ntru_crypto_ntru_encrypt_key_create_pubkey_blob( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint16_t const *pubkey, /* in - pointer to the @@ -128,7 +128,7 @@ ntru_crypto_ntru_encrypt_key_create_pubkey_blob( extern void ntru_crypto_ntru_encrypt_key_recreate_pubkey_blob( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint16_t packed_pubkey_len, /* in - no. octets in @@ -148,7 +148,7 @@ ntru_crypto_ntru_encrypt_key_recreate_pubkey_blob( extern void ntru_crypto_ntru_encrypt_key_create_privkey_blob( - NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to + ntru_param_set_t *params, /* in - pointer to param set parameters */ uint16_t const *pubkey, /* in - pointer to the diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.h b/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.h deleted file mode 100644 index e5e977a0ed..0000000000 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.h +++ /dev/null @@ -1,101 +0,0 @@ -/****************************************************************************** - * NTRU Cryptography Reference Source Code - * Copyright (c) 2009-2013, by Security Innovation, Inc. All rights reserved. - * - * ntru_crypto_ntru_encrypt_param_sets.h is a component of ntru-crypto. - * - * Copyright (C) 2009-2013 Security Innovation - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - *****************************************************************************/ - -/****************************************************************************** - * - * File: ntru_crypto_ntru_encrypt_param_sets.h - * - * Contents: Definitions and declarations for the NTRUEncrypt parameter sets. - * - *****************************************************************************/ - -#ifndef NTRU_CRYPTO_NTRU_ENCRYPT_PARAM_SETS_H -#define NTRU_CRYPTO_NTRU_ENCRYPT_PARAM_SETS_H - -#include "ntru_crypto.h" - -/* structures */ - -typedef struct _NTRU_ENCRYPT_PARAM_SET { - NTRU_ENCRYPT_PARAM_SET_ID id; /* parameter-set ID */ - uint8_t const OID[3]; /* pointer to OID */ - uint8_t der_id; /* parameter-set DER id */ - uint8_t N_bits; /* no. of bits in N (i.e. in - an index */ - uint16_t N; /* ring dimension */ - uint16_t sec_strength_len; /* no. of octets of - security strength */ - uint16_t q; /* big modulus */ - uint8_t q_bits; /* no. of bits in q (i.e. in - a coefficient */ - bool is_product_form; /* if product form used */ - uint32_t dF_r; /* no. of 1 or -1 coefficients - in ring elements F, r */ - uint16_t dg; /* no. - 1 of 1 coefficients - or no. of -1 coefficients - in ring element g */ - uint16_t m_len_max; /* max no. of plaintext - octets */ - uint16_t min_msg_rep_wt; /* min. message - representative weight */ - uint8_t c_bits; /* no. bits in candidate for - deriving an index in - IGF-2 */ - uint8_t m_len_len; /* no. of octets to hold - mLenOctets */ -} NTRU_ENCRYPT_PARAM_SET; - - - -/* function declarations */ - -/* ntru_encrypt_get_params_with_id - * - * Looks up a set of NTRU Encrypt parameters based on the id of the - * parameter set. - * - * Returns a pointer to the parameter set parameters if successful. - * Returns NULL if the parameter set cannot be found. - */ - -extern NTRU_ENCRYPT_PARAM_SET * -ntru_encrypt_get_params_with_id( - NTRU_ENCRYPT_PARAM_SET_ID id); /* in - parameter-set id */ - - -/* ntru_encrypt_get_params_with_OID - * - * Looks up a set of NTRU Encrypt parameters based on the OID of the - * parameter set. - * - * Returns a pointer to the parameter set parameters if successful. - * Returns NULL if the parameter set cannot be found. - */ - -extern NTRU_ENCRYPT_PARAM_SET * -ntru_encrypt_get_params_with_OID( - uint8_t const *oid); /* in - pointer to parameter-set OID */ - -#endif /* NTRU_CRYPTO_NTRU_ENCRYPT_PARAM_SETS_H */ - diff --git a/src/libstrongswan/plugins/ntru/ntru_ke.c b/src/libstrongswan/plugins/ntru/ntru_ke.c index 39fb261cd1..a954ed102e 100644 --- a/src/libstrongswan/plugins/ntru/ntru_ke.c +++ b/src/libstrongswan/plugins/ntru/ntru_ke.c @@ -15,6 +15,7 @@ #include "ntru_ke.h" #include "ntru_drbg.h" +#include "ntru_param_set.h" #include "ntru_crypto/ntru_crypto.h" @@ -28,7 +29,7 @@ typedef struct param_set_t param_set_t; * Defines an NTRU parameter set by ID or OID */ struct param_set_t { - NTRU_ENCRYPT_PARAM_SET_ID id; + ntru_param_set_id_t id; char oid[3]; char *name; }; diff --git a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.c b/src/libstrongswan/plugins/ntru/ntru_param_set.c similarity index 84% rename from src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.c rename to src/libstrongswan/plugins/ntru/ntru_param_set.c index 5ddf91d2a7..0d8a774e12 100644 --- a/src/libstrongswan/plugins/ntru/ntru_crypto/ntru_crypto_ntru_encrypt_param_sets.c +++ b/src/libstrongswan/plugins/ntru/ntru_param_set.c @@ -1,43 +1,26 @@ -/****************************************************************************** - * NTRU Cryptography Reference Source Code - * Copyright (c) 2009-2013, by Security Innovation, Inc. All rights reserved. - * - * ntru_crypto_ntru_param_sets.c is a component of ntru-crypto. +/* + * Copyright (C) 2014 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil * * Copyright (C) 2009-2013 Security Innovation - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - *****************************************************************************/ - -/****************************************************************************** - * - * File: ntru_crypto_ntru_encrypt_param_sets.c * - * Contents: Defines the NTRUEncrypt parameter sets. + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . * - *****************************************************************************/ - -#include -#include -#include "ntru_crypto_ntru_encrypt_param_sets.h" - + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ -/* parameter sets */ +#include "ntru_param_set.h" -static NTRU_ENCRYPT_PARAM_SET ntruParamSets[] = { +/** + * NTRU encryption parameter set definitions + */ +static ntru_param_set_t ntru_param_sets[] = { { NTRU_EES401EP1, /* parameter-set id */ @@ -329,56 +312,38 @@ static NTRU_ENCRYPT_PARAM_SET ntruParamSets[] = { }; -static size_t numParamSets = - sizeof(ntruParamSets)/sizeof(NTRU_ENCRYPT_PARAM_SET); - - -/* functions */ - -/* ntru_encrypt_get_params_with_id - * - * Looks up a set of NTRUEncrypt parameters based on the id of the - * parameter set. - * - * Returns a pointer to the parameter set parameters if successful. - * Returns NULL if the parameter set cannot be found. +/** + * See header. */ - -NTRU_ENCRYPT_PARAM_SET * -ntru_encrypt_get_params_with_id( - NTRU_ENCRYPT_PARAM_SET_ID id) /* in - parameter-set id */ +ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id) { - size_t i; - - for (i = 0; i < numParamSets; i++) { - if (ntruParamSets[i].id == id) { - return &(ntruParamSets[i]); - } - } - return NULL; + int i; + + for (i = 0; i < countof(ntru_param_sets); i++) + { + if (ntru_param_sets[i].id == id) + { + return &ntru_param_sets[i]; + } + } + return NULL; } -/* ntru_encrypt_get_params_with_OID - * - * Looks up a set of NTRUEncrypt parameters based on the OID of the - * parameter set. - * - * Returns a pointer to the parameter set parameters if successful. - * Returns NULL if the parameter set cannot be found. +/** + * See header. */ - -NTRU_ENCRYPT_PARAM_SET * -ntru_encrypt_get_params_with_OID( - uint8_t const *oid) /* in - pointer to parameter-set OID */ +ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid) { - size_t i; - - for (i = 0; i < numParamSets; i++) { - if (!memcmp(ntruParamSets[i].OID, oid, 3)) { - return &(ntruParamSets[i]); - } - } - return NULL; + int i; + + for (i = 0; i < countof(ntru_param_sets); i++) + { + if (memeq(ntru_param_sets[i].oid, oid, 3)) + { + return &ntru_param_sets[i]; + } + } + return NULL; } diff --git a/src/libstrongswan/plugins/ntru/ntru_param_set.h b/src/libstrongswan/plugins/ntru/ntru_param_set.h new file mode 100644 index 0000000000..548e866a17 --- /dev/null +++ b/src/libstrongswan/plugins/ntru/ntru_param_set.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2014 Andreas Steffen + * HSR Hochschule fuer Technik Rapperswil + * + * Copyright (C) 2009-2013 Security Innovation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +/** + * @defgroup ntru_param_set ntru_param_set + * @{ @ingroup ntru_p + */ + +#ifndef NTRU_PARAM_SET_H_ +#define NTRU_PARAM_SET_H_ + +typedef enum ntru_param_set_id_t ntru_param_set_id_t; +typedef struct ntru_param_set_t ntru_param_set_t; + +#include + +/** + * NTRU encryption parameter set ID list + */ +enum ntru_param_set_id_t { + NTRU_EES401EP1, + NTRU_EES449EP1, + NTRU_EES677EP1, + NTRU_EES1087EP2, + NTRU_EES541EP1, + NTRU_EES613EP1, + NTRU_EES887EP1, + NTRU_EES1171EP1, + NTRU_EES659EP1, + NTRU_EES761EP1, + NTRU_EES1087EP1, + NTRU_EES1499EP1, + NTRU_EES401EP2, + NTRU_EES439EP1, + NTRU_EES593EP1, + NTRU_EES743EP1, +}; + +/** + * NTRU encryption parameter set definitions + */ +struct ntru_param_set_t { + ntru_param_set_id_t id; /* NTRU parameter set ID */ + uint8_t oid[3]; /* pointer to OID */ + uint8_t der_id; /* parameter-set DER id */ + uint8_t N_bits; /* no. of bits in N (i.e. in an index */ + uint16_t N; /* ring dimension */ + uint16_t sec_strength_len; /* no. of octets of security strength */ + uint16_t q; /* big modulus */ + uint8_t q_bits; /* no. of bits in q (i.e. in a coefficient */ + bool is_product_form; /* if product form used */ + uint32_t dF_r; /* no. of +1 or -1 coefficients in ring elements + F, r */ + uint16_t dg; /* no. - 1 of +1 coefficients or + no. of -1 coefficients in ring element g */ + uint16_t m_len_max; /* max no. of plaintext octets */ + uint16_t min_msg_rep_wt; /* min. message representative weight */ + uint8_t c_bits; /* no. bits in candidate for deriving an index */ + uint8_t m_len_len; /* no. of octets to hold mLenOctets */ +}; + +/** + * Get NTRU encryption parameter set by NTRU parameter set ID + * + * @param id NTRU parameter set ID + * @return NTRU parameter set +*/ +ntru_param_set_t* ntru_param_set_get_by_id(ntru_param_set_id_t id); + +/** + * Get NTRU encryption parameter set by NTRU parameter set OID + * + * @param oid NTRU parameter set OID + * @return NTRU parameter set +*/ +ntru_param_set_t* ntru_param_set_get_by_oid(uint8_t const *oid); + +#endif /** NTRU_PARAM_SET_H_ @}*/ +