e_bf.c revision 160814
1130391Sle/* crypto/evp/e_bf.c */
2190507Slulf/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3190507Slulf * All rights reserved.
4190507Slulf *
5130391Sle * This package is an SSL implementation written
6152631Sle * by Eric Young (eay@cryptsoft.com).
7152631Sle * The implementation was written so as to conform with Netscapes SSL.
8152631Sle *
9152631Sle * This library is free for commercial and non-commercial use as long as
10152631Sle * the following conditions are aheared to.  The following conditions
11130391Sle * apply to all code found in this distribution, be it the RC4, RSA,
12130391Sle * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
13130391Sle * included with this distribution is covered by the same copyright terms
14130391Sle * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15130391Sle *
16130391Sle * Copyright remains Eric Young's, and as such any Copyright notices in
17130391Sle * the code are not to be removed.
18130391Sle * If this package is used in a product, Eric Young should be given attribution
19152631Sle * as the author of the parts of the library used.
20130391Sle * This can be in the form of a textual message at program startup or
21130391Sle * in documentation (online or textual) provided with the package.
22130391Sle *
23130391Sle * Redistribution and use in source and binary forms, with or without
24130391Sle * modification, are permitted provided that the following conditions
25130391Sle * are met:
26130391Sle * 1. Redistributions of source code must retain the copyright
27130391Sle *    notice, this list of conditions and the following disclaimer.
28130391Sle * 2. Redistributions in binary form must reproduce the above copyright
29130391Sle *    notice, this list of conditions and the following disclaimer in the
30130391Sle *    documentation and/or other materials provided with the distribution.
31130391Sle * 3. All advertising materials mentioning features or use of this software
32130391Sle *    must display the following acknowledgement:
33130391Sle *    "This product includes cryptographic software written by
34130391Sle *     Eric Young (eay@cryptsoft.com)"
35130391Sle *    The word 'cryptographic' can be left out if the rouines from the library
36130391Sle *    being used are not cryptographic related :-).
37130391Sle * 4. If you include any Windows specific code (or a derivative thereof) from
38130391Sle *    the apps directory (application code) you must include an acknowledgement:
39130391Sle *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40130391Sle *
41130391Sle * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42130391Sle * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43130391Sle * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44130391Sle * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45130391Sle * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46130391Sle * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47130391Sle * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48190507Slulf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49130391Sle * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50130391Sle * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51130391Sle * SUCH DAMAGE.
52130391Sle *
53130391Sle * The licence and distribution terms for any publically available version or
54130391Sle * derivative of this code cannot be changed.  i.e. this code cannot simply be
55130391Sle * copied and put under another distribution licence
56130391Sle * [including the GNU Public Licence.]
57130391Sle */
58130391Sle
59130391Sle#include <stdio.h>
60190507Slulf#include "cryptlib.h"
61190507Slulf#ifndef OPENSSL_NO_BF
62130391Sle#include <openssl/evp.h>
63190507Slulf#include "evp_locl.h"
64190884Slulf#include <openssl/objects.h>
65130391Sle#include <openssl/blowfish.h>
66130391Sle
67152616Slestatic int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68190507Slulf		       const unsigned char *iv, int enc);
69138110Sle
70130391Sletypedef struct
71190507Slulf	{
72152616Sle	BF_KEY ks;
73157052Sle	} EVP_BF_KEY;
74130391Sle
75130391Sle#define data(ctx)	EVP_C_DATA(EVP_BF_KEY,ctx)
76138112Sle
77130391SleIMPLEMENT_BLOCK_CIPHER(bf, ks, BF, EVP_BF_KEY, NID_bf, 8, 16, 8, 64,
78130391Sle			EVP_CIPH_VARIABLE_LENGTH, bf_init_key, NULL,
79190507Slulf			EVP_CIPHER_set_asn1_iv, EVP_CIPHER_get_asn1_iv, NULL)
80130391Sle
81130391Slestatic int bf_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
82130391Sle		       const unsigned char *iv, int enc)
83190507Slulf	{
84190507Slulf	BF_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),key);
85190507Slulf	return 1;
86190507Slulf	}
87204665Slulf
88204665Slulf#endif
89190507Slulf