00001 /* 00002 * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by Niels Provos. 00016 * 4. The name of the author may not be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00020 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00021 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00022 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 00023 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 00024 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00028 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 /* 00032 * Modified by <hongli@phusion.nl> on 2009-10-24: 00033 * 00034 * - Wrapped into C++ namespace. 00035 * - Changed some types (e.g. u_int8_t to uint8_t as defined in stdint.h) 00036 * for easier compilation. 00037 * - Moved some macros to the .c file. 00038 */ 00039 00040 #ifndef _PASSENGER_BCRYPT_H_ 00041 #define _PASSENGER_BCRYPT_H_ 00042 00043 #include <stdint.h> 00044 00045 #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ 00046 #define BCRYPT_SALT_OUTPUT_SIZE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1) 00047 #define BCRYPT_OUTPUT_SIZE 128 00048 00049 /* 00050 * Given a logarithmic cost parameter, generates a salt for use with bcrypt(). 00051 * 00052 * output: the computed salt will be stored here. This buffer must be 00053 * at least BCRYPT_SALT_OUTPUT_SIZE bytes. The result will be 00054 * null-terminated. 00055 * log_rounds: the logarithmic cost. 00056 * rseed: a seed of BCRYPT_MAXSALT bytes. Should be obtained from a 00057 * cryptographically secure random source. 00058 * Returns: output 00059 */ 00060 char *bcrypt_gensalt(char *output, unsigned int log_rounds, uint8_t *rseed); 00061 00062 /* 00063 * Given a secret and a salt, generates a salted hash (which you can then store safely). 00064 * 00065 * output: the computed salted hash will be stored here. This buffer must 00066 * be at least BCRYPT_OUTPUT_SIZE bytes, and will become null-terminated. 00067 * key: A null-terminated secret. 00068 * salt: The salt, as generated by bcrypt_gensalt(). 00069 * Returns: output on success, NULL on error. 00070 */ 00071 char *bcrypt(char *output, const char *key, const char *salt); 00072 00073 #endif /* _PASSENGER_BCRYPT_H_ */