1*49d46fa3Schristos /* crypto/des/ofb64enc.c */
2*49d46fa3Schristos /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3*49d46fa3Schristos * All rights reserved.
4*49d46fa3Schristos *
5*49d46fa3Schristos * This package is an SSL implementation written
6*49d46fa3Schristos * by Eric Young (eay@cryptsoft.com).
7*49d46fa3Schristos * The implementation was written so as to conform with Netscapes SSL.
8*49d46fa3Schristos *
9*49d46fa3Schristos * This library is free for commercial and non-commercial use as long as
10*49d46fa3Schristos * the following conditions are aheared to. The following conditions
11*49d46fa3Schristos * apply to all code found in this distribution, be it the RC4, RSA,
12*49d46fa3Schristos * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13*49d46fa3Schristos * included with this distribution is covered by the same copyright terms
14*49d46fa3Schristos * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15*49d46fa3Schristos *
16*49d46fa3Schristos * Copyright remains Eric Young's, and as such any Copyright notices in
17*49d46fa3Schristos * the code are not to be removed.
18*49d46fa3Schristos * If this package is used in a product, Eric Young should be given attribution
19*49d46fa3Schristos * as the author of the parts of the library used.
20*49d46fa3Schristos * This can be in the form of a textual message at program startup or
21*49d46fa3Schristos * in documentation (online or textual) provided with the package.
22*49d46fa3Schristos *
23*49d46fa3Schristos * Redistribution and use in source and binary forms, with or without
24*49d46fa3Schristos * modification, are permitted provided that the following conditions
25*49d46fa3Schristos * are met:
26*49d46fa3Schristos * 1. Redistributions of source code must retain the copyright
27*49d46fa3Schristos * notice, this list of conditions and the following disclaimer.
28*49d46fa3Schristos * 2. Redistributions in binary form must reproduce the above copyright
29*49d46fa3Schristos * notice, this list of conditions and the following disclaimer in the
30*49d46fa3Schristos * documentation and/or other materials provided with the distribution.
31*49d46fa3Schristos * 3. All advertising materials mentioning features or use of this software
32*49d46fa3Schristos * must display the following acknowledgement:
33*49d46fa3Schristos * "This product includes cryptographic software written by
34*49d46fa3Schristos * Eric Young (eay@cryptsoft.com)"
35*49d46fa3Schristos * The word 'cryptographic' can be left out if the rouines from the library
36*49d46fa3Schristos * being used are not cryptographic related :-).
37*49d46fa3Schristos * 4. If you include any Windows specific code (or a derivative thereof) from
38*49d46fa3Schristos * the apps directory (application code) you must include an acknowledgement:
39*49d46fa3Schristos * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40*49d46fa3Schristos *
41*49d46fa3Schristos * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42*49d46fa3Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43*49d46fa3Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44*49d46fa3Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45*49d46fa3Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46*49d46fa3Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47*49d46fa3Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48*49d46fa3Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49*49d46fa3Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50*49d46fa3Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51*49d46fa3Schristos * SUCH DAMAGE.
52*49d46fa3Schristos *
53*49d46fa3Schristos * The licence and distribution terms for any publically available version or
54*49d46fa3Schristos * derivative of this code cannot be changed. i.e. this code cannot simply be
55*49d46fa3Schristos * copied and put under another distribution licence
56*49d46fa3Schristos * [including the GNU Public Licence.]
57*49d46fa3Schristos */
58*49d46fa3Schristos
59*49d46fa3Schristos #include "des_locl.h"
60*49d46fa3Schristos
61*49d46fa3Schristos /* The input and output encrypted as though 64bit ofb mode is being
62*49d46fa3Schristos * used. The extra state information to record how much of the
63*49d46fa3Schristos * 64bit block we have used is contained in *num;
64*49d46fa3Schristos */
des_ofb64_encrypt(register const unsigned char * in,register unsigned char * out,long length,des_key_schedule schedule,des_cblock * ivec,int * num)65*49d46fa3Schristos void des_ofb64_encrypt(register const unsigned char *in,
66*49d46fa3Schristos register unsigned char *out, long length, des_key_schedule schedule,
67*49d46fa3Schristos des_cblock *ivec, int *num)
68*49d46fa3Schristos {
69*49d46fa3Schristos register DES_LONG v0,v1,t;
70*49d46fa3Schristos register int n= *num;
71*49d46fa3Schristos register long l=length;
72*49d46fa3Schristos des_cblock d;
73*49d46fa3Schristos register unsigned char *dp;
74*49d46fa3Schristos DES_LONG ti[2];
75*49d46fa3Schristos unsigned char *iv;
76*49d46fa3Schristos int save=0;
77*49d46fa3Schristos
78*49d46fa3Schristos iv = &(*ivec)[0];
79*49d46fa3Schristos c2l(iv,v0);
80*49d46fa3Schristos c2l(iv,v1);
81*49d46fa3Schristos ti[0]=v0;
82*49d46fa3Schristos ti[1]=v1;
83*49d46fa3Schristos dp=d;
84*49d46fa3Schristos l2c(v0,dp);
85*49d46fa3Schristos l2c(v1,dp);
86*49d46fa3Schristos while (l--)
87*49d46fa3Schristos {
88*49d46fa3Schristos if (n == 0)
89*49d46fa3Schristos {
90*49d46fa3Schristos des_encrypt1(ti,schedule,DES_ENCRYPT);
91*49d46fa3Schristos dp=d;
92*49d46fa3Schristos t=ti[0]; l2c(t,dp);
93*49d46fa3Schristos t=ti[1]; l2c(t,dp);
94*49d46fa3Schristos save++;
95*49d46fa3Schristos }
96*49d46fa3Schristos *(out++)= *(in++)^d[n];
97*49d46fa3Schristos n=(n+1)&0x07;
98*49d46fa3Schristos }
99*49d46fa3Schristos if (save)
100*49d46fa3Schristos {
101*49d46fa3Schristos v0=ti[0];
102*49d46fa3Schristos v1=ti[1];
103*49d46fa3Schristos iv = &(*ivec)[0];
104*49d46fa3Schristos l2c(v0,iv);
105*49d46fa3Schristos l2c(v1,iv);
106*49d46fa3Schristos }
107*49d46fa3Schristos t=v0=v1=ti[0]=ti[1]=0;
108*49d46fa3Schristos *num=n;
109*49d46fa3Schristos }
110*49d46fa3Schristos
111