Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

newhope.h
Go to the documentation of this file.
1 /*
2 * NEWHOPE Ring-LWE scheme
3 * Based on the public domain reference implementation by the
4 * designers (https://github.com/tpoeppelmann/newhope)
5 *
6 * Further changes
7 * (C) 2016 Jack Lloyd
8 *
9 * Botan is released under the Simplified BSD License (see license.txt)
10 */
11
12 #ifndef BOTAN_NEWHOPE_H__
13 #define BOTAN_NEWHOPE_H__
14
15 #include <botan/rng.h>
16
17 namespace Botan {
18
19 /*
20 * WARNING: This API is preliminary and will change
21 * Currently pubkey.h does not support a 2-phase KEM scheme of
22 * the sort NEWHOPE exports.
23 */
24
25 // TODO: change to just a secure_vector
26 class newhope_poly
27 {
28 public:
29 uint16_t coeffs[1024];
30 ~newhope_poly() { secure_scrub_memory(coeffs, sizeof(coeffs)); }
31 };
32
33 enum Newhope_Params {
34 NEWHOPE_SENDABYTES = 1824,
35 NEWHOPE_SENDBBYTES = 2048,
36
37 NEWHOPE_OFFER_BYTES = 1824,
38 NEWHOPE_ACCEPT_BYTES = 2048,
39 NEWHOPE_SHARED_KEY_BYTES = 32,
40
41 CECPQ1_OFFER_BYTES = NEWHOPE_OFFER_BYTES + 32,
42 CECPQ1_ACCEPT_BYTES = NEWHOPE_ACCEPT_BYTES + 32,
43 CECPQ1_SHARED_KEY_BYTES = NEWHOPE_SHARED_KEY_BYTES + 32
44 };
45
46 /**
47 * This chooses the XOF + hash for NewHope
48 * The official NewHope specification and reference implementation use
49 * SHA-3 and SHAKE-128. BoringSSL instead uses SHA-256 and AES-128 in
50 * CTR mode. CECPQ1 (x25519+NewHope) always uses BoringSSL's mode
51 */
52 enum class Newhope_Mode {
53 SHA3,
54 BoringSSL
55 };
56
57 // offer
58 void BOTAN_DLL newhope_keygen(uint8_t *send,
59 newhope_poly *sk,
60 RandomNumberGenerator& rng,
61 Newhope_Mode = Newhope_Mode::SHA3);
62
63 // accept
64 void BOTAN_DLL newhope_sharedb(uint8_t *sharedkey,
65 uint8_t *send,
66 const uint8_t *received,
67 RandomNumberGenerator& rng,
68 Newhope_Mode mode = Newhope_Mode::SHA3);
69
70 // finish
71 void BOTAN_DLL newhope_shareda(uint8_t *sharedkey,
72 const newhope_poly *ska,
73 const uint8_t *received,
74 Newhope_Mode mode = Newhope_Mode::SHA3);
75
76 }
77
78 #endif
Botan::newhope_poly::~newhope_poly
~newhope_poly()
Definition: newhope.h:30
Botan::secure_scrub_memory
void secure_scrub_memory(void *ptr, size_t n)
Definition: mem_ops.cpp:17
Botan::NEWHOPE_SHARED_KEY_BYTES
Definition: newhope.h:39
Botan::NEWHOPE_OFFER_BYTES
Definition: newhope.h:37
Botan::CECPQ1_OFFER_BYTES
Definition: newhope.h:41
Botan::Newhope_Mode
Newhope_Mode
Definition: newhope.h:52
Botan::NEWHOPE_ACCEPT_BYTES
Definition: newhope.h:38
Botan::newhope_poly
Definition: newhope.h:26
Botan::NEWHOPE_SENDBBYTES
Definition: newhope.h:35
Botan::newhope_sharedb
void newhope_sharedb(uint8_t *sharedkey, uint8_t *send, const uint8_t *received, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:725
Botan::newhope_shareda
void newhope_shareda(uint8_t *sharedkey, const poly *sk, const uint8_t *received, Newhope_Mode mode)
Definition: newhope.cpp:766
Botan::NEWHOPE_SENDABYTES
Definition: newhope.h:34
Botan::newhope_keygen
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:703
Botan
Definition: alg_id.cpp:13
Botan::CECPQ1_SHARED_KEY_BYTES
Definition: newhope.h:43
Botan::newhope_poly::coeffs
uint16_t coeffs[1024]
Definition: newhope.h:29
Botan::Newhope_Mode::SHA3
Botan::CECPQ1_ACCEPT_BYTES
Definition: newhope.h:42
Botan::Newhope_Mode::BoringSSL
Botan::Newhope_Params
Newhope_Params
Definition: newhope.h:33