Main Page   Compound List   File List   Compound Members   File Members  

hasher.h

Go to the documentation of this file.
00001 
00012 #ifndef HASHER_H
00013 #define HASHER_H
00014 
00015 #include <string.h>
00016 #include <stdlib.h>
00017 
00018 #include "sha256.h"
00019 #include "sha512.h"
00020 #include "sha1.h"
00021 #include "md5.h"
00022 #include "ripemd160.h"
00023 
00026 #ifdef __cplusplus
00027 extern "C" {
00028 #endif
00029 
00032 #ifdef WIN32
00033  #ifdef CRYPTO_EXPORTS
00034    #define extern   extern __declspec(dllexport)
00035  #else
00036    #define extern   extern __declspec(dllimport)
00037  #endif
00038 #endif
00039 
00043 extern const int hasher_lengths[CRYPTO_HASH_COUNT][2];
00044 
00047 #define HASHER_MAX_DIGEST_SIZE\
00048   ( max(\
00049      SHA256_DIGEST_SIZE,\
00050      max(\
00051       max(\
00052        RIPEMD160_DIGEST_SIZE,\
00053        MD5_DIGEST_SIZE\
00054       ),\
00055       max(\
00056        SHA1_DIGEST_SIZE,\
00057        SHA512_DIGEST_SIZE\
00058       )\
00059      )\
00060     )\
00061   )
00062 #define HASHER_MAX_CTX_SIZE\
00063   ( max(\
00064      sizeof(sha256_context),\
00065      max(\
00066       max(\
00067        sizeof(ripemd160_context),\
00068        sizeof(md5_context)\
00069       ),\
00070       max(\
00071        sizeof(sha512_context),\
00072        sizeof(sha1_context)\
00073       )\
00074      )\
00075     )\
00076   )
00077 
00078 typedef enum {
00079   HASHER_OK,
00080   HASHER_BAD_HASH_ALGO,
00081   HASHER_NULL_POINTER
00082 } hasher_retcode;
00083 
00084 typedef struct {
00086 #if (!defined LINUX32) && (!defined WIN32)
00087   private:
00088     md5_context md5;
00089     sha1_context sha1;
00090     sha256_context sha256;
00091     sha512_context sha512;
00092     ripemd160_context ripemd160;
00093   public:
00094 #endif
00095   
00103   void (*init_)(void*);
00104 
00112   void (*update_)(void*, const uns8*, uns32);
00113 
00121   void (*final_)(uns8*, void*);
00122 
00123 #define hasher_t void
00124 
00127   void (*init)(hasher_t *H);
00128   
00132   void (*update)(hasher_t *H, const uns8 *data, uns32 len);
00133 
00137   void (*final)(hasher_t *H, uns8 *d);
00138 #undef hasher_t
00139 
00142   void *ctx;
00143 
00147   int len;
00148 
00151   hash_t algo;
00152 
00156   hasher_retcode err;
00157 } hasher_t;
00158 
00162 extern void hasher_init  (hasher_t *H);
00163 
00171 extern void hasher_update(hasher_t *H, const uns8 *data, uns32 len);
00172 
00177 extern void hasher_final (hasher_t *H, uns8 *result);
00178 
00185 extern hasher_retcode hasher_setup(hasher_t *H, const char *algo);
00186 
00191 extern hasher_retcode hasher_teardown(hasher_t *H);
00192 
00196 extern const char* hasher_ret_msg(hasher_retcode c);
00197 
00198 #ifdef __cplusplus
00199 }
00200 #endif
00201 
00202 #ifdef WIN32
00203   #undef extern
00204 #endif
00205 
00206 #endif


GPL