1/* 2 * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10#include <assert.h> 11#include <string.h> 12 13#include "internal.h" 14 15 16static_assert(16 % sizeof(size_t) == 0, "block cannot be divided into size_t"); 17 18void CRYPTO_ofb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, 19 const AES_KEY *key, uint8_t ivec[16], unsigned *num, 20 block128_f block) { 21 assert(key != NULL && ivec != NULL && num != NULL); 22 assert(len == 0 || (in != NULL && out != NULL)); 23 24 unsigned n = *num; 25 26 while (n && len) { 27 *(out++) = *(in++) ^ ivec[n]; 28 --len; 29 n = (n + 1) % 16; 30 } 31 32 while (len >= 16) { 33 (*block)(ivec, ivec, key); 34 CRYPTO_xor16(out, in, ivec); 35 len -= 16; 36 out += 16; 37 in += 16; 38 n = 0; 39 } 40 if (len) { 41 (*block)(ivec, ivec, key); 42 while (len--) { 43 out[n] = in[n] ^ ivec[n]; 44 ++n; 45 } 46 } 47 *num = n; 48} 49