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 \
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
#include <library.h>
+#include "ntru_param_set.h"
#include "ntru_drbg.h"
#if !defined( NTRUCALL )
#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
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
#include <string.h>
#include <assert.h>
#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"
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;
{
/* 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;
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;
/* 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;
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
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;
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,
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 */
{
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:
*/
{
- 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 */
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 */
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
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
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;
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
/* 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;
#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 */
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 */
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
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
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
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
+++ /dev/null
-/******************************************************************************
- * 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 */
-
#include "ntru_ke.h"
#include "ntru_drbg.h"
+#include "ntru_param_set.h"
#include "ntru_crypto/ntru_crypto.h"
* 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;
};
-/******************************************************************************
- * 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 <http://www.fsf.org/copyleft/gpl.txt>.
*
- *****************************************************************************/
-
-#include <stdlib.h>
-#include <string.h>
-#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 */
};
-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;
}
--- /dev/null
+/*
+ * 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 <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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 <library.h>
+
+/**
+ * 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_ @}*/
+