~ubuntu-branches/ubuntu/maverick/openssl/maverick

« back to all changes in this revision

Viewing changes to crypto/des/cfb64ede.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Martin
  • Date: 2004-12-16 18:41:29 UTC
  • mto: (11.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041216184129-z7xjkul57mh1jiha
Tags: upstream-0.9.7e
ImportĀ upstreamĀ versionĀ 0.9.7e

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
        DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc);
141
141
        }
142
142
#endif
 
143
 
 
144
/* This is compatible with the single key CFB-r for DES, even thought that's
 
145
 * not what EVP needs.
 
146
 */
 
147
 
 
148
void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
 
149
                          int numbits,long length,DES_key_schedule *ks1,
 
150
                          DES_key_schedule *ks2,DES_key_schedule *ks3,
 
151
                          DES_cblock *ivec,int enc)
 
152
        {
 
153
        register DES_LONG d0,d1,v0,v1;
 
154
        register long l=length;
 
155
        register int num=numbits,n=(numbits+7)/8,i;
 
156
        DES_LONG ti[2];
 
157
        unsigned char *iv;
 
158
        unsigned char ovec[16];
 
159
 
 
160
        if (num > 64) return;
 
161
        iv = &(*ivec)[0];
 
162
        c2l(iv,v0);
 
163
        c2l(iv,v1);
 
164
        if (enc)
 
165
                {
 
166
                while (l >= n)
 
167
                        {
 
168
                        l-=n;
 
169
                        ti[0]=v0;
 
170
                        ti[1]=v1;
 
171
                        DES_encrypt3(ti,ks1,ks2,ks3);
 
172
                        c2ln(in,d0,d1,n);
 
173
                        in+=n;
 
174
                        d0^=ti[0];
 
175
                        d1^=ti[1];
 
176
                        l2cn(d0,d1,out,n);
 
177
                        out+=n;
 
178
                        /* 30-08-94 - eay - changed because l>>32 and
 
179
                         * l<<32 are bad under gcc :-( */
 
180
                        if (num == 32)
 
181
                                { v0=v1; v1=d0; }
 
182
                        else if (num == 64)
 
183
                                { v0=d0; v1=d1; }
 
184
                        else
 
185
                                {
 
186
                                iv=&ovec[0];
 
187
                                l2c(v0,iv);
 
188
                                l2c(v1,iv);
 
189
                                l2c(d0,iv);
 
190
                                l2c(d1,iv);
 
191
                                /* shift ovec left most of the bits... */
 
192
                                memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
 
193
                                /* now the remaining bits */
 
194
                                if(num%8 != 0)
 
195
                                        for(i=0 ; i < 8 ; ++i)
 
196
                                                {
 
197
                                                ovec[i]<<=num%8;
 
198
                                                ovec[i]|=ovec[i+1]>>(8-num%8);
 
199
                                                }
 
200
                                iv=&ovec[0];
 
201
                                c2l(iv,v0);
 
202
                                c2l(iv,v1);
 
203
                                }
 
204
                        }
 
205
                }
 
206
        else
 
207
                {
 
208
                while (l >= n)
 
209
                        {
 
210
                        l-=n;
 
211
                        ti[0]=v0;
 
212
                        ti[1]=v1;
 
213
                        DES_encrypt3(ti,ks1,ks2,ks3);
 
214
                        c2ln(in,d0,d1,n);
 
215
                        in+=n;
 
216
                        /* 30-08-94 - eay - changed because l>>32 and
 
217
                         * l<<32 are bad under gcc :-( */
 
218
                        if (num == 32)
 
219
                                { v0=v1; v1=d0; }
 
220
                        else if (num == 64)
 
221
                                { v0=d0; v1=d1; }
 
222
                        else
 
223
                                {
 
224
                                iv=&ovec[0];
 
225
                                l2c(v0,iv);
 
226
                                l2c(v1,iv);
 
227
                                l2c(d0,iv);
 
228
                                l2c(d1,iv);
 
229
                                /* shift ovec left most of the bits... */
 
230
                                memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
 
231
                                /* now the remaining bits */
 
232
                                if(num%8 != 0)
 
233
                                        for(i=0 ; i < 8 ; ++i)
 
234
                                                {
 
235
                                                ovec[i]<<=num%8;
 
236
                                                ovec[i]|=ovec[i+1]>>(8-num%8);
 
237
                                                }
 
238
                                iv=&ovec[0];
 
239
                                c2l(iv,v0);
 
240
                                c2l(iv,v1);
 
241
                                }
 
242
                        d0^=ti[0];
 
243
                        d1^=ti[1];
 
244
                        l2cn(d0,d1,out,n);
 
245
                        out+=n;
 
246
                        }
 
247
                }
 
248
        iv = &(*ivec)[0];
 
249
        l2c(v0,iv);
 
250
        l2c(v1,iv);
 
251
        v0=v1=d0=d1=ti[0]=ti[1]=0;
 
252
        }
 
253