Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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,
16 RandomNumberGenerator& rng)
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,
22 rng, Newhope_Mode::BoringSSL);
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],
28 RandomNumberGenerator& rng)
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,
37 rng, Newhope_Mode::BoringSSL);
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,
47 Newhope_Mode::BoringSSL);
48 }
49
50 }
Botan::CECPQ1_finish
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
Botan::CECPQ1_OFFER_BYTES
Definition: newhope.h:41
Botan::RandomNumberGenerator::random_vec
secure_vector< uint8_t > random_vec(size_t bytes)
Definition: rng.h:133
Botan::CECPQ1_key::m_newhope
newhope_poly m_newhope
Definition: cecpq1.h:20
Botan::CECPQ1_key
Definition: cecpq1.h:16
Botan::RandomNumberGenerator
Definition: rng.h:25
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::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::newhope_keygen
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:703
Botan::CECPQ1_accept
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
Botan
Definition: alg_id.cpp:13
Botan::CECPQ1_key::m_x25519
secure_vector< uint8_t > m_x25519
Definition: cecpq1.h:19
Botan::curve25519_basepoint
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition: curve25519.cpp:15
Botan::CECPQ1_SHARED_KEY_BYTES
Definition: newhope.h:43
Botan::CECPQ1_offer
void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES], CECPQ1_key *offer_key_output, RandomNumberGenerator &rng)
Definition: cecpq1.cpp:14
Botan::CECPQ1_ACCEPT_BYTES
Definition: newhope.h:42
Botan::Newhope_Mode::BoringSSL
Botan::curve25519_donna
void BOTAN_DLL curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])