diff --git a/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/List.test.js b/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/List.test.js index f0f60d18de4c6b5b89959c4a0cd6ce14189a6456..ae475fd692a7f10e58b35298b94fa3f3f7541200 100644 --- a/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/List.test.js +++ b/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/List.test.js @@ -30,6 +30,8 @@ import SecurityHuksSM2BasicAbort63KBPromiseJsunit from './SignVerify/SecurityHuk import SecurityHuksSM2BasicAbort65KBPromiseJsunit from './SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js' import SecurityHuksSM2BasicFinish63KBPromiseJsunit from './SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js' import SecurityHuksSM2BasicFinish65KBPromiseJsunit from './SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js' +import SecurityHuksRSASignExtendJsunit from './SignVerify/SecurityHuksRSASignExtendJsunit.test.js' + export default function testsuite() { SecurityHuksDSABasicAbort63KBPromiseJsunit() SecurityHuksDSABasicAbort65KBPromiseJsunit() @@ -48,4 +50,5 @@ SecurityHuksSM2BasicAbort63KBPromiseJsunit() SecurityHuksSM2BasicAbort65KBPromiseJsunit() SecurityHuksSM2BasicFinish63KBPromiseJsunit() SecurityHuksSM2BasicFinish65KBPromiseJsunit() +SecurityHuksRSASignExtendJsunit() } 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 new file mode 100644 index 0000000000000000000000000000000000000000..6bf570f93f1118f0ee9e43e7a6fc4833a67396de --- /dev/null +++ b/security/security_huks_reformed_test/huks_signverify_promise_BasicTest/src/main/js/test/SignVerify/SecurityHuksRSASignExtendJsunit.test.js @@ -0,0 +1,524 @@ +/*software + * 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 huks from "@ohos.security.huks"; +import { describe, it, expect } from "@ohos/hypium"; +import Data from '../../../../../../utils/data.json'; +import { stringToUint8Array } from '../../../../../../utils/param/publicFunc'; +import { HuksSignVerifyRSA } from '../../../../../../utils/param/signverify/publicSignverifyParam'; + +let inDataString = "Hks_RSA_Sign_Verify_Test_0000000000000000000000000000000000000000000000000000000" + + "00000000000000000000000000000000000000000000000000000000000000000000000000000000" + + "0000000000000000000000000000000000000000000000000000000000000000000000000_string"; +let inDataAfterSha512 = new Uint8Array( + 0x68, 0xD1, 0x5F, 0xE4, 0x46, 0xF7, 0xBF, 0x8D, 0x30, 0x91, 0x46, 0x53, 0x81, 0x49, 0xA0, 0xD5, + 0x39, 0xC7, 0xDC, 0x59, 0xE7, 0xF6, 0x42, 0x5D, 0x86, 0x09, 0x30, 0xD0, 0x3F, 0x4D, 0x91, 0x85, +); +let srcData64 = Data.Data64b; +let srcData64Kb = stringToUint8Array(srcData64); +let signedResult; +let handle; + +async function publicGenerateKeyFunc(srcKeyAlias, genHuksOptionsNONECBC) { + console.error(`enter promise generateKeyItem`); + try { + await huks.generateKeyItem(srcKeyAlias, genHuksOptionsNONECBC) + .then((data) => { + console.error(`promise: generateKeyItem success, data = ${JSON.stringify(data)}`); + }) + .catch(error => { + console.error(`promise: generateKeyItem failed, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + }); + } catch (error) { + console.error(`promise: generateKeyItem input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } +} + +async function publicInitFunc(srcKeyAlias, HuksOptions) { + console.error(`enter promise doInit`); + try { + await huks.initSession(srcKeyAlias, HuksOptions) + .then((data) => { + console.error(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + }) + .catch(error => { + console.error(`promise: doInit key failed, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + }); + } catch (error) { + console.error(`promise: doInit input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } +} + +async function publicInitSessionError(srcKeyAlias, HuksOptions, errCode) { + console.error("enter publicInitSessionError"); + try { + await huks.initSession(srcKeyAlias, HuksOptions).then(data => { + console.error(`promise: doInit success, data = ${JSON.stringify(data)}`); + handle = data.handle; + expect(null).assertFail(); + }).catch(err => { + console.error(`promise: doInit key failed, code: ${err.code}, msg: ${err.message}`); + expect(err.code == errCode).assertTrue(); + }) + } catch (err) { + console.error(`promise: doInit input arg invalid, code: ${err.code}, msg: ${err.message}`); + expect(null).assertFail(); + } +} + +async function publicUpdateSessionFunction(HuksOptions) { + const maxUpdateSize = 64; + const inData = HuksOptions.inData; + const lastInDataPosition = inData.length - 1; + let inDataSegSize = maxUpdateSize; + let inDataSegPosition = 0; + let isFinished = false; + let outData = []; + + while (inDataSegPosition <= lastInDataPosition) { + HuksOptions.inData = new Uint8Array( + Array.from(inData).slice(inDataSegPosition, inDataSegPosition + inDataSegSize) + ); + console.error(`enter promise doUpdate`); + try { + await huks.updateSession(handle, HuksOptions) + .then((data) => { + console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + outData = outData.concat(Array.from(data.outData)); + }) + .catch(error => { + console.error(`promise: doUpdate failed, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } + if (inDataSegPosition + maxUpdateSize > lastInDataPosition) { + isFinished = true; + inDataSegSize = lastInDataPosition - inDataSegPosition + 1; + console.error(`enter promise doUpdate`); + break; + } + if ((!isFinished) && (inDataSegPosition + maxUpdateSize > lastInDataPosition)) { + console.log(`update size invalid isFinished = ${isFinished}`); + console.log(`inDataSegPosition = ${inDataSegPosition}`); + console.log(`lastInDataPosition = ${lastInDataPosition}`); + expect(null).assertFail(); + return; + } + inDataSegPosition += maxUpdateSize; + } +} + +async function publicUpdateError(HuksOptions, errCode){ + console.error(`enter promise doUpdate`); + try { + await huks.updateSession(handle, HuksOptions) + .then((data) => { + console.error(`promise: doUpdate success, data = ${JSON.stringify(data)}`); + expect(null).assertFail(); + }) + .catch(error => { + console.error(`promise: doUpdate failed, code: ${error.code}, msg: ${error.message}`); + expect(err.code == errCode).assertTrue(); + }); + } catch (error) { + console.error(`promise: doUpdate input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } +} + +async function publicFinishSessionFunc(HuksOptions) { + console.error(`enter promise doFinish`); + try { + await huks.finishSession(handle, HuksOptions) + .then((data) => { + console.error(`promise: doFinish success, data = ${JSON.stringify(data)}`); + if (data !== null && data.outData !== null) { + signedResult = data.outData; + } + }) + .catch(error => { + console.error(`promise: doFinish failed, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + }); + } catch (error) { + console.error(`promise: doFinish input arg invalid, code: ${error.code}, msg: ${error.message}`); + expect(null).assertFail(); + } +} + +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(); + } +} + +export default function SecurityHuksRSASignExtendJsunit() { + describe('SecurityHuksRSASignExtendJsunit', function () { + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0100 + * @tc.name No Padding and Sign Verify with RSA. + * @tc.desc No Padding and Sign Verify with RSA. + */ + it("Security_HUKS_RSA_SignExtend_0100", 0, async function (done) { + let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0100_Gen"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + 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.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0200 + * @tc.name No Digest and Sign Verify with RSA. + * @tc.desc No Digest and Sign Verify with RSA. + */ + it("Security_HUKS_RSA_SignExtend_0200", 0, async function (done) { + let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0200"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + 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.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0300 + * @tc.name Alg, Purpose and length filled and Sign Verify with RSA. + * @tc.desc Alg, Purpose and length filled and Sign Verify with RSA. + */ + it("Security_HUKS_RSA_SignExtend_0300", 0, async function (done) { + let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0300"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + 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.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = srcData64Kb; + publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0400 + * @tc.name DigestNONE and Sign Verify with hashed plain test. + * @tc.desc DigestNONE and Sign Verify with hashed plain test. + */ + it("Security_HUKS_RSA_SignExtend_0400", 0, async function (done) { + let srcKeyAliesGen = "Security_HUKS_RSA_SignExtend_0400"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSINGVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: inDataAfterSha512, + } + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: inDataAfterSha512, + } + await publicGenerateKeyFunc(srcKeyAliesGen, HuksOptionsGen); + await publicInitFunc(srcKeyAliesGen, HuksOptionsSign); + HuksOptionsSign.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsSign); + HuksOptionsSign.inData = new Uint8Array(new Array()); + await publicFinishSessionFunc(HuksOptionsSign); + + let HuksOptionsVerify = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeVERIFY, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: signedResult, + } + await publicInitFunc(srcKeyAliesGen, HuksOptionsVerify); + HuksOptionsVerify.inData = inDataAfterSha512; + await publicUpdateSessionFunction(HuksOptionsVerify); + HuksOptionsVerify.inData = signedResult; + await publicFinishSessionFunc(HuksOptionsVerify); + await publicDeleteKeyFunc(srcKeyAliesGen, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0500 + * @tc.name No Padding while Sign Verify. + * @tc.desc No Padding while Sign Verify. + */ + it("Security_HUKS_RSA_SignExtend_0500", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_0500"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsSign, 401); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0600 + * @tc.name No Digest while Sign Verify. + * @tc.desc No Digest while Sign Verify. + */ + it("Security_HUKS_RSA_SignExtend_0600", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_0600"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsSign, 401); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0700 + * @tc.name Alg, Purpose and length only while Sign Verify. + * @tc.desc Alg, Purpose and length only while Sign Verify. + */ + it("Security_HUKS_RSA_SignExtend_0700", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_0700"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestSHA256, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: srcData64Kb, + } + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitSessionError(srcKeyAlies, HuksOptionsSign, 401); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + + /** + * @tc.number Security_HUKS_RSA_SignExtend_0800 + * @tc.name use plain text while Sign Verify. + * @tc.desc use plain text while Sign Verify. + */ + it("Security_HUKS_RSA_SignExtend_0800", 0, async function (done) { + let srcKeyAlies = "Security_HUKS_RSA_SignExtend_0800"; + let HuksOptionsGen = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: inDataAfterSha512, + }; + let HuksOptionsSign = { + properties: new Array( + HuksSignVerifyRSA.HuksKeyAlgRSA, + HuksSignVerifyRSA.HuksKeyRSAPurposeSIGN, + HuksSignVerifyRSA.HuksTagPKCS1DigestNONE, + HuksSignVerifyRSA.HuksKeyRSAPADDINGPKCS1V15, + HuksSignVerifyRSA.HuksKeyRSASize1024 + ), + inData: inDataString, + } + await publicGenerateKeyFunc(srcKeyAlies, HuksOptionsGen); + await publicInitFunc(srcKeyAlies, HuksOptionsSign); + await publicDeleteKeyFunc(srcKeyAlies, HuksOptionsGen); + done(); + }) + }) +} diff --git a/security_lite/huks/liteos_m_adapter/hks_derive_test.c b/security_lite/huks/liteos_m_adapter/hks_derive_test.c index 8ea66b806cefdeb48f1970b4487cb19616843c2e..a9bae3fc89b75e1ec036e76b7d5f4c6a0e677fd5 100644 --- a/security_lite/huks/liteos_m_adapter/hks_derive_test.c +++ b/security_lite/huks/liteos_m_adapter/hks_derive_test.c @@ -138,6 +138,32 @@ static const struct HksTestDeriveParams g_testDeriveParams[] = { { true, DEFAULT_LOCAL_KEY_SIZE, true, DEFAULT_LOCAL_KEY_SIZE } }, + /* pbkdf-sha256-salt-info */ + { 2, HKS_SUCCESS, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE }, + { + true, /* genKey params */ + true, HKS_ALG_AES, + true, HKS_AES_KEY_SIZE_256, + true, HKS_KEY_PURPOSE_DERIVE, + true, HKS_DIGEST_SHA256, + false, 0, + false, 0, + false, 0 }, + { 0 }, + { + true, /* derive params */ + true, HKS_ALG_PBKDF2, + true, HKS_KEY_PURPOSE_DERIVE, + true, HKS_DIGEST_SHA256, + true, 1000, + true, DEFAULT_SALT_SIZE, + true, DEFAULT_INFO_SIZE, + false, true }, + { + true, DEFAULT_DERIVE_SIZE, true, DEFAULT_DERIVE_SIZE }, + { + false, 0, false, 0 } + }, }; static int32_t DeriveKey(const struct HksTestDeriveParamSet *deriveParamSetParams, const struct HksBlob *masterKey, @@ -242,6 +268,15 @@ static void ExecHksDeriveTest002(void const *argument) osThreadExit(); } +static void ExecHksDeriveTest003(void const *argument) +{ + LiteTestPrint("HksDeriveTest003 Begin!\n"); + int32_t ret = BaseTestDerive(2); + TEST_ASSERT_TRUE(ret == 0); + LiteTestPrint("HksDeriveTest003 End!\n"); + osThreadExit(); +} + #ifndef _CUT_AUTHENTICATE_ /** * @tc.name: HksDeriveTest.HksDeriveTest001 @@ -264,6 +299,27 @@ LITE_TEST_CASE(HksDeriveTest, HksDeriveTest001, Level1) sleep(WAIT_TO_TEST_DONE); LiteTestPrint("HksDeriveTest001 End2!\n"); } +/** + * @tc.name: HksDeriveTest.HksDeriveTest003 + * @tc.desc: The static function will return true; + * @tc.type: FUNC + */ +LITE_TEST_CASE(HksDeriveTest, HksDeriveTest003, Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)ExecHksDeriveTest003, NULL, &attr); + sleep(WAIT_TO_TEST_DONE); + LiteTestPrint("HksDeriveTest001 End2!\n"); +} #endif /* _CUT_AUTHENTICATE_ */ /** @@ -287,4 +343,5 @@ LITE_TEST_CASE(HksDeriveTest, HksDeriveTest002, Level1) sleep(WAIT_TO_TEST_DONE); LiteTestPrint("HksDeriveTest002 End2!\n"); } + RUN_TEST_SUITE(HksDeriveTest); diff --git a/security_lite/huks/liteos_m_adapter/hks_hash_test.c b/security_lite/huks/liteos_m_adapter/hks_hash_test.c index 64f140c402ab34d670e223bff8e25ad192d29ed6..3800c29d8c2dffe0853cc39cf332283cef2896ec 100644 --- a/security_lite/huks/liteos_m_adapter/hks_hash_test.c +++ b/security_lite/huks/liteos_m_adapter/hks_hash_test.c @@ -30,7 +30,11 @@ #include #define DEFAULT_SRC_DATA_SIZE 200 +#define DIGEST_SHA1_HASH_SIZE 20 +#define DIGEST_SHA224_HASH_SIZE 28 #define DIGEST_SHA256_HASH_SIZE 32 +#define DIGEST_SHA384_HASH_SIZE 48 +#define DIGEST_SHA512_HASH_SIZE 64 #define TEST_TASK_STACK_SIZE 0x2000 #define WAIT_TO_TEST_DONE 4 @@ -92,50 +96,80 @@ static const struct HksTestHashParams g_testHashParams[] = { { true, DEFAULT_SRC_DATA_SIZE, true, DEFAULT_SRC_DATA_SIZE }, { true, DIGEST_SHA256_HASH_SIZE, true, DIGEST_SHA256_HASH_SIZE } }, + { 1, HKS_SUCCESS, + { true, true, HKS_DIGEST_SHA384 }, + { true, DEFAULT_SRC_DATA_SIZE, true, DEFAULT_SRC_DATA_SIZE }, + { true, DIGEST_SHA384_HASH_SIZE, true, DIGEST_SHA384_HASH_SIZE } + }, + { 2, HKS_SUCCESS, + { true, true, HKS_DIGEST_SHA512 }, + { true, DEFAULT_SRC_DATA_SIZE, true, DEFAULT_SRC_DATA_SIZE }, + { true, DIGEST_SHA512_HASH_SIZE, true, DIGEST_SHA512_HASH_SIZE } + }, }; -static void ExecHksHashTest001(void const *argument) +static void ExecHksHashTestCommon(int index) { - LiteTestPrint("HksMacTest001 Begin!\n"); struct HksParamSet *paramSet = NULL; struct HksBlob *srcData = NULL; struct HksBlob *hash = NULL; int32_t ret = TestConstructHashParamSet(¶mSet, - g_testHashParams[0].paramSetParams.paramSetExist, - g_testHashParams[0].paramSetParams.setDigest, g_testHashParams[0].paramSetParams.digest); + g_testHashParams[index].paramSetParams.paramSetExist, + g_testHashParams[index].paramSetParams.setDigest, g_testHashParams[index].paramSetParams.digest); TEST_ASSERT_TRUE(ret == 0); ret = TestConstuctBlob(&srcData, - g_testHashParams[0].srcDataParams.blobExist, - g_testHashParams[0].srcDataParams.blobSize, - g_testHashParams[0].srcDataParams.blobDataExist, - g_testHashParams[0].srcDataParams.blobDataSize); + g_testHashParams[index].srcDataParams.blobExist, + g_testHashParams[index].srcDataParams.blobSize, + g_testHashParams[index].srcDataParams.blobDataExist, + g_testHashParams[index].srcDataParams.blobDataSize); TEST_ASSERT_TRUE(ret == 0); ret = TestConstructBlobOut(&hash, - g_testHashParams[0].hashParams.blobExist, - g_testHashParams[0].hashParams.blobSize, - g_testHashParams[0].hashParams.blobDataExist, - g_testHashParams[0].hashParams.blobDataSize); + g_testHashParams[index].hashParams.blobExist, + g_testHashParams[index].hashParams.blobSize, + g_testHashParams[index].hashParams.blobDataExist, + g_testHashParams[index].hashParams.blobDataSize); TEST_ASSERT_TRUE(ret == 0); ret = HksHashRun(paramSet, srcData, hash, 1); - if (ret != g_testHashParams[0].expectResult) { - HKS_TEST_LOG_I("HksHashRun failed, ret[%u] = %d", g_testHashParams[0].testId, ret); + if (ret != g_testHashParams[index].expectResult) { + HKS_TEST_LOG_I("HksHashRun failed, ret[%u] = %d", g_testHashParams[index].testId, ret); } - TEST_ASSERT_TRUE(ret == g_testHashParams[0].expectResult); + TEST_ASSERT_TRUE(ret == g_testHashParams[index].expectResult); HksFreeParamSet(¶mSet); TestFreeBlob(&srcData); TestFreeBlob(&hash); - HKS_TEST_LOG_I("[%u]TestHash, Testcase_Hash_[%03u] pass!", 1, g_testHashParams[0].testId); + HKS_TEST_LOG_I("[%u]TestHash, Testcase_Hash_[%03u] pass!", 1, g_testHashParams[index].testId); TEST_ASSERT_TRUE(ret == 0); - +} + +static void ExecHksHashTest001(void const *argument) +{ + LiteTestPrint("HksMacTest001 Begin!\n"); + ExecHksHashTestCommon(0); LiteTestPrint("HksMacTest001 End!\n"); osThreadExit(); } +static void ExecHksHashTest002(void const *argument) +{ + LiteTestPrint("HksMacTest002 Begin!\n"); + ExecHksHashTestCommon(1); + LiteTestPrint("HksMacTest002 End!\n"); + osThreadExit(); +} + +static void ExecHksHashTest003(void const *argument) +{ + LiteTestPrint("HksMacTest003 Begin!\n"); + ExecHksHashTestCommon(2); + LiteTestPrint("HksMacTest003 End!\n"); + osThreadExit(); +} + /** * @tc.name: HksHashTest.HksHashTest001 * @tc.desc: The static function will return true; @@ -157,6 +191,48 @@ LITE_TEST_CASE(HksHashTest, HksHashTest001, Level1) sleep(WAIT_TO_TEST_DONE); LiteTestPrint("HksMacTest001 End2!\n"); } +/** + * @tc.name: HksHashTest.HksHashTest002 + * @tc.desc: The static function will return true; + * @tc.type: FUNC + */ +LITE_TEST_CASE(HksHashTest, HksHashTest002, Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)ExecHksHashTest002, NULL, &attr); + sleep(WAIT_TO_TEST_DONE); + LiteTestPrint("HksMacTest001 End2!\n"); +} +/** + * @tc.name: HksHashTest.HksHashTest003 + * @tc.desc: The static function will return true; + * @tc.type: FUNC + */ +LITE_TEST_CASE(HksHashTest, HksHashTest003, Level1) +{ + osThreadId_t id; + osThreadAttr_t attr; + g_setPriority = osPriorityAboveNormal6; + attr.name = "test"; + attr.attr_bits = 0U; + attr.cb_mem = NULL; + attr.cb_size = 0U; + attr.stack_mem = NULL; + attr.stack_size = TEST_TASK_STACK_SIZE; + attr.priority = g_setPriority; + id = osThreadNew((osThreadFunc_t)ExecHksHashTest003, NULL, &attr); + sleep(WAIT_TO_TEST_DONE); + LiteTestPrint("HksMacTest001 End2!\n"); +} RUN_TEST_SUITE(HksHashTest); #endif /* _CUT_AUTHENTICATE_ */