提交 5ed51502 编写于 作者: H hu-jixiang1

国密新增

Signed-off-by: Nhu-jixiang1 <hujixiang1@huawei.com>
Change-Id: I0d4065ea1453b9740a425d1c514fa44381b21f16
上级 b6727106
......@@ -360,3 +360,5 @@ describe('SecurityHuksCipherAESCallbackJsunit', function () {
done();
});
});
export {publicCipherFunc, IV, updateResult};
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import { HuksCipherSM4 } from '../../../../../../../utils/param/cipher/publicCipherParam';
import { HksTag } from '../../../../../../../utils/param/publicParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicCipherFunc, IV, updateResult } from './SecurityHuksAESBasicCallbackJsunit.test';
const plainString48Bytes = 'Hks_SM4_Cipher_Test_000000000000000000000_string';
const plainData48Bytes = stringToUint8Array(plainString48Bytes);
const plainString240Bytes =
'Hks_SM4_Cipher_Test_00000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000_string';
const plainData240Bytes = stringToUint8Array(plainString240Bytes);
let genHuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurpose
),
inData: new Uint8Array(new Array()),
};
describe('SecurityHuksCipherSM4CallbackJsunit', function () {
// HKS_SUPPORT_SM4_CBC_NOPADDING
it('testCipherSM4001_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias001';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4001_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias001';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4002_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias002';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4002_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias002';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_CBC_PKCS7
it('testCipherSM4003_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias003';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4003_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias003';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4004_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias004';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4004_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias004';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_CTR_NOPADDING
it('testCipherSM4005_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias005';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4005_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias005';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4006_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias006';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4006_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias006';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_ECB_NOPADDING
it('testCipherSM4007_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias007';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4007_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias007';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4008_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias008';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4008_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias008';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_ECB_PKCS7
it('testCipherSM4009_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias009';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4009_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias009';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(updateResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4010_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias010';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4010_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias010';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
});
......@@ -15,3 +15,4 @@
require('./Cipher/SecurityHuksAESBasicCallbackJsunit.test.js');
require('./Cipher/SecurityHuksRSABasicCallbackJsunit.test.js');
require('./Cipher/SecurityHuksSM4BasicCallbackJsunit.test.js');
\ No newline at end of file
......@@ -291,3 +291,5 @@ describe('SecurityHuksCipherAESPromiseJsunit', function () {
done();
});
});
export {publicCipherFunc, IV, updateResult};
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import { HuksCipherSM4 } from '../../../../../../../utils/param/cipher/publicCipherParam';
import { HksTag } from '../../../../../../../utils/param/publicParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicCipherFunc, IV, encryptedResult } from './SecurityHuksCipherAESBasicPromiseJsunit.test';
const plainString48Bytes = 'Hks_SM4_Cipher_Test_000000000000000000000_string';
const plainData48Bytes = stringToUint8Array(plainString48Bytes);
const plainString240Bytes =
'Hks_SM4_Cipher_Test_00000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'00000000000000000000000000000000000000000_string';
const plainData240Bytes = stringToUint8Array(plainString240Bytes);
let genHuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurpose
),
inData: new Uint8Array(new Array()),
};
describe('SecurityHuksCipherSM4PromiseJsunit', function () {
// HKS_SUPPORT_SM4_CBC_NOPADDING
it('testCipherSM4101_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias101';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4101_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias101';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4102_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias102';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4102_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECBCKeyAlias102';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_CBC_PKCS7
it('testCipherSM4103_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias103';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4103_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias103';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4104_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias104';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4104_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODECBCKeyAlias104';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECBC);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODECBC,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_CTR_NOPADDING
it('testCipherSM4105_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias105';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4105_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias105';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4106_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias106';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4106_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODECTRKeyAlias106';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODECTR);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODECTR,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_ECB_NOPADDING
it('testCipherSM4107_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias107';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4107_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias107';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4108_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias108';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4108_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGNONEMODEECBKeyAlias108';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGNONE);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGNONE,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
// HKS_SUPPORT_SM4_ECB_PKCS7
it('testCipherSM4109_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias109';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData48Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4109_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias109';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: plainData240Bytes,
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
true
);
HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeDECRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(encryptedResult),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'finish',
false
);
done();
});
it('testCipherSM4110_48', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias110';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData48Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
it('testCipherSM4110_240', 0, async function (done) {
const srcKeyAlias = 'testCipherSM4Size128PADDINGPKCS7MODEECBKeyAlias110';
genHuksOptions.properties.splice(2, 1, HuksCipherSM4.HuksKeySM4Size128);
genHuksOptions.properties.splice(3, 1, HuksCipherSM4.HuksKeySM4BLOCKMODEECB);
genHuksOptions.properties.splice(4, 1, HuksCipherSM4.HuksKeySM4PADDINGPKCS7);
let HuksOptions = {
properties: new Array(
HuksCipherSM4.HuksKeyAlgSM4,
HuksCipherSM4.HuksKeyPurposeENCRYPT,
HuksCipherSM4.HuksKeySM4Size128,
HuksCipherSM4.HuksKeySM4PADDINGPKCS7,
HuksCipherSM4.HuksKeySM4BLOCKMODEECB,
{ tag: HksTag.HKS_TAG_IV, value: stringToUint8Array(IV) }
),
inData: new Uint8Array(plainData240Bytes),
};
await publicCipherFunc(
srcKeyAlias,
genHuksOptions,
HuksOptions,
'abort',
true
);
done();
});
});
......@@ -15,3 +15,4 @@
require('./Cipher/SecurityHuksCipherAESBasicPromiseJsunit.test.js');
require('./Cipher/SecurityHuksCipherRSABasicPromiseJsunit.test.js');
require('./Cipher/SecurityHuksCipherSM4BasicPromiseJsunit.test.js');
\ No newline at end of file
......@@ -271,3 +271,113 @@ describe('SecurityHuksHmacCallbackJsunit', function () {
done();
});
});
describe('SecurityHuksHmacCallbackJsunit', function () {
it('testHmacSHA1001', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSHA1KeyAlias001';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSHA1
),
inData: srcData63Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSHA1002', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSHA1KeyAlias002';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSHA1
),
inData: srcData63Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
it('testHmacSHA1003', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSHA1KeyAlias003';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSHA1
),
inData: srcData65Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSHA1004', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSHA1KeyAlias004';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSHA1
),
inData: srcData65Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
it('testHmacSM3001', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias001';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData63Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSM3002', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias002';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData63Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
it('testHmacSM3003', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias003';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData65Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSM3004', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias004';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData65Kb,
};
await publicHmacGenFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
});
......@@ -179,4 +179,58 @@ describe('SecurityHuksHmacBasicPromiseJsunit', function () {
await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
it('testHmacSM3001', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias001';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData63Kb,
};
await publicHmacFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSM3002', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias002';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData63Kb,
};
await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
it('testHmacSM3003', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias003';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData65Kb,
};
await publicHmacFunc(srcKeyAlies, HuksOptions, 'finish');
done();
});
it('testHmacSM3004', 0, async function (done) {
let srcKeyAlies = 'testHmacDigestSM3KeyAlias004';
let HuksOptions = {
properties: new Array(
HuksHmac.HuksKeyAlg,
HuksHmac.HuksKeyPurpose,
HuksHmac.HuksTagDigestSM3
),
inData: srcData65Kb,
};
await publicHmacFunc(srcKeyAlies, HuksOptions, 'abort');
done();
});
});
......@@ -26,3 +26,7 @@ require('./SignVerify/SecurityHuksRSABasicAbort63KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksRSABasicFinish65KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksRSABasicAbort65KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksED25519BasicCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicAbort63KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicAbort65KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicFinish63KBCallbackJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicFinish65KBCallbackJsunit.test.js');
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js';
let srcData63 = Data.Data63b;
let srcData63Kb = stringToUint8Array(srcData63);
describe('SecurityHuksSignVerifySM2CallbackJsunit', function () {
it('testSignVerifySM200211111', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySm2Size256SIGNSM3KeyAlias002';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData63Kb,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'abort',
true,
srcData63Kb
);
done();
});
});
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js';
let srcData65 = Data.Data65b;
let srcData65Kb = stringToUint8Array(srcData65);
describe('SecurityHuksSignVerifySM2CallbackJsunit', function () {
it('testSignVerifySM2004', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias004';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData65Kb,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'abort',
true,
srcData65Kb
);
done();
});
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js';
let srcData63 = Data.Data63b;
let srcData63Kb = stringToUint8Array(srcData63);
let finishOutData;
describe('SecurityHuksSignVerifySM2CallbackJsunit', function () {
it('testSignVerifySM2001', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias001';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData63Kb,
};
finishOutData = await publicSignVerifyFunc(
srcKeyAlies,
srcKeyAlies + 'New',
HuksOptions,
'finish',
true,
srcData63Kb
);
HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeVERIFY,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: finishOutData,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
false,
srcData63Kb
);
done();
});
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyCallback.js';
let srcData65 = Data.Data65b;
let srcData65Kb = stringToUint8Array(srcData65);
let finishOutData;
describe('SecurityHuksSignVerifySM2CallbackJsunit', function () {
it('testSignVerifySM2003', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias003';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData65Kb,
};
finishOutData = await publicSignVerifyFunc(
srcKeyAlies,
srcKeyAlies + 'New',
HuksOptions,
'finish',
true,
srcData65Kb
);
HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeVERIFY,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: finishOutData,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
false,
srcData65Kb
);
done();
});
});
\ No newline at end of file
......@@ -26,3 +26,7 @@ require('./SignVerify/SecurityHuksRSABasicAbort63KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksRSABasicFinish65KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksRSABasicAbort65KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksED25519BasicPromiseJsunit.test');
require('./SignVerify/SecurityHuksSM2BasicAbort63KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicAbort65KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicFinish63KBPromiseJsunit.test.js');
require('./SignVerify/SecurityHuksSM2BasicFinish65KBPromiseJsunit.test.js');
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js';
let srcData63 = Data.Data63b;
let srcData63Kb = stringToUint8Array(srcData63);
describe('SecurityHuksSignVerifySM2PromiseJsunit', function () {
it('testSignVerifySM2102', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias102';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData63Kb,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'abort',
true,
srcData63Kb
);
done();
});
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js';
let srcData65 = Data.Data65b;
let srcData65Kb = stringToUint8Array(srcData65);
describe('SecurityHuksSignVerifySM2PromiseJsunit', function () {
it('testSignVerifySM2104', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias104';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData65Kb,
};
await publicSignVerifyFunc(srcKeyAlies, HuksOptions, 'abort', true, srcData65Kb);
done();
});
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js';
let srcData63 = Data.Data63b;
let srcData63Kb = stringToUint8Array(srcData63);
let finishOutData;
describe('SecurityHuksSignVerifySM2PromiseJsunit', function () {
it('testSignVerifySM2101', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias101';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData63Kb,
};
finishOutData = await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
true,
srcData63Kb
);
HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeVERIFY,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: finishOutData,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
false,
srcData63Kb
);
done();
});
});
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, it } from 'deccjsunit/index';
import Data from '../../../../../../../utils/data.json';
import { HuksSignVerifySM2 } from '../../../../../../../utils/param/signverify/publicSignverifyParam';
import { stringToUint8Array } from '../../../../../../../utils/param/publicFunc';
import { publicSignVerifyFunc } from '../../../../../../../utils/param/signverify/publicSignverifyPromise.js';
let srcData65 = Data.Data65b;
let srcData65Kb = stringToUint8Array(srcData65);
let finishOutData;
describe('SecurityHuksSignVerifySM2PromiseJsunit', function () {
it('testSignVerifySM2103', 0, async function (done) {
const srcKeyAlies = 'testSignVerifySM2Size256SIGNSM3KeyAlias103';
let HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeSIGN,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: srcData65Kb,
};
finishOutData = await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
true,
srcData65Kb
);
HuksOptions = {
properties: new Array(
HuksSignVerifySM2.HuksKeyAlgSM2,
HuksSignVerifySM2.HuksKeySM2PurposeVERIFY,
HuksSignVerifySM2.HuksTagSM2DigestSM3,
HuksSignVerifySM2.HuksKeySize256
),
inData: finishOutData,
};
await publicSignVerifyFunc(
srcKeyAlies,
HuksOptions,
'finish',
false,
srcData65Kb
);
done();
});
});
\ No newline at end of file
......@@ -132,4 +132,49 @@ let HuksCipherRSA = {
value: param.HksKeyDigest.HKS_DIGEST_SHA512,
},
};
export { HuksCipherAES, HuksCipherRSA };
let HuksCipherSM4 = {
HuksKeyAlgSM4: {
tag: param.HksTag.HKS_TAG_ALGORITHM,
value: param.HksKeyAlg.HKS_ALG_SM4,
},
HuksKeyPurpose: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value:
param.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT |
param.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
},
HuksKeyPurposeENCRYPT: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value: param.HksKeyPurpose.HKS_KEY_PURPOSE_ENCRYPT,
},
HuksKeyPurposeDECRYPT: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value: param.HksKeyPurpose.HKS_KEY_PURPOSE_DECRYPT,
},
HuksKeySM4Size128: {
tag: param.HksTag.HKS_TAG_KEY_SIZE,
value: param.HksKeySize.HKS_SM4_KEY_SIZE_128,
},
HuksKeySM4PADDINGNONE: {
tag: param.HksTag.HKS_TAG_PADDING,
value: param.HksKeyPadding.HKS_PADDING_NONE,
},
HuksKeySM4PADDINGPKCS7: {
tag: param.HksTag.HKS_TAG_PADDING,
value: param.HksKeyPadding.HKS_PADDING_PKCS7,
},
HuksKeySM4BLOCKMODECBC: {
tag: param.HksTag.HKS_TAG_BLOCK_MODE,
value: param.HksCipherMode.HKS_MODE_CBC,
},
HuksKeySM4BLOCKMODECTR: {
tag: param.HksTag.HKS_TAG_BLOCK_MODE,
value: param.HksCipherMode.HKS_MODE_CTR,
},
HuksKeySM4BLOCKMODEECB: {
tag: param.HksTag.HKS_TAG_BLOCK_MODE,
value: param.HksCipherMode.HKS_MODE_ECB,
},
};
export { HuksCipherAES, HuksCipherRSA, HuksCipherSM4 };
......@@ -14,7 +14,7 @@
*/
import * as param from '../publicParam';
let HuksHmac = {
let HuksHmac = {
HuksKeyAlg: {
tag: param.HksTag.HKS_TAG_ALGORITHM,
value: param.HksKeyAlg.HKS_ALG_HMAC,
......@@ -47,5 +47,9 @@ let HuksHmac = {
tag: param.HksTag.HKS_TAG_DIGEST,
value: param.HksKeyDigest.HKS_DIGEST_SHA512,
},
HuksTagDigestSM3: {
tag: param.HksTag.HKS_TAG_DIGEST,
value: param.HksKeyDigest.HKS_DIGEST_SM3,
},
};
export { HuksHmac };
......@@ -18,12 +18,15 @@ let HksKeyAlg = {
HKS_ALG_DH: 103,
HKS_ALG_AES: 20,
HKS_ALG_HMAC: 50,
HKS_ALG_X25519: 102,
HKS_ALG_X25519: 101,
HKS_ALG_RSA: 1,
HKS_ALG_PBKDF2: 52,
HKS_ALG_HKDF: 51,
HKS_ALG_DSA: 3,
HKS_ALG_ED25519: 102,
HKS_ALG_SM2: 150,
HKS_ALG_SM3: 151,
HKS_ALG_SM4: 152,
};
let HksKeyPurpose = {
HKS_KEY_PURPOSE_AGREE: 256,
......@@ -67,6 +70,8 @@ let HksKeySize = {
HKS_DSA_KEY_SIZE_2048: 2048,
HKS_DSA_KEY_SIZE_3072: 3072,
HKS_DSA_KEY_SIZE_4096: 4096,
HKS_SM2_KEY_SIZE_256: 256,
HKS_SM4_KEY_SIZE_128: 128,
};
let HksKeyStorageType = {
HKS_STORAGE_TEMP: 0,
......@@ -85,6 +90,7 @@ let HksKeyDigest = {
HKS_DIGEST_SHA256: 12,
HKS_DIGEST_SHA384: 13,
HKS_DIGEST_SHA512: 14,
HKS_DIGEST_SM3: 2,
};
let HksKeyPadding = {
HKS_PADDING_NONE: 0,
......
......@@ -261,4 +261,32 @@ let HuksSignVerifyRSA = {
value: param.HksKeyDigest.HKS_DIGEST_SHA512,
},
};
export { HuksSignVerifyRSA, HuksSignVerifyDSA, HuksSignVerifyECC, HuksSignVerifyED25519 };
let HuksSignVerifySM2 = {
HuksKeySize256: {
tag: param.HksTag.HKS_TAG_KEY_SIZE,
value: param.HksKeySize.HKS_SM2_KEY_SIZE_256,
},
HuksKeyAlgSM2: {
tag: param.HksTag.HKS_TAG_ALGORITHM,
value: param.HksKeyAlg.HKS_ALG_SM2,
},
HuksKeySM2PurposeSIGN: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value: param.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN,
},
HuksKeySM2PurposeVERIFY: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value: param.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
},
HuksTagSM2DigestSM3: {
tag: param.HksTag.HKS_TAG_DIGEST,
value: param.HksKeyDigest.HKS_DIGEST_SM3,
},
HuksKeySM2PurposeSINGVERIFY: {
tag: param.HksTag.HKS_TAG_PURPOSE,
value:
param.HksKeyPurpose.HKS_KEY_PURPOSE_SIGN |
param.HksKeyPurpose.HKS_KEY_PURPOSE_VERIFY,
},
};
export { HuksSignVerifyRSA, HuksSignVerifyDSA, HuksSignVerifyECC, HuksSignVerifyED25519 ,HuksSignVerifySM2};
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册