You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.5 KiB

  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. #ifndef OPENSSL_HEADER_NEWHOPE_INTERNAL_H
  15. #define OPENSSL_HEADER_NEWHOPE_INTERNAL_H
  16. #include <openssl/newhope.h>
  17. #include <openssl/sha.h>
  18. #include "../internal.h"
  19. /* The number of polynomial coefficients. */
  20. #define PARAM_N 1024
  21. /* The width the noise distribution. */
  22. #define PARAM_K 16
  23. /* Modulus. */
  24. #define PARAM_Q 12289
  25. /* Polynomial coefficients in unpacked form. */
  26. struct newhope_poly_st {
  27. uint16_t coeffs[PARAM_N];
  28. };
  29. /* SEED_LENGTH is the length of the AES-CTR seed used to derive a polynomial. */
  30. #define SEED_LENGTH 32
  31. /* newhope_poly_uniform generates the polynomial |a| using AES-CTR mode with the
  32. * seed
  33. * |seed|. (In the reference implementation this was done with SHAKE-128.) */
  34. void newhope_poly_uniform(NEWHOPE_POLY* a, const uint8_t* seed);
  35. void newhope_helprec(NEWHOPE_POLY* c, const NEWHOPE_POLY* v,
  36. const uint8_t rbits[32]);
  37. /* newhope_reconcile performs the error-reconciliation step using the input |v|
  38. * and
  39. * reconciliation data |c|, writing the resulting key to |key|. */
  40. void newhope_reconcile(uint8_t* key, const NEWHOPE_POLY* v,
  41. const NEWHOPE_POLY* c);
  42. /* newhope_poly_invntt performs the inverse of NTT(r) in-place. */
  43. void newhope_poly_invntt(NEWHOPE_POLY* r);
  44. void newhope_poly_add(NEWHOPE_POLY* r, const NEWHOPE_POLY* a,
  45. const NEWHOPE_POLY* b);
  46. void newhope_poly_pointwise(NEWHOPE_POLY* r, const NEWHOPE_POLY* a,
  47. const NEWHOPE_POLY* b);
  48. uint16_t newhope_montgomery_reduce(uint32_t a);
  49. uint16_t newhope_barrett_reduce(uint16_t a);
  50. void newhope_bitrev_vector(uint16_t* poly);
  51. void newhope_mul_coefficients(uint16_t* poly, const uint16_t* factors);
  52. void newhope_ntt(uint16_t* poly, const uint16_t* omegas);
  53. #endif /* OPENSSL_HEADER_NEWHOPE_INTERNAL_H */