summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes/xts128.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/modes/xts128.c')
-rw-r--r--src/lib/libcrypto/modes/xts128.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/lib/libcrypto/modes/xts128.c b/src/lib/libcrypto/modes/xts128.c
index 7516acf850..9c863e73d6 100644
--- a/src/lib/libcrypto/modes/xts128.c
+++ b/src/lib/libcrypto/modes/xts128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: xts128.c,v 1.12 2023/07/08 14:56:54 beck Exp $ */ 1/* $OpenBSD: xts128.c,v 1.15 2025/05/18 09:05:59 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -48,17 +48,12 @@
48 * ==================================================================== 48 * ====================================================================
49 */ 49 */
50 50
51#include <openssl/crypto.h>
52#include "modes_local.h"
53
54#include <endian.h> 51#include <endian.h>
55#include <string.h> 52#include <string.h>
56 53
57#ifndef MODES_DEBUG 54#include <openssl/crypto.h>
58# ifndef NDEBUG 55
59# define NDEBUG 56#include "modes_local.h"
60# endif
61#endif
62 57
63int 58int
64CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16], 59CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
@@ -66,9 +61,9 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
66 size_t len, int enc) 61 size_t len, int enc)
67{ 62{
68 union { 63 union {
69 u64 u[2]; 64 uint64_t u[2];
70 u32 d[4]; 65 uint32_t d[4];
71 u8 c[16]; 66 uint8_t c[16];
72 } tweak, scratch; 67 } tweak, scratch;
73 unsigned int i; 68 unsigned int i;
74 69
@@ -88,8 +83,8 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
88 scratch.u[0] ^= tweak.u[0]; 83 scratch.u[0] ^= tweak.u[0];
89 scratch.u[1] ^= tweak.u[1]; 84 scratch.u[1] ^= tweak.u[1];
90#else 85#else
91 scratch.u[0] = ((u64 *)inp)[0] ^ tweak.u[0]; 86 scratch.u[0] = ((uint64_t *)inp)[0] ^ tweak.u[0];
92 scratch.u[1] = ((u64 *)inp)[1] ^ tweak.u[1]; 87 scratch.u[1] = ((uint64_t *)inp)[1] ^ tweak.u[1];
93#endif 88#endif
94 (*ctx->block1)(scratch.c, scratch.c, ctx->key1); 89 (*ctx->block1)(scratch.c, scratch.c, ctx->key1);
95#ifdef __STRICT_ALIGNMENT 90#ifdef __STRICT_ALIGNMENT
@@ -97,8 +92,8 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
97 scratch.u[1] ^= tweak.u[1]; 92 scratch.u[1] ^= tweak.u[1];
98 memcpy(out, scratch.c, 16); 93 memcpy(out, scratch.c, 16);
99#else 94#else
100 ((u64 *)out)[0] = scratch.u[0] ^= tweak.u[0]; 95 ((uint64_t *)out)[0] = scratch.u[0] ^= tweak.u[0];
101 ((u64 *)out)[1] = scratch.u[1] ^= tweak.u[1]; 96 ((uint64_t *)out)[1] = scratch.u[1] ^= tweak.u[1];
102#endif 97#endif
103 inp += 16; 98 inp += 16;
104 out += 16; 99 out += 16;
@@ -120,15 +115,15 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
120 for (c = 0, i = 0; i < 16; ++i) { 115 for (c = 0, i = 0; i < 16; ++i) {
121 /*+ substitutes for |, because c is 1 bit */ 116 /*+ substitutes for |, because c is 1 bit */
122 c += ((size_t)tweak.c[i]) << 1; 117 c += ((size_t)tweak.c[i]) << 1;
123 tweak.c[i] = (u8)c; 118 tweak.c[i] = (uint8_t)c;
124 c = c >> 8; 119 c = c >> 8;
125 } 120 }
126 tweak.c[0] ^= (u8)(0x87 & (0 - c)); 121 tweak.c[0] ^= (uint8_t)(0x87 & (0 - c));
127#endif 122#endif
128 } 123 }
129 if (enc) { 124 if (enc) {
130 for (i = 0; i < len; ++i) { 125 for (i = 0; i < len; ++i) {
131 u8 ch = inp[i]; 126 uint8_t ch = inp[i];
132 out[i] = scratch.c[i]; 127 out[i] = scratch.c[i];
133 scratch.c[i] = ch; 128 scratch.c[i] = ch;
134 } 129 }
@@ -140,8 +135,8 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
140 memcpy(out - 16, scratch.c, 16); 135 memcpy(out - 16, scratch.c, 16);
141 } else { 136 } else {
142 union { 137 union {
143 u64 u[2]; 138 uint64_t u[2];
144 u8 c[16]; 139 uint8_t c[16];
145 } tweak1; 140 } tweak1;
146 141
147#if BYTE_ORDER == LITTLE_ENDIAN 142#if BYTE_ORDER == LITTLE_ENDIAN
@@ -157,25 +152,25 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
157 for (c = 0, i = 0; i < 16; ++i) { 152 for (c = 0, i = 0; i < 16; ++i) {
158 /*+ substitutes for |, because c is 1 bit */ 153 /*+ substitutes for |, because c is 1 bit */
159 c += ((size_t)tweak.c[i]) << 1; 154 c += ((size_t)tweak.c[i]) << 1;
160 tweak1.c[i] = (u8)c; 155 tweak1.c[i] = (uint8_t)c;
161 c = c >> 8; 156 c = c >> 8;
162 } 157 }
163 tweak1.c[0] ^= (u8)(0x87 & (0 - c)); 158 tweak1.c[0] ^= (uint8_t)(0x87 & (0 - c));
164#endif 159#endif
165#ifdef __STRICT_ALIGNMENT 160#ifdef __STRICT_ALIGNMENT
166 memcpy(scratch.c, inp, 16); 161 memcpy(scratch.c, inp, 16);
167 scratch.u[0] ^= tweak1.u[0]; 162 scratch.u[0] ^= tweak1.u[0];
168 scratch.u[1] ^= tweak1.u[1]; 163 scratch.u[1] ^= tweak1.u[1];
169#else 164#else
170 scratch.u[0] = ((u64 *)inp)[0] ^ tweak1.u[0]; 165 scratch.u[0] = ((uint64_t *)inp)[0] ^ tweak1.u[0];
171 scratch.u[1] = ((u64 *)inp)[1] ^ tweak1.u[1]; 166 scratch.u[1] = ((uint64_t *)inp)[1] ^ tweak1.u[1];
172#endif 167#endif
173 (*ctx->block1)(scratch.c, scratch.c, ctx->key1); 168 (*ctx->block1)(scratch.c, scratch.c, ctx->key1);
174 scratch.u[0] ^= tweak1.u[0]; 169 scratch.u[0] ^= tweak1.u[0];
175 scratch.u[1] ^= tweak1.u[1]; 170 scratch.u[1] ^= tweak1.u[1];
176 171
177 for (i = 0; i < len; ++i) { 172 for (i = 0; i < len; ++i) {
178 u8 ch = inp[16 + i]; 173 uint8_t ch = inp[16 + i];
179 out[16 + i] = scratch.c[i]; 174 out[16 + i] = scratch.c[i];
180 scratch.c[i] = ch; 175 scratch.c[i] = ch;
181 } 176 }
@@ -187,8 +182,8 @@ CRYPTO_xts128_encrypt(const XTS128_CONTEXT *ctx, const unsigned char iv[16],
187 scratch.u[1] ^= tweak.u[1]; 182 scratch.u[1] ^= tweak.u[1];
188 memcpy(out, scratch.c, 16); 183 memcpy(out, scratch.c, 16);
189#else 184#else
190 ((u64 *)out)[0] = scratch.u[0] ^ tweak.u[0]; 185 ((uint64_t *)out)[0] = scratch.u[0] ^ tweak.u[0];
191 ((u64 *)out)[1] = scratch.u[1] ^ tweak.u[1]; 186 ((uint64_t *)out)[1] = scratch.u[1] ^ tweak.u[1];
192#endif 187#endif
193 } 188 }
194 189