| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/modes/ccm128.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | void CRYPTO_ccm128_init(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 8 | unsigned int M, unsigned int L, void *key, | - | ||||||||||||||||||
| 9 | block128_f block) | - | ||||||||||||||||||
| 10 | { | - | ||||||||||||||||||
| 11 | memset(ctx->nonce.c, 0, sizeof(ctx->nonce.c)); | - | ||||||||||||||||||
| 12 | ctx->nonce.c[0] = ((u8)(L - 1) & 7) | (u8)(((M - 2) / 2) & 7) << 3; | - | ||||||||||||||||||
| 13 | ctx->blocks = 0; | - | ||||||||||||||||||
| 14 | ctx->block = block; | - | ||||||||||||||||||
| 15 | ctx->key = key; | - | ||||||||||||||||||
| 16 | } executed 235 times by 1 test: end of blockExecuted by:
| 235 | ||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | int CRYPTO_ccm128_setiv(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 22 | const unsigned char *nonce, size_t nlen, size_t mlen) | - | ||||||||||||||||||
| 23 | { | - | ||||||||||||||||||
| 24 | unsigned int L = ctx->nonce.c[0] & 7; | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | if (nlen < (14 - L)
| 0-469 | ||||||||||||||||||
| 27 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | if (sizeof(mlen) == 8
| 0-469 | ||||||||||||||||||
| 30 | ctx->nonce.c[8] = (u8)(mlen >> (56 % (sizeof(mlen) * 8))); | - | ||||||||||||||||||
| 31 | ctx->nonce.c[9] = (u8)(mlen >> (48 % (sizeof(mlen) * 8))); | - | ||||||||||||||||||
| 32 | ctx->nonce.c[10] = (u8)(mlen >> (40 % (sizeof(mlen) * 8))); | - | ||||||||||||||||||
| 33 | ctx->nonce.c[11] = (u8)(mlen >> (32 % (sizeof(mlen) * 8))); | - | ||||||||||||||||||
| 34 | } never executed: elseend of block | 0 | ||||||||||||||||||
| 35 | ctx->nonce.u[1] = 0; executed 469 times by 1 test: ctx->nonce.u[1] = 0;Executed by:
| 469 | ||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | ctx->nonce.c[12] = (u8)(mlen >> 24); | - | ||||||||||||||||||
| 38 | ctx->nonce.c[13] = (u8)(mlen >> 16); | - | ||||||||||||||||||
| 39 | ctx->nonce.c[14] = (u8)(mlen >> 8); | - | ||||||||||||||||||
| 40 | ctx->nonce.c[15] = (u8)mlen; | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | ctx->nonce.c[0] &= ~0x40; | - | ||||||||||||||||||
| 43 | memcpy(&ctx->nonce.c[1], nonce, 14 - L); | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | return executed 469 times by 1 test: 0;return 0;Executed by:
executed 469 times by 1 test: return 0;Executed by:
| 469 | ||||||||||||||||||
| 46 | } | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | void CRYPTO_ccm128_aad(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 50 | const unsigned char *aad, size_t alen) | - | ||||||||||||||||||
| 51 | { | - | ||||||||||||||||||
| 52 | unsigned int i; | - | ||||||||||||||||||
| 53 | block128_f block = ctx->block; | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | if (alen == 0
| 0-469 | ||||||||||||||||||
| 56 | return; never executed: return; | 0 | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | ctx->nonce.c[0] |= 0x40; | - | ||||||||||||||||||
| 59 | (*block) (ctx->nonce.c, ctx->cmac.c, ctx->key), ctx->blocks++; | - | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (alen < (0x10000 - 0x100)
| 0-469 | ||||||||||||||||||
| 62 | ctx->cmac.c[0] ^= (u8)(alen >> 8); | - | ||||||||||||||||||
| 63 | ctx->cmac.c[1] ^= (u8)alen; | - | ||||||||||||||||||
| 64 | i = 2; | - | ||||||||||||||||||
| 65 | } executed 469 times by 1 test: else if (sizeof(alen) == 8end of blockExecuted by:
| 0-469 | ||||||||||||||||||
| 66 | && alen >= (size_t)1 << (32 % (sizeof(alen) * 8))
| 0 | ||||||||||||||||||
| 67 | ctx->cmac.c[0] ^= 0xFF; | - | ||||||||||||||||||
| 68 | ctx->cmac.c[1] ^= 0xFF; | - | ||||||||||||||||||
| 69 | ctx->cmac.c[2] ^= (u8)(alen >> (56 % (sizeof(alen) * 8))); | - | ||||||||||||||||||
| 70 | ctx->cmac.c[3] ^= (u8)(alen >> (48 % (sizeof(alen) * 8))); | - | ||||||||||||||||||
| 71 | ctx->cmac.c[4] ^= (u8)(alen >> (40 % (sizeof(alen) * 8))); | - | ||||||||||||||||||
| 72 | ctx->cmac.c[5] ^= (u8)(alen >> (32 % (sizeof(alen) * 8))); | - | ||||||||||||||||||
| 73 | ctx->cmac.c[6] ^= (u8)(alen >> 24); | - | ||||||||||||||||||
| 74 | ctx->cmac.c[7] ^= (u8)(alen >> 16); | - | ||||||||||||||||||
| 75 | ctx->cmac.c[8] ^= (u8)(alen >> 8); | - | ||||||||||||||||||
| 76 | ctx->cmac.c[9] ^= (u8)alen; | - | ||||||||||||||||||
| 77 | i = 10; | - | ||||||||||||||||||
| 78 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 79 | ctx->cmac.c[0] ^= 0xFF; | - | ||||||||||||||||||
| 80 | ctx->cmac.c[1] ^= 0xFE; | - | ||||||||||||||||||
| 81 | ctx->cmac.c[2] ^= (u8)(alen >> 24); | - | ||||||||||||||||||
| 82 | ctx->cmac.c[3] ^= (u8)(alen >> 16); | - | ||||||||||||||||||
| 83 | ctx->cmac.c[4] ^= (u8)(alen >> 8); | - | ||||||||||||||||||
| 84 | ctx->cmac.c[5] ^= (u8)alen; | - | ||||||||||||||||||
| 85 | i = 6; | - | ||||||||||||||||||
| 86 | } never executed: end of block | 0 | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | do { | - | ||||||||||||||||||
| 89 | for (; i < 16
| 26-6405 | ||||||||||||||||||
| 90 | ctx->cmac.c[i] ^= *aad; executed 5936 times by 1 test: ctx->cmac.c[i] ^= *aad;Executed by:
| 5936 | ||||||||||||||||||
| 91 | (*block) (ctx->cmac.c, ctx->cmac.c, ctx->key), ctx->blocks++; | - | ||||||||||||||||||
| 92 | i = 0; | - | ||||||||||||||||||
| 93 | } executed 495 times by 1 test: while (alenend of blockExecuted by:
| 26-495 | ||||||||||||||||||
| 94 | } executed 469 times by 1 test: end of blockExecuted by:
| 469 | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | static void ctr64_inc(unsigned char *counter) | - | ||||||||||||||||||
| 103 | { | - | ||||||||||||||||||
| 104 | unsigned int n = 8; | - | ||||||||||||||||||
| 105 | u8 c; | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | counter += 8; | - | ||||||||||||||||||
| 108 | do { | - | ||||||||||||||||||
| 109 | --n; | - | ||||||||||||||||||
| 110 | c = counter[n]; | - | ||||||||||||||||||
| 111 | ++c; | - | ||||||||||||||||||
| 112 | counter[n] = c; | - | ||||||||||||||||||
| 113 | if (c
| 11-8894 | ||||||||||||||||||
| 114 | return; executed 8894 times by 1 test: return;Executed by:
| 8894 | ||||||||||||||||||
| 115 | } executed 11 times by 1 test: while (nend of blockExecuted by:
| 0-11 | ||||||||||||||||||
| 116 | } never executed: end of block | 0 | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | int CRYPTO_ccm128_encrypt(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 119 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
| 120 | size_t len) | - | ||||||||||||||||||
| 121 | { | - | ||||||||||||||||||
| 122 | size_t n; | - | ||||||||||||||||||
| 123 | unsigned int i, L; | - | ||||||||||||||||||
| 124 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
| 125 | block128_f block = ctx->block; | - | ||||||||||||||||||
| 126 | void *key = ctx->key; | - | ||||||||||||||||||
| 127 | union { | - | ||||||||||||||||||
| 128 | u64 u[2]; | - | ||||||||||||||||||
| 129 | u8 c[16]; | - | ||||||||||||||||||
| 130 | } scratch; | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | if (!(flags0 & 0x40)
| 0-310 | ||||||||||||||||||
| 133 | (* never executed: block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++;(*block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++;never executed: (*block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++; | 0 | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | ctx->nonce.c[0] = L = flags0 & 7; | - | ||||||||||||||||||
| 136 | for (n = 0, i = 15 - L; i < 15
| 310-614 | ||||||||||||||||||
| 137 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
| 138 | ctx->nonce.c[i] = 0; | - | ||||||||||||||||||
| 139 | n <<= 8; | - | ||||||||||||||||||
| 140 | } executed 614 times by 1 test: end of blockExecuted by:
| 614 | ||||||||||||||||||
| 141 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
| 142 | ctx->nonce.c[15] = 1; | - | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (n != len
| 0-310 | ||||||||||||||||||
| 145 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | ctx->blocks += ((len + 15) >> 3) | 1; | - | ||||||||||||||||||
| 148 | if (ctx->blocks > (1ULL << 61)
| 0-310 | ||||||||||||||||||
| 149 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | while (len >= 16
| 310-4688 | ||||||||||||||||||
| 152 | ctx->cmac.u[0] ^= ((u64 *)inp)[0]; | - | ||||||||||||||||||
| 153 | ctx->cmac.u[1] ^= ((u64 *)inp)[1]; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 156 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 157 | ctr64_inc(ctx->nonce.c); | - | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | ((u64 *)out)[0] = scratch.u[0] ^ ((u64 *)inp)[0]; | - | ||||||||||||||||||
| 164 | ((u64 *)out)[1] = scratch.u[1] ^ ((u64 *)inp)[1]; | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | inp += 16; | - | ||||||||||||||||||
| 167 | out += 16; | - | ||||||||||||||||||
| 168 | len -= 16; | - | ||||||||||||||||||
| 169 | } executed 4688 times by 1 test: end of blockExecuted by:
| 4688 | ||||||||||||||||||
| 170 | - | |||||||||||||||||||
| 171 | if (len
| 121-189 | ||||||||||||||||||
| 172 | for (i = 0; i < len
| 189-1249 | ||||||||||||||||||
| 173 | ctx->cmac.c[i] ^= inp[i]; executed 1249 times by 1 test: ctx->cmac.c[i] ^= inp[i];Executed by:
| 1249 | ||||||||||||||||||
| 174 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 175 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 176 | for (i = 0; i < len
| 189-1249 | ||||||||||||||||||
| 177 | out[i] = scratch.c[i] ^ inp[i]; executed 1249 times by 1 test: out[i] = scratch.c[i] ^ inp[i];Executed by:
| 1249 | ||||||||||||||||||
| 178 | } executed 189 times by 1 test: end of blockExecuted by:
| 189 | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | for (i = 15 - L; i < 16
| 310-924 | ||||||||||||||||||
| 181 | ctx->nonce.c[i] = 0; executed 924 times by 1 test: ctx->nonce.c[i] = 0;Executed by:
| 924 | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 184 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
| 185 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | return executed 310 times by 1 test: 0;return 0;Executed by:
executed 310 times by 1 test: return 0;Executed by:
| 310 | ||||||||||||||||||
| 190 | } | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | int CRYPTO_ccm128_decrypt(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 193 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
| 194 | size_t len) | - | ||||||||||||||||||
| 195 | { | - | ||||||||||||||||||
| 196 | size_t n; | - | ||||||||||||||||||
| 197 | unsigned int i, L; | - | ||||||||||||||||||
| 198 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
| 199 | block128_f block = ctx->block; | - | ||||||||||||||||||
| 200 | void *key = ctx->key; | - | ||||||||||||||||||
| 201 | union { | - | ||||||||||||||||||
| 202 | u64 u[2]; | - | ||||||||||||||||||
| 203 | u8 c[16]; | - | ||||||||||||||||||
| 204 | } scratch; | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | if (!(flags0 & 0x40)
| 0-159 | ||||||||||||||||||
| 207 | (* never executed: block) (ctx->nonce.c, ctx->cmac.c, key);(*block) (ctx->nonce.c, ctx->cmac.c, key);never executed: (*block) (ctx->nonce.c, ctx->cmac.c, key); | 0 | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | ctx->nonce.c[0] = L = flags0 & 7; | - | ||||||||||||||||||
| 210 | for (n = 0, i = 15 - L; i < 15
| 159-311 | ||||||||||||||||||
| 211 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
| 212 | ctx->nonce.c[i] = 0; | - | ||||||||||||||||||
| 213 | n <<= 8; | - | ||||||||||||||||||
| 214 | } executed 311 times by 1 test: end of blockExecuted by:
| 311 | ||||||||||||||||||
| 215 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
| 216 | ctx->nonce.c[15] = 1; | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | if (n != len
| 0-159 | ||||||||||||||||||
| 219 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 220 | - | |||||||||||||||||||
| 221 | while (len >= 16
| 159-4206 | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | - | |||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 229 | ctr64_inc(ctx->nonce.c); | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | ctx->cmac.u[0] ^= (((u64 *)out)[0] = scratch.u[0] ^ ((u64 *)inp)[0]); | - | ||||||||||||||||||
| 237 | ctx->cmac.u[1] ^= (((u64 *)out)[1] = scratch.u[1] ^ ((u64 *)inp)[1]); | - | ||||||||||||||||||
| 238 | - | |||||||||||||||||||
| 239 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 240 | - | |||||||||||||||||||
| 241 | inp += 16; | - | ||||||||||||||||||
| 242 | out += 16; | - | ||||||||||||||||||
| 243 | len -= 16; | - | ||||||||||||||||||
| 244 | } executed 4206 times by 1 test: end of blockExecuted by:
| 4206 | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | if (len
| 59-100 | ||||||||||||||||||
| 247 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 248 | for (i = 0; i < len
| 59-454 | ||||||||||||||||||
| 249 | ctx->cmac.c[i] ^= (out[i] = scratch.c[i] ^ inp[i]); executed 454 times by 1 test: ctx->cmac.c[i] ^= (out[i] = scratch.c[i] ^ inp[i]);Executed by:
| 454 | ||||||||||||||||||
| 250 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 251 | } executed 59 times by 1 test: end of blockExecuted by:
| 59 | ||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | for (i = 15 - L; i < 16
| 159-470 | ||||||||||||||||||
| 254 | ctx->nonce.c[i] = 0; executed 470 times by 1 test: ctx->nonce.c[i] = 0;Executed by:
| 470 | ||||||||||||||||||
| 255 | - | |||||||||||||||||||
| 256 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 257 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
| 258 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
| 259 | - | |||||||||||||||||||
| 260 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
| 261 | - | |||||||||||||||||||
| 262 | return executed 159 times by 1 test: 0;return 0;Executed by:
executed 159 times by 1 test: return 0;Executed by:
| 159 | ||||||||||||||||||
| 263 | } | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | static void ctr64_add(unsigned char *counter, size_t inc) | - | ||||||||||||||||||
| 266 | { | - | ||||||||||||||||||
| 267 | size_t n = 8, val = 0; | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | counter += 8; | - | ||||||||||||||||||
| 270 | do { | - | ||||||||||||||||||
| 271 | --n; | - | ||||||||||||||||||
| 272 | val += counter[n] + (inc & 0xff); | - | ||||||||||||||||||
| 273 | counter[n] = (unsigned char)val; | - | ||||||||||||||||||
| 274 | val >>= 8; | - | ||||||||||||||||||
| 275 | inc >>= 8; | - | ||||||||||||||||||
| 276 | } never executed: while (nend of block
| 0 | ||||||||||||||||||
| 277 | } never executed: end of block | 0 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | int CRYPTO_ccm128_encrypt_ccm64(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 280 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
| 281 | size_t len, ccm128_f stream) | - | ||||||||||||||||||
| 282 | { | - | ||||||||||||||||||
| 283 | size_t n; | - | ||||||||||||||||||
| 284 | unsigned int i, L; | - | ||||||||||||||||||
| 285 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
| 286 | block128_f block = ctx->block; | - | ||||||||||||||||||
| 287 | void *key = ctx->key; | - | ||||||||||||||||||
| 288 | union { | - | ||||||||||||||||||
| 289 | u64 u[2]; | - | ||||||||||||||||||
| 290 | u8 c[16]; | - | ||||||||||||||||||
| 291 | } scratch; | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | if (!(flags0 & 0x40)
| 0 | ||||||||||||||||||
| 294 | (* never executed: block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++;(*block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++;never executed: (*block) (ctx->nonce.c, ctx->cmac.c, key), ctx->blocks++; | 0 | ||||||||||||||||||
| 295 | - | |||||||||||||||||||
| 296 | ctx->nonce.c[0] = L = flags0 & 7; | - | ||||||||||||||||||
| 297 | for (n = 0, i = 15 - L; i < 15
| 0 | ||||||||||||||||||
| 298 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
| 299 | ctx->nonce.c[i] = 0; | - | ||||||||||||||||||
| 300 | n <<= 8; | - | ||||||||||||||||||
| 301 | } never executed: end of block | 0 | ||||||||||||||||||
| 302 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
| 303 | ctx->nonce.c[15] = 1; | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | if (n != len
| 0 | ||||||||||||||||||
| 306 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | ctx->blocks += ((len + 15) >> 3) | 1; | - | ||||||||||||||||||
| 309 | if (ctx->blocks > (1ULL << 61)
| 0 | ||||||||||||||||||
| 310 | return never executed: -2;return -2;never executed: return -2; | 0 | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | if ((
| 0 | ||||||||||||||||||
| 313 | (*stream) (inp, out, n, key, ctx->nonce.c, ctx->cmac.c); | - | ||||||||||||||||||
| 314 | n *= 16; | - | ||||||||||||||||||
| 315 | inp += n; | - | ||||||||||||||||||
| 316 | out += n; | - | ||||||||||||||||||
| 317 | len -= n; | - | ||||||||||||||||||
| 318 | if (len
| 0 | ||||||||||||||||||
| 319 | ctr64_add(ctx->nonce.c, n / 16); never executed: ctr64_add(ctx->nonce.c, n / 16); | 0 | ||||||||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | if (len
| 0 | ||||||||||||||||||
| 323 | for (i = 0; i < len
| 0 | ||||||||||||||||||
| 324 | ctx->cmac.c[i] ^= inp[i]; never executed: ctx->cmac.c[i] ^= inp[i]; | 0 | ||||||||||||||||||
| 325 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 326 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 327 | for (i = 0; i < len
| 0 | ||||||||||||||||||
| 328 | out[i] = scratch.c[i] ^ inp[i]; never executed: out[i] = scratch.c[i] ^ inp[i]; | 0 | ||||||||||||||||||
| 329 | } never executed: end of block | 0 | ||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | for (i = 15 - L; i < 16
| 0 | ||||||||||||||||||
| 332 | ctx->nonce.c[i] = 0; never executed: ctx->nonce.c[i] = 0; | 0 | ||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 335 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
| 336 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 341 | } | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | int CRYPTO_ccm128_decrypt_ccm64(CCM128_CONTEXT *ctx, | - | ||||||||||||||||||
| 344 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
| 345 | size_t len, ccm128_f stream) | - | ||||||||||||||||||
| 346 | { | - | ||||||||||||||||||
| 347 | size_t n; | - | ||||||||||||||||||
| 348 | unsigned int i, L; | - | ||||||||||||||||||
| 349 | unsigned char flags0 = ctx->nonce.c[0]; | - | ||||||||||||||||||
| 350 | block128_f block = ctx->block; | - | ||||||||||||||||||
| 351 | void *key = ctx->key; | - | ||||||||||||||||||
| 352 | union { | - | ||||||||||||||||||
| 353 | u64 u[2]; | - | ||||||||||||||||||
| 354 | u8 c[16]; | - | ||||||||||||||||||
| 355 | } scratch; | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | if (!(flags0 & 0x40)
| 0 | ||||||||||||||||||
| 358 | (* never executed: block) (ctx->nonce.c, ctx->cmac.c, key);(*block) (ctx->nonce.c, ctx->cmac.c, key);never executed: (*block) (ctx->nonce.c, ctx->cmac.c, key); | 0 | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | ctx->nonce.c[0] = L = flags0 & 7; | - | ||||||||||||||||||
| 361 | for (n = 0, i = 15 - L; i < 15
| 0 | ||||||||||||||||||
| 362 | n |= ctx->nonce.c[i]; | - | ||||||||||||||||||
| 363 | ctx->nonce.c[i] = 0; | - | ||||||||||||||||||
| 364 | n <<= 8; | - | ||||||||||||||||||
| 365 | } never executed: end of block | 0 | ||||||||||||||||||
| 366 | n |= ctx->nonce.c[15]; | - | ||||||||||||||||||
| 367 | ctx->nonce.c[15] = 1; | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | if (n != len
| 0 | ||||||||||||||||||
| 370 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | if ((
| 0 | ||||||||||||||||||
| 373 | (*stream) (inp, out, n, key, ctx->nonce.c, ctx->cmac.c); | - | ||||||||||||||||||
| 374 | n *= 16; | - | ||||||||||||||||||
| 375 | inp += n; | - | ||||||||||||||||||
| 376 | out += n; | - | ||||||||||||||||||
| 377 | len -= n; | - | ||||||||||||||||||
| 378 | if (len
| 0 | ||||||||||||||||||
| 379 | ctr64_add(ctx->nonce.c, n / 16); never executed: ctr64_add(ctx->nonce.c, n / 16); | 0 | ||||||||||||||||||
| 380 | } never executed: end of block | 0 | ||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | if (len
| 0 | ||||||||||||||||||
| 383 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 384 | for (i = 0; i < len
| 0 | ||||||||||||||||||
| 385 | ctx->cmac.c[i] ^= (out[i] = scratch.c[i] ^ inp[i]); never executed: ctx->cmac.c[i] ^= (out[i] = scratch.c[i] ^ inp[i]); | 0 | ||||||||||||||||||
| 386 | (*block) (ctx->cmac.c, ctx->cmac.c, key); | - | ||||||||||||||||||
| 387 | } never executed: end of block | 0 | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | for (i = 15 - L; i < 16
| 0 | ||||||||||||||||||
| 390 | ctx->nonce.c[i] = 0; never executed: ctx->nonce.c[i] = 0; | 0 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | (*block) (ctx->nonce.c, scratch.c, key); | - | ||||||||||||||||||
| 393 | ctx->cmac.u[0] ^= scratch.u[0]; | - | ||||||||||||||||||
| 394 | ctx->cmac.u[1] ^= scratch.u[1]; | - | ||||||||||||||||||
| 395 | - | |||||||||||||||||||
| 396 | ctx->nonce.c[0] = flags0; | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 399 | } | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | size_t CRYPTO_ccm128_tag(CCM128_CONTEXT *ctx, unsigned char *tag, size_t len) | - | ||||||||||||||||||
| 402 | { | - | ||||||||||||||||||
| 403 | unsigned int M = (ctx->nonce.c[0] >> 3) & 7; | - | ||||||||||||||||||
| 404 | - | |||||||||||||||||||
| 405 | M *= 2; | - | ||||||||||||||||||
| 406 | M += 2; | - | ||||||||||||||||||
| 407 | if (len < M
| 0-469 | ||||||||||||||||||
| 408 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 409 | memcpy(tag, ctx->cmac.c, M); | - | ||||||||||||||||||
| 410 | return executed 469 times by 1 test: M;return M;Executed by:
executed 469 times by 1 test: return M;Executed by:
| 469 | ||||||||||||||||||
| 411 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |