• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/lib/utils/poly_dbl/poly_dbl.cpp
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

9
#include <botan/exceptn.h>
10
#include <botan/internal/loadstor.h>
11

12
namespace Botan {
13

14
namespace {
15

16
/*
17
* The minimum weight irreducible binary polynomial of size n
18
*
19
* See "Table of Low-Weight Binary Irreducible Polynomials"
20
* by Gadiel Seroussi, HP Labs Tech Report HPL-98-135
21
* http://www.hpl.hp.com/techreports/98/HPL-98-135.pdf
22
*/
23
enum class MinWeightPolynomial : uint64_t {
24
   P64 = 0x1B,
25
   P128 = 0x87,
26
   P192 = 0x87,
27
   P256 = 0x425,
28
   P512 = 0x125,
29
   P1024 = 0x80043,
30
};
31

32
template <size_t LIMBS, MinWeightPolynomial P>
33
void poly_double(uint8_t out[], const uint8_t in[]) {
40,431✔
34
   uint64_t W[LIMBS];
35
   load_be(W, in, LIMBS);
40,431✔
36

37
   const uint64_t POLY = static_cast<uint64_t>(P);
40,431✔
38

39
   const uint64_t carry = POLY * (W[0] >> 63);
40,431✔
40

41
   if constexpr(LIMBS > 0) {
42
      for(size_t i = 0; i != LIMBS - 1; ++i)
146,147✔
43
         W[i] = (W[i] << 1) ^ (W[i + 1] >> 63);
105,716✔
44
   }
45

46
   W[LIMBS - 1] = (W[LIMBS - 1] << 1) ^ carry;
40,431✔
47

48
   copy_out_be(out, LIMBS * 8, W);
40,431✔
49
}
40,431✔
50

51
template <size_t LIMBS, MinWeightPolynomial P>
52
void poly_double_le(uint8_t out[], const uint8_t in[]) {
336,330✔
53
   uint64_t W[LIMBS];
54
   load_le(W, in, LIMBS);
336,330✔
55

56
   const uint64_t POLY = static_cast<uint64_t>(P);
336,330✔
57

58
   const uint64_t carry = POLY * (W[LIMBS - 1] >> 63);
336,330✔
59

60
   if constexpr(LIMBS > 0) {
61
      for(size_t i = 0; i != LIMBS - 1; ++i)
663,914✔
62
         W[LIMBS - 1 - i] = (W[LIMBS - 1 - i] << 1) ^ (W[LIMBS - 2 - i] >> 63);
361,942✔
63
   }
64

65
   W[0] = (W[0] << 1) ^ carry;
336,330✔
66

67
   copy_out_le(out, LIMBS * 8, W);
336,330✔
68
}
336,330✔
69

70
}  // namespace
71

72
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n) {
40,431✔
73
   switch(n) {
40,431✔
74
      case 8:
4,402✔
75
         return poly_double<1, MinWeightPolynomial::P64>(out, in);
4,402✔
76
      case 16:
17,405✔
77
         return poly_double<2, MinWeightPolynomial::P128>(out, in);
17,405✔
78
      case 24:
6,609✔
79
         return poly_double<3, MinWeightPolynomial::P192>(out, in);
6,609✔
80
      case 32:
5,957✔
81
         return poly_double<4, MinWeightPolynomial::P256>(out, in);
5,957✔
82
      case 64:
4,206✔
83
         return poly_double<8, MinWeightPolynomial::P512>(out, in);
4,206✔
84
      case 128:
1,852✔
85
         return poly_double<16, MinWeightPolynomial::P1024>(out, in);
1,852✔
86
      default:
×
87
         throw Invalid_Argument("Unsupported size for poly_double_n");
×
88
   }
89
}
90

91
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n) {
336,330✔
92
   switch(n) {
336,330✔
93
      case 8:
34,358✔
94
         return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
370,688✔
95
      case 16:
289,427✔
96
         return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
289,427✔
97
      case 24:
3,400✔
98
         return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
3,400✔
99
      case 32:
3,949✔
100
         return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
3,949✔
101
      case 64:
3,009✔
102
         return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
3,009✔
103
      case 128:
2,187✔
104
         return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
2,187✔
105
      default:
×
106
         throw Invalid_Argument("Unsupported size for poly_double_n_le");
×
107
   }
108
}
109

110
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc