fix: set init vector iv to 0 with memset. Else everytime you encrypt, a diffrent data set is generated

master
leonnicolas 5 years ago
parent 8e6736398e
commit 5b0eeb5bd8

@ -10,7 +10,7 @@
#define mycryptwrapper_
#define NEED_LIBGCRYPT_VERSION "1.6.5" //should be 1.8.5 but my libgcrypt as mismatched versions :(
#define NEED_LIBGCRYPT_VERSION "1.8.5" //should be 1.8.5 but my libgcrypt as mismatched versions :(
#define algo GCRY_MD_SHA256
#define cipher GCRY_CIPHER_DES

@ -5,12 +5,14 @@ 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 (NEED_LIBGCRYPT_VERSION))
if (!gcry_check_version (GCRYPT_VERSION))
{
fprintf (stderr, "libgcrypt is too old (need %s, have %s)\n",
NEED_LIBGCRYPT_VERSION, gcry_check_version (NULL));
GCRYPT_VERSION, gcry_check_version (NULL));
exit (2);
}
// printf("gcrypt version = %s\n",GCRYPT_VERSION);
/* Disable secure memory. */
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);

@ -64,12 +64,14 @@ int main(int argc, char const *argv[]) {
perror("could not open handle for cipher\n");
return 1;
}
if(gcry_cipher_setkey(hd,pw_hash,8)){
printf("could not set key for encryption");
return 1;
}
size_t len = 8;
void * iv = malloc(len);
memset(iv,0,len);
if (gcry_cipher_setiv(hd, iv , len)){
printf("could not init init vector");
return 1;
@ -82,7 +84,7 @@ int main(int argc, char const *argv[]) {
perror("could not write all data\n");
return 1;
}
free(iv);
gcry_cipher_close(hd);
fclose(fptr);

Loading…
Cancel
Save