Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/fipsmodule/modes/ofb.c

raw
1 // Copyright (c) 2008 The OpenSSL Project. All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <openssl/type_check.h>
5
6 #include <assert.h>
7 #include <string.h>
8
9 #include "internal.h"
10
11
12 OPENSSL_STATIC_ASSERT(16 % sizeof(size_t) == 0,
13 ofb_block_cannot_be_divided_into_size_t)
14
15 void CRYPTO_ofb128_encrypt(const uint8_t *in, uint8_t *out, size_t len,
16 const AES_KEY *key, uint8_t ivec[16], unsigned *num,
17 block128_f block) {
18 assert(key != NULL && ivec != NULL && num != NULL);
19 assert(len == 0 || (in != NULL && out != NULL));
20
21 unsigned n = *num;
22
23 while (n && len) {
24 *(out++) = *(in++) ^ ivec[n];
25 --len;
26 n = (n + 1) % 16;
27 }
28
29 while (len >= 16) {
30 (*block)(ivec, ivec, key);
31 CRYPTO_xor16(out, in, ivec);
32 len -= 16;
33 out += 16;
34 in += 16;
35 n = 0;
36 }
37 if (len) {
38 (*block)(ivec, ivec, key);
39 while (len--) {
40 out[n] = in[n] ^ ivec[n];
41 ++n;
42 }
43 }
44 *num = n;
45 }