Created
May 29, 2014 17:15
-
-
Save daviddahl/8173966312f029d9736b to your computer and use it in GitHub Desktop.
WTF
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
#define SALT_LENGTH 16 | |
int generateKeyFromPassword(char* passphrase, struct keyItem* item) | |
{ | |
int i; | |
unsigned char* salt = gcry_random_bytes(SALT_LENGTH, GCRY_STRONG_RANDOM); | |
char* keyBuffer; | |
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, SALT_LENGTH, | |
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