| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/modes/xts128.c |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | int CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, | - | ||||||||||||||||||
| 4 | const unsigned char iv[16], | - | ||||||||||||||||||
| 5 | const unsigned char *inp, unsigned char *out, | - | ||||||||||||||||||
| 6 | size_t len, int enc) | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | const union { | - | ||||||||||||||||||
| 9 | long one; | - | ||||||||||||||||||
| 10 | char little; | - | ||||||||||||||||||
| 11 | } is_endian = { | - | ||||||||||||||||||
| 12 | 1 | - | ||||||||||||||||||
| 13 | }; | - | ||||||||||||||||||
| 14 | union { | - | ||||||||||||||||||
| 15 | u64 u[2]; | - | ||||||||||||||||||
| 16 | u32 d[4]; | - | ||||||||||||||||||
| 17 | u8 c[16]; | - | ||||||||||||||||||
| 18 | } tweak, scratch; | - | ||||||||||||||||||
| 19 | unsigned int i; | - | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | if (len < 16
| 0 | ||||||||||||||||||
| 22 | return never executed: -1;return -1;never executed: return -1; | 0 | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | memcpy(tweak.c, iv, 16); | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | (*ctx->block2) (tweak.c, tweak.c, ctx->key2); | - | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | if (!enc
| 0 | ||||||||||||||||||
| 29 | len -= 16; never executed: len -= 16; | 0 | ||||||||||||||||||
| 30 | - | |||||||||||||||||||
| 31 | while (len >= 16
| 0 | ||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | - | |||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | - | |||||||||||||||||||
| 37 | scratch.u[0] = ((u64 *)inp)[0] ^ tweak.u[0]; | - | ||||||||||||||||||
| 38 | scratch.u[1] = ((u64 *)inp)[1] ^ tweak.u[1]; | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | (*ctx->block1) (scratch.c, scratch.c, ctx->key1); | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | - | |||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | ((u64 *)out)[0] = scratch.u[0] ^= tweak.u[0]; | - | ||||||||||||||||||
| 47 | ((u64 *)out)[1] = scratch.u[1] ^= tweak.u[1]; | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | inp += 16; | - | ||||||||||||||||||
| 50 | out += 16; | - | ||||||||||||||||||
| 51 | len -= 16; | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | if (len == 0
| 0 | ||||||||||||||||||
| 54 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | if (is_endian.little
| 0 | ||||||||||||||||||
| 57 | unsigned int carry, res; | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | res = 0x87 & (((int)tweak.d[3]) >> 31); | - | ||||||||||||||||||
| 60 | carry = (unsigned int)(tweak.u[0] >> 63); | - | ||||||||||||||||||
| 61 | tweak.u[0] = (tweak.u[0] << 1) ^ res; | - | ||||||||||||||||||
| 62 | tweak.u[1] = (tweak.u[1] << 1) | carry; | - | ||||||||||||||||||
| 63 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 64 | size_t c; | - | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | for (c = 0, i = 0; i < 16
| 0 | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | c += ((size_t)tweak.c[i]) << 1; | - | ||||||||||||||||||
| 71 | tweak.c[i] = (u8)c; | - | ||||||||||||||||||
| 72 | c = c >> 8; | - | ||||||||||||||||||
| 73 | } never executed: end of block | 0 | ||||||||||||||||||
| 74 | tweak.c[0] ^= (u8)(0x87 & (0 - c)); | - | ||||||||||||||||||
| 75 | } never executed: end of block | 0 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | if (enc
| 0 | ||||||||||||||||||
| 78 | for (i = 0; i < len
| 0 | ||||||||||||||||||
| 79 | u8 c = inp[i]; | - | ||||||||||||||||||
| 80 | out[i] = scratch.c[i]; | - | ||||||||||||||||||
| 81 | scratch.c[i] = c; | - | ||||||||||||||||||
| 82 | } never executed: end of block | 0 | ||||||||||||||||||
| 83 | scratch.u[0] ^= tweak.u[0]; | - | ||||||||||||||||||
| 84 | scratch.u[1] ^= tweak.u[1]; | - | ||||||||||||||||||
| 85 | (*ctx->block1) (scratch.c, scratch.c, ctx->key1); | - | ||||||||||||||||||
| 86 | scratch.u[0] ^= tweak.u[0]; | - | ||||||||||||||||||
| 87 | scratch.u[1] ^= tweak.u[1]; | - | ||||||||||||||||||
| 88 | memcpy(out - 16, scratch.c, 16); | - | ||||||||||||||||||
| 89 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 90 | union { | - | ||||||||||||||||||
| 91 | u64 u[2]; | - | ||||||||||||||||||
| 92 | u8 c[16]; | - | ||||||||||||||||||
| 93 | } tweak1; | - | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | if (is_endian.little
| 0 | ||||||||||||||||||
| 96 | unsigned int carry, res; | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | res = 0x87 & (((int)tweak.d[3]) >> 31); | - | ||||||||||||||||||
| 99 | carry = (unsigned int)(tweak.u[0] >> 63); | - | ||||||||||||||||||
| 100 | tweak1.u[0] = (tweak.u[0] << 1) ^ res; | - | ||||||||||||||||||
| 101 | tweak1.u[1] = (tweak.u[1] << 1) | carry; | - | ||||||||||||||||||
| 102 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 103 | size_t c; | - | ||||||||||||||||||
| 104 | - | |||||||||||||||||||
| 105 | for (c = 0, i = 0; i < 16
| 0 | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | c += ((size_t)tweak.c[i]) << 1; | - | ||||||||||||||||||
| 110 | tweak1.c[i] = (u8)c; | - | ||||||||||||||||||
| 111 | c = c >> 8; | - | ||||||||||||||||||
| 112 | } never executed: end of block | 0 | ||||||||||||||||||
| 113 | tweak1.c[0] ^= (u8)(0x87 & (0 - c)); | - | ||||||||||||||||||
| 114 | } never executed: end of block | 0 | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | scratch.u[0] = ((u64 *)inp)[0] ^ tweak1.u[0]; | - | ||||||||||||||||||
| 121 | scratch.u[1] = ((u64 *)inp)[1] ^ tweak1.u[1]; | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | (*ctx->block1) (scratch.c, scratch.c, ctx->key1); | - | ||||||||||||||||||
| 124 | scratch.u[0] ^= tweak1.u[0]; | - | ||||||||||||||||||
| 125 | scratch.u[1] ^= tweak1.u[1]; | - | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | for (i = 0; i < len
| 0 | ||||||||||||||||||
| 128 | u8 c = inp[16 + i]; | - | ||||||||||||||||||
| 129 | out[16 + i] = scratch.c[i]; | - | ||||||||||||||||||
| 130 | scratch.c[i] = c; | - | ||||||||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||||||||
| 132 | scratch.u[0] ^= tweak.u[0]; | - | ||||||||||||||||||
| 133 | scratch.u[1] ^= tweak.u[1]; | - | ||||||||||||||||||
| 134 | (*ctx->block1) (scratch.c, scratch.c, ctx->key1); | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | - | |||||||||||||||||||
| 140 | ((u64 *)out)[0] = scratch.u[0] ^ tweak.u[0]; | - | ||||||||||||||||||
| 141 | ((u64 *)out)[1] = scratch.u[1] ^ tweak.u[1]; | - | ||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | } never executed: end of block | 0 | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||
| 146 | } | - | ||||||||||||||||||
| Switch to Source code | Preprocessed file |