change included header in aes

Signed-off-by: xwb <xuwanbing1@huawei.com>
This commit is contained in:
xwb 2022-12-08 18:12:28 +08:00
parent 6331bf2750
commit d14f568370
6 changed files with 134 additions and 39 deletions

View File

@ -55,7 +55,6 @@ ohos_shared_library("crypto_framework_lib") {
deps = [
"//base/security/crypto_framework:crypto_openssl_plugin_lib",
"//base/security/crypto_framework/common:crypto_plugin_common",
"//third_party/openssl:libcrypto_shared",
]
external_deps = [

View File

@ -16,7 +16,6 @@
#include "cipher.h"
#include "aes_openssl.h"
#include "config.h"
#include "aes_openssl_common.h"
#include "securec.h"
#include "result.h"
#include "string.h"

View File

@ -23,7 +23,6 @@ framework_inc_path = [
"${base_path}/interfaces/innerkits/key",
"${base_path}/interfaces/innerkits/rand",
"${base_path}/common/inc",
"${plugin_path}/openssl_plugin/aes/inc",
"${plugin_path}/openssl_plugin/certificate/inc",
"${plugin_path}/openssl_plugin/crypto_operation/key_agreement/inc",
"${plugin_path}/openssl_plugin/crypto_operation/signature/inc",

View File

@ -13,31 +13,30 @@
* limitations under the License.
*/
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef HCF_AES_OPENSSL_COMMON_H
#define HCF_AES_OPENSSL_COMMON_H
#include <stdbool.h>
#include <openssl/evp.h>
#include "aes_openssl.h"
#include "detailed_iv_params.h"
#include "detailed_ccm_params.h"
#include "detailed_gcm_params.h"
#include "aes_openssl.h"
#include <openssl/evp.h>
typedef struct {
EVP_CIPHER_CTX *ctx;
enum HcfCryptoMode enc;
/* EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE need AEAD */
bool aead;
uint32_t updateLen;
unsigned char *iv;
uint32_t ivLen;
/* GCM, CCM only */
unsigned char *aad;
uint32_t aadLen;
unsigned char *tag;
uint32_t tagLen;
} CipherData;
#ifdef __cplusplus
extern "C" {

View File

@ -15,26 +15,8 @@
#ifndef HCF_AES_OPENSSL_H
#define HCF_AES_OPENSSL_H
#include <stdbool.h>
#include <openssl/evp.h>
#include "params_parser.h"
#include "cipher_factory_spi.h"
typedef struct {
EVP_CIPHER_CTX *ctx;
enum HcfCryptoMode enc;
/* EVP_CIPH_GCM_MODE, EVP_CIPH_CCM_MODE need AEAD */
bool aead;
uint32_t updateLen;
unsigned char *iv;
uint32_t ivLen;
/* GCM, CCM only */
unsigned char *aad;
uint32_t aadLen;
unsigned char *tag;
uint32_t tagLen;
} CipherData;
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -46,6 +46,7 @@ constexpr int32_t CCM_IV_LEN = 7; // CCM
constexpr int32_t CCM_AAD_LEN = 8;
constexpr int32_t CCM_TAG_LEN = 12;
constexpr int32_t PLAINTEXT_LEN = 13;
constexpr int32_t AES_KEY_SIZE = 128;
class CryptoAesCipherTest : public testing::Test {
public:
@ -6611,4 +6612,120 @@ HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest144, TestSize.Level0)
}
EXPECT_NE(ret, 0);
}
HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest145, TestSize.Level0)
{
int ret = 0;
HcfSymKeyGeneratorSpi *generator = nullptr;
HcfSymKey *key = nullptr;
SymKeyAttr attr = { .algo = HCF_ALG_AES, .keySize = AES_KEY_SIZE };
ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator);
if (ret != 0) {
LOGE("HcfSymKeyGeneratorSpiCreate failed!%d", ret);
goto CLEAR_UP;
}
ret = generator->engineGenerateSymmKey(nullptr, &key);
if (ret != 0) {
LOGE("engineGenerateSymmKey failed!");
}
CLEAR_UP:
HcfObjDestroy(key);
HcfObjDestroy(generator);
EXPECT_NE(ret, 0);
}
HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest146, TestSize.Level0)
{
int ret = 0;
HcfSymKeyGeneratorSpi *generator = nullptr;
HcfSymKey *key = nullptr;
HcfCipher *cipher = nullptr;
SymKeyAttr attr = { .algo = HCF_ALG_AES, .keySize = AES_KEY_SIZE };
ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher);
if (ret != 0) {
LOGE("HcfCipherCreate failed!");
goto CLEAR_UP;
}
ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator);
if (ret != 0) {
LOGE("HcfSymKeyGeneratorSpiCreate failed!%d", ret);
goto CLEAR_UP;
}
ret = generator->engineGenerateSymmKey(reinterpret_cast<HcfSymKeyGeneratorSpi *>(cipher), &key);
if (ret != 0) {
LOGE("engineGenerateSymmKey failed!");
}
CLEAR_UP:
HcfObjDestroy(key);
HcfObjDestroy(generator);
HcfObjDestroy(cipher);
EXPECT_NE(ret, 0);
}
HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest147, TestSize.Level0)
{
int ret = 0;
HcfSymKeyGeneratorSpi *generator = nullptr;
HcfSymKey *key = nullptr;
uint8_t keyMaterial[] = {
0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56,
0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c
};
HcfBlob keyTmpBlob = { .data = keyMaterial, .len = KEY_MATERIAL_LEN };
SymKeyAttr attr = { .algo = HCF_ALG_AES, .keySize = AES_KEY_SIZE };
ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator);
if (ret != 0) {
LOGE("HcfSymKeyGeneratorSpiCreate failed!%d", ret);
goto CLEAR_UP;
}
ret = generator->engineConvertSymmKey(nullptr, &keyTmpBlob, &key);
if (ret != 0) {
LOGE("engineConvertSymmKey failed!");
}
CLEAR_UP:
HcfObjDestroy(key);
HcfObjDestroy(generator);
EXPECT_NE(ret, 0);
}
HWTEST_F(CryptoAesCipherTest, CryptoAesCipherTest148, TestSize.Level0)
{
int ret = 0;
HcfSymKeyGeneratorSpi *generator = nullptr;
HcfSymKey *key = nullptr;
uint8_t keyMaterial[] = {
0xba, 0x3b, 0xc2, 0x71, 0x21, 0x1e, 0x30, 0x56,
0xad, 0x47, 0xfc, 0x5a, 0x46, 0x39, 0xee, 0x7c
};
HcfBlob keyTmpBlob = { .data = keyMaterial, .len = KEY_MATERIAL_LEN };
HcfCipher *cipher = nullptr;
SymKeyAttr attr = { .algo = HCF_ALG_AES, .keySize = AES_KEY_SIZE };
ret = HcfCipherCreate("AES128|ECB|PKCS5", &cipher);
if (ret != 0) {
LOGE("HcfCipherCreate failed!");
goto CLEAR_UP;
}
ret = HcfSymKeyGeneratorSpiCreate(&attr, &generator);
if (ret != 0) {
LOGE("HcfSymKeyGeneratorSpiCreate failed!%d", ret);
goto CLEAR_UP;
}
ret = generator->engineConvertSymmKey(reinterpret_cast<HcfSymKeyGeneratorSpi *>(cipher), &keyTmpBlob, &key);
if (ret != 0) {
LOGE("engineConvertSymmKey failed!");
}
CLEAR_UP:
HcfObjDestroy(key);
HcfObjDestroy(generator);
HcfObjDestroy(cipher);
EXPECT_NE(ret, 0);
}
}