SHA

Name

SHA -- SHA Hash

Synopsis



struct      GSHA;
#define     GNET_SHA_HASH_LENGTH
GSHA*       gnet_sha_new                    (const guint8 *buffer,
                                             guint length);
GSHA*       gnet_sha_new_string             (const gchar *str);
GSHA*       gnet_sha_clone                  (const GSHA *gsha);
void        gnet_sha_delete                 (GSHA *gsha);
GSHA*       gnet_sha_new_incremental        (void);
void        gnet_sha_update                 (GSHA *gsha,
                                             const guchar *buffer,
                                             guint length);
void        gnet_sha_final                  (GSHA *gsha);
gint        gnet_sha_equal                  (gconstpointer p1,
                                             gconstpointer p2);
guint       gnet_sha_hash                   (gconstpointer p);
guint8*     gnet_sha_get_digest             (const GSHA *gsha);
gchar*      gnet_sha_get_string             (const GSHA *gsha);
void        gnet_sha_copy_string            (const GSHA *gsha,
                                             guint8 *buffer);

Description

Details

struct GSHA

struct GSHA;


GNET_SHA_HASH_LENGTH

#define     GNET_SHA_HASH_LENGTH

Length of the SHA hash in bytes.


gnet_sha_new ()

GSHA*       gnet_sha_new                    (const guint8 *buffer,
                                             guint length);

Create an SHA hash of the buffer.

buffer : Buffer to hash
length : Length of that buffer
Returns : a new GSHA.


gnet_sha_new_string ()

GSHA*       gnet_sha_new_string             (const gchar *str);

Create an SHA hash from a hexidecimal string. The string must be of length greater than or equal to GNET_SHA_HASH_LENGTH * 2.

str : Hexidecimal string
Returns : a new GSHA.


gnet_sha_clone ()

GSHA*       gnet_sha_clone                  (const GSHA *gsha);

Create a SHA from another one.

gsha : SHA to clone.
Returns : a new GSHA.


gnet_sha_delete ()

void        gnet_sha_delete                 (GSHA *gsha);

Delete a GSHA.

gsha : GSHA to delete


gnet_sha_new_incremental ()

GSHA*       gnet_sha_new_incremental        (void);

Create a SHA hash in incremental mode. After creating the GSHA, call gnet_sha_update() and gnet_sha_final().

Returns : new GSHA


gnet_sha_update ()

void        gnet_sha_update                 (GSHA *gsha,
                                             const guchar *buffer,
                                             guint length);

Update the hash with buffer. This may be called several times on an incremental hash before being finalized.

gsha : GSHA to update
buffer : Buffer to add
length : Length of that buffer


gnet_sha_final ()

void        gnet_sha_final                  (GSHA *gsha);

Calcuate the final hash value. This is called on a GSHA created using gnet_sha_new_incremental() and updated using gnet_sha_update() possibly several times.

gsha : GSHA to finalize


gnet_sha_equal ()

gint        gnet_sha_equal                  (gconstpointer p1,
                                             gconstpointer p2);

Compare two GSHA's.

p1 : Pointer to first GSHA.
p2 : Pointer to second GSHA.
Returns : 1 if they are the same; 0 otherwise.


gnet_sha_hash ()

guint       gnet_sha_hash                   (gconstpointer p);

Hash the GSHA hash value. This is not the actual SHA hash, but a hash of this hash.

p : GSHA to get hash value of
Returns : hash value.


gnet_sha_get_digest ()

guint8*     gnet_sha_get_digest             (const GSHA *gsha);

Get the SHA hash digest.

gsha : GSHA to get hash digest from
Returns : buffer containing the SHA hash digest. The buffer is GNET_SHA_HASH_LENGTH bytes long. The GSHA owns the buffer - do not free it.


gnet_sha_get_string ()

gchar*      gnet_sha_get_string             (const GSHA *gsha);

Get a hash string.

gsha : GSHA to get hash from
Returns : Hexadecimal string representing the hash. The string is of length 2 * GNET_SHA_HASH_LENGTH and null terminated. The caller must free the string.


gnet_sha_copy_string ()

void        gnet_sha_copy_string            (const GSHA *gsha,
                                             guint8 *buffer);

Copy the hash string into the buffer.

gsha : GSHA to get hash from
buffer : Buffer of length of at least 2 * GNET_SHA_HASH_LENGTH