Coverage Report

Created: 2020-02-14 15:38

/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/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 http://www.hpl.hp.com/techreports/98/HPL-98-135.pdf
19
*/
20
enum class MinWeightPolynomial : uint64_t {
21
   P64   = 0x1B,
22
   P128  = 0x87,
23
   P192  = 0x87,
24
   P256  = 0x425,
25
   P512  = 0x125,
26
   P1024 = 0x80043,
27
};
28
29
template<size_t LIMBS, MinWeightPolynomial P>
30
void poly_double(uint8_t out[], const uint8_t in[])
31
4.68k
   {
32
4.68k
   uint64_t W[LIMBS];
33
4.68k
   load_be(W, in, LIMBS);
34
4.68k
35
4.68k
   const uint64_t POLY = static_cast<uint64_t>(P);
36
4.68k
37
4.68k
   const uint64_t carry = POLY * (W[0] >> 63);
38
4.68k
39
4.68k
   BOTAN_IF_CONSTEXPR(LIMBS > 0)
40
4.68k
      {
41
9.36k
      for(size_t i = 0; i != LIMBS - 1; ++i)
42
4.68k
         W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
43
4.68k
      }
44
4.68k
45
4.68k
   W[LIMBS-1] = (W[LIMBS-1] << 1) ^ carry;
46
4.68k
47
4.68k
   copy_out_be(out, LIMBS*8, W);
48
4.68k
   }
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
31
4.68k
   {
32
4.68k
   uint64_t W[LIMBS];
33
4.68k
   load_be(W, in, LIMBS);
34
4.68k
35
4.68k
   const uint64_t POLY = static_cast<uint64_t>(P);
36
4.68k
37
4.68k
   const uint64_t carry = POLY * (W[0] >> 63);
38
4.68k
39
4.68k
   BOTAN_IF_CONSTEXPR(LIMBS > 0)
40
4.68k
      {
41
9.36k
      for(size_t i = 0; i != LIMBS - 1; ++i)
42
4.68k
         W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
43
4.68k
      }
44
4.68k
45
4.68k
   W[LIMBS-1] = (W[LIMBS-1] << 1) ^ carry;
46
4.68k
47
4.68k
   copy_out_be(out, LIMBS*8, W);
48
4.68k
   }
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*)
49
50
template<size_t LIMBS, MinWeightPolynomial P>
51
void poly_double_le(uint8_t out[], const uint8_t in[])
52
0
   {
53
0
   uint64_t W[LIMBS];
54
0
   load_le(W, in, LIMBS);
55
0
56
0
   const uint64_t POLY = static_cast<uint64_t>(P);
57
0
58
0
   const uint64_t carry = POLY * (W[LIMBS-1] >> 63);
59
0
60
0
   BOTAN_IF_CONSTEXPR(LIMBS > 0)
61
0
      {
62
0
      for(size_t i = 0; i != LIMBS - 1; ++i)
63
0
         W[LIMBS-1-i] = (W[LIMBS-1-i] << 1) ^ (W[LIMBS-2-i] >> 63);
64
0
      }
65
0
66
0
   W[0] = (W[0] << 1) ^ carry;
67
0
68
0
   copy_out_le(out, LIMBS*8, W);
69
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*)
70
71
}
72
73
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
74
4.68k
   {
75
4.68k
   switch(n)
76
4.68k
      {
77
4.68k
      case 8:
78
0
         return poly_double<1, MinWeightPolynomial::P64>(out, in);
79
4.68k
      case 16:
80
4.68k
         return poly_double<2, MinWeightPolynomial::P128>(out, in);
81
4.68k
      case 24:
82
0
         return poly_double<3, MinWeightPolynomial::P192>(out, in);
83
4.68k
      case 32:
84
0
         return poly_double<4, MinWeightPolynomial::P256>(out, in);
85
4.68k
      case 64:
86
0
         return poly_double<8, MinWeightPolynomial::P512>(out, in);
87
4.68k
      case 128:
88
0
         return poly_double<16, MinWeightPolynomial::P1024>(out, in);
89
4.68k
      default:
90
0
         throw Invalid_Argument("Unsupported size for poly_double_n");
91
4.68k
      }
92
4.68k
   }
93
94
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
95
   {
96
   switch(n)
97
      {
98
      case 8:
99
         return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
100
      case 16:
101
         return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
102
      case 24:
103
         return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
104
      case 32:
105
         return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
106
      case 64:
107
         return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
108
      case 128:
109
         return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
110
      default:
111
         throw Invalid_Argument("Unsupported size for poly_double_n_le");
112
      }
113
   }
114
115
}