| 1 |
/* Copyright (c) 2016, Google Inc. |
| 2 |
* |
| 3 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 4 |
* purpose with or without fee is hereby granted, provided that the above |
| 5 |
* copyright notice and this permission notice appear in all copies. |
| 6 |
* |
| 7 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 10 |
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 12 |
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 13 |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ |
| 14 |
|
| 15 |
#ifndef OPENSSL_HEADER_NEWHOPE_INTERNAL_H |
| 16 |
#define OPENSSL_HEADER_NEWHOPE_INTERNAL_H |
| 17 |
|
| 18 |
#include <openssl/newhope.h> |
| 19 |
#include <openssl/sha.h> |
| 20 |
|
| 21 |
#include "../internal.h" |
| 22 |
|
| 23 |
|
| 24 |
/* The number of polynomial coefficients. */ |
| 25 |
#define PARAM_N 1024 |
| 26 |
|
| 27 |
/* The width the noise distribution. */ |
| 28 |
#define PARAM_K 16 |
| 29 |
|
| 30 |
/* Modulus. */ |
| 31 |
#define PARAM_Q 12289 |
| 32 |
|
| 33 |
/* Polynomial coefficients in unpacked form. */ |
| 34 |
struct newhope_poly_st { |
| 35 |
uint16_t coeffs[PARAM_N]; |
| 36 |
}; |
| 37 |
|
| 38 |
/* SEED_LENGTH is the length of the AES-CTR seed used to derive a polynomial. */ |
| 39 |
#define SEED_LENGTH 32 |
| 40 |
|
| 41 |
/* newhope_poly_uniform generates the polynomial |a| using AES-CTR mode with the |
| 42 |
* seed |
| 43 |
* |seed|. (In the reference implementation this was done with SHAKE-128.) */ |
| 44 |
void newhope_poly_uniform(NEWHOPE_POLY* a, const uint8_t* seed); |
| 45 |
|
| 46 |
void newhope_helprec(NEWHOPE_POLY* c, const NEWHOPE_POLY* v, |
| 47 |
const uint8_t rbits[32]); |
| 48 |
|
| 49 |
/* newhope_reconcile performs the error-reconciliation step using the input |v| |
| 50 |
* and |
| 51 |
* reconciliation data |c|, writing the resulting key to |key|. */ |
| 52 |
void newhope_reconcile(uint8_t* key, const NEWHOPE_POLY* v, |
| 53 |
const NEWHOPE_POLY* c); |
| 54 |
|
| 55 |
/* newhope_poly_invntt performs the inverse of NTT(r) in-place. */ |
| 56 |
void newhope_poly_invntt(NEWHOPE_POLY* r); |
| 57 |
|
| 58 |
void newhope_poly_add(NEWHOPE_POLY* r, const NEWHOPE_POLY* a, |
| 59 |
const NEWHOPE_POLY* b); |
| 60 |
void newhope_poly_pointwise(NEWHOPE_POLY* r, const NEWHOPE_POLY* a, |
| 61 |
const NEWHOPE_POLY* b); |
| 62 |
|
| 63 |
uint16_t newhope_montgomery_reduce(uint32_t a); |
| 64 |
uint16_t newhope_barrett_reduce(uint16_t a); |
| 65 |
|
| 66 |
void newhope_bitrev_vector(uint16_t* poly); |
| 67 |
void newhope_mul_coefficients(uint16_t* poly, const uint16_t* factors); |
| 68 |
void newhope_ntt(uint16_t* poly, const uint16_t* omegas); |
| 69 |
|
| 70 |
|
| 71 |
#endif /* OPENSSL_HEADER_NEWHOPE_INTERNAL_H */ |