147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* crypto/bf/bf_ecb.c */
247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * All rights reserved.
447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This package is an SSL implementation written
647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * by Eric Young (eay@cryptsoft.com).
747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * The implementation was written so as to conform with Netscapes SSL.
847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This library is free for commercial and non-commercial use as long as
1047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * the following conditions are aheared to.  The following conditions
1147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * apply to all code found in this distribution, be it the RC4, RSA,
1247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
1347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * included with this distribution is covered by the same copyright terms
1447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
1647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * Copyright remains Eric Young's, and as such any Copyright notices in
1747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * the code are not to be removed.
1847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * If this package is used in a product, Eric Young should be given attribution
1947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * as the author of the parts of the library used.
2047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * This can be in the form of a textual message at program startup or
2147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * in documentation (online or textual) provided with the package.
2247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
2347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * Redistribution and use in source and binary forms, with or without
2447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * modification, are permitted provided that the following conditions
2547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * are met:
2647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 1. Redistributions of source code must retain the copyright
2747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    notice, this list of conditions and the following disclaimer.
2847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 2. Redistributions in binary form must reproduce the above copyright
2947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    notice, this list of conditions and the following disclaimer in the
3047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    documentation and/or other materials provided with the distribution.
3147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 3. All advertising materials mentioning features or use of this software
3247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    must display the following acknowledgement:
3347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    "This product includes cryptographic software written by
3447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *     Eric Young (eay@cryptsoft.com)"
3547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    The word 'cryptographic' can be left out if the rouines from the library
3647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    being used are not cryptographic related :-).
3747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * 4. If you include any Windows specific code (or a derivative thereof) from
3847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    the apps directory (application code) you must include an acknowledgement:
3947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
4047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
4147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
4247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
5047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * SUCH DAMAGE.
5247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom *
5347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * The licence and distribution terms for any publically available version or
5447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * derivative of this code cannot be changed.  i.e. this code cannot simply be
5547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * copied and put under another distribution licence
5647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * [including the GNU Public Licence.]
5747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
5847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
5947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#include <openssl/blowfish.h>
6047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#include "bf_locl.h"
6147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#include <openssl/opensslv.h>
6247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
6347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom/* Blowfish as implemented from 'Blowfish: Springer-Verlag paper'
6447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * (From LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION,
6547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
6647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom */
6747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
6847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstromconst char BF_version[]="Blowfish" OPENSSL_VERSION_PTEXT;
6947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
7047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstromconst char *BF_options(void)
7147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	{
7247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#ifdef BF_PTR
7347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	return("blowfish(ptr)");
7447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#elif defined(BF_PTR2)
7547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	return("blowfish(ptr2)");
7647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#else
7747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	return("blowfish(idx)");
7847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom#endif
7947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	}
8047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
8147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstromvoid BF_ecb_encrypt(const unsigned char *in, unsigned char *out,
8247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	     const BF_KEY *key, int encrypt)
8347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	{
8447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	BF_LONG l,d[2];
8547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
8647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	n2l(in,l); d[0]=l;
8747e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	n2l(in,l); d[1]=l;
8847e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	if (encrypt)
8947e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		BF_encrypt(d,key);
9047e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	else
9147e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom		BF_decrypt(d,key);
9247e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	l=d[0]; l2n(l,out);
9347e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	l=d[1]; l2n(l,out);
9447e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	l=d[0]=d[1]=0;
9547e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom	}
9647e6a167f114f4c4b0bae4bce4ba1c4f539e0dc1Brian Carlstrom
97