1121072Sume/* crypto/bf/bf_ecb.c */
2121072Sume/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3121072Sume * All rights reserved.
4121072Sume *
5121072Sume * This package is an SSL implementation written
6121072Sume * by Eric Young (eay@cryptsoft.com).
7121072Sume * The implementation was written so as to conform with Netscapes SSL.
8121072Sume *
9121072Sume * This library is free for commercial and non-commercial use as long as
10121072Sume * the following conditions are aheared to.  The following conditions
11121072Sume * apply to all code found in this distribution, be it the RC4, RSA,
12121072Sume * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13121072Sume * included with this distribution is covered by the same copyright terms
14121072Sume * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15121072Sume *
16121072Sume * Copyright remains Eric Young's, and as such any Copyright notices in
17121072Sume * the code are not to be removed.
18121072Sume * If this package is used in a product, Eric Young should be given attribution
19121072Sume * as the author of the parts of the library used.
20121072Sume * This can be in the form of a textual message at program startup or
21121072Sume * in documentation (online or textual) provided with the package.
22121072Sume *
23121072Sume * Redistribution and use in source and binary forms, with or without
24121072Sume * modification, are permitted provided that the following conditions
25121072Sume * are met:
26121072Sume * 1. Redistributions of source code must retain the copyright
27121072Sume *    notice, this list of conditions and the following disclaimer.
28121072Sume * 2. Redistributions in binary form must reproduce the above copyright
29121072Sume *    notice, this list of conditions and the following disclaimer in the
30121072Sume *    documentation and/or other materials provided with the distribution.
31121072Sume * 3. All advertising materials mentioning features or use of this software
32121072Sume *    must display the following acknowledgement:
33121072Sume *    "This product includes cryptographic software written by
34121072Sume *     Eric Young (eay@cryptsoft.com)"
35121072Sume *    The word 'cryptographic' can be left out if the rouines from the library
36121072Sume *    being used are not cryptographic related :-).
37121072Sume * 4. If you include any Windows specific code (or a derivative thereof) from
38121072Sume *    the apps directory (application code) you must include an acknowledgement:
39121072Sume *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40121072Sume *
41121072Sume * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42121072Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43121072Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44121072Sume * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45121072Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46121072Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47121072Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48121072Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49121072Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50121072Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51121072Sume * SUCH DAMAGE.
52121072Sume *
53121072Sume * The licence and distribution terms for any publically available version or
54121072Sume * derivative of this code cannot be changed.  i.e. this code cannot simply be
55121072Sume * copied and put under another distribution licence
56121072Sume * [including the GNU Public Licence.]
57121072Sume */
58121072Sume
59121072Sume#include <sys/cdefs.h>
60121072Sume__FBSDID("$FreeBSD$");
61121072Sume
62121072Sume#include <sys/types.h>
63121072Sume#include <crypto/blowfish/blowfish.h>
64121072Sume#include <crypto/blowfish/bf_locl.h>
65121072Sume
66121072Sume/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
67121072Sume * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
68121072Sume * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
69121072Sume */
70121072Sume
71121072Sumevoid BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
72121072Sume	     BF_KEY *key, int encrypt)
73121072Sume	{
74121072Sume	BF_LONG l,d[2];
75121072Sume
76121072Sume	n2l(in,l); d[0]=l;
77121072Sume	n2l(in,l); d[1]=l;
78121072Sume	if (encrypt)
79121072Sume		BF_encrypt(d,key);
80121072Sume	else
81121072Sume		BF_decrypt(d,key);
82121072Sume	l=d[0]; l2n(l,out);
83121072Sume	l=d[1]; l2n(l,out);
84121072Sume	l=d[0]=d[1]=0;
85121072Sume	}
86121072Sume
87