aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-10-18 12:27:37 -0400
committerJack Lloyd <[email protected]>2016-10-19 14:41:10 -0400
commit3324f00a8b094c86cee1f5a59ec6fc746663bd7e (patch)
treebc3dfb670237c9b7ebaac3539cdf91a02414a712 /src/lib/pubkey
parentd1817c9960f619b130388a570ed09ccbed568e2e (diff)
Add proper SHA-3
Kind of a copy and paste of Keccak, but only a single copy of the permutation at least. Keccak depends on SHA-3 instead of the reverse, so that SHA-3 can be enabled without also bringing in an unapproved hash function. Updates newhope code and removes API function newhope_hash which was an unofficial SHA-3-256.
Diffstat (limited to 'src/lib/pubkey')
-rw-r--r--src/lib/pubkey/newhope/info.txt2
-rw-r--r--src/lib/pubkey/newhope/newhope.cpp26
-rw-r--r--src/lib/pubkey/newhope/newhope.h7
3 files changed, 11 insertions, 24 deletions
diff --git a/src/lib/pubkey/newhope/info.txt b/src/lib/pubkey/newhope/info.txt
index 8019b6a7c..08b68fc7a 100644
--- a/src/lib/pubkey/newhope/info.txt
+++ b/src/lib/pubkey/newhope/info.txt
@@ -1,5 +1,5 @@
define NEWHOPE 20160829
<requires>
-keccak
+sha3
</requires>
diff --git a/src/lib/pubkey/newhope/newhope.cpp b/src/lib/pubkey/newhope/newhope.cpp
index 8436457b4..25168cc58 100644
--- a/src/lib/pubkey/newhope/newhope.cpp
+++ b/src/lib/pubkey/newhope/newhope.cpp
@@ -10,7 +10,7 @@
*/
#include <botan/newhope.h>
-#include <botan/keccak.h>
+#include <botan/sha3.h>
#include <botan/loadstor.h>
namespace Botan {
@@ -445,7 +445,7 @@ void keccak_absorb(uint64_t *s,
for (i = 0; i < r / 8; ++i)
s[i] ^= load_le<u64bit>(m, i);
- Keccak_1600::permute(s);
+ SHA_3::permute(s);
mlen -= r;
m += r;
}
@@ -465,7 +465,7 @@ inline void keccak_squeezeblocks(uint8_t *h, size_t nblocks,
{
while(nblocks > 0)
{
- Keccak_1600::permute(s);
+ SHA_3::permute(s);
copy_out_le(h, r, s);
@@ -511,24 +511,18 @@ void gen_a(poly *a, const uint8_t *seed)
}
}
-}
-
-// API FUNCTIONS
-
void newhope_hash(uint8_t *output, const uint8_t *input, size_t inputByteLen)
-{
-const size_t SHA3_256_RATE = 136;
+ {
+ SHA_3_256 sha3;
- uint64_t s[25];
- uint8_t t[SHA3_256_RATE];
- int i;
+ sha3.update(input, inputByteLen);
+ sha3.final(output);
+}
- keccak_absorb(s, SHA3_256_RATE, input, inputByteLen, 0x06);
- keccak_squeezeblocks(t, 1, s, SHA3_256_RATE);
- for(i=0;i<32;i++)
- output[i] = t[i];
}
+// API FUNCTIONS
+
void newhope_keygen(uint8_t *send, poly *sk, RandomNumberGenerator& rng)
{
poly a, e, r, pk;
diff --git a/src/lib/pubkey/newhope/newhope.h b/src/lib/pubkey/newhope/newhope.h
index 794f0750f..875c6e092 100644
--- a/src/lib/pubkey/newhope/newhope.h
+++ b/src/lib/pubkey/newhope/newhope.h
@@ -32,13 +32,6 @@ void BOTAN_DLL newhope_keygen(uint8_t *send, newhope_poly *sk, RandomNumberGener
void BOTAN_DLL newhope_sharedb(uint8_t *sharedkey, uint8_t *send, const uint8_t *received, RandomNumberGenerator& rng);
void BOTAN_DLL newhope_shareda(uint8_t *sharedkey, const newhope_poly *ska, const uint8_t *received);
-
-/*
-* This is just exposed for testing
-*/
-void BOTAN_DLL newhope_hash(uint8_t *output, const uint8_t *input, size_t inputByteLen);
-
-
}
#endif