hashes can be saved in binary.

dev
leonnicolas 4 years ago
parent b3e917b369
commit cb77fed321

@ -6,30 +6,128 @@
#include "cryptwrapper.h"
#include "readBulk.h"
char bulk_buf[BULKSIZE][MAXMEM];
struct s_rainbowvalue256 bulk_buf_out[BULKSIZE];
int main(int argc, char const *argv[]) {
if (argc != 2){
printf("one argument expected ,argc =%i\n",argc);
return 1;
#include <argp.h>
const char *argp_program_version =
"create Rainbow 0.1";
/* Program documentation. */
static char doc[] =
"I wonder for what this is";
static struct argp_option options[] = {
{"verbose", 'v', 0, 0, "Produce verbose output" },
{"quiet", 'q', 0, 0, "Don't produce any output" },
{"base64", 'b', 0, 0, "Saves data in base 64" },
{"humanreadable", 'H', 0, 0, "Output is human readable (slower)" },
{"output", 'o', "FILE", 0, "Output to FILE instead of <name of input file>.sha256" },
{ 0 }
};
struct arguments
{
char *input_file; /* arg1 & arg2 */
int silent, verbose, humanreadable, base64;
int use_output_file, use_input_file;
char *output_file;
};
/* Parse a single option. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = state->input;
switch (key)
{
case 'q': case 's':
arguments->silent = 1;
break;
case 'v':
arguments->verbose = 1;
break;
case 'H':
arguments->humanreadable = 1;
break;
case 'b':
arguments->base64 = 1;
break;
case 'o':
arguments->output_file = arg;
arguments->use_output_file = 1;
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1)
/* Too many arguments. */
argp_usage (state);
arguments->input_file = arg;
break;
case ARGP_KEY_END:
if (state->arg_num < 1)
/* Not enough arguments. */
argp_usage (state);
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = { options, parse_opt, 0 , doc };
//parsing args set up end---------------------------------------------------------------
char bulk_buf[BULKSIZE][MAX_PW_LEN];
struct s_rainbowvalue256 bulk_buf_out[BULKSIZE];
int main(int argc, char **argv) {
//parsing args----------------------------------------------------------------
struct arguments arguments;
/* Default values. */
arguments.silent = 0;
arguments.verbose = 0;
arguments.humanreadable = 0;
arguments.base64 = 0;
arguments.output_file = "-";
arguments.input_file = "-";
argp_parse (&argp, argc, argv, 0, 0, &arguments);
//parsing args end---------------------------------------------------------------
FILE *fptr;
fptr = fopen(argv[1],"r");
fptr = fopen(arguments.input_file,"r");
if(fptr == NULL)
{
printf("Could not open file %s\n", argv[1]);
printf("Could not open file %s\n", arguments.input_file);
return 1;
}
FILE *tfptr;
char str[strlen(argv[1])+7];
strcpy(str,argv[1]);
strcat(str,".sha256");
tfptr = fopen(str,"wb");
if(tfptr == NULL)
{
printf("Could not create file %s\n", str);
return 1;
if (arguments.use_output_file){
tfptr = fopen(arguments.output_file,"wb");
if(tfptr == NULL)
{
printf("Could not create file %s\n", arguments.output_file);
return 1;
}
}
else {
char str[strlen(argv[1])+7];
strcpy(str,argv[1]);
strcat(str,".sha256");
tfptr = fopen(str,"wb");
if(tfptr == NULL)
{
printf("Could not create file %s\n", str);
return 1;
}
}
mycryptwrapper_init();
char line[256];
@ -37,34 +135,26 @@ int main(int argc, char const *argv[]) {
size_t mens = gcry_md_get_algo_dlen(algo);
void * digest=malloc(mens);
//printdata(buf,5);
//printf("\n");
size_t entries;
while ((entries = getBulk(fptr,bulk_buf))){
#pragma omp parallel for
for (size_t i = 0 ; i < entries;++i){
//printf("thread: %i\n",omp_get_thread_num());
struct s_rainbowvalue256 r;
gcry_md_hash_buffer(algo,r.hash,bulk_buf[i],strlen(bulk_buf[i])-1);// -1 so trailing \n is not used for calculation
//mycryptwrapper_print(digest, strlen(digest));
//printf("%s", line);
strcpy(r.pw , bulk_buf[i]);
//strcpy(r.hash,digest);
bulk_buf_out[i]= r;
}
fwrite(bulk_buf_out, sizeof(struct s_rainbowvalue256),entries,tfptr);
}
if (arguments.humanreadable){
/*while (fgets(line, sizeof(line), fptr)) {
}
else if(arguments.base64){
}
else {
fwrite(bulk_buf_out, sizeof(struct s_rainbowvalue256),entries,tfptr);
}
fwrite(&r, sizeof(struct s_rainbowvalue256),1,tfptr);
}
*/
fclose(tfptr);
fclose(fptr);
return 0;

@ -5,7 +5,7 @@
#include <stdint.h>
#include <strings.h>
#include <omp.h>
#include <time.h>
#include <inttypes.h>
#include "cryptwrapper.h"
#include "rainbowvalue.h"
@ -64,15 +64,19 @@ int main(int argc, char const *argv[]) {
struct s_rainbowvalue256 * rs = malloc(sizeof(struct s_rainbowvalue256)*BULKSIZE);
size_t num_rainbow_values;
clock_t old_clock;
// 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);
//printf("read %d rainbow values\n", (int) num_rainbow_values);
// iterate through rainbow values and decrypt
old_clock=clock();
#pragma omp parallel for
for (size_t i = 0 ; i < num_rainbow_values ; i++){
if (success==1){
#pragma omp exitregion
}
uint8_t * decrypted_buf = malloc(file_len);//allocate mem for decrypted buffer
gcry_cipher_hd_t dhd;
if (gcry_cipher_open(&dhd,cipher,GCRY_CIPHER_MODE_CFB,0)){perror("could not open cypher\n");}
@ -99,56 +103,18 @@ 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;
gcry_error_t err= gcry_cipher_open(&dhd,cipher,GCRY_CIPHER_MODE_CFB,0);
if (err){
printf("could not open handle\n");
}
err = gcry_cipher_setkey(dhd,r.hash,8);
if (err) {
printf("could not set key \n");
}
memset(iv,0,len);
err = gcry_cipher_setiv(dhd, iv , len);
if (err){
printf("could not init init vector");
}
memset(out,0,256);
err = gcry_cipher_decrypt(dhd,out,256,encrypted_secret,strlen(encrypted_secret));
if (err){
printf("could not decrypt\n");
}
}// end parallel
float sec = (float)((clock()-old_clock))/(float)CLOCKS_PER_SEC;
printf("\rcalc/sec: %4.0f", num_rainbow_values/sec);
if (strcmp(out,dummydata)==0){
printf("pw: %sfor data: %s\npwhash: ", r.pw, (char*)out);
mycryptwrapper_print(r.hash, strlen(r.hash));
gcry_cipher_close(dhd);//close cipher
return 0;
}
gcry_cipher_close(dhd);//close cipher
}
*/
if(success==0){
printf("\nnothing found\n");
}
//printdata(digest,mens);
return 0;
}

@ -1,9 +1,9 @@
#include "readBulk.h"
size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAXMEM]){
size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAX_PW_LEN]){
size_t i;
for (i = 0; i < BULKSIZE; ++i) {
if (!fgets(bulk[i], MAXMEM, fptr)){
if (!fgets(bulk[i], MAX_PW_LEN, fptr)){
break;
}
}
@ -11,4 +11,7 @@ size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAXMEM]){
}
size_t getHashBulk(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]){
return fread(rs, sizeof(struct s_rainbowvalue256),BULKSIZE,fptr );
}
size_t writeHashHumanReadable(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]){
return 0;
}

@ -1,14 +1,14 @@
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include "rainbowvalue.h"
#ifndef readBulk
#define readBulk
#define BULKSIZE 2000
#define MAXMEM 256
#define BULKSIZE 20000
/**
* reads bulk from file, file pointer is used as handle so if you read several bulk, dont use file pointer between
* if BULKSIZE or EOF is reached, 2000 or number of lines read is returned. Memory must be allocated by caller
@ -16,7 +16,7 @@
* @bulk allocated memory fot bulk
* @return
*/
size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAXMEM]);
size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAX_PW_LEN]);
/**
* reads bulk of s_rainbowvalues and stores them in rs
* @param fptr
@ -24,4 +24,19 @@ size_t getBulk(FILE * fptr, char bulk[BULKSIZE][MAXMEM]);
* @return values read
*/
size_t getHashBulk(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]);
/**
* writes to tsv file
* @param fptr file pointer to which values are written
* @param rs buffer of values to be written
* @return values written
*/
size_t writeHashHumanReadable(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]);
/**
* writes hash to tsv in base 64
* @param fptr
* @param rs
* @return
*/
size_t writeHashBase64(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]);
#endif
Loading…
Cancel
Save