Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/siphash/siphash.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | size_t SipHash_ctx_size(void) | - | ||||||
3 | { | - | ||||||
4 | return never executed: sizeof(SIPHASH);return sizeof(SIPHASH); never executed: return sizeof(SIPHASH); | 0 | ||||||
5 | } | - | ||||||
6 | - | |||||||
7 | size_t SipHash_hash_size(SIPHASH *ctx) | - | ||||||
8 | { | - | ||||||
9 | return executed 52 times by 1 test: ctx->hash_size;return ctx->hash_size; Executed by:
executed 52 times by 1 test: return ctx->hash_size; Executed by:
| 52 | ||||||
10 | } | - | ||||||
11 | - | |||||||
12 | static size_t siphash_adjust_hash_size(size_t hash_size) | - | ||||||
13 | { | - | ||||||
14 | if (hash_size == 0
| 28-885 | ||||||
15 | hash_size = 16; executed 28 times by 2 tests: hash_size = 16; Executed by:
| 28 | ||||||
16 | return executed 913 times by 2 tests: hash_size;return hash_size; Executed by:
executed 913 times by 2 tests: return hash_size; Executed by:
| 913 | ||||||
17 | } | - | ||||||
18 | - | |||||||
19 | int SipHash_set_hash_size(SIPHASH *ctx, size_t hash_size) | - | ||||||
20 | { | - | ||||||
21 | hash_size = siphash_adjust_hash_size(hash_size); | - | ||||||
22 | if (hash_size != 8
| 221-225 | ||||||
23 | && hash_size != 16
| 2-223 | ||||||
24 | return executed 2 times by 2 tests: 0;return 0; Executed by:
executed 2 times by 2 tests: return 0; Executed by:
| 2 | ||||||
25 | - | |||||||
26 | ctx->hash_size = hash_size; | - | ||||||
27 | return executed 444 times by 2 tests: 1;return 1; Executed by:
executed 444 times by 2 tests: return 1; Executed by:
| 444 | ||||||
28 | } | - | ||||||
29 | - | |||||||
30 | - | |||||||
31 | int SipHash_Init(SIPHASH *ctx, const unsigned char *k, int crounds, int drounds) | - | ||||||
32 | { | - | ||||||
33 | uint64_t k0 = (((uint64_t)((k)[0])) | ((uint64_t)((k)[1]) << 8) | ((uint64_t)((k)[2]) << 16) | ((uint64_t)((k)[3]) << 24) | ((uint64_t)((k)[4]) << 32) | ((uint64_t)((k)[5]) << 40) | ((uint64_t)((k)[6]) << 48) | ((uint64_t)((k)[7]) << 56)); | - | ||||||
34 | uint64_t k1 = (((uint64_t)((k + 8)[0])) | ((uint64_t)((k + 8)[1]) << 8) | ((uint64_t)((k + 8)[2]) << 16) | ((uint64_t)((k + 8)[3]) << 24) | ((uint64_t)((k + 8)[4]) << 32) | ((uint64_t)((k + 8)[5]) << 40) | ((uint64_t)((k + 8)[6]) << 48) | ((uint64_t)((k + 8)[7]) << 56)); | - | ||||||
35 | - | |||||||
36 | - | |||||||
37 | ctx->hash_size = siphash_adjust_hash_size(ctx->hash_size); | - | ||||||
38 | - | |||||||
39 | if (drounds == 0
| 0-467 | ||||||
40 | drounds = 4; executed 467 times by 2 tests: drounds = 4; Executed by:
| 467 | ||||||
41 | if (crounds == 0
| 0-467 | ||||||
42 | crounds = 2; executed 467 times by 2 tests: crounds = 2; Executed by:
| 467 | ||||||
43 | - | |||||||
44 | ctx->crounds = crounds; | - | ||||||
45 | ctx->drounds = drounds; | - | ||||||
46 | - | |||||||
47 | ctx->len = 0; | - | ||||||
48 | ctx->total_inlen = 0; | - | ||||||
49 | - | |||||||
50 | ctx->v0 = 0x736f6d6570736575ULL ^ k0; | - | ||||||
51 | ctx->v1 = 0x646f72616e646f6dULL ^ k1; | - | ||||||
52 | ctx->v2 = 0x6c7967656e657261ULL ^ k0; | - | ||||||
53 | ctx->v3 = 0x7465646279746573ULL ^ k1; | - | ||||||
54 | - | |||||||
55 | if (ctx->hash_size == 16
| 220-247 | ||||||
56 | ctx->v1 ^= 0xee; executed 247 times by 2 tests: ctx->v1 ^= 0xee; Executed by:
| 247 | ||||||
57 | - | |||||||
58 | return executed 467 times by 2 tests: 1;return 1; Executed by:
executed 467 times by 2 tests: return 1; Executed by:
| 467 | ||||||
59 | } | - | ||||||
60 | - | |||||||
61 | void SipHash_Update(SIPHASH *ctx, const unsigned char *in, size_t inlen) | - | ||||||
62 | { | - | ||||||
63 | uint64_t m; | - | ||||||
64 | const uint8_t *end; | - | ||||||
65 | int left; | - | ||||||
66 | int i; | - | ||||||
67 | uint64_t v0 = ctx->v0; | - | ||||||
68 | uint64_t v1 = ctx->v1; | - | ||||||
69 | uint64_t v2 = ctx->v2; | - | ||||||
70 | uint64_t v3 = ctx->v3; | - | ||||||
71 | - | |||||||
72 | ctx->total_inlen += inlen; | - | ||||||
73 | - | |||||||
74 | if (ctx->len
| 150-624 | ||||||
75 | - | |||||||
76 | size_t available = 8 - ctx->len; | - | ||||||
77 | - | |||||||
78 | - | |||||||
79 | if (inlen < available
| 0-150 | ||||||
80 | memcpy(&ctx->leavings[ctx->len], in, inlen); | - | ||||||
81 | ctx->len += inlen; | - | ||||||
82 | return; never executed: return; | 0 | ||||||
83 | } | - | ||||||
84 | - | |||||||
85 | - | |||||||
86 | memcpy(&ctx->leavings[ctx->len], in, available); | - | ||||||
87 | inlen -= available; | - | ||||||
88 | in += available; | - | ||||||
89 | - | |||||||
90 | - | |||||||
91 | m = (((uint64_t)((ctx->leavings)[0])) | ((uint64_t)((ctx->leavings)[1]) << 8) | ((uint64_t)((ctx->leavings)[2]) << 16) | ((uint64_t)((ctx->leavings)[3]) << 24) | ((uint64_t)((ctx->leavings)[4]) << 32) | ((uint64_t)((ctx->leavings)[5]) << 40) | ((uint64_t)((ctx->leavings)[6]) << 48) | ((uint64_t)((ctx->leavings)[7]) << 56)); | - | ||||||
92 | v3 ^= m; | - | ||||||
93 | for (i = 0; i < ctx->crounds
| 150-300 | ||||||
94 | do { v0 += v1; v1 = (uint64_t)(((v1) << (13)) | ((v1) >> (64 - (13)))); v1 ^= v0; v0 = (uint64_t)(((v0) << (32)) | ((v0) >> (64 - (32)))); v2 += v3; v3 = (uint64_t)(((v3) << (16)) | ((v3) >> (64 - (16)))); v3 ^= v2; v0 += v3; v3 = (uint64_t)(((v3) << (21)) | ((v3) >> (64 - (21)))); v3 ^= v0; v2 += v1; v1 = (uint64_t)(((v1) << (17)) | ((v1) >> (64 - (17)))); v1 ^= v2; v2 = (uint64_t)(((v2) << (32)) | ((v2) >> (64 - (32)))); } executed 300 times by 1 test: while (0);end of block Executed by:
| 300 | ||||||
95 | v0 ^= m; | - | ||||||
96 | } executed 150 times by 1 test: end of block Executed by:
| 150 | ||||||
97 | left = inlen & (8 -1); | - | ||||||
98 | end = in + inlen - left; | - | ||||||
99 | - | |||||||
100 | for (; in != end
| 774-2000 | ||||||
101 | m = (((uint64_t)((in)[0])) | ((uint64_t)((in)[1]) << 8) | ((uint64_t)((in)[2]) << 16) | ((uint64_t)((in)[3]) << 24) | ((uint64_t)((in)[4]) << 32) | ((uint64_t)((in)[5]) << 40) | ((uint64_t)((in)[6]) << 48) | ((uint64_t)((in)[7]) << 56)); | - | ||||||
102 | v3 ^= m; | - | ||||||
103 | for (i = 0; i < ctx->crounds
| 2000-4000 | ||||||
104 | do { v0 += v1; v1 = (uint64_t)(((v1) << (13)) | ((v1) >> (64 - (13)))); v1 ^= v0; v0 = (uint64_t)(((v0) << (32)) | ((v0) >> (64 - (32)))); v2 += v3; v3 = (uint64_t)(((v3) << (16)) | ((v3) >> (64 - (16)))); v3 ^= v2; v0 += v3; v3 = (uint64_t)(((v3) << (21)) | ((v3) >> (64 - (21)))); v3 ^= v0; v2 += v1; v1 = (uint64_t)(((v1) << (17)) | ((v1) >> (64 - (17)))); v1 ^= v2; v2 = (uint64_t)(((v2) << (32)) | ((v2) >> (64 - (32)))); } executed 4000 times by 2 tests: while (0);end of block Executed by:
| 4000 | ||||||
105 | v0 ^= m; | - | ||||||
106 | } executed 2000 times by 2 tests: end of block Executed by:
| 2000 | ||||||
107 | - | |||||||
108 | - | |||||||
109 | if (left
| 210-564 | ||||||
110 | memcpy(ctx->leavings, end, left); executed 564 times by 2 tests: memcpy(ctx->leavings, end, left); Executed by:
| 564 | ||||||
111 | ctx->len = left; | - | ||||||
112 | - | |||||||
113 | ctx->v0 = v0; | - | ||||||
114 | ctx->v1 = v1; | - | ||||||
115 | ctx->v2 = v2; | - | ||||||
116 | ctx->v3 = v3; | - | ||||||
117 | } executed 774 times by 2 tests: end of block Executed by:
| 774 | ||||||
118 | - | |||||||
119 | int SipHash_Final(SIPHASH *ctx, unsigned char *out, size_t outlen) | - | ||||||
120 | { | - | ||||||
121 | - | |||||||
122 | int i; | - | ||||||
123 | uint64_t b = ctx->total_inlen << 56; | - | ||||||
124 | uint64_t v0 = ctx->v0; | - | ||||||
125 | uint64_t v1 = ctx->v1; | - | ||||||
126 | uint64_t v2 = ctx->v2; | - | ||||||
127 | uint64_t v3 = ctx->v3; | - | ||||||
128 | - | |||||||
129 | if (outlen != (size_t)ctx->hash_size
| 3-467 | ||||||
130 | return executed 3 times by 1 test: 0;return 0; Executed by:
executed 3 times by 1 test: return 0; Executed by:
| 3 | ||||||
131 | - | |||||||
132 | switch (ctx->len) { | - | ||||||
133 | case executed 64 times by 2 tests: 7:case 7: Executed by:
executed 64 times by 2 tests: case 7: Executed by:
| 64 | ||||||
134 | b |= ((uint64_t)ctx->leavings[6]) << 48; | - | ||||||
135 | - | |||||||
136 | case executed 58 times by 2 tests: 6:case 6: Executed by:
executed 58 times by 2 tests: case 6: Executed by:
code before this statement executed 64 times by 2 tests: case 6: Executed by:
| 58-64 | ||||||
137 | b |= ((uint64_t)ctx->leavings[5]) << 40; | - | ||||||
138 | - | |||||||
139 | case executed 58 times by 2 tests: 5:case 5: Executed by:
executed 58 times by 2 tests: case 5: Executed by:
code before this statement executed 122 times by 2 tests: case 5: Executed by:
| 58-122 | ||||||
140 | b |= ((uint64_t)ctx->leavings[4]) << 32; | - | ||||||
141 | - | |||||||
142 | case executed 58 times by 2 tests: 4:case 4: Executed by:
executed 58 times by 2 tests: case 4: Executed by:
code before this statement executed 180 times by 2 tests: case 4: Executed by:
| 58-180 | ||||||
143 | b |= ((uint64_t)ctx->leavings[3]) << 24; | - | ||||||
144 | - | |||||||
145 | case executed 58 times by 2 tests: 3:case 3: Executed by:
executed 58 times by 2 tests: case 3: Executed by:
code before this statement executed 238 times by 2 tests: case 3: Executed by:
| 58-238 | ||||||
146 | b |= ((uint64_t)ctx->leavings[2]) << 16; | - | ||||||
147 | - | |||||||
148 | case executed 58 times by 2 tests: 2:case 2: Executed by:
executed 58 times by 2 tests: case 2: Executed by:
code before this statement executed 296 times by 2 tests: case 2: Executed by:
| 58-296 | ||||||
149 | b |= ((uint64_t)ctx->leavings[1]) << 8; | - | ||||||
150 | - | |||||||
151 | case executed 60 times by 2 tests: 1:case 1: Executed by:
executed 60 times by 2 tests: case 1: Executed by:
code before this statement executed 354 times by 2 tests: case 1: Executed by:
| 60-354 | ||||||
152 | b |= ((uint64_t)ctx->leavings[0]); | - | ||||||
153 | case executed 467 times by 2 tests: 0:case 0: Executed by:
executed 467 times by 2 tests: case 0: Executed by:
code before this statement executed 414 times by 2 tests: case 0: Executed by:
| 414-467 | ||||||
154 | break; executed 467 times by 2 tests: break; Executed by:
| 467 | ||||||
155 | } | - | ||||||
156 | - | |||||||
157 | v3 ^= b; | - | ||||||
158 | for (i = 0; i < ctx->crounds
| 467-934 | ||||||
159 | do { v0 += v1; v1 = (uint64_t)(((v1) << (13)) | ((v1) >> (64 - (13)))); v1 ^= v0; v0 = (uint64_t)(((v0) << (32)) | ((v0) >> (64 - (32)))); v2 += v3; v3 = (uint64_t)(((v3) << (16)) | ((v3) >> (64 - (16)))); v3 ^= v2; v0 += v3; v3 = (uint64_t)(((v3) << (21)) | ((v3) >> (64 - (21)))); v3 ^= v0; v2 += v1; v1 = (uint64_t)(((v1) << (17)) | ((v1) >> (64 - (17)))); v1 ^= v2; v2 = (uint64_t)(((v2) << (32)) | ((v2) >> (64 - (32)))); } executed 934 times by 2 tests: while (0);end of block Executed by:
| 934 | ||||||
160 | v0 ^= b; | - | ||||||
161 | if (ctx->hash_size == 16
| 221-246 | ||||||
162 | v2 ^= 0xee; executed 246 times by 2 tests: v2 ^= 0xee; Executed by:
| 246 | ||||||
163 | else | - | ||||||
164 | v2 ^= 0xff; executed 221 times by 2 tests: v2 ^= 0xff; Executed by:
| 221 | ||||||
165 | for (i = 0; i < ctx->drounds
| 467-1868 | ||||||
166 | do { v0 += v1; v1 = (uint64_t)(((v1) << (13)) | ((v1) >> (64 - (13)))); v1 ^= v0; v0 = (uint64_t)(((v0) << (32)) | ((v0) >> (64 - (32)))); v2 += v3; v3 = (uint64_t)(((v3) << (16)) | ((v3) >> (64 - (16)))); v3 ^= v2; v0 += v3; v3 = (uint64_t)(((v3) << (21)) | ((v3) >> (64 - (21)))); v3 ^= v0; v2 += v1; v1 = (uint64_t)(((v1) << (17)) | ((v1) >> (64 - (17)))); v1 ^= v2; v2 = (uint64_t)(((v2) << (32)) | ((v2) >> (64 - (32)))); } executed 1868 times by 2 tests: while (0);end of block Executed by:
| 1868 | ||||||
167 | b = v0 ^ v1 ^ v2 ^ v3; | - | ||||||
168 | ((out))[0] = (uint8_t)(((uint32_t)((b)))); ((out))[1] = (uint8_t)(((uint32_t)((b))) >> 8); ((out))[2] = (uint8_t)(((uint32_t)((b))) >> 16); ((out))[3] = (uint8_t)(((uint32_t)((b))) >> 24);; ((out) + 4)[0] = (uint8_t)(((uint32_t)((b) >> 32))); ((out) + 4)[1] = (uint8_t)(((uint32_t)((b) >> 32)) >> 8); ((out) + 4)[2] = (uint8_t)(((uint32_t)((b) >> 32)) >> 16); ((out) + 4)[3] = (uint8_t)(((uint32_t)((b) >> 32)) >> 24);;; | - | ||||||
169 | if (ctx->hash_size == 8
| 221-246 | ||||||
170 | return executed 221 times by 2 tests: 1;return 1; Executed by:
executed 221 times by 2 tests: return 1; Executed by:
| 221 | ||||||
171 | v1 ^= 0xdd; | - | ||||||
172 | for (i = 0; i < ctx->drounds
| 246-984 | ||||||
173 | do { v0 += v1; v1 = (uint64_t)(((v1) << (13)) | ((v1) >> (64 - (13)))); v1 ^= v0; v0 = (uint64_t)(((v0) << (32)) | ((v0) >> (64 - (32)))); v2 += v3; v3 = (uint64_t)(((v3) << (16)) | ((v3) >> (64 - (16)))); v3 ^= v2; v0 += v3; v3 = (uint64_t)(((v3) << (21)) | ((v3) >> (64 - (21)))); v3 ^= v0; v2 += v1; v1 = (uint64_t)(((v1) << (17)) | ((v1) >> (64 - (17)))); v1 ^= v2; v2 = (uint64_t)(((v2) << (32)) | ((v2) >> (64 - (32)))); } executed 984 times by 2 tests: while (0);end of block Executed by:
| 984 | ||||||
174 | b = v0 ^ v1 ^ v2 ^ v3; | - | ||||||
175 | ((out + 8))[0] = (uint8_t)(((uint32_t)((b)))); ((out + 8))[1] = (uint8_t)(((uint32_t)((b))) >> 8); ((out + 8))[2] = (uint8_t)(((uint32_t)((b))) >> 16); ((out + 8))[3] = (uint8_t)(((uint32_t)((b))) >> 24);; ((out + 8) + 4)[0] = (uint8_t)(((uint32_t)((b) >> 32))); ((out + 8) + 4)[1] = (uint8_t)(((uint32_t)((b) >> 32)) >> 8); ((out + 8) + 4)[2] = (uint8_t)(((uint32_t)((b) >> 32)) >> 16); ((out + 8) + 4)[3] = (uint8_t)(((uint32_t)((b) >> 32)) >> 24);;; | - | ||||||
176 | return executed 246 times by 2 tests: 1;return 1; Executed by:
executed 246 times by 2 tests: return 1; Executed by:
| 246 | ||||||
177 | } | - | ||||||
Switch to Source code | Preprocessed file |