OSDN Git Service

am 6efa9351: Merge "Don\'t use deprecated OpenSSL functions."
authorAlex Klyubin <klyubin@google.com>
Fri, 19 Sep 2014 23:02:26 +0000 (23:02 +0000)
committerAndroid Git Automerger <android-git-automerger@android.com>
Fri, 19 Sep 2014 23:02:26 +0000 (23:02 +0000)
* commit '6efa9351a257edc53ce07eb8c544ccf08efb64ae':
  Don't use deprecated OpenSSL functions.

1  2 
cryptfs.c

diff --cc cryptfs.c
+++ b/cryptfs.c
@@@ -1248,40 -897,14 +1248,41 @@@ static int encrypt_master_key(const cha
      unsigned char ikey[32+32] = { 0 }; /* Big enough to hold a 256 bit key and 256 bit IV */
      EVP_CIPHER_CTX e_ctx;
      int encrypted_len, final_len;
 +    int rc = 0;
  
 -    /* Turn the password into a key and IV that can decrypt the master key */
 +    /* Turn the password into an intermediate key and IV that can decrypt the master key */
      get_device_scrypt_params(crypt_ftr);
 -    scrypt(passwd, salt, ikey, crypt_ftr);
 +
 +    switch (crypt_ftr->kdf_type) {
 +    case KDF_SCRYPT_KEYMASTER_UNPADDED:
 +    case KDF_SCRYPT_KEYMASTER_BADLY_PADDED:
 +    case KDF_SCRYPT_KEYMASTER:
 +        if (keymaster_create_key(crypt_ftr)) {
 +            SLOGE("keymaster_create_key failed");
 +            return -1;
 +        }
 +
 +        if (scrypt_keymaster(passwd, salt, ikey, crypt_ftr)) {
 +            SLOGE("scrypt failed");
 +            return -1;
 +        }
 +        break;
 +
 +    case KDF_SCRYPT:
 +        if (scrypt(passwd, salt, ikey, crypt_ftr)) {
 +            SLOGE("scrypt failed");
 +            return -1;
 +        }
 +        break;
 +
 +    default:
 +        SLOGE("Invalid kdf_type");
 +        return -1;
 +    }
  
      /* Initialize the decryption engine */
-     if (! EVP_EncryptInit(&e_ctx, EVP_aes_128_cbc(), ikey, ikey+KEY_LEN_BYTES)) {
+     EVP_CIPHER_CTX_init(&e_ctx);
+     if (! EVP_EncryptInit_ex(&e_ctx, EVP_aes_128_cbc(), NULL, ikey, ikey+KEY_LEN_BYTES)) {
          SLOGE("EVP_EncryptInit failed\n");
          return -1;
      }
@@@ -1335,15 -938,12 +1336,16 @@@ static int decrypt_master_key_aux(char 
    EVP_CIPHER_CTX d_ctx;
    int decrypted_len, final_len;
  
 -  /* Turn the password into a key and IV that can decrypt the master key */
 -  kdf(passwd, salt, ikey, kdf_params);
 +  /* Turn the password into an intermediate key and IV that can decrypt the
 +     master key */
 +  if (kdf(passwd, salt, ikey, kdf_params)) {
 +    SLOGE("kdf failed");
 +    return -1;
 +  }
  
    /* Initialize the decryption engine */
-   if (! EVP_DecryptInit(&d_ctx, EVP_aes_128_cbc(), ikey, ikey+KEY_LEN_BYTES)) {
+   EVP_CIPHER_CTX_init(&d_ctx);
+   if (! EVP_DecryptInit_ex(&d_ctx, EVP_aes_128_cbc(), NULL, ikey, ikey+KEY_LEN_BYTES)) {
      return -1;
    }
    EVP_CIPHER_CTX_set_padding(&d_ctx, 0); /* Turn off padding as our data is block aligned */