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

randombit / botan / 23963731334

03 Apr 2026 09:29PM UTC coverage: 91.886% (+2.4%) from 89.501%
23963731334

push

github

web-flow
Merge pull request #5518 from randombit/jack/fix-unknown-ext-handling

Improve handling of X509 extensions which fail to parse

108312 of 117876 relevant lines covered (91.89%)

11232507.64 hits per line

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

84.85
/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/ct_utils.h>
11
#include <botan/internal/loadstor.h>
12

13
namespace Botan {
14

15
namespace {
16

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

33
/**
34
* If the top bit of c is set, returns the carry (the polynomial)
35
*
36
* Otherwise returns zero.
37
*/
38
template <MinWeightPolynomial P>
39
inline uint64_t return_carry(uint64_t c) {
1,519,869✔
40
   return CT::Mask<uint64_t>::expand_top_bit(c).if_set_return(static_cast<uint64_t>(P));
1,519,869✔
41
}
42

43
template <size_t LIMBS, MinWeightPolynomial P>
44
void poly_double(uint8_t out[], const uint8_t in[]) {
22,139✔
45
   uint64_t W[LIMBS];
46
   load_be(W, in, LIMBS);
22,139✔
47

48
   const uint64_t carry = return_carry<P>(W[0]);
22,139✔
49

50
   if constexpr(LIMBS > 0) {
51
      for(size_t i = 0; i != LIMBS - 1; ++i) {
62,506✔
52
         W[i] = (W[i] << 1) ^ (W[i + 1] >> 63);
40,367✔
53
      }
54
   }
55

56
   W[LIMBS - 1] = (W[LIMBS - 1] << 1) ^ carry;
22,139✔
57

58
   copy_out_be(std::span(out, LIMBS * 8), W);
22,139✔
59
}
22,139✔
60

61
template <size_t LIMBS, MinWeightPolynomial P>
62
void poly_double_le(uint8_t out[], const uint8_t in[]) {
682,142✔
63
   uint64_t W[LIMBS];
64
   load_le(W, in, LIMBS);
682,142✔
65

66
   const uint64_t carry = return_carry<P>(W[LIMBS - 1]);
682,142✔
67

68
   if constexpr(LIMBS > 0) {
69
      for(size_t i = 0; i != LIMBS - 1; ++i) {
684,242✔
70
         W[LIMBS - 1 - i] = (W[LIMBS - 1 - i] << 1) ^ (W[LIMBS - 2 - i] >> 63);
2,100✔
71
      }
72
   }
73

74
   W[0] = (W[0] << 1) ^ carry;
682,142✔
75

76
   copy_out_le(std::span(out, LIMBS * 8), W);
682,142✔
77
}
682,142✔
78

79
}  // namespace
80

81
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n) {
22,139✔
82
   switch(n) {
22,139✔
83
      case 8:
628✔
84
         return poly_double<1, MinWeightPolynomial::P64>(out, in);
628✔
85
      case 16:
13,771✔
86
         return poly_double<2, MinWeightPolynomial::P128>(out, in);
13,771✔
87
      case 24:
3,368✔
88
         return poly_double<3, MinWeightPolynomial::P192>(out, in);
3,368✔
89
      case 32:
2,690✔
90
         return poly_double<4, MinWeightPolynomial::P256>(out, in);
2,690✔
91
      case 64:
1,680✔
92
         return poly_double<8, MinWeightPolynomial::P512>(out, in);
1,680✔
93
      case 128:
2✔
94
         return poly_double<16, MinWeightPolynomial::P1024>(out, in);
2✔
95
      default:
×
96
         throw Invalid_Argument("Unsupported size for poly_double_n");
×
97
   }
98
}
99

100
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n) {
682,142✔
101
   switch(n) {
682,142✔
102
      case 8:
681,482✔
103
         return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
681,482✔
104
      case 16:
×
105
         return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
×
106
      case 24:
×
107
         return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
×
108
      case 32:
630✔
109
         return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
630✔
110
      case 64:
30✔
111
         return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
30✔
112
      case 128:
×
113
         return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
×
114
      default:
×
115
         throw Invalid_Argument("Unsupported size for poly_double_n_le");
×
116
   }
117
}
118

119
void xts_compute_tweak_block(uint8_t tweak[], size_t BS, size_t blocks_in_tweak) {
27,654✔
120
   BOTAN_ASSERT_NOMSG(blocks_in_tweak > 0);
27,654✔
121

122
   if(BS == 16) {
27,654✔
123
      constexpr size_t LIMBS = 2;
22,268✔
124

125
      uint64_t W[LIMBS];
22,268✔
126
      load_le(W, &tweak[0], LIMBS);
22,268✔
127

128
      for(size_t i = 1; i < blocks_in_tweak; ++i) {
837,856✔
129
         const uint64_t carry = return_carry<MinWeightPolynomial::P128>(W[1]);
815,588✔
130
         W[1] = (W[1] << 1) ^ (W[0] >> 63);
815,588✔
131
         W[0] = (W[0] << 1) ^ carry;
815,588✔
132
         copy_out_le(std::span(&tweak[i * BS], 2 * 8), W);
815,588✔
133
      }
134
   } else {
135
      for(size_t i = 1; i < blocks_in_tweak; ++i) {
687,528✔
136
         const uint8_t* prev = &tweak[(i - 1) * BS];
682,142✔
137
         uint8_t* cur = &tweak[i * BS];
682,142✔
138
         poly_double_n_le(cur, prev, BS);
682,142✔
139
      }
140
   }
141
}
27,654✔
142

143
}  // 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

© 2026 Coveralls, Inc