1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci/* 11e1051a39Sopenharmony_ci * BF low level APIs are deprecated for public use, but still ok for internal 12e1051a39Sopenharmony_ci * use. 13e1051a39Sopenharmony_ci */ 14e1051a39Sopenharmony_ci#include "internal/deprecated.h" 15e1051a39Sopenharmony_ci 16e1051a39Sopenharmony_ci#include <openssl/blowfish.h> 17e1051a39Sopenharmony_ci#include "bf_local.h" 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ci/* 20e1051a39Sopenharmony_ci * The input and output encrypted as though 64bit ofb mode is being used. 21e1051a39Sopenharmony_ci * The extra state information to record how much of the 64bit block we have 22e1051a39Sopenharmony_ci * used is contained in *num; 23e1051a39Sopenharmony_ci */ 24e1051a39Sopenharmony_civoid BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, 25e1051a39Sopenharmony_ci long length, const BF_KEY *schedule, 26e1051a39Sopenharmony_ci unsigned char *ivec, int *num) 27e1051a39Sopenharmony_ci{ 28e1051a39Sopenharmony_ci register BF_LONG v0, v1, t; 29e1051a39Sopenharmony_ci register int n = *num; 30e1051a39Sopenharmony_ci register long l = length; 31e1051a39Sopenharmony_ci unsigned char d[8]; 32e1051a39Sopenharmony_ci register char *dp; 33e1051a39Sopenharmony_ci BF_LONG ti[2]; 34e1051a39Sopenharmony_ci unsigned char *iv; 35e1051a39Sopenharmony_ci int save = 0; 36e1051a39Sopenharmony_ci 37e1051a39Sopenharmony_ci iv = (unsigned char *)ivec; 38e1051a39Sopenharmony_ci n2l(iv, v0); 39e1051a39Sopenharmony_ci n2l(iv, v1); 40e1051a39Sopenharmony_ci ti[0] = v0; 41e1051a39Sopenharmony_ci ti[1] = v1; 42e1051a39Sopenharmony_ci dp = (char *)d; 43e1051a39Sopenharmony_ci l2n(v0, dp); 44e1051a39Sopenharmony_ci l2n(v1, dp); 45e1051a39Sopenharmony_ci while (l--) { 46e1051a39Sopenharmony_ci if (n == 0) { 47e1051a39Sopenharmony_ci BF_encrypt((BF_LONG *)ti, schedule); 48e1051a39Sopenharmony_ci dp = (char *)d; 49e1051a39Sopenharmony_ci t = ti[0]; 50e1051a39Sopenharmony_ci l2n(t, dp); 51e1051a39Sopenharmony_ci t = ti[1]; 52e1051a39Sopenharmony_ci l2n(t, dp); 53e1051a39Sopenharmony_ci save++; 54e1051a39Sopenharmony_ci } 55e1051a39Sopenharmony_ci *(out++) = *(in++) ^ d[n]; 56e1051a39Sopenharmony_ci n = (n + 1) & 0x07; 57e1051a39Sopenharmony_ci } 58e1051a39Sopenharmony_ci if (save) { 59e1051a39Sopenharmony_ci v0 = ti[0]; 60e1051a39Sopenharmony_ci v1 = ti[1]; 61e1051a39Sopenharmony_ci iv = (unsigned char *)ivec; 62e1051a39Sopenharmony_ci l2n(v0, iv); 63e1051a39Sopenharmony_ci l2n(v1, iv); 64e1051a39Sopenharmony_ci } 65e1051a39Sopenharmony_ci t = v0 = v1 = ti[0] = ti[1] = 0; 66e1051a39Sopenharmony_ci *num = n; 67e1051a39Sopenharmony_ci} 68