Back to index

python-bcrypt  0.2
pybc_blf.h
Go to the documentation of this file.
00001 /* $OpenBSD: blf.h,v 1.6 2002/02/16 21:27:17 millert Exp $ */
00002 /*
00003  * Blowfish - a fast block cipher designed by Bruce Schneier
00004  *
00005  * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. All advertising materials mentioning features or use of this software
00017  *    must display the following acknowledgement:
00018  *      This product includes software developed by Niels Provos.
00019  * 4. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00023  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00024  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00025  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00027  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00028  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00029  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00030  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00031  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  */
00033 
00034 #ifndef _PYBC_BLF_H_
00035 #define _PYBC_BLF_H_
00036 
00037 #if defined(_MSC_VER)
00038 typedef unsigned __int8            u_int8_t;
00039 typedef unsigned __int16    u_int16_t;
00040 typedef unsigned __int32    u_int32_t;
00041 #endif
00042 
00043 /* Schneier specifies a maximum key length of 56 bytes.
00044  * This ensures that every key bit affects every cipher
00045  * bit.  However, the subkeys can hold up to 72 bytes.
00046  * Warning: For normal blowfish encryption only 56 bytes
00047  * of the key affect all cipherbits.
00048  */
00049 
00050 #define BLF_N 16                   /* Number of Subkeys */
00051 #define BLF_MAXKEYLEN ((BLF_N-2)*4)       /* 448 bits */
00052 
00053 /* Blowfish context */
00054 typedef struct BlowfishContext {
00055        u_int32_t S[4][256]; /* S-Boxes */
00056        u_int32_t P[BLF_N + 2];     /* Subkeys */
00057 } pybc_blf_ctx;
00058 
00059 /* Raw access to customized Blowfish
00060  *     blf_key is just:
00061  *     Blowfish_initstate( state )
00062  *     Blowfish_expand0state( state, key, keylen )
00063  */
00064 
00065 void pybc_Blowfish_initstate(pybc_blf_ctx *);
00066 void pybc_Blowfish_expand0state(pybc_blf_ctx *, const u_int8_t *, u_int16_t);
00067 void pybc_Blowfish_expandstate(pybc_blf_ctx *, const u_int8_t *, u_int16_t,
00068     const u_int8_t *, u_int16_t);
00069 
00070 /* Standard Blowfish */
00071 
00072 void pybc_blf_enc(pybc_blf_ctx *, u_int32_t *, u_int16_t);
00073 
00074 /* Converts u_int8_t to u_int32_t */
00075 u_int32_t pybc_Blowfish_stream2word(const u_int8_t *, u_int16_t, u_int16_t *);
00076 
00077 #endif