OpenCoverage

gost89_keywrap.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/gost/gost89_keywrap.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7static void-
8key_diversify_crypto_pro(GOST2814789_KEY *ctx, const unsigned char *inputKey,-
9 const unsigned char *ukm, unsigned char *outputKey)-
10{-
11 unsigned long k, s1, s2;-
12 int i, mask;-
13 unsigned char S[8];-
14 unsigned char *p;-
15-
16 memcpy(outputKey, inputKey, 32);-
17 for (i = 0; i < 8
i < 8Description
TRUEnever evaluated
FALSEnever evaluated
; i++) {
0
18-
19-
20 s1 = 0, s2 = 0;-
21 p = outputKey;-
22 for (mask = 1; mask < 256
mask < 256Description
TRUEnever evaluated
FALSEnever evaluated
; mask <<= 1) {
0
23 ((k)=*((const unsigned int *)(p)), (p)+=4);-
24 if (mask & ukm[i]
mask & ukm[i]Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
25 s1 += k;-
26 }
never executed: end of block
else {
0
27 s2 += k;-
28 }
never executed: end of block
0
29 }-
30 p = S;-
31 (*((unsigned int *)(p))=(s1), (p)+=4);-
32 (*((unsigned int *)(p))=(s2), (p)+=4);-
33 Gost2814789_set_key(ctx, outputKey, 256);-
34 mask = 0;-
35 Gost2814789_cfb64_encrypt(outputKey, outputKey, 32, ctx, S,-
36 &mask, 1);-
37 }
never executed: end of block
0
38}
never executed: end of block
0
39-
40int-
41gost_key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey,-
42 const unsigned char *ukm, const unsigned char *sessionKey,-
43 unsigned char *wrappedKey)-
44{-
45 GOST2814789_KEY ctx;-
46 unsigned char kek_ukm[32];-
47-
48 Gost2814789_set_sbox(&ctx, nid);-
49 key_diversify_crypto_pro(&ctx, keyExchangeKey, ukm, kek_ukm);-
50 Gost2814789_set_key(&ctx, kek_ukm, 256);-
51 memcpy(wrappedKey, ukm, 8);-
52 Gost2814789_encrypt(sessionKey + 0, wrappedKey + 8 + 0, &ctx);-
53 Gost2814789_encrypt(sessionKey + 8, wrappedKey + 8 + 8, &ctx);-
54 Gost2814789_encrypt(sessionKey + 16, wrappedKey + 8 + 16, &ctx);-
55 Gost2814789_encrypt(sessionKey + 24, wrappedKey + 8 + 24, &ctx);-
56 GOST2814789IMIT(sessionKey, 32, wrappedKey + 40, nid, kek_ukm, ukm);-
57 return
never executed: return 1;
1;
never executed: return 1;
0
58}-
59-
60int-
61gost_key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey,-
62 const unsigned char *wrappedKey, unsigned char *sessionKey)-
63{-
64 unsigned char kek_ukm[32], cek_mac[4];-
65 GOST2814789_KEY ctx;-
66-
67 Gost2814789_set_sbox(&ctx, nid);-
68-
69 key_diversify_crypto_pro(&ctx, keyExchangeKey, wrappedKey, kek_ukm);-
70 Gost2814789_set_key(&ctx, kek_ukm, 256);-
71 Gost2814789_decrypt(wrappedKey + 8 + 0, sessionKey + 0, &ctx);-
72 Gost2814789_decrypt(wrappedKey + 8 + 8, sessionKey + 8, &ctx);-
73 Gost2814789_decrypt(wrappedKey + 8 + 16, sessionKey + 16, &ctx);-
74 Gost2814789_decrypt(wrappedKey + 8 + 24, sessionKey + 24, &ctx);-
75-
76 GOST2814789IMIT(sessionKey, 32, cek_mac, nid, kek_ukm, wrappedKey);-
77 if (memcmp(cek_mac, wrappedKey + 40, 4)
memcmp(cek_mac...edKey + 40, 4)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
78 return
never executed: return 0;
0;
never executed: return 0;
0
79-
80 return
never executed: return 1;
1;
never executed: return 1;
0
81}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2