aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-06 14:18:53 -0500
committerJack Lloyd <[email protected]>2018-03-06 14:18:53 -0500
commit0c30178c88513320ec2e515a5ae2f2748c45844b (patch)
treee32a859c92a8486b772a8b02e604f33cca3c52d0 /src/lib
parent29d740f468ca6feb9782d65c675be7f4ced3cedc (diff)
Support 1024-bit inputs in poly_double function
GH #1477
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/utils/poly_dbl/poly_dbl.cpp48
-rw-r--r--src/lib/utils/poly_dbl/poly_dbl.h2
2 files changed, 36 insertions, 14 deletions
diff --git a/src/lib/utils/poly_dbl/poly_dbl.cpp b/src/lib/utils/poly_dbl/poly_dbl.cpp
index 2b989db57..62c7695da 100644
--- a/src/lib/utils/poly_dbl/poly_dbl.cpp
+++ b/src/lib/utils/poly_dbl/poly_dbl.cpp
@@ -1,5 +1,5 @@
/*
-* (C) 2017 Jack Lloyd
+* (C) 2017,2018 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
@@ -12,12 +12,28 @@ namespace Botan {
namespace {
-template<size_t LIMBS, uint64_t POLY>
+/*
+* The minimum weight irreducible binary polynomial of size n
+*
+* See http://www.hpl.hp.com/techreports/98/HPL-98-135.pdf
+*/
+enum class MinWeightPolynomial : uint64_t {
+ P64 = 0x1B,
+ P128 = 0x87,
+ P192 = 0x87,
+ P256 = 0x425,
+ P512 = 0x125,
+ P1024 = 0x80043,
+};
+
+template<size_t LIMBS, MinWeightPolynomial P>
void poly_double(uint8_t out[], const uint8_t in[])
{
uint64_t W[LIMBS];
load_be(W, in, LIMBS);
+ const uint64_t POLY = static_cast<uint64_t>(P);
+
const uint64_t carry = POLY * (W[0] >> 63);
for(size_t i = 0; i != LIMBS - 1; ++i)
W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
@@ -26,12 +42,14 @@ void poly_double(uint8_t out[], const uint8_t in[])
copy_out_be(out, LIMBS*8, W);
}
-template<size_t LIMBS, uint64_t POLY>
+template<size_t LIMBS, MinWeightPolynomial P>
void poly_double_le(uint8_t out[], const uint8_t in[])
{
uint64_t W[LIMBS];
load_le(W, in, LIMBS);
+ const uint64_t POLY = static_cast<uint64_t>(P);
+
const uint64_t carry = POLY * (W[LIMBS-1] >> 63);
for(size_t i = 0; i != LIMBS - 1; ++i)
W[LIMBS-1-i] = (W[LIMBS-1-i] << 1) ^ (W[LIMBS-2-i] >> 63);
@@ -47,15 +65,17 @@ void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
switch(n)
{
case 8:
- return poly_double<1, 0x1B>(out, in);
+ return poly_double<1, MinWeightPolynomial::P64>(out, in);
case 16:
- return poly_double<2, 0x87>(out, in);
+ return poly_double<2, MinWeightPolynomial::P128>(out, in);
case 24:
- return poly_double<3, 0x87>(out, in);
+ return poly_double<3, MinWeightPolynomial::P192>(out, in);
case 32:
- return poly_double<4, 0x425>(out, in);
+ return poly_double<4, MinWeightPolynomial::P256>(out, in);
case 64:
- return poly_double<8, 0x125>(out, in);
+ return poly_double<8, MinWeightPolynomial::P512>(out, in);
+ case 128:
+ return poly_double<8, MinWeightPolynomial::P1024>(out, in);
default:
throw Invalid_Argument("Unsupported size for poly_double_n");
}
@@ -66,15 +86,17 @@ void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
switch(n)
{
case 8:
- return poly_double_le<1, 0x1B>(out, in);
+ return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
case 16:
- return poly_double_le<2, 0x87>(out, in);
+ return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
case 24:
- return poly_double_le<3, 0x87>(out, in);
+ return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
case 32:
- return poly_double_le<4, 0x425>(out, in);
+ return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
case 64:
- return poly_double_le<8, 0x125>(out, in);
+ return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
+ case 128:
+ return poly_double_le<8, MinWeightPolynomial::P1024>(out, in);
default:
throw Invalid_Argument("Unsupported size for poly_double_n_le");
}
diff --git a/src/lib/utils/poly_dbl/poly_dbl.h b/src/lib/utils/poly_dbl/poly_dbl.h
index 8f9c0d3aa..931b4873e 100644
--- a/src/lib/utils/poly_dbl/poly_dbl.h
+++ b/src/lib/utils/poly_dbl/poly_dbl.h
@@ -21,7 +21,7 @@ void BOTAN_PUBLIC_API(2,3) poly_double_n(uint8_t out[], const uint8_t in[], size
*/
inline bool poly_double_supported_size(size_t n)
{
- return (n == 8 || n == 16 || n == 24 || n == 32 || n == 64);
+ return (n == 8 || n == 16 || n == 24 || n == 32 || n == 64 || n == 128);
}
inline void poly_double_n(uint8_t buf[], size_t n)