1218885Sdim/* crypto/des/ofb64enc.c */ 2218885Sdim/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 3218885Sdim * All rights reserved. 4218885Sdim * 5218885Sdim * This package is an SSL implementation written 6218885Sdim * by Eric Young (eay@cryptsoft.com). 7218885Sdim * The implementation was written so as to conform with Netscapes SSL. 8218885Sdim * 9218885Sdim * This library is free for commercial and non-commercial use as long as 10218885Sdim * the following conditions are aheared to. The following conditions 11218885Sdim * apply to all code found in this distribution, be it the RC4, RSA, 12218885Sdim * lhash, DES, etc., code; not just the SSL code. The SSL documentation 13218885Sdim * included with this distribution is covered by the same copyright terms 14218885Sdim * except that the holder is Tim Hudson (tjh@cryptsoft.com). 15218885Sdim * 16218885Sdim * Copyright remains Eric Young's, and as such any Copyright notices in 17218885Sdim * the code are not to be removed. 18218885Sdim * If this package is used in a product, Eric Young should be given attribution 19218885Sdim * as the author of the parts of the library used. 20218885Sdim * This can be in the form of a textual message at program startup or 21218885Sdim * in documentation (online or textual) provided with the package. 22218885Sdim * 23218885Sdim * Redistribution and use in source and binary forms, with or without 24218885Sdim * modification, are permitted provided that the following conditions 25239462Sdim * are met: 26239462Sdim * 1. Redistributions of source code must retain the copyright 27218885Sdim * notice, this list of conditions and the following disclaimer. 28218885Sdim * 2. Redistributions in binary form must reproduce the above copyright 29218885Sdim * notice, this list of conditions and the following disclaimer in the 30218885Sdim * documentation and/or other materials provided with the distribution. 31218885Sdim * 3. All advertising materials mentioning features or use of this software 32218885Sdim * must display the following acknowledgement: 33218885Sdim * "This product includes cryptographic software written by 34218885Sdim * Eric Young (eay@cryptsoft.com)" 35218885Sdim * The word 'cryptographic' can be left out if the rouines from the library 36218885Sdim * being used are not cryptographic related :-). 37218885Sdim * 4. If you include any Windows specific code (or a derivative thereof) from 38218885Sdim * the apps directory (application code) you must include an acknowledgement: 39218885Sdim * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 40218885Sdim * 41218885Sdim * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 42218885Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43218885Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 44218885Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 45218885Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 46218885Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 47218885Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 48218885Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 49218885Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 50218885Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 51218885Sdim * SUCH DAMAGE. 52218885Sdim * 53218885Sdim * The licence and distribution terms for any publically available version or 54218885Sdim * derivative of this code cannot be changed. i.e. this code cannot simply be 55218885Sdim * copied and put under another distribution licence 56218885Sdim * [including the GNU Public Licence.] 57218885Sdim */ 58218885Sdim 59218885Sdim#include "des_locl.h" 60218885Sdim 61218885Sdim/* The input and output encrypted as though 64bit ofb mode is being 62218885Sdim * used. The extra state information to record how much of the 63218885Sdim * 64bit block we have used is contained in *num; 64218885Sdim */ 65218885Sdimvoid DES_ofb64_encrypt(register const unsigned char *in, 66218885Sdim register unsigned char *out, long length, 67234353Sdim DES_key_schedule *schedule, DES_cblock *ivec, int *num) 68218885Sdim { 69218885Sdim register DES_LONG v0,v1,t; 70218885Sdim register int n= *num; 71218885Sdim register long l=length; 72218885Sdim DES_cblock d; 73218885Sdim register unsigned char *dp; 74218885Sdim DES_LONG ti[2]; 75218885Sdim unsigned char *iv; 76218885Sdim int save=0; 77218885Sdim 78218885Sdim iv = &(*ivec)[0]; 79218885Sdim c2l(iv,v0); 80218885Sdim c2l(iv,v1); 81218885Sdim ti[0]=v0; 82218885Sdim ti[1]=v1; 83218885Sdim dp=d; 84218885Sdim l2c(v0,dp); 85218885Sdim l2c(v1,dp); 86218885Sdim while (l--) 87218885Sdim { 88218885Sdim if (n == 0) 89218885Sdim { 90218885Sdim DES_encrypt1(ti,schedule,DES_ENCRYPT); 91218885Sdim dp=d; 92218885Sdim t=ti[0]; l2c(t,dp); 93218885Sdim t=ti[1]; l2c(t,dp); 94218885Sdim save++; 95218885Sdim } 96218885Sdim *(out++)= *(in++)^d[n]; 97234353Sdim n=(n+1)&0x07; 98218885Sdim } 99218885Sdim if (save) 100218885Sdim { 101218885Sdim v0=ti[0]; 102218885Sdim v1=ti[1]; 103218885Sdim iv = &(*ivec)[0]; 104218885Sdim l2c(v0,iv); 105218885Sdim l2c(v1,iv); 106218885Sdim } 107218885Sdim t=v0=v1=ti[0]=ti[1]=0; 108218885Sdim *num=n; 109218885Sdim } 110218885Sdim 111218885Sdim