Arduino Cryptography Library
NewHope.h
1 /*
2  * Copyright (C) 2016 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef CRYPTO_NEWHOPE_h
24 #define CRYPTO_NEWHOPE_h
25 
26 #include <inttypes.h>
27 
28 #define NEWHOPE_SENDABYTES 1824
29 #define NEWHOPE_SENDBBYTES 2048
30 #define NEWHOPE_SHAREDBYTES 32
31 
32 #if defined(__AVR__)
33 #define NEWHOPE_SMALL_FOOTPRINT 1
34 #else
35 #define NEWHOPE_SMALL_FOOTPRINT 0
36 #endif
37 
38 typedef struct
39 {
41 #if NEWHOPE_SMALL_FOOTPRINT
42  uint8_t seed[32];
43 #else
44  uint16_t coeffs[1024];
45 #endif
49 
50 class NewHope
51 {
52 private:
53  NewHope() {}
54  ~NewHope() {}
55 
56 public:
57  enum Variant
58  {
59  Ref,
60  Torref
61  };
62 
63  static void keygen(uint8_t send[NEWHOPE_SENDABYTES], NewHopePrivateKey &sk,
64  Variant variant = Ref, const uint8_t *random_seed = 0);
65  static void sharedb(uint8_t shared_key[NEWHOPE_SHAREDBYTES],
66  uint8_t send[NEWHOPE_SENDBBYTES],
67  uint8_t received[NEWHOPE_SENDABYTES],
68  Variant variant = Ref, const uint8_t *random_seed = 0);
69  static void shareda(uint8_t shared_key[NEWHOPE_SHAREDBYTES],
70  const NewHopePrivateKey &sk,
71  uint8_t received[NEWHOPE_SENDBBYTES]);
72 };
73 
74 #endif
NewHope post-quantum key exchange algorithm.
Definition: NewHope.h:51
static void sharedb(uint8_t shared_key[NEWHOPE_SHAREDBYTES], uint8_t send[NEWHOPE_SENDBBYTES], uint8_t received[NEWHOPE_SENDABYTES], Variant variant=Ref, const uint8_t *random_seed=0)
Generates the public key and shared secret for Bob.
Definition: NewHope.cpp:1137
static void keygen(uint8_t send[NEWHOPE_SENDABYTES], NewHopePrivateKey &sk, Variant variant=Ref, const uint8_t *random_seed=0)
Generates the key pair for Alice in a New Hope key exchange.
Definition: NewHope.cpp:1025
Variant
Describes the variant of the New Hope algorithm to implement.
Definition: NewHope.h:58
@ Ref
The standard "reference" version of the New Hope algorithm.
Definition: NewHope.h:59
@ Torref
The alternative "torref" version of the New Hope algorithm.
Definition: NewHope.h:60
static void shareda(uint8_t shared_key[NEWHOPE_SHAREDBYTES], const NewHopePrivateKey &sk, uint8_t received[NEWHOPE_SENDBBYTES])
Generates the shared secret for Alice.
Definition: NewHope.cpp:1319
NewHope private key representation.
Definition: NewHope.h:39