OpenCoverage

bcrypt_pbkdf.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssh/src/openbsd-compat/bcrypt_pbkdf.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6static void-
7bcrypt_hash(u_int8_t *sha2pass, u_int8_t *sha2salt, u_int8_t *out)-
8{-
9 blf_ctx state;-
10 u_int8_t ciphertext[(8 * 4)] =-
11 "OxychromaticBlowfishSwatDynamite";-
12 uint32_t cdata[8];-
13 int i;-
14 uint16_t j;-
15 size_t shalen = 64U;-
16-
17-
18 Blowfish_initstate(&state);-
19 Blowfish_expandstate(&state, sha2salt, shalen, sha2pass, shalen);-
20 for (i = 0; i < 64
i < 64Description
TRUEevaluated 8192 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 128 times by 1 test
Evaluated by:
  • test_sshkey
; i++) {
128-8192
21 Blowfish_expand0state(&state, sha2salt, shalen);-
22 Blowfish_expand0state(&state, sha2pass, shalen);-
23 }
executed 8192 times by 1 test: end of block
Executed by:
  • test_sshkey
8192
24-
25-
26 j = 0;-
27 for (i = 0; i < 8
i < 8Description
TRUEevaluated 1024 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 128 times by 1 test
Evaluated by:
  • test_sshkey
; i++)
128-1024
28 cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext),
executed 1024 times by 1 test: cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext), &j);
Executed by:
  • test_sshkey
1024
29 &j);
executed 1024 times by 1 test: cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext), &j);
Executed by:
  • test_sshkey
1024
30 for (i = 0; i < 64
i < 64Description
TRUEevaluated 8192 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 128 times by 1 test
Evaluated by:
  • test_sshkey
; i++)
128-8192
31 blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
executed 8192 times by 1 test: blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
Executed by:
  • test_sshkey
8192
32-
33-
34 for (i = 0; i < 8
i < 8Description
TRUEevaluated 1024 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 128 times by 1 test
Evaluated by:
  • test_sshkey
; i++) {
128-1024
35 out[4 * i + 3] = (cdata[i] >> 24) & 0xff;-
36 out[4 * i + 2] = (cdata[i] >> 16) & 0xff;-
37 out[4 * i + 1] = (cdata[i] >> 8) & 0xff;-
38 out[4 * i + 0] = cdata[i] & 0xff;-
39 }
executed 1024 times by 1 test: end of block
Executed by:
  • test_sshkey
1024
40-
41-
42 explicit_bzero(ciphertext, sizeof(ciphertext));-
43 explicit_bzero(cdata, sizeof(cdata));-
44 explicit_bzero(&state, sizeof(state));-
45}
executed 128 times by 1 test: end of block
Executed by:
  • test_sshkey
128
46-
47int-
48bcrypt_pbkdf(const char *pass, size_t passlen, const u_int8_t *salt, size_t saltlen,-
49 u_int8_t *key, size_t keylen, unsigned int rounds)-
50{-
51 u_int8_t sha2pass[64U];-
52 u_int8_t sha2salt[64U];-
53 u_int8_t out[(8 * 4)];-
54 u_int8_t tmpout[(8 * 4)];-
55 u_int8_t *countsalt;-
56 size_t i, j, amt, stride;-
57 uint32_t count;-
58 size_t origkeylen = keylen;-
59-
60-
61 if (rounds < 1
rounds < 1Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
)
0-4
62 return
never executed: return -1;
-1;
never executed: return -1;
0
63 if (passlen == 0
passlen == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
|| saltlen == 0
saltlen == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
|| keylen == 0
keylen == 0Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
||
0-4
64 keylen > sizeof(out) * sizeof(out)
keylen > sizeo... * sizeof(out)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
|| saltlen > 1<<20
saltlen > 1<<20Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
)
0-4
65 return
never executed: return -1;
-1;
never executed: return -1;
0
66 if ((
(countsalt = c...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
countsalt = calloc(1, saltlen + 4)) ==
(countsalt = c...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
0-4
67 ((void *)0)
(countsalt = c...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
0-4
68 )-
69 return
never executed: return -1;
-1;
never executed: return -1;
0
70 stride = (keylen + sizeof(out) - 1) / sizeof(out);-
71 amt = (keylen + stride - 1) / stride;-
72-
73 memcpy(countsalt, salt, saltlen);-
74-
75-
76 crypto_hash_sha512(sha2pass, pass, passlen);-
77-
78-
79 for (count = 1; keylen > 0
keylen > 0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
; count++) {
4-8
80 countsalt[saltlen + 0] = (count >> 24) & 0xff;-
81 countsalt[saltlen + 1] = (count >> 16) & 0xff;-
82 countsalt[saltlen + 2] = (count >> 8) & 0xff;-
83 countsalt[saltlen + 3] = count & 0xff;-
84-
85-
86 crypto_hash_sha512(sha2salt, countsalt, saltlen + 4);-
87-
88 bcrypt_hash(sha2pass, sha2salt, tmpout);-
89 memcpy(out, tmpout, sizeof(out));-
90-
91 for (i = 1; i < rounds
i < roundsDescription
TRUEevaluated 120 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 8 times by 1 test
Evaluated by:
  • test_sshkey
; i++) {
8-120
92-
93 crypto_hash_sha512(sha2salt, tmpout, sizeof(tmpout));-
94 bcrypt_hash(sha2pass, sha2salt, tmpout);-
95 for (j = 0; j < sizeof(out)
j < sizeof(out)Description
TRUEevaluated 3840 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 120 times by 1 test
Evaluated by:
  • test_sshkey
; j++)
120-3840
96 out[j] ^= tmpout[j];
executed 3840 times by 1 test: out[j] ^= tmpout[j];
Executed by:
  • test_sshkey
3840
97 }
executed 120 times by 1 test: end of block
Executed by:
  • test_sshkey
120
98-
99-
100-
101-
102 amt = (((
((amt) < (keylen))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
amt) < (keylen))
((amt) < (keylen))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 4 times by 1 test
Evaluated by:
  • test_sshkey
? (amt) : (keylen));
4
103 for (i = 0; i < amt
i < amtDescription
TRUEevaluated 192 times by 1 test
Evaluated by:
  • test_sshkey
FALSEevaluated 8 times by 1 test
Evaluated by:
  • test_sshkey
; i++) {
8-192
104 size_t dest = i * stride + (count - 1);-
105 if (dest >= origkeylen
dest >= origkeylenDescription
TRUEnever evaluated
FALSEevaluated 192 times by 1 test
Evaluated by:
  • test_sshkey
)
0-192
106 break;
never executed: break;
0
107 key[dest] = out[i];-
108 }
executed 192 times by 1 test: end of block
Executed by:
  • test_sshkey
192
109 keylen -= i;-
110 }
executed 8 times by 1 test: end of block
Executed by:
  • test_sshkey
8
111-
112-
113 explicit_bzero(out, sizeof(out));-
114 free(countsalt);-
115-
116 return
executed 4 times by 1 test: return 0;
Executed by:
  • test_sshkey
0;
executed 4 times by 1 test: return 0;
Executed by:
  • test_sshkey
4
117}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2