Changeset 34afea7 for lib/sha1.h


Ignore:
Timestamp:
2015-01-31T23:58:57Z (6 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0ca1d79
Parents:
e41cc40
git-author:
dequis <dx@…> (18-01-15 06:39:20)
git-committer:
dequis <dx@…> (31-01-15 23:58:57)
Message:

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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/sha1.h

    re41cc40 r34afea7  
    1 /*
    2  * SHA1 hashing code copied from Lepton's crack <http://usuarios.lycos.es/reinob/>
    3  *
    4  * Adapted to be API-compatible with the previous (GPL-incompatible) code.
    5  */
    6 
    7 /*
    8  *  sha1.h
    9  *
    10  *  Description:
    11  *      This is the header file for code which implements the Secure
    12  *      Hashing Algorithm 1 as defined in FIPS PUB 180-1 published
    13  *      April 17, 1995.
    14  *
    15  *      Many of the variable names in this code, especially the
    16  *      single character names, were used because those were the names
    17  *      used in the publication.
    18  *
    19  *      Please read the file sha1.c for more information.
    20  *
    21  */
    221
    232#ifndef _SHA1_H_
    243#define _SHA1_H_
    254
    26 #if(__sun)
    27 #include <inttypes.h>
    28 #else
    29 #include <stdint.h>
    30 #endif
     5#include <glib.h>
    316#include <gmodule.h>
    327
    33 #ifndef _SHA_enum_
    34 #define _SHA_enum_
    35 enum {
    36         shaSuccess = 0,
    37         shaNull,                /* Null pointer parameter */
    38         shaInputTooLong,        /* input data too long */
    39         shaStateError           /* called Input after Result */
    40 };
    41 #endif
    42 #define sha1_hash_size 20
     8#define SHA1_HASH_SIZE 20
    439
    44 /*
    45  *  This structure will hold context information for the SHA-1
    46  *  hashing operation
    47  */
    48 typedef struct SHA1Context {
    49         uint32_t Intermediate_Hash[sha1_hash_size/4];   /* Message Digest   */
     10typedef GChecksum *sha1_state_t;
    5011
    51         uint32_t Length_Low;            /* Message length in bits           */
    52         uint32_t Length_High;           /* Message length in bits           */
    53 
    54         /* Index into message block array   */
    55         int_least16_t Message_Block_Index;
    56         uint8_t Message_Block[64];      /* 512-bit message blocks           */
    57 
    58         int Computed;                   /* Is the digest computed?          */
    59         int Corrupted;                  /* Is the message digest corrupted? */
    60 } sha1_state_t;
    61 
    62 /*
    63  *  Function Prototypes
    64  */
    65 
    66 G_MODULE_EXPORT int sha1_init(sha1_state_t *);
    67 G_MODULE_EXPORT int sha1_append(sha1_state_t *, const uint8_t *, unsigned int);
    68 G_MODULE_EXPORT int sha1_finish(sha1_state_t *, uint8_t Message_Digest[sha1_hash_size]);
    69 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]);
    70 G_MODULE_EXPORT char *sha1_random_uuid( sha1_state_t * context );
     12void sha1_init(sha1_state_t *);
     13void sha1_append(sha1_state_t *, const guint8 *, unsigned int);
     14void sha1_finish(sha1_state_t *, guint8 digest[SHA1_HASH_SIZE]);
     15void sha1_hmac(const char *, size_t, const char *, size_t, guint8 digest[SHA1_HASH_SIZE]);
     16char *sha1_random_uuid(sha1_state_t *);
    7117
    7218#endif
Note: See TracChangeset for help on using the changeset viewer.