1 /*
2  * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
10 #include "des_local.h"
12 /*
13  * The input and output encrypted as though 64bit cfb mode is being used.
14  * The extra state information to record how much of the 64bit block we have
15  * used is contained in *num;
16  */
18 void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
19                             long length, DES_key_schedule *ks1,
20                             DES_key_schedule *ks2, DES_key_schedule *ks3,
21                             DES_cblock *ivec, int *num, int enc)
22 {
23     register DES_LONG v0, v1;
24     register long l = length;
25     register int n = *num;
26     DES_LONG ti;
27     unsigned char *iv, c, cc;
29     iv = &(*ivec);
30     if (enc) {
31         while (l--) {
32             if (n == 0) {
33                 c2l(iv, v0);
34                 c2l(iv, v1);
36                 ti = v0;
37                 ti = v1;
38                 DES_encrypt3(ti, ks1, ks2, ks3);
39                 v0 = ti;
40                 v1 = ti;
42                 iv = &(*ivec);
43                 l2c(v0, iv);
44                 l2c(v1, iv);
45                 iv = &(*ivec);
46             }
47             c = *(in++) ^ iv[n];
48             *(out++) = c;
49             iv[n] = c;
50             n = (n + 1) & 0x07;
51         }
52     } else {
53         while (l--) {
54             if (n == 0) {
55                 c2l(iv, v0);
56                 c2l(iv, v1);
58                 ti = v0;
59                 ti = v1;
60                 DES_encrypt3(ti, ks1, ks2, ks3);
61                 v0 = ti;
62                 v1 = ti;
64                 iv = &(*ivec);
65                 l2c(v0, iv);
66                 l2c(v1, iv);
67                 iv = &(*ivec);
68             }
69             cc = *(in++);
70             c = iv[n];
71             iv[n] = cc;
72             *(out++) = c ^ cc;
73             n = (n + 1) & 0x07;
74         }
75     }
76     v0 = v1 = ti = ti = c = cc = 0;
77     *num = n;
78 }
80 /*
81  * This is compatible with the single key CFB-r for DES, even thought that's
82  * not what EVP needs.
83  */
85 void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
86                           int numbits, long length, DES_key_schedule *ks1,
87                           DES_key_schedule *ks2, DES_key_schedule *ks3,
88                           DES_cblock *ivec, int enc)
89 {
90     register DES_LONG d0, d1, v0, v1;
91     register unsigned long l = length, n = ((unsigned int)numbits + 7) / 8;
92     register int num = numbits, i;
93     DES_LONG ti;
94     unsigned char *iv;
95     unsigned char ovec;
97     if (num > 64)
98         return;
99     iv = &(*ivec);
100     c2l(iv, v0);
101     c2l(iv, v1);
102     if (enc) {
103         while (l >= n) {
104             l -= n;
105             ti = v0;
106             ti = v1;
107             DES_encrypt3(ti, ks1, ks2, ks3);
108             c2ln(in, d0, d1, n);
109             in += n;
110             d0 ^= ti;
111             d1 ^= ti;
112             l2cn(d0, d1, out, n);
113             out += n;
114             /*
115              * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under
116              * gcc :-(
117              */
118             if (num == 32) {
119                 v0 = v1;
120                 v1 = d0;
121             } else if (num == 64) {
122                 v0 = d0;
123                 v1 = d1;
124             } else {
125                 iv = &ovec;
126                 l2c(v0, iv);
127                 l2c(v1, iv);
128                 l2c(d0, iv);
129                 l2c(d1, iv);
130                 /* shift ovec left most of the bits... */
131                 memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0));
132                 /* now the remaining bits */
133                 if (num % 8 != 0)
134                     for (i = 0; i < 8; ++i) {
135                         ovec[i] <<= num % 8;
136                         ovec[i] |= ovec[i + 1] >> (8 - num % 8);
137                     }
138                 iv = &ovec;
139                 c2l(iv, v0);
140                 c2l(iv, v1);
141             }
142         }
143     } else {
144         while (l >= n) {
145             l -= n;
146             ti = v0;
147             ti = v1;
148             DES_encrypt3(ti, ks1, ks2, ks3);
149             c2ln(in, d0, d1, n);
150             in += n;
151             /*
152              * 30-08-94 - eay - changed because l>>32 and l<<32 are bad under
153              * gcc :-(
154              */
155             if (num == 32) {
156                 v0 = v1;
157                 v1 = d0;
158             } else if (num == 64) {
159                 v0 = d0;
160                 v1 = d1;
161             } else {
162                 iv = &ovec;
163                 l2c(v0, iv);
164                 l2c(v1, iv);
165                 l2c(d0, iv);
166                 l2c(d1, iv);
167                 /* shift ovec left most of the bits... */
168                 memmove(ovec, ovec + num / 8, 8 + (num % 8 ? 1 : 0));
169                 /* now the remaining bits */
170                 if (num % 8 != 0)
171                     for (i = 0; i < 8; ++i) {
172                         ovec[i] <<= num % 8;
173                         ovec[i] |= ovec[i + 1] >> (8 - num % 8);
174                     }
175                 iv = &ovec;
176                 c2l(iv, v0);
177                 c2l(iv, v1);
178             }
179             d0 ^= ti;
180             d1 ^= ti;
181             l2cn(d0, d1, out, n);
182             out += n;
183         }
184     }
185     iv = &(*ivec);
186     l2c(v0, iv);
187     l2c(v1, iv);
188     v0 = v1 = d0 = d1 = ti = ti = 0;
189 }
{"ft_lang_label":"__label__en","ft_lang_prob":0.59574974,"math_prob":0.9844226,"size":2215,"snap":"2020-10-2020-16","text_gpt3_token_len":756,"char_repetition_ratio":0.111714154,"word_repetition_ratio":0.21077283,"special_character_ratio":0.4343115,"punctuation_ratio":0.19135803,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9696593,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-03-29T22:19:42Z\",\"WARC-Record-ID\":\"<urn:uuid:0ca4f67a-bc27-42d1-89f1-351a38c8475a>\",\"Content-Length\":\"54255\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1ec2eccf-6ea6-4153-8acf-8f1a37d9701a>\",\"WARC-Concurrent-To\":\"<urn:uuid:47cc0c60-a61a-4330-ab71-6296443b80ef>\",\"WARC-IP-Address\":\"194.97.150.234\",\"WARC-Target-URI\":\"https://git.openssl.org/gitweb/?p=openssl.git;a=blob;f=crypto/des/cfb64ede.c;h=cb5dad2ca63afba3b17f85ab5fdbf0ec46b1e56b\",\"WARC-Payload-Digest\":\"sha1:OLKWN7OCFFD5FGUF6ZMKY46DRSRHRSNF\",\"WARC-Block-Digest\":\"sha1:CUS6SV3LDTXIVXCM6YEJ64SW6DQ4T3OQ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370496227.25_warc_CC-MAIN-20200329201741-20200329231741-00108.warc.gz\"}"}