Created
May 29, 2014 17:17
-
-
Save daviddahl/b8edb58299707670b39a to your computer and use it in GitHub Desktop.
WTF-fails.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int generateKeyFromPassword(char* passphrase, struct keyItem* item) | |
{ | |
int i; | |
unsigned char* salt = gcry_random_bytes(16, GCRY_STRONG_RANDOM); | |
char* keyBuffer; | |
size_t saltLen = 16; | |
size_t keySize = 32; | |
gpg_error_t err; | |
unsigned long iterations = 10000; | |
err = gcry_kdf_derive(passphrase, strlen(passphrase), | |
GCRY_KDF_PBKDF2, GCRY_MD_SHA256, | |
salt, saltLen, | |
iterations, keySize, keyBuffer); | |
if (err) { | |
printf("Error generating key from password. Error no: %d and message: %s\n ", | |
err, | |
gcry_strerror(err)); | |
return 1; | |
} | |
printf("Key: \n"); | |
printf("%s\n", keyBuffer); | |
item->key = keyBuffer; | |
item->salt = salt; | |
item->name = (unsigned char)"masterKey"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment