summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/modes/ctr128.c
diff options
context:
space:
mode:
authorjsing <>2025-04-22 14:01:07 +0000
committerjsing <>2025-04-22 14:01:07 +0000
commit485e95e28f88263129557e462e78bc980255bbe1 (patch)
treee0b288381ae00d071a0bc37190fcb5544c41f35c /src/lib/libcrypto/modes/ctr128.c
parent7b71790663bf087f295bfd28475a1e55ce684dbd (diff)
downloadopenbsd-485e95e28f88263129557e462e78bc980255bbe1.tar.gz
openbsd-485e95e28f88263129557e462e78bc980255bbe1.tar.bz2
openbsd-485e95e28f88263129557e462e78bc980255bbe1.zip
Use crypto_load_be32toh()/crypto_store_htobe32() instead of GETU32/PUTU32.
ok tb@
Diffstat (limited to 'src/lib/libcrypto/modes/ctr128.c')
-rw-r--r--src/lib/libcrypto/modes/ctr128.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libcrypto/modes/ctr128.c b/src/lib/libcrypto/modes/ctr128.c
index 9d1be0757b..c2ce1bda21 100644
--- a/src/lib/libcrypto/modes/ctr128.c
+++ b/src/lib/libcrypto/modes/ctr128.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ctr128.c,v 1.14 2025/04/21 16:01:18 jsing Exp $ */ 1/* $OpenBSD: ctr128.c,v 1.15 2025/04/22 14:01:07 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2008 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -54,6 +54,7 @@
54 54
55#include <openssl/crypto.h> 55#include <openssl/crypto.h>
56 56
57#include "crypto_internal.h"
57#include "modes_local.h" 58#include "modes_local.h"
58 59
59/* NOTE: the IV/counter CTR mode is big-endian. The code itself 60/* NOTE: the IV/counter CTR mode is big-endian. The code itself
@@ -212,7 +213,8 @@ CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
212 n = (n + 1) % 16; 213 n = (n + 1) % 16;
213 } 214 }
214 215
215 ctr32 = GETU32(ivec + 12); 216 ctr32 = crypto_load_be32toh(&ivec[12]);
217
216 while (len >= 16) { 218 while (len >= 16) {
217 size_t blocks = len/16; 219 size_t blocks = len/16;
218 /* 220 /*
@@ -236,7 +238,7 @@ CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
236 } 238 }
237 (*func)(in, out, blocks, key, ivec); 239 (*func)(in, out, blocks, key, ivec);
238 /* (*ctr) does not update ivec, caller does: */ 240 /* (*ctr) does not update ivec, caller does: */
239 PUTU32(ivec + 12, ctr32); 241 crypto_store_htobe32(&ivec[12], ctr32);
240 /* ... overflow was detected, propagate carry. */ 242 /* ... overflow was detected, propagate carry. */
241 if (ctr32 == 0) 243 if (ctr32 == 0)
242 ctr96_inc(ivec); 244 ctr96_inc(ivec);
@@ -249,7 +251,7 @@ CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out,
249 memset(ecount_buf, 0, 16); 251 memset(ecount_buf, 0, 16);
250 (*func)(ecount_buf, ecount_buf, 1, key, ivec); 252 (*func)(ecount_buf, ecount_buf, 1, key, ivec);
251 ++ctr32; 253 ++ctr32;
252 PUTU32(ivec + 12, ctr32); 254 crypto_store_htobe32(&ivec[12], ctr32);
253 if (ctr32 == 0) 255 if (ctr32 == 0)
254 ctr96_inc(ivec); 256 ctr96_inc(ivec);
255 while (len--) { 257 while (len--) {