- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List

# Blowfish.h

    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 /*
    00035  * Modified by <hongli@phusion.nl> on 2009-10-24:
    00036  *
    00037  *   - Made it so that this header cannot be included directly.
    00038  */
    00039
    00040 #ifndef IN_PASSENGER_BCRYPT_C
    00041         #error "Do not include this header directly. Use BCrypt.h instead!"
    00042 #endif
    00043
    00044 #ifndef _PASSENGER_BLOWFISH_H_
    00045 #define _PASSENGER_BLOWFISH_H_
    00046
    00047 /* Add this type so we'll compile nicely on Solaris.
    00048    Thanks to Jeremy LaTrasse and the Twitter crew. */
    00049 #ifdef __sun
    00050         #define u_int8_t uint8_t
    00051         #define u_int16_t uint16_t
    00052         #define u_int32_t uint32_t
    00053         #define u_int64_t uint64_t
    00054 #endif
    00055
    00056 // Imported from pwd.h. <coda.hale@gmail.com>
    00057 #define _PASSWORD_LEN           128     /* max length, not counting NUL */
    00058
    00059 /* Schneier specifies a maximum key length of 56 bytes.
    00060  * This ensures that every key bit affects every cipher
    00061  * bit.  However, the subkeys can hold up to 72 bytes.
    00062  * Warning: For normal blowfish encryption only 56 bytes
    00063  * of the key affect all cipherbits.
    00064  */
    00065
    00066 #define BLF_N   16                      /* Number of Subkeys */
    00067 #define BLF_MAXKEYLEN ((BLF_N-2)*4)     /* 448 bits */
    00068
    00069 /* Blowfish context */
    00070 typedef struct BlowfishContext {
    00071         u_int32_t S[4][256];    /* S-Boxes */
    00072         u_int32_t P[BLF_N + 2]; /* Subkeys */
    00073 } blf_ctx;
    00074
    00075 /* Raw access to customized Blowfish
    00076  *      blf_key is just:
    00077  *      Blowfish_initstate( state )
    00078  *      Blowfish_expand0state( state, key, keylen )
    00079  */
    00080
    00081 void Blowfish_encipher(blf_ctx *, u_int32_t *, u_int32_t *);
    00082 void Blowfish_decipher(blf_ctx *, u_int32_t *, u_int32_t *);
    00083 void Blowfish_initstate(blf_ctx *);
    00084 void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
    00085 void Blowfish_expandstate
    00086 (blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
    00087
    00088 /* Standard Blowfish */
    00089
    00090 void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
    00091 void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
    00092 void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
    00093
    00094 void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
    00095 void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
    00096
    00097 void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
    00098 void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
    00099
    00100 /* Converts u_int8_t to u_int32_t */
    00101 u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *);
    00102
    00103 #endif /* _PASSENGER_BLOWFISH_H_ */