Cleaned up ntru-crypto library
This commit is contained in:
@@ -34,9 +34,10 @@
|
|||||||
#ifndef NTRU_CRYPTO_H
|
#ifndef NTRU_CRYPTO_H
|
||||||
#define NTRU_CRYPTO_H
|
#define NTRU_CRYPTO_H
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
|
||||||
#include "ntru_crypto_error.h"
|
#include "ntru_crypto_error.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
#include "ntru_drbg.h"
|
#include "ntru_drbg.h"
|
||||||
|
|
||||||
#if !defined( NTRUCALL )
|
#if !defined( NTRUCALL )
|
||||||
@@ -52,11 +53,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif /* NTRUCALL */
|
#endif /* NTRUCALL */
|
||||||
|
|
||||||
#if defined ( __cplusplus )
|
|
||||||
extern "C" {
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
|
||||||
/* parameter set ID list */
|
/* parameter set ID list */
|
||||||
|
|
||||||
typedef enum _NTRU_ENCRYPT_PARAM_SET_ID {
|
typedef enum _NTRU_ENCRYPT_PARAM_SET_ID {
|
||||||
@@ -249,90 +245,4 @@ ntru_crypto_ntru_encrypt_keygen(
|
|||||||
in privkey_blob */
|
in privkey_blob */
|
||||||
uint8_t *privkey_blob); /* out - address for
|
uint8_t *privkey_blob); /* out - address for
|
||||||
private key blob */
|
private key blob */
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo
|
|
||||||
*
|
|
||||||
* DER-encodes an NTRUEncrypt public-key from a public-key blob into a
|
|
||||||
* SubjectPublicKeyInfo field for inclusion in an X.509 certificate.
|
|
||||||
*
|
|
||||||
* The required minimum size of the output SubjectPublicKeyInfo buffer
|
|
||||||
* (encoded_subjectPublicKeyInfo) may be queried by invoking this function
|
|
||||||
* with encoded_subjectPublicKeyInfo = NULL. In this case, no encoding is
|
|
||||||
* performed, NTRU_OK is returned, and the required minimum size for
|
|
||||||
* encoded_subjectPublicKeyInfo is returned in encoded_subjectPublicKeyInfo_len.
|
|
||||||
*
|
|
||||||
* When encoded_subjectPublicKeyInfo != NULL, at invocation
|
|
||||||
* *encoded_subjectPublicKeyInfo_len must be the size of the
|
|
||||||
* encoded_subjectPublicKeyInfo buffer.
|
|
||||||
* Upon return, it is the actual size of the encoded public key.
|
|
||||||
*
|
|
||||||
* Returns NTRU_OK if successful.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PARAMETER if an argument pointer
|
|
||||||
* (other than encoded_subjectPublicKeyInfo) is NULL.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_LENGTH if pubkey_blob_len is zero.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PUBLIC_KEY if the public-key blob is
|
|
||||||
* invalid (unknown format, corrupt, bad length).
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BUFFER_TOO_SMALL if the SubjectPublicKeyInfo
|
|
||||||
* buffer is too small.
|
|
||||||
*/
|
|
||||||
|
|
||||||
NTRUCALL
|
|
||||||
ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(
|
|
||||||
uint16_t pubkey_blob_len, /* in - no. of octets in public-key
|
|
||||||
blob */
|
|
||||||
uint8_t const *pubkey_blob, /* in - ptr to public-key blob */
|
|
||||||
uint16_t *encoded_subjectPublicKeyInfo_len,
|
|
||||||
/* in/out - no. of octets in encoded info,
|
|
||||||
address for no. of octets in
|
|
||||||
encoded info */
|
|
||||||
uint8_t *encoded_subjectPublicKeyInfo);
|
|
||||||
/* out - address for encoded info */
|
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_SubjectPublicKeyInfo2PublicKey
|
|
||||||
*
|
|
||||||
* Decodes a DER-encoded NTRUEncrypt public-key from a
|
|
||||||
* SubjectPublicKeyInfo field in an X.509 certificate and returns the
|
|
||||||
* public-key blob itself.
|
|
||||||
*
|
|
||||||
* The required minimum size of the output public-key buffer (pubkey_blob)
|
|
||||||
* may be queried by invoking this function with pubkey_blob = NULL.
|
|
||||||
* In this case, no decoding is performed, NTRU_OK is returned, and the
|
|
||||||
* required minimum size for pubkey_blob is returned in pubkey_blob_len.
|
|
||||||
*
|
|
||||||
* When pubkey_blob != NULL, at invocation *pubkey_blob_len must be the
|
|
||||||
* size of the pubkey_blob buffer.
|
|
||||||
* Upon return, it is the actual size of the public-key blob.
|
|
||||||
*
|
|
||||||
* Returns NTRU_OK if successful.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PARAMETER if an argument pointer
|
|
||||||
* (other than pubkey_blob) is NULL.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_ENCODING if the encoded data is
|
|
||||||
* an invalid encoding of an NTRU public key.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_OID_NOT_RECOGNIZED if the
|
|
||||||
* encoded data contains an OID that identifies an object other than
|
|
||||||
* an NTRU public key.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BUFFER_TOO_SMALL if the pubkey_blob buffer
|
|
||||||
* is too small.
|
|
||||||
*/
|
|
||||||
|
|
||||||
NTRUCALL
|
|
||||||
ntru_crypto_ntru_encrypt_subjectPublicKeyInfo2PublicKey(
|
|
||||||
uint8_t const *encoded_data, /* in - ptr to subjectPublicKeyInfo
|
|
||||||
in the encoded data */
|
|
||||||
uint16_t *pubkey_blob_len, /* in/out - no. of octets in pubkey blob,
|
|
||||||
address for no. of octets in
|
|
||||||
pubkey blob */
|
|
||||||
uint8_t *pubkey_blob, /* out - address for pubkey blob */
|
|
||||||
uint8_t **next); /* out - address for ptr to encoded
|
|
||||||
data following the
|
|
||||||
subjectPublicKeyInfo */
|
|
||||||
|
|
||||||
|
|
||||||
#if defined ( __cplusplus )
|
|
||||||
}
|
|
||||||
#endif /* __cplusplus */
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* NTRU_CRYPTO_H */
|
#endif /* NTRU_CRYPTO_H */
|
||||||
|
|||||||
@@ -33,12 +33,12 @@
|
|||||||
#ifndef NTRU_CRYPTO_HASH_H
|
#ifndef NTRU_CRYPTO_HASH_H
|
||||||
#define NTRU_CRYPTO_HASH_H
|
#define NTRU_CRYPTO_HASH_H
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
|
||||||
#include "ntru_crypto_error.h"
|
#include "ntru_crypto_error.h"
|
||||||
#include "ntru_crypto_hash_basics.h"
|
#include "ntru_crypto_hash_basics.h"
|
||||||
#include "ntru_crypto_sha1.h"
|
#include "ntru_crypto_sha1.h"
|
||||||
#include "ntru_crypto_sha256.h"
|
#include "ntru_crypto_sha256.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
/***************
|
/***************
|
||||||
* error macro *
|
* error macro *
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
#ifndef NTRU_CRYPTO_HASH_BASICS_H
|
#ifndef NTRU_CRYPTO_HASH_BASICS_H
|
||||||
#define NTRU_CRYPTO_HASH_BASICS_H
|
#define NTRU_CRYPTO_HASH_BASICS_H
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
#include <library.h>
|
||||||
|
|
||||||
|
|
||||||
/**************
|
/**************
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
#define NTRU_CRYPTO_MSBYTE_UINT32_H
|
#define NTRU_CRYPTO_MSBYTE_UINT32_H
|
||||||
|
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
#include <library.h>
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_msbyte_2_uint32()
|
/* ntru_crypto_msbyte_2_uint32()
|
||||||
|
|||||||
@@ -1026,278 +1026,3 @@ ntru_crypto_ntru_encrypt_keygen(
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* DER-encoding prefix template for NTRU public keys,
|
|
||||||
* with parameter-set-specific fields nomalized
|
|
||||||
*/
|
|
||||||
|
|
||||||
static uint8_t const der_prefix_template[] = {
|
|
||||||
0x30, 0x82,
|
|
||||||
0x00, 0x23, /* add pubkey length */
|
|
||||||
0x30, 0x18, 0x06, 0x0a, 0x2b, 0x06, 0x01,
|
|
||||||
0x04, 0x01, 0xc1, 0x70, 0x01, 0x01, 0x02, /* end of NTRU OID compare */
|
|
||||||
0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01,
|
|
||||||
0xc1, 0x70, 0x01, 0x02,
|
|
||||||
0x00, /* set param-set DER id */
|
|
||||||
0x03, 0x82,
|
|
||||||
0x00, 0x05, /* add pubkey length */
|
|
||||||
0x00, 0x04, 0x82,
|
|
||||||
0x00, 0x00, /* add pubkey length */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* add_16_to_8s
|
|
||||||
*
|
|
||||||
* adds a 16-bit value to two bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
add_16_to_8s(
|
|
||||||
uint16_t a,
|
|
||||||
uint8_t *b)
|
|
||||||
{
|
|
||||||
uint16_t tmp = ((uint16_t)b[0] << 8) + b[1];
|
|
||||||
|
|
||||||
tmp = tmp + a;
|
|
||||||
b[0] = (uint8_t)((tmp >> 8) & 0xff);
|
|
||||||
b[1] = (uint8_t)(tmp & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* sub_16_from_8s
|
|
||||||
*
|
|
||||||
* subtracts a 16-bit value from two bytes
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void
|
|
||||||
sub_16_from_8s(
|
|
||||||
uint16_t a,
|
|
||||||
uint8_t *b)
|
|
||||||
{
|
|
||||||
uint16_t tmp = ((uint16_t)b[0] << 8) + b[1];
|
|
||||||
|
|
||||||
tmp = tmp - a;
|
|
||||||
b[0] = (uint8_t)((tmp >> 8) & 0xff);
|
|
||||||
b[1] = (uint8_t)(tmp & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo
|
|
||||||
*
|
|
||||||
* DER-encodes an NTRUEncrypt public-key from a public-key blob into a
|
|
||||||
* SubjectPublicKeyInfo field for inclusion in an X.509 certificate.
|
|
||||||
*
|
|
||||||
* The required minimum size of the output SubjectPublicKeyInfo buffer
|
|
||||||
* (encoded_subjectPublicKeyInfo) may be queried by invoking this function
|
|
||||||
* with encoded_subjectPublicKeyInfo = NULL. In this case, no encoding is
|
|
||||||
* performed, NTRU_OK is returned, and the required minimum size for
|
|
||||||
* encoded_subjectPublicKeyInfo is returned in encoded_subjectPublicKeyInfo_len.
|
|
||||||
*
|
|
||||||
* When encoded_subjectPublicKeyInfo != NULL, at invocation
|
|
||||||
* *encoded_subjectPublicKeyInfo_len must be the size of the
|
|
||||||
* encoded_subjectPublicKeyInfo buffer.
|
|
||||||
* Upon return, it is the actual size of the encoded public key.
|
|
||||||
*
|
|
||||||
* Returns NTRU_OK if successful.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PARAMETER if an argument pointer
|
|
||||||
* (other than encoded_subjectPublicKeyInfo) is NULL.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_LENGTH if pubkey_blob_len is zero.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PUBLIC_KEY if the public-key blob is
|
|
||||||
* invalid (unknown format, corrupt, bad length).
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BUFFER_TOO_SMALL if the SubjectPublicKeyInfo
|
|
||||||
* buffer is too small.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
ntru_crypto_ntru_encrypt_publicKey2SubjectPublicKeyInfo(
|
|
||||||
uint16_t pubkey_blob_len, /* in - no. of octets in public-key
|
|
||||||
blob */
|
|
||||||
uint8_t const *pubkey_blob, /* in - ptr to public-key blob */
|
|
||||||
uint16_t *encoded_subjectPublicKeyInfo_len,
|
|
||||||
/* in/out - no. of octets in encoded info,
|
|
||||||
address for no. of octets in
|
|
||||||
encoded info */
|
|
||||||
uint8_t *encoded_subjectPublicKeyInfo)
|
|
||||||
/* out - address for encoded info */
|
|
||||||
{
|
|
||||||
NTRU_ENCRYPT_PARAM_SET *params = NULL;
|
|
||||||
uint8_t const *pubkey_packed = NULL;
|
|
||||||
uint8_t pubkey_pack_type;
|
|
||||||
uint16_t packed_pubkey_len;
|
|
||||||
uint16_t encoded_len;
|
|
||||||
|
|
||||||
/* check for bad parameters */
|
|
||||||
|
|
||||||
if (!pubkey_blob || !encoded_subjectPublicKeyInfo_len)
|
|
||||||
NTRU_RET(NTRU_BAD_PARAMETER);
|
|
||||||
if (pubkey_blob_len == 0)
|
|
||||||
NTRU_RET(NTRU_BAD_LENGTH);
|
|
||||||
|
|
||||||
/* get a pointer to the parameter-set parameters, the packing type for
|
|
||||||
* the public key, and a pointer to the packed public key
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!ntru_crypto_ntru_encrypt_key_parse(TRUE /* pubkey */, pubkey_blob_len,
|
|
||||||
pubkey_blob, &pubkey_pack_type,
|
|
||||||
NULL, ¶ms, &pubkey_packed,
|
|
||||||
NULL))
|
|
||||||
NTRU_RET(NTRU_BAD_PUBLIC_KEY);
|
|
||||||
|
|
||||||
/* return the encoded_subjectPublicKeyInfo size if requested */
|
|
||||||
|
|
||||||
packed_pubkey_len = (params->N * params->q_bits + 7) >> 3;
|
|
||||||
encoded_len = sizeof(der_prefix_template) + packed_pubkey_len;
|
|
||||||
if (!encoded_subjectPublicKeyInfo) {
|
|
||||||
*encoded_subjectPublicKeyInfo_len = encoded_len;
|
|
||||||
NTRU_RET(NTRU_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check the encoded_subjectPublicKeyInfo buffer size */
|
|
||||||
|
|
||||||
if (*encoded_subjectPublicKeyInfo_len < encoded_len) {
|
|
||||||
NTRU_RET(NTRU_BUFFER_TOO_SMALL);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* form the encoded subjectPublicKey */
|
|
||||||
|
|
||||||
memcpy(encoded_subjectPublicKeyInfo, der_prefix_template,
|
|
||||||
sizeof(der_prefix_template));
|
|
||||||
add_16_to_8s(packed_pubkey_len, encoded_subjectPublicKeyInfo + 2);
|
|
||||||
add_16_to_8s(packed_pubkey_len, encoded_subjectPublicKeyInfo + 32);
|
|
||||||
add_16_to_8s(packed_pubkey_len, encoded_subjectPublicKeyInfo + 37);
|
|
||||||
encoded_subjectPublicKeyInfo[29] = params->der_id;
|
|
||||||
memcpy(encoded_subjectPublicKeyInfo + sizeof(der_prefix_template),
|
|
||||||
pubkey_packed, packed_pubkey_len);
|
|
||||||
|
|
||||||
*encoded_subjectPublicKeyInfo_len = encoded_len;
|
|
||||||
|
|
||||||
NTRU_RET(NTRU_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_subjectPublicKeyInfo2PublicKey
|
|
||||||
*
|
|
||||||
* Decodes a DER-encoded NTRUEncrypt public-key from a
|
|
||||||
* SubjectPublicKeyInfo field in an X.509 certificate and returns the
|
|
||||||
* public-key blob itself.
|
|
||||||
*
|
|
||||||
* The required minimum size of the output public-key buffer (pubkey_blob)
|
|
||||||
* may be queried by invoking this function with pubkey_blob = NULL.
|
|
||||||
* In this case, no decoding is performed, NTRU_OK is returned, and the
|
|
||||||
* required minimum size for pubkey_blob is returned in pubkey_blob_len.
|
|
||||||
*
|
|
||||||
* When pubkey_blob != NULL, at invocation *pubkey_blob_len must be the
|
|
||||||
* size of the pubkey_blob buffer.
|
|
||||||
* Upon return, it is the actual size of the public-key blob.
|
|
||||||
*
|
|
||||||
* Returns NTRU_OK if successful.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_PARAMETER if an argument pointer
|
|
||||||
* (other than pubkey_blob) is NULL.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BAD_ENCODING if the encoded data is
|
|
||||||
* an invalid encoding of an NTRU public key.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_OID_NOT_RECOGNIZED if the
|
|
||||||
* encoded data contains an OID that identifies an object other than
|
|
||||||
* an NTRU public key.
|
|
||||||
* Returns NTRU_ERROR_BASE + NTRU_BUFFER_TOO_SMALL if the pubkey_blob buffer
|
|
||||||
* is too small.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint32_t
|
|
||||||
ntru_crypto_ntru_encrypt_subjectPublicKeyInfo2PublicKey(
|
|
||||||
uint8_t const *encoded_data, /* in - ptr to subjectPublicKeyInfo
|
|
||||||
in the encoded data */
|
|
||||||
uint16_t *pubkey_blob_len, /* in/out - no. of octets in pubkey blob,
|
|
||||||
address for no. of octets in
|
|
||||||
pubkey blob */
|
|
||||||
uint8_t *pubkey_blob, /* out - address for pubkey blob */
|
|
||||||
uint8_t **next) /* out - address for ptr to encoded
|
|
||||||
data following the
|
|
||||||
subjectPublicKeyInfo */
|
|
||||||
{
|
|
||||||
NTRU_ENCRYPT_PARAM_SET *params = NULL;
|
|
||||||
uint8_t prefix_buf[39];
|
|
||||||
bool der_id_valid;
|
|
||||||
uint16_t packed_pubkey_len = 0;
|
|
||||||
uint8_t pubkey_pack_type;
|
|
||||||
uint16_t public_key_blob_len;
|
|
||||||
|
|
||||||
/* check for bad parameters */
|
|
||||||
|
|
||||||
if (!encoded_data || !pubkey_blob_len || !next)
|
|
||||||
NTRU_RET(NTRU_BAD_PARAMETER);
|
|
||||||
|
|
||||||
/* determine if data to be decoded is a valid encoding of an NTRU
|
|
||||||
* public key
|
|
||||||
*/
|
|
||||||
|
|
||||||
memcpy(prefix_buf, encoded_data, sizeof(prefix_buf));
|
|
||||||
|
|
||||||
/* get a pointer to the parameter-set parameters */
|
|
||||||
|
|
||||||
if ((params = ntru_encrypt_get_params_with_DER_id(encoded_data[29])) ==
|
|
||||||
NULL) {
|
|
||||||
der_id_valid = FALSE;
|
|
||||||
|
|
||||||
/* normalize the prefix-buffer data used in an NTRU OID comparison */
|
|
||||||
|
|
||||||
prefix_buf[2] = der_prefix_template[2];
|
|
||||||
prefix_buf[3] = der_prefix_template[3];
|
|
||||||
|
|
||||||
} else {
|
|
||||||
der_id_valid = TRUE;
|
|
||||||
|
|
||||||
/* normalize the prefix-buffer data for the specific parameter set */
|
|
||||||
|
|
||||||
packed_pubkey_len = (params->N * params->q_bits + 7) >> 3;
|
|
||||||
sub_16_from_8s(packed_pubkey_len, prefix_buf + 2);
|
|
||||||
sub_16_from_8s(packed_pubkey_len, prefix_buf + 32);
|
|
||||||
sub_16_from_8s(packed_pubkey_len, prefix_buf + 37);
|
|
||||||
prefix_buf[29] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* validate the DER prefix encoding */
|
|
||||||
|
|
||||||
if (!der_id_valid || memcmp(prefix_buf, der_prefix_template,
|
|
||||||
sizeof(der_prefix_template))) {
|
|
||||||
|
|
||||||
/* bad DER prefix, so determine if this is a bad NTRU encoding or an
|
|
||||||
* unknown OID by comparing the first 18 octets
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (memcmp(prefix_buf, der_prefix_template, 18))
|
|
||||||
NTRU_RET(NTRU_OID_NOT_RECOGNIZED);
|
|
||||||
else
|
|
||||||
NTRU_RET(NTRU_BAD_ENCODING);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get public key packing type and blob length */
|
|
||||||
|
|
||||||
ntru_crypto_ntru_encrypt_key_get_blob_params(params, &pubkey_pack_type,
|
|
||||||
&public_key_blob_len, NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
/* return the pubkey_blob size if requested */
|
|
||||||
|
|
||||||
if (!pubkey_blob) {
|
|
||||||
*pubkey_blob_len = public_key_blob_len;
|
|
||||||
NTRU_RET(NTRU_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check size of output buffer */
|
|
||||||
|
|
||||||
if (*pubkey_blob_len < public_key_blob_len)
|
|
||||||
NTRU_RET(NTRU_BUFFER_TOO_SMALL);
|
|
||||||
|
|
||||||
/* create the public-key blob */
|
|
||||||
|
|
||||||
ntru_crypto_ntru_encrypt_key_recreate_pubkey_blob(params, packed_pubkey_len,
|
|
||||||
encoded_data + sizeof(der_prefix_template),
|
|
||||||
pubkey_pack_type, pubkey_blob);
|
|
||||||
*pubkey_blob_len = public_key_blob_len;
|
|
||||||
|
|
||||||
*next = *next + sizeof(der_prefix_template) + packed_pubkey_len;
|
|
||||||
|
|
||||||
NTRU_RET(NTRU_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -290,43 +290,6 @@ ntru_crypto_ntru_encrypt_key_create_pubkey_blob(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_key_recreate_pubkey_blob
|
|
||||||
*
|
|
||||||
* Returns a public key blob, recreated from an already-packed public key.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
ntru_crypto_ntru_encrypt_key_recreate_pubkey_blob(
|
|
||||||
NTRU_ENCRYPT_PARAM_SET const *params, /* in - pointer to
|
|
||||||
param set
|
|
||||||
parameters */
|
|
||||||
uint16_t packed_pubkey_len, /* in - no. octets in
|
|
||||||
packed pubkey */
|
|
||||||
uint8_t const *packed_pubkey, /* in - pointer to the
|
|
||||||
packed pubkey */
|
|
||||||
uint8_t pubkey_pack_type, /* out - pubkey packing
|
|
||||||
type */
|
|
||||||
uint8_t *pubkey_blob) /* out - addr for the
|
|
||||||
pubkey blob */
|
|
||||||
{
|
|
||||||
assert(params);
|
|
||||||
assert(packed_pubkey);
|
|
||||||
assert(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);
|
|
||||||
memcpy(pubkey_blob, packed_pubkey, packed_pubkey_len);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(FALSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ntru_crypto_ntru_encrypt_key_create_privkey_blob
|
/* ntru_crypto_ntru_encrypt_key_create_privkey_blob
|
||||||
*
|
*
|
||||||
* Returns a private key blob, packed according to the packing type provided.
|
* Returns a private key blob, packed according to the packing type provided.
|
||||||
|
|||||||
@@ -430,28 +430,3 @@ ntru_encrypt_get_params_with_OID(
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ntru_encrypt_get_params_with_DER_id
|
|
||||||
*
|
|
||||||
* Looks up a set of NTRUEncrypt parameters based on the DER id of the
|
|
||||||
* parameter set.
|
|
||||||
*
|
|
||||||
* Returns a pointer to the parameter set parameters if successful.
|
|
||||||
* Returns NULL if the parameter set cannot be found.
|
|
||||||
*/
|
|
||||||
|
|
||||||
NTRU_ENCRYPT_PARAM_SET *
|
|
||||||
ntru_encrypt_get_params_with_DER_id(
|
|
||||||
uint8_t der_id) /* in - parameter-set DER id */
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < numParamSets; i++) {
|
|
||||||
if (ntruParamSets[i].der_id == der_id) {
|
|
||||||
return &(ntruParamSets[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
/******************************************************************************
|
|
||||||
* NTRU Cryptography Reference Source Code
|
|
||||||
* Copyright (c) 2009-2013, by Security Innovation, Inc. All rights reserved.
|
|
||||||
*
|
|
||||||
* ntru_crypto_platform.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_platform.h
|
|
||||||
*
|
|
||||||
* Contents: Platform-specific basic definitions.
|
|
||||||
*
|
|
||||||
*****************************************************************************/
|
|
||||||
|
|
||||||
#ifndef NTRU_CRYPTO_PLATFORM_H
|
|
||||||
#define NTRU_CRYPTO_PLATFORM_H
|
|
||||||
|
|
||||||
#include <library.h>
|
|
||||||
|
|
||||||
#endif /* NTRU_CRYPTO_PLATFORM_H */
|
|
||||||
@@ -34,9 +34,9 @@
|
|||||||
#define NTRU_CRYPTO_SHA1_H
|
#define NTRU_CRYPTO_SHA1_H
|
||||||
|
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
|
||||||
#include "ntru_crypto_sha.h"
|
#include "ntru_crypto_sha.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
* macros needed for generic hash objects *
|
* macros needed for generic hash objects *
|
||||||
|
|||||||
@@ -34,9 +34,9 @@
|
|||||||
#define NTRU_CRYPTO_SHA2_H
|
#define NTRU_CRYPTO_SHA2_H
|
||||||
|
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
|
||||||
#include "ntru_crypto_sha.h"
|
#include "ntru_crypto_sha.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
/*************************
|
/*************************
|
||||||
* structure definitions *
|
* structure definitions *
|
||||||
|
|||||||
@@ -35,9 +35,9 @@
|
|||||||
#define CRYPTO_SHA256_H
|
#define CRYPTO_SHA256_H
|
||||||
|
|
||||||
|
|
||||||
#include "ntru_crypto_platform.h"
|
|
||||||
#include "ntru_crypto_sha2.h"
|
#include "ntru_crypto_sha2.h"
|
||||||
|
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
/******************************************
|
/******************************************
|
||||||
* macros needed for generic hash objects *
|
* macros needed for generic hash objects *
|
||||||
|
|||||||
Reference in New Issue
Block a user