Line | Source | Count |
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | | - |
12 | | - |
13 | | - |
14 | | - |
15 | | - |
16 | | - |
17 | | - |
18 | | - |
19 | | - |
20 | | - |
21 | | - |
22 | | - |
23 | | - |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | | - |
31 | | - |
32 | | - |
33 | | - |
34 | | - |
35 | | - |
36 | | - |
37 | | - |
38 | | - |
39 | | - |
40 | | - |
41 | | - |
42 | | - |
43 | | - |
44 | | - |
45 | | - |
46 | | - |
47 | | - |
48 | | - |
49 | | - |
50 | | - |
51 | | - |
52 | #include <string.h> | - |
53 | | - |
54 | #include <openssl/opensslconf.h> | - |
55 | | - |
56 | #ifndef OPENSSL_NO_GOST | - |
57 | | - |
58 | #include <openssl/gost.h> | - |
59 | | - |
60 | #include "gost_locl.h" | - |
61 | | - |
62 | static void | - |
63 | key_diversify_crypto_pro(GOST2814789_KEY *ctx, const unsigned char *inputKey, | - |
64 | const unsigned char *ukm, unsigned char *outputKey) | - |
65 | { | - |
66 | unsigned long k, s1, s2; | - |
67 | int i, mask; | - |
68 | unsigned char S[8]; | - |
69 | unsigned char *p; | - |
70 | | - |
71 | memcpy(outputKey, inputKey, 32); | - |
72 | for (i = 0; i < 8; i++) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
73 | | - |
74 | | - |
75 | s1 = 0, s2 = 0; | - |
76 | p = outputKey; | - |
77 | for (mask = 1; mask < 256; mask <<= 1) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
78 | c2l(p, k); | - |
79 | if (mask & ukm[i]) {TRUE | never evaluated | FALSE | never evaluated |
| 0 |
80 | s1 += k; | - |
81 | } else { never executed: end of block | 0 |
82 | s2 += k; | - |
83 | } never executed: end of block | 0 |
84 | } | - |
85 | p = S; | - |
86 | l2c (s1, p); | - |
87 | l2c (s2, p); | - |
88 | Gost2814789_set_key(ctx, outputKey, 256); | - |
89 | mask = 0; | - |
90 | Gost2814789_cfb64_encrypt(outputKey, outputKey, 32, ctx, S, | - |
91 | &mask, 1); | - |
92 | } never executed: end of block | 0 |
93 | } never executed: end of block | 0 |
94 | | - |
95 | int | - |
96 | gost_key_wrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | - |
97 | const unsigned char *ukm, const unsigned char *sessionKey, | - |
98 | unsigned char *wrappedKey) | - |
99 | { | - |
100 | GOST2814789_KEY ctx; | - |
101 | unsigned char kek_ukm[32]; | - |
102 | | - |
103 | Gost2814789_set_sbox(&ctx, nid); | - |
104 | key_diversify_crypto_pro(&ctx, keyExchangeKey, ukm, kek_ukm); | - |
105 | Gost2814789_set_key(&ctx, kek_ukm, 256); | - |
106 | memcpy(wrappedKey, ukm, 8); | - |
107 | Gost2814789_encrypt(sessionKey + 0, wrappedKey + 8 + 0, &ctx); | - |
108 | Gost2814789_encrypt(sessionKey + 8, wrappedKey + 8 + 8, &ctx); | - |
109 | Gost2814789_encrypt(sessionKey + 16, wrappedKey + 8 + 16, &ctx); | - |
110 | Gost2814789_encrypt(sessionKey + 24, wrappedKey + 8 + 24, &ctx); | - |
111 | GOST2814789IMIT(sessionKey, 32, wrappedKey + 40, nid, kek_ukm, ukm); | - |
112 | return 1; never executed: return 1; | 0 |
113 | } | - |
114 | | - |
115 | int | - |
116 | gost_key_unwrap_crypto_pro(int nid, const unsigned char *keyExchangeKey, | - |
117 | const unsigned char *wrappedKey, unsigned char *sessionKey) | - |
118 | { | - |
119 | unsigned char kek_ukm[32], cek_mac[4]; | - |
120 | GOST2814789_KEY ctx; | - |
121 | | - |
122 | Gost2814789_set_sbox(&ctx, nid); | - |
123 | | - |
124 | key_diversify_crypto_pro(&ctx, keyExchangeKey, wrappedKey, kek_ukm); | - |
125 | Gost2814789_set_key(&ctx, kek_ukm, 256); | - |
126 | Gost2814789_decrypt(wrappedKey + 8 + 0, sessionKey + 0, &ctx); | - |
127 | Gost2814789_decrypt(wrappedKey + 8 + 8, sessionKey + 8, &ctx); | - |
128 | Gost2814789_decrypt(wrappedKey + 8 + 16, sessionKey + 16, &ctx); | - |
129 | Gost2814789_decrypt(wrappedKey + 8 + 24, sessionKey + 24, &ctx); | - |
130 | | - |
131 | GOST2814789IMIT(sessionKey, 32, cek_mac, nid, kek_ukm, wrappedKey); | - |
132 | if (memcmp(cek_mac, wrappedKey + 40, 4))TRUE | never evaluated | FALSE | never evaluated |
| 0 |
133 | return 0; never executed: return 0; | 0 |
134 | | - |
135 | return 1; never executed: return 1; | 0 |
136 | } | - |
137 | | - |
138 | #endif | - |
| | |