/* this program compute md5 on cuda device and try to discover the clear text by brute force. Copyright (C) 2008 Luigi Tarenga This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This code take inspiration from wikipedia MD5 explanation and code from L. Peter Deutsch */ #include #include #include #include #define BLOCK_SIZE 96 #define GRID_SIZE 96 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) #define F(x, y ,z) ((z) ^ ((x) & ((y) ^ (z)))) /*(((x) & (y)) | (~(x) & (z)))*/ #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) /*(((x) & (z)) | ((y) & ~(z)))*/ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define R1OP(a, b, c, d, idx, s, K) t = a + F(b,c,d) + intmess[idx] + K; a = ROTATE_LEFT(t, s) + b #define R2OP(a, b, c, d, idx, s, K) t = a + G(b,c,d) + intmess[idx] + K; a = ROTATE_LEFT(t, s) + b #define R3OP(a, b, c, d, idx, s, K) t = a + H(b,c,d) + intmess[idx] + K; a = ROTATE_LEFT(t, s) + b #define R4OP(a, b, c, d, idx, s, K) t = a + I(b,c,d) + intmess[idx] + K; a = ROTATE_LEFT(t, s) + b /* formula per generare le costanti for i from 0 to 63 K := floor(abs(sin(i + 1)) × (2 pow 32)) */ __global__ void cudaMD5(unsigned char *mess, unsigned int len, uint4 digest){ unsigned int intmess[16]; unsigned char *charmess; unsigned int i,j; unsigned int a; unsigned int b; unsigned int c; unsigned int d; unsigned int t; charmess=(unsigned char *)intmess; /* trick to save 4 sum on the gpu */ digest.x-=0x67452301; digest.y-=0xefcdab89; digest.z-=0x98badcfe; digest.w-=0x10325476; for(i=0;i<16;i++){ intmess[i]=0; } charmess[0]=(unsigned char)(blockIdx.x+32); charmess[1]=(unsigned char)(threadIdx.x+32); for(i=2;i>>(dev_ptr,4,d); err=cudaThreadSynchronize(); if( cudaSuccess != err ){ printf("errore in cudaThreadSynchronize\n"); exit(1); } err=cudaMemcpy((void *)message,(void *)dev_ptr,64,cudaMemcpyDeviceToHost); if( cudaSuccess != err ){ printf("errore in cudaMemcpy\n"); exit(1); } err=cudaFree((void *)dev_ptr); if( cudaSuccess != err ){ printf("errore in cudaFree\n"); exit(1); } printf("la stringa in chiaro è: \"%s\"\n",message); for(i=0;i<64;i++){ printf("%02x ",message[i]); } printf("\n"); exit(0); }