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

systemd / systemd / 25351067578

04 May 2026 06:45PM UTC coverage: 72.674% (+0.7%) from 71.943%
25351067578

push

github

keszybz
test: suppress PCR public key auto-loading in TEST-70-TPM2 dditest

The dditest block calls systemd-repart with Encrypt=tpm2 but without
--tpm2-public-key-pcrs=. Since systemd-stub drops
/run/systemd/tpm2-pcr-public-key.pem when booting from a signed UKI
systemd-repart auto-loads it and enrolls a signed PCR policy, and
then systemd-cryptsetup tpm2-device=auto has no matching signature file,
so unlock fails.

--tpm2-public-key= is not enough as the default kicks in then.

Follow-up for cd18656d4

325892 of 448432 relevant lines covered (72.67%)

1195556.07 hits per line

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

95.37
/src/basic/siphash24.c
1
/* SPDX-License-Identifier: CC0-1.0 */
2

3
/*
4
   SipHash reference C implementation
5

6
   Written in 2012 by
7
   Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
8
   Daniel J. Bernstein <djb@cr.yp.to>
9

10
   To the extent possible under law, the author(s) have dedicated all copyright
11
   and related and neighboring rights to this software to the public domain
12
   worldwide. This software is distributed without any warranty.
13

14
   You should have received a copy of the CC0 Public Domain Dedication along with
15
   this software. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
16

17
   (Minimal changes made by Lennart Poettering, to make clean for inclusion in systemd)
18
   (Refactored by Tom Gundersen to split up in several functions and follow systemd
19
    coding style)
20
*/
21

22
#include <stdio.h>
23

24
#include "iovec-util.h"
25
#include "siphash24.h"
26
#include "string-util.h"
27
#include "unaligned.h"
28

29
static uint64_t rotate_left(uint64_t x, uint8_t b) {
2,147,483,647✔
30
        assert(b < 64);
2,147,483,647✔
31

32
        return (x << b) | (x >> (64 - b));
2,147,483,647✔
33
}
34

35
static void sipround(struct siphash *state) {
2,147,483,647✔
36
        assert(state);
2,147,483,647✔
37

38
        state->v0 += state->v1;
2,147,483,647✔
39
        state->v1 = rotate_left(state->v1, 13);
2,147,483,647✔
40
        state->v1 ^= state->v0;
2,147,483,647✔
41
        state->v0 = rotate_left(state->v0, 32);
2,147,483,647✔
42
        state->v2 += state->v3;
2,147,483,647✔
43
        state->v3 = rotate_left(state->v3, 16);
2,147,483,647✔
44
        state->v3 ^= state->v2;
2,147,483,647✔
45
        state->v0 += state->v3;
2,147,483,647✔
46
        state->v3 = rotate_left(state->v3, 21);
2,147,483,647✔
47
        state->v3 ^= state->v0;
2,147,483,647✔
48
        state->v2 += state->v1;
2,147,483,647✔
49
        state->v1 = rotate_left(state->v1, 17);
2,147,483,647✔
50
        state->v1 ^= state->v2;
2,147,483,647✔
51
        state->v2 = rotate_left(state->v2, 32);
2,147,483,647✔
52
}
2,147,483,647✔
53

54
void siphash24_init(struct siphash *state, const uint8_t k[static 16]) {
275,608,823✔
55
        uint64_t k0, k1;
275,608,823✔
56

57
        assert(state);
275,608,823✔
58
        assert(k);
275,608,823✔
59

60
        k0 = unaligned_read_le64(k);
275,608,823✔
61
        k1 = unaligned_read_le64(k + 8);
275,608,823✔
62

63
        *state = (struct siphash) {
275,608,823✔
64
                /* "somepseudorandomlygeneratedbytes" */
65
                .v0 = 0x736f6d6570736575ULL ^ k0,
275,608,823✔
66
                .v1 = 0x646f72616e646f6dULL ^ k1,
275,608,823✔
67
                .v2 = 0x6c7967656e657261ULL ^ k0,
275,608,823✔
68
                .v3 = 0x7465646279746573ULL ^ k1,
275,608,823✔
69
                .padding = 0,
70
                .inlen = 0,
71
        };
72
}
275,608,823✔
73

74
void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) {
604,181,211✔
75

76
        const uint8_t *in = ASSERT_PTR(_in);
604,181,211✔
77
        const uint8_t *end = in + inlen;
604,181,211✔
78
        size_t left = state->inlen & 7;
604,181,211✔
79
        uint64_t m;
604,181,211✔
80

81
        assert(state);
604,181,211✔
82

83
        /* Update total length */
84
        state->inlen += inlen;
604,181,211✔
85

86
        /* If padding exists, fill it out */
87
        if (left > 0) {
604,181,211✔
88
                for ( ; in < end && left < 8; in ++, left ++)
987,293,676✔
89
                        state->padding |= ((uint64_t) *in) << (left * 8);
685,623,759✔
90

91
                if (in == end && left < 8)
301,669,917✔
92
                        /* We did not have enough input to fill out the padding completely */
93
                        return;
94

95
#if ENABLE_DEBUG_SIPHASH
96
                printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
97
                printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
98
                printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
99
                printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
100
                printf("(%3zu) compress padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t)state->padding);
101
#endif
102

103
                state->v3 ^= state->padding;
140,370,408✔
104
                sipround(state);
140,370,408✔
105
                sipround(state);
140,370,408✔
106
                state->v0 ^= state->padding;
140,370,408✔
107

108
                state->padding = 0;
140,370,408✔
109
        }
110

111
        end -= (state->inlen % sizeof(uint64_t));
442,881,702✔
112

113
        for ( ; in < end; in += 8) {
962,434,861✔
114
                m = unaligned_read_le64(in);
519,553,159✔
115
#if ENABLE_DEBUG_SIPHASH
116
                printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
117
                printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
118
                printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
119
                printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
120
                printf("(%3zu) compress %08x %08x\n", state->inlen, (uint32_t) (m >> 32), (uint32_t) m);
121
#endif
122
                state->v3 ^= m;
519,553,159✔
123
                sipround(state);
519,553,159✔
124
                sipround(state);
519,553,159✔
125
                state->v0 ^= m;
519,553,159✔
126
        }
127

128
        left = state->inlen & 7;
442,881,702✔
129
        switch (left) {
442,881,702✔
130
                case 7:
33,233,412✔
131
                        state->padding |= ((uint64_t) in[6]) << 48;
33,233,412✔
132
                        _fallthrough_;
71,715,724✔
133
                case 6:
71,715,724✔
134
                        state->padding |= ((uint64_t) in[5]) << 40;
71,715,724✔
135
                        _fallthrough_;
98,155,556✔
136
                case 5:
98,155,556✔
137
                        state->padding |= ((uint64_t) in[4]) << 32;
98,155,556✔
138
                        _fallthrough_;
130,466,252✔
139
                case 4:
130,466,252✔
140
                        state->padding |= ((uint64_t) in[3]) << 24;
130,466,252✔
141
                        _fallthrough_;
165,506,261✔
142
                case 3:
165,506,261✔
143
                        state->padding |= ((uint64_t) in[2]) << 16;
165,506,261✔
144
                        _fallthrough_;
194,410,355✔
145
                case 2:
194,410,355✔
146
                        state->padding |= ((uint64_t) in[1]) <<  8;
194,410,355✔
147
                        _fallthrough_;
277,005,485✔
148
                case 1:
277,005,485✔
149
                        state->padding |= ((uint64_t) in[0]);
277,005,485✔
150
                        _fallthrough_;
151
                case 0:
152
                        break;
153
        }
154
}
155

156
void siphash24_compress_string(const char *in, struct siphash *state) {
240,896✔
157
        siphash24_compress_safe(in, strlen_ptr(in), state);
240,896✔
158
}
240,896✔
159

160
void siphash24_compress_iovec(const struct iovec *iov, struct siphash *state) {
×
161
        assert(iovec_is_valid(iov));
×
162
        assert(state);
×
163

164
        if (!iovec_is_set(iov))
×
165
                return;
166

167
        siphash24_compress(iov->iov_base, iov->iov_len, state);
×
168
}
169

170
uint64_t siphash24_finalize(struct siphash *state) {
275,608,821✔
171
        uint64_t b;
275,608,821✔
172

173
        assert(state);
275,608,821✔
174

175
        b = state->padding | (((uint64_t) state->inlen) << 56);
275,608,821✔
176

177
#if ENABLE_DEBUG_SIPHASH
178
        printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
179
        printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
180
        printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
181
        printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
182
        printf("(%3zu) padding   %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t) state->padding);
183
#endif
184

185
        state->v3 ^= b;
275,608,821✔
186
        sipround(state);
275,608,821✔
187
        sipround(state);
275,608,821✔
188
        state->v0 ^= b;
275,608,821✔
189

190
#if ENABLE_DEBUG_SIPHASH
191
        printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0);
192
        printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1);
193
        printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2);
194
        printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3);
195
#endif
196
        state->v2 ^= 0xff;
275,608,821✔
197

198
        sipround(state);
275,608,821✔
199
        sipround(state);
275,608,821✔
200
        sipround(state);
275,608,821✔
201
        sipround(state);
275,608,821✔
202

203
        return state->v0 ^ state->v1 ^ state->v2  ^ state->v3;
275,608,821✔
204
}
205

206
uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[static 16]) {
37,178,989✔
207
        struct siphash state;
37,178,989✔
208

209
        assert(in);
37,178,989✔
210
        assert(k);
37,178,989✔
211

212
        siphash24_init(&state, k);
37,178,989✔
213
        siphash24_compress(in, inlen, &state);
37,178,989✔
214

215
        return siphash24_finalize(&state);
37,178,989✔
216
}
217

218
uint64_t siphash24_string(const char *s, const uint8_t k[static 16]) {
107✔
219
        return siphash24(s, strlen(s) + 1, k);
107✔
220
}
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