2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (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
11 * DES low level APIs are deprecated for public use, but still ok for internal
14 #include "internal/deprecated.h"
16 #include "des_local.h"
19 * The input and output encrypted as though 64bit cfb mode is being used.
20 * The extra state information to record how much of the 64bit block we have
21 * used is contained in *num;
24 void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
25 long length, DES_key_schedule *ks1,
26 DES_key_schedule *ks2, DES_key_schedule *ks3,
27 DES_cblock *ivec, int *num, int enc)
29 register DES_LONG v0, v1;
30 register long l = length;
31 register int n = *num;
33 unsigned char *iv, c, cc;
44 DES_encrypt3(ti, ks1, ks2, ks3);
66 DES_encrypt3(ti, ks1, ks2, ks3);
82 v0 = v1 = ti[0] = ti[1] = c = cc = 0;
87 * This is compatible with the single key CFB-r for DES, even thought that's
91 void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
92 int numbits, long length, DES_key_schedule *ks1,
93 DES_key_schedule *ks2, DES_key_schedule *ks3,
94 DES_cblock *ivec, int enc)
96 register DES_LONG d0, d1, v0, v1;
97 register unsigned long l = length, n = ((unsigned int)numbits + 7) / 8;
98 register int num = numbits, i;
101 unsigned char ovec[16];
113 DES_encrypt3(ti, ks1, ks2, ks3);
118 l2cn(d0, d1, out, n);
121 * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under
127 } else if (num == 64) {
136 /* shift ovec left most of the bits... */
137 memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0));
138 /* now the remaining bits */
140 for (i = 0; i < 8; ++i) {
142 ovec[i] |= ovec[i + 1] >> (8 - num % 8);
154 DES_encrypt3(ti, ks1, ks2, ks3);
158 * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under
164 } else if (num == 64) {
173 /* shift ovec left most of the bits... */
174 memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0));
175 /* now the remaining bits */
177 for (i = 0; i < 8; ++i) {
179 ovec[i] |= ovec[i + 1] >> (8 - num % 8);
187 l2cn(d0, d1, out, n);
194 v0 = v1 = d0 = d1 = ti[0] = ti[1] = 0;