From: Simon Josefsson Date: Sat, 8 Oct 2005 09:26:59 +0000 (+0000) Subject: 2005-10-08 Simon Josefsson X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2a551e042cdbf596e033b6155338b59ffb404ff;p=pspp 2005-10-08 Simon Josefsson * gc.h: Add gc_hash and gc_hash_buffer. * gc-gnulib.c (gc_hash_buffer): Add. Reorder #include's. * gc-libgcrypt.c (gc_hash_buffer): Add. --- diff --git a/lib/gc-gnulib.c b/lib/gc-gnulib.c index 99d6dc2bce..abb1bb466a 100644 --- a/lib/gc-gnulib.c +++ b/lib/gc-gnulib.c @@ -24,11 +24,12 @@ # include #endif -#include - /* Get prototype. */ #include +#include +#include + /* For randomize. */ #include #include @@ -36,7 +37,8 @@ #include #include -#include +#include "md5.h" +#include "hmac.h" int gc_init (void) @@ -133,7 +135,23 @@ gc_set_allocators (gc_malloc_t func_malloc, return; } -#include "md5.h" +/* Hashes. */ + +int +gc_hash_buffer (int hash, const void *in, size_t inlen, char *resbuf) +{ + switch (hash) + { + case GC_MD5: + md5_buffer (in, inlen, resbuf); + break; + + default: + return GC_INVALID_HASH; + } + + return GC_OK; +} int gc_md5 (const void *in, size_t inlen, void *resbuf) @@ -142,8 +160,6 @@ gc_md5 (const void *in, size_t inlen, void *resbuf) return 0; } -#include "hmac.h" - int gc_hmac_md5 (const void *key, size_t keylen, const void *in, size_t inlen, char *resbuf) diff --git a/lib/gc-libgcrypt.c b/lib/gc-libgcrypt.c index f4a93d35b4..65cc1b0571 100644 --- a/lib/gc-libgcrypt.c +++ b/lib/gc-libgcrypt.c @@ -94,6 +94,28 @@ gc_set_allocators (gc_malloc_t func_malloc, func_realloc, func_free); } +/* Hashes. */ + +int +gc_hash_buffer (int hash, const void *in, size_t inlen, char *resbuf) +{ + int gcryalg; + + switch (hash) + { + case GC_MD5: + gcryalg = GCRY_MD_MD5; + break; + + default: + return GC_INVALID_HASH; + } + + gcry_md_hash_buffer (gcryalg, resbuf, in, inlen); + + return GC_OK; +} + /* One-call interface. */ int diff --git a/lib/gc.h b/lib/gc.h index e40a681168..f9b66d1bff 100644 --- a/lib/gc.h +++ b/lib/gc.h @@ -24,8 +24,6 @@ /* Get size_t. */ # include -#define GC_MD5_DIGEST_SIZE 16 - enum Gc_rc { GC_OK = 0, @@ -40,6 +38,16 @@ enum Gc_rc }; typedef enum Gc_rc Gc_rc; +/* Hash types. */ +enum Gc_hash + { + GC_MD5 + }; +typedef enum Gc_hash Gc_hash; + +#define GC_MD5_DIGEST_SIZE 16 + +/* Call before respectively after any other functions. */ extern int gc_init (void); extern void gc_done (void); @@ -54,6 +62,10 @@ extern void gc_set_allocators (gc_malloc_t func_malloc, gc_realloc_t func_realloc, gc_free_t func_free); +/* Hashes. */ +extern int +gc_hash_buffer (int hash, const void *in, size_t inlen, char *out); + /* One-call interface. */ extern int gc_md5 (const void *in, size_t inlen, void *resbuf); extern int gc_hmac_md5 (const void *key, size_t keylen,