mirror of
https://gitee.com/openharmony/security_crypto_framework
synced 2024-11-23 15:00:04 +00:00
commit
47b43b4c11
@ -16,7 +16,8 @@ import("//base/security/crypto_framework/frameworks/frameworks.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("cj_cryptoframework_ffi") {
|
||||
include_dirs = framework_inc_path
|
||||
include_dirs = [ "include" ]
|
||||
include_dirs += framework_inc_path
|
||||
|
||||
if (os_level == "standard") {
|
||||
sanitize = {
|
||||
@ -48,16 +49,26 @@ ohos_shared_library("cj_cryptoframework_ffi") {
|
||||
"napi:cj_bind_native",
|
||||
]
|
||||
sources = [
|
||||
"src/asy_key_generator_impl.cpp",
|
||||
"src/asy_key_spec_generator_impl.cpp",
|
||||
"src/cipher_impl.cpp",
|
||||
"src/crypto_ffi.cpp",
|
||||
"src/crypto_utils.cpp",
|
||||
"src/dh_key_util_impl.cpp",
|
||||
"src/ecc_key_util_impl.cpp",
|
||||
"src/kdf_impl.cpp",
|
||||
"src/key_agreement_impl.cpp",
|
||||
"src/key_impl.cpp",
|
||||
"src/key_pair_impl.cpp",
|
||||
"src/mac_impl.cpp",
|
||||
"src/md_impl.cpp",
|
||||
"src/pri_key_impl.cpp",
|
||||
"src/pub_key_impl.cpp",
|
||||
"src/random_impl.cpp",
|
||||
"src/sign_impl.cpp",
|
||||
"src/symkey_generator_impl.cpp",
|
||||
"src/symkey_impl.cpp",
|
||||
"src/sm2_crypto_util_impl.cpp",
|
||||
"src/sym_key_generator_impl.cpp",
|
||||
"src/sym_key_impl.cpp",
|
||||
"src/verify_impl.cpp",
|
||||
]
|
||||
} else {
|
||||
defines += [ "PREVIEWER" ]
|
||||
|
34
frameworks/cj/include/asy_key_generator_impl.h
Normal file
34
frameworks/cj/include/asy_key_generator_impl.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 ASY_KEY_GENERATOR_IMPL_H
|
||||
#define ASY_KEY_GENERATOR_IMPL_H
|
||||
|
||||
#include "asy_key_generator.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class AsyKeyGeneratorImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(AsyKeyGeneratorImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit AsyKeyGeneratorImpl(HcfAsyKeyGenerator *generator);
|
||||
~AsyKeyGeneratorImpl();
|
||||
HcfAsyKeyGenerator *GetAsyKeyGenerator();
|
||||
private:
|
||||
HcfAsyKeyGenerator *generator_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
34
frameworks/cj/include/asy_key_spec_generator_impl.h
Normal file
34
frameworks/cj/include/asy_key_spec_generator_impl.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 ASY_KEY_SPEC_GENERATOR_IMPL_H
|
||||
#define ASY_KEY_SPEC_GENERATOR_IMPL_H
|
||||
|
||||
#include "asy_key_generator.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class AsyKeyGeneratorBySpecImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(AsyKeyGeneratorBySpecImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit AsyKeyGeneratorBySpecImpl(HcfAsyKeyGeneratorBySpec *generator);
|
||||
~AsyKeyGeneratorBySpecImpl();
|
||||
HcfAsyKeyGeneratorBySpec *GetAsyKeyGeneratorBySpec();
|
||||
private:
|
||||
HcfAsyKeyGeneratorBySpec *generator_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -32,7 +32,7 @@ public:
|
||||
HcfResult CipherUpdate(HcfBlob *input, HcfBlob *output);
|
||||
HcfResult CipherDoFinal(HcfBlob *input, HcfBlob *output);
|
||||
HcfResult SetCipherSpec(CipherSpecItem item, HcfBlob pSource);
|
||||
HcfResult GetCipherSpecString(CipherSpecItem item, char **returnString);
|
||||
HcfResult GetCipherSpecString(CipherSpecItem item, char *returnString);
|
||||
HcfResult GetCipherSpecUint8Array(CipherSpecItem item, HcfBlob *returnUint8Array);
|
||||
const char *GetAlgorithm(int32_t* errCode);
|
||||
|
194
frameworks/cj/include/crypto_ffi.h
Normal file
194
frameworks/cj/include/crypto_ffi.h
Normal file
@ -0,0 +1,194 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 CRYPTO_FFI_H
|
||||
#define CRYPTO_FFI_H
|
||||
|
||||
#include "asy_key_generator_impl.h"
|
||||
#include "asy_key_spec_generator_impl.h"
|
||||
#include "cipher_impl.h"
|
||||
#include "dh_key_util_impl.h"
|
||||
#include "detailed_iv_params.h"
|
||||
#include "detailed_gcm_params.h"
|
||||
#include "detailed_ccm_params.h"
|
||||
#include "detailed_dsa_key_params.h"
|
||||
#include "detailed_ecc_key_params.h"
|
||||
#include "detailed_rsa_key_params.h"
|
||||
#include "detailed_alg_25519_key_params.h"
|
||||
#include "detailed_dh_key_params.h"
|
||||
#include "ecc_key_util_impl.h"
|
||||
#include "kdf_impl.h"
|
||||
#include "key_agreement_impl.h"
|
||||
#include "key_pair_impl.h"
|
||||
#include "mac_impl.h"
|
||||
#include "md_impl.h"
|
||||
#include "pri_key_impl.h"
|
||||
#include "pub_key_impl.h"
|
||||
#include "random_impl.h"
|
||||
#include "securec.h"
|
||||
#include "sign_impl.h"
|
||||
#include "sm2_crypto_util_impl.h"
|
||||
#include "sym_key_generator_impl.h"
|
||||
#include "sym_key_impl.h"
|
||||
#include "verify_impl.h"
|
||||
|
||||
extern "C" {
|
||||
typedef struct {
|
||||
HcfBlob iv;
|
||||
HcfBlob add;
|
||||
HcfBlob authTag;
|
||||
} CParamsSpec;
|
||||
|
||||
// random
|
||||
FFI_EXPORT int64_t FfiOHOSCreateRandom(int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSRandomGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT HcfBlob FfiOHOSGenerateRandom(int64_t id, int32_t numBytes, int32_t* errCode);
|
||||
FFI_EXPORT void FfiOHOSSetSeed(int64_t id, HcfBlob *seed, int32_t* errCode);
|
||||
|
||||
// md
|
||||
FFI_EXPORT int64_t FfiOHOSCreateMd(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSMdUpdate(int64_t id, HcfBlob *input);
|
||||
FFI_EXPORT HcfBlob FfiOHOSDigest(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT uint32_t FfiOHOSGetMdLength(int64_t id, int32_t* errCode);
|
||||
|
||||
// symkeygenerator
|
||||
FFI_EXPORT int64_t FfiOHOSCreateSymKeyGenerator(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGeneratorGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSGenerateSymKey(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSConvertKey(int64_t id, HcfBlob *key, int32_t* errCode);
|
||||
|
||||
// symkey
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGetFormat(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSSymKeyGetEncoded(int64_t id, HcfBlob *returnBlob);
|
||||
FFI_EXPORT void FfiOHOSClearMem(int64_t id);
|
||||
FFI_EXPORT void* FfiOHOSSymKeyGetHcfKey(int64_t id);
|
||||
|
||||
// cipher
|
||||
FFI_EXPORT int64_t FfiOHOSCreateCipher(char* transformation, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByIv(int64_t id, int32_t opMode, void* key, HcfBlob blob1);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByGcm(int64_t id, int32_t opMode, void* key, CParamsSpec spec);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByCcm(int64_t id, int32_t opMode, void* key, CParamsSpec spec);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitWithOutParams(int64_t id, int32_t opMode, void* key);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherUpdate(int64_t id, HcfBlob *input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherDoFinal(int64_t id, HcfBlob *input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FfiOHOSSetCipherSpec(int64_t id, int32_t item, HcfBlob pSource);
|
||||
FFI_EXPORT int32_t FfiOHOSGetCipherSpecString(int64_t id, int32_t item, char *returnString);
|
||||
FFI_EXPORT int32_t FfiOHOSGetCipherSpecUint8Array(int64_t id, int32_t item, HcfBlob *returnUint8Array);
|
||||
FFI_EXPORT const char *FfiOHOSCipherGetAlgName(int64_t id, int32_t* errCode);
|
||||
|
||||
// mac
|
||||
FFI_EXPORT int64_t FFiOHOSCryptoMacConstructor(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSCryptoMacInit(int64_t id, int64_t symKeyId);
|
||||
FFI_EXPORT int32_t FfiOHOSCryptoMacUpdate(int64_t id, HcfBlob *input);
|
||||
FFI_EXPORT HcfBlob FfiOHOSCryptoMacDoFinal(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT uint32_t FfiOHOSCryptoGetMacLength(int64_t id);
|
||||
|
||||
// sign
|
||||
FFI_EXPORT int64_t FFiOHOSCryptoSignConstructor(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FFiOHOSSignInit(int64_t sid, int64_t pid);
|
||||
FFI_EXPORT int32_t FFiOHOSSignUpdate(int64_t id, HcfBlob input);
|
||||
FFI_EXPORT int32_t FFiOHOSSignSign(int64_t id, HcfBlob *input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FFiOHOSSignSetSignSpecByNum(int64_t id, int32_t itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSSignSetSignSpecByArr(int64_t id, HcfBlob itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSSignGetSignSpecString(int64_t id, SignSpecItem item, char *itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSSignGetSignSpecNum(int64_t id, SignSpecItem item, int32_t *itemValue);
|
||||
|
||||
// verify
|
||||
FFI_EXPORT int64_t FFiOHOSVerifyConstructor(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifyInit(int64_t vid, int64_t pid);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifyUpdate(int64_t id, HcfBlob input);
|
||||
FFI_EXPORT bool FFiOHOSVerifyVerify(int64_t id, HcfBlob *data, HcfBlob signatureData, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifyRecover(int64_t id, HcfBlob input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifySetVerifySpecByNum(int64_t id, int32_t itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifySetVerifySpecByArr(int64_t id, HcfBlob itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifyGetVerifySpecString(int64_t id, SignSpecItem item, char *itemValue);
|
||||
FFI_EXPORT int32_t FFiOHOSVerifyGetVerifySpecNum(int64_t id, SignSpecItem item, int32_t *itemValue);
|
||||
|
||||
// asykeygenerator
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorConstructor(char *algName, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorGenerateKeyPair(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorConvertKey(int64_t id, HcfBlob *pubKey, HcfBlob *priKey, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorConvertPemKey(int64_t id, char *pubKey, char *priKey, int32_t *errCode);
|
||||
|
||||
// asykeyspecgenerator
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDsaCommonSpec(HcfDsaCommParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDsaPubKeySpec(HcfDsaPubKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDsaKeyPairSpec(HcfDsaKeyPairParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByEccCommonSpec(HcfEccCommParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByEccPriKeySpec(HcfEccPriKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByEccPubKeySpec(HcfEccPubKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByEccKeyPairSpec(HcfEccKeyPairParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByRsaPubKeySpec(HcfRsaPubKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByRsaKeyPairSpec(HcfRsaKeyPairParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByAlg25519PriKeySpec(HcfAlg25519PriKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByAlg25519PubKeySpec(HcfAlg25519PubKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByAlg25519KeyPairSpec(
|
||||
HcfAlg25519KeyPairParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDhPriKeySpec(HcfDhPriKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDhPubKeySpec(HcfDhPubKeyParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDhKeyPairSpec(HcfDhKeyPairParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorByDhCommonSpec(HcfDhCommParamsSpec *spec, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorBySpecGenerateKeyPair(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorBySpecGeneratePriKey(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSAsyKeyGeneratorBySpecGeneratePubKey(int64_t id, int32_t *errCode);
|
||||
|
||||
// prikey
|
||||
FFI_EXPORT HcfBlob FFiOHOSPriKeyGetEncoded(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT HcfBlob FFiOHOSPriKeyGetEncodedDer(int64_t id, char *format, int32_t *errCode);
|
||||
FFI_EXPORT char *FFiOHOSPriKeyGetEncodedPem(int64_t id, char *format, int32_t *errCode);
|
||||
FFI_EXPORT int32_t FFiOHOSPriKeyClearMem(int64_t id);
|
||||
FFI_EXPORT int FFiOHOSPriKeyGetAsyKeySpecByNum(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT char *FFiOHOSPriKeyGetAsyKeySpecByStr(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT HcfBigInteger FFiOHOSPriKeyGetAsyKeySpecByBigInt(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT const char *FfiOHOSPriKeyKeyGetFormat(int64_t id, int32_t* errCode);
|
||||
|
||||
// pubkey
|
||||
FFI_EXPORT HcfBlob FFiOHOSPubKeyGetEncoded(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT HcfBlob FFiOHOSPubKeyGetEncodedDer(int64_t id, char *format, int32_t *errCode);
|
||||
FFI_EXPORT char *FFiOHOSPubKeyGetEncodedPem(int64_t id, char *format, int32_t *errCode);
|
||||
FFI_EXPORT int FFiOHOSPubKeyGetAsyKeySpecByNum(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT char *FFiOHOSPubKeyGetAsyKeySpecByStr(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT HcfBigInteger FFiOHOSPubKeyGetAsyKeySpecByBigInt(int64_t id, int32_t itemType, int32_t *errCode);
|
||||
FFI_EXPORT const char *FfiOHOSPubKeyKeyGetFormat(int64_t id, int32_t* errCode);
|
||||
|
||||
// keypair
|
||||
FFI_EXPORT int64_t FFiOHOSKeyPairPubKey(int64_t id, int32_t *errCode);
|
||||
FFI_EXPORT int64_t FFiOHOSKeyPairPriKey(int64_t id, int32_t *errCode);
|
||||
|
||||
// kdf
|
||||
FFI_EXPORT int64_t FFiOHOSKdfConstructor(char *algName, int32_t *errCode);
|
||||
FFI_EXPORT int32_t FFiOHOSKdfGenerateSecretByPB(int64_t id, HcfPBKDF2ParamsSpec *params);
|
||||
FFI_EXPORT int32_t FFiOHOSKdfGenerateSecretByH(int64_t id, HcfHkdfParamsSpec *params);
|
||||
|
||||
// ecc_key_util
|
||||
FFI_EXPORT HcfEccCommParamsSpec *FFiOHOSECCKeyUtilGenECCCommonParamsSpec(char *curveName, int32_t *errCode);
|
||||
FFI_EXPORT HcfPoint FFiOHOSECCKeyUtilConvertPoint(char *curveName, HcfBlob encodedPoint, int32_t *errCode);
|
||||
FFI_EXPORT HcfBlob FFiOHOSECCKeyUtilGetEncodedPoint(
|
||||
char *curveName, HcfPoint point, char *format, int32_t *errCode);
|
||||
|
||||
// keyagreement
|
||||
FFI_EXPORT int64_t FFiOHOSKeyAgreementConstructor(char *algName, int32_t *errCode);
|
||||
FFI_EXPORT HcfBlob FFiOHOSKeyAgreementGenerateSecret(int64_t id, int64_t priId, int64_t pubId, int32_t *errCode);
|
||||
|
||||
// dh_key_util
|
||||
FFI_EXPORT HcfDhCommParamsSpec *FFiOHOSDHKeyUtilGenDHCommonParamsSpec(
|
||||
int32_t pLen, int32_t skLen, int32_t *errCode);
|
||||
|
||||
// sm2_crypto_util
|
||||
FFI_EXPORT HcfBlob FFiOHOSSm2CryptoUtilGenCipherTextBySpec(Sm2CipherTextSpec spec, char *mode, int32_t *errCode);
|
||||
FFI_EXPORT Sm2CipherTextSpec *FFiOHOSSm2CryptoUtilGetCipherTextSpec(HcfBlob input, char *mode, int32_t *errCode);
|
||||
}
|
||||
|
||||
#endif
|
31
frameworks/cj/include/dh_key_util_impl.h
Normal file
31
frameworks/cj/include/dh_key_util_impl.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 DH_KEY_UTIL_IMPL_H
|
||||
#define DH_KEY_UTIL_IMPL_H
|
||||
|
||||
#include "dh_key_util.h"
|
||||
#include "blob.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class DHKeyUtilImpl {
|
||||
public:
|
||||
explicit DHKeyUtilImpl();
|
||||
~DHKeyUtilImpl();
|
||||
static HcfDhCommParamsSpec *GenDHCommonParamsSpec(int32_t pLen, int32_t skLen, int32_t *errCode);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
33
frameworks/cj/include/ecc_key_util_impl.h
Normal file
33
frameworks/cj/include/ecc_key_util_impl.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 ECC_KEY_UTIL_IMPL_H
|
||||
#define ECC_KEY_UTIL_IMPL_H
|
||||
|
||||
#include "ecc_key_util.h"
|
||||
#include "blob.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class ECCKeyUtilImpl {
|
||||
public:
|
||||
explicit ECCKeyUtilImpl();
|
||||
~ECCKeyUtilImpl();
|
||||
static HcfEccCommParamsSpec *GenECCCommonParamsSpec(char *algName, int32_t *errCode);
|
||||
static HcfPoint ConvertPoint(char *curveName, HcfBlob encodedPoint, int32_t *errCode);
|
||||
static HcfBlob GetEncodedPoint(char *curveName, HcfPoint point, char *format, int32_t *errCode);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
39
frameworks/cj/include/kdf_impl.h
Normal file
39
frameworks/cj/include/kdf_impl.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 KDF_IMPL_H
|
||||
#define KDF_IMPL_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "blob.h"
|
||||
#include "kdf.h"
|
||||
#include "kdf_params.h"
|
||||
#include "detailed_pbkdf2_params.h"
|
||||
#include "detailed_hkdf_params.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class KdfImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(KdfImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit KdfImpl(HcfKdf *kdf);
|
||||
~KdfImpl();
|
||||
HcfKdf *GetKdf() const;
|
||||
int32_t GenerateSecret(HcfKdfParamsSpec *paramsSpec);
|
||||
private:
|
||||
HcfKdf *kdf = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
37
frameworks/cj/include/key_agreement_impl.h
Normal file
37
frameworks/cj/include/key_agreement_impl.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 KEY_AGREEMENT_IMPL_H
|
||||
#define KEY_AGREEMENT_IMPL_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "key_agreement.h"
|
||||
#include "pri_key.h"
|
||||
#include "pub_key.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class KeyAgreementImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(KeyAgreementImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit KeyAgreementImpl(HcfKeyAgreement *keyAgreement);
|
||||
~KeyAgreementImpl();
|
||||
HcfKeyAgreement *GetKeyAgreement();
|
||||
HcfBlob GenerateSecret(HcfPriKey *priKey, HcfPubKey *pubKey, int32_t *errCode);
|
||||
private:
|
||||
HcfKeyAgreement *keyAgreement_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -18,6 +18,7 @@
|
||||
#include "ffi_remote_data.h"
|
||||
#include "result.h"
|
||||
#include "key.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
36
frameworks/cj/include/key_pair_impl.h
Normal file
36
frameworks/cj/include/key_pair_impl.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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 KEY_PAIR_IMPL_H
|
||||
#define KEY_PAIR_IMPL_H
|
||||
|
||||
#include <cstdint>
|
||||
#include "key_pair.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class KeyPairImpl : public OHOS::FFI::FFIData {
|
||||
public:
|
||||
explicit KeyPairImpl(HcfKeyPair *keyPair);
|
||||
HcfKeyPair *GetHcfKeyPair();
|
||||
~KeyPairImpl();
|
||||
|
||||
private:
|
||||
HcfKeyPair *keyPair_ = nullptr;
|
||||
};
|
||||
} // namespace CryptoFramework
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -19,6 +19,8 @@
|
||||
#include "ffi_remote_data.h"
|
||||
#include "mac.h"
|
||||
#include "blob.h"
|
||||
#include "log.h"
|
||||
#include "result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
@ -18,6 +18,8 @@
|
||||
#include "ffi_remote_data.h"
|
||||
#include "md.h"
|
||||
#include "blob.h"
|
||||
#include "log.h"
|
||||
#include "result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
33
frameworks/cj/include/pri_key_impl.h
Normal file
33
frameworks/cj/include/pri_key_impl.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 PRI_KEY_IMPL_H
|
||||
#define PRI_KEY_IMPL_H
|
||||
|
||||
#include "key_impl.h"
|
||||
#include "pri_key.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class PriKeyImpl : public KeyImpl {
|
||||
DECL_TYPE(PriKeyImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit PriKeyImpl(HcfPriKey *priKey);
|
||||
~PriKeyImpl() override;
|
||||
HcfPriKey *GetPriKey();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
33
frameworks/cj/include/pub_key_impl.h
Normal file
33
frameworks/cj/include/pub_key_impl.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 PUB_KEY_IMPL_H
|
||||
#define PUB_KEY_IMPL_H
|
||||
|
||||
#include "key_impl.h"
|
||||
#include "pub_key.h"
|
||||
#include "ffi_remote_data.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class PubKeyImpl : public KeyImpl {
|
||||
DECL_TYPE(PubKeyImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit PubKeyImpl(HcfPubKey *pubKey);
|
||||
~PubKeyImpl() override;
|
||||
HcfPubKey *GetPubKey();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -18,6 +18,8 @@
|
||||
#include "ffi_remote_data.h"
|
||||
#include "rand.h"
|
||||
#include "blob.h"
|
||||
#include "result.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
@ -19,6 +19,8 @@
|
||||
#include "ffi_remote_data.h"
|
||||
#include "signature.h"
|
||||
#include "blob.h"
|
||||
#include "result.h"
|
||||
#include "pri_key.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
@ -27,6 +29,13 @@ class SignImpl : public OHOS::FFI::FFIData {
|
||||
public:
|
||||
explicit SignImpl(HcfSign *signObj);
|
||||
~SignImpl();
|
||||
HcfResult Init(HcfPriKey *priKey);
|
||||
HcfResult Update(HcfBlob *input);
|
||||
HcfResult Sign(HcfBlob *input, HcfBlob *output);
|
||||
HcfResult SetSignSpecByNum(int32_t itemValue);
|
||||
HcfResult SetSignSpecByArr(HcfBlob itemValue);
|
||||
HcfResult GetSignSpecString(SignSpecItem item, char *itemValue);
|
||||
HcfResult GetSignSpecNum(SignSpecItem item, int32_t *itemValue);
|
||||
|
||||
private:
|
||||
HcfSign *signObj_ = nullptr;
|
31
frameworks/cj/include/sm2_crypto_util_impl.h
Normal file
31
frameworks/cj/include/sm2_crypto_util_impl.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 SM2_CRYPTO_UTIL_IMPL_H
|
||||
#define SM2_CRYPTO_UTIL_IMPL_H
|
||||
|
||||
#include "sm2_crypto_util.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class Sm2CryptoUtilImpl {
|
||||
public:
|
||||
explicit Sm2CryptoUtilImpl();
|
||||
~Sm2CryptoUtilImpl();
|
||||
static HcfBlob GenCipherTextBySpec(Sm2CipherTextSpec spec, char *mode, int32_t *errCode);
|
||||
static Sm2CipherTextSpec *GetCipherTextSpec(HcfBlob input, char *mode, int32_t *errCode);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -12,13 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef SYMKEY_GENERATOR_IMPL_H
|
||||
#define SYMKEY_GENERATOR_IMPL_H
|
||||
#ifndef SYM_KEY_GENERATOR_IMPL_H
|
||||
#define SYM_KEY_GENERATOR_IMPL_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "sym_key.h"
|
||||
#include "result.h"
|
||||
#include "sym_key_generator.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
@ -12,12 +12,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef SYMKEY_IMPL_H
|
||||
#define SYMKEY_IMPL_H
|
||||
#ifndef SYM_KEY_IMPL_H
|
||||
#define SYM_KEY_IMPL_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "sym_key.h"
|
||||
#include "key_impl.h"
|
||||
#include "result.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
43
frameworks/cj/include/verify_impl.h
Normal file
43
frameworks/cj/include/verify_impl.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 VERIFY_IMPL_H
|
||||
#define VERIFY_IMPL_H
|
||||
|
||||
#include "ffi_remote_data.h"
|
||||
#include "pub_key.h"
|
||||
#include "signature.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
class VerifyImpl : public OHOS::FFI::FFIData {
|
||||
DECL_TYPE(VerifyImpl, OHOS::FFI::FFIData)
|
||||
public:
|
||||
explicit VerifyImpl(HcfVerify *verify);
|
||||
~VerifyImpl();
|
||||
HcfVerify *GetVerify();
|
||||
HcfResult Init(HcfPubKey *pubKey);
|
||||
HcfResult Update(HcfBlob *input);
|
||||
bool Verify(HcfBlob *data, HcfBlob signatureData, int32_t *errCode);
|
||||
HcfResult Recover(HcfBlob input, HcfBlob *output);
|
||||
HcfResult SetVerifySpecByNum(int32_t itemValue);
|
||||
HcfResult SetVerifySpecByArr(HcfBlob itemValue);
|
||||
HcfResult GetVerifySpecString(SignSpecItem item, char *itemValue);
|
||||
HcfResult GetVerifySpecNum(SignSpecItem item, int32_t *itemValue);
|
||||
private:
|
||||
HcfVerify *verify_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
@ -1,28 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
#include "crypto_utils.h"
|
||||
|
||||
char* Utils::MallocCString(const std::string& origin)
|
||||
{
|
||||
if (origin.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
auto len = origin.length() + 1;
|
||||
char* res = static_cast<char*>(malloc(sizeof(char) * len));
|
||||
if (res == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return std::char_traits<char>::copy(res, origin.c_str(), len);
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
#include "asy_key_generator_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
AsyKeyGeneratorImpl::AsyKeyGeneratorImpl(HcfAsyKeyGenerator *generator)
|
||||
{
|
||||
this->generator_ = generator;
|
||||
}
|
||||
|
||||
AsyKeyGeneratorImpl::~AsyKeyGeneratorImpl()
|
||||
{
|
||||
HcfObjDestroy(this->generator_);
|
||||
}
|
||||
|
||||
HcfAsyKeyGenerator *AsyKeyGeneratorImpl::GetAsyKeyGenerator()
|
||||
{
|
||||
return this->generator_;
|
||||
}
|
||||
}
|
||||
}
|
34
frameworks/cj/src/asy_key_spec_generator_impl.cpp
Normal file
34
frameworks/cj/src/asy_key_spec_generator_impl.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
#include "asy_key_spec_generator_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
AsyKeyGeneratorBySpecImpl::AsyKeyGeneratorBySpecImpl(HcfAsyKeyGeneratorBySpec *generator)
|
||||
{
|
||||
this->generator_ = generator;
|
||||
}
|
||||
|
||||
AsyKeyGeneratorBySpecImpl::~AsyKeyGeneratorBySpecImpl()
|
||||
{
|
||||
HcfObjDestroy(this->generator_);
|
||||
}
|
||||
|
||||
HcfAsyKeyGeneratorBySpec *AsyKeyGeneratorBySpecImpl::GetAsyKeyGeneratorBySpec()
|
||||
{
|
||||
return this->generator_;
|
||||
}
|
||||
}
|
||||
}
|
@ -61,30 +61,27 @@ namespace OHOS {
|
||||
{
|
||||
if (cipher_ == nullptr) {
|
||||
LOGE("fail to get cipher obj!");
|
||||
return HCF_ERR_MALLOC;
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
HcfResult res = cipher_->setCipherSpecUint8Array(cipher_, item, pSource);
|
||||
return res;
|
||||
return cipher_->setCipherSpecUint8Array(cipher_, item, pSource);
|
||||
}
|
||||
|
||||
HcfResult CipherImpl::GetCipherSpecString(CipherSpecItem item, char **returnString)
|
||||
HcfResult CipherImpl::GetCipherSpecString(CipherSpecItem item, char *returnString)
|
||||
{
|
||||
if (cipher_ == nullptr) {
|
||||
LOGE("fail to get cipher obj!");
|
||||
return HCF_ERR_MALLOC;
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
HcfResult res = cipher_->getCipherSpecString(cipher_, item, returnString);
|
||||
return res;
|
||||
return cipher_->getCipherSpecString(cipher_, item, &returnString);
|
||||
}
|
||||
|
||||
HcfResult CipherImpl::GetCipherSpecUint8Array(CipherSpecItem item, HcfBlob *returnUint8Array)
|
||||
{
|
||||
if (cipher_ == nullptr) {
|
||||
LOGE("fail to get cipher obj!");
|
||||
return HCF_ERR_MALLOC;
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
HcfResult res = cipher_->getCipherSpecUint8Array(cipher_, item, returnUint8Array);
|
||||
return res;
|
||||
return cipher_->getCipherSpecUint8Array(cipher_, item, returnUint8Array);
|
||||
}
|
||||
|
||||
const char *CipherImpl::GetAlgorithm(int32_t* errCode)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 CRYPTO_FFI_H
|
||||
#define CRYPTO_FFI_H
|
||||
|
||||
#include "cj_common_ffi.h"
|
||||
#include "blob.h"
|
||||
#include "cipher.h"
|
||||
#include "algorithm_parameter.h"
|
||||
|
||||
extern "C" {
|
||||
typedef struct {
|
||||
HcfBlob iv;
|
||||
HcfBlob add;
|
||||
HcfBlob authTag;
|
||||
} CParamsSpec;
|
||||
|
||||
// random
|
||||
FFI_EXPORT int64_t FfiOHOSCreateRandom(int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSRandomGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT HcfBlob FfiOHOSGenerateRandom(int64_t id, int32_t numBytes, int32_t* errCode);
|
||||
FFI_EXPORT void FfiOHOSSetSeed(int64_t id, HcfBlob *seed, int32_t* errCode);
|
||||
|
||||
// md
|
||||
FFI_EXPORT int64_t FfiOHOSCreateMd(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSMdUpdate(int64_t id, HcfBlob *input);
|
||||
FFI_EXPORT HcfBlob FfiOHOSDigest(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT uint32_t FfiOHOSGetMdLength(int64_t id, int32_t* errCode);
|
||||
|
||||
// symkeygenerator
|
||||
FFI_EXPORT int64_t FfiOHOSCreateSymKeyGenerator(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGeneratorGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSGenerateSymKey(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int64_t FfiOHOSConvertKey(int64_t id, HcfBlob *key, int32_t* errCode);
|
||||
|
||||
// symkey
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGetAlgName(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT const char *FfiOHOSSymKeyGetFormat(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSSymKeyGetEncoded(int64_t id, HcfBlob *returnBlob);
|
||||
FFI_EXPORT void FfiOHOSClearMem(int64_t id);
|
||||
FFI_EXPORT void* FfiOHOSSymKeyGetHcfKey(int64_t id);
|
||||
|
||||
// cipher
|
||||
FFI_EXPORT int64_t FfiOHOSCreateCipher(char* transformation, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByIv(int64_t id, int32_t opMode, void* key, HcfBlob blob1);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByGcm(int64_t id, int32_t opMode, void* key, CParamsSpec spec);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitByCcm(int64_t id, int32_t opMode, void* key, CParamsSpec spec);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherInitWithOutParams(int64_t id, int32_t opMode, void* key);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherUpdate(int64_t id, HcfBlob *input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FfiOHOSCipherDoFinal(int64_t id, HcfBlob *input, HcfBlob *output);
|
||||
FFI_EXPORT int32_t FfiOHOSSetCipherSpec(int64_t id, int32_t item, HcfBlob pSource);
|
||||
FFI_EXPORT int32_t FfiOHOSGetCipherSpecString(int64_t id, int32_t item, char **returnString);
|
||||
FFI_EXPORT int32_t FfiOHOSGetCipherSpecUint8Array(int64_t id, int32_t item, HcfBlob *returnUint8Array);
|
||||
FFI_EXPORT const char *FfiOHOSCipherGetAlgName(int64_t id, int32_t* errCode);
|
||||
|
||||
// mac
|
||||
FFI_EXPORT int64_t FFiOHOSCryptoMacConstructor(char* algName, int32_t* errCode);
|
||||
FFI_EXPORT int32_t FfiOHOSCryptoMacInit(int64_t id, int64_t symKeyId);
|
||||
FFI_EXPORT int32_t FfiOHOSCryptoMacUpdate(int64_t id, HcfBlob *input);
|
||||
FFI_EXPORT HcfBlob FfiOHOSCryptoMacDoFinal(int64_t id, int32_t* errCode);
|
||||
FFI_EXPORT uint32_t FfiOHOSGCryptoGetMacLength(int64_t id);
|
||||
|
||||
// sign
|
||||
FFI_EXPORT int64_t FFiOHOSCryptoSignConstructor(char* algName, int32_t* errCode);
|
||||
}
|
||||
|
||||
#endif
|
31
frameworks/cj/src/dh_key_util_impl.cpp
Normal file
31
frameworks/cj/src/dh_key_util_impl.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "dh_key_util_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
DHKeyUtilImpl::DHKeyUtilImpl() {}
|
||||
|
||||
DHKeyUtilImpl::~DHKeyUtilImpl() {}
|
||||
|
||||
HcfDhCommParamsSpec *DHKeyUtilImpl::GenDHCommonParamsSpec(int32_t pLen, int32_t skLen, int32_t *errCode)
|
||||
{
|
||||
HcfDhCommParamsSpec *dhCommParamsSpec = nullptr;
|
||||
*errCode = HcfDhKeyUtilCreate(pLen, skLen, &dhCommParamsSpec);
|
||||
return dhCommParamsSpec;
|
||||
}
|
||||
}
|
||||
}
|
45
frameworks/cj/src/ecc_key_util_impl.cpp
Normal file
45
frameworks/cj/src/ecc_key_util_impl.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "ecc_key_util_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
ECCKeyUtilImpl::ECCKeyUtilImpl() {}
|
||||
|
||||
ECCKeyUtilImpl::~ECCKeyUtilImpl() {}
|
||||
|
||||
HcfEccCommParamsSpec *ECCKeyUtilImpl::GenECCCommonParamsSpec(char *algName, int32_t *errCode)
|
||||
{
|
||||
HcfEccCommParamsSpec *eccCommParamsSpec = nullptr;
|
||||
*errCode = HcfEccKeyUtilCreate(algName, &eccCommParamsSpec);
|
||||
return eccCommParamsSpec;
|
||||
}
|
||||
|
||||
HcfPoint ECCKeyUtilImpl::ConvertPoint(char *curveName, HcfBlob encodedPoint, int32_t *errCode)
|
||||
{
|
||||
HcfPoint point;
|
||||
*errCode = HcfConvertPoint(curveName, &encodedPoint, &point);
|
||||
return point;
|
||||
}
|
||||
|
||||
HcfBlob ECCKeyUtilImpl::GetEncodedPoint(char *curveName, HcfPoint point, char *format, int32_t *errCode)
|
||||
{
|
||||
HcfBlob returnBlob;
|
||||
*errCode = HcfGetEncodedPoint(curveName, &point, format, &returnBlob);
|
||||
return returnBlob;
|
||||
}
|
||||
}
|
||||
}
|
44
frameworks/cj/src/kdf_impl.cpp
Normal file
44
frameworks/cj/src/kdf_impl.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "kdf_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
KdfImpl::KdfImpl(HcfKdf *kdfObj)
|
||||
{
|
||||
this->kdf = kdfObj;
|
||||
}
|
||||
|
||||
KdfImpl::~KdfImpl()
|
||||
{
|
||||
HcfObjDestroy(this->kdf);
|
||||
this->kdf = nullptr;
|
||||
}
|
||||
|
||||
HcfKdf *KdfImpl::GetKdf() const
|
||||
{
|
||||
return this->kdf;
|
||||
}
|
||||
|
||||
int32_t KdfImpl::GenerateSecret(HcfKdfParamsSpec *paramsSpec)
|
||||
{
|
||||
if (this->kdf == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->kdf->generateSecret(kdf, paramsSpec);
|
||||
}
|
||||
}
|
||||
}
|
47
frameworks/cj/src/key_agreement_impl.cpp
Normal file
47
frameworks/cj/src/key_agreement_impl.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "key_agreement_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
KeyAgreementImpl::KeyAgreementImpl(HcfKeyAgreement *keyAgreement)
|
||||
{
|
||||
this->keyAgreement_ = keyAgreement;
|
||||
}
|
||||
|
||||
KeyAgreementImpl::~KeyAgreementImpl()
|
||||
{
|
||||
HcfObjDestroy(this->keyAgreement_);
|
||||
this->keyAgreement_ = nullptr;
|
||||
}
|
||||
|
||||
HcfKeyAgreement *KeyAgreementImpl::GetKeyAgreement()
|
||||
{
|
||||
return this->keyAgreement_;
|
||||
}
|
||||
|
||||
HcfBlob KeyAgreementImpl::GenerateSecret(HcfPriKey *priKey, HcfPubKey *pubKey, int32_t *errCode)
|
||||
{
|
||||
HcfBlob returnSecret = { .data = nullptr, .len = 0 };
|
||||
if (this->keyAgreement_ == nullptr || priKey == nullptr || pubKey == nullptr) {
|
||||
*errCode = HCF_INVALID_PARAMS;
|
||||
return returnSecret;
|
||||
}
|
||||
*errCode = this->keyAgreement_->generateSecret(keyAgreement_, priKey, pubKey, &returnSecret);
|
||||
return returnSecret;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "key_impl.h"
|
||||
#include "result.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
|
36
frameworks/cj/src/key_pair_impl.cpp
Normal file
36
frameworks/cj/src/key_pair_impl.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "key_pair_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
KeyPairImpl::KeyPairImpl(HcfKeyPair *keyPair)
|
||||
{
|
||||
this->keyPair_ = keyPair;
|
||||
}
|
||||
|
||||
KeyPairImpl::~KeyPairImpl()
|
||||
{
|
||||
HcfObjDestroy(this->keyPair_);
|
||||
this->keyPair_ = nullptr;
|
||||
}
|
||||
|
||||
HcfKeyPair *KeyPairImpl::GetHcfKeyPair()
|
||||
{
|
||||
return this->keyPair_;
|
||||
}
|
||||
}
|
||||
}
|
@ -14,8 +14,6 @@
|
||||
*/
|
||||
|
||||
#include "mac_impl.h"
|
||||
#include "log.h"
|
||||
#include "result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
|
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "md_impl.h"
|
||||
#include "log.h"
|
||||
#include "result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
|
@ -12,18 +12,17 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pri_key_impl.h"
|
||||
|
||||
#ifndef OHOS_CRYPTO_UTILS_H
|
||||
#define OHOS_CRYPTO_UTILS_H
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
PriKeyImpl::PriKeyImpl(HcfPriKey *priKey) : KeyImpl(reinterpret_cast<HcfKey *>(priKey)) {}
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
PriKeyImpl::~PriKeyImpl() {}
|
||||
|
||||
#define FFI_EXPORT __attribute__((visibility("default")))
|
||||
|
||||
class FFI_EXPORT Utils {
|
||||
public:
|
||||
static char* MallocCString(const std::string& origin);
|
||||
};
|
||||
#endif
|
||||
HcfPriKey *PriKeyImpl::GetPriKey()
|
||||
{
|
||||
return reinterpret_cast<HcfPriKey *>(KeyImpl::GetHcfKey());
|
||||
}
|
||||
}
|
||||
}
|
28
frameworks/cj/src/pub_key_impl.cpp
Normal file
28
frameworks/cj/src/pub_key_impl.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
#include "pub_key_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
PubKeyImpl::PubKeyImpl(HcfPubKey *pubKey) : KeyImpl(reinterpret_cast<HcfKey *>(pubKey)) {}
|
||||
|
||||
PubKeyImpl::~PubKeyImpl() {}
|
||||
|
||||
HcfPubKey *PubKeyImpl::GetPubKey()
|
||||
{
|
||||
return reinterpret_cast<HcfPubKey *>(KeyImpl::GetHcfKey());
|
||||
}
|
||||
}
|
||||
}
|
@ -13,8 +13,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "random_impl.h"
|
||||
#include "result.h"
|
||||
#include "log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
|
@ -14,19 +14,73 @@
|
||||
*/
|
||||
|
||||
#include "sign_impl.h"
|
||||
#include "log.h"
|
||||
#include "result.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
SignImpl::SignImpl(HcfSign *signObj)
|
||||
{
|
||||
signObj_ = signObj;
|
||||
}
|
||||
namespace CryptoFramework {
|
||||
SignImpl::SignImpl(HcfSign *signObj)
|
||||
{
|
||||
signObj_ = signObj;
|
||||
}
|
||||
|
||||
SignImpl::~SignImpl()
|
||||
{
|
||||
HcfObjDestroy(this->signObj_);
|
||||
}
|
||||
SignImpl::~SignImpl()
|
||||
{
|
||||
HcfObjDestroy(this->signObj_);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::Init(HcfPriKey *priKey)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->init(signObj_, nullptr, priKey);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::Update(HcfBlob *input)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->update(signObj_, input);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::Sign(HcfBlob *input, HcfBlob *output)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->sign(signObj_, input, output);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::SetSignSpecByNum(int32_t itemValue)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->setSignSpecInt(signObj_, PSS_SALT_LEN_INT, itemValue);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::SetSignSpecByArr(HcfBlob itemValue)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->setSignSpecUint8Array(signObj_, SM2_USER_ID_UINT8ARR, itemValue);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::GetSignSpecString(SignSpecItem item, char *itemValue)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->getSignSpecString(signObj_, item, &itemValue);
|
||||
}
|
||||
|
||||
HcfResult SignImpl::GetSignSpecNum(SignSpecItem item, int32_t *itemValue)
|
||||
{
|
||||
if (this->signObj_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->signObj_->getSignSpecInt(signObj_, item, itemValue);
|
||||
}
|
||||
}
|
||||
}
|
38
frameworks/cj/src/sm2_crypto_util_impl.cpp
Normal file
38
frameworks/cj/src/sm2_crypto_util_impl.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "sm2_crypto_util_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
Sm2CryptoUtilImpl::Sm2CryptoUtilImpl() {}
|
||||
|
||||
Sm2CryptoUtilImpl::~Sm2CryptoUtilImpl() {}
|
||||
|
||||
HcfBlob Sm2CryptoUtilImpl::GenCipherTextBySpec(Sm2CipherTextSpec spec, char *mode, int32_t *errCode)
|
||||
{
|
||||
HcfBlob output = { 0 };
|
||||
*errCode = HcfGenCipherTextBySpec(&spec, mode, &output);
|
||||
return output;
|
||||
}
|
||||
|
||||
Sm2CipherTextSpec *Sm2CryptoUtilImpl::GetCipherTextSpec(HcfBlob input, char *mode, int32_t *errCode)
|
||||
{
|
||||
Sm2CipherTextSpec *returnSpec = nullptr;
|
||||
*errCode = HcfGetCipherTextSpec(&input, mode, &returnSpec);
|
||||
return returnSpec;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,8 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "symkey_generator_impl.h"
|
||||
#include "log.h"
|
||||
#include "sym_key_generator_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
@ -39,7 +38,6 @@ namespace OHOS {
|
||||
return algo;
|
||||
}
|
||||
|
||||
|
||||
HcfResult SymKeyGeneratorImpl::GenerateSymKey(HcfSymKey **symKey)
|
||||
{
|
||||
if (generator_ == nullptr) {
|
@ -12,9 +12,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "symkey_impl.h"
|
||||
#include "result.h"
|
||||
#include "log.h"
|
||||
#include "sym_key_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
96
frameworks/cj/src/verify_impl.cpp
Normal file
96
frameworks/cj/src/verify_impl.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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.
|
||||
*/
|
||||
|
||||
#include "verify_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace CryptoFramework {
|
||||
VerifyImpl::VerifyImpl(HcfVerify *verify)
|
||||
{
|
||||
this->verify_ = verify;
|
||||
}
|
||||
|
||||
VerifyImpl::~VerifyImpl()
|
||||
{
|
||||
HcfObjDestroy(this->verify_);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::Init(HcfPubKey *pubKey)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->init(verify_, nullptr, pubKey);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::Update(HcfBlob *input)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->update(verify_, input);
|
||||
}
|
||||
|
||||
bool VerifyImpl::Verify(HcfBlob *data, HcfBlob signatureData, int32_t *errCode)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
*errCode = HCF_INVALID_PARAMS;
|
||||
return false;
|
||||
}
|
||||
*errCode = HCF_SUCCESS;
|
||||
return this->verify_->verify(verify_, data, &signatureData);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::Recover(HcfBlob input, HcfBlob *output)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->recover(verify_, &input, output);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::SetVerifySpecByNum(int32_t itemValue)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->setVerifySpecInt(verify_, PSS_SALT_LEN_INT, itemValue);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::SetVerifySpecByArr(HcfBlob itemValue)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->setVerifySpecUint8Array(verify_, SM2_USER_ID_UINT8ARR, itemValue);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::GetVerifySpecString(SignSpecItem item, char *itemValue)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->getVerifySpecString(verify_, item, &itemValue);
|
||||
}
|
||||
|
||||
HcfResult VerifyImpl::GetVerifySpecNum(SignSpecItem item, int32_t *itemValue)
|
||||
{
|
||||
if (this->verify_ == nullptr) {
|
||||
return HCF_INVALID_PARAMS;
|
||||
}
|
||||
return this->verify_->getVerifySpecInt(verify_, item, itemValue);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user