| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/gost/gost89_params.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | static const gost_subst_block GostR3411_94_TestParamSet = { | - | ||||||
| 8 | {0x1,0xF,0xD,0x0,0x5,0x7,0xA,0x4,0x9,0x2,0x3,0xE,0x6,0xB,0x8,0xC}, | - | ||||||
| 9 | {0xD,0xB,0x4,0x1,0x3,0xF,0x5,0x9,0x0,0xA,0xE,0x7,0x6,0x8,0x2,0xC}, | - | ||||||
| 10 | {0x4,0xB,0xA,0x0,0x7,0x2,0x1,0xD,0x3,0x6,0x8,0x5,0x9,0xC,0xF,0xE}, | - | ||||||
| 11 | {0x6,0xC,0x7,0x1,0x5,0xF,0xD,0x8,0x4,0xA,0x9,0xE,0x0,0x3,0xB,0x2}, | - | ||||||
| 12 | {0x7,0xD,0xA,0x1,0x0,0x8,0x9,0xF,0xE,0x4,0x6,0xC,0xB,0x2,0x5,0x3}, | - | ||||||
| 13 | {0x5,0x8,0x1,0xD,0xA,0x3,0x4,0x2,0xE,0xF,0xC,0x7,0x6,0x0,0x9,0xB}, | - | ||||||
| 14 | {0xE,0xB,0x4,0xC,0x6,0xD,0xF,0xA,0x2,0x3,0x8,0x1,0x0,0x7,0x5,0x9}, | - | ||||||
| 15 | {0x4,0xA,0x9,0x2,0xD,0x8,0x0,0xE,0x6,0xB,0x1,0xC,0x7,0xF,0x5,0x3} | - | ||||||
| 16 | }; | - | ||||||
| 17 | - | |||||||
| 18 | - | |||||||
| 19 | static const gost_subst_block GostR3411_94_CryptoProParamSet = { | - | ||||||
| 20 | {0x1,0x3,0xA,0x9,0x5,0xB,0x4,0xF,0x8,0x6,0x7,0xE,0xD,0x0,0x2,0xC}, | - | ||||||
| 21 | {0xD,0xE,0x4,0x1,0x7,0x0,0x5,0xA,0x3,0xC,0x8,0xF,0x6,0x2,0x9,0xB}, | - | ||||||
| 22 | {0x7,0x6,0x2,0x4,0xD,0x9,0xF,0x0,0xA,0x1,0x5,0xB,0x8,0xE,0xC,0x3}, | - | ||||||
| 23 | {0x7,0x6,0x4,0xB,0x9,0xC,0x2,0xA,0x1,0x8,0x0,0xE,0xF,0xD,0x3,0x5}, | - | ||||||
| 24 | {0x4,0xA,0x7,0xC,0x0,0xF,0x2,0x8,0xE,0x1,0x6,0x5,0xD,0xB,0x9,0x3}, | - | ||||||
| 25 | {0x7,0xF,0xC,0xE,0x9,0x4,0x1,0x0,0x3,0xB,0x5,0x2,0x6,0xA,0x8,0xD}, | - | ||||||
| 26 | {0x5,0xF,0x4,0x0,0x2,0xD,0xB,0x9,0x1,0x7,0x6,0x3,0xC,0xE,0xA,0x8}, | - | ||||||
| 27 | {0xA,0x4,0x5,0x6,0x8,0x1,0x3,0x7,0xD,0xC,0xE,0x0,0x9,0x2,0xB,0xF} | - | ||||||
| 28 | }; | - | ||||||
| 29 | - | |||||||
| 30 | - | |||||||
| 31 | gost_subst_block Gost28147_TestParamSet = { | - | ||||||
| 32 | {0xC,0x6,0x5,0x2,0xB,0x0,0x9,0xD,0x3,0xE,0x7,0xA,0xF,0x4,0x1,0x8}, | - | ||||||
| 33 | {0x9,0xB,0xC,0x0,0x3,0x6,0x7,0x5,0x4,0x8,0xE,0xF,0x1,0xA,0x2,0xD}, | - | ||||||
| 34 | {0x8,0xF,0x6,0xB,0x1,0x9,0xC,0x5,0xD,0x3,0x7,0xA,0x0,0xE,0x2,0x4}, | - | ||||||
| 35 | {0x3,0xE,0x5,0x9,0x6,0x8,0x0,0xD,0xA,0xB,0x7,0xC,0x2,0x1,0xF,0x4}, | - | ||||||
| 36 | {0xE,0x9,0xB,0x2,0x5,0xF,0x7,0x1,0x0,0xD,0xC,0x6,0xA,0x4,0x3,0x8}, | - | ||||||
| 37 | {0xD,0x8,0xE,0xC,0x7,0x3,0x9,0xA,0x1,0x5,0x2,0x4,0x6,0xF,0x0,0xB}, | - | ||||||
| 38 | {0xC,0x9,0xF,0xE,0x8,0x1,0x3,0xA,0x2,0x7,0x4,0xD,0x6,0x0,0xB,0x5}, | - | ||||||
| 39 | {0x4,0x2,0xF,0x5,0x9,0x1,0x0,0x8,0xE,0x3,0xB,0xC,0xD,0x7,0xA,0x6} | - | ||||||
| 40 | }; | - | ||||||
| 41 | - | |||||||
| 42 | - | |||||||
| 43 | - | |||||||
| 44 | static const gost_subst_block Gost28147_CryptoProParamSetA = { | - | ||||||
| 45 | {0xB,0xA,0xF,0x5,0x0,0xC,0xE,0x8,0x6,0x2,0x3,0x9,0x1,0x7,0xD,0x4}, | - | ||||||
| 46 | {0x1,0xD,0x2,0x9,0x7,0xA,0x6,0x0,0x8,0xC,0x4,0x5,0xF,0x3,0xB,0xE}, | - | ||||||
| 47 | {0x3,0xA,0xD,0xC,0x1,0x2,0x0,0xB,0x7,0x5,0x9,0x4,0x8,0xF,0xE,0x6}, | - | ||||||
| 48 | {0xB,0x5,0x1,0x9,0x8,0xD,0xF,0x0,0xE,0x4,0x2,0x3,0xC,0x7,0xA,0x6}, | - | ||||||
| 49 | {0xE,0x7,0xA,0xC,0xD,0x1,0x3,0x9,0x0,0x2,0xB,0x4,0xF,0x8,0x5,0x6}, | - | ||||||
| 50 | {0xE,0x4,0x6,0x2,0xB,0x3,0xD,0x8,0xC,0xF,0x5,0xA,0x0,0x7,0x1,0x9}, | - | ||||||
| 51 | {0x3,0x7,0xE,0x9,0x8,0xA,0xF,0x0,0x5,0x2,0x6,0xC,0xB,0x4,0xD,0x1}, | - | ||||||
| 52 | {0x9,0x6,0x3,0x2,0x8,0xB,0x1,0x7,0xA,0x4,0xE,0xF,0xC,0x0,0xD,0x5} | - | ||||||
| 53 | }; | - | ||||||
| 54 | - | |||||||
| 55 | - | |||||||
| 56 | static const gost_subst_block Gost28147_CryptoProParamSetB = { | - | ||||||
| 57 | {0x0,0x4,0xB,0xE,0x8,0x3,0x7,0x1,0xA,0x2,0x9,0x6,0xF,0xD,0x5,0xC}, | - | ||||||
| 58 | {0x5,0x2,0xA,0xB,0x9,0x1,0xC,0x3,0x7,0x4,0xD,0x0,0x6,0xF,0x8,0xE}, | - | ||||||
| 59 | {0x8,0x3,0x2,0x6,0x4,0xD,0xE,0xB,0xC,0x1,0x7,0xF,0xA,0x0,0x9,0x5}, | - | ||||||
| 60 | {0x2,0x7,0xC,0xF,0x9,0x5,0xA,0xB,0x1,0x4,0x0,0xD,0x6,0x8,0xE,0x3}, | - | ||||||
| 61 | {0x7,0x5,0x0,0xD,0xB,0x6,0x1,0x2,0x3,0xA,0xC,0xF,0x4,0xE,0x9,0x8}, | - | ||||||
| 62 | {0xE,0xC,0x0,0xA,0x9,0x2,0xD,0xB,0x7,0x5,0x8,0xF,0x3,0x6,0x1,0x4}, | - | ||||||
| 63 | {0x0,0x1,0x2,0xA,0x4,0xD,0x5,0xC,0x9,0x7,0x3,0xF,0xB,0x8,0x6,0xE}, | - | ||||||
| 64 | {0x8,0x4,0xB,0x1,0x3,0x5,0x0,0x9,0x2,0xE,0xA,0xC,0xD,0x6,0x7,0xF} | - | ||||||
| 65 | }; | - | ||||||
| 66 | - | |||||||
| 67 | - | |||||||
| 68 | static const gost_subst_block Gost28147_CryptoProParamSetC = { | - | ||||||
| 69 | {0x7,0x4,0x0,0x5,0xA,0x2,0xF,0xE,0xC,0x6,0x1,0xB,0xD,0x9,0x3,0x8}, | - | ||||||
| 70 | {0xA,0x9,0x6,0x8,0xD,0xE,0x2,0x0,0xF,0x3,0x5,0xB,0x4,0x1,0xC,0x7}, | - | ||||||
| 71 | {0xC,0x9,0xB,0x1,0x8,0xE,0x2,0x4,0x7,0x3,0x6,0x5,0xA,0x0,0xF,0xD}, | - | ||||||
| 72 | {0x8,0xD,0xB,0x0,0x4,0x5,0x1,0x2,0x9,0x3,0xC,0xE,0x6,0xF,0xA,0x7}, | - | ||||||
| 73 | {0x3,0x6,0x0,0x1,0x5,0xD,0xA,0x8,0xB,0x2,0x9,0x7,0xE,0xF,0xC,0x4}, | - | ||||||
| 74 | {0x8,0x2,0x5,0x0,0x4,0x9,0xF,0xA,0x3,0x7,0xC,0xD,0x6,0xE,0x1,0xB}, | - | ||||||
| 75 | {0x0,0x1,0x7,0xD,0xB,0x4,0x5,0x2,0x8,0xE,0xF,0xC,0x9,0xA,0x6,0x3}, | - | ||||||
| 76 | {0x1,0xB,0xC,0x2,0x9,0xD,0x0,0xF,0x4,0x5,0x8,0xE,0xA,0x7,0x6,0x3} | - | ||||||
| 77 | }; | - | ||||||
| 78 | - | |||||||
| 79 | - | |||||||
| 80 | static const gost_subst_block Gost28147_CryptoProParamSetD = { | - | ||||||
| 81 | {0x1,0xA,0x6,0x8,0xF,0xB,0x0,0x4,0xC,0x3,0x5,0x9,0x7,0xD,0x2,0xE}, | - | ||||||
| 82 | {0x3,0x0,0x6,0xF,0x1,0xE,0x9,0x2,0xD,0x8,0xC,0x4,0xB,0xA,0x5,0x7}, | - | ||||||
| 83 | {0x8,0x0,0xF,0x3,0x2,0x5,0xE,0xB,0x1,0xA,0x4,0x7,0xC,0x9,0xD,0x6}, | - | ||||||
| 84 | {0x0,0xC,0x8,0x9,0xD,0x2,0xA,0xB,0x7,0x3,0x6,0x5,0x4,0xE,0xF,0x1}, | - | ||||||
| 85 | {0x1,0x5,0xE,0xC,0xA,0x7,0x0,0xD,0x6,0x2,0xB,0x4,0x9,0x3,0xF,0x8}, | - | ||||||
| 86 | {0x1,0xC,0xB,0x0,0xF,0xE,0x6,0x5,0xA,0xD,0x4,0x8,0x9,0x3,0x7,0x2}, | - | ||||||
| 87 | {0xB,0x6,0x3,0x4,0xC,0xF,0xE,0x2,0x7,0xD,0x8,0x0,0x5,0xA,0x9,0x1}, | - | ||||||
| 88 | {0xF,0xC,0x2,0xA,0x6,0x4,0x5,0x0,0x7,0x9,0xE,0xD,0x1,0xB,0x8,0x3} | - | ||||||
| 89 | }; | - | ||||||
| 90 | - | |||||||
| 91 | static const gost_subst_block Gost28147_TC26ParamSetZ = { | - | ||||||
| 92 | {0x1,0x7,0xe,0xd,0x0,0x5,0x8,0x3,0x4,0xf,0xa,0x6,0x9,0xc,0xb,0x2}, | - | ||||||
| 93 | {0x8,0xe,0x2,0x5,0x6,0x9,0x1,0xc,0xf,0x4,0xb,0x0,0xd,0xa,0x3,0x7}, | - | ||||||
| 94 | {0x5,0xd,0xf,0x6,0x9,0x2,0xc,0xa,0xb,0x7,0x8,0x1,0x4,0x3,0xe,0x0}, | - | ||||||
| 95 | {0x7,0xf,0x5,0xa,0x8,0x1,0x6,0xd,0x0,0x9,0x3,0xe,0xb,0x4,0x2,0xc}, | - | ||||||
| 96 | {0xc,0x8,0x2,0x1,0xd,0x4,0xf,0x6,0x7,0x0,0xa,0x5,0x3,0xe,0x9,0xb}, | - | ||||||
| 97 | {0xb,0x3,0x5,0x8,0x2,0xf,0xa,0xd,0xe,0x1,0x7,0x4,0xc,0x9,0x6,0x0}, | - | ||||||
| 98 | {0x6,0x8,0x2,0x3,0x9,0xa,0x5,0xc,0x1,0xe,0x4,0x7,0xb,0xd,0x0,0xf}, | - | ||||||
| 99 | {0xc,0x4,0x6,0x2,0xa,0x5,0xb,0x9,0xe,0x8,0xd,0x7,0x0,0x3,0xf,0x1} | - | ||||||
| 100 | }; | - | ||||||
| 101 | - | |||||||
| 102 | static const unsigned char CryptoProKeyMeshingKey[] = { | - | ||||||
| 103 | 0x69, 0x00, 0x72, 0x22, 0x64, 0xC9, 0x04, 0x23, | - | ||||||
| 104 | 0x8D, 0x3A, 0xDB, 0x96, 0x46, 0xE9, 0x2A, 0xC4, | - | ||||||
| 105 | 0x18, 0xFE, 0xAC, 0x94, 0x00, 0xED, 0x07, 0x12, | - | ||||||
| 106 | 0xC0, 0x86, 0xDC, 0xC2, 0xEF, 0x4C, 0xA9, 0x2B | - | ||||||
| 107 | }; | - | ||||||
| 108 | - | |||||||
| 109 | static const struct gost89_parameters_info { | - | ||||||
| 110 | int nid; | - | ||||||
| 111 | const gost_subst_block *sblock; | - | ||||||
| 112 | int key_meshing; | - | ||||||
| 113 | } gost_cipher_list[] = | - | ||||||
| 114 | { | - | ||||||
| 115 | {824,&Gost28147_CryptoProParamSetA,1}, | - | ||||||
| 116 | {825,&Gost28147_CryptoProParamSetB,1}, | - | ||||||
| 117 | {826,&Gost28147_CryptoProParamSetC,1}, | - | ||||||
| 118 | {827,&Gost28147_CryptoProParamSetD,1}, | - | ||||||
| 119 | {945,&Gost28147_TC26ParamSetZ,1}, | - | ||||||
| 120 | {823,&Gost28147_TestParamSet,0}, | - | ||||||
| 121 | {821,&GostR3411_94_TestParamSet,0}, | - | ||||||
| 122 | {822,&GostR3411_94_CryptoProParamSet,0}, | - | ||||||
| 123 | {0, | - | ||||||
| 124 | ((void *)0) | - | ||||||
| 125 | ,0} | - | ||||||
| 126 | }; | - | ||||||
| 127 | - | |||||||
| 128 | int | - | ||||||
| 129 | Gost2814789_set_sbox(GOST2814789_KEY *key, int nid) | - | ||||||
| 130 | { | - | ||||||
| 131 | int i; | - | ||||||
| 132 | const gost_subst_block *b = | - | ||||||
| 133 | ((void *)0) | - | ||||||
| 134 | ; | - | ||||||
| 135 | unsigned int t; | - | ||||||
| 136 | - | |||||||
| 137 | for (i = 0; gost_cipher_list[i].nid != 0
| 0-10497 | ||||||
| 138 | if (gost_cipher_list[i].nid != nid
| 1344-9153 | ||||||
| 139 | continue; executed 9153 times by 3 tests: continue;Executed by:
| 9153 | ||||||
| 140 | - | |||||||
| 141 | b = gost_cipher_list[i].sblock; | - | ||||||
| 142 | key->key_meshing = gost_cipher_list[i].key_meshing; | - | ||||||
| 143 | break; executed 1344 times by 3 tests: break;Executed by:
| 1344 | ||||||
| 144 | } | - | ||||||
| 145 | - | |||||||
| 146 | if (b ==
| 0-1344 | ||||||
| 147 | ((void *)0)
| 0-1344 | ||||||
| 148 | ) | - | ||||||
| 149 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 150 | - | |||||||
| 151 | for (i = 0; i < 256
| 1344-344064 | ||||||
| 152 | t = (unsigned int)(b->k8[i >> 4] <<4 | b->k7 [i & 15]) << 24; | - | ||||||
| 153 | key->k87[i] = (t << 11) | (t >> 21); | - | ||||||
| 154 | t = (unsigned int)(b->k6[i >> 4] <<4 | b->k5 [i & 15]) << 16; | - | ||||||
| 155 | key->k65[i] = (t << 11) | (t >> 21); | - | ||||||
| 156 | t = (unsigned int)(b->k4[i >> 4] <<4 | b->k3 [i & 15]) << 8; | - | ||||||
| 157 | key->k43[i] = (t << 11) | (t >> 21); | - | ||||||
| 158 | t = (unsigned int)(b->k2[i >> 4] <<4 | b->k1 [i & 15]) << 0; | - | ||||||
| 159 | key->k21[i] = (t << 11) | (t >> 21); | - | ||||||
| 160 | } executed 344064 times by 3 tests: end of blockExecuted by:
| 344064 | ||||||
| 161 | - | |||||||
| 162 | return executed 1344 times by 3 tests: 1;return 1;Executed by:
executed 1344 times by 3 tests: return 1;Executed by:
| 1344 | ||||||
| 163 | } | - | ||||||
| 164 | - | |||||||
| 165 | int | - | ||||||
| 166 | Gost2814789_set_key(GOST2814789_KEY *key, const unsigned char *userKey, | - | ||||||
| 167 | const int bits) | - | ||||||
| 168 | { | - | ||||||
| 169 | int i; | - | ||||||
| 170 | - | |||||||
| 171 | if (bits != 256
| 0-41010 | ||||||
| 172 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||
| 173 | - | |||||||
| 174 | for (i = 0; i < 8
| 41010-328080 | ||||||
| 175 | (( executed 328080 times by 3 tests: key->key[i])=*((const unsigned int *)(userKey)), (userKey)+=4);((key->key[i])=*((const unsigned int *)(userKey)), (userKey)+=4);Executed by:
executed 328080 times by 3 tests: ((key->key[i])=*((const unsigned int *)(userKey)), (userKey)+=4);Executed by:
| 328080 | ||||||
| 176 | - | |||||||
| 177 | key->count = 0; | - | ||||||
| 178 | - | |||||||
| 179 | return executed 41010 times by 3 tests: 1;return 1;Executed by:
executed 41010 times by 3 tests: return 1;Executed by:
| 41010 | ||||||
| 180 | } | - | ||||||
| 181 | - | |||||||
| 182 | void | - | ||||||
| 183 | Gost2814789_cryptopro_key_mesh(GOST2814789_KEY *key) | - | ||||||
| 184 | { | - | ||||||
| 185 | unsigned char newkey[32]; | - | ||||||
| 186 | - | |||||||
| 187 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 0, newkey + 0, key); | - | ||||||
| 188 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 8, newkey + 8, key); | - | ||||||
| 189 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 16, newkey + 16, key); | - | ||||||
| 190 | Gost2814789_decrypt(CryptoProKeyMeshingKey + 24, newkey + 24, key); | - | ||||||
| 191 | - | |||||||
| 192 | Gost2814789_set_key(key, newkey, 256); | - | ||||||
| 193 | } executed 15362 times by 1 test: end of blockExecuted by:
| 15362 | ||||||
| Switch to Source code | Preprocessed file |