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 "sha384.h"
00020 #include "sha512.h"
00021 #include "sha1.h"
00022 #include "md5.h"
00023 #include "ripemd160.h"
00024
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030
00033 #ifdef WIN32
00034 #ifdef CRYPTO_EXPORTS
00035 #define extern extern __declspec(dllexport)
00036 #else
00037 #define extern extern __declspec(dllimport)
00038 #endif
00039 #endif
00040
00044 extern const int hasher_lengths[CRYPTO_HASH_COUNT][2];
00045
00048 #define HASHER_MAX_DIGEST_SIZE\
00049 ( max(\
00050 max(\
00051 SHA256_DIGEST_SIZE,\
00052 SHA384_DIGEST_SIZE\
00053 ),\
00054 max(\
00055 max(\
00056 RIPEMD160_DIGEST_SIZE,\
00057 MD5_DIGEST_SIZE\
00058 ),\
00059 max(\
00060 SHA1_DIGEST_SIZE,\
00061 SHA512_DIGEST_SIZE\
00062 )\
00063 )\
00064 )\
00065 )
00066 #define HASHER_MAX_CTX_SIZE\
00067 ( max(\
00068 max(\
00069 sizeof(sha256_context),\
00070 sizeof(sha384_context)\
00071 ),\
00072 max(\
00073 max(\
00074 sizeof(ripemd160_context),\
00075 sizeof(md5_context)\
00076 ),\
00077 max(\
00078 sizeof(sha512_context),\
00079 sizeof(sha1_context)\
00080 )\
00081 )\
00082 )\
00083 )
00084
00085 typedef enum {
00086 HASHER_OK,
00087 HASHER_BAD_HASH_ALGO,
00088 HASHER_NULL_POINTER
00089 } hasher_retcode;
00090
00091 typedef struct {
00093 #if (!defined LINUX32) && (!defined WIN32)
00094 private:
00095 md5_context md5;
00096 sha1_context sha1;
00097 sha256_context sha256;
00098 sha384_context sha384;
00099 sha512_context sha512;
00100 ripemd160_context ripemd160;
00101 public:
00102 #endif
00103
00113 void (*init_)(void*);
00114
00124 void (*update_)(void*, const uns8*, uns32);
00125
00135 void (*final_)(uns8*, void*);
00136
00137 #define hasher_t void
00138
00141 void (*init)(hasher_t *H);
00142
00146 void (*update)(hasher_t *H, const uns8 *data, uns32 len);
00147
00151 void (*final)(hasher_t *H, uns8 *d);
00152 #undef hasher_t
00153
00156 void *ctx;
00157
00161 int len;
00162
00165 hash_t algo;
00166
00170 hasher_retcode err;
00171 } hasher_t;
00172
00176 extern void hasher_init (hasher_t *H);
00177
00185 extern void hasher_update(hasher_t *H, const uns8 *data, uns32 len);
00186
00191 extern void hasher_final (hasher_t *H, uns8 *result);
00192
00199 extern hasher_retcode hasher_setup(hasher_t *H, const char *algo);
00200
00205 extern hasher_retcode hasher_teardown(hasher_t *H);
00206
00210 extern const char* hasher_ret_msg(hasher_retcode c);
00211
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215
00216 #ifdef WIN32
00217 #undef extern
00218 #endif
00219
00220 #endif