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 * DES 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 "des_local.h" 17e1051a39Sopenharmony_ci 18e1051a39Sopenharmony_ci/* 19e1051a39Sopenharmony_ci * The input and output encrypted as though 64bit ofb mode is being used. 20e1051a39Sopenharmony_ci * The extra state information to record how much of the 64bit block we have 21e1051a39Sopenharmony_ci * used is contained in *num; 22e1051a39Sopenharmony_ci */ 23e1051a39Sopenharmony_civoid DES_ofb64_encrypt(register const unsigned char *in, 24e1051a39Sopenharmony_ci register unsigned char *out, long length, 25e1051a39Sopenharmony_ci DES_key_schedule *schedule, DES_cblock *ivec, int *num) 26e1051a39Sopenharmony_ci{ 27e1051a39Sopenharmony_ci register DES_LONG v0, v1, t; 28e1051a39Sopenharmony_ci register int n = *num; 29e1051a39Sopenharmony_ci register long l = length; 30e1051a39Sopenharmony_ci DES_cblock d; 31e1051a39Sopenharmony_ci register unsigned char *dp; 32e1051a39Sopenharmony_ci DES_LONG ti[2]; 33e1051a39Sopenharmony_ci unsigned char *iv; 34e1051a39Sopenharmony_ci int save = 0; 35e1051a39Sopenharmony_ci 36e1051a39Sopenharmony_ci iv = &(*ivec)[0]; 37e1051a39Sopenharmony_ci c2l(iv, v0); 38e1051a39Sopenharmony_ci c2l(iv, v1); 39e1051a39Sopenharmony_ci ti[0] = v0; 40e1051a39Sopenharmony_ci ti[1] = v1; 41e1051a39Sopenharmony_ci dp = d; 42e1051a39Sopenharmony_ci l2c(v0, dp); 43e1051a39Sopenharmony_ci l2c(v1, dp); 44e1051a39Sopenharmony_ci while (l--) { 45e1051a39Sopenharmony_ci if (n == 0) { 46e1051a39Sopenharmony_ci DES_encrypt1(ti, schedule, DES_ENCRYPT); 47e1051a39Sopenharmony_ci dp = d; 48e1051a39Sopenharmony_ci t = ti[0]; 49e1051a39Sopenharmony_ci l2c(t, dp); 50e1051a39Sopenharmony_ci t = ti[1]; 51e1051a39Sopenharmony_ci l2c(t, dp); 52e1051a39Sopenharmony_ci save++; 53e1051a39Sopenharmony_ci } 54e1051a39Sopenharmony_ci *(out++) = *(in++) ^ d[n]; 55e1051a39Sopenharmony_ci n = (n + 1) & 0x07; 56e1051a39Sopenharmony_ci } 57e1051a39Sopenharmony_ci if (save) { 58e1051a39Sopenharmony_ci v0 = ti[0]; 59e1051a39Sopenharmony_ci v1 = ti[1]; 60e1051a39Sopenharmony_ci iv = &(*ivec)[0]; 61e1051a39Sopenharmony_ci l2c(v0, iv); 62e1051a39Sopenharmony_ci l2c(v1, iv); 63e1051a39Sopenharmony_ci } 64e1051a39Sopenharmony_ci t = v0 = v1 = ti[0] = ti[1] = 0; 65e1051a39Sopenharmony_ci *num = n; 66e1051a39Sopenharmony_ci} 67