Coverage Report

Created: 2021-02-21 07:20

/src/botan/src/lib/utils/poly_dbl/poly_dbl.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
* (C) 2017,2018 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6
7
#include <botan/internal/poly_dbl.h>
8
#include <botan/internal/loadstor.h>
9
#include <botan/exceptn.h>
10
11
namespace Botan {
12
13
namespace {
14
15
/*
16
* The minimum weight irreducible binary polynomial of size n
17
*
18
* See "Table of Low-Weight Binary Irreducible Polynomials"
19
* by Gadiel Seroussi, HP Labs Tech Report HPL-98-135
20
* http://www.hpl.hp.com/techreports/98/HPL-98-135.pdf
21
*/
22
enum class MinWeightPolynomial : uint64_t {
23
   P64   = 0x1B,
24
   P128  = 0x87,
25
   P192  = 0x87,
26
   P256  = 0x425,
27
   P512  = 0x125,
28
   P1024 = 0x80043,
29
};
30
31
template<size_t LIMBS, MinWeightPolynomial P>
32
void poly_double(uint8_t out[], const uint8_t in[])
33
3.43k
   {
34
3.43k
   uint64_t W[LIMBS];
35
3.43k
   load_be(W, in, LIMBS);
36
37
3.43k
   const uint64_t POLY = static_cast<uint64_t>(P);
38
39
3.43k
   const uint64_t carry = POLY * (W[0] >> 63);
40
41
3.43k
   if constexpr(LIMBS > 0)
42
3.43k
      {
43
6.87k
      for(size_t i = 0; i != LIMBS - 1; ++i)
44
3.43k
         W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
45
3.43k
      }
46
47
3.43k
   W[LIMBS-1] = (W[LIMBS-1] << 1) ^ carry;
48
49
3.43k
   copy_out_be(out, LIMBS*8, W);
50
3.43k
   }
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<1ul, (Botan::(anonymous namespace)::MinWeightPolynomial)27>(unsigned char*, unsigned char const*)
poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<2ul, (Botan::(anonymous namespace)::MinWeightPolynomial)135>(unsigned char*, unsigned char const*)
Line
Count
Source
33
3.43k
   {
34
3.43k
   uint64_t W[LIMBS];
35
3.43k
   load_be(W, in, LIMBS);
36
37
3.43k
   const uint64_t POLY = static_cast<uint64_t>(P);
38
39
3.43k
   const uint64_t carry = POLY * (W[0] >> 63);
40
41
3.43k
   if constexpr(LIMBS > 0)
42
3.43k
      {
43
6.87k
      for(size_t i = 0; i != LIMBS - 1; ++i)
44
3.43k
         W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
45
3.43k
      }
46
47
3.43k
   W[LIMBS-1] = (W[LIMBS-1] << 1) ^ carry;
48
49
3.43k
   copy_out_be(out, LIMBS*8, W);
50
3.43k
   }
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<3ul, (Botan::(anonymous namespace)::MinWeightPolynomial)135>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<4ul, (Botan::(anonymous namespace)::MinWeightPolynomial)1061>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<8ul, (Botan::(anonymous namespace)::MinWeightPolynomial)293>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double<16ul, (Botan::(anonymous namespace)::MinWeightPolynomial)524355>(unsigned char*, unsigned char const*)
51
52
template<size_t LIMBS, MinWeightPolynomial P>
53
void poly_double_le(uint8_t out[], const uint8_t in[])
54
0
   {
55
0
   uint64_t W[LIMBS];
56
0
   load_le(W, in, LIMBS);
57
58
0
   const uint64_t POLY = static_cast<uint64_t>(P);
59
60
0
   const uint64_t carry = POLY * (W[LIMBS-1] >> 63);
61
62
0
   if constexpr(LIMBS > 0)
63
0
      {
64
0
      for(size_t i = 0; i != LIMBS - 1; ++i)
65
0
         W[LIMBS-1-i] = (W[LIMBS-1-i] << 1) ^ (W[LIMBS-2-i] >> 63);
66
0
      }
67
68
0
   W[0] = (W[0] << 1) ^ carry;
69
70
0
   copy_out_le(out, LIMBS*8, W);
71
0
   }
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<1ul, (Botan::(anonymous namespace)::MinWeightPolynomial)27>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<2ul, (Botan::(anonymous namespace)::MinWeightPolynomial)135>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<3ul, (Botan::(anonymous namespace)::MinWeightPolynomial)135>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<4ul, (Botan::(anonymous namespace)::MinWeightPolynomial)1061>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<8ul, (Botan::(anonymous namespace)::MinWeightPolynomial)293>(unsigned char*, unsigned char const*)
Unexecuted instantiation: poly_dbl.cpp:void Botan::(anonymous namespace)::poly_double_le<16ul, (Botan::(anonymous namespace)::MinWeightPolynomial)524355>(unsigned char*, unsigned char const*)
72
73
}
74
75
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
76
3.43k
   {
77
3.43k
   switch(n)
78
3.43k
      {
79
0
      case 8:
80
0
         return poly_double<1, MinWeightPolynomial::P64>(out, in);
81
3.43k
      case 16:
82
3.43k
         return poly_double<2, MinWeightPolynomial::P128>(out, in);
83
0
      case 24:
84
0
         return poly_double<3, MinWeightPolynomial::P192>(out, in);
85
0
      case 32:
86
0
         return poly_double<4, MinWeightPolynomial::P256>(out, in);
87
0
      case 64:
88
0
         return poly_double<8, MinWeightPolynomial::P512>(out, in);
89
0
      case 128:
90
0
         return poly_double<16, MinWeightPolynomial::P1024>(out, in);
91
0
      default:
92
0
         throw Invalid_Argument("Unsupported size for poly_double_n");
93
3.43k
      }
94
3.43k
   }
95
96
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
97
0
   {
98
0
   switch(n)
99
0
      {
100
0
      case 8:
101
0
         return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
102
0
      case 16:
103
0
         return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
104
0
      case 24:
105
0
         return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
106
0
      case 32:
107
0
         return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
108
0
      case 64:
109
0
         return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
110
0
      case 128:
111
0
         return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
112
0
      default:
113
0
         throw Invalid_Argument("Unsupported size for poly_double_n_le");
114
0
      }
115
0
   }
116
117
}