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 "sha2.h"
00019 #include "sha1.h"
00020 #include "md5.h"
00021 #include "ripemd160.h"
00022 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00031 #ifdef WIN32
00032  #ifdef CRYPTO_EXPORTS
00033    #define extern   extern __declspec(dllexport)
00034  #else
00035    #define extern   extern __declspec(dllimport)
00036  #endif
00037 #endif
00038 
00042 extern const int hasher_lengths[CRYPTO_HASH_COUNT][2];
00043 
00046 #define HASHER_MAX_DIGEST_SIZE\
00047   ( max(\
00048      max(\
00049       RIPEMD160_DIGEST_SIZE,\
00050       MD5_DIGEST_SIZE\
00051      ),\
00052      max(\
00053       SHA1_DIGEST_SIZE,\
00054       SHA2_DIGEST_SIZE\
00055      )\
00056     )\
00057   )
00058 #define HASHER_MAX_CTX_SIZE\
00059   ( max(\
00060      max(\
00061       sizeof(ripemd160_context),\
00062       sizeof(md5_context)\
00063      ),\
00064      max(\
00065       sizeof(sha2_context),\
00066       sizeof(sha1_context)\
00067      )\
00068     )\
00069   )
00070 
00071 typedef enum {
00072   HASHER_OK,
00073   HASHER_BAD_HASH_ALGO,
00074   HASHER_NULL_POINTER
00075 } hasher_retcode;
00076 
00077 typedef struct {
00079 #if (!defined LINUX32) && (!defined WIN32)
00080   private:
00081     md5_context md5;
00082     sha1_context sha1;
00083     sha2_context sha2;
00084     ripemd160_context ripemd160;
00085   public:
00086 #endif
00087   
00095   void (*init_)(void*);
00096 
00104   void (*update_)(void*, const uns8*, uns32);
00105 
00113   void (*final_)(uns8*, void*);
00114 
00115 #define hasher_t void
00116 
00119   void (*init)(hasher_t *H);
00120   
00124   void (*update)(hasher_t *H, const uns8 *data, uns32 len);
00125 
00129   void (*final)(hasher_t *H, uns8 *d);
00130 #undef hasher_t
00131 
00134   void *ctx;
00135 
00139   int len;
00140 
00143   hash_t algo;
00144 
00148   hasher_retcode err;
00149 } hasher_t;
00150 
00154 extern void hasher_init  (hasher_t *H);
00155 
00163 extern void hasher_update(hasher_t *H, const uns8 *data, uns32 len);
00164 
00169 extern void hasher_final (hasher_t *H, uns8 *result);
00170 
00177 extern hasher_retcode hasher_setup(hasher_t *H, const char *algo);
00178 
00183 extern hasher_retcode hasher_teardown(hasher_t *H);
00184 
00188 extern const char* hasher_ret_msg(hasher_retcode c);
00189 
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193 
00194 #ifdef WIN32
00195   #undef extern
00196 #endif
00197 
00198 #endif


Confidential