Changeset 5284:3fcf039ca02c in roaraudio


Ignore:
Timestamp:
11/22/11 12:53:18 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

ported hash API to < 32 bit archs

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/hash.h

    r4878 r5284  
    3939#include "libroar.h" 
    4040 
     41typedef uint_least32_t roar_hash_t; 
     42 
    4143// the hashtypes: 
    42 #define ROAR_HT_NONE        0 
    43 #define ROAR_HT_MD5         1 
    44 #define ROAR_HT_SHA1        2 
    45 #define ROAR_HT_RIPEMD160   3 
    46 #define ROAR_HT_MD2         5 
    47 #define ROAR_HT_TIGER       6 
    48 #define ROAR_HT_HAVAL       7 
    49 #define ROAR_HT_SHA256      8 
    50 #define ROAR_HT_SHA384      9 
    51 #define ROAR_HT_SHA512      10 
    52 #define ROAR_HT_SHA224      11 
    53 #define ROAR_HT_MD4         301 
    54 #define ROAR_HT_CRC32       302 
    55 #define ROAR_HT_RFC1510     303 
    56 #define ROAR_HT_RFC2440     304 
    57 #define ROAR_HT_WHIRLPOOL   305 
    58 #define ROAR_HT_UUID        70000 
    59 #define ROAR_HT_GTN8        70001 
    60 #define ROAR_HT_GTN16       70002 
    61 #define ROAR_HT_GTN32       70004 
    62 #define ROAR_HT_GTN64       70008 
    63 #define ROAR_HT_CLIENTID    71001 
    64 #define ROAR_HT_STREAMID    71002 
    65 #define ROAR_HT_SOURCEID    71003 
    66 #define ROAR_HT_SAMPLEID    71004 
    67 #define ROAR_HT_MIXERID     71005 
    68 #define ROAR_HT_BRIDGEID    71006 
    69 #define ROAR_HT_LISTENID    71007 
    70 #define ROAR_HT_ACTIONID    71008 
    71 #define ROAR_HT_MSGQUEUEID  71009 
    72 #define ROAR_HT_MSGBUSID    71010 
    73 #define ROAR_HT_GTIN8       72001 
    74 #define ROAR_HT_GTIN13      72002 
    75 #define ROAR_HT_ISBN10      72003 
     44#define ROAR_HT_NONE        ((roar_hash_t)0UL) 
     45#define ROAR_HT_MD5         ((roar_hash_t)1UL) 
     46#define ROAR_HT_SHA1        ((roar_hash_t)2UL) 
     47#define ROAR_HT_RIPEMD160   ((roar_hash_t)3UL) 
     48#define ROAR_HT_MD2         ((roar_hash_t)5UL) 
     49#define ROAR_HT_TIGER       ((roar_hash_t)6UL) 
     50#define ROAR_HT_HAVAL       ((roar_hash_t)7UL) 
     51#define ROAR_HT_SHA256      ((roar_hash_t)8UL) 
     52#define ROAR_HT_SHA384      ((roar_hash_t)9UL) 
     53#define ROAR_HT_SHA512      ((roar_hash_t)10UL) 
     54#define ROAR_HT_SHA224      ((roar_hash_t)11UL) 
     55#define ROAR_HT_MD4         ((roar_hash_t)301UL) 
     56#define ROAR_HT_CRC32       ((roar_hash_t)302UL) 
     57#define ROAR_HT_RFC1510     ((roar_hash_t)303UL) 
     58#define ROAR_HT_RFC2440     ((roar_hash_t)304UL) 
     59#define ROAR_HT_WHIRLPOOL   ((roar_hash_t)305UL) 
     60#define ROAR_HT_UUID        ((roar_hash_t)70000UL) 
     61#define ROAR_HT_GTN8        ((roar_hash_t)70001UL) 
     62#define ROAR_HT_GTN16       ((roar_hash_t)70002UL) 
     63#define ROAR_HT_GTN32       ((roar_hash_t)70004UL) 
     64#define ROAR_HT_GTN64       ((roar_hash_t)70008UL) 
     65#define ROAR_HT_CLIENTID    ((roar_hash_t)71001UL) 
     66#define ROAR_HT_STREAMID    ((roar_hash_t)71002UL) 
     67#define ROAR_HT_SOURCEID    ((roar_hash_t)71003UL) 
     68#define ROAR_HT_SAMPLEID    ((roar_hash_t)71004UL) 
     69#define ROAR_HT_MIXERID     ((roar_hash_t)71005UL) 
     70#define ROAR_HT_BRIDGEID    ((roar_hash_t)71006UL) 
     71#define ROAR_HT_LISTENID    ((roar_hash_t)71007UL) 
     72#define ROAR_HT_ACTIONID    ((roar_hash_t)71008UL) 
     73#define ROAR_HT_MSGQUEUEID  ((roar_hash_t)71009UL) 
     74#define ROAR_HT_MSGBUSID    ((roar_hash_t)71010UL) 
     75#define ROAR_HT_GTIN8       ((roar_hash_t)72001UL) 
     76#define ROAR_HT_GTIN13      ((roar_hash_t)72002UL) 
     77#define ROAR_HT_ISBN10      ((roar_hash_t)72003UL) 
    7678#define ROAR_HT_ISBN13      ROAR_HT_GTIN13 
    77 #define ROAR_HT_ADLER32     73001 
     79#define ROAR_HT_ADLER32     ((roar_hash_t)73001UL) 
    7880 
    7981struct roar_hash_cmds { 
    80  int algo; 
     82 roar_hash_t algo; 
    8183 ssize_t statelen; 
    8284 ssize_t blocksize; 
     
    8890}; 
    8991 
    90 const char * roar_ht2str (const int    ht); 
    91 int          roar_str2ht (const char * ht); 
     92const char * roar_ht2str (const roar_hash_t ht); 
     93roar_hash_t  roar_str2ht (const char * ht); 
    9294 
    93 ssize_t      roar_ht_digestlen (const int    ht); 
     95ssize_t      roar_ht_digestlen (const roar_hash_t ht); 
    9496 
    95 ssize_t      roar_hash_digest2str(char * out, size_t outlen, void * digest, size_t digestlen, int ht); 
     97ssize_t      roar_hash_digest2str(char * out, size_t outlen, void * digest, size_t digestlen, roar_hash_t ht); 
    9698 
    97 int          roar_ht_is_supported(const int    ht); 
     99int          roar_ht_is_supported(const roar_hash_t ht); 
    98100 
    99101struct roar_hash_state; 
    100102 
    101 struct roar_hash_state * roar_hash_new(int algo); 
     103struct roar_hash_state * roar_hash_new(roar_hash_t algo); 
    102104int roar_hash_free(struct roar_hash_state * state); 
    103105int roar_hash_digest(struct roar_hash_state * state, void * digest, size_t * len); 
    104106int roar_hash_proc(struct roar_hash_state * state, const void * data, size_t len); 
    105107 
    106 int roar_hash_buffer(void * digest, const void * data, size_t datalen, int algo); 
    107 int roar_hash_salted_buffer(void * digest, const void * data, size_t datalen, int algo, const void * salt, size_t saltlen); 
     108int roar_hash_buffer(void * digest, const void * data, size_t datalen, roar_hash_t algo); 
     109int roar_hash_salted_buffer(void * digest, const void * data, size_t datalen, roar_hash_t algo, const void * salt, size_t saltlen); 
    108110 
    109111#endif 
  • libroar/hash.c

    r5270 r5284  
    4646 
    4747static const struct hashes { 
    48  const uint_least32_t id; 
     48 const roar_hash_t    id; 
    4949 const char         * name; 
    5050 const ssize_t        dlen; 
     
    110110}; 
    111111 
    112 static struct roar_hash_cmds * roar_ht2cmds(const int ht) { 
     112static struct roar_hash_cmds * roar_ht2cmds(const roar_hash_t ht) { 
    113113 size_t i; 
    114114 
    115  for(i = 0; _libroar_hash_cmds[i].algo != -1; i++) 
     115 for(i = 0; _libroar_hash_cmds[i].algo != (roar_hash_t)-1; i++) 
    116116  if ( _libroar_hash_cmds[i].algo == ht ) 
    117117   return &(_libroar_hash_cmds[i]); 
     
    121121} 
    122122 
    123 static inline int roar_ht2gcrypt_tested (const int ht) { 
     123static inline int roar_ht2gcrypt_tested (const roar_hash_t ht) { 
    124124#ifdef ROAR_HAVE_LIBGCRYPT 
    125125 const char * name; 
     
    143143} 
    144144 
    145 const char * roar_ht2str (const int    ht) { 
     145const char * roar_ht2str (const roar_hash_t  ht) { 
    146146 int i; 
    147147 
    148  for (i = 0; _libroar_hashes[i].id != (uint_least32_t)-1; i++) 
     148 for (i = 0; _libroar_hashes[i].id != (roar_hash_t)-1; i++) 
    149149  if ( _libroar_hashes[i].id == ht ) 
    150150   return _libroar_hashes[i].name; 
     
    154154} 
    155155 
    156 int          roar_str2ht (const char * ht) { 
     156roar_hash_t      roar_str2ht (const char * ht) { 
    157157 int i; 
    158158 
    159  for (i = 0; _libroar_hashes[i].id != (uint_least32_t)-1; i++) 
     159 for (i = 0; _libroar_hashes[i].id != (roar_hash_t)-1; i++) 
    160160  if ( !strcasecmp(_libroar_hashes[i].name, ht) ) 
    161161   return _libroar_hashes[i].id; 
     
    165165} 
    166166 
    167 ssize_t      roar_ht_digestlen (const int    ht) { 
     167ssize_t      roar_ht_digestlen (const roar_hash_t   ht) { 
    168168 int i; 
    169169 
     
    192192} 
    193193 
    194 ssize_t      roar_hash_digest2str(char * out, size_t outlen, void * digest, size_t digestlen, int ht) { 
     194ssize_t      roar_hash_digest2str(char * out, size_t outlen, void * digest, size_t digestlen, roar_hash_t ht) { 
    195195 ssize_t slen = roar_ht_digestlen(ht); 
    196196 union { 
     
    300300} 
    301301 
    302 int          roar_ht_is_supported(const int    ht) { 
     302int          roar_ht_is_supported(const roar_hash_t ht) { 
    303303 roar_crypto_init(); 
    304304 
     
    316316} 
    317317 
    318 struct roar_hash_state * roar_hash_new(int algo) { 
     318struct roar_hash_state * roar_hash_new(roar_hash_t algo) { 
    319319 struct roar_hash_cmds  * cmds = roar_ht2cmds(algo); 
    320320 struct roar_hash_state * self; 
     
    397397} 
    398398 
    399 int roar_hash_buffer(void * digest, const void * data, size_t datalen, int algo) { 
     399int roar_hash_buffer(void * digest, const void * data, size_t datalen, roar_hash_t algo) { 
    400400 roar_crypto_init(); 
    401401 
     
    404404 
    405405#ifdef ROAR_HAVE_LIBGCRYPT 
    406 static inline int roar_hash_salted_buffer_gcrypt(void * digest, const void * data, size_t datalen, int algo, const void * salt, size_t saltlen) { 
     406static inline int roar_hash_salted_buffer_gcrypt(void * digest, const void * data, size_t datalen, roar_hash_t algo, const void * salt, size_t saltlen) { 
    407407 gcry_md_hd_t hdl; 
    408408 
     
    434434#endif 
    435435 
    436 int roar_hash_salted_buffer(void * digest, const void * data, size_t datalen, int algo, const void * salt, size_t saltlen) { 
     436int roar_hash_salted_buffer(void * digest, const void * data, size_t datalen, roar_hash_t algo, const void * salt, size_t saltlen) { 
    437437 struct roar_hash_state * state; 
    438438 size_t len; 
Note: See TracChangeset for help on using the changeset viewer.