vuls: init at 0.27.0
[NixPkgs.git] / nixos / modules / system / boot / pbkdf2-sha512.c
blob67e989957ba6c70e5b09cb401fecd1dd56894ffe
1 #include <stdint.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <openssl/evp.h>
6 void hextorb(uint8_t* hex, uint8_t* rb)
8 while(sscanf(hex, "%2x", rb) == 1)
10 hex += 2;
11 rb += 1;
13 *rb = '\0';
16 int main(int argc, char** argv)
18 uint8_t k_user[2048];
19 uint8_t salt[2048];
20 uint8_t key[4096];
22 uint32_t key_length = atoi(argv[1]);
23 uint32_t iteration_count = atoi(argv[2]);
25 hextorb(argv[3], salt);
26 uint32_t salt_length = strlen(argv[3]) / 2;
28 fgets(k_user, 2048, stdin);
29 uint32_t k_user_length = strlen(k_user);
30 if(k_user[k_user_length - 1] == '\n') {
31 k_user[k_user_length - 1] = '\0';
34 PKCS5_PBKDF2_HMAC(k_user, k_user_length, salt, salt_length, iteration_count, EVP_sha512(), key_length, key);
35 fwrite(key, 1, key_length, stdout);
37 return 0;