From dc915300b3ee657456f8c75d7964ddf9e5989903 Mon Sep 17 00:00:00 2001 From: lcc Date: Wed, 30 Apr 2025 17:39:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E6=B3=95=E5=BA=93arkts=E9=9D=99?= =?UTF-8?q?=E6=80=81=E5=8C=96=E6=94=B9=E9=80=A0=E5=A2=9E=E5=8A=A0=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=AF=86=E9=92=A5=E5=8F=82=E6=95=B0=E7=94=9F=E6=88=90?= =?UTF-8?q?=E9=9D=9E=E5=AF=B9=E7=A7=B0=E5=AF=86=E9=92=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lcc --- frameworks/js/ani/BUILD.gn | 1 + ...rity.cryptoFramework.cryptoFramework.taihe | 212 +++++++- .../ani/inc/ani_asy_key_generator_by_spec.h | 42 ++ .../ani/src/ani_asy_key_generator_by_spec.cpp | 500 ++++++++++++++++++ ...y.cryptoFramework.cryptoFramework.impl.cpp | 51 +- .../test/test_asy_key_generator_by_spec.ets | 493 +++++++++++++++++ frameworks/js/ani/test/test_main.ets | 16 +- 7 files changed, 1292 insertions(+), 23 deletions(-) create mode 100644 frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h create mode 100644 frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp create mode 100644 frameworks/js/ani/test/test_asy_key_generator_by_spec.ets diff --git a/frameworks/js/ani/BUILD.gn b/frameworks/js/ani/BUILD.gn index 875d047..98b782e 100644 --- a/frameworks/js/ani/BUILD.gn +++ b/frameworks/js/ani/BUILD.gn @@ -43,6 +43,7 @@ taihe_shared_library("crypto_framework_ani") { sources = get_target_outputs(":run_taihe") sources += [ "${framework_path}/js/ani/src/ani_asy_key_generator.cpp", + "${framework_path}/js/ani/src/ani_asy_key_generator_by_spec.cpp", "${framework_path}/js/ani/src/ani_cipher.cpp", "${framework_path}/js/ani/src/ani_constructor.cpp", "${framework_path}/js/ani/src/ani_kdf.cpp", diff --git a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe index a6be60c..0f41ba2 100644 --- a/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe +++ b/frameworks/js/ani/idl/ohos.security.cryptoFramework.cryptoFramework.taihe @@ -81,6 +81,13 @@ interface Key { @get GetAlgName(): String; } +enum AsyKeySpecType: i32 { + COMMON_PARAMS_SPEC = 0, + PRIVATE_KEY_SPEC = 1, + PUBLIC_KEY_SPEC = 2, + KEY_PAIR_SPEC = 3 +} + enum AsyKeySpecEnum: i32 { DSA_P_BN = 101, DSA_Q_BN = 102, @@ -120,7 +127,7 @@ struct KeyEncodingConfig { } union OptKeySpec { - BIGINT: @bigint Array; + BIGINT: @bigint Array; STRING: String; INT32: i32; } @@ -272,3 +279,206 @@ interface Cipher { @get GetAlgName(): String; } function CreateCipher(transformation: String): Cipher; + +struct AsyKeySpec { + algName: String; + specType: AsyKeySpecType; +} + +struct DSACommonParamsSpec { + @extends base: AsyKeySpec; + p: @bigint Array; + q: @bigint Array; + g: @bigint Array; +} + +struct DSAPubKeySpec { + @extends base: AsyKeySpec; + params: DSACommonParamsSpec; + pk: @bigint Array; +} + +struct DSAKeyPairSpec { + @extends base: AsyKeySpec; + params: DSACommonParamsSpec; + sk: @bigint Array; + pk: @bigint Array; +} + +struct DSAAsyKeySpec { + @extends base: AsyKeySpec; + params: DSACommonParamsSpec; + sk: @bigint Array; +} + +struct ECCField { + fieldType: String; +} + +struct Point { + x: @bigint Array; + y: @bigint Array; +} + +struct ECCCommonParamsSpec { + @extends base: AsyKeySpec; + field: OptECField; + a: @bigint Array; + b: @bigint Array; + g: Point; + n: @bigint Array; + h: i32; +} + +struct ECCPriKeySpec { + @extends base: AsyKeySpec; + params: ECCCommonParamsSpec; + sk: @bigint Array; +} + +struct ECCPubKeySpec { + @extends base: AsyKeySpec; + params: ECCCommonParamsSpec; + pk: Point; +} + +struct ECCKeyPairSpec { + @extends base: AsyKeySpec; + params: ECCCommonParamsSpec; + sk: @bigint Array; + pk: Point; +} + +struct ECCAsyKeySpec { + @extends base: AsyKeySpec; + params: ECCCommonParamsSpec; + sk: @bigint Array; +} + +struct DHCommonParamsSpec { + @extends base: AsyKeySpec; + p: @bigint Array; + g: @bigint Array; + l: i32; +} + +struct DHPriKeySpec { + @extends base: AsyKeySpec; + params: DHCommonParamsSpec; + sk: @bigint Array; +} + +struct DHPubKeySpec { + @extends base: AsyKeySpec; + params: DHCommonParamsSpec; + pk: @bigint Array; +} + +struct DHKeyPairSpec { + @extends base: AsyKeySpec; + params: DHCommonParamsSpec; + sk: @bigint Array; + pk: @bigint Array; +} + +struct ED25519PriKeySpec { + @extends base: AsyKeySpec; + sk: @bigint Array; +} + +struct ED25519PubKeySpec { + @extends base: AsyKeySpec; + pk: @bigint Array; +} + +struct ED25519KeyPairSpec { + @extends base: AsyKeySpec; + sk: @bigint Array; + pk: @bigint Array; +} + +struct X25519PriKeySpec { + @extends base: AsyKeySpec; + sk: @bigint Array; +} + +struct X25519PubKeySpec { + @extends base: AsyKeySpec; + pk: @bigint Array; +} + +struct X25519KeyPairSpec { + @extends base: AsyKeySpec; + sk: @bigint Array; + pk: @bigint Array; +} + +struct RSACommonParamsSpec { + @extends base: AsyKeySpec; + n: @bigint Array; +} + +struct RSAPubKeySpec { + @extends base: AsyKeySpec; + params: RSACommonParamsSpec; + pk: @bigint Array; +} + +struct RSAKeyPairSpec { + @extends base: AsyKeySpec; + params: RSACommonParamsSpec; + sk: @bigint Array; + pk: @bigint Array; +} + +struct ECField { + fieldType: String; +} + +struct ECFieldFp { + @extends base: ECField; + p: @bigint Array; +} + +union OptECField { + ECFIELDFP: ECFieldFp; + ECFIELD: ECCField; +} + +union OptAsyKeySpec { + DSACOMMONPARAMSSPEC: DSACommonParamsSpec; + DSAPUBKEYSPEC: DSAPubKeySpec; + DSAKEYPAIRSPEC: DSAKeyPairSpec; + ECCCOMMONPARAMSSPEC: ECCCommonParamsSpec; + ECCPRIKEYSPEC: ECCPriKeySpec; + ECCPUBKEYSPEC: ECCPubKeySpec; + ECCKEYPAIRSPEC: ECCKeyPairSpec; + DHCOMMONPARAMSSPEC: DHCommonParamsSpec; + DHPRIKEYSPEC: DHPriKeySpec; + DHPUBKEYSPEC: DHPubKeySpec; + DHKEYPAIRSPEC: DHKeyPairSpec; + ED25519PRIKEYSPEC: ED25519PriKeySpec; + ED25519PUBKEYSPEC: ED25519PubKeySpec; + ED25519KEYPAIRSPEC: ED25519KeyPairSpec; + X25519PRIKEYSPEC: X25519PriKeySpec; + X25519PUBKEYSPEC: X25519PubKeySpec; + X25519KEYPAIRSPEC: X25519KeyPairSpec; + RSACOMMONPARAMSSPEC: RSACommonParamsSpec; + RSAPUBKEYSPEC: RSAPubKeySpec; + RSAKEYPAIRSPEC: RSAKeyPairSpec; + ASYKEYSPEC: AsyKeySpec; +} + +interface AsyKeyGeneratorBySpec { + @gen_async("generateKeyPair") + @gen_promise("generateKeyPair") + GenerateKeyPairSync(): KeyPair; + @gen_async("generatePriKey") + @gen_promise("generatePriKey") + GeneratePriKeySync(): PriKey; + @gen_async("generatePubKey") + @gen_promise("generatePubKey") + GeneratePubKeySync(): PubKey; + @get GetAlgName(): String; +} +function CreateAsyKeyGeneratorBySpec(asyKeySpec: OptAsyKeySpec): AsyKeyGeneratorBySpec; \ No newline at end of file diff --git a/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h b/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h new file mode 100644 index 0000000..5d02857 --- /dev/null +++ b/frameworks/js/ani/inc/ani_asy_key_generator_by_spec.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025-2025 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 ANI_ASY_KEY_GENERATOR_BY_SPEC_H +#define ANI_ASY_KEY_GENERATOR_BY_SPEC_H + +#include "ani_common.h" +#include "asy_key_generator.h" + +namespace ANI::CryptoFramework { +using namespace taihe; +using namespace ohos::security::cryptoFramework::cryptoFramework; + +class AsyKeyGeneratorBySpecImpl { +public: + AsyKeyGeneratorBySpecImpl(); + explicit AsyKeyGeneratorBySpecImpl(HcfAsyKeyGeneratorBySpec *generator); + ~AsyKeyGeneratorBySpecImpl(); + + KeyPair GenerateKeyPairSync(); + PriKey GeneratePriKeySync(); + PubKey GeneratePubKeySync(); + string GetAlgName(); + +private: + HcfAsyKeyGeneratorBySpec *generator_ = nullptr; +}; +} // namespace ANI::CryptoFramework + +#endif // ANI_ASY_KEY_GENERATOR_BY_SPEC_H diff --git a/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp b/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp new file mode 100644 index 0000000..76a4c13 --- /dev/null +++ b/frameworks/js/ani/src/ani_asy_key_generator_by_spec.cpp @@ -0,0 +1,500 @@ +/* + * Copyright (c) 2025-2025 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 "ani_asy_key_generator_by_spec.h" +#include "ani_key_pair.h" +#include "ani_pri_key.h" +#include "ani_pub_key.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" + +using namespace taihe; +using namespace ohos::security::cryptoFramework::cryptoFramework; +using namespace ANI::CryptoFramework; + +// 添加算法名称常量定义 +namespace { +const std::string DSA_ALG_NAME = "DSA"; +const std::string ECC_ALG_NAME = "ECC"; +const std::string RSA_ALG_NAME = "RSA"; +const std::string DH_ALG_NAME = "DH"; +const std::string ED25519_ALG_NAME = "Ed25519"; +const std::string X25519_ALG_NAME = "X25519"; +const std::string SM2_ALG_NAME = "SM2"; + +void SetDSAKeyPairParamsSpecAttribute(DSAKeyPairSpec const& dsaParams, HcfDsaKeyPairParamsSpec &dsaKeyPairSpec) +{ + dsaKeyPairSpec.base.base.specType = HCF_KEY_PAIR_SPEC; + dsaKeyPairSpec.base.base.algName = const_cast(dsaParams.base.algName.c_str()); + dsaKeyPairSpec.base.p.data = dsaParams.params.p.data(); + dsaKeyPairSpec.base.p.len = dsaParams.params.p.size(); + dsaKeyPairSpec.base.q.data = dsaParams.params.q.data(); + dsaKeyPairSpec.base.q.len = dsaParams.params.q.size(); + dsaKeyPairSpec.base.g.data = dsaParams.params.g.data(); + dsaKeyPairSpec.base.g.len = dsaParams.params.g.size(); + dsaKeyPairSpec.pk.data = dsaParams.pk.data(); + dsaKeyPairSpec.pk.len = dsaParams.pk.size(); + dsaKeyPairSpec.sk.data = dsaParams.sk.data(); + dsaKeyPairSpec.sk.len = dsaParams.sk.size(); +} + +void SetDSAPubKeyParamsSpecAttribute(DSAPubKeySpec const& dsaParams, HcfDsaPubKeyParamsSpec &dsaPubKeySpec) +{ + dsaPubKeySpec.base.base.specType = HCF_PUBLIC_KEY_SPEC; + dsaPubKeySpec.base.base.algName = const_cast(dsaParams.base.algName.c_str()); + dsaPubKeySpec.base.p.data = dsaParams.params.p.data(); + dsaPubKeySpec.base.p.len = dsaParams.params.p.size(); + dsaPubKeySpec.base.q.data = dsaParams.params.q.data(); + dsaPubKeySpec.base.q.len = dsaParams.params.q.size(); + dsaPubKeySpec.base.g.data = dsaParams.params.g.data(); + dsaPubKeySpec.base.g.len = dsaParams.params.g.size(); + dsaPubKeySpec.pk.data = dsaParams.pk.data(); + dsaPubKeySpec.pk.len = dsaParams.pk.size(); +} + +void SetDSACommonParamsSpecAttribute(DSACommonParamsSpec const& dsaParams, HcfDsaCommParamsSpec &dsaCommonParamsSpec) +{ + dsaCommonParamsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; + dsaCommonParamsSpec.base.algName = const_cast(dsaParams.base.algName.c_str()); + dsaCommonParamsSpec.p.data = dsaParams.p.data(); + dsaCommonParamsSpec.p.len = dsaParams.p.size(); + dsaCommonParamsSpec.q.data = dsaParams.q.data(); + dsaCommonParamsSpec.q.len = dsaParams.q.size(); + dsaCommonParamsSpec.g.data = dsaParams.g.data(); + dsaCommonParamsSpec.g.len = dsaParams.g.size(); +} + +void SetECCKeyPairParamsSpecAttribute(ECCKeyPairSpec const& eccParams, HcfEccKeyPairParamsSpec &eccKeyPairSpec) +{ + eccKeyPairSpec.base.base.specType = HCF_KEY_PAIR_SPEC; + eccKeyPairSpec.base.base.algName = const_cast(eccParams.base.algName.c_str()); + if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELD) { + eccKeyPairSpec.base.field->fieldType = const_cast(eccParams.params.field.get_ECFIELD_ref().fieldType.c_str()); + } else if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELDFP) { + HcfECFieldFp* fieldFp = reinterpret_cast(eccKeyPairSpec.base.field); + fieldFp->base.fieldType = const_cast(eccParams.params.field.get_ECFIELDFP_ref().base.fieldType.c_str()); + fieldFp->p.data = eccParams.params.field.get_ECFIELDFP_ref().p.data(); + fieldFp->p.len = eccParams.params.field.get_ECFIELDFP_ref().p.size(); + } + eccKeyPairSpec.base.a.data = eccParams.params.a.data(); + eccKeyPairSpec.base.a.len = eccParams.params.a.size(); + eccKeyPairSpec.base.b.data = eccParams.params.b.data(); + eccKeyPairSpec.base.b.len = eccParams.params.b.size(); + eccKeyPairSpec.base.g.x.data = eccParams.params.g.x.data(); + eccKeyPairSpec.base.g.x.len = eccParams.params.g.x.size(); + eccKeyPairSpec.base.g.y.data = eccParams.params.g.y.data(); + eccKeyPairSpec.base.g.y.len = eccParams.params.g.y.size(); + eccKeyPairSpec.base.n.data = eccParams.params.n.data(); + eccKeyPairSpec.base.n.len = eccParams.params.n.size(); + eccKeyPairSpec.base.h = eccParams.params.h; + eccKeyPairSpec.pk.x.data = eccParams.pk.x.data(); + eccKeyPairSpec.pk.x.len = eccParams.pk.x.size(); + eccKeyPairSpec.pk.y.data = eccParams.pk.y.data(); + eccKeyPairSpec.pk.y.len = eccParams.pk.y.size(); + eccKeyPairSpec.sk.data = eccParams.sk.data(); + eccKeyPairSpec.sk.len = eccParams.sk.size(); +} + +void SetECCPubKeyParamsSpecAttribute(ECCPubKeySpec const& eccParams, HcfEccPubKeyParamsSpec &eccPubKeySpec) +{ + eccPubKeySpec.base.base.specType = HCF_PUBLIC_KEY_SPEC; + eccPubKeySpec.base.base.algName = const_cast(eccParams.base.algName.c_str()); + if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELD) { + eccPubKeySpec.base.field->fieldType = const_cast(eccParams.params.field.get_ECFIELD_ref().fieldType.c_str()); + } else if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELDFP) { + HcfECFieldFp* fieldFp = reinterpret_cast(eccPubKeySpec.base.field); + fieldFp->base.fieldType = const_cast(eccParams.params.field.get_ECFIELDFP_ref().base.fieldType.c_str()); + fieldFp->p.data = eccParams.params.field.get_ECFIELDFP_ref().p.data(); + fieldFp->p.len = eccParams.params.field.get_ECFIELDFP_ref().p.size(); + } + eccPubKeySpec.base.a.data = eccParams.params.a.data(); + eccPubKeySpec.base.a.len = eccParams.params.a.size(); + eccPubKeySpec.base.b.data = eccParams.params.b.data(); + eccPubKeySpec.base.b.len = eccParams.params.b.size(); + eccPubKeySpec.base.g.x.data = eccParams.params.g.x.data(); + eccPubKeySpec.base.g.x.len = eccParams.params.g.x.size(); + eccPubKeySpec.base.g.y.data = eccParams.params.g.y.data(); + eccPubKeySpec.base.g.y.len = eccParams.params.g.y.size(); + eccPubKeySpec.base.n.data = eccParams.params.n.data(); + eccPubKeySpec.base.n.len = eccParams.params.n.size(); + eccPubKeySpec.base.h = eccParams.params.h; + eccPubKeySpec.pk.x.data = eccParams.pk.x.data(); + eccPubKeySpec.pk.x.len = eccParams.pk.x.size(); + eccPubKeySpec.pk.y.data = eccParams.pk.y.data(); + eccPubKeySpec.pk.y.len = eccParams.pk.y.size(); +} + +void SetECCPriKeyParamsSpecAttribute(ECCPriKeySpec const& eccParams, HcfEccPriKeyParamsSpec &eccPriKeySpec) +{ + eccPriKeySpec.base.base.specType = HCF_PRIVATE_KEY_SPEC; + eccPriKeySpec.base.base.algName = const_cast(eccParams.base.algName.c_str()); + if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELD) { + eccPriKeySpec.base.field->fieldType = const_cast(eccParams.params.field.get_ECFIELD_ref().fieldType.c_str()); + } else if (eccParams.params.field.get_tag() == OptECField::tag_t::ECFIELDFP) { + HcfECFieldFp* fieldFp = reinterpret_cast(eccPriKeySpec.base.field); + fieldFp->base.fieldType = const_cast(eccParams.params.field.get_ECFIELDFP_ref().base.fieldType.c_str()); + fieldFp->p.data = eccParams.params.field.get_ECFIELDFP_ref().p.data(); + fieldFp->p.len = eccParams.params.field.get_ECFIELDFP_ref().p.size(); + } + eccPriKeySpec.base.a.data = eccParams.params.a.data(); + eccPriKeySpec.base.a.len = eccParams.params.a.size(); + eccPriKeySpec.base.b.data = eccParams.params.b.data(); + eccPriKeySpec.base.b.len = eccParams.params.b.size(); + eccPriKeySpec.base.g.x.data = eccParams.params.g.x.data(); + eccPriKeySpec.base.g.x.len = eccParams.params.g.x.size(); + eccPriKeySpec.base.g.y.data = eccParams.params.g.y.data(); + eccPriKeySpec.base.g.y.len = eccParams.params.g.y.size(); + eccPriKeySpec.base.n.data = eccParams.params.n.data(); + eccPriKeySpec.base.n.len = eccParams.params.n.size(); + eccPriKeySpec.base.h = eccParams.params.h; + eccPriKeySpec.sk.data = eccParams.sk.data(); + eccPriKeySpec.sk.len = eccParams.sk.size(); +} + +void SetECCCommonParamsSpecAttribute(ECCCommonParamsSpec const& eccParams, HcfEccCommParamsSpec &eccCommonParamsSpec) +{ + eccCommonParamsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; + eccCommonParamsSpec.base.algName = const_cast(eccParams.base.algName.c_str()); + + if (eccParams.field.get_tag() == OptECField::tag_t::ECFIELD) { + eccCommonParamsSpec.field->fieldType = const_cast(eccParams.field.get_ECFIELD_ref().fieldType.c_str()); + } else if (eccParams.field.get_tag() == OptECField::tag_t::ECFIELDFP) { + HcfECFieldFp* fieldFp = reinterpret_cast(eccCommonParamsSpec.field); + fieldFp->base.fieldType = const_cast(eccParams.field.get_ECFIELDFP_ref().base.fieldType.c_str()); + fieldFp->p.data = eccParams.field.get_ECFIELDFP_ref().p.data(); + fieldFp->p.len = eccParams.field.get_ECFIELDFP_ref().p.size(); + } + eccCommonParamsSpec.a.data = eccParams.a.data(); + eccCommonParamsSpec.a.len = eccParams.a.size(); + eccCommonParamsSpec.b.data = eccParams.b.data(); + eccCommonParamsSpec.b.len = eccParams.b.size(); + eccCommonParamsSpec.g.x.data = eccParams.g.x.data(); + eccCommonParamsSpec.g.x.len = eccParams.g.x.size(); + eccCommonParamsSpec.g.y.data = eccParams.g.y.data(); + eccCommonParamsSpec.g.y.len = eccParams.g.y.size(); + eccCommonParamsSpec.n.data = eccParams.n.data(); + eccCommonParamsSpec.n.len = eccParams.n.size(); + eccCommonParamsSpec.h = eccParams.h; +} + +void SetRSAKeyPairParamsSpecAttribute(RSAKeyPairSpec const& rsaParams, HcfRsaKeyPairParamsSpec &rsaKeyPairSpec) +{ + rsaKeyPairSpec.base.base.specType = HCF_KEY_PAIR_SPEC; + rsaKeyPairSpec.base.base.algName = const_cast(rsaParams.base.algName.c_str()); + rsaKeyPairSpec.base.n.data = rsaParams.params.n.data(); + rsaKeyPairSpec.base.n.len = rsaParams.params.n.size(); + rsaKeyPairSpec.pk.data = rsaParams.pk.data(); + rsaKeyPairSpec.pk.len = rsaParams.pk.size(); + rsaKeyPairSpec.sk.data = rsaParams.sk.data(); + rsaKeyPairSpec.sk.len = rsaParams.sk.size(); +} + +void SetRSAPubKeyParamsSpecAttribute(RSAPubKeySpec const& rsaParams, HcfRsaPubKeyParamsSpec &rsaPubKeySpec) +{ + rsaPubKeySpec.base.base.specType = HCF_PUBLIC_KEY_SPEC; + rsaPubKeySpec.base.base.algName = const_cast(rsaParams.base.algName.c_str()); + rsaPubKeySpec.base.n.data = rsaParams.params.n.data(); + rsaPubKeySpec.base.n.len = rsaParams.params.n.size(); + rsaPubKeySpec.pk.data = rsaParams.pk.data(); + rsaPubKeySpec.pk.len = rsaParams.pk.size(); +} + +void SetRSACommonParamsSpecAttribute(RSACommonParamsSpec const& rsaParams, HcfRsaCommParamsSpec &rsaCommonParamsSpec) +{ + rsaCommonParamsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; + rsaCommonParamsSpec.base.algName = const_cast(rsaParams.base.algName.c_str()); + rsaCommonParamsSpec.n.data = rsaParams.n.data(); + rsaCommonParamsSpec.n.len = rsaParams.n.size(); +} + +void SetEd25519KeyPairParamsSpecAttribute(ED25519KeyPairSpec const& ed25519Params, HcfAlg25519KeyPairParamsSpec &ed25519KeyPairSpec) +{ + ed25519KeyPairSpec.base.specType = HCF_KEY_PAIR_SPEC; + ed25519KeyPairSpec.base.algName = const_cast(ed25519Params.base.algName.c_str()); + ed25519KeyPairSpec.pk.data = ed25519Params.pk.data(); + ed25519KeyPairSpec.pk.len = ed25519Params.pk.size(); + ed25519KeyPairSpec.sk.data = ed25519Params.sk.data(); + ed25519KeyPairSpec.sk.len = ed25519Params.sk.size(); +} + +void SetEd25519PubKeyParamsSpecAttribute(ED25519PubKeySpec const& ed25519Params, HcfAlg25519PubKeyParamsSpec &ed25519PubKeySpec) +{ + ed25519PubKeySpec.base.specType = HCF_PUBLIC_KEY_SPEC; + ed25519PubKeySpec.base.algName = const_cast(ed25519Params.base.algName.c_str()); + ed25519PubKeySpec.pk.data = ed25519Params.pk.data(); + ed25519PubKeySpec.pk.len = ed25519Params.pk.size(); +} + +void SetEd25519PriKeyParamsSpecAttribute(ED25519PriKeySpec const& ed25519Params, HcfAlg25519PriKeyParamsSpec &ed25519PriKeySpec) +{ + ed25519PriKeySpec.base.specType = HCF_PRIVATE_KEY_SPEC; + ed25519PriKeySpec.base.algName = const_cast(ed25519Params.base.algName.c_str()); + ed25519PriKeySpec.sk.data = ed25519Params.sk.data(); + ed25519PriKeySpec.sk.len = ed25519Params.sk.size(); +} + +void SetX25519KeyPairParamsSpecAttribute(X25519KeyPairSpec const& x25519Params, HcfAlg25519KeyPairParamsSpec &x25519KeyPairSpec) +{ + x25519KeyPairSpec.base.specType = HCF_KEY_PAIR_SPEC; + x25519KeyPairSpec.base.algName = const_cast(x25519Params.base.algName.c_str()); + x25519KeyPairSpec.pk.data = x25519Params.pk.data(); + x25519KeyPairSpec.pk.len = x25519Params.pk.size(); + x25519KeyPairSpec.sk.data = x25519Params.sk.data(); + x25519KeyPairSpec.sk.len = x25519Params.sk.size(); +} + +void SetX25519PubKeyParamsSpecAttribute(X25519PubKeySpec const& x25519Params, HcfAlg25519PubKeyParamsSpec &x25519PubKeySpec) +{ + x25519PubKeySpec.base.specType = HCF_PUBLIC_KEY_SPEC; + x25519PubKeySpec.base.algName = const_cast(x25519Params.base.algName.c_str()); + x25519PubKeySpec.pk.data = x25519Params.pk.data(); + x25519PubKeySpec.pk.len = x25519Params.pk.size(); +} + +void SetX25519PriKeyParamsSpecAttribute(X25519PriKeySpec const& x25519Params, HcfAlg25519PriKeyParamsSpec &x25519PriKeySpec) +{ + x25519PriKeySpec.base.specType = HCF_PRIVATE_KEY_SPEC; + x25519PriKeySpec.base.algName = const_cast(x25519Params.base.algName.c_str()); + x25519PriKeySpec.sk.data = x25519Params.sk.data(); + x25519PriKeySpec.sk.len = x25519Params.sk.size(); +} + +void SetDhKeyPairParamsSpecAttribute(DHKeyPairSpec const& dhParams, HcfDhKeyPairParamsSpec &dhKeyPairSpec) +{ + dhKeyPairSpec.base.base.specType = HCF_KEY_PAIR_SPEC; + dhKeyPairSpec.base.base.algName = const_cast(dhParams.base.algName.c_str()); + dhKeyPairSpec.base.p.data = dhParams.params.p.data(); + dhKeyPairSpec.base.p.len = dhParams.params.p.size(); + dhKeyPairSpec.base.g.data = dhParams.params.g.data(); + dhKeyPairSpec.base.g.len = dhParams.params.g.size(); + dhKeyPairSpec.base.length = dhParams.params.l; + dhKeyPairSpec.pk.data = dhParams.pk.data(); + dhKeyPairSpec.pk.len = dhParams.pk.size(); + dhKeyPairSpec.sk.data = dhParams.sk.data(); + dhKeyPairSpec.sk.len = dhParams.sk.size(); +} + +void SetDhPubKeyParamsSpecAttribute(DHPubKeySpec const& dhParams, HcfDhPubKeyParamsSpec &dhPubKeySpec) +{ + dhPubKeySpec.base.base.specType = HCF_PUBLIC_KEY_SPEC; + dhPubKeySpec.base.base.algName = const_cast(dhParams.base.algName.c_str()); + dhPubKeySpec.base.p.data = dhParams.params.p.data(); + dhPubKeySpec.base.p.len = dhParams.params.p.size(); + dhPubKeySpec.base.g.data = dhParams.params.g.data(); + dhPubKeySpec.base.g.len = dhParams.params.g.size(); + dhPubKeySpec.base.length = dhParams.params.l; + dhPubKeySpec.pk.data = dhParams.pk.data(); + dhPubKeySpec.pk.len = dhParams.pk.size(); +} + +void SetDhPriKeyParamsSpecAttribute(DHPriKeySpec const& dhParams, HcfDhPriKeyParamsSpec &dhPriKeySpec) +{ + dhPriKeySpec.base.base.specType = HCF_PRIVATE_KEY_SPEC; + dhPriKeySpec.base.base.algName = const_cast(dhParams.base.algName.c_str()); + dhPriKeySpec.base.p.data = dhParams.params.p.data(); + dhPriKeySpec.base.p.len = dhParams.params.p.size(); + dhPriKeySpec.base.g.data = dhParams.params.g.data(); + dhPriKeySpec.base.g.len = dhParams.params.g.size(); + dhPriKeySpec.base.length = dhParams.params.l; + dhPriKeySpec.sk.data = dhParams.sk.data(); + dhPriKeySpec.sk.len = dhParams.sk.size(); +} + +void SetDhCommonParamsSpecAttribute(DHCommonParamsSpec const& dhParams, HcfDhCommParamsSpec &dhCommonParamsSpec) +{ + dhCommonParamsSpec.base.specType = HCF_COMMON_PARAMS_SPEC; + dhCommonParamsSpec.base.algName = const_cast(dhParams.base.algName.c_str()); + dhCommonParamsSpec.p.data = dhParams.p.data(); + dhCommonParamsSpec.p.len = dhParams.p.size(); + dhCommonParamsSpec.g.data = dhParams.g.data(); + dhCommonParamsSpec.g.len = dhParams.g.size(); + dhCommonParamsSpec.length = dhParams.l; +} + +} // namespace + +namespace ANI::CryptoFramework { +AsyKeyGeneratorBySpecImpl::AsyKeyGeneratorBySpecImpl() {} + +AsyKeyGeneratorBySpecImpl::AsyKeyGeneratorBySpecImpl(HcfAsyKeyGeneratorBySpec *generator) : generator_(generator) {} + +AsyKeyGeneratorBySpecImpl::~AsyKeyGeneratorBySpecImpl() +{ + HcfObjDestroy(this->generator_); + this->generator_ = nullptr; +} + +KeyPair AsyKeyGeneratorBySpecImpl::GenerateKeyPairSync() +{ + HcfKeyPair *keyPair = nullptr; + HcfResult result = this->generator_->generateKeyPair(this->generator_, &keyPair); + if (result != HCF_SUCCESS) { + ANI_LOGE_THROW(result, "generateKeyPair failed"); + return make_holder(); + } + return make_holder(keyPair); +} + +PriKey AsyKeyGeneratorBySpecImpl::GeneratePriKeySync() +{ + HcfPriKey *priKey = nullptr; + HcfResult result = this->generator_->generatePriKey(this->generator_, &priKey); + if (result != HCF_SUCCESS) { + ANI_LOGE_THROW(result, "generatePriKey failed"); + return make_holder(); + } + return make_holder(priKey); +} + +PubKey AsyKeyGeneratorBySpecImpl::GeneratePubKeySync() +{ + HcfPubKey *pubKey = nullptr; + HcfResult result = this->generator_->generatePubKey(this->generator_, &pubKey); + if (result != HCF_SUCCESS) { + ANI_LOGE_THROW(result, "generatePubKey failed"); + return make_holder(); + } + return make_holder(pubKey); +} + +string AsyKeyGeneratorBySpecImpl::GetAlgName() +{ + if (this->generator_ == nullptr) { + ANI_LOGE_THROW(HCF_INVALID_PARAMS, "generator obj is nullptr!"); + return ""; + } + const char *algName = this->generator_->getAlgName(this->generator_); + return (algName == nullptr) ? "" : string(algName); +} + +AsyKeyGeneratorBySpec CreateAsyKeyGeneratorBySpec(OptAsyKeySpec const& asyKeySpec) +{ + HcfAsyKeyGeneratorBySpec *generator = nullptr; + const std::string &algName = asyKeySpec.get_ASYKEYSPEC_ref().algName.c_str(); + HcfAsyKeyParamsSpec *spec = nullptr; + HcfResult result = HCF_SUCCESS; + + HcfDsaKeyPairParamsSpec dsaKeyPairSpec = {}; + HcfDsaPubKeyParamsSpec dsaPubKeySpec = {}; + HcfDsaCommParamsSpec dsaCommonParamsSpec = {}; + HcfEccKeyPairParamsSpec eccKeyPairSpec = {}; + HcfEccPubKeyParamsSpec eccPubKeySpec = {}; + HcfEccPriKeyParamsSpec eccPriKeySpec = {}; + HcfEccCommParamsSpec eccCommonParamsSpec = {}; + HcfRsaKeyPairParamsSpec rsaKeyPairSpec = {}; + HcfRsaPubKeyParamsSpec rsaPubKeySpec = {}; + HcfRsaCommParamsSpec rsaCommonParamsSpec = {}; + HcfAlg25519KeyPairParamsSpec ed25519KeyPairSpec = {}; + HcfAlg25519PubKeyParamsSpec ed25519PubKeySpec = {}; + HcfAlg25519PriKeyParamsSpec ed25519PriKeySpec = {}; + HcfAlg25519KeyPairParamsSpec x25519KeyPairSpec = {}; + HcfAlg25519PubKeyParamsSpec x25519PubKeySpec = {}; + HcfAlg25519PriKeyParamsSpec x25519PriKeySpec = {}; + HcfDhCommParamsSpec dhCommonParamsSpec = {}; + HcfDhPubKeyParamsSpec dhPubKeySpec = {}; + HcfDhPriKeyParamsSpec dhPriKeySpec = {}; + HcfDhKeyPairParamsSpec dhKeyPairSpec = {}; + HcfECFieldFp ecFieldFp = {}; + HcfECField *ecField = &ecFieldFp.base; + + if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DSAKEYPAIRSPEC && algName == DSA_ALG_NAME) { + SetDSAKeyPairParamsSpecAttribute(asyKeySpec.get_DSAKEYPAIRSPEC_ref(), dsaKeyPairSpec); + spec = reinterpret_cast(&dsaKeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DSAPUBKEYSPEC && algName == DSA_ALG_NAME) { + SetDSAPubKeyParamsSpecAttribute(asyKeySpec.get_DSAPUBKEYSPEC_ref(), dsaPubKeySpec); + spec = reinterpret_cast(&dsaPubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DSACOMMONPARAMSSPEC && algName == DSA_ALG_NAME) { + SetDSACommonParamsSpecAttribute(asyKeySpec.get_DSACOMMONPARAMSSPEC_ref(), dsaCommonParamsSpec); + spec = reinterpret_cast(&dsaCommonParamsSpec); + } else if (algName == ECC_ALG_NAME || algName == SM2_ALG_NAME) { + if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ECCKEYPAIRSPEC) { + eccKeyPairSpec.base.field = ecField; + SetECCKeyPairParamsSpecAttribute(asyKeySpec.get_ECCKEYPAIRSPEC_ref(), eccKeyPairSpec); + spec = reinterpret_cast(&eccKeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ECCPUBKEYSPEC) { + eccPubKeySpec.base.field = ecField; + SetECCPubKeyParamsSpecAttribute(asyKeySpec.get_ECCPUBKEYSPEC_ref(), eccPubKeySpec); + spec = reinterpret_cast(&eccPubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ECCPRIKEYSPEC) { + eccPriKeySpec.base.field = ecField; + SetECCPriKeyParamsSpecAttribute(asyKeySpec.get_ECCPRIKEYSPEC_ref(), eccPriKeySpec); + spec = reinterpret_cast(&eccPriKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ECCCOMMONPARAMSSPEC) { + eccCommonParamsSpec.field = ecField; + SetECCCommonParamsSpecAttribute(asyKeySpec.get_ECCCOMMONPARAMSSPEC_ref(), eccCommonParamsSpec); + spec = reinterpret_cast(&eccCommonParamsSpec); + } + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::RSAKEYPAIRSPEC && algName == RSA_ALG_NAME) { + SetRSAKeyPairParamsSpecAttribute(asyKeySpec.get_RSAKEYPAIRSPEC_ref(), rsaKeyPairSpec); + spec = reinterpret_cast(&rsaKeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::RSAPUBKEYSPEC && algName == RSA_ALG_NAME) { + SetRSAPubKeyParamsSpecAttribute(asyKeySpec.get_RSAPUBKEYSPEC_ref(), rsaPubKeySpec); + spec = reinterpret_cast(&rsaPubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::RSACOMMONPARAMSSPEC && algName == RSA_ALG_NAME) { + SetRSACommonParamsSpecAttribute(asyKeySpec.get_RSACOMMONPARAMSSPEC_ref(), rsaCommonParamsSpec); + spec = reinterpret_cast(&rsaCommonParamsSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ED25519KEYPAIRSPEC && algName == ED25519_ALG_NAME) { + SetEd25519KeyPairParamsSpecAttribute(asyKeySpec.get_ED25519KEYPAIRSPEC_ref(), ed25519KeyPairSpec); + spec = reinterpret_cast(&ed25519KeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ED25519PUBKEYSPEC && algName == ED25519_ALG_NAME) { + SetEd25519PubKeyParamsSpecAttribute(asyKeySpec.get_ED25519PUBKEYSPEC_ref(), ed25519PubKeySpec); + spec = reinterpret_cast(&ed25519PubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::ED25519PRIKEYSPEC && algName == ED25519_ALG_NAME) { + SetEd25519PriKeyParamsSpecAttribute(asyKeySpec.get_ED25519PRIKEYSPEC_ref(), ed25519PriKeySpec); + spec = reinterpret_cast(&ed25519PriKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::X25519KEYPAIRSPEC && algName == X25519_ALG_NAME) { + SetX25519KeyPairParamsSpecAttribute(asyKeySpec.get_X25519KEYPAIRSPEC_ref(), x25519KeyPairSpec); + spec = reinterpret_cast(&x25519KeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::X25519PUBKEYSPEC && algName == X25519_ALG_NAME) { + SetX25519PubKeyParamsSpecAttribute(asyKeySpec.get_X25519PUBKEYSPEC_ref(), x25519PubKeySpec); + spec = reinterpret_cast(&x25519PubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::X25519PRIKEYSPEC && algName == X25519_ALG_NAME) { + SetX25519PriKeyParamsSpecAttribute(asyKeySpec.get_X25519PRIKEYSPEC_ref(), x25519PriKeySpec); + spec = reinterpret_cast(&x25519PriKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DHKEYPAIRSPEC && algName == DH_ALG_NAME) { + SetDhKeyPairParamsSpecAttribute(asyKeySpec.get_DHKEYPAIRSPEC_ref(), dhKeyPairSpec); + spec = reinterpret_cast(&dhKeyPairSpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DHPUBKEYSPEC && algName == DH_ALG_NAME) { + SetDhPubKeyParamsSpecAttribute(asyKeySpec.get_DHPUBKEYSPEC_ref(), dhPubKeySpec); + spec = reinterpret_cast(&dhPubKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DHPRIKEYSPEC && algName == DH_ALG_NAME) { + SetDhPriKeyParamsSpecAttribute(asyKeySpec.get_DHPRIKEYSPEC_ref(), dhPriKeySpec); + spec = reinterpret_cast(&dhPriKeySpec); + } else if (asyKeySpec.get_tag() == OptAsyKeySpec::tag_t::DHCOMMONPARAMSSPEC && algName == DH_ALG_NAME) { + SetDhCommonParamsSpecAttribute(asyKeySpec.get_DHCOMMONPARAMSSPEC_ref(), dhCommonParamsSpec); + spec = reinterpret_cast(&dhCommonParamsSpec); + } else { + ANI_LOGE_THROW(HCF_INVALID_PARAMS, "Unsupported algorithm or key type"); + return make_holder(); + } + + result = HcfAsyKeyGeneratorBySpecCreate(spec, &generator); + if (result != HCF_SUCCESS) { + ANI_LOGE_THROW(result, "HcfAsyKeyGeneratorBySpecCreate failed"); + return make_holder(); + } + + return make_holder(generator); +} + +} // namespace ANI::CryptoFramework + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_CreateAsyKeyGeneratorBySpec(CreateAsyKeyGeneratorBySpec); +// NOLINTEND diff --git a/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp b/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp index f70e570..a085fa0 100644 --- a/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp +++ b/frameworks/js/ani/src/impl/ohos.security.cryptoFramework.cryptoFramework.impl.cpp @@ -1,18 +1,3 @@ -/* - * Copyright (c) 2025-2025 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 "ohos.security.cryptoFramework.cryptoFramework.proj.hpp" #include "ohos.security.cryptoFramework.cryptoFramework.impl.hpp" #include "taihe/runtime.hpp" @@ -330,6 +315,35 @@ public: } }; +class AsyKeyGeneratorBySpecImpl { +public: + AsyKeyGeneratorBySpecImpl() { + // Don't forget to implement the constructor. + } + + KeyPair GenerateKeyPairSync() { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return make_holder(); + } + + PriKey GeneratePriKeySync() { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return make_holder(); + } + + PubKey GeneratePubKeySync() { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return make_holder(); + } + + string GetAlgName() { + TH_THROW(std::runtime_error, "GetAlgName not implemented"); + } +}; + Md CreateMd(string_view algName) { // The parameters in the make_holder function should be of the same type // as the parameters in the constructor of the actual implementation class. @@ -371,6 +385,12 @@ Cipher CreateCipher(string_view transformation) { // as the parameters in the constructor of the actual implementation class. return make_holder(); } + +AsyKeyGeneratorBySpec CreateAsyKeyGeneratorBySpec(OptAsyKeySpec const& asyKeySpec) { + // The parameters in the make_holder function should be of the same type + // as the parameters in the constructor of the actual implementation class. + return make_holder(); +} } // namespace // Since these macros are auto-generate, lint will cause false positive. @@ -382,4 +402,5 @@ TH_EXPORT_CPP_API_CreateSymKeyGenerator(CreateSymKeyGenerator); TH_EXPORT_CPP_API_CreateAsyKeyGenerator(CreateAsyKeyGenerator); TH_EXPORT_CPP_API_CreateKdf(CreateKdf); TH_EXPORT_CPP_API_CreateCipher(CreateCipher); +TH_EXPORT_CPP_API_CreateAsyKeyGeneratorBySpec(CreateAsyKeyGeneratorBySpec); // NOLINTEND diff --git a/frameworks/js/ani/test/test_asy_key_generator_by_spec.ets b/frameworks/js/ani/test/test_asy_key_generator_by_spec.ets new file mode 100644 index 0000000..f30476c --- /dev/null +++ b/frameworks/js/ani/test/test_asy_key_generator_by_spec.ets @@ -0,0 +1,493 @@ +/* + * Copyright (c) 2025-2025 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. + */ + +import cryptoFramework from "@ohos.security.cryptoFramework"; +import utils from "./test_utils"; + +function testRsaKeyPairSpec() { + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: BigInt('18478533428762900543234234052165078897463517255891144687945154912560048989428973394502225231475673469493935673076685067666412374336644121661834634328568716128398010589214210242328473325052801924104401463496007910632384934591085795699377924655299831802536043790200563589400549497200957189436092639854513167455276408048482654440065204807879459064738847828290321155399964745065695320081378543586408514487910074079683525564599260683751683646405712006009189387522266386739458730786983547267804377576955002031599762775938196698277063712871930011053484489532696001735479019329660933285131374020059017332898114690445944576549'), + algName: "RSA", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + }; + let rsaKeyPairSpec: cryptoFramework.RSAKeyPairSpec = { + params: rsaCommSpec, + sk: BigInt('13443367797579784472906374191268730591149473415683261174245648123593551364374079107625793014808865760593273402148759743980757062361671347127799770055874205659183190363964544152829383091462724002309744989516180102276157076935260650085211862081846405192552335715817353665234496972306343601367818009443948359153845315745091050102576900263842800919302048139131982882174917741979278274761193212951786209086143141198926907682548667292864640458922412016755237410423934679056828519631212431348847746741608018079408263762113939943821319770453677716209206087481504965313847534151150635490465180371871825563931626039033876425137'), + pk: BigInt('65537'), + algName: "RSA", + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + }; + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaKeyPairSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get rsa key pair result success!'); + } else { + console.error('get rsa key pair result fail!'); + } + } catch (e) { + console.error(`get rsa key pair result fail`+ e); + } +} + +function testRsaPubKeySpec() { + try { + let nIn = BigInt('18478533428762900543234234052165078897463517255891144687945154912560048989428973394502225231475673469493935673076685067666412374336644121661834634328568716128398010589214210242328473325052801924104401463496007910632384934591085795699377924655299831802536043790200563589400549497200957189436092639854513167455276408048482654440065204807879459064738847828290321155399964745065695320081378543586408514487910074079683525564599260683751683646405712006009189387522266386739458730786983547267804377576955002031599762775938196698277063712871930011053484489532696001735479019329660933285131374020059017332898114690445944576549'); + let eIn = BigInt('65537'); + let rsaCommSpec: cryptoFramework.RSACommonParamsSpec = { + n: nIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + let rsaPubKeySpec: cryptoFramework.RSAPubKeySpec = { + params: rsaCommSpec, + pk: eIn, + algName: 'RSA', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC + }; + let rsaGeneratorSpec = cryptoFramework.createAsyKeyGeneratorBySpec(rsaPubKeySpec); + let pubKey = rsaGeneratorSpec.generatePubKeySync(); + if (pubKey !== null) { + console.info('get rsa pub key result success!'); + } else { + console.error('get rsa pub key result fail!'); + } + + } catch (err) { + console.error("[error] testRsaPubKeySpec: " + err); + } +} + +function testEccCommonSpec() { + let fieldFp: cryptoFramework.ECFieldFp = { + fieldType: 'Fp', + p: BigInt('26959946667150639794667015087019630673557916260026308143510066298881') + } + let G: cryptoFramework.Point = { + x: BigInt('19277929113566293071110308034699488026831934219452440156649784352033'), + y: BigInt('19926808758034470970197974370888749184205991990603949537637343198772') + } + let eccCommonSpec: cryptoFramework.ECCCommonParamsSpec = { + algName: 'ECC', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + field: fieldFp, + a: BigInt('26959946667150639794667015087019630673557916260026308143510066298878'), + b: BigInt('18958286285566608000408668544493926415504680968679321075787234672564'), + g: G, + n: BigInt('26959946667150639794667015087019625940457807714424391721682722368061'), + h: 1 + } + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(eccCommonSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); // Generate an ECC key pair. + if (keyPair !== null) { + console.info('get key pair result success!'); + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function genEccPriKeySpec(xIn: bigint, yIn: bigint, aIn: bigint, bIn: bigint, pIn: bigint, + nIn: bigint, skIn: bigint): cryptoFramework.ECCPriKeySpec { + let field: cryptoFramework.ECFieldFp = { + fieldType: "Fp", + p: pIn + }; + let g: cryptoFramework.Point = { + x: xIn, + y: yIn + }; + let params: cryptoFramework.ECCCommonParamsSpec = { + field: field, + a: aIn, + b: bIn, + g: g, + n: nIn, + h: 1, + algName: "ECC", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC + }; + + let eccPriKeySpec: cryptoFramework.ECCPriKeySpec = { + params: params, + sk: skIn, + algName: "ECC", + specType: cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC + } + + return eccPriKeySpec; +} + +function testEccPriKeySpec() { + try { + let a: bigint = BigInt('26959946667150639794667015087019630673557916260026308143510066298878'); + let b: bigint = BigInt('18958286285566608000408668544493926415504680968679321075787234672564'); + let p: bigint = BigInt('26959946667150639794667015087019630673557916260026308143510066298881'); + let gX: bigint = BigInt('19277929113566293071110308034699488026831934219452440156649784352033'); + let gY: bigint = BigInt('19926808758034470970197974370888749184205991990603949537637343198772'); + let n: bigint = BigInt('26959946667150639794667015087019625940457807714424391721682722368061'); + let sk: bigint = BigInt('5958211279885070464920675858557961186290168537951857871398143937432'); + let eccPriKeySpec: cryptoFramework.ECCPriKeySpec = genEccPriKeySpec(gX, gY, a, b, p, n, sk); + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(eccPriKeySpec); + let priKey = generatorBySpec.generatePriKeySync(); + if (priKey !== null) { + console.info('get pri key result success!'); + } else { + console.error('get pri key result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function testSm2AsyKeyGeneratorBySpecSync() { + let fieldFp: cryptoFramework.ECFieldFp = { + fieldType: 'Fp', + p: BigInt('115792089210356248756420345214020892766250353991924191454421193933289684991999') + } + let G: cryptoFramework.Point = { + x: BigInt('22963146547237050559479531362550074578802567295341616970375194840604139615431'), + y: BigInt('85132369209828568825618990617112496413088388631904505083283536607588877201568') + }; + let sm2CommonParamsSpec: cryptoFramework.ECCCommonParamsSpec = { + algName: 'SM2', + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + field: fieldFp, + a: BigInt('115792089210356248756420345214020892766250353991924191454421193933289684991996'), + b: BigInt('18505919022281880113072981827955639221458448578012075254857346196103069175443'), + g: G, + n: BigInt('115792089210356248756420345214020892766061623724957744567843809356293439045923'), + h: 1 + }; + let sm2KeyPairSpec: cryptoFramework.ECCKeyPairSpec = { + algName: "SM2", + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + params: sm2CommonParamsSpec, + sk: BigInt('44865034034753528279576865928075303946258226058363947036220155068824166297716'), + pk: { + x: BigInt('47018839338924435050110785031351759007822306695053504711021879526595239871172'), + y: BigInt('96133091491756192384849037905113087024675932328759814704074462890629083635825') + }, + }; + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(sm2KeyPairSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get key pair result success!'); + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function getDsaCommonParamsSpec() { + let dsaCommonSpec: cryptoFramework.DSACommonParamsSpec = { + algName: "DSA", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + p: BigInt('20216857044408199932376494764599580727974045843915439721502938327198864725169044809813204952147752413624701213316563574475039748055346468178028625826092035313601316397655587341814674633664886284528623285325653023780498382484985239780177599233965758919159102159171718273864148712746797113414042595739717319731696609579150841956081703573371531465350272238016149836326224001841088360384367898447054044508716751610019070103182911963258176168025828573385356097755187338108832184592810352254309012721096301415240345204182050921863355546837078288047550266434252240460770780823402663658159753063957196734025229736568089530267'), + q: BigInt("867213547744821940284222002039163947454712583963"), + g: BigInt('5613702672530613039214328932450936898231965110898797142283557379865685939526291625923546497805448201404435739446597666135884235480978009652818140400499199787725528596067079382996609708472937555140407402057536621734502472274147757401975812355605352555485852816071445663853971471514294654628089019755771069636793509413303062371896404562622361502073164175883230960631373093173990688756272270068057277748993274083763062285503458176853646465605466871218985585055660513268314836972803355963121806305145618647016398490455324285041057243421484005529145312291069828934043829252492089834817718429184649225777566648238469211448'), + } + return dsaCommonSpec; +} + +function testDsaKeyPairSpec() { + let dsaCommonSpec = getDsaCommonParamsSpec(); + let dsaKeyPairSpec: cryptoFramework.DSAKeyPairSpec = { + algName: "DSA", + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + params: dsaCommonSpec, + sk: BigInt("287759317661555678461170451498783134028435263911"), + pk: BigInt('2974320683131303383593011718103778438067248821010128068603330890682877434550441281827351603361334506610914048116228047158214093207291532728181748676811787843316027859373324322706845202765204260289964362553170484033902517855022371250354897430992714094652148720967777508481265194493537489752556929433399052957551421373353304195295773950194626096020536543310165869112300390873999312126377909122302697760566740696966174036865456319235321580616931347110147760623816495949862659419251353007558185295016129505360845025009080058771674461404631229857893492589646335484050582997233310521320078311463229120799046072712830367694'), + }; + try { + let asyKeyPairSpec = cryptoFramework.createAsyKeyGeneratorBySpec(dsaKeyPairSpec); + let keyPair = asyKeyPairSpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get key pair result success!'); + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function testDsaPubKeySpec() { + let dsaCommonSpec = getDsaCommonParamsSpec(); + let dsaPubKeySpec: cryptoFramework.DSAPubKeySpec = { + algName: "DSA", + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, + params: dsaCommonSpec, + pk: BigInt('2974320683131303383593011718103778438067248821010128068603330890682877434550441281827351603361334506610914048116228047158214093207291532728181748676811787843316027859373324322706845202765204260289964362553170484033902517855022371250354897430992714094652148720967777508481265194493537489752556929433399052957551421373353304195295773950194626096020536543310165869112300390873999312126377909122302697760566740696966174036865456319235321580616931347110147760623816495949862659419251353007558185295016129505360845025009080058771674461404631229857893492589646335484050582997233310521320078311463229120799046072712830367694'), + }; + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(dsaPubKeySpec); + let pubKey = generatorBySpec.generatePubKeySync(); + if (pubKey !== null) { + console.info('get pub key result success!'); + } else { + console.error('get pub key result fail!'); + } + } catch (e) { + console.error(`get pub key result fail`+ e); + } +} + +function testX25519Keypair() { + let X25519CommonParamsSpec: cryptoFramework.X25519KeyPairSpec = { + algName: 'X25519', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + sk: BigInt("29134879258262849023515049744816060961199782584720683500454612335506387469072"), + pk: BigInt("31365230504828109670384793213724615431161708201306102578527937807624152602700") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(X25519CommonParamsSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get key pair result success!'); + // console.info('pub key: ' + keyPair.pubKey.getEncoded().data); sig11 + // console.info('pri key: ' + keyPair.priKey.getEncoded().data); sig11 + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function testX25519PubKeySpec() { + let X25519CommonParamsSpec: cryptoFramework.X25519PubKeySpec = { + algName: 'X25519', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, + pk: BigInt("31365230504828109670384793213724615431161708201306102578527937807624152602700") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(X25519CommonParamsSpec); + let pubKey = generatorBySpec.generatePubKeySync(); + if (pubKey !== null) { + console.info('get pub key result success!'); + } else { + console.error('get pub key result fail!'); + } + } catch (e) { + console.error(`get pub key result fail`+ e); + } +} + +function testX25519PriKeySpec() { + let X25519CommonParamsSpec: cryptoFramework.X25519PriKeySpec = { + algName: 'X25519', + specType: cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC, + sk: BigInt("29134879258262849023515049744816060961199782584720683500454612335506387469072") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(X25519CommonParamsSpec); + let priKey = generatorBySpec.generatePriKeySync(); + if (priKey !== null) { + console.info('get pri key result success!'); + } else { + console.error('get pri key result fail!'); + } + } catch (e) { + console.error(`get pri key result fail`+ e); + } +} + +function testEd25519Keypair() { + let ed25519CommonParamsSpec: cryptoFramework.ED25519KeyPairSpec = { + algName: 'Ed25519', + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + sk: BigInt("43647624700350065415986689228612485845309737963740022737531181108678917972381"), + pk: BigInt("11904025543770991234575058927481377460341025403748801838533672290029823089367") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(ed25519CommonParamsSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get key pair result success!'); + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function testEd25519PubKeySpec() { + let ed25519CommonParamsSpec: cryptoFramework.ED25519PubKeySpec = { + algName: 'Ed25519', + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, + pk: BigInt("11904025543770991234575058927481377460341025403748801838533672290029823089367") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(ed25519CommonParamsSpec); + let pubKey = generatorBySpec.generatePubKeySync(); + if (pubKey !== null) { + console.info('get pub key result success!'); + } else { + console.error('get pub key result fail!'); + } + } catch (e) { + console.error(`get pub key result fail`+ e); + } +} + +function testEd25519PriKeySpec() { + let ed25519CommonParamsSpec: cryptoFramework.ED25519PriKeySpec = { + algName: 'Ed25519', + specType: cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC, + sk: BigInt("43647624700350065415986689228612485845309737963740022737531181108678917972381") + }; + + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(ed25519CommonParamsSpec); + let priKey = generatorBySpec.generatePriKeySync(); + if (priKey !== null) { + console.info('get pri key result success!'); + } else { + console.error('get pri key result fail!'); + } + } catch (e) { + console.error(`get pri key result fail`+ e); + } +} + +function testDhKeyPairSpec() { + let dhCommonParamsSpec: cryptoFramework.DHCommonParamsSpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + p: BigInt("32317006071311007300338913926423828248817941241140239112842009751400741706634354222619689417363569347117901737909704191754605873209195028853758986185622153212175412514901774520270235796078236248884246189477587641105928646099411723245426622522193230540919037680524235519125679715870117001058055877651038861847280257976054903569732561526167081339361799541336476559160368317896729073178384589680639671900977202194168647225871031411336429319536193471636533209717077448227988588565369208645296636077250268955505928362751121174096972998068410554359584866583291642136218231078990999448652468262416972035911852507045361090559"), + g: BigInt("2"), + l: 0 + } + let dhKeyPairSpec: cryptoFramework.DHKeyPairSpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.KEY_PAIR_SPEC, + params: dhCommonParamsSpec, + sk: BigInt("9125804188382698099196638873877782224672995953990412992193262858452"), + pk: BigInt("11186379976064470039868881878113769238712700906887300917098479964653512172113576763135554305151065797508933293770633594570926859095962764040640418979407741972148004696002324963207972460619492683808125462174028180856400991828519744547190389466471420338820024463169406721124154332160520586677979673497445849107467994302619965190756490288108819919869861215042849364387924978117630413281355079408669272089515824403370917658313427949840680278654651434802556809089942821560326598440829155965101298935067032294104326983788672385588749202093591460978545538061369828131252628133733300047966728872928488819485461523493709658652"), + } + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(dhKeyPairSpec); + let keyPair = generatorBySpec.generateKeyPairSync(); + if (keyPair !== null) { + console.info('get key pair result success!'); + } else { + console.error('get key pair result fail!'); + } + } catch (e) { + console.error(`get key pair result fail`+ e); + } +} + +function testDhPubKeySpec() { + let dhCommonParamsSpec: cryptoFramework.DHCommonParamsSpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + p: BigInt("32317006071311007300338913926423828248817941241140239112842009751400741706634354222619689417363569347117901737909704191754605873209195028853758986185622153212175412514901774520270235796078236248884246189477587641105928646099411723245426622522193230540919037680524235519125679715870117001058055877651038861847280257976054903569732561526167081339361799541336476559160368317896729073178384589680639671900977202194168647225871031411336429319536193471636533209717077448227988588565369208645296636077250268955505928362751121174096972998068410554359584866583291642136218231078990999448652468262416972035911852507045361090559"), + g: BigInt("2"), + l: 0 + } + let dhPubKeySpec: cryptoFramework.DHPubKeySpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.PUBLIC_KEY_SPEC, + params: dhCommonParamsSpec, + pk: BigInt("11186379976064470039868881878113769238712700906887300917098479964653512172113576763135554305151065797508933293770633594570926859095962764040640418979407741972148004696002324963207972460619492683808125462174028180856400991828519744547190389466471420338820024463169406721124154332160520586677979673497445849107467994302619965190756490288108819919869861215042849364387924978117630413281355079408669272089515824403370917658313427949840680278654651434802556809089942821560326598440829155965101298935067032294104326983788672385588749202093591460978545538061369828131252628133733300047966728872928488819485461523493709658652"), + } + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(dhPubKeySpec); + let pubKey = generatorBySpec.generatePubKeySync(); + if (pubKey !== null) { + console.info('get pub key result success!'); + } else { + console.error('get pub key result fail!'); + } + } catch (e) { + console.error(`get pub key result fail`+ e); + } +} + +function testDhPriKeySpec() { + let dhCommonParamsSpec: cryptoFramework.DHCommonParamsSpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.COMMON_PARAMS_SPEC, + p: BigInt("32317006071311007300338913926423828248817941241140239112842009751400741706634354222619689417363569347117901737909704191754605873209195028853758986185622153212175412514901774520270235796078236248884246189477587641105928646099411723245426622522193230540919037680524235519125679715870117001058055877651038861847280257976054903569732561526167081339361799541336476559160368317896729073178384589680639671900977202194168647225871031411336429319536193471636533209717077448227988588565369208645296636077250268955505928362751121174096972998068410554359584866583291642136218231078990999448652468262416972035911852507045361090559"), + g: BigInt("2"), + l: 0 + } + let dhPriKeySpec: cryptoFramework.DHPriKeySpec = { + algName: "DH", + specType: cryptoFramework.AsyKeySpecType.PRIVATE_KEY_SPEC, + params: dhCommonParamsSpec, + sk: BigInt("9125804188382698099196638873877782224672995953990412992193262858452"), + } + try { + let generatorBySpec = cryptoFramework.createAsyKeyGeneratorBySpec(dhPriKeySpec); + let priKey = generatorBySpec.generatePriKeySync(); + if (priKey !== null) { + console.info('get pri key result success!'); + } else { + console.error('get pri key result fail!'); + } + } catch (e) { + console.error(`get pri key result fail`+ e); + } +} + +export function testAsyKeyGeneratorBySpec() { + console.log(">>>>>>>>>>>>>>>>>>>> testEccAsyKeyGeneratorBySpecSync"); + testEccCommonSpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testEccPriKeySpec"); + testEccPriKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testSm2AsyKeyGeneratorBySpecSync"); + testSm2AsyKeyGeneratorBySpecSync(); + console.log(">>>>>>>>>>>>>>>>>>>> testDsaKeyPairSpec"); + testDsaKeyPairSpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testDsaPubKeySpec"); + testDsaPubKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testRsaKeyPairSpec"); + testRsaKeyPairSpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testRsaPubKeySpec"); + testRsaPubKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testX25519Keypair"); + testX25519Keypair(); + console.log(">>>>>>>>>>>>>>>>>>>> testX25519PubKeySpec"); + testX25519PubKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testX25519PriKeySpec"); + testX25519PriKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testEd25519Keypair"); + testEd25519Keypair(); + console.log(">>>>>>>>>>>>>>>>>>>> testEd25519PubKeySpec"); + testEd25519PubKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testEd25519PriKeySpec"); + testEd25519PriKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testDhKeyPairSpec"); + testDhKeyPairSpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testDhPubKeySpec"); + testDhPubKeySpec(); + console.log(">>>>>>>>>>>>>>>>>>>> testDhPriKeySpec"); + testDhPriKeySpec(); +} \ No newline at end of file diff --git a/frameworks/js/ani/test/test_main.ets b/frameworks/js/ani/test/test_main.ets index 334b461..6704bae 100644 --- a/frameworks/js/ani/test/test_main.ets +++ b/frameworks/js/ani/test/test_main.ets @@ -20,13 +20,15 @@ import { testKdf } from "./test_kdf"; import { testAsyKeyGenerator } from "./test_asy_key_generator"; import { testSymKeyGenerator } from "./test_sym_key_generator"; import { testCipher } from "./test_cipher"; +import { testAsyKeyGeneratorBySpec } from "./test_asy_key_generator_by_spec"; function main() { - testRandom(); - testMd(); - testMac(); - testKdf(); - testAsyKeyGenerator(); - testSymKeyGenerator(); - testCipher(); + // testRandom(); + // testMd(); + // testMac(); + // testKdf(); + // testAsyKeyGenerator(); + // testSymKeyGenerator(); + // testCipher(); + testAsyKeyGeneratorBySpec(); } -- Gitee