Coverage Report

Created: 2025-04-11 06:34

/src/botan/build/include/internal/botan/internal/ed25519_internal.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* Ed25519
3
* (C) 2017 Ribose Inc
4
*
5
* Based on the public domain code from SUPERCOP ref10 by
6
* Peter Schwabe, Daniel J. Bernstein, Niels Duif, Tanja Lange, Bo-Yin Yang
7
*
8
* Botan is released under the Simplified BSD License (see license.txt)
9
*/
10
11
#ifndef BOTAN_ED25519_INT_H_
12
#define BOTAN_ED25519_INT_H_
13
14
#include <botan/internal/ed25519_fe.h>
15
#include <botan/internal/loadstor.h>
16
17
namespace Botan {
18
19
0
inline uint64_t load_3(const uint8_t in[3]) {
20
0
   return static_cast<uint64_t>(in[0]) | (static_cast<uint64_t>(in[1]) << 8) | (static_cast<uint64_t>(in[2]) << 16);
21
0
}
22
23
0
inline uint64_t load_4(const uint8_t* in) {
24
0
   return load_le<uint32_t>(in, 0);
25
0
}
26
27
template <size_t S, int64_t MUL = 1>
28
inline void carry(int64_t& h0, int64_t& h1)
29
   requires(S > 0 && S < 64)
30
26.7k
{
31
26.7k
   const int64_t X1 = (static_cast<int64_t>(1) << S);
32
26.7k
   const int64_t X2 = (static_cast<int64_t>(1) << (S - 1));
33
26.7k
   int64_t c = (h0 + X2) >> S;
34
26.7k
   h1 += c * MUL;
35
26.7k
   h0 -= c * X1;
36
26.7k
}
_ZN5Botan5carryILm26ELl1EEEvRlS1_QaagtT_Li0EltT_Li64E
Line
Count
Source
30
15.6k
{
31
15.6k
   const int64_t X1 = (static_cast<int64_t>(1) << S);
32
15.6k
   const int64_t X2 = (static_cast<int64_t>(1) << (S - 1));
33
15.6k
   int64_t c = (h0 + X2) >> S;
34
15.6k
   h1 += c * MUL;
35
15.6k
   h0 -= c * X1;
36
15.6k
}
_ZN5Botan5carryILm25ELl1EEEvRlS1_QaagtT_Li0EltT_Li64E
Line
Count
Source
30
8.92k
{
31
8.92k
   const int64_t X1 = (static_cast<int64_t>(1) << S);
32
8.92k
   const int64_t X2 = (static_cast<int64_t>(1) << (S - 1));
33
8.92k
   int64_t c = (h0 + X2) >> S;
34
8.92k
   h1 += c * MUL;
35
8.92k
   h0 -= c * X1;
36
8.92k
}
_ZN5Botan5carryILm25ELl19EEEvRlS1_QaagtT_Li0EltT_Li64E
Line
Count
Source
30
2.23k
{
31
2.23k
   const int64_t X1 = (static_cast<int64_t>(1) << S);
32
2.23k
   const int64_t X2 = (static_cast<int64_t>(1) << (S - 1));
33
2.23k
   int64_t c = (h0 + X2) >> S;
34
2.23k
   h1 += c * MUL;
35
2.23k
   h0 -= c * X1;
36
2.23k
}
Unexecuted instantiation: _ZN5Botan5carryILm21ELl1EEEvRlS1_QaagtT_Li0EltT_Li64E
37
38
template <size_t S>
39
inline void carry0(int64_t& h0, int64_t& h1)
40
   requires(S > 0 && S < 64)
41
0
{
42
0
   const int64_t X1 = (static_cast<int64_t>(1) << S);
43
0
   int64_t c = h0 >> S;
44
0
   h1 += c;
45
0
   h0 -= c * X1;
46
0
}
47
48
template <size_t S>
49
inline void carry0(int32_t& h0, int32_t& h1)
50
   requires(S > 0 && S < 32)
51
54
{
52
54
   const int32_t X1 = (static_cast<int64_t>(1) << S);
53
54
   int32_t c = h0 >> S;
54
54
   h1 += c;
55
54
   h0 -= c * X1;
56
54
}
_ZN5Botan6carry0ILm26EEEvRiS1_QaagtT_Li0EltT_Li32E
Line
Count
Source
51
30
{
52
30
   const int32_t X1 = (static_cast<int64_t>(1) << S);
53
30
   int32_t c = h0 >> S;
54
30
   h1 += c;
55
30
   h0 -= c * X1;
56
30
}
_ZN5Botan6carry0ILm25EEEvRiS1_QaagtT_Li0EltT_Li32E
Line
Count
Source
51
24
{
52
24
   const int32_t X1 = (static_cast<int64_t>(1) << S);
53
24
   int32_t c = h0 >> S;
54
24
   h1 += c;
55
24
   h0 -= c * X1;
56
24
}
57
58
0
inline void redc_mul(int64_t& s1, int64_t& s2, int64_t& s3, int64_t& s4, int64_t& s5, int64_t& s6, int64_t& X) {
59
0
   s1 += X * 666643;
60
0
   s2 += X * 470296;
61
0
   s3 += X * 654183;
62
0
   s4 -= X * 997805;
63
0
   s5 += X * 136657;
64
0
   s6 -= X * 683901;
65
0
   X = 0;
66
0
}
67
68
/*
69
ge means group element.
70
71
Here the group is the set of pairs (x,y) of field elements (see fe.h)
72
satisfying -x^2 + y^2 = 1 + d x^2y^2
73
where d = -121665/121666.
74
75
Representations:
76
  ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
77
*/
78
79
struct ge_p3 {
80
      FE_25519 X;
81
      FE_25519 Y;
82
      FE_25519 Z;
83
      FE_25519 T;
84
};
85
86
int ge_frombytes_negate_vartime(ge_p3* v, const uint8_t*);
87
void ge_scalarmult_base(uint8_t out[32], const uint8_t in[32]);
88
89
void ge_double_scalarmult_vartime(uint8_t out[32], const uint8_t a[], const ge_p3* A, const uint8_t b[]);
90
91
/*
92
The set of scalars is \Z/l
93
where l = 2^252 + 27742317777372353535851937790883648493.
94
*/
95
96
void sc_reduce(uint8_t*);
97
void sc_muladd(uint8_t*, const uint8_t*, const uint8_t*, const uint8_t*);
98
99
}  // namespace Botan
100
101
#endif