whirlpool.h

Go to the documentation of this file.
00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org>
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 2
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
00016 
00017 /*!
00018  * @defgroup whirlpool Whirlpool hash function
00019  *
00020  * WHIRLPOOL is a cryptographic hash function designed after the Square block
00021  * cipher. WHIRLPOOL is a Miyaguchi-Preneel construction based on a
00022  * substantially modified Advanced Encryption Standard (AES). Given a message
00023  * less than 2^256 bits in length, it returns a 512-bit message digest.
00024  *
00025  * The whirlpool_init() function initializes the hash context pointed to by
00026  * context. After initialization input can be added to the transform routine
00027  * using whirlpool_add(). Once all bytes have been added the transform has to be
00028  * finished by calling whilrpool_finalize().
00029  *
00030  * An application should not directly use the internal whirlpool_transform()
00031  * function, but always use whirlpool_add().
00032  *
00033  * The whirlpool_digest() function combines the procedure explained above for a
00034  * single string and returns the digest in hexadecimal notation.
00035  *
00036  * @{
00037  */
00038 
00039 #ifndef _LUCID_WHIRLPOOL_H
00040 #define _LUCID_WHIRLPOOL_H
00041 
00042 #include <stdint.h>
00043 
00044 /*! @brief number of bytes in the digest */
00045 #define DIGESTBYTES 64
00046 
00047 /*! @brief number of bits in the digest */
00048 #define DIGESTBITS  (8*DIGESTBYTES) /* 512 */
00049 
00050 
00051 /*! @brief number of bytes in the input buffer */
00052 #define WBLOCKBYTES 64
00053 
00054 /*! @brief number of bits in the input buffer */
00055 #define WBLOCKBITS  (8*WBLOCKBYTES) /* 512 */
00056 
00057 
00058 /*! @brief number of hashed bytes */
00059 #define LENGTHBYTES 32
00060 
00061 /*! @brief number of hashed bits */
00062 #define LENGTHBITS  (8*LENGTHBYTES) /* 256 */
00063 
00064 /*!
00065  * @brief dynamic whirlpool state data
00066  *
00067  * This struct is used to keep track of the whirlpool transform, i.e. its
00068  * hashing state, input buffer, number of hashed bits, etc.
00069  */
00070 typedef struct {
00071         uint8_t  len[LENGTHBYTES];    /*!< global number of hashed bits */
00072         uint8_t  buf[WBLOCKBYTES];    /*!< buffer of data to hash */
00073         int      bits;                /*!< current number of bits on the buffer */
00074         int      pos;                 /*!< current (possibly incomplete) byte slot on the buffer */
00075         uint64_t hash[DIGESTBYTES/8]; /*!< the hashing state */
00076 } whirlpool_t;
00077 
00078 /*!
00079  * @brief internal transform routine
00080  *
00081  * @param[in] context whirlpool state context
00082  */
00083 void whirlpool_transform(whirlpool_t * const context);
00084 
00085 /*!
00086  * @brief initialize whirlpool state context
00087  *
00088  * @param[in] context whirlpool state context
00089  */
00090 void whirlpool_init(whirlpool_t * const context);
00091 
00092 /*!
00093  * @brief finalize whirlpool transformation
00094  *
00095  * @param[in]  context whirlpool state context
00096  * @param[out] result  string to store digest
00097  */
00098 void whirlpool_finalize(whirlpool_t * const context, unsigned char * const result);
00099 
00100 /*!
00101  * @brief add bytes to the transform routine
00102  *
00103  * @param[in] context whirlpool state context
00104  * @param[in] src     source string
00105  * @param[in] bits    number of bits in the source string
00106  */
00107 void whirlpool_add(whirlpool_t * const context,
00108                    const unsigned char * const src, unsigned long bits);
00109 
00110 /*!
00111  * @brief create digest from string
00112  *
00113  * @param[in] str source string
00114  *
00115  * @return digest string (memory obtained by malloc(3))
00116  *
00117  * @note The caller should free obtained memory using free(3)
00118  *
00119  * @see malloc(3)
00120  * @see free(3)
00121  */
00122 char *whirlpool_digest(const char *str);
00123 
00124 #endif
00125 
00126 /*! @} str */

Generated on Tue Jun 19 20:38:27 2007 for lucid by  doxygen 1.5.2