From 5ed5150292a121fac5a476f3cc90a474863985f7 Mon Sep 17 00:00:00 2001 From: hu-jixiang1 Date: Mon, 13 Jun 2022 16:03:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E5=AF=86=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hu-jixiang1 Change-Id: I0d4065ea1453b9740a425d1c514fa44381b21f16 --- ...SecurityHuksAESBasicCallbackJsunit.test.js | 2 + ...SecurityHuksSM4BasicCallbackJsunit.test.js | 744 ++++++++++++++++++ .../entry/src/main/js/test/List.test.js | 1 + ...ityHuksCipherAESBasicPromiseJsunit.test.js | 2 + ...ityHuksCipherSM4BasicPromiseJsunit.test.js | 744 ++++++++++++++++++ .../entry/src/main/js/test/List.test.js | 1 + ...ecurityHuksHmacBasicCallbackJsunit.test.js | 110 +++ ...SecurityHuksHmacBasicPromiseJsunit.test.js | 54 ++ .../entry/src/main/js/test/List.test.js | 4 + ...uksSM2BasicAbort63KBCallbackJsunit.test.js | 43 + ...uksSM2BasicAbort65KBCallbackJsunit.test.js | 43 + ...ksSM2BasicFinish63KBCallbackJsunit.test.js | 61 ++ ...ksSM2BasicFinish65KBCallbackJsunit.test.js | 61 ++ .../entry/src/main/js/test/List.test.js | 4 + ...HuksSM2BasicAbort63KBPromiseJsunit.test.js | 43 + ...HuksSM2BasicAbort65KBPromiseJsunit.test.js | 37 + ...uksSM2BasicFinish63KBPromiseJsunit.test.js | 60 ++ ...uksSM2BasicFinish65KBPromiseJsunit.test.js | 60 ++ .../utils/param/cipher/publicCipherParam.js | 47 +- .../utils/param/hmac/publicHmacParam.js | 6 +- .../utils/param/publicParam.js | 8 +- .../param/signverify/publicSignverifyParam.js | 30 +- 22 files changed, 2161 insertions(+), 4 deletions(-) create mode 100755 security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js create mode 100755 security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js create mode 100755 security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js diff --git a/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksAESBasicCallbackJsunit.test.js b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksAESBasicCallbackJsunit.test.js index 64150fc82..eed32edf3 100644 --- a/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksAESBasicCallbackJsunit.test.js +++ b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksAESBasicCallbackJsunit.test.js @@ -360,3 +360,5 @@ describe('SecurityHuksCipherAESCallbackJsunit', function () { done(); }); }); + +export {publicCipherFunc, IV, updateResult}; diff --git a/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js new file mode 100755 index 000000000..ee34e7981 --- /dev/null +++ b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js @@ -0,0 +1,744 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it } from 'deccjsunit/index'; +import { HuksCipherSM4 } from '../../../../../../../utils/param/cipher/publicCipherParam'; +import { HksTag } from '../../../../../../../utils/param/publicParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicCipherFunc, IV, updateResult } from './SecurityHuksAESBasicCallbackJsunit.test'; + +const plainString48Bytes = 'Hks_SM4_Cipher_Test_000000000000000000000_string'; +const plainData48Bytes = stringToUint8Array(plainString48Bytes); +const plainString240Bytes = + 'Hks_SM4_Cipher_Test_00000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000000' + + '00000000000000000000000000000000000000000_string'; +const plainData240Bytes = stringToUint8Array(plainString240Bytes); + +let genHuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose + ), + inData: new Uint8Array(new Array()), +}; + +describe('SecurityHuksCipherSM4CallbackJsunit', function () { + // HKS_SUPPORT_SM4_CBC_NOPADDING + it('testCipherSM4001_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias001'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4001_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias001'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4002_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias002'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4002_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias002'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_CBC_PKCS7 + it('testCipherSM4003_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias003'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4003_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias003'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4004_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias004'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4004_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias004'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_CTR_NOPADDING + it('testCipherSM4005_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias005'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4005_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias005'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4006_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias006'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4006_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias006'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_ECB_NOPADDING + it('testCipherSM4007_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias007'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4007_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias007'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4008_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias008'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4008_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias008'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_ECB_PKCS7 + it('testCipherSM4009_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias009'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4009_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias009'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(updateResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4010_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias010'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4010_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias010'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/List.test.js b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/List.test.js index 9aba31c2a..d161ef0e4 100644 --- a/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/List.test.js +++ b/security/security_huks_basic/huks_cipher_callback_BasicTest/entry/src/main/js/test/List.test.js @@ -15,3 +15,4 @@ require('./Cipher/SecurityHuksAESBasicCallbackJsunit.test.js'); require('./Cipher/SecurityHuksRSABasicCallbackJsunit.test.js'); +require('./Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js'); \ No newline at end of file diff --git a/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js index c3a97ab71..7acc81f66 100644 --- a/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js +++ b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js @@ -291,3 +291,5 @@ describe('SecurityHuksCipherAESPromiseJsunit', function () { done(); }); }); + +export {publicCipherFunc, IV, updateResult}; \ No newline at end of file diff --git a/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js new file mode 100755 index 000000000..a156d2231 --- /dev/null +++ b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js @@ -0,0 +1,744 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { describe, it } from 'deccjsunit/index'; +import { HuksCipherSM4 } from '../../../../../../../utils/param/cipher/publicCipherParam'; +import { HksTag } from '../../../../../../../utils/param/publicParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicCipherFunc, IV, encryptedResult } from './SecurityHuksCipherAESBasicPromiseJsunit.test'; + +const plainString48Bytes = 'Hks_SM4_Cipher_Test_000000000000000000000_string'; +const plainData48Bytes = stringToUint8Array(plainString48Bytes); +const plainString240Bytes = + 'Hks_SM4_Cipher_Test_00000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000000' + + '0000000000000000000000000000000000000000000000000000000000000000' + + '00000000000000000000000000000000000000000_string'; +const plainData240Bytes = stringToUint8Array(plainString240Bytes); + +let genHuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose + ), + inData: new Uint8Array(new Array()), +}; + +describe('SecurityHuksCipherSM4PromiseJsunit', function () { + // HKS_SUPPORT_SM4_CBC_NOPADDING + it('testCipherSM4101_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias101'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4101_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias101'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4102_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias102'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4102_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias102'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_CBC_PKCS7 + it('testCipherSM4103_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias103'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4103_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias103'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4104_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias104'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4104_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias104'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_CTR_NOPADDING + it('testCipherSM4105_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias105'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4105_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias105'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4106_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias106'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4106_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias106'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECTR, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_ECB_NOPADDING + it('testCipherSM4107_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias107'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4107_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias107'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4108_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias108'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4108_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias108'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + // HKS_SUPPORT_SM4_ECB_PKCS7 + it('testCipherSM4109_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias109'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData48Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4109_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias109'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: plainData240Bytes, + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + true + ); + HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(encryptedResult), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'finish', + false + ); + done(); + }); + + it('testCipherSM4110_48', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias110'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData48Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); + + it('testCipherSM4110_240', 0, async function (done) { + const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias110'; + genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128); + genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB); + genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7); + let HuksOptions = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGPKCS7, + HuksCipherSM4.HuksKeySM4BLOCKMODEECB, + { tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) } + ), + inData: new Uint8Array(plainData240Bytes), + }; + await publicCipherFunc( + srcKeyAlias, + genHuksOptions, + HuksOptions, + 'abort', + true + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/List.test.js b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/List.test.js index bac533622..d494da0bd 100644 --- a/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/List.test.js +++ b/security/security_huks_basic/huks_cipher_promise_BasicTest/entry/src/main/js/test/List.test.js @@ -15,3 +15,4 @@ require('./Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js'); require('./Cipher/SecurityHuksCipherRSABasicPromiseJsunit.test.js'); +require('./Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js'); \ No newline at end of file diff --git a/security/security_huks_basic/huks_hmac_callback_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicCallbackJsunit.test.js b/security/security_huks_basic/huks_hmac_callback_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicCallbackJsunit.test.js index 8e842faa5..3ee77b1ec 100644 --- a/security/security_huks_basic/huks_hmac_callback_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicCallbackJsunit.test.js +++ b/security/security_huks_basic/huks_hmac_callback_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicCallbackJsunit.test.js @@ -271,3 +271,113 @@ describe('SecurityHuksHmacCallbackJsunit', function () { done(); }); }); +describe('SecurityHuksHmacCallbackJsunit', function () { + it('testHmacSHA1001', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSHA1KeyAlias001'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSHA1 + ), + inData: srcData63Kb, + }; + + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + + it('testHmacSHA1002', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSHA1KeyAlias002'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSHA1 + ), + inData: srcData63Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); + it('testHmacSHA1003', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSHA1KeyAlias003'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSHA1 + ), + inData: srcData65Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + it('testHmacSHA1004', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSHA1KeyAlias004'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSHA1 + ), + inData: srcData65Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); + it('testHmacSM3001', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias001'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData63Kb, + }; + + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + + it('testHmacSM3002', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias002'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData63Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); + it('testHmacSM3003', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias003'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData65Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + it('testHmacSM3004', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias004'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData65Kb, + }; + await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_hmac_promise_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicPromiseJsunit.test.js b/security/security_huks_basic/huks_hmac_promise_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicPromiseJsunit.test.js index 8deee00b0..d600fe50e 100644 --- a/security/security_huks_basic/huks_hmac_promise_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicPromiseJsunit.test.js +++ b/security/security_huks_basic/huks_hmac_promise_BasicTest/entry/src/main/js/test/HMAC/SecurityHuksHmacBasicPromiseJsunit.test.js @@ -179,4 +179,58 @@ describe('SecurityHuksHmacBasicPromiseJsunit', function () { await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort'); done(); }); + it('testHmacSM3001', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias001'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData63Kb, + }; + + await publicHmacFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + + it('testHmacSM3002', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias002'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData63Kb, + }; + await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); + it('testHmacSM3003', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias003'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData65Kb, + }; + await publicHmacFunc(srcKeyAlies, HuksOptions, 'finish'); + done(); + }); + it('testHmacSM3004', 0, async function (done) { + let srcKeyAlies = 'testHmacDigestSM3KeyAlias004'; + let HuksOptions = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksTagDigestSM3 + ), + inData: srcData65Kb, + }; + await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort'); + done(); + }); }); diff --git a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/List.test.js b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/List.test.js index 4487b0266..eabd107a0 100644 --- a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/List.test.js +++ b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/List.test.js @@ -26,3 +26,7 @@ require('./SignVerify/SecurityHuksRSABasicAbort63KBCallbackJsunit.test.js'); require('./SignVerify/SecurityHuksRSABasicFinish65KBCallbackJsunit.test.js'); require('./SignVerify/SecurityHuksRSABasicAbort65KBCallbackJsunit.test.js'); require('./SignVerify/SecurityHuksED25519BasicCallbackJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js'); \ No newline at end of file diff --git a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js new file mode 100755 index 000000000..70a8361a3 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js'; +let srcData63 = Data.Data63b; +let srcData63Kb = stringToUint8Array(srcData63); +describe('SecurityHuksSignVerifySM2CallbackJsunit', function () { + it('testSignVerifySM200211111', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySm2Size256SIGNSM3KeyAlias002'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData63Kb, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'abort', + true, + srcData63Kb + ); + done(); + }); +}); \ No newline at end of file diff --git a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js new file mode 100755 index 000000000..9736a749b --- /dev/null +++ b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js'; +let srcData65 = Data.Data65b; +let srcData65Kb = stringToUint8Array(srcData65); +describe('SecurityHuksSignVerifySM2CallbackJsunit', function () { + it('testSignVerifySM2004', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias004'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData65Kb, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'abort', + true, + srcData65Kb + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js new file mode 100755 index 000000000..a1268c1b1 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js'; +let srcData63 = Data.Data63b; +let srcData63Kb = stringToUint8Array(srcData63); +let finishOutData; +describe('SecurityHuksSignVerifySM2CallbackJsunit', function () { + it('testSignVerifySM2001', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias001'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData63Kb, + }; + finishOutData = await publicSignVerifyFunc( + srcKeyAlies, + srcKeyAlies + 'New', + HuksOptions, + 'finish', + true, + srcData63Kb + ); + HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: finishOutData, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + false, + srcData63Kb + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js new file mode 100755 index 000000000..0aa169852 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_callback_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js'; +let srcData65 = Data.Data65b; +let srcData65Kb = stringToUint8Array(srcData65); +let finishOutData; +describe('SecurityHuksSignVerifySM2CallbackJsunit', function () { + it('testSignVerifySM2003', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias003'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData65Kb, + }; + finishOutData = await publicSignVerifyFunc( + srcKeyAlies, + srcKeyAlies + 'New', + HuksOptions, + 'finish', + true, + srcData65Kb + ); + HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: finishOutData, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + false, + srcData65Kb + ); + done(); + }); +}); \ No newline at end of file diff --git a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/List.test.js b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/List.test.js index 94a5e5897..55417b0e8 100644 --- a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/List.test.js +++ b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/List.test.js @@ -26,3 +26,7 @@ require('./SignVerify/SecurityHuksRSABasicAbort63KBPromiseJsunit.test.js'); require('./SignVerify/SecurityHuksRSABasicFinish65KBPromiseJsunit.test.js'); require('./SignVerify/SecurityHuksRSABasicAbort65KBPromiseJsunit.test.js'); require('./SignVerify/SecurityHuksED25519BasicPromiseJsunit.test'); +require('./SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js'); +require('./SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js'); \ No newline at end of file diff --git a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js new file mode 100755 index 000000000..0d6a84854 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js'; +let srcData63 = Data.Data63b; +let srcData63Kb = stringToUint8Array(srcData63); +describe('SecurityHuksSignVerifySM2PromiseJsunit', function () { + it('testSignVerifySM2102', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias102'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData63Kb, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'abort', + true, + srcData63Kb + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js new file mode 100755 index 000000000..71c75bed7 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js'; +let srcData65 = Data.Data65b; +let srcData65Kb = stringToUint8Array(srcData65); +describe('SecurityHuksSignVerifySM2PromiseJsunit', function () { + it('testSignVerifySM2104', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias104'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData65Kb, + }; + await publicSignVerifyFunc(srcKeyAlies, HuksOptions, 'abort', true, srcData65Kb); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js new file mode 100755 index 000000000..0120b80ea --- /dev/null +++ b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js'; +let srcData63 = Data.Data63b; +let srcData63Kb = stringToUint8Array(srcData63); +let finishOutData; +describe('SecurityHuksSignVerifySM2PromiseJsunit', function () { + it('testSignVerifySM2101', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias101'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData63Kb, + }; + finishOutData = await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + true, + srcData63Kb + ); + HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: finishOutData, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + false, + srcData63Kb + ); + done(); + }); +}); diff --git a/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js new file mode 100755 index 000000000..edb9e28e4 --- /dev/null +++ b/security/security_huks_basic/huks_signverify_promise_BasicTest/entry/src/main/js/test/SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { describe, it } from 'deccjsunit/index'; +import Data from '../../../../../../../utils/data.json'; +import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam'; +import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc'; +import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js'; +let srcData65 = Data.Data65b; +let srcData65Kb = stringToUint8Array(srcData65); +let finishOutData; +describe('SecurityHuksSignVerifySM2PromiseJsunit', function () { + it('testSignVerifySM2103', 0, async function (done) { + const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias103'; + let HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData65Kb, + }; + finishOutData = await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + true, + srcData65Kb + ); + HuksOptions = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: finishOutData, + }; + await publicSignVerifyFunc( + srcKeyAlies, + HuksOptions, + 'finish', + false, + srcData65Kb + ); + done(); + }); +}); \ No newline at end of file diff --git a/security/security_huks_basic/utils/param/cipher/publicCipherParam.js b/security/security_huks_basic/utils/param/cipher/publicCipherParam.js index d5f1d10af..081a3aee5 100644 --- a/security/security_huks_basic/utils/param/cipher/publicCipherParam.js +++ b/security/security_huks_basic/utils/param/cipher/publicCipherParam.js @@ -132,4 +132,49 @@ let HuksCipherRSA = { value: param.HksKeyDigest.HKS_DIGEST_SHA512, }, }; -export { HuksCipherAES, HuksCipherRSA }; + +let HuksCipherSM4 = { + HuksKeyAlgSM4: { + tag: param.HksTag.HKS_TAG_ALGORITHM, + value: param.HksKeyAlg.HKS_ALG_SM4, + }, + HuksKeyPurpose: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: + param.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT | + param.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT, + }, + HuksKeyPurposeENCRYPT: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: param.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT, + }, + HuksKeyPurposeDECRYPT: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: param.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT, + }, + HuksKeySM4Size128: { + tag: param.HksTag.HKS_TAG_KEY_SIZE, + value: param.HksKeySize.HKS_SM4_KEY_SIZE_128, + }, + HuksKeySM4PADDINGNONE: { + tag: param.HksTag.HKS_TAG_PADDING, + value: param.HksKeyPadding.HKS_PADDING_NONE, + }, + HuksKeySM4PADDINGPKCS7: { + tag: param.HksTag.HKS_TAG_PADDING, + value: param.HksKeyPadding.HKS_PADDING_PKCS7, + }, + HuksKeySM4BLOCKMODECBC: { + tag: param.HksTag.HKS_TAG_BLOCK_MODE, + value: param.HksCipherMode.HKS_MODE_CBC, + }, + HuksKeySM4BLOCKMODECTR: { + tag: param.HksTag.HKS_TAG_BLOCK_MODE, + value: param.HksCipherMode.HKS_MODE_CTR, + }, + HuksKeySM4BLOCKMODEECB: { + tag: param.HksTag.HKS_TAG_BLOCK_MODE, + value: param.HksCipherMode.HKS_MODE_ECB, + }, +}; +export { HuksCipherAES, HuksCipherRSA, HuksCipherSM4 }; diff --git a/security/security_huks_basic/utils/param/hmac/publicHmacParam.js b/security/security_huks_basic/utils/param/hmac/publicHmacParam.js index 248eb36ea..0d6cb7e91 100644 --- a/security/security_huks_basic/utils/param/hmac/publicHmacParam.js +++ b/security/security_huks_basic/utils/param/hmac/publicHmacParam.js @@ -14,7 +14,7 @@ */ import * as param from '../publicParam'; -let HuksHmac = { +let HuksHmac = { HuksKeyAlg: { tag: param.HksTag.HKS_TAG_ALGORITHM, value: param.HksKeyAlg.HKS_ALG_HMAC, @@ -47,5 +47,9 @@ let HuksHmac = { tag: param.HksTag.HKS_TAG_DIGEST, value: param.HksKeyDigest.HKS_DIGEST_SHA512, }, + HuksTagDigestSM3: { + tag: param.HksTag.HKS_TAG_DIGEST, + value: param.HksKeyDigest.HKS_DIGEST_SM3, + }, }; export { HuksHmac }; diff --git a/security/security_huks_basic/utils/param/publicParam.js b/security/security_huks_basic/utils/param/publicParam.js index 350fbb7be..d8c95b2f4 100644 --- a/security/security_huks_basic/utils/param/publicParam.js +++ b/security/security_huks_basic/utils/param/publicParam.js @@ -18,12 +18,15 @@ let HksKeyAlg = { HKS_ALG_DH: 103, HKS_ALG_AES: 20, HKS_ALG_HMAC: 50, - HKS_ALG_X25519: 102, + HKS_ALG_X25519: 101, HKS_ALG_RSA: 1, HKS_ALG_PBKDF2: 52, HKS_ALG_HKDF: 51, HKS_ALG_DSA: 3, HKS_ALG_ED25519: 102, + HKS_ALG_SM2: 150, + HKS_ALG_SM3: 151, + HKS_ALG_SM4: 152, }; let HksKeyPurpose = { HKS_KEY_PURPOSE_AGREE: 256, @@ -67,6 +70,8 @@ let HksKeySize = { HKS_DSA_KEY_SIZE_2048: 2048, HKS_DSA_KEY_SIZE_3072: 3072, HKS_DSA_KEY_SIZE_4096: 4096, + HKS_SM2_KEY_SIZE_256: 256, + HKS_SM4_KEY_SIZE_128: 128, }; let HksKeyStorageType = { HKS_STORAGE_TEMP: 0, @@ -85,6 +90,7 @@ let HksKeyDigest = { HKS_DIGEST_SHA256: 12, HKS_DIGEST_SHA384: 13, HKS_DIGEST_SHA512: 14, + HKS_DIGEST_SM3: 2, }; let HksKeyPadding = { HKS_PADDING_NONE: 0, diff --git a/security/security_huks_basic/utils/param/signverify/publicSignverifyParam.js b/security/security_huks_basic/utils/param/signverify/publicSignverifyParam.js index 0e713a78f..05e8b46e5 100644 --- a/security/security_huks_basic/utils/param/signverify/publicSignverifyParam.js +++ b/security/security_huks_basic/utils/param/signverify/publicSignverifyParam.js @@ -261,4 +261,32 @@ let HuksSignVerifyRSA = { value: param.HksKeyDigest.HKS_DIGEST_SHA512, }, }; -export { HuksSignVerifyRSA, HuksSignVerifyDSA, HuksSignVerifyECC, HuksSignVerifyED25519 }; +let HuksSignVerifySM2 = { + HuksKeySize256: { + tag: param.HksTag.HKS_TAG_KEY_SIZE, + value: param.HksKeySize.HKS_SM2_KEY_SIZE_256, + }, + HuksKeyAlgSM2: { + tag: param.HksTag.HKS_TAG_ALGORITHM, + value: param.HksKeyAlg.HKS_ALG_SM2, + }, + HuksKeySM2PurposeSIGN: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: param.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN, + }, + HuksKeySM2PurposeVERIFY: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: param.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY, + }, + HuksTagSM2DigestSM3: { + tag: param.HksTag.HKS_TAG_DIGEST, + value: param.HksKeyDigest.HKS_DIGEST_SM3, + }, + HuksKeySM2PurposeSINGVERIFY: { + tag: param.HksTag.HKS_TAG_PURPOSE, + value: + param.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN | + param.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY, + }, +}; +export { HuksSignVerifyRSA, HuksSignVerifyDSA, HuksSignVerifyECC, HuksSignVerifyED25519 ,HuksSignVerifySM2}; -- GitLab