Coverage Report

Created: 2026-11-12 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opensc/src/common/constant-time.h
Line
Count
Source
1
/* Original source: https://github.com/openssl/openssl/blob/9890cc42daff5e2d0cad01ac4bf78c391f599a6e/include/internal/constant_time.h */
2
3
#ifndef CONSTANT_TIME_H
4
#define CONSTANT_TIME_H
5
6
#include <stdlib.h>
7
#include <string.h>
8
9
#if !defined(inline)
10
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
11
#define constant_inline inline
12
#elif defined(__GNUC__) && __GNUC__ >= 2
13
#elif defined(__GNUC__) && __GNUC__ >= 2
14
#elif defined(_MSC_VER)
15
#define constant_inline __inline
16
#else
17
#define constant_inline
18
#endif
19
#else            /* use what caller wants as inline  may be from config.h */
20
#define constant_inline inline /* inline */
21
#endif
22
23
/*-
24
 * The boolean methods return a bitmask of all ones (0xff...f) for true
25
 * and 0 for false. For example,
26
 *      if (a < b) {
27
 *        c = a;
28
 *      } else {
29
 *        c = b;
30
 *      }
31
 * can be written as
32
 *      unsigned int lt = constant_time_lt(a, b);
33
 *      c = constant_time_select(lt, a, b);
34
 */
35
36
static constant_inline unsigned int
37
value_barrier(unsigned int a)
38
389k
{
39
389k
  volatile unsigned int r = a;
40
389k
  return r;
41
389k
}
Unexecuted instantiation: misc.c:value_barrier
Unexecuted instantiation: mechanism.c:value_barrier
framework-pkcs15.c:value_barrier
Line
Count
Source
38
133k
{
39
133k
  volatile unsigned int r = a;
40
133k
  return r;
41
133k
}
padding.c:value_barrier
Line
Count
Source
38
256k
{
39
256k
  volatile unsigned int r = a;
40
256k
  return r;
41
256k
}
42
43
static constant_inline size_t
44
value_barrier_s(size_t a)
45
266k
{
46
266k
  volatile size_t r = a;
47
266k
  return r;
48
266k
}
Unexecuted instantiation: misc.c:value_barrier_s
Unexecuted instantiation: mechanism.c:value_barrier_s
framework-pkcs15.c:value_barrier_s
Line
Count
Source
45
266k
{
46
266k
  volatile size_t r = a;
47
266k
  return r;
48
266k
}
Unexecuted instantiation: padding.c:value_barrier_s
49
50
/* MSB */
51
static constant_inline size_t
52
constant_time_msb_s(size_t a)
53
136k
{
54
136k
  return 0 - (a >> (sizeof(a) * 8 - 1));
55
136k
}
misc.c:constant_time_msb_s
Line
Count
Source
53
3.03k
{
54
3.03k
  return 0 - (a >> (sizeof(a) * 8 - 1));
55
3.03k
}
mechanism.c:constant_time_msb_s
Line
Count
Source
53
164
{
54
164
  return 0 - (a >> (sizeof(a) * 8 - 1));
55
164
}
framework-pkcs15.c:constant_time_msb_s
Line
Count
Source
53
133k
{
54
133k
  return 0 - (a >> (sizeof(a) * 8 - 1));
55
133k
}
Unexecuted instantiation: padding.c:constant_time_msb_s
56
57
static constant_inline unsigned int
58
constant_time_msb(unsigned int a)
59
35.1k
{
60
35.1k
  return 0 - (a >> (sizeof(a) * 8 - 1));
61
35.1k
}
Unexecuted instantiation: misc.c:constant_time_msb
Unexecuted instantiation: mechanism.c:constant_time_msb
framework-pkcs15.c:constant_time_msb
Line
Count
Source
59
65
{
60
65
  return 0 - (a >> (sizeof(a) * 8 - 1));
61
65
}
padding.c:constant_time_msb
Line
Count
Source
59
35.1k
{
60
35.1k
  return 0 - (a >> (sizeof(a) * 8 - 1));
61
35.1k
}
62
63
/* Select */
64
static constant_inline unsigned int
65
constant_time_select(unsigned int mask, unsigned int a, unsigned int b)
66
194k
{
67
194k
  return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
68
194k
}
Unexecuted instantiation: misc.c:constant_time_select
Unexecuted instantiation: mechanism.c:constant_time_select
framework-pkcs15.c:constant_time_select
Line
Count
Source
66
66.5k
{
67
66.5k
  return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
68
66.5k
}
padding.c:constant_time_select
Line
Count
Source
66
128k
{
67
128k
  return (value_barrier(mask) & a) | (value_barrier(~mask) & b);
68
128k
}
69
70
static constant_inline unsigned char
71
constant_time_select_8(unsigned char mask, unsigned char a, unsigned char b)
72
175k
{
73
175k
  return (unsigned char)constant_time_select(mask, a, b);
74
175k
}
Unexecuted instantiation: misc.c:constant_time_select_8
Unexecuted instantiation: mechanism.c:constant_time_select_8
framework-pkcs15.c:constant_time_select_8
Line
Count
Source
72
66.5k
{
73
66.5k
  return (unsigned char)constant_time_select(mask, a, b);
74
66.5k
}
padding.c:constant_time_select_8
Line
Count
Source
72
108k
{
73
108k
  return (unsigned char)constant_time_select(mask, a, b);
74
108k
}
75
76
static constant_inline size_t
77
constant_time_select_s(size_t mask, size_t a, size_t b)
78
133k
{
79
133k
  return (value_barrier_s(mask) & a) | (value_barrier_s(~mask) & b);
80
133k
}
Unexecuted instantiation: misc.c:constant_time_select_s
Unexecuted instantiation: mechanism.c:constant_time_select_s
framework-pkcs15.c:constant_time_select_s
Line
Count
Source
78
133k
{
79
133k
  return (value_barrier_s(mask) & a) | (value_barrier_s(~mask) & b);
80
133k
}
Unexecuted instantiation: padding.c:constant_time_select_s
81
82
/* Zero */
83
static constant_inline unsigned int
84
constant_time_is_zero(unsigned int a)
85
30.4k
{
86
30.4k
  return constant_time_msb(~a & (a - 1));
87
30.4k
}
Unexecuted instantiation: misc.c:constant_time_is_zero
Unexecuted instantiation: mechanism.c:constant_time_is_zero
framework-pkcs15.c:constant_time_is_zero
Line
Count
Source
85
65
{
86
65
  return constant_time_msb(~a & (a - 1));
87
65
}
padding.c:constant_time_is_zero
Line
Count
Source
85
30.3k
{
86
30.3k
  return constant_time_msb(~a & (a - 1));
87
30.3k
}
88
89
static constant_inline size_t
90
constant_time_is_zero_s(size_t a)
91
3.35k
{
92
3.35k
  return constant_time_msb_s(~a & (a - 1));
93
3.35k
}
misc.c:constant_time_is_zero_s
Line
Count
Source
91
3.03k
{
92
3.03k
  return constant_time_msb_s(~a & (a - 1));
93
3.03k
}
mechanism.c:constant_time_is_zero_s
Line
Count
Source
91
164
{
92
164
  return constant_time_msb_s(~a & (a - 1));
93
164
}
framework-pkcs15.c:constant_time_is_zero_s
Line
Count
Source
91
162
{
92
162
  return constant_time_msb_s(~a & (a - 1));
93
162
}
Unexecuted instantiation: padding.c:constant_time_is_zero_s
94
95
/* Comparison*/
96
static constant_inline size_t
97
constant_time_lt_s(size_t a, size_t b)
98
133k
{
99
133k
  return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
100
133k
}
Unexecuted instantiation: misc.c:constant_time_lt_s
Unexecuted instantiation: mechanism.c:constant_time_lt_s
framework-pkcs15.c:constant_time_lt_s
Line
Count
Source
98
133k
{
99
133k
  return constant_time_msb_s(a ^ ((a ^ b) | ((a - b) ^ b)));
100
133k
}
Unexecuted instantiation: padding.c:constant_time_lt_s
101
102
static constant_inline unsigned int
103
constant_time_lt(unsigned int a, unsigned int b)
104
4.73k
{
105
4.73k
  return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
106
4.73k
}
Unexecuted instantiation: misc.c:constant_time_lt
Unexecuted instantiation: mechanism.c:constant_time_lt
Unexecuted instantiation: framework-pkcs15.c:constant_time_lt
padding.c:constant_time_lt
Line
Count
Source
104
4.73k
{
105
4.73k
  return constant_time_msb(a ^ ((a ^ b) | ((a - b) ^ b)));
106
4.73k
}
107
108
static constant_inline unsigned int
109
constant_time_ge(unsigned int a, unsigned int b)
110
102
{
111
102
  return ~constant_time_lt(a, b);
112
102
}
Unexecuted instantiation: misc.c:constant_time_ge
Unexecuted instantiation: mechanism.c:constant_time_ge
Unexecuted instantiation: framework-pkcs15.c:constant_time_ge
padding.c:constant_time_ge
Line
Count
Source
110
102
{
111
102
  return ~constant_time_lt(a, b);
112
102
}
113
114
/* Equality*/
115
116
static constant_inline unsigned int
117
constant_time_eq(unsigned int a, unsigned int b)
118
539
{
119
539
  return constant_time_is_zero(a ^ b);
120
539
}
Unexecuted instantiation: misc.c:constant_time_eq
Unexecuted instantiation: mechanism.c:constant_time_eq
framework-pkcs15.c:constant_time_eq
Line
Count
Source
118
65
{
119
65
  return constant_time_is_zero(a ^ b);
120
65
}
padding.c:constant_time_eq
Line
Count
Source
118
474
{
119
474
  return constant_time_is_zero(a ^ b);
120
474
}
121
122
static constant_inline size_t
123
constant_time_eq_s(size_t a, size_t b)
124
3.35k
{
125
3.35k
  return constant_time_is_zero_s(a ^ b);
126
3.35k
}
misc.c:constant_time_eq_s
Line
Count
Source
124
3.03k
{
125
3.03k
  return constant_time_is_zero_s(a ^ b);
126
3.03k
}
mechanism.c:constant_time_eq_s
Line
Count
Source
124
164
{
125
164
  return constant_time_is_zero_s(a ^ b);
126
164
}
framework-pkcs15.c:constant_time_eq_s
Line
Count
Source
124
162
{
125
162
  return constant_time_is_zero_s(a ^ b);
126
162
}
Unexecuted instantiation: padding.c:constant_time_eq_s
127
128
static constant_inline unsigned int
129
constant_time_eq_i(int a, int b)
130
65
{
131
65
  return constant_time_eq((unsigned int)a, (unsigned int)b);
132
65
}
Unexecuted instantiation: misc.c:constant_time_eq_i
Unexecuted instantiation: mechanism.c:constant_time_eq_i
framework-pkcs15.c:constant_time_eq_i
Line
Count
Source
130
65
{
131
65
  return constant_time_eq((unsigned int)a, (unsigned int)b);
132
65
}
Unexecuted instantiation: padding.c:constant_time_eq_i
133
134
#endif /* CONSTANT_TIME_H */