/**
- * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2017 - 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return -1;
}
+ int iv_len_option = -1;
+
// right now use AES GCM only (could be further extended to CCM)
switch (op->info.algorithm)
{
case TEE_ALG_AES_GCM: {
+ iv_len_option = EVP_CTRL_GCM_SET_IVLEN;
switch (op->info.keySize) {
case 128: EVP_alg = EVP_aes_128_gcm; break;
case 192: EVP_alg = EVP_aes_192_gcm; break;
}
}
- ret = EVP_CipherInit(ctx, EVP_alg(), key->secret.buffer, (unsigned char*)iv,
+ ret = EVP_CipherInit(ctx, EVP_alg(), NULL, NULL,
+ (op->info.mode == TEE_MODE_ENCRYPT) ? 1 : 0);
+ if (ret != EVP_SUCCESS) {
+ LOGE(MODULE_SSF_LIB, "Failed to initialize cipher");
+ return ret;
+ }
+
+ if (iv_len_option >= 0) {
+ ret = EVP_CIPHER_CTX_ctrl(ctx, iv_len_option, iv_len, NULL);
+ if (ret != EVP_SUCCESS) {
+ LOGE(MODULE_SSF_LIB, "EVP_CIPHER_CTX_ctrl() failed");
+ return ret;
+ }
+ }
+
+ ret = EVP_CipherInit(ctx, NULL, key->secret.buffer, (unsigned char*)iv,
(op->info.mode == TEE_MODE_ENCRYPT) ? 1 : 0);
if (ret != EVP_SUCCESS) {
LOGE(MODULE_SSF_LIB, "Failed to initialize cipher");