xref: /netbsd-src/sys/crypto/blowfish/bf_ecb.c (revision 95e1ffb15694e54f29f8baaa4232152b703c2a5a)
1*95e1ffb1Schristos /*	$NetBSD: bf_ecb.c,v 1.3 2005/12/11 12:20:48 christos Exp $	*/
2e77423d9Sthorpej 
3e77423d9Sthorpej /* crypto/bf/bf_ecb.c */
4e77423d9Sthorpej /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5e77423d9Sthorpej  * All rights reserved.
6e77423d9Sthorpej  *
7e77423d9Sthorpej  * This package is an SSL implementation written
8e77423d9Sthorpej  * by Eric Young (eay@cryptsoft.com).
9e77423d9Sthorpej  * The implementation was written so as to conform with Netscapes SSL.
10e77423d9Sthorpej  *
11e77423d9Sthorpej  * This library is free for commercial and non-commercial use as long as
12e77423d9Sthorpej  * the following conditions are aheared to.  The following conditions
13e77423d9Sthorpej  * apply to all code found in this distribution, be it the RC4, RSA,
14e77423d9Sthorpej  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
15e77423d9Sthorpej  * included with this distribution is covered by the same copyright terms
16e77423d9Sthorpej  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17e77423d9Sthorpej  *
18e77423d9Sthorpej  * Copyright remains Eric Young's, and as such any Copyright notices in
19e77423d9Sthorpej  * the code are not to be removed.
20e77423d9Sthorpej  * If this package is used in a product, Eric Young should be given attribution
21e77423d9Sthorpej  * as the author of the parts of the library used.
22e77423d9Sthorpej  * This can be in the form of a textual message at program startup or
23e77423d9Sthorpej  * in documentation (online or textual) provided with the package.
24e77423d9Sthorpej  *
25e77423d9Sthorpej  * Redistribution and use in source and binary forms, with or without
26e77423d9Sthorpej  * modification, are permitted provided that the following conditions
27e77423d9Sthorpej  * are met:
28e77423d9Sthorpej  * 1. Redistributions of source code must retain the copyright
29e77423d9Sthorpej  *    notice, this list of conditions and the following disclaimer.
30e77423d9Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
31e77423d9Sthorpej  *    notice, this list of conditions and the following disclaimer in the
32e77423d9Sthorpej  *    documentation and/or other materials provided with the distribution.
33e77423d9Sthorpej  * 3. All advertising materials mentioning features or use of this software
34e77423d9Sthorpej  *    must display the following acknowledgement:
35e77423d9Sthorpej  *    "This product includes cryptographic software written by
36e77423d9Sthorpej  *     Eric Young (eay@cryptsoft.com)"
37e77423d9Sthorpej  *    The word 'cryptographic' can be left out if the rouines from the library
38e77423d9Sthorpej  *    being used are not cryptographic related :-).
39e77423d9Sthorpej  * 4. If you include any Windows specific code (or a derivative thereof) from
40e77423d9Sthorpej  *    the apps directory (application code) you must include an acknowledgement:
41e77423d9Sthorpej  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42e77423d9Sthorpej  *
43e77423d9Sthorpej  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44e77423d9Sthorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45e77423d9Sthorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46e77423d9Sthorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47e77423d9Sthorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48e77423d9Sthorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49e77423d9Sthorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50e77423d9Sthorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51e77423d9Sthorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52e77423d9Sthorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53e77423d9Sthorpej  * SUCH DAMAGE.
54e77423d9Sthorpej  *
55e77423d9Sthorpej  * The licence and distribution terms for any publically available version or
56e77423d9Sthorpej  * derivative of this code cannot be changed.  i.e. this code cannot simply be
57e77423d9Sthorpej  * copied and put under another distribution licence
58e77423d9Sthorpej  * [including the GNU Public Licence.]
59e77423d9Sthorpej  */
60e77423d9Sthorpej 
61e77423d9Sthorpej #include <sys/cdefs.h>
62*95e1ffb1Schristos __KERNEL_RCSID(0, "$NetBSD: bf_ecb.c,v 1.3 2005/12/11 12:20:48 christos Exp $");
63e77423d9Sthorpej 
64e77423d9Sthorpej #include <sys/types.h>
65e77423d9Sthorpej 
66e77423d9Sthorpej #include <crypto/blowfish/blowfish.h>
67e77423d9Sthorpej #include "bf_locl.h"
68e77423d9Sthorpej 
69e77423d9Sthorpej /* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
70e77423d9Sthorpej  * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
71e77423d9Sthorpej  * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
72e77423d9Sthorpej  */
73e77423d9Sthorpej 
BF_ecb_encrypt(const unsigned char * in,unsigned char * out,const BF_KEY * key,int encrypt)74e77423d9Sthorpej void BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
75e77423d9Sthorpej 	     const BF_KEY *key, int encrypt)
76e77423d9Sthorpej 	{
77e77423d9Sthorpej 	BF_LONG l,d[2];
78e77423d9Sthorpej 
79e77423d9Sthorpej 	n2l(in,l); d[0]=l;
80e77423d9Sthorpej 	n2l(in,l); d[1]=l;
81e77423d9Sthorpej 	if (encrypt)
82e77423d9Sthorpej 		BF_encrypt(d,key);
83e77423d9Sthorpej 	else
84e77423d9Sthorpej 		BF_decrypt(d,key);
85e77423d9Sthorpej 	l=d[0]; l2n(l,out);
86e77423d9Sthorpej 	l=d[1]; l2n(l,out);
87e77423d9Sthorpej 	l=d[0]=d[1]=0;
88e77423d9Sthorpej 	}
89e77423d9Sthorpej 
90