From 193a5098856083ab372f1cdeafbf7f4013858c43 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Sat, 28 Mar 2020 19:28:33 +0100 Subject: [PATCH] some code cleaning --- crypwrapper.c | 15 +--------- decrypt.c | 2 +- encrypt.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ readBulk.c | 2 +- 4 files changed, 79 insertions(+), 16 deletions(-) diff --git a/crypwrapper.c b/crypwrapper.c index bc8e103..e481d45 100644 --- a/crypwrapper.c +++ b/crypwrapper.c @@ -4,7 +4,7 @@ void mycryptwrapper_init(){ /* Version check should be the very first call because it makes sure that important subsystems are initialized. - #define NEED_LIBGCRYPT_VERSION to the minimum required version. */ + */ if (!gcry_check_version (GCRYPT_VERSION)) { fprintf (stderr, "libgcrypt is too old (need %s, have %s)\n", @@ -36,24 +36,11 @@ void mycryptwrapper_print(const void * buf, size_t len){ int check_sha256_tag(uint8_t * ptr, size_t file_len){ uint8_t * calc_hash = malloc(HASH_SIZE); gcry_md_hash_buffer(algo,calc_hash,ptr,file_len-HASH_SIZE); - /*printf("hash\n"); - mycryptwrapper_print(calc_hash,32); - printf("HASH in file:\n"); - for (int i = 0 ; i< HASH_SIZE; i++){ - printf("%02x ", ptr[file_len+i-HASH_SIZE]); - } - printf("file:\n%s",(char* )ptr); -*/ for (int i=0 ; i< HASH_SIZE; i++){ - //printf("%02x ", calc_hash[i]); if (calc_hash[i] != ptr[i+file_len-HASH_SIZE]){ free(calc_hash); - // printf("no match\n"); return 0; } } - - return 1; - } diff --git a/decrypt.c b/decrypt.c index 562be2e..51fb1cf 100644 --- a/decrypt.c +++ b/decrypt.c @@ -104,7 +104,7 @@ int main(int argc, char const *argv[]) { //return 0; success=1; #pragma omp exitregion - } + }// decryption succesfull end free(iv); free(decrypted_buf); gcry_cipher_close(dhd); diff --git a/encrypt.c b/encrypt.c index b3881c2..eaafd25 100644 --- a/encrypt.c +++ b/encrypt.c @@ -8,6 +8,82 @@ #include "cryptwrapper.h" +#include + +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" }, + {"output", 'o', "FILE", 0, "Output to FILE instead of .encry" }, + {"authentication_mode", 'm', "MODE", 0, "default MtE (only one implemented)" }, + {"password", 'p', "clear_pw", 0, "password used for encryption" }, + { 0 } +}; +struct arguments +{ + char *authentication_mode; + char *output_file; + char *input_file; + char *clear_pw; + int silent, verbose; + int use_output_file, use_clear_pw; +}; +/* 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 'o': + arguments->output_file = arg; + arguments->use_output_file = 1; + break; + case 'p': + arguments->use_clear_pw = 1; + arguments->clear_pw = arg; + 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--------------------------------------------------------------- + + int main(int argc, char const *argv[]) { if (argc < 3){ printf("please select file and pw\n"); diff --git a/readBulk.c b/readBulk.c index e36a056..aba1e7b 100644 --- a/readBulk.c +++ b/readBulk.c @@ -16,5 +16,5 @@ size_t writeHashHumanReadable(FILE *fptr, struct s_rainbowvalue256 rs[BULKSIZE]) return 0; } size_t writeHashBase64(FILE *fptr,size_t num ,struct s_rainbowvalue256 rs[BULKSIZE]){ - + return 0; } \ No newline at end of file