Skip to content

Instantly share code, notes, and snippets.

@stv0g
Last active February 4, 2021 01:27
Show Gist options
  • Select an option

  • Save stv0g/b5c90bc008b40f0ee4e2 to your computer and use it in GitHub Desktop.

Select an option

Save stv0g/b5c90bc008b40f0ee4e2 to your computer and use it in GitHub Desktop.
PKCS5_PBKDF2_HMAC_SHA1
#include <stdio.h>
#include <string.h>
#include <openssl/x509.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
int main(int argc, char *argv[])
{
char pass[1024]; // passphrase read from stdin
char salt[1024]; // salt
char result[1024]; // result
int salt_len; // salt length
int ic; // iteration counter
FILE *fp;
if (argc != 3) {
fprintf(stderr, "usage: %s salt_file iteration < passwd_file > binary_key_file\n", argv[0]);
exit(1);
}
ic = atoi(argv[2]);
fp = fopen(argv[1], "r");
if (!fp) {
fprintf(stderr, "error opening salt file: %s\n", argv[1]);
exit(2);
}
salt_len = fread(salt, 1, sizeof(salt), fp);
fclose(fp);
fgets(pass, 1024, stdin);
if (pass[strlen(pass)-1] == '\n')
pass[strlen(pass)-1] = '\0';
PKCS5_PBKDF2_HMAC_SHA1(pass, strlen(pass), (const unsigned char *) salt, salt_len, ic, 16, (unsigned char *) result);
fwrite(result, 1, 16, stdout);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment