Botan 2.19.1
Crypto and TLS for C&
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
13namespace Botan {
14
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
26void 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
41void 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}
secure_vector< uint8_t > m_x25519
Definition: cecpq1.h:19
newhope_poly m_newhope
Definition: cecpq1.h:20
secure_vector< uint8_t > random_vec(size_t bytes)
Definition: rng.h:143
Definition: alg_id.cpp:13
void CECPQ1_offer(uint8_t send[CECPQ1_OFFER_BYTES], CECPQ1_key *offer_key_output, RandomNumberGenerator &rng)
Definition: cecpq1.cpp:15
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
@ CECPQ1_ACCEPT_BYTES
Definition: newhope.h:48
@ CECPQ1_SHARED_KEY_BYTES
Definition: newhope.h:49
@ CECPQ1_OFFER_BYTES
Definition: newhope.h:47
void newhope_shareda(uint8_t sharedkey[], const poly *sk, const uint8_t received[], Newhope_Mode mode)
Definition: newhope.cpp:779
void newhope_sharedb(uint8_t *sharedkey, uint8_t *send, const uint8_t *received, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:742
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator &rng, Newhope_Mode mode)
Definition: newhope.cpp:720
void curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32])
Definition: donna.cpp:440
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
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32])
Definition: curve25519.cpp:16
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:65