11cb0ef41Sopenharmony_ci/* 21cb0ef41Sopenharmony_ci * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved. 31cb0ef41Sopenharmony_ci * 41cb0ef41Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 51cb0ef41Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 61cb0ef41Sopenharmony_ci * in the file LICENSE in the source distribution or at 71cb0ef41Sopenharmony_ci * https://www.openssl.org/source/license.html 81cb0ef41Sopenharmony_ci */ 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci/* 111cb0ef41Sopenharmony_ci * BF low level APIs are deprecated for public use, but still ok for internal 121cb0ef41Sopenharmony_ci * use. 131cb0ef41Sopenharmony_ci */ 141cb0ef41Sopenharmony_ci#include "internal/deprecated.h" 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci#include <openssl/blowfish.h> 171cb0ef41Sopenharmony_ci#include "bf_local.h" 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci/* 201cb0ef41Sopenharmony_ci * The input and output encrypted as though 64bit ofb mode is being used. 211cb0ef41Sopenharmony_ci * The extra state information to record how much of the 64bit block we have 221cb0ef41Sopenharmony_ci * used is contained in *num; 231cb0ef41Sopenharmony_ci */ 241cb0ef41Sopenharmony_civoid BF_ofb64_encrypt(const unsigned char *in, unsigned char *out, 251cb0ef41Sopenharmony_ci long length, const BF_KEY *schedule, 261cb0ef41Sopenharmony_ci unsigned char *ivec, int *num) 271cb0ef41Sopenharmony_ci{ 281cb0ef41Sopenharmony_ci register BF_LONG v0, v1, t; 291cb0ef41Sopenharmony_ci register int n = *num; 301cb0ef41Sopenharmony_ci register long l = length; 311cb0ef41Sopenharmony_ci unsigned char d[8]; 321cb0ef41Sopenharmony_ci register char *dp; 331cb0ef41Sopenharmony_ci BF_LONG ti[2]; 341cb0ef41Sopenharmony_ci unsigned char *iv; 351cb0ef41Sopenharmony_ci int save = 0; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci iv = (unsigned char *)ivec; 381cb0ef41Sopenharmony_ci n2l(iv, v0); 391cb0ef41Sopenharmony_ci n2l(iv, v1); 401cb0ef41Sopenharmony_ci ti[0] = v0; 411cb0ef41Sopenharmony_ci ti[1] = v1; 421cb0ef41Sopenharmony_ci dp = (char *)d; 431cb0ef41Sopenharmony_ci l2n(v0, dp); 441cb0ef41Sopenharmony_ci l2n(v1, dp); 451cb0ef41Sopenharmony_ci while (l--) { 461cb0ef41Sopenharmony_ci if (n == 0) { 471cb0ef41Sopenharmony_ci BF_encrypt((BF_LONG *)ti, schedule); 481cb0ef41Sopenharmony_ci dp = (char *)d; 491cb0ef41Sopenharmony_ci t = ti[0]; 501cb0ef41Sopenharmony_ci l2n(t, dp); 511cb0ef41Sopenharmony_ci t = ti[1]; 521cb0ef41Sopenharmony_ci l2n(t, dp); 531cb0ef41Sopenharmony_ci save++; 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci *(out++) = *(in++) ^ d[n]; 561cb0ef41Sopenharmony_ci n = (n + 1) & 0x07; 571cb0ef41Sopenharmony_ci } 581cb0ef41Sopenharmony_ci if (save) { 591cb0ef41Sopenharmony_ci v0 = ti[0]; 601cb0ef41Sopenharmony_ci v1 = ti[1]; 611cb0ef41Sopenharmony_ci iv = (unsigned char *)ivec; 621cb0ef41Sopenharmony_ci l2n(v0, iv); 631cb0ef41Sopenharmony_ci l2n(v1, iv); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci t = v0 = v1 = ti[0] = ti[1] = 0; 661cb0ef41Sopenharmony_ci *num = n; 671cb0ef41Sopenharmony_ci} 68