diff options
Diffstat (limited to 'src/lib/libcrypto/modes/ofb128.c')
-rw-r--r-- | src/lib/libcrypto/modes/ofb128.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/src/lib/libcrypto/modes/ofb128.c b/src/lib/libcrypto/modes/ofb128.c index 3cf5d98150..9ef812a08b 100644 --- a/src/lib/libcrypto/modes/ofb128.c +++ b/src/lib/libcrypto/modes/ofb128.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ofb128.c,v 1.5 2022/11/26 16:08:53 tb Exp $ */ | 1 | /* $OpenBSD: ofb128.c,v 1.6 2023/07/08 14:55:36 beck 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 | * |
@@ -7,7 +7,7 @@ | |||
7 | * are met: | 7 | * are met: |
8 | * | 8 | * |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * | 11 | * |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in | 13 | * notice, this list of conditions and the following disclaimer in |
@@ -63,57 +63,61 @@ | |||
63 | * used. The extra state information to record how much of the | 63 | * used. The extra state information to record how much of the |
64 | * 128bit block we have used is contained in *num; | 64 | * 128bit block we have used is contained in *num; |
65 | */ | 65 | */ |
66 | void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, | 66 | void |
67 | size_t len, const void *key, | 67 | CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, |
68 | unsigned char ivec[16], int *num, | 68 | size_t len, const void *key, |
69 | block128_f block) | 69 | unsigned char ivec[16], int *num, |
70 | block128_f block) | ||
70 | { | 71 | { |
71 | unsigned int n; | 72 | unsigned int n; |
72 | size_t l=0; | 73 | size_t l = 0; |
73 | 74 | ||
74 | n = *num; | 75 | n = *num; |
75 | 76 | ||
76 | #if !defined(OPENSSL_SMALL_FOOTPRINT) | 77 | #if !defined(OPENSSL_SMALL_FOOTPRINT) |
77 | if (16%sizeof(size_t) == 0) do { /* always true actually */ | 78 | if (16 % sizeof(size_t) == 0) |
78 | while (n && len) { | 79 | do { /* always true actually */ |
79 | *(out++) = *(in++) ^ ivec[n]; | 80 | while (n && len) { |
80 | --len; | 81 | *(out++) = *(in++) ^ ivec[n]; |
81 | n = (n+1) % 16; | 82 | --len; |
82 | } | 83 | n = (n + 1) % 16; |
84 | } | ||
83 | #ifdef __STRICT_ALIGNMENT | 85 | #ifdef __STRICT_ALIGNMENT |
84 | if (((size_t)in|(size_t)out|(size_t)ivec)%sizeof(size_t) != 0) | 86 | if (((size_t)in|(size_t)out|(size_t)ivec) % |
85 | break; | 87 | sizeof(size_t) != 0) |
88 | break; | ||
86 | #endif | 89 | #endif |
87 | while (len>=16) { | 90 | while (len >= 16) { |
88 | (*block)(ivec, ivec, key); | 91 | (*block)(ivec, ivec, key); |
89 | for (; n<16; n+=sizeof(size_t)) | 92 | for (; n < 16; n += sizeof(size_t)) |
90 | *(size_t*)(out+n) = | 93 | *(size_t *)(out + n) = |
91 | *(size_t*)(in+n) ^ *(size_t*)(ivec+n); | 94 | *(size_t *)(in + n) ^ *(size_t *)(ivec + |
92 | len -= 16; | 95 | n); |
93 | out += 16; | 96 | len -= 16; |
94 | in += 16; | 97 | out += 16; |
95 | n = 0; | 98 | in += 16; |
96 | } | 99 | n = 0; |
97 | if (len) { | ||
98 | (*block)(ivec, ivec, key); | ||
99 | while (len--) { | ||
100 | out[n] = in[n] ^ ivec[n]; | ||
101 | ++n; | ||
102 | } | 100 | } |
103 | } | 101 | if (len) { |
104 | *num = n; | 102 | (*block)(ivec, ivec, key); |
105 | return; | 103 | while (len--) { |
106 | } while(0); | 104 | out[n] = in[n] ^ ivec[n]; |
105 | ++n; | ||
106 | } | ||
107 | } | ||
108 | *num = n; | ||
109 | return; | ||
110 | } while (0); | ||
107 | /* the rest would be commonly eliminated by x86* compiler */ | 111 | /* the rest would be commonly eliminated by x86* compiler */ |
108 | #endif | 112 | #endif |
109 | while (l<len) { | 113 | while (l < len) { |
110 | if (n==0) { | 114 | if (n == 0) { |
111 | (*block)(ivec, ivec, key); | 115 | (*block)(ivec, ivec, key); |
112 | } | 116 | } |
113 | out[l] = in[l] ^ ivec[n]; | 117 | out[l] = in[l] ^ ivec[n]; |
114 | ++l; | 118 | ++l; |
115 | n = (n+1) % 16; | 119 | n = (n + 1) % 16; |
116 | } | 120 | } |
117 | 121 | ||
118 | *num=n; | 122 | *num = n; |
119 | } | 123 | } |