Skip to content

Instantly share code, notes, and snippets.

@daviddahl
Created May 29, 2014 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daviddahl/b8edb58299707670b39a to your computer and use it in GitHub Desktop.
Save daviddahl/b8edb58299707670b39a to your computer and use it in GitHub Desktop.
WTF-fails.c
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