/* $KAME: des_ecb.c,v 1.6 2001/09/10 04:03:58 itojun Exp $ */12/* crypto/des/ecb_enc.c */34/* Copyright (C) 1995-1998 Eric Young ([email protected])5* All rights reserved.6*7* This file is part of an SSL implementation written8* by Eric Young ([email protected]).9* The implementation was written so as to conform with Netscapes SSL10* specification. This library and applications are11* FREE FOR COMMERCIAL AND NON-COMMERCIAL USE12* as long as the following conditions are aheared to.13*14* Copyright remains Eric Young's, and as such any Copyright notices in15* the code are not to be removed. If this code is used in a product,16* Eric Young should be given attribution as the author of the parts used.17* This can be in the form of a textual message at program startup or18* in documentation (online or textual) provided with the package.19*20* Redistribution and use in source and binary forms, with or without21* modification, are permitted provided that the following conditions22* are met:23* 1. Redistributions of source code must retain the copyright24* notice, this list of conditions and the following disclaimer.25* 2. Redistributions in binary form must reproduce the above copyright26* notice, this list of conditions and the following disclaimer in the27* documentation and/or other materials provided with the distribution.28* 3. All advertising materials mentioning features or use of this software29* must display the following acknowledgement:30* This product includes software developed by Eric Young ([email protected])31*32* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND33* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE34* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE35* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE36* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL37* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS38* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)39* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT40* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY41* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF42* SUCH DAMAGE.43*44* The licence and distribution terms for any publically available version or45* derivative of this code cannot be changed. i.e. this code cannot simply be46* copied and put under another distribution licence47* [including the GNU Public Licence.]48*/4950#include <sys/param.h>51#include <sys/systm.h>52#include <crypto/des/des_locl.h>53#include <crypto/des/spr.h>5455/* char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; */ /* wrong */56/* char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996"; */5758char *des_options(void)59{60static int init=1;61static char buf[32];6263if (init)64{65const char *ptr,*unroll,*risc,*size;6667#ifdef DES_PTR68ptr="ptr";69#else70ptr="idx";71#endif72#if defined(DES_RISC1) || defined(DES_RISC2)73#ifdef DES_RISC174risc="risc1";75#endif76#ifdef DES_RISC277risc="risc2";78#endif79#else80risc="cisc";81#endif82#ifdef DES_UNROLL83unroll="16";84#else85unroll="4";86#endif87if (sizeof(DES_LONG) != sizeof(long))88size="int";89else90size="long";91sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size);92init=0;93}94return(buf);95}96void des_ecb_encrypt(unsigned char *input, unsigned char *output,97des_key_schedule ks, int enc)98{99register DES_LONG l;100DES_LONG ll[2];101const unsigned char *in = input;102unsigned char *out = output;103104c2l(in,l); ll[0]=l;105c2l(in,l); ll[1]=l;106des_encrypt1(ll,ks,enc);107l=ll[0]; l2c(l,out);108l=ll[1]; l2c(l,out);109l=ll[0]=ll[1]=0;110}111112void des_ecb3_encrypt(unsigned char *input, unsigned char *output,113des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3,114int enc)115{116register DES_LONG l0,l1;117DES_LONG ll[2];118const unsigned char *in = input;119unsigned char *out = output;120121c2l(in,l0);122c2l(in,l1);123ll[0]=l0;124ll[1]=l1;125126if (enc)127des_encrypt3(ll,ks1,ks2,ks3);128else129des_decrypt3(ll,ks1,ks2,ks3);130131l0=ll[0];132l1=ll[1];133l2c(l0,out);134l2c(l1,out);135}136137138