summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2025-05-25 06:27:02 +0000
committerjsing <>2025-05-25 06:27:02 +0000
commit3f1042c159dd74ae4a5a7d804aa45647154e99c9 (patch)
tree3e980eff4547d926dcf98f444a905706946f095b /src
parente10b3fc3007b5ea0fdd7a0977201e503aca26aff (diff)
downloadopenbsd-3f1042c159dd74ae4a5a7d804aa45647154e99c9.tar.gz
openbsd-3f1042c159dd74ae4a5a7d804aa45647154e99c9.tar.bz2
openbsd-3f1042c159dd74ae4a5a7d804aa45647154e99c9.zip
Merge AES-IGE into aes.c.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/Makefile3
-rw-r--r--src/lib/libcrypto/aes/aes.c66
-rw-r--r--src/lib/libcrypto/aes/aes_ige.c118
3 files changed, 66 insertions, 121 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile
index 40f29b998b..3ad03831f8 100644
--- a/src/lib/libcrypto/Makefile
+++ b/src/lib/libcrypto/Makefile
@@ -1,4 +1,4 @@
1# $OpenBSD: Makefile,v 1.236 2025/05/25 05:29:54 jsing Exp $ 1# $OpenBSD: Makefile,v 1.237 2025/05/25 06:27:02 jsing Exp $
2 2
3LIB= crypto 3LIB= crypto
4LIBREBUILD=y 4LIBREBUILD=y
@@ -67,7 +67,6 @@ SRCS+= crypto_memory.c
67# aes/ 67# aes/
68SRCS+= aes.c 68SRCS+= aes.c
69SRCS+= aes_core.c 69SRCS+= aes_core.c
70SRCS+= aes_ige.c
71 70
72# asn1/ 71# asn1/
73SRCS+= a_bitstr.c 72SRCS+= a_bitstr.c
diff --git a/src/lib/libcrypto/aes/aes.c b/src/lib/libcrypto/aes/aes.c
index 1c1c61a7a9..50e4ce13cc 100644
--- a/src/lib/libcrypto/aes/aes.c
+++ b/src/lib/libcrypto/aes/aes.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: aes.c,v 1.7 2025/05/19 04:32:51 jsing Exp $ */ 1/* $OpenBSD: aes.c,v 1.8 2025/05/25 06:27:02 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2002-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -52,6 +52,7 @@
52 52
53#include <openssl/aes.h> 53#include <openssl/aes.h>
54#include <openssl/bio.h> 54#include <openssl/bio.h>
55#include <openssl/crypto.h>
55#include <openssl/modes.h> 56#include <openssl/modes.h>
56 57
57#include "crypto_arch.h" 58#include "crypto_arch.h"
@@ -202,6 +203,69 @@ aes_ecb_encrypt_internal(const unsigned char *in, unsigned char *out,
202 } 203 }
203} 204}
204 205
206#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long))
207typedef struct {
208 unsigned long data[N_WORDS];
209} aes_block_t;
210
211void
212AES_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length,
213 const AES_KEY *key, unsigned char *ivec, const int enc)
214{
215 aes_block_t tmp, tmp2;
216 aes_block_t iv;
217 aes_block_t iv2;
218 size_t n;
219 size_t len;
220
221 /* N.B. The IV for this mode is _twice_ the block size */
222
223 OPENSSL_assert((length % AES_BLOCK_SIZE) == 0);
224
225 len = length / AES_BLOCK_SIZE;
226
227 memcpy(iv.data, ivec, AES_BLOCK_SIZE);
228 memcpy(iv2.data, ivec + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
229
230 if (AES_ENCRYPT == enc) {
231 while (len) {
232 memcpy(tmp.data, in, AES_BLOCK_SIZE);
233 for (n = 0; n < N_WORDS; ++n)
234 tmp2.data[n] = tmp.data[n] ^ iv.data[n];
235 AES_encrypt((unsigned char *)tmp2.data,
236 (unsigned char *)tmp2.data, key);
237 for (n = 0; n < N_WORDS; ++n)
238 tmp2.data[n] ^= iv2.data[n];
239 memcpy(out, tmp2.data, AES_BLOCK_SIZE);
240 iv = tmp2;
241 iv2 = tmp;
242 --len;
243 in += AES_BLOCK_SIZE;
244 out += AES_BLOCK_SIZE;
245 }
246 } else {
247 while (len) {
248 memcpy(tmp.data, in, AES_BLOCK_SIZE);
249 tmp2 = tmp;
250 for (n = 0; n < N_WORDS; ++n)
251 tmp.data[n] ^= iv2.data[n];
252 AES_decrypt((unsigned char *)tmp.data,
253 (unsigned char *)tmp.data, key);
254 for (n = 0; n < N_WORDS; ++n)
255 tmp.data[n] ^= iv.data[n];
256 memcpy(out, tmp.data, AES_BLOCK_SIZE);
257 iv = tmp2;
258 iv2 = tmp;
259 --len;
260 in += AES_BLOCK_SIZE;
261 out += AES_BLOCK_SIZE;
262 }
263 }
264 memcpy(ivec, iv.data, AES_BLOCK_SIZE);
265 memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE);
266}
267LCRYPTO_ALIAS(AES_ige_encrypt);
268
205void 269void
206AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length, 270AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, size_t length,
207 const AES_KEY *key, unsigned char *ivec, int *num) 271 const AES_KEY *key, unsigned char *ivec, int *num)
diff --git a/src/lib/libcrypto/aes/aes_ige.c b/src/lib/libcrypto/aes/aes_ige.c
deleted file mode 100644
index 1330397573..0000000000
--- a/src/lib/libcrypto/aes/aes_ige.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* $OpenBSD: aes_ige.c,v 1.11 2025/05/25 06:24:37 jsing Exp $ */
2/* ====================================================================
3 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <openssl/aes.h>
53#include <openssl/crypto.h>
54
55#include "aes_local.h"
56
57#define N_WORDS (AES_BLOCK_SIZE / sizeof(unsigned long))
58typedef struct {
59 unsigned long data[N_WORDS];
60} aes_block_t;
61
62void
63AES_ige_encrypt(const unsigned char *in, unsigned char *out, size_t length,
64 const AES_KEY *key, unsigned char *ivec, const int enc)
65{
66 aes_block_t tmp, tmp2;
67 aes_block_t iv;
68 aes_block_t iv2;
69 size_t n;
70 size_t len;
71
72 /* N.B. The IV for this mode is _twice_ the block size */
73
74 OPENSSL_assert((length % AES_BLOCK_SIZE) == 0);
75
76 len = length / AES_BLOCK_SIZE;
77
78 memcpy(iv.data, ivec, AES_BLOCK_SIZE);
79 memcpy(iv2.data, ivec + AES_BLOCK_SIZE, AES_BLOCK_SIZE);
80
81 if (AES_ENCRYPT == enc) {
82 while (len) {
83 memcpy(tmp.data, in, AES_BLOCK_SIZE);
84 for (n = 0; n < N_WORDS; ++n)
85 tmp2.data[n] = tmp.data[n] ^ iv.data[n];
86 AES_encrypt((unsigned char *)tmp2.data,
87 (unsigned char *)tmp2.data, key);
88 for (n = 0; n < N_WORDS; ++n)
89 tmp2.data[n] ^= iv2.data[n];
90 memcpy(out, tmp2.data, AES_BLOCK_SIZE);
91 iv = tmp2;
92 iv2 = tmp;
93 --len;
94 in += AES_BLOCK_SIZE;
95 out += AES_BLOCK_SIZE;
96 }
97 } else {
98 while (len) {
99 memcpy(tmp.data, in, AES_BLOCK_SIZE);
100 tmp2 = tmp;
101 for (n = 0; n < N_WORDS; ++n)
102 tmp.data[n] ^= iv2.data[n];
103 AES_decrypt((unsigned char *)tmp.data,
104 (unsigned char *)tmp.data, key);
105 for (n = 0; n < N_WORDS; ++n)
106 tmp.data[n] ^= iv.data[n];
107 memcpy(out, tmp.data, AES_BLOCK_SIZE);
108 iv = tmp2;
109 iv2 = tmp;
110 --len;
111 in += AES_BLOCK_SIZE;
112 out += AES_BLOCK_SIZE;
113 }
114 }
115 memcpy(ivec, iv.data, AES_BLOCK_SIZE);
116 memcpy(ivec + AES_BLOCK_SIZE, iv2.data, AES_BLOCK_SIZE);
117}
118LCRYPTO_ALIAS(AES_ige_encrypt);