diff --git a/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/SignVerify/SecurityHuksRSASignExtendJsunit.test.js b/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/SignVerify/SecurityHuksRSASignExtendJsunit.test.js index 287ddce6d760d48eda425b152891b8971e4f1b48..ec9547df4df427203b4cbe549252b7a07ed52c95 100644 --- a/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/SignVerify/SecurityHuksRSASignExtendJsunit.test.js +++ b/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/SignVerify/SecurityHuksRSASignExtendJsunit.test.js @@ -13,10 +13,33 @@ * limitations under the License. */ import huks from "@ohos.security.huks"; -import { describe, it, expect, beforeAll } from "@ohos/hypium"; +import { describe, it, expect } from "@ohos/hypium"; import Data from '../../../../../../utils/data.json'; -import { stringToUint8Array, checkSoftware } from '../../../../../../utils/param/publicFunc'; -import { HuksSignVerifyRSA } from '../../../../../../utils/param/signverify/publicSignverifyParam'; +import { + stringToUint8Array, + arrayEqual, + checkSoftware +} from '../../../../../../utils/param/publicFunc'; +import { + HuksSignVerifyRSA, + HuksSignVerifyDSA, + HuksSignVerifyECC, + HuksSignVerifyED25519, + HuksSignVerifySM2 +} from '../../../../../../utils/param/signverify/publicSignverifyParam'; +import { HuksAgreeECDH } from '../../../../../../utils/param/agree/publicAgreeParam'; +import { + HuksCipherAES, + HuksCipherRSA, + HuksCipherSM4 +} from '../../../../../../utils/param/cipher/publicCipherParam'; +import { + HuksDeriveHKDF, + HuksDerivePBKDF2 +} from '../../../../../../utils/param/derive/publicDeriveParam'; +import { + HuksHmac +} from '../../../../../../utils/param/hmac/publicHmacParam'; let inDataString = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + @@ -29,10 +52,16 @@ let srcData64 = Data.Data64b; let srcData64Kb = stringToUint8Array(srcData64); let signedResult; let handle; + +let IV = '0000000000000000'; +let IVErr = '00000000000000000000000000000000000000000000000000000000000000000000'; +let AAD = '0000000000000000'; +let NONCE = '00000000000'; +let AEAD = '0000000000000000'; let useSoftware = true; async function publicGenerateKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) { - console.error(`enter promise generateKeyItem`); + console.error(`promise: generateKeyItem options, data = ${JSON.stringify(genHuksOptionsNONECBC)}`); try { await huks.generateKeyItem(srcKeyAlias, genHuksOptionsNONECBC) .then((data) => { @@ -83,6 +112,23 @@ async function publicInitSessionError(srcKeyAlias, HuksOptions, errCode) { } } +async function publicDeleteKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) { + console.error(`enter promise deleteKeyItem`); + try { + await huks.deleteKeyItem(srcKeyAlias, genHuksOptionsNONECBC) + .then((data) => { + console.error(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + }) + .catch(error => { + console.error(`promise: deleteKeyItem failed, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + }); + } catch (error) { + console.error(`promise: deleteKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } +} + async function publicUpdateSessionFunction(HuksOptions) { const maxUpdateSize = 64; const inData = HuksOptions.inData; @@ -121,29 +167,33 @@ async function publicUpdateSessionFunction(HuksOptions) { console.log(`update size invalid isFinished = ${isFinished}`); console.log(`inDataSegPosition = ${inDataSegPosition}`); console.log(`lastInDataPosition = ${lastInDataPosition}`); + outData = []; expect(null).assertFail(); - return; + return outData; } inDataSegPosition += maxUpdateSize; } + return outData; } -async function publicUpdateError(HuksOptions, errCode) { +async function publicUpdateOnce(HuksOptions) { console.error(`enter promise doUpdate`); + let outData; try { await huks.updateSession(handle, HuksOptions) .then((data) => { console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`); - expect(null).assertFail(); + outData = data.outData; }) .catch(error => { console.error(`promise: doUpdate failed, code: ${error.code}, msg: ${error.message}`); - expect(err.code == errCode).assertTrue(); + expect(null).assertFail(); }); } catch (error) { console.error(`promise: doUpdate input arg invalid, code: ${error.code}, msg: ${error.message}`); expect(null).assertFail(); } + return outData; } async function publicFinishSessionFunc(HuksOptions) { @@ -166,29 +216,33 @@ async function publicFinishSessionFunc(HuksOptions) { } } -async function publicDeleteKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) { - console.error(`enter promise deleteKeyItem`); +async function publicExportFunc(srcKeyAlies, HuksOptions) { + console.info(`enter promise export`); + let exportKey; try { - await huks.deleteKeyItem(srcKeyAlias, genHuksOptionsNONECBC) + await huks.exportKeyItem(srcKeyAlies, HuksOptions) .then((data) => { - console.error(`promise: deleteKeyItem key success, data = ${JSON.stringify(data)}`); + console.info(`promise: exportKeyItem success, data = ${JSON.stringify(data)}`); + exportKey = data.outData; }) .catch(error => { - console.error(`promise: deleteKeyItem failed, code: ${error.code}, msg: ${error.message}`); + console.error(`promise: exportKeyItem failed, code: ${error.code}, msg: ${error.message}`); expect(null).assertFail(); }); } catch (error) { - console.error(`promise: deleteKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`); + console.error(`promise: exportKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`); expect(null).assertFail(); } + return exportKey; } export default function SecurityHuksRSASignExtendJsunit() { describe('SecurityHuksRSASignExtendJsunit', function () { beforeAll(async function (done) { - useSoftware = await checkSoftware(); + useSoftware = checkSoftware(); done(); }) + /** * @tc.number Security_HUKS_RSA_SignExtend_0100 * @tc.name No Padding and Sign Verify with RSA. @@ -196,50 +250,48 @@ export default function SecurityHuksRSASignExtendJsunit() { */ it("Security_HUKS_RSA_SignExtend_0100", 0, async function (done) { let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0100_Gen"; - if (useSoftware) { - let HuksOptionsGen = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - }; - let HuksOptionsSign = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - } - await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); - await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); - HuksOptionsSign.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsSign); - HuksOptionsSign.inData = new Uint8Array(new Array()); - await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, + } + await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); + await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); - let HuksOptionsVerify = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - } - await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); - HuksOptionsVerify.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsVerify); - HuksOptionsVerify.inData = signedResult; - await publicFinishSessionFunc(HuksOptionsVerify); - await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); done(); }) @@ -250,50 +302,48 @@ export default function SecurityHuksRSASignExtendJsunit() { */ it("Security_HUKS_RSA_SignExtend_0200", 0, async function (done) { let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0200"; - if (useSoftware) { - let HuksOptionsGen = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - }; - let HuksOptionsSign = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - } - await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); - await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); - HuksOptionsSign.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsSign); - HuksOptionsSign.inData = new Uint8Array(new Array()); - await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, + } + await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); + await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); - let HuksOptionsVerify = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - } - await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); - HuksOptionsVerify.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsVerify); - HuksOptionsVerify.inData = signedResult; - await publicFinishSessionFunc(HuksOptionsVerify); - await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); done(); }) @@ -322,31 +372,29 @@ export default function SecurityHuksRSASignExtendJsunit() { ), inData: srcData64Kb, } - if (useSoftware) { - await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); - await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); - HuksOptionsSign.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsSign); - HuksOptionsSign.inData = new Uint8Array(new Array()); - await publicFinishSessionFunc(HuksOptionsSign); + await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); + await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); - let HuksOptionsVerify = { - properties: new Array( - HuksSignVerifyRSA.HuksKeyAlgRSA, - HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, - HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, - HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, - HuksSignVerifyRSA.HuksKeyRSASize4096 - ), - inData: srcData64Kb, - } - await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); - HuksOptionsVerify.inData = srcData64Kb; - await publicUpdateSessionFunction(HuksOptionsVerify); - HuksOptionsVerify.inData = signedResult; - await publicFinishSessionFunc(HuksOptionsVerify); - await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: srcData64Kb, } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); done(); }) @@ -530,5 +578,2168 @@ export default function SecurityHuksRSASignExtendJsunit() { await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); done(); }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0900 + * @tc.name AES not GCM,no BlockMode while generate. + * @tc.desc AES not GCM,no BlockMode while generate. + */ + it("Security_HUKS_RSA_SignExtend_0900", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_0900"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1000 + * @tc.name AES not GCM,no digest while generate. + * @tc.desc AES not GCM,no digest while generate. + */ + it("Security_HUKS_RSA_SignExtend_1000", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1000"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1100 + * @tc.name AES not GCM,no padding while generate. + * @tc.desc AES not GCM,no padding while generate. + */ + it("Security_HUKS_RSA_SignExtend_1100", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1100"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1200 + * @tc.name AES not GCM,no IV while generate. + * @tc.desc AES not GCM,no IV while generate. + */ + it("Security_HUKS_RSA_SignExtend_1200", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1200"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1300 + * @tc.name AES not GCM,no blockmode,digest,padding,IV while generate. + * @tc.desc AES not GCM,no blockmode,digest,padding,IV while generate. + */ + it("Security_HUKS_RSA_SignExtend_1300", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1300"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1400 + * @tc.name AES GCM,no blockmode while generate. + * @tc.desc AES GCM,no blockmode while generate. + */ + it("Security_HUKS_RSA_SignExtend_1400", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1400"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1500 + * @tc.name AES GCM,no digest while generate. + * @tc.desc AES GCM,no digest while generate. + */ + it("Security_HUKS_RSA_SignExtend_1500", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1500"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1600 + * @tc.name AES GCM,no padding while generate. + * @tc.desc AES GCM,no padding while generate. + */ + it("Security_HUKS_RSA_SignExtend_1600", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1600"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1700 + * @tc.name AES GCM,no blockmode,digest,padding while generate. + * @tc.desc AES GCM,no blockmode,digest,padding while generate. + */ + it("Security_HUKS_RSA_SignExtend_1700", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1700"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeDECRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherAES.HuksKeyAESDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_ASSOCIATED_DATA, + value: stringToUint8Array(AAD) + }, + { + tag: huks.HuksTag.HUKS_TAG_NONCE, + value: stringToUint8Array(NONCE) + }, + { + tag: huks.HuksTag.HUKS_TAG_AE_TAG, + value: stringToUint8Array(AEAD) + }, + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1800 + * @tc.name AES GCM,no digest while generate,use wrong digest (SHA256) + * @tc.desc AES GCM,no digest while generate,use wrong digest (SHA256) + */ + it("Security_HUKS_RSA_SignExtend_1800", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1800"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurpose, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherAES.HuksKeyAlgAES, + HuksCipherAES.HuksKeyPurposeENCRYPT, + HuksCipherAES.HuksKeyAESSize256, + HuksCipherAES.HuksKeyAESPADDINGNONE, + HuksCipherAES.HuksKeyAESBLOCKMODE, + HuksCipherRSA.HuksKeyRSADIGESTSHA256, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_1900 + * @tc.name RSA Cipher,no blockMode while generate. + * @tc.desc RSA Cipher,no blockMode while generate. + */ + it("Security_HUKS_RSA_SignExtend_1900", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_1900"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurpose, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeENCRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + await publicUpdateSessionFunction(HuksOptionsEncrypt); + await publicFinishSessionFunc(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeDECRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: signedResult, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + await publicUpdateSessionFunction(HuksOptionsDecrypt); + await publicFinishSessionFunc(signedResult); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2000 + * @tc.name RSA Cipher,no digest while generate. + * @tc.desc RSA Cipher,no digest while generate. + */ + it("Security_HUKS_RSA_SignExtend_2000", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2000"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurpose, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeENCRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + await publicUpdateSessionFunction(HuksOptionsEncrypt); + await publicFinishSessionFunc(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeDECRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: signedResult, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + await publicUpdateSessionFunction(HuksOptionsDecrypt); + await publicFinishSessionFunc(signedResult); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2100 + * @tc.name RSA Cipher,no padding while generate. + * @tc.desc RSA Cipher,no padding while generate. + */ + it("Security_HUKS_RSA_SignExtend_2100", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2100"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurpose, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeENCRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + await publicUpdateSessionFunction(HuksOptionsEncrypt); + await publicFinishSessionFunc(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeDECRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: signedResult, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + await publicUpdateSessionFunction(HuksOptionsDecrypt); + await publicFinishSessionFunc(signedResult); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2200 + * @tc.name RSA Cipher,no blockmode,digest,padding while generate. + * @tc.desc RSA Cipher,no blockmode,digest,padding while generate. + */ + it("Security_HUKS_RSA_SignExtend_2200", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2200"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurpose, + HuksCipherRSA.HuksKeyRSASize4096, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeENCRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + await publicUpdateSessionFunction(HuksOptionsEncrypt); + await publicFinishSessionFunc(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeDECRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSABLOCKMODEECB, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: signedResult, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + await publicUpdateSessionFunction(HuksOptionsDecrypt); + await publicFinishSessionFunc(signedResult); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2300 + * @tc.name RSA Cipher,wrong blockmode + * @tc.desc RSA Cipher,wrong blockmode + */ + it("Security_HUKS_RSA_SignExtend_2300", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2300"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurpose, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherRSA.HuksKeyAlgRSA, + HuksCipherRSA.HuksKeyPurposeENCRYPT, + HuksCipherRSA.HuksKeyRSASize4096, + HuksCipherRSA.HuksKeyRSAPADDINGOAEP, + HuksCipherAES.HuksKeyAESBLOCKMODEGCM, + HuksCipherRSA.HuksKeyRSADIGESTSHA256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2400 + * @tc.name SM4 Cipher,no blockmode while generate + * @tc.desc SM4 Cipher,no blockmode while generate + */ + it("Security_HUKS_RSA_SignExtend_2400", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2400"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2600 + * @tc.name SM4 Cipher,no padding while generate + * @tc.desc SM4 Cipher,no padding while generate + */ + it("Security_HUKS_RSA_SignExtend_2600", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2600"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2700 + * @tc.name SM4 Cipher,no IV while generate + * @tc.desc SM4 Cipher,no IV while generate + */ + it("Security_HUKS_RSA_SignExtend_2700", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2700"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2800 + * @tc.name SM4 Cipher,no blockMode,padding,IV while generate + * @tc.desc SM4 Cipher,no blockMode,padding,IV while generate + */ + it("Security_HUKS_RSA_SignExtend_2800", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2800"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose, + HuksCipherSM4.HuksKeySM4Size128, + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsEncrypt); + let encryptedData = await publicUpdateSessionFunction(HuksOptionsEncrypt); + let HuksOptionsDecrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeDECRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: encryptedData, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsDecrypt); + let outData = await publicUpdateSessionFunction(HuksOptionsDecrypt); + expect(arrayEqual(Array.from(outData), Array.from(srcData64Kb))).assertTrue(); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_2900 + * @tc.name SM4 Cipher,wrong padding while generate + * @tc.desc SM4 Cipher,wrong padding while generate + */ + it("Security_HUKS_RSA_SignExtend_2900", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_2900"; + let HuksOptionsGen = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurpose, + HuksCipherSM4.HuksKeySM4Size128, + HuksCipherSM4.HuksKeySM4PADDINGNONE, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsEncrypt = { + properties: new Array( + HuksCipherSM4.HuksKeyAlgSM4, + HuksCipherSM4.HuksKeyPurposeENCRYPT, + HuksCipherSM4.HuksKeySM4Size128, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksCipherSM4.HuksKeySM4BLOCKMODECBC, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsEncrypt, 401); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3000 + * @tc.name RSA SignVreify,hash mode doesn't suite for the hashed data + * @tc.desc RSA SignVreify,hash mode doesn't suite for the hashed data + */ + it("Security_HUKS_RSA_SignExtend_3000", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3000"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: inDataAfterSha512, + } + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize4096 + ), + inData: inDataAfterSha512, + } + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3100 + * @tc.name DSA SignVerify,no digest while generate(TEE Not support) + * @tc.desc DSA SignVerify,no digest while generate(TEE Not support) + */ + it("Security_HUKS_RSA_SignExtend_3100", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3100"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyDSA.HuksKeyAlgDSA, + HuksSignVerifyDSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyDSA.HuksKeySIZE1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyDSA.HuksKeyAlgDSA, + HuksSignVerifyDSA.HuksKeyDSAPurposeSIGN, + HuksSignVerifyDSA.HuksTagDSADigestSHA1, + HuksSignVerifyDSA.HuksKeySIZE1024 + ), + inData: srcData64Kb, + }; + if (useSoftware) { + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyDSA.HuksKeyAlgDSA, + HuksSignVerifyDSA.HuksKeyDSAPurposeVERIFY, + HuksSignVerifyDSA.HuksTagDSADigestSHA1, + HuksSignVerifyDSA.HuksKeySIZE1024 + ), + inData: srcData64Kb, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + } + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3200 + * @tc.name ECC SignVerify,no Hash Support + * @tc.desc ECC SignVerify,no Hash Support + */ + it("Security_HUKS_RSA_SignExtend_3200", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3200"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSINGVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: inDataAfterSha512, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSIGN, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: inDataAfterSha512, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: inDataAfterSha512, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3300 + * @tc.name ECC SignVerify,hash mode doesn't suite for the hashed data + * @tc.desc ECC SignVerify,hash mode doesn't suite for the hashed data + */ + it("Security_HUKS_RSA_SignExtend_3300", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3300"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSINGVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: inDataAfterSha512, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSIGN, + HuksSignVerifyECC.HuksTagECCDigestSHA384, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: inDataAfterSha512, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsSign, 401); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3400 + * @tc.name ECC SignVerify,no digest while generate + * @tc.desc ECC SignVerify,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_3400", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3400"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSINGVERIFY, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeSIGN, + HuksSignVerifyECC.HuksTagECCDigestSHA256, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyECC.HuksKeyAlgECC, + HuksSignVerifyECC.HuksKeyECCPurposeVERIFY, + HuksSignVerifyECC.HuksTagECCDigestSHA256, + HuksSignVerifyECC.HuksKeyECCSize384 + ), + inData: srcData64Kb, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3500 + * @tc.name ED25519 SignVerify,no digest while generate + * @tc.desc ED25519 SignVerify,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_3500", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3500"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyED25519.HuksKeyAlgED25519, + HuksSignVerifyED25519.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyED25519.HuksKeyED25519Size256, + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyED25519.HuksKeyAlgED25519, + HuksSignVerifyED25519.HuksKeyED25519PurposeSIGN, + HuksSignVerifyED25519.HuksKeyED25519Size256, + HuksSignVerifyED25519.HuksTagDigestSHA1 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyED25519.HuksKeyAlgED25519, + HuksSignVerifyED25519.HuksKeyED25519PurposeVERIFY, + HuksSignVerifyED25519.HuksKeyED25519Size256, + HuksSignVerifyED25519.HuksTagDigestSHA1 + ), + inData: srcData64Kb, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3600 + * @tc.name SM2 SignVerify,no hash support + * @tc.desc SM2 SignVerify,no hash support + */ + it("Security_HUKS_RSA_SignExtend_3600", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3600"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSINGVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: inDataAfterSha512, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: inDataAfterSha512, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: inDataAfterSha512, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3700 + * @tc.name SM2 SignVerify,hash mode doesn't suite for the hashed data + * @tc.desc SM2 SignVerify,hash mode doesn't suite for the hashed data + */ + it("Security_HUKS_RSA_SignExtend_3700", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3700"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSINGVERIFY, + HuksSignVerifyECC.HuksTagECCDigestNONE, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: inDataAfterSha512, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifyECC.HuksTagECCDigestSHA384, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: inDataAfterSha512, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsSign, 401); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3800 + * @tc.name SM2 SignVerify,no digest while generate + * @tc.desc SM2 SignVerify,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_3800", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3800"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSINGVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeSIGN, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + HuksOptionsSign.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifySM2.HuksKeyAlgSM2, + HuksSignVerifySM2.HuksKeySM2PurposeVERIFY, + HuksSignVerifySM2.HuksTagSM2DigestSM3, + HuksSignVerifySM2.HuksKeySize256 + ), + inData: srcData64Kb, + }; + await publicInitFunc(srcKeyAlies, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_3900 + * @tc.name ECDH Agree,no blockMode while generate + * @tc.desc ECDH Agree,no blockMode while generate + */ + it("Security_HUKS_RSA_SignExtend_3900", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_3900"; + let srcKeyAliesSecond = "Security_HUKS_RSA_SignExtend_3900_02"; + let HuksOptionsGen = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECC, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCPADDING + ), + inData: srcData64Kb, + }; + let HuksOptionsAgree = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECDH, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCPADDING, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksAgreeECDH.HuksKeySTORAGE, + HuksAgreeECDH.HuksKeyISKEYALIAS, + HuksAgreeECDH.HuksKeyALGORITHMAES, + HuksAgreeECDH.HuksKeySIZE256, + HuksAgreeECDH.HuksKeyPurposeENCRYPTDECRYPT, + HuksAgreeECDH.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksAgreeECDH.HuksKeyPADDINGNONE, + HuksAgreeECDH.HuksKeyBLOCKMODEECB + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicGenerateKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + let exportKeyFrist = await publicExportFunc(srcKeyAlies, HuksOptionsGen); + let exportKeySecond = await publicExportFunc(srcKeyAliesSecond, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeySecond; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinish); + let huksOptionsFinishSecond = huksOptionsFinish; + huksOptionsFinishSecond.properties.splice(6, 1, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliesSecond + 'final'), + }); + await publicInitFunc(srcKeyAliesSecond, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeyFrist; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinishSecond); + await publicDeleteKeyFunc(srcKeyAliesSecond + 'final', HuksOptionsAgree); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicDeleteKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4000 + * @tc.name ECDH Agree,no digest while generate + * @tc.desc ECDH Agree,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_4000", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4000"; + let srcKeyAliesSecond = "Security_HUKS_RSA_SignExtend_4000_02"; + let HuksOptionsGen = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECC, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCPADDING, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let HuksOptionsAgree = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECDH, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCPADDING, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksAgreeECDH.HuksKeySTORAGE, + HuksAgreeECDH.HuksKeyISKEYALIAS, + HuksAgreeECDH.HuksKeyALGORITHMAES, + HuksAgreeECDH.HuksKeySIZE256, + HuksAgreeECDH.HuksKeyPurposeENCRYPTDECRYPT, + HuksAgreeECDH.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksAgreeECDH.HuksKeyPADDINGNONE, + HuksAgreeECDH.HuksKeyBLOCKMODEECB + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicGenerateKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + let exportKeyFrist = await publicExportFunc(srcKeyAlies, HuksOptionsGen); + let exportKeySecond = await publicExportFunc(srcKeyAliesSecond, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeySecond; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinish); + let huksOptionsFinishSecond = huksOptionsFinish; + huksOptionsFinishSecond.properties.splice(6, 1, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliesSecond + 'final'), + }); + await publicInitFunc(srcKeyAliesSecond, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeyFrist; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinishSecond); + await publicDeleteKeyFunc(srcKeyAliesSecond + 'final', HuksOptionsAgree); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicDeleteKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4100 + * @tc.name ECDH Agree,no padding while generate + * @tc.desc ECDH Agree,no padding while generate + */ + it("Security_HUKS_RSA_SignExtend_4100", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4100"; + let srcKeyAliesSecond = "Security_HUKS_RSA_SignExtend_4100_02"; + let HuksOptionsGen = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECC, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let HuksOptionsAgree = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECDH, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCPADDING, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksAgreeECDH.HuksKeySTORAGE, + HuksAgreeECDH.HuksKeyISKEYALIAS, + HuksAgreeECDH.HuksKeyALGORITHMAES, + HuksAgreeECDH.HuksKeySIZE256, + HuksAgreeECDH.HuksKeyPurposeENCRYPTDECRYPT, + HuksAgreeECDH.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksAgreeECDH.HuksKeyPADDINGNONE, + HuksAgreeECDH.HuksKeyBLOCKMODEECB + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicGenerateKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + let exportKeyFrist = await publicExportFunc(srcKeyAlies, HuksOptionsGen); + let exportKeySecond = await publicExportFunc(srcKeyAliesSecond, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeySecond; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinish); + let huksOptionsFinishSecond = huksOptionsFinish; + huksOptionsFinishSecond.properties.splice(6, 1, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliesSecond + 'final'), + }); + await publicInitFunc(srcKeyAliesSecond, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeyFrist; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinishSecond); + await publicDeleteKeyFunc(srcKeyAliesSecond + 'final', HuksOptionsAgree); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicDeleteKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4200 + * @tc.name ECDH Agree,no padding,blockmode,digest while generate + * @tc.desc ECDH Agree,no padding,blockmode,digest while generate + */ + it("Security_HUKS_RSA_SignExtend_4200", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4200"; + let srcKeyAliesSecond = "Security_HUKS_RSA_SignExtend_4200_02"; + let HuksOptionsGen = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECC, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256 + ), + inData: srcData64Kb, + }; + let HuksOptionsAgree = { + properties: new Array( + HuksAgreeECDH.HuksKeyAlgECDH, + HuksAgreeECDH.HuksKeyPurposeECDH, + HuksAgreeECDH.HuksKeyECCSize256, + HuksAgreeECDH.HuksKeyECCDIGEST, + HuksAgreeECDH.HuksKeyECCPADDING, + HuksAgreeECDH.HuksKeyECCBLOCKMODE + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksAgreeECDH.HuksKeySTORAGE, + HuksAgreeECDH.HuksKeyISKEYALIAS, + HuksAgreeECDH.HuksKeyALGORITHMAES, + HuksAgreeECDH.HuksKeySIZE256, + HuksAgreeECDH.HuksKeyPurposeENCRYPTDECRYPT, + HuksAgreeECDH.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksAgreeECDH.HuksKeyPADDINGNONE, + HuksAgreeECDH.HuksKeyBLOCKMODEECB + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicGenerateKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + let exportKeyFrist = await publicExportFunc(srcKeyAlies, HuksOptionsGen); + let exportKeySecond = await publicExportFunc(srcKeyAliesSecond, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeySecond; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinish); + let huksOptionsFinishSecond = huksOptionsFinish; + huksOptionsFinishSecond.properties.splice(6, 1, { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAliesSecond + 'final'), + }); + await publicInitFunc(srcKeyAliesSecond, HuksOptionsAgree); + HuksOptionsAgree.inData = exportKeyFrist; + await publicUpdateOnce(HuksOptionsAgree); + await publicFinishSessionFunc(huksOptionsFinishSecond); + await publicDeleteKeyFunc(srcKeyAliesSecond + 'final', HuksOptionsAgree); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicDeleteKeyFunc(srcKeyAliesSecond, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4300 + * @tc.name HKDF Derive,no digest while generate + * @tc.desc HKDF Derive,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_4300", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4300"; + let HuksOptionsGen = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgAES, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksKeyHKDFSize192, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgHKDF, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyDERIVEKEYSIZE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksDeriveHKDF.HuksKeySTORAGE, + HuksDeriveHKDF.HuksKeyISKEYALIAS, + HuksDeriveHKDF.HuksKeyALGORITHMAES, + HuksDeriveHKDF.HuksKeySIZE256, + HuksDeriveHKDF.HuksKeyPurposeENCRYPTDECRYPT, + HuksDeriveHKDF.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksDeriveHKDF.HuksKeyPADDINGNONE, + HuksDeriveHKDF.HuksKeyBLOCKMODEGCM + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsDerive); + await publicUpdateOnce(HuksOptionsDerive); + await publicFinishSessionFunc(huksOptionsFinish); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4400 + * @tc.name HKDF Derive,no IV while generate + * @tc.desc HKDF Derive,no IV while generate + */ + it("Security_HUKS_RSA_SignExtend_4400", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4400"; + let HuksOptionsGen = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgAES, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyHKDFSize192, + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgHKDF, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyDERIVEKEYSIZE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksDeriveHKDF.HuksKeySTORAGE, + HuksDeriveHKDF.HuksKeyISKEYALIAS, + HuksDeriveHKDF.HuksKeyALGORITHMAES, + HuksDeriveHKDF.HuksKeySIZE256, + HuksDeriveHKDF.HuksKeyPurposeENCRYPTDECRYPT, + HuksDeriveHKDF.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksDeriveHKDF.HuksKeyPADDINGNONE, + HuksDeriveHKDF.HuksKeyBLOCKMODEGCM + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsDerive); + await publicUpdateOnce(HuksOptionsDerive); + await publicFinishSessionFunc(huksOptionsFinish); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4500 + * @tc.name HKDF Derive,no digest,IV while generate + * @tc.desc HKDF Derive,no digest,IV while generate + */ + it("Security_HUKS_RSA_SignExtend_4500", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4500"; + let HuksOptionsGen = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgAES, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksKeyHKDFSize192, + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgHKDF, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyDERIVEKEYSIZE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IV) + } + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksDeriveHKDF.HuksKeySTORAGE, + HuksDeriveHKDF.HuksKeyISKEYALIAS, + HuksDeriveHKDF.HuksKeyALGORITHMAES, + HuksDeriveHKDF.HuksKeySIZE256, + HuksDeriveHKDF.HuksKeyPurposeENCRYPTDECRYPT, + HuksDeriveHKDF.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksDeriveHKDF.HuksKeyPADDINGNONE, + HuksDeriveHKDF.HuksKeyBLOCKMODEGCM + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsDerive); + await publicUpdateOnce(HuksOptionsDerive); + await publicFinishSessionFunc(huksOptionsFinish); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4600 + * @tc.name HKDF Derive,IV length err + * @tc.desc HKDF Derive,IV length err + */ + it("Security_HUKS_RSA_SignExtend_4600", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4600"; + let HuksOptionsGen = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgAES, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyHKDFSize192, + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgHKDF, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyDERIVEKEYSIZE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: stringToUint8Array(IVErr) + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsDerive); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4700 + * @tc.name HKDF Derive,IV format err + * @tc.desc HKDF Derive,IV format err + */ + it("Security_HUKS_RSA_SignExtend_4700", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4700"; + let HuksOptionsGen = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgAES, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyHKDFSize192, + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDeriveHKDF.HuksKeyAlgHKDF, + HuksDeriveHKDF.HuksKeyPurposeHKDF, + HuksDeriveHKDF.HuksTagHKDFDigestSHA256, + HuksDeriveHKDF.HuksKeyDERIVEKEYSIZE, + { + tag: huks.HuksTag.HUKS_TAG_IV, + value: IV + } + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + try { + await huks.initSession(srcKeyAlies, HuksOptionsDerive).then(data => { + console.error(`promise: doInit success, data = ${JSON.stringify(data)}`); + expect(null).assertFail(); + }).catch(err => { + console.error(`promise: doInit key failed, code: ${err.code}, msg: ${err.message}`); + expect(err.code == 401).assertTrue(); + }) + } catch (err) { + console.error(`promise: doInit input arg invalid, code: ${err.code}, msg: ${err.message}`); + expect(err.code == 401).assertTrue(); + } + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4800 + * @tc.name PBKDF Derive,no digest while generate + * @tc.desc PBKDF Derive,no digest while generate + */ + it("Security_HUKS_RSA_SignExtend_4800", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4800"; + let HuksOptionsGen = { + properties: new Array( + HuksDerivePBKDF2.HuksKeyAlgAES, + HuksDerivePBKDF2.HuksKeyPurposePBKDF2, + HuksDerivePBKDF2.HuksKeyPBKDF2Size192, + HuksDerivePBKDF2.HuksKeyPBKDF2Iteration, + HuksDerivePBKDF2.HuksKeyPBKDF2Salt + ), + inData: srcData64Kb, + }; + let HuksOptionsDerive = { + properties: new Array( + HuksDerivePBKDF2.HuksKeyAlgPBKDF2, + HuksDerivePBKDF2.HuksKeyPurposePBKDF2, + HuksDerivePBKDF2.HuksTagPBKDF2DigestSHA256, + HuksDerivePBKDF2.HuksKeyDERIVEKEYSIZE, + HuksDerivePBKDF2.HuksKeyPBKDF2Iteration, + HuksDerivePBKDF2.HuksKeyPBKDF2Salt + ), + inData: srcData64Kb, + }; + let huksOptionsFinish = { + properties: new Array( + HuksDerivePBKDF2.HuksKeySTORAGE, + HuksDerivePBKDF2.HuksKeyISKEYALIAS, + HuksDerivePBKDF2.HuksKeyALGORITHMAES, + HuksDerivePBKDF2.HuksKeySIZE256, + HuksDerivePBKDF2.HuksKeyPurposeENCRYPTDECRYPT, + HuksDerivePBKDF2.HuksKeyDIGESTNONE, + { + tag: huks.HuksTag.HUKS_TAG_KEY_ALIAS, + value: stringToUint8Array(srcKeyAlies), + }, + HuksDerivePBKDF2.HuksKeyPADDINGNONE, + HuksDerivePBKDF2.HuksKeyBLOCKMODEGCM + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsDerive); + await publicUpdateOnce(HuksOptionsDerive); + await publicFinishSessionFunc(huksOptionsFinish); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_4900 + * @tc.name HMAC ,no digest while ... + * @tc.desc HMAC ,no digest while ... + */ + it("Security_HUKS_RSA_SignExtend_4900", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_4900"; + let HuksOptionsGen = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksKeySIZE, + ), + inData: srcData64Kb, + }; + let HuksOptionsUse = { + properties: new Array( + HuksHmac.HuksKeyAlg, + HuksHmac.HuksKeyPurpose, + HuksHmac.HuksKeySIZE, + HuksHmac.HuksTagDigestSHA512 + ), + inData: srcData64Kb, + }; + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsUse); + await publicUpdateSessionFunction(HuksOptionsUse); + await publicFinishSessionFunc(HuksOptionsUse); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) }) }