191671Sume/* $KAME: des_ecb.c,v 1.6 2001/09/10 04:03:58 itojun Exp $ */ 262587Sitojun 355009Sshin/* crypto/des/ecb_enc.c */ 4130443Sobrien 591671Sume/* Copyright (C) 1995-1998 Eric Young (eay@mincom.oz.au) 655009Sshin * All rights reserved. 755009Sshin * 855009Sshin * This file is part of an SSL implementation written 955009Sshin * by Eric Young (eay@mincom.oz.au). 1055009Sshin * The implementation was written so as to conform with Netscapes SSL 1155009Sshin * specification. This library and applications are 1255009Sshin * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE 1355009Sshin * as long as the following conditions are aheared to. 1455009Sshin * 1555009Sshin * Copyright remains Eric Young's, and as such any Copyright notices in 1655009Sshin * the code are not to be removed. If this code is used in a product, 1755009Sshin * Eric Young should be given attribution as the author of the parts used. 1855009Sshin * This can be in the form of a textual message at program startup or 1955009Sshin * in documentation (online or textual) provided with the package. 2055009Sshin * 2155009Sshin * Redistribution and use in source and binary forms, with or without 2255009Sshin * modification, are permitted provided that the following conditions 2355009Sshin * are met: 2455009Sshin * 1. Redistributions of source code must retain the copyright 2555009Sshin * notice, this list of conditions and the following disclaimer. 2655009Sshin * 2. Redistributions in binary form must reproduce the above copyright 2755009Sshin * notice, this list of conditions and the following disclaimer in the 2855009Sshin * documentation and/or other materials provided with the distribution. 2955009Sshin * 3. All advertising materials mentioning features or use of this software 3055009Sshin * must display the following acknowledgement: 3155009Sshin * This product includes software developed by Eric Young (eay@mincom.oz.au) 3255009Sshin * 3355009Sshin * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 3455009Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3555009Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3655009Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 3755009Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3855009Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3955009Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4055009Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 4155009Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 4255009Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 4355009Sshin * SUCH DAMAGE. 4455009Sshin * 4555009Sshin * The licence and distribution terms for any publically available version or 4655009Sshin * derivative of this code cannot be changed. i.e. this code cannot simply be 4755009Sshin * copied and put under another distribution licence 4855009Sshin * [including the GNU Public Licence.] 4955009Sshin */ 5055009Sshin 51130443Sobrien#include <sys/cdefs.h> 52130443Sobrien__FBSDID("$FreeBSD$"); 53130443Sobrien 5478064Sume#include <sys/param.h> 5578064Sume#include <sys/systm.h> 5655009Sshin#include <crypto/des/des_locl.h> 5755009Sshin#include <crypto/des/spr.h> 5855009Sshin 5991671Sume/* char *libdes_version="libdes v 3.24 - 20-Apr-1996 - eay"; */ /* wrong */ 6091671Sume/* char *DES_version="DES part of SSLeay 0.6.4 30-Aug-1996"; */ 6155009Sshin 6291671Sumechar *des_options(void) 6391671Sume { 6491671Sume static int init=1; 6591671Sume static char buf[32]; 6691671Sume 6791671Sume if (init) 6891671Sume { 6991671Sume const char *ptr,*unroll,*risc,*size; 7091671Sume 7155009Sshin#ifdef DES_PTR 7291671Sume ptr="ptr"; 7355009Sshin#else 7491671Sume ptr="idx"; 7555009Sshin#endif 7691671Sume#if defined(DES_RISC1) || defined(DES_RISC2) 7791671Sume#ifdef DES_RISC1 7891671Sume risc="risc1"; 7991671Sume#endif 8091671Sume#ifdef DES_RISC2 8191671Sume risc="risc2"; 8291671Sume#endif 8391671Sume#else 8491671Sume risc="cisc"; 8591671Sume#endif 8691671Sume#ifdef DES_UNROLL 8791671Sume unroll="16"; 8891671Sume#else 8991671Sume unroll="4"; 9091671Sume#endif 9191671Sume if (sizeof(DES_LONG) != sizeof(long)) 9291671Sume size="int"; 9391671Sume else 9491671Sume size="long"; 9591671Sume sprintf(buf,"des(%s,%s,%s,%s)",ptr,risc,unroll,size); 9691671Sume init=0; 9791671Sume } 9891671Sume return(buf); 9991671Sume} 10091671Sumevoid des_ecb_encrypt(des_cblock *input, des_cblock *output, 10191671Sume des_key_schedule ks, int enc) 10291671Sume{ 10355009Sshin register DES_LONG l; 10455009Sshin DES_LONG ll[2]; 10591671Sume const unsigned char *in=&(*input)[0]; 10691671Sume unsigned char *out = &(*output)[0]; 10755009Sshin 10855009Sshin c2l(in,l); ll[0]=l; 10955009Sshin c2l(in,l); ll[1]=l; 11091671Sume des_encrypt1(ll,ks,enc); 11155009Sshin l=ll[0]; l2c(l,out); 11255009Sshin l=ll[1]; l2c(l,out); 11355009Sshin l=ll[0]=ll[1]=0; 11491671Sume} 11555009Sshin 11691671Sumevoid des_ecb3_encrypt(des_cblock *input, des_cblock *output, 11791671Sume des_key_schedule ks1, des_key_schedule ks2, des_key_schedule ks3, 11891671Sume int enc) 11991671Sume{ 12091671Sume register DES_LONG l0,l1; 12191671Sume DES_LONG ll[2]; 12291671Sume const unsigned char *in = &(*input)[0]; 12391671Sume unsigned char *out = &(*output)[0]; 12491671Sume 12591671Sume c2l(in,l0); 12691671Sume c2l(in,l1); 12791671Sume ll[0]=l0; 12891671Sume ll[1]=l1; 12955009Sshin 13091671Sume if (enc) 13191671Sume des_encrypt3(ll,ks1,ks2,ks3); 13255009Sshin else 13391671Sume des_decrypt3(ll,ks1,ks2,ks3); 13455009Sshin 13591671Sume l0=ll[0]; 13691671Sume l1=ll[1]; 13791671Sume l2c(l0,out); 13891671Sume l2c(l1,out); 13991671Sume} 140