1 #include "main.h" 2 multihash_initialize()3void hash_context_obj::multihash_initialize() 4 { 5 for (int i = 0 ; i < NUM_ALGORITHMS ; ++i) { 6 if (hashes[i].inuse) { 7 hashes[i].f_init(this->hash_context[i]); 8 } 9 } 10 } 11 12 multihash_update(const unsigned char * buf,size_t len)13void hash_context_obj::multihash_update(const unsigned char *buf, size_t len) 14 { 15 /* 16 * We no longer have to copy the data being hashed from the buffer we were 17 * passed into another structure because the SHA-1 update 18 * routine now copies its own data. 19 */ 20 for (int i = 0 ; i < NUM_ALGORITHMS ; ++i) { 21 if (hashes[i].inuse) { 22 hashes[i].f_update(this->hash_context[i],buf,len); 23 } 24 } 25 } 26 27 28 /** 29 * multihash_finalizes finalizes each algorithm and converts to hex. 30 * Only the hex is preserved. 31 */ multihash_finalize(std::string dest[])32void hash_context_obj::multihash_finalize(std::string dest[]) 33 { 34 uint16_t j; 35 static char hex[] = "0123456789abcdef"; 36 37 for (int i = 0 ; i < NUM_ALGORITHMS ; ++i) { 38 dest[i]=""; 39 if (hashes[i].inuse) { 40 /* Calculate the residue and convert to hex */ 41 uint8_t residue[MAX_ALGORITHM_RESIDUE_SIZE]; 42 hashes[i].f_finalize(this->hash_context[i], residue); 43 for (j = 0; j < hashes[i].bit_length/8 ; j++) { 44 dest[i].push_back(hex[(residue[j] >> 4) & 0xf]); 45 dest[i].push_back(hex[residue[j] & 0xf]); 46 } 47 } 48 } 49 } 50 51 52 53