| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/gost/gost89_keywrap.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | static void | - | ||||||
| 8 | key_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
| 0 | ||||||
| 18 | - | |||||||
| 19 | - | |||||||
| 20 | s1 = 0, s2 = 0; | - | ||||||
| 21 | p = outputKey; | - | ||||||
| 22 | for (mask = 1; mask < 256
| 0 | ||||||
| 23 | ((k)=*((const unsigned int *)(p)), (p)+=4); | - | ||||||
| 24 | if (mask & ukm[i]
| 0 | ||||||
| 25 | s1 += k; | - | ||||||
| 26 | } never executed: else {end of block | 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 | - | |||||||
| 40 | int | - | ||||||
| 41 | gost_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: 1;return 1;never executed: return 1; | 0 | ||||||
| 58 | } | - | ||||||
| 59 | - | |||||||
| 60 | int | - | ||||||
| 61 | gost_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)
| 0 | ||||||
| 78 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 79 | - | |||||||
| 80 | return never executed: 1;return 1;never executed: return 1; | 0 | ||||||
| 81 | } | - | ||||||
| Switch to Source code | Preprocessed file |