Changeset 4451:839e9e3f1b46 in roaraudio
- Timestamp:
- 10/09/10 21:11:16 (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroar/hash.c
r4450 r4451 35 35 36 36 #include "libroar.h" 37 38 #ifdef ROAR_HAVE_LIBGCRYPT 39 #include <gcrypt.h> 40 #endif 37 41 38 42 static const struct hashes { … … 81 85 }; 82 86 87 static inline int roar_ht2gcrypt_tested (const int ht) { 88 const char * name; 89 90 if ( ht > 512 ) 91 return -1; 92 93 // test the algo: 94 name = gcry_md_algo_name(ht); 95 96 if ( name == NULL ) 97 return -1; 98 99 if ( *name == 0 ) 100 return -1; 101 102 return ht; 103 } 104 83 105 const char * roar_ht2str (const int ht) { 84 106 int i; … … 105 127 } 106 128 129 #ifdef ROAR_HAVE_LIBGCRYPT 130 static inline int roar_hash_salted_buffer_gcrypt(void * digest, const void * data, size_t datalen, int algo, const void * salt, size_t saltlen) { 131 gcry_md_hd_t hdl; 132 133 algo = roar_ht2gcrypt_tested(algo); 134 if ( algo == -1 ) 135 return -1; 136 137 138 if ( salt == NULL ) { 139 // optimized for unsalted: 140 gcry_md_hash_buffer(algo, digest, data, datalen); 141 return 0; 142 } else { 143 if ( gcry_md_open(&hdl, algo, 0) != 0 ) 144 return -1; 145 146 gcry_md_write(hdl, data, datalen); 147 gcry_md_write(hdl, salt, saltlen); 148 149 memcpy(digest, gcry_md_read(hdl, algo), gcry_md_get_algo_dlen(algo)); 150 151 gcry_md_close(hdl); 152 } 153 154 return 0; 155 } 156 #endif 157 107 158 int roar_hash_salted_buffer(void * digest, const void * data, size_t datalen, int algo, const void * salt, size_t saltlen) { 159 if ( digest == NULL || data == NULL ) 160 return -1; 161 162 #ifdef ROAR_HAVE_LIBGCRYPT 163 return roar_hash_salted_buffer_gcrypt(digest, data, datalen, algo, salt, saltlen); 164 #else 108 165 return -1; 166 #endif 109 167 } 110 168
Note: See TracChangeset
for help on using the changeset viewer.