Botan  2.1.0
Crypto and TLS for C++11
cecpq1.cpp
Go to the documentation of this file.
1 /*
2 * CECPQ1 (x25519 + NewHope)
3 * (C) 2016 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #include <botan/cecpq1.h>
9 #include <botan/newhope.h>
10 #include <botan/curve25519.h>
11 
12 namespace Botan {
13 
14 void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES],
15  CECPQ1_key* offer_key_output,
17  {
18  offer_key_output->m_x25519 = rng.random_vec(32);
19  curve25519_basepoint(send, offer_key_output->m_x25519.data());
20 
21  newhope_keygen(send + 32, &offer_key_output->m_newhope,
23  }
24 
25 void CECPQ1_accept(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES],
26  uint8_t send[CECPQ1_ACCEPT_BYTES],
27  const uint8_t received[CECPQ1_OFFER_BYTES],
29  {
30  secure_vector<uint8_t> x25519_key = rng.random_vec(32);
31 
32  curve25519_basepoint(send, x25519_key.data());
33 
34  curve25519_donna(shared_key, x25519_key.data(), received);
35 
36  newhope_sharedb(shared_key + 32, send + 32, received + 32,
38  }
39 
40 void CECPQ1_finish(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES],
41  const CECPQ1_key& offer_key,
42  const uint8_t received[CECPQ1_ACCEPT_BYTES])
43  {
44  curve25519_donna(shared_key, offer_key.m_x25519.data(), received);
45 
46  newhope_shareda(shared_key + 32, &offer_key.m_newhope, received + 32,
48  }
49 
50 }
void CECPQ1_finish(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES], const CECPQ1_key &offer_key, const uint8_t received[CECPQ1_ACCEPT_BYTES])
Definition: cecpq1.cpp:40
secure_vector< uint8_t > random_vec(size_t bytes)
Definition: rng.h:133
newhope_poly m_newhope
Definition: cecpq1.h:20
void newhope_sharedb(uint8_t *sharedkey, uint8_t *send, const uint8_t *received, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:725
void newhope_shareda(uint8_t *sharedkey, const poly *sk, const uint8_t *received, Newhope_Mode mode)
Definition: newhope.cpp:766
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:703
void CECPQ1_accept(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES], uint8_t send[CECPQ1_ACCEPT_BYTES], const uint8_t received[CECPQ1_OFFER_BYTES], RandomNumberGenerator &rng)
Definition: cecpq1.cpp:25
Definition: alg_id.cpp:13
secure_vector< uint8_t > m_x25519
Definition: cecpq1.h:19
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition: curve25519.cpp:15
void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES], CECPQ1_key *offer_key_output, RandomNumberGenerator &rng)
Definition: cecpq1.cpp:14
void BOTAN_DLL curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])