Advertisement
coolnickname

Untitled

Feb 1st, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <openssl/x509.h>
  4. #include <openssl/evp.h>
  5. #include <openssl/hmac.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. unsigned char pass[1024]; // passphrase read from stdin
  10. unsigned char salt[1024]; // salt
  11. int salt_len; // salt length
  12. int ic; // iteration
  13. unsigned char result[1024]; // result
  14. FILE *fp_salt;
  15.  
  16. if ( argc != 3 ) {
  17. fprintf(stderr, "usage: %s salt_file iteration < passwd_file > binary_key_file \n", argv[0]);
  18. exit(1);
  19. }
  20.  
  21. ic = atoi(argv[2]);
  22.  
  23. fp_salt = fopen(argv[1], "r");
  24. if(!fp_salt) {
  25. fprintf(stderr, "error opening salt file: %s\n", argv[1]);
  26. exit(2);
  27. }
  28.  
  29. salt_len=0;
  30. int ch;
  31. while((ch = fgetc(fp_salt)) != EOF) {
  32. salt[salt_len++] = (unsigned char)ch;
  33. }
  34.  
  35. fclose(fp_salt);
  36.  
  37. fgets(pass, 1024, stdin);
  38. if ( pass[strlen(pass)-1] == '\n' )
  39. pass[strlen(pass)-1] = '\0';
  40.  
  41. PKCS5_PBKDF2_HMAC_SHA1(pass, strlen(pass), salt, salt_len, ic, 16, result);
  42.  
  43. fwrite(result, 1, 16, stdout);
  44.  
  45. return(0);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement