void dump_stuff_mmx_msg_sepline(const void * msg, void * buf, unsigned int size, unsigned int index) { printf("%s :\n", (char *) msg); dump_stuff_mmx(buf, size, index); }
static void wpapsk_crypt_all(int count) { #ifdef MMX_COEF /*int i;*/ printf("\n"); dump_stuff_mmx(ipad, 64, 0); memcpy(dump, ipad, 64*MMX_COEF); shammx_nosizeupdate( dump, dump, 64); memcpy(dump, cursalt, 64*MMX_COEF); shammx_noinit_uniformsizeupdate(dump, dump, total_len + 64 ); dump_stuff_mmx(dump, SHA_SIZE, 0); shammx_nosizeupdate( dump, opad, 64); shammx_noinit_uniformsizeupdate(dump, dump, SHA_SIZE + 64); dump_stuff_mmx(dump, SHA_SIZE, 0); return; #else unsigned char dump[SHA_SIZE]; unsigned char digest[SHA_SIZE]; unsigned char ptk[20*4]; unsigned int i,j; MD5_CTX md5ctx; //printf("\n"); //first calculation - left part SHA1_Init( &ctx ); SHA1_Update( &ctx, ipad, 64 ); SHA1_Update( &ctx, cursalt, strlen(cursalt) + 4 ); SHA1_Final( dump, &ctx); SHA1_Init( &ctx ); SHA1_Update( &ctx, opad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( dump, &ctx); memcpy(digest, dump, SHA_SIZE); for(i=1;i<4096;i++) { SHA1_Init( &ctx ); SHA1_Update( &ctx, ipad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE ); SHA1_Final( dump, &ctx); SHA1_Init( &ctx ); SHA1_Update( &ctx, opad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( dump, &ctx); for(j=0;j<SHA_SIZE;j++) digest[j] ^= dump[j]; } //first calculation - right part cursalt[ strlen(cursalt) + 3 ] = 2; SHA1_Init( &ctx ); SHA1_Update( &ctx, ipad, 64 ); SHA1_Update( &ctx, cursalt, strlen(cursalt) + 4 ); SHA1_Final( dump, &ctx); SHA1_Init( &ctx ); SHA1_Update( &ctx, opad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( dump, &ctx); memcpy(digest+SHA_SIZE, dump, 32-SHA_SIZE); for(i=1;i<4096;i++) { SHA1_Init( &ctx ); SHA1_Update( &ctx, ipad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE ); SHA1_Final( dump, &ctx); SHA1_Init( &ctx ); SHA1_Update( &ctx, opad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( dump, &ctx); for(j=0;j<32-SHA_SIZE;j++) digest[j+SHA_SIZE] ^= dump[j]; } //we now got pmk in digest,32 //dump_stuff(digest, 32 ); for(i=0;i<32;i++) { nipad[i] = 0x36 ^ digest[i]; nopad[i] = 0x5c ^ digest[i]; } //a hmac must be done with secret key pmk/32, and text "Pairwise key expansion",0,DATA,counter nDATA[23+64+12] = 0; SHA1_Init( &ctx ); SHA1_Update( &ctx, nipad, 64 ); SHA1_Update( &ctx, nDATA, 22+1+12+64+1 ); SHA1_Final( dump, &ctx ); SHA1_Init( &ctx ); SHA1_Update( &ctx, nopad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( ptk, &ctx); //seems not to be used ... /* nDATA[23+64+12] = 1; SHA1_Init( &ctx ); SHA1_Update( &ctx, nipad, 64 ); SHA1_Update( &ctx, nDATA, 22+1+12+64+1 ); SHA1_Final( dump, &ctx ); SHA1_Init( &ctx ); SHA1_Update( &ctx, nopad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( ptk + 20, &ctx); nDATA[23+64+12] = 2; SHA1_Init( &ctx ); SHA1_Update( &ctx, nipad, 64 ); SHA1_Update( &ctx, nDATA, 22+1+12+64+1 ); SHA1_Final( dump, &ctx ); SHA1_Init( &ctx ); SHA1_Update( &ctx, nopad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( ptk + 40, &ctx); nDATA[23+64+12] = 3; SHA1_Init( &ctx ); SHA1_Update( &ctx, nipad, 64 ); SHA1_Update( &ctx, nDATA, 22+1+12+64+1 ); SHA1_Final( dump, &ctx ); SHA1_Init( &ctx ); SHA1_Update( &ctx, nopad, 64 ); SHA1_Update( &ctx, dump, SHA_SIZE); SHA1_Final( ptk + 60, &ctx); */ //we now have the ptk ... //now hmac md5 ... memset(nipad + 16, 0x36 , 16); memset(nopad + 16, 0x5C , 16); for(i=0;i<16;i++) { nipad[i] = 0x36 ^ ptk[i]; nopad[i] = 0x5C ^ ptk[i]; } MD5_Init( &md5ctx ); MD5_Update( &md5ctx, nipad, 64 ); MD5_Update( &md5ctx, EAPOL, sizeof(EAPOL) ); MD5_Final ( dump, &md5ctx ); MD5_Init( &md5ctx ); MD5_Update( &md5ctx, nopad, 64 ); MD5_Update( &md5ctx, dump, 16 ); MD5_Final ( crypt_key, &md5ctx ); #endif }