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 64150fc82cb3fd9a688c7f8523f717f2414f3353..eed32edf376e49347cbad852a9f796e96f784736 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 0000000000000000000000000000000000000000..ee34e7981dfb669e0bc18fcfbb8c2e921cba12f0 --- /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 9aba31c2a99c347672f1bb64b91cdfa323d7cf81..d161ef0e4d9db66708b5c645aceb436984f6c583 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 c3a97ab715998ebc9f8e5ee13c2b27416a737736..7acc81f66290c2fe1a096ae9d85f418887cfa3f3 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 0000000000000000000000000000000000000000..a156d2231b386290267ab61250d7fafec9df6e6a --- /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 bac53362294dba49a975a0c762b09a9d1472f350..d494da0bda041c57a6b2ca1eb3bf7d725cf5d6df 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 8e842faa52c5512cdfb6fce7af6fef4c40110060..3ee77b1ec90f7bd72c2128b9c7352a16e66892d1 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 8deee00b0ef102bbdc60a82601dec6ea6510d31b..d600fe50e9da0ea111c5401d3f2c6a165d354035 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 4487b0266ae2d71e42cdb032b79e4b34c99f7032..eabd107a0ffabe2f40ddd837552651a0b2f2f165 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 0000000000000000000000000000000000000000..70a8361a3645fb00195573d44e661ecc9c4600dd --- /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 0000000000000000000000000000000000000000..9736a749b8077da948f6d0cdc51f895c6da25d8a --- /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 0000000000000000000000000000000000000000..a1268c1b1abdf32a420325c39a85413b491f0043 --- /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 0000000000000000000000000000000000000000..0aa1698520aece628190ffc123ccd926d81e54a1 --- /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 94a5e5897052bc948fec85c3b42170f26f0899b0..55417b0e85b4135c51d479d9d98daaaa7cce4e19 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 0000000000000000000000000000000000000000..0d6a84854a02395e38b9e5309f9e99126675370d --- /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 0000000000000000000000000000000000000000..71c75bed7883827442f9150c26b61e0336b8d886 --- /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 0000000000000000000000000000000000000000..0120b80ead6e3c9889c638e61f96803ce9efc831 --- /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 0000000000000000000000000000000000000000..edb9e28e446742fb6dfb723e30c1235fba5190c4 --- /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 d5f1d10af7d945729403f7952a35f113d561ecfb..081a3aee5e184367741086fa2f7a6b4ac46a1f32 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 248eb36ea3b88f3123ae3442122496c133778abf..0d6cb7e9193ef4d69f0381ac6ab83b2f12d47823 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 350fbb7be77121dd5824f29ad18f6202e2e1d9f6..d8c95b2f494159ca82ec1f83167b4683e4c25317 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 0e713a78faee0542743a86b28b5bf6241b8a6c54..05e8b46e538c8987640c04187b1fdc7e34c64334 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};