diff options
author | dequis <dx@dxzone.com.ar> | 2015-01-18 03:39:20 -0300 |
---|---|---|
committer | dequis <dx@dxzone.com.ar> | 2015-01-31 20:58:57 -0300 |
commit | 34afea7dd6b066a9e7153d16a8e386c7c90ffe87 (patch) | |
tree | ea152e8c35fe5c9c273a8d2a64dfe0b91c51bf4b /lib/sha1.h | |
parent | e41cc4034741547c17ec4d24b9fdc50a8d2a5ee5 (diff) |
Use glib's GChecksum for md5/sha1
This changes behavior slightly:
- md5_init()/sha1_init() allocate a GChecksum
- md5_finish()/sha1_finish() close and free() it
- md5_digest_keep() was added (no sha1 equivalent needed)
And yes, glib has this concept of "closing" the GChecksum, which means
it can't be used anymore after g_checksum_get_digest().
jabber_cache_add() actually seems to need to do that to generate some
random-ish values, so i kept that working by adding a md5_digest_keep()
function that copies the GChecksum before it gets closed
GChecksum was introduced in glib 2.16, so the configure script version
was bumped. We were already depending on glib 2.16 accidentally
(some post-3.2.2 code uses GHashTableIter)
Diffstat (limited to 'lib/sha1.h')
-rw-r--r-- | lib/sha1.h | 70 |
1 files changed, 8 insertions, 62 deletions
@@ -1,72 +1,18 @@ -/* - * SHA1 hashing code copied from Lepton's crack <http://usuarios.lycos.es/reinob/> - * - * Adapted to be API-compatible with the previous (GPL-incompatible) code. - */ - -/* - * sha1.h - * - * Description: - * This is the header file for code which implements the Secure - * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published - * April 17, 1995. - * - * Many of the variable names in this code, especially the - * single character names, were used because those were the names - * used in the publication. - * - * Please read the file sha1.c for more information. - * - */ #ifndef _SHA1_H_ #define _SHA1_H_ -#if(__sun) -#include <inttypes.h> -#else -#include <stdint.h> -#endif +#include <glib.h> #include <gmodule.h> -#ifndef _SHA_enum_ -#define _SHA_enum_ -enum { - shaSuccess = 0, - shaNull, /* Null pointer parameter */ - shaInputTooLong, /* input data too long */ - shaStateError /* called Input after Result */ -}; -#endif -#define sha1_hash_size 20 - -/* - * This structure will hold context information for the SHA-1 - * hashing operation - */ -typedef struct SHA1Context { - uint32_t Intermediate_Hash[sha1_hash_size/4]; /* Message Digest */ - - uint32_t Length_Low; /* Message length in bits */ - uint32_t Length_High; /* Message length in bits */ - - /* Index into message block array */ - int_least16_t Message_Block_Index; - uint8_t Message_Block[64]; /* 512-bit message blocks */ - - int Computed; /* Is the digest computed? */ - int Corrupted; /* Is the message digest corrupted? */ -} sha1_state_t; +#define SHA1_HASH_SIZE 20 -/* - * Function Prototypes - */ +typedef GChecksum *sha1_state_t; -G_MODULE_EXPORT int sha1_init(sha1_state_t *); -G_MODULE_EXPORT int sha1_append(sha1_state_t *, const uint8_t *, unsigned int); -G_MODULE_EXPORT int sha1_finish(sha1_state_t *, uint8_t Message_Digest[sha1_hash_size]); -G_MODULE_EXPORT void sha1_hmac(const char *key_, size_t key_len, const char *payload, size_t payload_len, uint8_t Message_Digest[sha1_hash_size]); -G_MODULE_EXPORT char *sha1_random_uuid( sha1_state_t * context ); +void sha1_init(sha1_state_t *); +void sha1_append(sha1_state_t *, const guint8 *, unsigned int); +void sha1_finish(sha1_state_t *, guint8 digest[SHA1_HASH_SIZE]); +void sha1_hmac(const char *, size_t, const char *, size_t, guint8 digest[SHA1_HASH_SIZE]); +char *sha1_random_uuid(sha1_state_t *); #endif |