Mercurial > dropbear
comparison src/headers/tomcrypt_hash.h @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05
Import of libtomcrypt 1.05
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 03:53:40 +0000 |
parents | 1c15b283127b |
children |
comparison
equal
deleted
inserted
replaced
191:1c15b283127b | 209:39d5d58461d6 |
---|---|
130 unsigned char ID; | 130 unsigned char ID; |
131 /** Size of digest in octets */ | 131 /** Size of digest in octets */ |
132 unsigned long hashsize; | 132 unsigned long hashsize; |
133 /** Input block size in octets */ | 133 /** Input block size in octets */ |
134 unsigned long blocksize; | 134 unsigned long blocksize; |
135 /** ASN.1 DER identifier */ | 135 /** ASN.1 OID */ |
136 unsigned char DER[64]; | 136 unsigned long OID[16]; |
137 /** Length of DER encoding */ | 137 /** Length of DER encoding */ |
138 unsigned long DERlen; | 138 unsigned long OIDlen; |
139 | |
139 /** Init a hash state | 140 /** Init a hash state |
140 @param hash The hash to initialize | 141 @param hash The hash to initialize |
141 @return CRYPT_OK if successful | 142 @return CRYPT_OK if successful |
142 */ | 143 */ |
143 int (*init)(hash_state *hash); | 144 int (*init)(hash_state *hash); |
276 int find_hash_any(const char *name, int digestlen); | 277 int find_hash_any(const char *name, int digestlen); |
277 int register_hash(const struct ltc_hash_descriptor *hash); | 278 int register_hash(const struct ltc_hash_descriptor *hash); |
278 int unregister_hash(const struct ltc_hash_descriptor *hash); | 279 int unregister_hash(const struct ltc_hash_descriptor *hash); |
279 int hash_is_valid(int idx); | 280 int hash_is_valid(int idx); |
280 | 281 |
282 LTC_MUTEX_PROTO(ltc_hash_mutex); | |
283 | |
281 int hash_memory(int hash, | 284 int hash_memory(int hash, |
282 const unsigned char *in, unsigned long inlen, | 285 const unsigned char *in, unsigned long inlen, |
283 unsigned char *out, unsigned long *outlen); | 286 unsigned char *out, unsigned long *outlen); |
284 int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen, | 287 int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen, |
285 const unsigned char *in, unsigned long inlen, ...); | 288 const unsigned char *in, unsigned long inlen, ...); |
290 #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ | 293 #define HASH_PROCESS(func_name, compress_name, state_var, block_size) \ |
291 int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \ | 294 int func_name (hash_state * md, const unsigned char *in, unsigned long inlen) \ |
292 { \ | 295 { \ |
293 unsigned long n; \ | 296 unsigned long n; \ |
294 int err; \ | 297 int err; \ |
295 LTC_ARGCHK(md != NULL); \ | 298 LTC_ARGCHK(md != NULL); \ |
296 LTC_ARGCHK(in != NULL); \ | 299 LTC_ARGCHK(in != NULL); \ |
297 if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ | 300 if (md-> state_var .curlen > sizeof(md-> state_var .buf)) { \ |
298 return CRYPT_INVALID_ARG; \ | 301 return CRYPT_INVALID_ARG; \ |
299 } \ | 302 } \ |
300 while (inlen > 0) { \ | 303 while (inlen > 0) { \ |
301 if (md-> state_var .curlen == 0 && inlen >= block_size) { \ | 304 if (md-> state_var .curlen == 0 && inlen >= block_size) { \ |
302 if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) { \ | 305 if ((err = compress_name (md, (unsigned char *)in)) != CRYPT_OK) { \ |
303 return err; \ | 306 return err; \ |
304 } \ | 307 } \ |
305 md-> state_var .length += block_size * 8; \ | 308 md-> state_var .length += block_size * 8; \ |
306 in += block_size; \ | 309 in += block_size; \ |
307 inlen -= block_size; \ | 310 inlen -= block_size; \ |
308 } else { \ | 311 } else { \ |
309 n = MIN(inlen, (block_size - md-> state_var .curlen)); \ | 312 n = MIN(inlen, (block_size - md-> state_var .curlen)); \ |
310 memcpy(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ | 313 memcpy(md-> state_var .buf + md-> state_var.curlen, in, (size_t)n); \ |
311 md-> state_var .curlen += n; \ | 314 md-> state_var .curlen += n; \ |
312 in += n; \ | 315 in += n; \ |
313 inlen -= n; \ | 316 inlen -= n; \ |
314 if (md-> state_var .curlen == block_size) { \ | 317 if (md-> state_var .curlen == block_size) { \ |
315 if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) {\ | 318 if ((err = compress_name (md, md-> state_var .buf)) != CRYPT_OK) { \ |
316 return err; \ | 319 return err; \ |
317 } \ | 320 } \ |
318 md-> state_var .length += 8*block_size; \ | 321 md-> state_var .length += 8*block_size; \ |
319 md-> state_var .curlen = 0; \ | 322 md-> state_var .curlen = 0; \ |
320 } \ | 323 } \ |
321 } \ | 324 } \ |
322 } \ | 325 } \ |
323 return CRYPT_OK; \ | 326 return CRYPT_OK; \ |
324 } | 327 } |
328 | |
329 /* $Source: /cvs/libtom/libtomcrypt/src/headers/tomcrypt_hash.h,v $ */ | |
330 /* $Revision: 1.12 $ */ | |
331 /* $Date: 2005/06/19 18:00:28 $ */ |