works for larger files and threads are exit if pw was found. I do this with global variable. This should be thread safe as long as only one password matches (so ranbow table must be a set with no equal entries).

dev
leonnicolas 4 years ago
parent cd807b6dc6
commit b3e917b369

@ -5,4 +5,6 @@ usage:
./encryptf file password to encrypt file with passwort(the sha256 hash is used)
./brutef file.txt.sha256 file.encry to decrypt
notes: does not work with larger files and all threads continue calculating even if password was found
fix:
does not work with larger files (>60840bytes) and all threads continue calculating even if password was found

@ -67,6 +67,7 @@ int main(int argc, char const *argv[]) {
// read a block of rainbow values
int success = 0;
while ((num_rainbow_values=fread(rs, sizeof(struct s_rainbowvalue256),BULKSIZE,fptr_rainbow ))!=0){
if (success==1){break;}
printf("read %d rainbow values\n", (int) num_rainbow_values);
// iterate through rainbow values and decrypt
@ -77,12 +78,14 @@ int main(int argc, char const *argv[]) {
if (gcry_cipher_open(&dhd,cipher,GCRY_CIPHER_MODE_CFB,0)){perror("could not open cypher\n");}
if (gcry_cipher_setkey(dhd,rs[i].hash,8)){perror("could not set key\n");};
void * iv = malloc(len);
memset(iv,0,len);
if (gcry_cipher_setiv(dhd, iv , len)){perror("could not set init vector\n");}
if (gcry_cipher_decrypt(dhd,decrypted_buf,file_len,buf,file_len)){perror("could not decrypt\n");}
//mycryptwrapper_print(decrypted_buf,file_len);
//printf("pw: %s\nfile:%s\n",rs[i].pw,decrypted_buf);
if (check_sha256_tag(decrypted_buf,file_len)){
printf("pw: %s\n", rs[i].pw);
char * enc_fname = malloc(strlen(argv[2])+5);
strcpy(enc_fname, argv[2]);
strcat(enc_fname,".decr");
@ -96,12 +99,15 @@ int main(int argc, char const *argv[]) {
printf("successfully saved decrypted data in %s\n", enc_fname);
//return 0;
success=1;
#pragma omp exitregion
#pragma omp exitregion
}
free(iv);
free(decrypted_buf);
gcry_cipher_close(dhd);
}
if (success==1){
#pragma omp exitregion
}
}
/*while (fread(&r, sizeof(struct s_rainbowvalue256), 1,fptr)) {//reading hash values from rainbowtable
gcry_cipher_hd_t dhd;

@ -30,6 +30,9 @@ int main(int argc, char const *argv[]) {
rewind(fptr);// sets pointer to beginning of file
//printf("file is %d long\n", file_len);
char * buf_out = malloc(file_len + 32); // for sha256 check sum 32*8=256 lol
if (buf_out==NULL){
perror("could not allocate memory\n");
}
if (buf_out == NULL){
printf("could not allocate memory, maybe file is too large\n");
return 1;
@ -48,7 +51,8 @@ int main(int argc, char const *argv[]) {
mycryptwrapper_init();
gcry_md_hash_buffer(algo,pw_hash,argv[2],strlen(argv[2]));
gcry_md_hash_buffer(algo,file_hash,buf_out,file_len);
printf("filehash:\n");
mycryptwrapper_print(file_hash,32);
//appending sha256 to end of buffer
for (size_t i = 0; i<+32; i++){

Loading…
Cancel
Save