Advertisement
Guest User

Untitled

a guest
Jun 6th, 2014
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. void compute_session_keys(uint8_t encryptkey[AES128_KEY_LEN],
  2.         uint8_t IV[AES128_KEY_LEN],
  3.         uint8_t integrity[AES128_KEY_LEN],
  4.         uint8_t master_key[AES128_KEY_LEN],
  5.         uint8_t encryption_salt[8]){
  6.  
  7.     uint8_t long_encryptkey[SHA256_DIGEST_LEN];
  8.     uint8_t long_IV[SHA256_DIGEST_LEN];
  9.     uint8_t long_integrity[SHA256_DIGEST_LEN];
  10.  
  11.     HMAC_SHA256_CTX ctx;
  12.  
  13.     HMAC_SHA256_Init(&ctx, master_key, sizeof(master_key));
  14.     HMAC_SHA256_Update(&ctx,encryption_salt, 8);
  15.     HMAC_SHA256_Update(&ctx, "encryption", 10);
  16.     HMAC_SHA256_Final(long_encryptkey, &ctx);
  17.  
  18.     HMAC_SHA256_Init(&ctx, master_key, sizeof(master_key));
  19.     HMAC_SHA256_Update(&ctx,encryption_salt, 8);
  20.     HMAC_SHA256_Update(&ctx, "IV", 2);
  21.     HMAC_SHA256_Final(long_IV, &ctx);
  22.  
  23.     HMAC_SHA256_Init(&ctx, master_key, sizeof(master_key));
  24.     HMAC_SHA256_Update(&ctx,encryption_salt, 8);
  25.     HMAC_SHA256_Update(&ctx, "integrity", 9);
  26.     HMAC_SHA256_Final(long_integrity, &ctx);
  27.  
  28.     memcpy(encryptkey, long_encryptkey, AES128_KEY_LEN);
  29.     memcpy(IV, long_IV, AES128_KEY_LEN);
  30.     memcpy(integrity, long_integrity, AES128_KEY_LEN);
  31.     ZERO(long_encryptkey);
  32.     ZERO(long_IV);
  33.     ZERO(long_integrity);
  34.     ZERO(ctx);
  35. }
  36.  
  37. void compute_session_keys_password (char *password, int iterations,
  38.         uint8_t encryptkey[16],
  39.         uint8_t IV[16],
  40.         uint8_t integrity[16],
  41.         uint8_t encryption_salt[8],
  42.         uint8_t password_salt[8]
  43.         ){
  44.  
  45.     uint8_t master_key[AES128_KEY_LEN];
  46.     /* compute the password hash */
  47.     PBKDF2_SHA256((uint8_t *)password, strlen(password), password_salt, 8, iterations,
  48.             master_key, sizeof(master_key));
  49. #ifdef CRYPTO_DEBUG
  50.     print_key("masterkey", master_key, sizeof(master_key));
  51. #endif
  52.     compute_session_keys(encryptkey, IV, integrity, master_key, encryption_salt);
  53.     ZERO(master_key);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement