Botan  2.4.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 #include <botan/rng.h>
12 
13 namespace Botan {
14 
15 void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES],
16  CECPQ1_key* offer_key_output,
18  {
19  offer_key_output->m_x25519 = rng.random_vec(32);
20  curve25519_basepoint(send, offer_key_output->m_x25519.data());
21 
22  newhope_keygen(send + 32, &offer_key_output->m_newhope,
24  }
25 
26 void CECPQ1_accept(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES],
27  uint8_t send[CECPQ1_ACCEPT_BYTES],
28  const uint8_t received[CECPQ1_OFFER_BYTES],
30  {
31  secure_vector<uint8_t> x25519_key = rng.random_vec(32);
32 
33  curve25519_basepoint(send, x25519_key.data());
34 
35  curve25519_donna(shared_key, x25519_key.data(), received);
36 
37  newhope_sharedb(shared_key + 32, send + 32, received + 32,
39  }
40 
41 void CECPQ1_finish(uint8_t shared_key[CECPQ1_SHARED_KEY_BYTES],
42  const CECPQ1_key& offer_key,
43  const uint8_t received[CECPQ1_ACCEPT_BYTES])
44  {
45  curve25519_donna(shared_key, offer_key.m_x25519.data(), received);
46 
47  newhope_shareda(shared_key + 32, &offer_key.m_newhope, received + 32,
49  }
50 
51 }
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:41
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:712
secure_vector< uint8_t > random_vec(size_t bytes)
Definition: rng.h:132
newhope_poly m_newhope
Definition: cecpq1.h:20
void curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition: curve25519.cpp:16
void newhope_sharedb(uint8_t *sharedkey, uint8_t *send, const uint8_t *received, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:734
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:26
Definition: alg_id.cpp:13
secure_vector< uint8_t > m_x25519
Definition: cecpq1.h:19
void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES], CECPQ1_key *offer_key_output, RandomNumberGenerator &rng)
Definition: cecpq1.cpp:15
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88
void newhope_shareda(uint8_t sharedkey[], const poly *sk, const uint8_t received[], Newhope_Mode mode)
Definition: newhope.cpp:771