diff --git a/AppScope/app.json5 b/AppScope/app.json5 new file mode 100644 index 0000000000000000000000000000000000000000..a64f0c3b87fa32e55570cb5882fedb83c7b2cd1e --- /dev/null +++ b/AppScope/app.json5 @@ -0,0 +1,11 @@ +{ + "app": { + "bundleName": "com.ohos.myapplication", + "vendor": "example", + "versionCode": 1000002, + "versionName": "1.0.2", + "icon": "$media:app_icon", + "label": "$string:app_name", + "distributedNotificationEnabled": true + } +} diff --git a/AppScope/resources/base/element/string.json b/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..39bb6adfe67251a77a3443db211bb603951604dd --- /dev/null +++ b/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "OHOS_APP_crypto-js" + } + ] +} diff --git a/AppScope/resources/base/media/app_icon.png b/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/AppScope/resources/base/media/app_icon.png differ diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d3eb86aed211f2984145a01d8cadef795f8600..46cc95b2365f7ed8bd1ccd88b3210a3142b9a009 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,42 @@ #### 版本迭代 +- v1.0.2 +- 适配API9 + +- v1.0.1 +- 已实现功能 + 1. sha224 + 2. sha384 + 3. sha3 + 4. hmac-sha224 + 5. hmac-sha384 + 6. hmac-sha3 + 7. pbkdf2 + 8. aes + 9. tripledes + 10. rc4 + 11. rabbit + 12. rabbit-legacy + 13. evpkdf + 14. format-openssl + 15. format-hex + 16. enc-latin1 + 17. enc-utf8 + 18. enc-hex + 19. enc-utf16 + 20. enc-base64 + 21. mode-cfb + 22. mode-ctr + 23. mode-ctr-gladman + 24. mode-ofb + 25. mode-ecb + 26. pad-pkcs7 + 27. pad-ansix923 + 28. pad-iso10126 + 29. pad-iso97971 + 30. pad-zeropadding + 31. pad-nopadding + - v1.0.0 - 已实现功能 1. md5 diff --git a/README.md b/README.md index f43a66ef31b8e2b7f7978e17a52ad7f47b085aae..8a99586b5616673f3b2d4d35e5d692ba6a5567e7 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # crypto-js ## 简介 -> crypto-js是一个加密算法类库,可以非常方便的在前端进行其所支持的加解密操作。目前crypto-js已支持的算法有:MD5、SHA-1、SHA-256、HMAC、HMAC-MD5、HMAC-SHA1、HMAC-SHA256、PBKDF2等。 +> 加密算法类库,可以非常方便的在前端进行其所支持的加解密操作。目前crypto-js已支持的算法有:MD5、SHA-1、SHA-256、HMAC、HMAC-MD5、HMAC-SHA1、HMAC-SHA256、PBKDF2等。 ![preview.gif](preview/preview.gif) @@ -14,11 +14,26 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony ## 使用说明 1. 引入依赖 ``` + import { BlockCipher } from '@ohos/crypto/' + import prompt from '@system.prompt' import { md5 } from '@ohos/crypto/' import { sha1 } from '@ohos/crypto/' import { sha256 } from '@ohos/crypto/' import { sha512 } from '@ohos/crypto/' import { ripemd160 } from '@ohos/crypto/' + import { sha224 } from '@ohos/crypto/' + import { sha384 } from '@ohos/crypto/' + import { sha3 } from '@ohos/crypto/' + import { Latin1 } from '@ohos/crypto/' + import { Hex } from '@ohos/crypto/' + import { WordArray } from '@ohos/crypto/' + import { EvpKDF } from '@ohos/crypto/' + import { Utf8 } from '@ohos/crypto/' + import { Utf16 } from '@ohos/crypto/' + import { Utf16LE } from '@ohos/crypto/' + import { PBKDF2 } from '@ohos/crypto/' + import { AES, ECB, NoPadding } from '@ohos/crypto/' + import { Base64 } from '@ohos/crypto/' ``` 2. md5 ``` @@ -60,6 +75,30 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony ``` ripemd160.prototype.hex_hmac_rmd160('message', 'pwd') ``` +12. WordArray + ``` + let random: WordArray = WordArray.create(words, sigBytes) + let random: WordArray = WordArray.random(nBytes) + ``` +12. hex + ``` + let wordArray = Hex.parse(hexStr) + let result = Hex.stringify(wordArray); + ``` +13. aes + ``` + var ciphertext = aes.encrypt(value, key,{mode:CBC,padding:PKCS7,iv:iv}).toString(); + + var msg = aes.decrypt("dxzV163oPuT1U/2786nFDHP4dcg8W2Kj4GRgkzAwv1s=", key,{mode:CBC,padding:PKCS7,iv:iv}).toString(Utf8.prototype); + ``` +14. 处理中文编码 +``` + **编码 + aes.encrypt(Utils.strToBinary("测试中文"), key,{mode:CBC,padding:PKCS7,iv:iv}).toString(); + **解码 + var bytes = aes.decrypt("i1bWXSmmhXu9V4+eXGgimxBpobMMq06/ej9qQnG3QtNvNMHddUTiKnaKXvXTXNRljFJ5ASQhD8HbBPmKuJre8A==", key,{mode:CBC,padding:PKCS7,iv:iv}).toString(Utf8.prototype); + var value = Utils.binaryToStr(bytes) +``` ## 接口说明 1. md5加密 @@ -72,6 +111,10 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony `sha512.hex_sha512(s)` 5. ripemd160加密 `ripemd160.hex_rmd160(s)` +6. 十六进制解析`Hex.parse()` +7. WordArray转换十六进制字符串`Hex.stringify()` +8. 随机生成WordArray`WordArray.random()` +9. 创建WordArray`WordArray.create()` ## 兼容性 支持 OpenHarmony API version 8 及以上版本。 @@ -84,17 +127,43 @@ OpenHarmony npm环境配置等更多内容,请参考 [如何安装OpenHarmony | |---- src | |---- main | |---- ets -| |---- md5.ets # md5加密类 -| |---- ripemd160.ets # ripemd160加密类 -| |---- sha1.ets # sha1加密类 -| |---- sha256.ets # sha256加密类 -| |---- sha512.ets # sha512加密类 +| |---- AES # aes加密类 +| |---- BufferedBlockAlgorithmConfig.ts # mode接口 +| |---- EDS.ts # des加密类 +| |---- enc-base64.ts # base64加密类 +| |---- enc-hex.ts # hex加密类 +| |---- enc-utf8.ts # utf8加密类 +| |---- enc-utf16.ts # utf16加密类 +| |---- enc-utf16LE.ts # utf16LE加密类 +| |---- Encoding.ts # Encoding接口 +| |---- evpkdf.ts # evpkdf加密类 +| |---- KDF.ts # kdf加密类 +| |---- Latin1.ts # latin1加密类 +| |---- lib-WordArray.ts # 随机数类 +| |---- hmac.ts # hmac加密类 +| |---- md5.ts # md5加密类 +| |---- MyMD5.ts # md5加密类 +| |---- MySha1.ts # sha1加密类 +| |---- pbkdf2.ts # pbkdf2加密类 +| |---- rabbit.ts # rabbit加密类 +| |---- rabbit-legacy.ts # rabbit-legacy加密类 +| |---- RC4.ts # RC4加密类 +| |---- RC4Drop.ts # RC4Drop加密类 +| |---- ripemd160.ts # ripemd160加密类 +| |---- sha1.ts # sha1加密类 +| |---- sha256.ts # sha256加密类 +| |---- sha512.ts # sha512加密类 +| |---- StreamCipher.ts # 流加密类 +| |---- TripleDES.ts # TripleDES加密类 +| |---- Utf8.ts # Utf8加密类 +| |---- Utils.ts # 针对string转ascii 和ascii 转string +| |---- x64_core.ts # sha3的实体 | |---- index.ets # 对外接口 | |---- README.md # 安装使用方法 ```` ## 贡献代码 -使用过程中发现任何问题都可以提 [Issue](https://gitee.com/openharmony-sig/crypto-js/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/openharmony-sig/crypto-js/pulls) 。 +使用过程中发现任何问题都可以提 [Issue](https://gitee.com/hihopeorg/crypto-js/issues) 给我们,当然,我们也非常欢迎你给我们发 [PR](https://gitee.com/hihopeorg/crypto-js/pulls) 。 ## 开源协议 -本项目基于 [MIT License](https://gitee.com/openharmony-sig/crypto-js/blob/master/LICENSE) ,请自由地享受和参与开源。 +本项目基于 [MIT License](https://gitee.com/hihopeorg/crypto-js/blob/master/LICENSE) ,请自由地享受和参与开源。 diff --git a/build-profile.json5 b/build-profile.json5 index 7f9e2f32dff3cc6765fa9fe134f88e3cef856c53..3d053a0d0a68c406f34c23d0d18fb0a9a9c1aecc 100644 --- a/build-profile.json5 +++ b/build-profile.json5 @@ -1,11 +1,11 @@ { "app": { - "compileSdkVersion": 8, - "compatibleSdkVersion": 8, + "compileSdkVersion": 9, + "compatibleSdkVersion": 9, "products": [ { "name": "default", - "signingConfig": "default", + "signingConfig": "default" } ] }, diff --git a/crypto/build-profile.json5 b/crypto/build-profile.json5 index 107d8c761a767ae4bd6c3798021d9fad61751005..35dff6d53cb3a241f8de4fb68bd01d38ade0f108 100644 --- a/crypto/build-profile.json5 +++ b/crypto/build-profile.json5 @@ -1,5 +1,5 @@ { - "apiType": "faMode", + "apiType": "stageMode", "buildOption": { } } diff --git a/crypto/hvigorfile.js b/crypto/hvigorfile.js index 3a7c40cd644527fdf586c81b110e346329f38c9a..42ed4b4a54a873e2b53441556aae93fab24b794f 100644 --- a/crypto/hvigorfile.js +++ b/crypto/hvigorfile.js @@ -1,3 +1,3 @@ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -module.exports = require('@ohos/hvigor-ohos-plugin').legacyHarTasks +module.exports = require('@ohos/hvigor-ohos-plugin').harTasks diff --git a/crypto/index.ts b/crypto/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..9433b98779d28a27c9808da6366ec8bf243c4260 --- /dev/null +++ b/crypto/index.ts @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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. + */ +export { BlockCipher }from './src/main/ets/AES/lib/BlockCipher' + +export { md5 } from './src/main/ets/md5' + +export { sha1 } from './src/main/ets/sha1' + +export { sha256 } from './src/main/ets/sha256' + +export { sha512 } from './src/main/ets/sha512' + +export { ripemd160 } from './src/main/ets/ripemd160' + +export { sha224 } from './src/main/ets/sha224' + +export { sha384 } from './src/main/ets/sha384' + +export { sha3 } from './src/main/ets/sha3' + +export { Latin1 } from './src/main/ets/enc-latin1' + +export { Utf8 } from './src/main/ets/enc-utf8' + +export { Utf16 } from './src/main/ets/enc-utf16' + +export { Utf16BE } from './src/main/ets/enc-utf16BE' + +export { Utf16LE } from './src/main/ets/enc-utf16LE' + +export { Hex } from './src/main/ets/enc-hex' + +export { WordArray } from './src/main/ets/lib-WordArray' + +export { EvpKDF } from './src/main/ets/evpkdf' + +export { AES } from './src/main/ets/AES/AES' + +export { ECB }from './src/main/ets/AES/mode/ECB' + +export { CBC }from './src/main/ets/AES/mode/CBC' + +export { CFB }from './src/main/ets/AES/mode/CFB' + +export { CTR }from './src/main/ets/AES/mode/CTR' + +export { CTRGladman }from './src/main/ets/AES/mode/CTRGladman' + +export { OFB }from './src/main/ets/AES/mode/OFB' + +export { NoPadding }from './src/main/ets/AES/pad/NoPadding' + +export { PKCS7 }from './src/main/ets/AES/pad/PKCS7' + +export { AnsiX923 }from './src/main/ets/AES/pad/AnsiX923' + +export { Iso10126 }from './src/main/ets/AES/pad/Iso10126' + +export { Iso97971 }from './src/main/ets/AES/pad/Iso97971' + +export { ZeroPadding }from './src/main/ets/AES/pad/ZeroPadding' + +export { CipherParams }from './src/main/ets/AES/lib/CipherParams' + +export { PBKDF2 } from './src/main/ets/pbkdf2' + +export { OpenSSL } from './src/main/ets/AES/format/OpenSSL' + +export { HexFormatter } from './src/main/ets/AES/format/format-hex' + +export { Base64 } from './src/main/ets/enc-base64' + +export { Base64Url } from './src/main/ets/enc-base64url' + +export { DES } from './src/main/ets/DES' + +export { TripleDES } from './src/main/ets/TripleDES' + +export { RC4 } from './src/main/ets/RC4' + +export { RC4Drop } from './src/main/ets/RC4Drop' + +export { StreamCipher } from './src/main/ets/StreamCipher' + +export { Rabbit } from './src/main/ets/rabbit' + +export { Rabbit_Legacy } from './src/main/ets/rabbit-legacy' + +export { Utils } from './src/main/ets/Utils' diff --git a/crypto/package-lock.json b/crypto/package-lock.json index 5324b3fb444ce295c0a277089d1c74d49ff9d80e..de27e5eaf32502a9bfad8e6e06caf7fa1a66b9c7 100644 --- a/crypto/package-lock.json +++ b/crypto/package-lock.json @@ -1,5 +1,13 @@ { "name": "@ohos/crypto-js", - "version": "1.0.0", - "lockfileVersion": 1 + "version": "1.0.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "jssha": { + "version": "3.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/jssha/-/jssha-3.2.0.tgz", + "integrity": "sha512-QuruyBENDWdN4tZwJbQq7/eAK85FqrI4oDbXjy5IBhYD+2pTJyBUWZe8ctWaCkrV0gy6AaelgOZZBMeswEa/6Q==" + } + } } diff --git a/crypto/package.json b/crypto/package.json index a7257d5fab451e1ebd605e6580bb6ac2b4f97a69..b9251b32574b1d1a29f243e3985ecc0a7f3e2529 100644 --- a/crypto/package.json +++ b/crypto/package.json @@ -1,18 +1,25 @@ { - "name": "@ohos/crypto-js", - "version": "1.0.0", - "description": "The encryption algorithm class library can be very convenient to perform the encryption and decryption operations it supports in the front end. Currently, the algorithms supported by crypto-js are: MD5, SHA-1, SHA-256, HMAC, HMAC-MD5, HMAC-SHA1, HMAC-SHA256, PBKDF2, etc.", - "ohos": { - "org": "" - }, - "main": "index.ets", - "types": "", - "author": "hihope", - "license": "MIT", - "repository": "https://gitee.com/openharmony-tpc/crypto-js", - "dependencies": {}, - "keywords": [ - "crypto-js", - "OpenHarmony" - ] + "types": "", + "keywords": [ + "crypto-js", + "OpenHarmony" + ], + "author": "hihope", + "description": "The encryption algorithm class library can be very convenient to perform the encryption and decryption operations it supports in the front end. Currently, the algorithms supported by crypto-js are: MD5, SHA-1, SHA-256, HMAC, HMAC-MD5, HMAC-SHA1, HMAC-SHA256, PBKDF2, etc.", + "ohos": { + "org": "opensource" + }, + "main": "index.ets", + "repository": "https://gitee.com/openharmony-sig/crypto-js", + "version": "1.0.1", + "tags": [ + "crypto-js", + "OpenHarmony" + ], + "dependencies": { + "jssha": "^3.2.0" + }, + "license": "MIT", + "devDependencies": {}, + "name": "@ohos/crypto-js" } diff --git a/crypto/src/main/config.json b/crypto/src/main/config.json deleted file mode 100644 index 24b6eea9b1f3bb5d7cb24af5bed67872e6a5ada0..0000000000000000000000000000000000000000 --- a/crypto/src/main/config.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "app": { - "bundleName": "cn.openharmony.crypto-js", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.crypto", - "deviceType": [ - "phone", - "tablet" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "crypto", - "moduleType": "har" - }, - "uiSyntax": "ets" - } -} diff --git a/crypto/src/main/ets/AES/AES.ts b/crypto/src/main/ets/AES/AES.ts new file mode 100644 index 0000000000000000000000000000000000000000..8f8da3d6b5438651c8d29f10f00caf7c1694c511 --- /dev/null +++ b/crypto/src/main/ets/AES/AES.ts @@ -0,0 +1,244 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../lib-WordArray'; +import { BlockCipher } from '../AES/lib/BlockCipher'; + +import { BufferedBlockAlgorithmConfig } from '../bufferedblockalgorithmconfig'; + +// Define lookup tables +const SBOX: Array = []; +const INV_SBOX: Array = []; +const SUB_MIX_0: Array = []; +const SUB_MIX_1: Array = []; +const SUB_MIX_2: Array = []; +const SUB_MIX_3: Array = []; +const INV_SUB_MIX_0: Array = []; +const INV_SUB_MIX_1: Array = []; +const INV_SUB_MIX_2: Array = []; +const INV_SUB_MIX_3: Array = []; + +// Compute lookup tables +(function () { + // Compute double table + const d = []; + for (let i = 0; i < 256; i++) { + if (i < 128) { + d[i] = i << 1; + } else { + d[i] = (i << 1) ^ 0x11b; + } + } + + // Walk GF(2^8) + let x = 0; + let xi = 0; + for (let i = 0; i < 256; i++) { + // Compute sbox + let sx = xi ^ (xi << 1) ^ (xi << 2) ^ (xi << 3) ^ (xi << 4); + sx = (sx >>> 8) ^ (sx & 0xff) ^ 0x63; + SBOX[x] = sx; + INV_SBOX[sx] = x; + + // Compute multiplication + const x2 = d[x]; + const x4 = d[x2]; + const x8 = d[x4]; + + // Compute sub bytes, mix columns tables + let t = (d[sx] * 0x101) ^ (sx * 0x1010100); + SUB_MIX_0[x] = (t << 24) | (t >>> 8); + SUB_MIX_1[x] = (t << 16) | (t >>> 16); + SUB_MIX_2[x] = (t << 8) | (t >>> 24); + SUB_MIX_3[x] = t; + + // Compute inv sub bytes, inv mix columns tables + t = (x8 * 0x1010101) ^ (x4 * 0x10001) ^ (x2 * 0x101) ^ (x * 0x1010100); + INV_SUB_MIX_0[sx] = (t << 24) | (t >>> 8); + INV_SUB_MIX_1[sx] = (t << 16) | (t >>> 16); + INV_SUB_MIX_2[sx] = (t << 8) | (t >>> 24); + INV_SUB_MIX_3[sx] = t; + + // Compute next counter + if (!x) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } +}()); + +// Precomputed Rcon lookup +const RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; + +export class AES extends BlockCipher { + // 256 / 32 + public static keySize = 8; + + _nRounds!: number; + + _key!: WordArray; + + _keyPriorReset!: WordArray; + + _keySchedule!: Array; + + _invKeySchedule!: Array; + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, cfg); + } + + reset() { + // reset core values + super.reset(); + + // Skip reset of nRounds has been set before and key did not change + if (this._nRounds && this._keyPriorReset === this._key) { + return; + } + + // Shortcuts + const key = this._keyPriorReset = this._key; + const keyWords = key.words; + const keySize = key.sigBytes / 4; + + // Compute number of rounds + const nRounds = this._nRounds = keySize + 6; + + // Compute number of key schedule rows + const ksRows = (nRounds + 1) * 4; + + // Compute key schedule + const keySchedule: Array = this._keySchedule = []; + for (let ksRow = 0; ksRow < ksRows; ksRow++) { + if (ksRow < keySize) { + keySchedule[ksRow] = keyWords[ksRow]; + } else { + let t = keySchedule[ksRow - 1]; + + if (!(ksRow % keySize)) { + // Rot word + t = (t << 8) | (t >>> 24); + + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + + // Mix Rcon + t ^= RCON[(ksRow / keySize) | 0] << 24; + } else if (keySize > 6 && ksRow % keySize === 4) { + // Sub word + t = (SBOX[t >>> 24] << 24) | (SBOX[(t >>> 16) & 0xff] << 16) | (SBOX[(t >>> 8) & 0xff] << 8) | SBOX[t & 0xff]; + } + + keySchedule[ksRow] = keySchedule[ksRow - keySize] ^ t; + } + } + + // Compute inv key schedule + const invKeySchedule: Array = this._invKeySchedule = []; + for (let invKsRow = 0; invKsRow < ksRows; invKsRow++) { + const ksRow = ksRows - invKsRow; + + let t; + if (invKsRow % 4) { + t = keySchedule[ksRow]; + } else { + t = keySchedule[ksRow - 4]; + } + + if (invKsRow < 4 || ksRow <= 4) { + invKeySchedule[invKsRow] = t; + } else { + invKeySchedule[invKsRow] = INV_SUB_MIX_0[SBOX[t >>> 24]] ^ INV_SUB_MIX_1[SBOX[(t >>> 16) & 0xff]] ^ + INV_SUB_MIX_2[SBOX[(t >>> 8) & 0xff]] ^ INV_SUB_MIX_3[SBOX[t & 0xff]]; + } + } + } + + encryptBlock(M: Array, offset: number) { + this._doCryptBlock(M, offset, this._keySchedule, SUB_MIX_0, SUB_MIX_1, SUB_MIX_2, SUB_MIX_3, SBOX); + } + + decryptBlock(M: Array, offset: number) { + // Swap 2nd and 4th rows + let t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + + this._doCryptBlock(M, offset, this._invKeySchedule, INV_SUB_MIX_0, INV_SUB_MIX_1, INV_SUB_MIX_2, INV_SUB_MIX_3, INV_SBOX); + + // Inv swap 2nd and 4th rows + t = M[offset + 1]; + M[offset + 1] = M[offset + 3]; + M[offset + 3] = t; + } + + _doCryptBlock( + M: Array, + offset: number, + keySchedule: Array, + sub_mix_0: Array, + sub_mix_1: Array, + sub_mix_2: Array, + sub_mix_3: Array, + sbox: Array + ) { + // Get input, add round key + let s0 = M[offset] ^ keySchedule[0]; + let s1 = M[offset + 1] ^ keySchedule[1]; + let s2 = M[offset + 2] ^ keySchedule[2]; + let s3 = M[offset + 3] ^ keySchedule[3]; + + // Key schedule row counter + let ksRow = 4; + + // Rounds + for (let round = 1; round < this._nRounds; round++) { + // Shift rows, sub bytes, mix columns, add round key + const t0 = sub_mix_0[s0 >>> 24] ^ sub_mix_1[(s1 >>> 16) & 0xff] ^ sub_mix_2[(s2 >>> 8) & 0xff] ^ sub_mix_3[s3 & 0xff] ^ + keySchedule[ksRow++]; + const t1 = sub_mix_0[s1 >>> 24] ^ sub_mix_1[(s2 >>> 16) & 0xff] ^ sub_mix_2[(s3 >>> 8) & 0xff] ^ sub_mix_3[s0 & 0xff] ^ + keySchedule[ksRow++]; + const t2 = sub_mix_0[s2 >>> 24] ^ sub_mix_1[(s3 >>> 16) & 0xff] ^ sub_mix_2[(s0 >>> 8) & 0xff] ^ sub_mix_3[s1 & 0xff] ^ + keySchedule[ksRow++]; + const t3 = sub_mix_0[s3 >>> 24] ^ sub_mix_1[(s0 >>> 16) & 0xff] ^ sub_mix_2[(s1 >>> 8) & 0xff] ^ sub_mix_3[s2 & 0xff] ^ + keySchedule[ksRow++]; + + // Update state + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + // Shift rows, sub bytes, add round key + const t0g = ((sbox[s0 >>> 24] << 24) | (sbox[(s1 >>> 16) & 0xff] << 16) | (sbox[(s2 >>> 8) & 0xff] << 8) | sbox[s3 & 0xff]) ^ + keySchedule[ksRow++]; + const t1g = ((sbox[s1 >>> 24] << 24) | (sbox[(s2 >>> 16) & 0xff] << 16) | (sbox[(s3 >>> 8) & 0xff] << 8) | sbox[s0 & 0xff]) ^ + keySchedule[ksRow++]; + const t2g = ((sbox[s2 >>> 24] << 24) | (sbox[(s3 >>> 16) & 0xff] << 16) | (sbox[(s0 >>> 8) & 0xff] << 8) | sbox[s1 & 0xff]) ^ + keySchedule[ksRow++]; + const t3g = ((sbox[s3 >>> 24] << 24) | (sbox[(s0 >>> 16) & 0xff] << 16) | (sbox[(s1 >>> 8) & 0xff] << 8) | sbox[s2 & 0xff]) ^ + keySchedule[ksRow++]; + + // Set output + M[offset] = t0g; + M[offset + 1] = t1g; + M[offset + 2] = t2g; + M[offset + 3] = t3g; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/Base64.ts b/crypto/src/main/ets/AES/Base64.ts new file mode 100644 index 0000000000000000000000000000000000000000..82154326cba85a1dcf574ac3449eb1cda0f1ee62 --- /dev/null +++ b/crypto/src/main/ets/AES/Base64.ts @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../lib-WordArray'; +import {Encoding} from '../Encoding' + +export class Base64 { + public static _map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + public static _reverseMap: Array | undefined = undefined; + + /** + * Converts a word array to a Base64 string. + * + * @param wordArray The word array. + * + * @return The Base64 string. + * + * @example + * + * let base64String = Base64.stringify(wordArray); + */ + public static stringify(wordArray: WordArray): string { + // Clamp excess bits + wordArray.clamp(); + + // Convert + const base64Chars = []; + for (let i = 0; i < wordArray.sigBytes; i += 3) { + const byte1 = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + const byte2 = (wordArray.words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + const byte3 = (wordArray.words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + const triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (let j = 0; (j < 4) && (i + j * 0.75 < wordArray.sigBytes); j++) { + base64Chars.push(this._map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + const paddingChar = this._map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + } + + /** + * Converts a Base64 string to a word array. + * + * @param base64Str The Base64 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Base64.parse(base64String); + */ + public static parse(base64Str: string): WordArray { + // Shortcuts + let base64StrLength = base64Str.length; + + if(this._reverseMap === undefined) { + this._reverseMap = []; + for(let j = 0; j < this._map.length; j++) { + this._reverseMap[this._map.charCodeAt(j)] = j; + } + } + + // Ignore padding + const paddingChar = this._map.charAt(64); + if(paddingChar) { + const paddingIndex = base64Str.indexOf(paddingChar); + if(paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return this.parseLoop(base64Str, base64StrLength, this._reverseMap); + } + + public static parseLoop(base64Str: string, base64StrLength: number, reverseMap: Array): WordArray { + const words: Array = []; + let nBytes = 0; + for(let i = 0; i < base64StrLength; i++) { + if(i % 4) { + const bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + const bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + + return new WordArray(words, nBytes); + } +} + +// type guard for the formatter (to ensure it has the required static methods) +const _: Encoding = Base64; \ No newline at end of file diff --git a/crypto/index.ets b/crypto/src/main/ets/AES/format/Local_Formatter.ts similarity index 71% rename from crypto/index.ets rename to crypto/src/main/ets/AES/format/Local_Formatter.ts index 2173305eb650688b3dbf23c67b444c864c9e152a..724854345db4303ab6c4058274a3e45643721303 100644 --- a/crypto/index.ets +++ b/crypto/src/main/ets/AES/format/Local_Formatter.ts @@ -13,8 +13,10 @@ * limitations under the License. */ -export { md5 } from './src/main/ets/md5' -export { sha1 } from './src/main/ets/sha1' -export { sha256 } from './src/main/ets/sha256' -export { sha512 } from './src/main/ets/sha512' -export { ripemd160 } from './src/main/ets/ripemd160' +import { CipherParams } from '../lib/CipherParams'; + +export interface Local_Formatter { + stringify: (cipherParams: CipherParams) => string; + + parse: (paramsStr: string) => CipherParams; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/format/OpenSSL.ts b/crypto/src/main/ets/AES/format/OpenSSL.ts new file mode 100644 index 0000000000000000000000000000000000000000..d1538323c637ce01429015b23e8f380509c2e370 --- /dev/null +++ b/crypto/src/main/ets/AES/format/OpenSSL.ts @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { Local_Formatter } from './Local_Formatter'; +import { CipherParams } from '../lib/CipherParams'; +import { Base64 } from '../Base64'; + +export class OpenSSL { + /** + * Converts a cipher params object to an OpenSSL-compatible string. + * + * @param cipherParams The cipher params object. + * + * @return The OpenSSL-compatible string. + * + * @example + * + * let openSSLString = OpenSSLFormatter.stringify(cipherParams); + */ + public static stringify(cipherParams: CipherParams): string { + if(!cipherParams.ciphertext) { + throw new Error('missing ciphertext in params'); + } + + // Shortcuts + const ciphertext = cipherParams.ciphertext; + const salt = cipherParams.salt; + + // Format + let wordArray: WordArray; + if(salt) { + if(typeof salt === 'string') { + throw new Error('salt is expected to be a WordArray'); + } + + wordArray = (new WordArray([0x53616c74, 0x65645f5f])).concat(salt).concat(ciphertext); + } else { + wordArray = ciphertext; + } + + return wordArray.toString(Base64); + } + + /** + * Converts an OpenSSL-compatible string to a cipher params object. + * + * @param openSSLStr The OpenSSL-compatible string. + * + * @return The cipher params object. + * + * @example + * + * let cipherParams = OpenSSLFormatter.parse(openSSLString); + */ + public static parse(openSSLStr: string): CipherParams { + // Parse base64 + const ciphertext = Base64.parse(openSSLStr); + + // Test for salt + let salt: WordArray | undefined; + if(ciphertext.words[0] === 0x53616c74 && ciphertext.words[1] === 0x65645f5f) { + // Extract salt + salt = new WordArray(ciphertext.words.slice(2, 4)); + + // Remove salt from ciphertext + ciphertext.words.splice(0, 4); + ciphertext.sigBytes -= 16; + } + + return new CipherParams({ ciphertext: ciphertext, salt: salt }); + } +} + +//// type guard for OpenSSL formatter (to ensure it has the required static methods) +const _: Local_Formatter = OpenSSL; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/format/format-hex.ts b/crypto/src/main/ets/AES/format/format-hex.ts new file mode 100644 index 0000000000000000000000000000000000000000..4a0508190644f7928012fc9c1df0a204274d655f --- /dev/null +++ b/crypto/src/main/ets/AES/format/format-hex.ts @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Hex } from '../../enc-hex'; +import { CipherParams } from '../lib/CipherParams'; +export class HexFormatter{ + static stringify(cipherParams:CipherParams):string { + return cipherParams.ciphertext.toString(Hex); + } + static parse(input:string) :CipherParams{ + var ciphertext = Hex.parse(input); + return CipherParams.create({ ciphertext: ciphertext }); + } +} + + diff --git a/entry/src/ohosTest/ets/TestAbility/app.ets b/crypto/src/main/ets/AES/kdf/KDF.ts similarity index 48% rename from entry/src/ohosTest/ets/TestAbility/app.ets rename to crypto/src/main/ets/AES/kdf/KDF.ts index b3e4bfe9f4368f6301e729de78a62b34d80cb5b9..bdc58ed3ae39143739cdd24ea950438427347f86 100644 --- a/entry/src/ohosTest/ets/TestAbility/app.ets +++ b/crypto/src/main/ets/AES/kdf/KDF.ts @@ -13,21 +13,9 @@ * limitations under the License. */ -import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' -import { Hypium } from 'hypium/index' -import testsuite from '../test/List.test' +import { WordArray } from '../../lib-WordArray'; +import { CipherParams } from '../lib/CipherParams'; -export default { - onCreate() { - console.info('Application onCreate') - var abilityDelegator: any - abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() - var abilityDelegatorArguments: any - abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() - console.info('start run testcase!!!') - Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) - }, - onDestroy() { - console.info('Application onDestroy') - }, +export interface KDF { + execute: (password: string, keySize: number, ivSize: number, salt?: WordArray | string) => CipherParams; } \ No newline at end of file diff --git a/crypto/src/main/ets/AES/kdf/OpenSSLKdf.ts b/crypto/src/main/ets/AES/kdf/OpenSSLKdf.ts new file mode 100644 index 0000000000000000000000000000000000000000..12c143d673af98ab94c6e9de29144df6191c0d61 --- /dev/null +++ b/crypto/src/main/ets/AES/kdf/OpenSSLKdf.ts @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { EvpKDF } from '../../evpkdf'; +import { WordArray } from '../../lib-WordArray'; +import { KDF } from './KDF'; +import { CipherParams } from '../lib/CipherParams'; + +export class OpenSSLKdf { + /** + * Derives a key and IV from a password. + * + * @param password The password to derive from. + * @param keySize The size in words of the key to generate. + * @param ivSize The size in words of the IV to generate. + * @param salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. + * + * @return A cipher params object with the key, IV, and salt. + * + * @example + * + * let derivedParams = OpenSSL.execute('Password', 256/32, 128/32); + * let derivedParams = OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); + */ + public static execute(password: string, keySize: number, ivSize: number, salt?: WordArray | string): CipherParams { + // Generate random salt + if(!salt) { + salt = WordArray.random(64 / 8); + } + + // Derive key and IV + const key = (new EvpKDF({ keySize: keySize + ivSize })).compute(password, salt); + + // Separate key and IV + const iv = new WordArray(key.words.slice(keySize), ivSize * 4); + key.sigBytes = keySize * 4; + + // Return params + return new CipherParams({ key: key, iv: iv, salt: salt }); + } +} + +const _: KDF = OpenSSLKdf; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/BlockCipher.ts b/crypto/src/main/ets/AES/lib/BlockCipher.ts new file mode 100644 index 0000000000000000000000000000000000000000..9836e77ba7a0c74666f55816af6d58a2c28d8315 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/BlockCipher.ts @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { Cipher } from './Cipher'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; +import { BlockCipherModeAlgorithm } from '../mode/BlockCipherModeAlgorithm'; +import { CBC } from '../mode/CBC'; +import { PKCS7 } from '../pad/PKCS7'; + +export abstract class BlockCipher extends Cipher { + public _mode!: BlockCipherModeAlgorithm; + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, Object.assign({ + // default: 128 / 32 + blockSize: 4, + mode: CBC, + padding: PKCS7 + }, cfg)); + } + + public reset() { + // Reset cipher + super.reset(); + + // Check if we have a blockSize + if(this.cfg.mode === undefined) { + throw new Error('missing mode in config'); + } + + // Reset block mode + let modeCreator; + if (this._xformMode === ( this.constructor)._ENC_XFORM_MODE) { + modeCreator = this.cfg.mode.createEncryptor; + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + modeCreator = this.cfg.mode.createDecryptor; + // Keep at least one block in the buffer for unpadding + this._minBufferSize = 1; + } + + if (this._mode && this._mode.__creator === modeCreator) { + this._mode.init(this, this.cfg.iv && this.cfg.iv.words); + } else { + this._mode = modeCreator.call(this.cfg.mode, this, this.cfg.iv && this.cfg.iv.words); + this._mode.__creator = modeCreator; + } + } + + _doProcessBlock(words: Array, offset: number) { + this._mode.processBlock(words, offset); + } + + _doFinalize() { + // Check if we have a padding strategy + if(this.cfg.padding === undefined) { + throw new Error('missing padding in config'); + } + + // Finalize + let finalProcessedBlocks; + if(this._xformMode === ( this.constructor)._ENC_XFORM_MODE) { + // Check if we have a blockSize + if(this.cfg.blockSize === undefined) { + throw new Error('missing blockSize in config'); + } + + // Pad data + this.cfg.padding.pad(this._data, this.cfg.blockSize); + + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ { + // Process final blocks + finalProcessedBlocks = this._process(!!'flush'); + + // Unpad data + this.cfg.padding.unpad(finalProcessedBlocks); + } + + return finalProcessedBlocks; + } + + public abstract encryptBlock(M: Array, offset: number): void; + + public abstract decryptBlock(M: Array, offset: number): void; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/BufferedBlockAlgorithm.ts b/crypto/src/main/ets/AES/lib/BufferedBlockAlgorithm.ts new file mode 100644 index 0000000000000000000000000000000000000000..3e00331cd0548025155e315fdb9d2edd12fc12c0 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/BufferedBlockAlgorithm.ts @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { Utf8 } from '../../enc-utf8'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; + +export abstract class BufferedBlockAlgorithm { + public _minBufferSize = 0; + + public _data: WordArray; + + public _nDataBytes: number; + + public cfg: BufferedBlockAlgorithmConfig; + + abstract _doProcessBlock(wordArray: Array, offset: number): void; + + public constructor(xformMode: number, key: WordArray,cfg?: BufferedBlockAlgorithmConfig) { + this.cfg = Object.assign({ + blockSize: 1 + }, cfg); + + // Initial values + this._data = new WordArray(); + this._nDataBytes = 0; + } + + /** + * Resets this block algorithm's data buffer to its initial state. + * + * @example + * + * bufferedBlockAlgorithm.reset(); + */ + reset() { + // Initial values + this._data = new WordArray(); + this._nDataBytes = 0; + } + + /** + * Adds new data to this block algorithm's buffer. + * + * @param data The data to append. Strings are converted to a WordArray using UTF-8. + * + * @example + * + * bufferedBlockAlgorithm._append('data'); + * bufferedBlockAlgorithm._append(wordArray); + */ + _append(data: string | WordArray) { + // Convert string to WordArray, else assume WordArray already + if(typeof data === 'string') { + data = Utf8.prototype.parse(data); + } + + // Append + this._data.concat(data); + this._nDataBytes += data.sigBytes; + } + + /** + * Processes available data blocks. + * + * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype. + * + * @param doFlush Whether all blocks and partial blocks should be processed. + * + * @return The processed data. + * + * @example + * + * let processedData = bufferedBlockAlgorithm._process(); + * let processedData = bufferedBlockAlgorithm._process(!!'flush'); + */ + _process(doFlush?: boolean): WordArray { + if(!this.cfg.blockSize) { + throw new Error('missing blockSize in config'); + } + + // Shortcuts + const blockSizeBytes = this.cfg.blockSize * 4; + + // Count blocks ready + let nBlocksReady = this._data.sigBytes / blockSizeBytes; + if (doFlush) { + // Round up to include partial blocks + nBlocksReady = Math.ceil(nBlocksReady); + } else { + // Round down to include only full blocks, + // less the number of blocks that must remain in the buffer + nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0); + } + + // Count words ready + const nWordsReady = nBlocksReady * this.cfg.blockSize; + + // Count bytes ready + const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes); + + // Process blocks + let processedWords; + if (nWordsReady) { + for (let offset = 0; offset < nWordsReady; offset += this.cfg.blockSize) { + // Perform concrete-algorithm logic + this._doProcessBlock(this._data.words, offset); + } + + // Remove processed words + processedWords = this._data.words.splice(0, nWordsReady); + this._data.sigBytes -= nBytesReady; + } + + // Return processed words + return new WordArray(processedWords, nBytesReady); + } + + /** + * Creates a copy of this object. + * + * @return The clone. + * + * @example + * + * let clone = bufferedBlockAlgorithm.clone(); + */ + clone(): BufferedBlockAlgorithm { + const clone = this.constructor(); + + for(const attr in this) { + if(this.hasOwnProperty(attr)) { + clone[attr] = this[attr]; + } + } + + clone._data = this._data.clone(); + + return clone; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/Cipher.ts b/crypto/src/main/ets/AES/lib/Cipher.ts new file mode 100644 index 0000000000000000000000000000000000000000..c9f38fc5e509ea9829bc41f39992a149f33cdfce --- /dev/null +++ b/crypto/src/main/ets/AES/lib/Cipher.ts @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { BufferedBlockAlgorithm } from './BufferedBlockAlgorithm'; +import { SerializableCipher } from './SerializableCipher'; +import { PasswordBasedCipher } from './PasswordBasedCipher'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; +import { CipherParams } from './CipherParams'; + +export abstract class Cipher extends BufferedBlockAlgorithm { + /** + * A constant representing encryption mode. + */ + public static _ENC_XFORM_MODE = 1; + + /** + * A constant representing decryption mode. + */ + public static _DEC_XFORM_MODE = 2; + + /** + * This cipher's key size. Default: 4 (128 bits / 32 Bits) + */ + public static keySize = 4; + + /** + * This cipher's IV size. Default: 4 (128 bits / 32 Bits) + */ + public static ivSize = 4; + + /** + * Either the encryption or decryption transformation mode constant. + */ + public _xformMode: number; + + /** + * The key. + */ + public _key: WordArray; + + /** + * Creates this cipher in encryption mode. + * + * @param key The key. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return A cipher instance. + * + * @example + * + * let cipher = AES.createEncryptor(keyWordArray, { iv: ivWordArray }); + */ + public static createEncryptor(key: WordArray, cfg?: BufferedBlockAlgorithmConfig): Cipher { + // workaround for typescript not being able to create a abstract creator function directly + const thisClass: any = this; + + return new thisClass(this._ENC_XFORM_MODE, key, cfg); + } + + /** + * Creates this cipher in decryption mode. + * + * @param key The key. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return A cipher instance. + * + * @example + * + * let cipher = AES.createDecryptor(keyWordArray, { iv: ivWordArray }); + */ + public static createDecryptor(key: WordArray, cfg?: BufferedBlockAlgorithmConfig): Cipher { + // workaround for typescript not being able to create a abstract creator function directly + const thisClass: any = this; + + return new thisClass(this._DEC_XFORM_MODE, key, cfg); + } + + /** + * Creates shortcut functions to a cipher's object interface. + * + * @param cipher The cipher to create a helper for. + * + * @return An object with encrypt and decrypt shortcut functions. + * + * @example + * + * let AES = Cipher._createHelper(AESAlgorithm); + */ + public static _createHelper(cipher: typeof Cipher) { + function encrypt(message: WordArray | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig) { + if(typeof key === 'string') { + return PasswordBasedCipher.encrypt(cipher, message, key, cfg); + } else { + return SerializableCipher.encrypt(cipher, message, key, cfg); + } + } + + function decrypt(ciphertext: CipherParams | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig) { + if(typeof key === 'string') { + return PasswordBasedCipher.decrypt(cipher, ciphertext, key, cfg); + } else { + return SerializableCipher.decrypt(cipher, ciphertext, key, cfg); + } + } + + return { + encrypt: encrypt, + decrypt: decrypt + }; + } + + /** + * Initializes a newly created cipher. + * + * @param xformMode Either the encryption or decryption transormation mode constant. + * @param key The key. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @example + * + * let cipher = AES.create(AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); + */ + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + // Apply config defaults + super(xformMode,key,Object.assign({ + blockSize: 1 + }, cfg)); + + // Store transform mode and key + this._xformMode = xformMode; + this._key = key; + + // Set initial values + this.reset(); + } + + /** + * Adds data to be encrypted or decrypted. + * + * @param dataUpdate The data to encrypt or decrypt. + * + * @return The data after processing. + * + * @example + * + * let encrypted = cipher.process('data'); + * let encrypted = cipher.process(wordArray); + */ + public process(dataUpdate: WordArray | string): WordArray { + // Append + this._append(dataUpdate); + + // Process available blocks + return this._process(); + } + + /** + * Finalizes the encryption or decryption process. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param dataUpdate The final data to encrypt or decrypt. + * + * @return The data after final processing. + * + * @example + * + * var encrypted = cipher.finalize(); + * var encrypted = cipher.finalize('data'); + * var encrypted = cipher.finalize(wordArray); + */ + public finalize(dataUpdate?: WordArray | string): WordArray { + // Final data update + if(dataUpdate) { + this._append(dataUpdate); + } + + // Perform concrete-cipher logic + const finalProcessedData = this._doFinalize(); + + return finalProcessedData; + } + + /** + * Cipher specific finalize function explicitly implemented in the derived class. + */ + public abstract _doFinalize(): WordArray; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/CipherParams.ts b/crypto/src/main/ets/AES/lib/CipherParams.ts new file mode 100644 index 0000000000000000000000000000000000000000..ecd05cebac3ee721ee91235b32fb24d6c7d9c041 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/CipherParams.ts @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; + +import { CipherParamsInterface } from './CipherParamsInterface'; +import { Cipher } from '../lib/Cipher'; +import { BlockCipherMode } from '../mode/BlockCipherMode'; +import { EPadding } from '../pad/EPadding'; +import { Local_Formatter } from '../format/Local_Formatter'; + +export class CipherParams implements CipherParamsInterface { + ciphertext?: WordArray; + + key?: WordArray | string; + + iv?: WordArray; + + salt?: WordArray | string; + + algorithm?: typeof Cipher; + + mode?: typeof BlockCipherMode; + + padding?: EPadding; + + blockSize?: number; + + formatter?: Local_Formatter; + + /** + * Initializes a newly created cipher params object. + * + * @param cipherParams An object with any of the possible cipher parameters. + * + * @example + * + * let cipherParams = CipherParams.create({ + * ciphertext: ciphertextWordArray, + * key: keyWordArray, + * iv: ivWordArray, + * salt: saltWordArray, + * algorithm: AESAlgorithm, + * mode: CBC, + * padding: PKCS7, + * blockSize: 4, + * formatter: OpenSSLFormatter + * }); + */ + public constructor(cipherParams: CipherParamsInterface) { + this.ciphertext = cipherParams.ciphertext; + this.key = cipherParams.key; + this.iv = cipherParams.iv; + this.salt = cipherParams.salt; + this.algorithm = cipherParams.algorithm; + this.mode = cipherParams.mode; + this.padding = cipherParams.padding; + this.blockSize = cipherParams.blockSize; + this.formatter = cipherParams.formatter; + } + + public static create(cipherParams: CipherParamsInterface):CipherParams{ + return new CipherParams(cipherParams); + } + + public extend(additionalParams: CipherParams): CipherParams { + if(additionalParams.ciphertext !== undefined) { + this.ciphertext = additionalParams.ciphertext; + } + + if(additionalParams.key !== undefined) { + this.key = additionalParams.key; + } + + if(additionalParams.iv !== undefined) { + this.iv = additionalParams.iv; + } + + if(additionalParams.salt !== undefined) { + this.salt = additionalParams.salt; + } + + if(additionalParams.algorithm !== undefined) { + this.algorithm = additionalParams.algorithm; + } + + if(additionalParams.mode !== undefined) { + this.mode = additionalParams.mode; + } + + if(additionalParams.padding !== undefined) { + this.padding = additionalParams.padding; + } + + if(additionalParams.blockSize !== undefined) { + this.blockSize = additionalParams.blockSize; + } + + if(additionalParams.formatter !== undefined) { + this.formatter = additionalParams.formatter; + } + + + return this; + } + + /** + * Converts this cipher params object to a string. + * + * @param formatter (Optional) The formatting strategy to use. + * + * @return The stringified cipher params. + * + * @throws Error If neither the formatter nor the default formatter is set. + * + * @example + * + * let string = cipherParams + ''; + * let string = cipherParams.toString(); + * let string = cipherParams.toString(CryptoJS.format.OpenSSL); + */ + public toString(formatter?: Local_Formatter): string { + if(formatter) { + return formatter.stringify(this); + } else if(this.formatter) { + return this.formatter.stringify(this); + } else { + throw new Error('cipher needs a formatter to be able to convert the result into a string'); + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/CipherParamsInterface.ts b/crypto/src/main/ets/AES/lib/CipherParamsInterface.ts new file mode 100644 index 0000000000000000000000000000000000000000..7d0fe39cbcaab228792869b973a593c3fb4a1131 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/CipherParamsInterface.ts @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { Cipher } from '../lib/Cipher'; +import { BlockCipherMode } from '../mode/BlockCipherMode'; +import { EPadding } from '../pad/EPadding'; +import { Local_Formatter } from '../format/Local_Formatter'; + +export interface CipherParamsInterface { + ciphertext?: WordArray; + + key?: WordArray | string; + + iv?: WordArray; + + salt?: WordArray | string; + + algorithm?: typeof Cipher; + + mode?: typeof BlockCipherMode; + + padding?: EPadding; + + blockSize?: number; + + formatter?: Local_Formatter; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/Hasher.ts b/crypto/src/main/ets/AES/lib/Hasher.ts new file mode 100644 index 0000000000000000000000000000000000000000..cecf603998e12ff85a1603316e277d75894e8821 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/Hasher.ts @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { BufferedBlockAlgorithm } from '../lib/BufferedBlockAlgorithm'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; +import { HMAC } from '../../hmac'; + + +export abstract class Hasher extends BufferedBlockAlgorithm { + /** + * Creates a shortcut function to a hasher's object interface. + * + * @param hasher The hasher to create a helper for. + * + * @return The shortcut function. + * + * @example + * + * let SHA256 = Hasher._createHelper(SHA256); + */ + blockSize: number = 18 + + public static _createHelper(hasher: typeof Hasher) { + function helper(message: WordArray | string, cfg?: BufferedBlockAlgorithmConfig) { + const hasherClass: any = hasher; + const hasherInstance: any = new hasherClass(cfg); + return hasherInstance.finalize(message); + } + + return { + helper: helper + } + } + + public static _createHmacHelper(hasher: Hasher) { + function helper(message: WordArray | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig) { + const hmacHasher: any = hasher; + const hasherInstance: any = new hmacHasher(cfg); + return new HMAC(hasherInstance, key).finalize(message); + }; + return { + helper: helper + }; + } + + /** + * Initializes a newly created hasher. + * + * @param cfg (Optional) The configuration options to use for this hash computation. + * + * @example + * + * let hasher = CryptoJS.algo.SHA256.create(); + */ + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + // Apply config defaults + super(xformMode, key, Object.assign({ + blockSize: 512 / 32 + }, cfg)); + // Set initial values + this.reset(); + } + + /** + * Updates this hasher with a message. + * + * @param messageUpdate The message to append. + * + * @return This hasher. + * + * @example + * + * hasher.update('message'); + * hasher.update(wordArray); + */ + update(messageUpdate: WordArray | string): Hasher { + // Append + this._append(messageUpdate); + // Update the hash + this._process(); + // Chainable + return this; + } + + /** + * Finalizes the hash computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param messageUpdate (Optional) A final message update. + * + * @return The hash. + * + * @example + * + * let hash = hasher.finalize(); + * let hash = hasher.finalize('message'); + * let hash = hasher.finalize(wordArray); + */ + public finalize(messageUpdate: WordArray | string): WordArray { + // Final message update + if (messageUpdate) { + this._append(messageUpdate); + } + // Perform concrete-hasher logic + const hash = this._doFinalize(); + return hash; + } + + public abstract _doFinalize(): WordArray; + + clone() { + return super.clone(); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/PasswordBasedCipher.ts b/crypto/src/main/ets/AES/lib/PasswordBasedCipher.ts new file mode 100644 index 0000000000000000000000000000000000000000..7c22ccbfb5706b9b468099e4104464969889ee5f --- /dev/null +++ b/crypto/src/main/ets/AES/lib/PasswordBasedCipher.ts @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { OpenSSLKdf } from '../kdf/OpenSSLKdf'; +import { WordArray } from '../../lib-WordArray'; +import { SerializableCipher } from './SerializableCipher'; +import { Cipher } from './Cipher'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; +import { OpenSSL } from '../format/OpenSSL'; +import { CipherParams } from './CipherParams'; +import { Local_Formatter } from '../format/Local_Formatter'; + +export class PasswordBasedCipher { + public static cfg: BufferedBlockAlgorithmConfig = { + blockSize: 4, + iv: new WordArray([]), + format: OpenSSL, + kdf: OpenSSLKdf + }; + + /** + * Encrypts a message using a password. + * + * @param cipher The cipher algorithm to use. + * @param message The message to encrypt. + * @param password The password. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return A cipher params object. + * + * @example + * + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(AES, message, 'password'); + * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(AES, message, 'password', { format: OpenSSL }); + */ + public static encrypt( + cipher: typeof Cipher, + message: WordArray | string, + password: string, + cfg?: BufferedBlockAlgorithmConfig + ): CipherParams { + // Apply config defaults + const config = Object.assign({}, this.cfg, cfg); + + // Check if we have a kdf + if(config.kdf === undefined) { + throw new Error('missing kdf in config'); + } + + // Derive key and other params + const derivedParams: CipherParams = config.kdf.execute(password, cipher.keySize, cipher.ivSize); + + // Check if we have an IV + if(derivedParams.iv !== undefined) { + // Add IV to config + config.iv = derivedParams.iv; + } + + // Encrypt + const ciphertext: CipherParams = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, config); + + // Mix in derived params + return ciphertext.extend(derivedParams); + } + + /** + * Decrypts serialized ciphertext using a password. + * + * @param cipher The cipher algorithm to use. + * @param ciphertext The ciphertext to decrypt. + * @param password The password. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return The plaintext. + * + * @example + * + * var plaintext = PasswordBasedCipher.decrypt(AES, formattedCiphertext, 'password', { format: OpenSSL }); + * var plaintext = PasswordBasedCipher.decrypt(AES, ciphertextParams, 'password', { format: OpenSSL }); + */ + public static decrypt( + cipher: typeof Cipher, + ciphertext: CipherParams | string, + password: string, + cfg?: BufferedBlockAlgorithmConfig + ): WordArray { + // Apply config defaults + const config = Object.assign({}, this.cfg, cfg); + + // Check if we have a kdf + if(config.format === undefined) { + throw new Error('missing format in config'); + } + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, config.format); + + // Check if we have a kdf + if(config.kdf === undefined) { + throw new Error('the key derivation function must be set'); + } + + // Derive key and other params + const derivedParams = config.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt); + + // Check if we have an IV + if(derivedParams.iv !== undefined) { + // Add IV to config + config.iv = derivedParams.iv; + } + + // Decrypt + const plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, config); + + return plaintext; + } + + /** + * Converts serialized ciphertext to CipherParams, + * else assumed CipherParams already and returns ciphertext unchanged. + * + * @param ciphertext The ciphertext. + * @param format The formatting strategy to use to parse serialized ciphertext. + * + * @return The unserialized ciphertext. + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); + */ + public static _parse(ciphertext: CipherParams | string, format: Local_Formatter): CipherParams { + if(typeof ciphertext === 'string') { + return format.parse(ciphertext); + } else { + return ciphertext; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/lib/SerializableCipher.ts b/crypto/src/main/ets/AES/lib/SerializableCipher.ts new file mode 100644 index 0000000000000000000000000000000000000000..014a7894313f75015d68ddc1d99d78d92a226ba1 --- /dev/null +++ b/crypto/src/main/ets/AES/lib/SerializableCipher.ts @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { Cipher } from './Cipher'; +import { BufferedBlockAlgorithmConfig } from '../../BufferedBlockAlgorithmConfig'; +import { OpenSSL } from '../format/OpenSSL'; +import { CipherParams } from './CipherParams'; +import { Local_Formatter } from '../format/Local_Formatter'; + +export class SerializableCipher { + public static cfg: BufferedBlockAlgorithmConfig = { + blockSize: 4, + iv: new WordArray([]), + format: OpenSSL + }; + + /** + * Encrypts a message. + * + * @param cipher The cipher algorithm to use. + * @param message The message to encrypt. + * @param key The key. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return A cipher params object. + * + * @example + * + * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); + * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); + * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { + * iv: iv, + * format: CryptoJS.format.OpenSSL + * }); + */ + public static encrypt( + cipher: typeof Cipher, + message: WordArray | string, + key: WordArray, + cfg?: BufferedBlockAlgorithmConfig + ): CipherParams { + // Apply config defaults + const config = Object.assign({}, this.cfg, cfg); + + // Encrypt + const encryptor = cipher.createEncryptor(key, config); + const ciphertext = encryptor.finalize(message); + + // Create and return serializable cipher params + return new CipherParams({ + ciphertext: ciphertext, + key: key, + iv: encryptor.cfg.iv, + algorithm: cipher, + mode: ( encryptor.cfg).mode, + padding: ( encryptor.cfg).padding, + blockSize: encryptor.cfg.blockSize, + formatter: config.format + }); + } + + /** + * Decrypts serialized ciphertext. + * + * @param cipher The cipher algorithm to use. + * @param ciphertext The ciphertext to decrypt. + * @param key The key. + * @param cfg (Optional) The configuration options to use for this operation. + * + * @return The plaintext. + * + * @example + * + * let plaintext = SerializableCipher.decrypt( + * AESAlgorithm, + * formattedCiphertext, + * key, { + * iv: iv, + * format: CryptoJS.format.OpenSSL + * } + * ); + * + * let plaintext = SerializableCipher.decrypt( + * AESAlgorithm, + * ciphertextParams, + * key, { + * iv: iv, + * format: CryptoJS.format.OpenSSL + * } + * ); + */ + public static decrypt( + cipher: typeof Cipher, + ciphertext: CipherParams | string, + key: WordArray, + optionalCfg?: BufferedBlockAlgorithmConfig + ): WordArray { + // Apply config defaults + const cfg = Object.assign({}, this.cfg, optionalCfg); + + if(!cfg.format) { + throw new Error('could not determine format'); + } + + // Convert string to CipherParams + ciphertext = this._parse(ciphertext, cfg.format); + + if(!ciphertext.ciphertext) { + throw new Error('could not determine ciphertext'); + } + + // Decrypt + const plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); + + return plaintext; + } + + /** + * Converts serialized ciphertext to CipherParams, + * else assumed CipherParams already and returns ciphertext unchanged. + * + * @param ciphertext The ciphertext. + * @param format The formatting strategy to use to parse serialized ciphertext. + * + * @return The unserialized ciphertext. + * + * @example + * + * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); + */ + public static _parse(ciphertext: CipherParams | string, format: Local_Formatter): CipherParams { + if(typeof ciphertext === 'string') { + return format.parse(ciphertext); + } else { + return ciphertext; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/BlockCipherMode.ts b/crypto/src/main/ets/AES/mode/BlockCipherMode.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c74b0f6519c2cedeba0539b7f70521c61ddd653 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/BlockCipherMode.ts @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipher } from '../lib/BlockCipher'; +import { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export abstract class BlockCipherMode { + public static Encryptor: any = BlockCipherModeAlgorithm; + + public static Decryptor: any = BlockCipherModeAlgorithm; + + /** + * Creates this mode for encryption. + * + * @param cipher A block cipher instance. + * @param iv The IV words. + * + * @example + * + * var mode = CBC.createEncryptor(cipher, iv.words); + */ + public static createEncryptor(cipher: BlockCipher, iv: Array): BlockCipherModeAlgorithm { + // workaround for typescript not being able to create a abstract creator function directly + const encryptorClass: any = this.Encryptor; + + return new encryptorClass(cipher, iv); + } + + /** + * Creates this mode for decryption. + * + * @param cipher A block cipher instance. + * @param iv The IV words. + * + * @example + * + * var mode = CBC.createDecryptor(cipher, iv.words); + */ + public static createDecryptor(cipher: BlockCipher, iv: Array): BlockCipherModeAlgorithm { + // workaround for typescript not being able to create a abstract creator function directly + const decryptorClass: any = this.Decryptor; + + return new decryptorClass(cipher, iv); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/BlockCipherModeAlgorithm.ts b/crypto/src/main/ets/AES/mode/BlockCipherModeAlgorithm.ts new file mode 100644 index 0000000000000000000000000000000000000000..c5f601cafa326cf81ecfe67be77b646e55f3d5dc --- /dev/null +++ b/crypto/src/main/ets/AES/mode/BlockCipherModeAlgorithm.ts @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipher } from '../lib/BlockCipher'; +import { BlockCipherMode } from './BlockCipherMode'; + +export abstract class BlockCipherModeAlgorithm { + public _cipher!: BlockCipher; + + public _iv: Array | undefined; + + public __creator: ((cipher: BlockCipher, iv: number[]) => BlockCipherMode) | undefined; + + public constructor(cipher: BlockCipher, iv: Array) { + this.init(cipher, iv); + } + + /** + * Initializes a newly created mode. + * + * @param cipher A block cipher instance. + * @param iv The IV words. + * + * @example + * + * var mode = CBC.Encryptor.create(cipher, iv.words); + */ + public init(cipher: BlockCipher, iv?: Array) { + this._cipher = cipher; + this._iv = iv; + } + + public abstract processBlock(words: Array, offset: number): void; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CBC.ts b/crypto/src/main/ets/AES/mode/CBC.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ce45d8fef6ecf466e7031bf7484cf56b1d7fe65 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CBC.ts @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherMode } from './BlockCipherMode'; +import { CBCEncryptor } from './CBCEncryptor'; +import { CBCDecryptor } from './CBCDecryptor'; + +/** + * Cipher Block Chaining mode. + */ +export abstract class CBC extends BlockCipherMode { + public static Encryptor: any = CBCEncryptor; + + public static Decryptor: any = CBCDecryptor; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CBCDecryptor.ts b/crypto/src/main/ets/AES/mode/CBCDecryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..067267c678a4c3e5aeeb0183a35c97a031981fc3 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CBCDecryptor.ts @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CBCDecryptor extends BlockCipherModeAlgorithm { + public _prevBlock: Array | undefined; + + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + // Check if we have a blockSize + if(this._cipher.cfg.blockSize === undefined) { + throw new Error('missing blockSize in cipher config'); + } + + // Remember this block to use with next block + const thisBlock = words.slice(offset, offset + this._cipher.cfg.blockSize); + + // Decrypt and XOR + this._cipher.decryptBlock(words, offset); + this.xorBlock(words, offset, this._cipher.cfg.blockSize); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + + public xorBlock(words: Array, offset: number, blockSize: number) { + // Choose mixing block + let block; + if(this._iv) { + block = this._iv; + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + block = this._prevBlock; + } + + // block should never be undefined but we want to make typescript happy + if(block !== undefined) { + // XOR blocks + for(let i = 0; i < blockSize; i++) { + words[offset + i] ^= block[i]; + } + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CBCEncryptor.ts b/crypto/src/main/ets/AES/mode/CBCEncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..1a5da209c2bd3eb906bbe9893f1739cb7aefd91a --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CBCEncryptor.ts @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CBCEncryptor extends BlockCipherModeAlgorithm { + public _prevBlock: Array | undefined; + + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + // Check if we have a blockSize + if(this._cipher.cfg.blockSize === undefined) { + throw new Error('missing blockSize in cipher config'); + } + + // XOR and encrypt + this.xorBlock(words, offset, this._cipher.cfg.blockSize); + this._cipher.encryptBlock(words, offset); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + this._cipher.cfg.blockSize); + } + + public xorBlock(words: Array, offset: number, blockSize: number) { + // Choose mixing block + let block; + if(this._iv) { + block = this._iv; + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + block = this._prevBlock; + } + + // block should never be undefined but we want to make typescript happy + if(block !== undefined) { + // XOR blocks + for(let i = 0; i < blockSize; i++) { + words[offset + i] ^= block[i]; + } + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CFB.ts b/crypto/src/main/ets/AES/mode/CFB.ts new file mode 100644 index 0000000000000000000000000000000000000000..418133bc97dc06a4df06704356f80c6e1da89482 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CFB.ts @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherMode } from './BlockCipherMode'; +import { CFBEncryptor } from './CFBEncryptor'; +import { CFBDecryptor } from './CFBDecryptor'; + +/** + * Cipher Block Chaining mode. + */ +export abstract class CFB extends BlockCipherMode { + public static Encryptor: any = CFBEncryptor; + + public static Decryptor: any = CFBDecryptor; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CFBDecryptor.ts b/crypto/src/main/ets/AES/mode/CFBDecryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..c079bf3d5cf63075de193b1b99ea9cca3c841e5b --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CFBDecryptor.ts @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CFBDecryptor extends BlockCipherModeAlgorithm { + private _prevBlock:Array + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + // Shortcuts + var cipher = this._cipher; + var blockSize = cipher.cfg.blockSize; + if (blockSize == 0 || blockSize == undefined) { + blockSize = 1; + } + + // Remember this block to use with next block + var thisBlock = words.slice(offset, offset + blockSize); + + this.generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // This block becomes the previous block + this._prevBlock = thisBlock; + } + + generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + + // Shortcut + var iv = this._iv; + + // Generate keystream + if (iv) { + keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + keystream = this._prevBlock; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CFBEncryptor.ts b/crypto/src/main/ets/AES/mode/CFBEncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..774fabcfe56aa3f013e11020d0b44a49e87553e6 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CFBEncryptor.ts @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CFBEncryptor extends BlockCipherModeAlgorithm { + private _prevBlock + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + // Shortcuts + var cipher = this._cipher; + var blockSize = this._cipher.cfg.blockSize; + + if (blockSize == 0 || blockSize == undefined) { + blockSize = 1; + } + + this.generateKeystreamAndEncrypt.call(this, words, offset, blockSize, cipher); + + // Remember this block to use with next block + this._prevBlock = words.slice(offset, offset + blockSize); + } + + generateKeystreamAndEncrypt(words, offset, blockSize, cipher) { + var keystream; + + // Shortcut + var iv = this._iv; + + // Generate keystream + if (iv) { + keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } else { + keystream = this._prevBlock; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CTR.ts b/crypto/src/main/ets/AES/mode/CTR.ts new file mode 100644 index 0000000000000000000000000000000000000000..eabc48dd1d2790697a285f89be3f4074d18f6974 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CTR.ts @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { CTREncryptor } from './CTREncryptor'; +import { BlockCipherMode } from './BlockCipherMode'; + +export abstract class CTR extends BlockCipherMode { + public static Encryptor: any = CTREncryptor; + + public static Decryptor: any = CTREncryptor; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CTREncryptor.ts b/crypto/src/main/ets/AES/mode/CTREncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..7fd34a87f041e416cf25da86ffaaf0222f9e262a --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CTREncryptor.ts @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CTREncryptor extends BlockCipherModeAlgorithm { + private _counter + public processBlock(words: Array, offset: number) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.cfg.blockSize; + var iv = this._iv; + var counter = this._counter; + + if (blockSize == 0 || blockSize == undefined) { + blockSize = 1; + } + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Increment counter + counter[blockSize - 1] = (counter[blockSize - 1] + 1) | 0 + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CTRGladman.ts b/crypto/src/main/ets/AES/mode/CTRGladman.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c224598810c7aab93bf0db75b50a771022ab459 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CTRGladman.ts @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { CTRGladmanEncryptor } from './CTRGladmanEncryptor'; +import { BlockCipherMode } from './BlockCipherMode'; + +export abstract class CTRGladman extends BlockCipherMode { + + public static Encryptor: any = CTRGladmanEncryptor + + public static Decryptor: any = CTRGladmanEncryptor +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/CTRGladmanEncryptor.ts b/crypto/src/main/ets/AES/mode/CTRGladmanEncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..b11a8bd50c5a3db3322d7a02ddd879c319107ef4 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/CTRGladmanEncryptor.ts @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class CTRGladmanEncryptor extends BlockCipherModeAlgorithm { + private _counter + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + // Shortcuts + var cipher = this._cipher + var blockSize = this._cipher.cfg.blockSize; + var iv = this._iv; + var counter = this._counter; + + if (blockSize == 0 || blockSize == undefined) { + blockSize = 1; + } + + // Generate keystream + if (iv) { + counter = this._counter = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + + this.incCounter(counter); + + var keystream = counter.slice(0); + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } + + incCounter(counter) { + if ((counter[0] = this.incWord(counter[0])) === 0) { + // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8 + counter[1] = this.incWord(counter[1]); + } + return counter; + } + + incWord(word) { + if (((word >> 24) & 0xff) === 0xff) { //overflow + var b1 = (word >> 16) & 0xff; + var b2 = (word >> 8) & 0xff; + var b3 = word & 0xff; + + if (b1 === 0xff) // overflow b1 + { + b1 = 0; + if (b2 === 0xff) { + b2 = 0; + if (b3 === 0xff) { + b3 = 0; + } + else { + ++b3; + } + } + else { + ++b2; + } + } + else { + ++b1; + } + + word = 0; + word += (b1 << 16); + word += (b2 << 8); + word += b3; + } + else { + word += (0x01 << 24); + } + return word; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/ECB.ts b/crypto/src/main/ets/AES/mode/ECB.ts new file mode 100644 index 0000000000000000000000000000000000000000..74eb55f435ed336d89d557d36cc7f61708fbe71f --- /dev/null +++ b/crypto/src/main/ets/AES/mode/ECB.ts @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherMode } from './BlockCipherMode'; +import { ECBEncryptor } from './ECBEncryptor'; +import { ECBDecryptor } from './ECBDecryptor'; + +/** + * Cipher Block Chaining mode. + */ +export abstract class ECB extends BlockCipherMode { + public static Encryptor: typeof ECBEncryptor = ECBEncryptor; + + public static Decryptor: typeof ECBDecryptor = ECBDecryptor; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/ECBDecryptor.ts b/crypto/src/main/ets/AES/mode/ECBDecryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..4fcb3d6fca009bbdda2428221f5a71b58376aa01 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/ECBDecryptor.ts @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class ECBDecryptor extends BlockCipherModeAlgorithm { + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + this._cipher.decryptBlock(words, offset); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/ECBEncryptor.ts b/crypto/src/main/ets/AES/mode/ECBEncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3c36ed88bd5c3f2fafe2debb2ba1988bb0c2c4e --- /dev/null +++ b/crypto/src/main/ets/AES/mode/ECBEncryptor.ts @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class ECBEncryptor extends BlockCipherModeAlgorithm { + /** + * Processes the data block at offset. + * + * @param words The data words to operate on. + * @param offset The offset where the block starts. + * + * @example + * + * mode.processBlock(data.words, offset); + */ + public processBlock(words: Array, offset: number) { + this._cipher.encryptBlock(words, offset); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/OFB.ts b/crypto/src/main/ets/AES/mode/OFB.ts new file mode 100644 index 0000000000000000000000000000000000000000..49616f5c7014b36a5ae698f2343b312007e8e1e8 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/OFB.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { OFBEncryptor } from './OFBEncryptor'; +import { BlockCipherMode } from './BlockCipherMode'; + +export abstract class OFB extends BlockCipherMode { + public static Encryptor: any = OFBEncryptor + public static Decryptor: any = OFBEncryptor +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/mode/OFBEncryptor.ts b/crypto/src/main/ets/AES/mode/OFBEncryptor.ts new file mode 100644 index 0000000000000000000000000000000000000000..7711ab215989309eff3a45618c55eaf21eeaf5b8 --- /dev/null +++ b/crypto/src/main/ets/AES/mode/OFBEncryptor.ts @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherModeAlgorithm } from './BlockCipherModeAlgorithm'; + +export class OFBEncryptor extends BlockCipherModeAlgorithm { + _keystream : Array + + public processBlock(words: Array, offset: number) { + // Shortcuts + var cipher = this._cipher + var blockSize = cipher.cfg.blockSize; + var iv = this._iv; + var keystream = this._keystream; + + if (blockSize == 0 || blockSize == undefined) { + blockSize = 1; + } + // Generate keystream + if (iv) { + keystream = this._keystream = iv.slice(0); + + // Remove IV for subsequent blocks + this._iv = undefined; + } + cipher.encryptBlock(keystream, 0); + + // Encrypt + for (var i = 0; i < blockSize; i++) { + words[offset + i] ^= keystream[i]; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/AnsiX923.ts b/crypto/src/main/ets/AES/pad/AnsiX923.ts new file mode 100644 index 0000000000000000000000000000000000000000..92b4d4e8ba21259deb2d5ec6e5d1eaa705f8cb64 --- /dev/null +++ b/crypto/src/main/ets/AES/pad/AnsiX923.ts @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { EPadding } from '../pad/EPadding'; + +export class AnsiX923 { + public static pad(data: WordArray, blockSize: number): void { + // Shortcuts + var dataSigBytes = data.sigBytes; + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - dataSigBytes % blockSizeBytes; + + // Compute last byte position + var lastBytePos = dataSigBytes + nPaddingBytes - 1; + + // Pad + data.clamp(); + data.words[lastBytePos >>> 2] |= nPaddingBytes << (24 - (lastBytePos % 4) * 8); + data.sigBytes += nPaddingBytes; + } + + public static unpad(data: WordArray): void { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } +} +const _: EPadding = AnsiX923; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/EPadding.ts b/crypto/src/main/ets/AES/pad/EPadding.ts new file mode 100644 index 0000000000000000000000000000000000000000..bd65c18a27232ef06fc6c574d76c9b78ade37367 --- /dev/null +++ b/crypto/src/main/ets/AES/pad/EPadding.ts @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; + + +export interface EPadding { + pad: (data: WordArray, blockSize: number) => void; + + unpad: (data: WordArray) => void; +} \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/Iso10126.ts b/crypto/src/main/ets/AES/pad/Iso10126.ts new file mode 100644 index 0000000000000000000000000000000000000000..4248cce581f622fca411a76b492fc72677dfd081 --- /dev/null +++ b/crypto/src/main/ets/AES/pad/Iso10126.ts @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { EPadding } from '../pad/EPadding'; + +export class Iso10126 { + public static pad(data: WordArray, blockSize: number): void { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Count padding bytes + var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Pad + data.concat(WordArray.random(nPaddingBytes - 1)). + concat(WordArray.create([nPaddingBytes << 24], 1)); + } + + public static unpad(data: WordArray): void { + // Get number of padding bytes from last byte + var nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } +} +const _: EPadding = Iso10126; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/Iso97971.ts b/crypto/src/main/ets/AES/pad/Iso97971.ts new file mode 100644 index 0000000000000000000000000000000000000000..c9d3104f5f6f568a6b718d91f56da40ba9466410 --- /dev/null +++ b/crypto/src/main/ets/AES/pad/Iso97971.ts @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { ZeroPadding } from './ZeroPadding'; +import { WordArray } from '../../lib-WordArray'; +import { EPadding } from '../pad/EPadding'; + +export class Iso97971{ + /** + * Doesn't pad the data provided. + * + * @param data The data to pad. + * @param blockSize The multiple that the data should be padded to. + * + * @example + * + * NoPadding.pad(wordArray, 4); + */ + public static pad(data: WordArray, blockSize: number): void { + data.concat(WordArray.create([0x80000000], 1)); + // Zero pad the rest + ZeroPadding.pad(data, blockSize); + } + + /** + * Doesn't unpad the data provided. + * + * @param data The data to unpad. + * + * @example + * + * NoPadding.unpad(wordArray); + */ + public static unpad(data: WordArray): void { + // Remove zero padding + ZeroPadding.unpad(data); + + // Remove one more byte -- the 0x80 byte + data.sigBytes--; + } +} + +const _: EPadding = Iso97971; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/NoPadding.ts b/crypto/src/main/ets/AES/pad/NoPadding.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7bb9f64635500a532ae6b5cc79e24754068358f --- /dev/null +++ b/crypto/src/main/ets/AES/pad/NoPadding.ts @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; + +import { EPadding } from '../pad/EPadding'; + +export class NoPadding { + /** + * Doesn't pad the data provided. + * + * @param data The data to pad. + * @param blockSize The multiple that the data should be padded to. + * + * @example + * + * NoPadding.pad(wordArray, 4); + */ + public static pad(data: WordArray, blockSize: number): void { + } + + /** + * Doesn't unpad the data provided. + * + * @param data The data to unpad. + * + * @example + * + * NoPadding.unpad(wordArray); + */ + public static unpad(data: WordArray): void { + } +} + +// type guard for the padding (to ensure it has the required static methods) +const _: EPadding = NoPadding; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/PKCS7.ts b/crypto/src/main/ets/AES/pad/PKCS7.ts new file mode 100644 index 0000000000000000000000000000000000000000..f9bab59237553fbfa84ee96f83adfd7cfd3fbacf --- /dev/null +++ b/crypto/src/main/ets/AES/pad/PKCS7.ts @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { EPadding } from '../pad/EPadding'; + +export class PKCS7 { + /** + * Pads data using the algorithm defined in PKCS #5/7. + * + * @param data The data to pad. + * @param blockSize The multiple that the data should be padded to. + * + * @example + * + * PKCS7.pad(wordArray, 4); + */ + public static pad(data: WordArray, blockSize: number): void { + // Shortcut + const blockSizeBytes = blockSize * 4; + + // Count padding bytes + const nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; + + // Create padding word + const paddingWord = (nPaddingBytes << 24) | (nPaddingBytes << 16) | (nPaddingBytes << 8) | nPaddingBytes; + + // Create padding + const paddingWords = []; + for (let i = 0; i < nPaddingBytes; i += 4) { + paddingWords.push(paddingWord); + } + const padding = new WordArray(paddingWords, nPaddingBytes); + + // Add padding + data.concat(padding); + } + + /** + * Unpads data that had been padded using the algorithm defined in PKCS #5/7. + * + * @param data The data to unpad. + * + * @example + * + * PKCS7.unpad(wordArray); + */ + public static unpad(data: WordArray): void { + // Get number of padding bytes from last byte + const nPaddingBytes = data.words[(data.sigBytes - 1) >>> 2] & 0xff; + + // Remove padding + data.sigBytes -= nPaddingBytes; + } +} + +// type guard for the formatter (to ensure it has the required static methods) +const _: EPadding = PKCS7; \ No newline at end of file diff --git a/crypto/src/main/ets/AES/pad/ZeroPadding.ts b/crypto/src/main/ets/AES/pad/ZeroPadding.ts new file mode 100644 index 0000000000000000000000000000000000000000..248e944331991d2d421f6813576c68a9a4570497 --- /dev/null +++ b/crypto/src/main/ets/AES/pad/ZeroPadding.ts @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from '../../lib-WordArray'; +import { EPadding } from '../pad/EPadding'; + +export class ZeroPadding { + public static pad(data: WordArray, blockSize: number): void { + // Shortcut + var blockSizeBytes = blockSize * 4; + + // Pad + data.clamp(); + data.sigBytes += blockSizeBytes - ((data.sigBytes % blockSizeBytes) || blockSizeBytes); + } + + public static unpad(data: WordArray): void { + // Shortcut + var dataWords = data.words; + + // Unpad + var i = data.sigBytes - 1; + for (var i = data.sigBytes - 1; i >= 0; i--) { + if (((dataWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff)) { + data.sigBytes = i + 1; + break; + } + } + } +} +const _: EPadding = ZeroPadding; \ No newline at end of file diff --git a/crypto/src/main/ets/BufferedBlockAlgorithmConfig.ts b/crypto/src/main/ets/BufferedBlockAlgorithmConfig.ts new file mode 100644 index 0000000000000000000000000000000000000000..c82cee7b246663391350b664339afafbf9558739 --- /dev/null +++ b/crypto/src/main/ets/BufferedBlockAlgorithmConfig.ts @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipherMode } from './AES/mode/BlockCipherMode'; +import { WordArray } from './lib-WordArray'; +import { KDF } from './AES/kdf/KDF'; +import {Local_Formatter} from "./AES/format/Local_Formatter" +import { EPadding } from '../ets/AES/pad/EPadding'; + +export interface BufferedBlockAlgorithmConfig { + // requires at least a blockSize + blockSize?: number; + + iv?: WordArray; + + format?: Local_Formatter; + + kdf?: KDF; + + mode?: typeof BlockCipherMode; + + padding?: EPadding; + + drop?: number + + outputLength?:number +} \ No newline at end of file diff --git a/crypto/src/main/ets/DES.ts b/crypto/src/main/ets/DES.ts new file mode 100644 index 0000000000000000000000000000000000000000..a655836617b644848ade57e4703c3a75983bcade --- /dev/null +++ b/crypto/src/main/ets/DES.ts @@ -0,0 +1,706 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig'; +import { BlockCipher } from './AES/lib/BlockCipher'; + +// Permuted Choice 1 constants +const PC1 = [ + 57, 49, 41, 33, 25, 17, 9, 1, + 58, 50, 42, 34, 26, 18, 10, 2, + 59, 51, 43, 35, 27, 19, 11, 3, + 60, 52, 44, 36, 63, 55, 47, 39, + 31, 23, 15, 7, 62, 54, 46, 38, + 30, 22, 14, 6, 61, 53, 45, 37, + 29, 21, 13, 5, 28, 20, 12, 4 +]; + +// Permuted Choice 2 constants +const PC2 = [ + 14, 17, 11, 24, 1, 5, + 3, 28, 15, 6, 21, 10, + 23, 19, 12, 4, 26, 8, + 16, 7, 27, 20, 13, 2, + 41, 52, 31, 37, 47, 55, + 30, 40, 51, 45, 33, 48, + 44, 49, 39, 56, 34, 53, + 46, 42, 50, 36, 29, 32 +]; + +// Cumulative bit shift constants +const BIT_SHIFTS = [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28]; + +// SBOXes and round permutation constants +const SBOX_P = [ + { + 0x0: 0x808200, + 0x10000000: 0x8000, + 0x20000000: 0x808002, + 0x30000000: 0x2, + 0x40000000: 0x200, + 0x50000000: 0x808202, + 0x60000000: 0x800202, + 0x70000000: 0x800000, + 0x80000000: 0x202, + 0x90000000: 0x800200, + 0xa0000000: 0x8200, + 0xb0000000: 0x808000, + 0xc0000000: 0x8002, + 0xd0000000: 0x800002, + 0xe0000000: 0x0, + 0xf0000000: 0x8202, + 0x8000000: 0x0, + 0x18000000: 0x808202, + 0x28000000: 0x8202, + 0x38000000: 0x8000, + 0x48000000: 0x808200, + 0x58000000: 0x200, + 0x68000000: 0x808002, + 0x78000000: 0x2, + 0x88000000: 0x800200, + 0x98000000: 0x8200, + 0xa8000000: 0x808000, + 0xb8000000: 0x800202, + 0xc8000000: 0x800002, + 0xd8000000: 0x8002, + 0xe8000000: 0x202, + 0xf8000000: 0x800000, + 0x1: 0x8000, + 0x10000001: 0x2, + 0x20000001: 0x808200, + 0x30000001: 0x800000, + 0x40000001: 0x808002, + 0x50000001: 0x8200, + 0x60000001: 0x200, + 0x70000001: 0x800202, + 0x80000001: 0x808202, + 0x90000001: 0x808000, + 0xa0000001: 0x800002, + 0xb0000001: 0x8202, + 0xc0000001: 0x202, + 0xd0000001: 0x800200, + 0xe0000001: 0x8002, + 0xf0000001: 0x0, + 0x8000001: 0x808202, + 0x18000001: 0x808000, + 0x28000001: 0x800000, + 0x38000001: 0x200, + 0x48000001: 0x8000, + 0x58000001: 0x800002, + 0x68000001: 0x2, + 0x78000001: 0x8202, + 0x88000001: 0x8002, + 0x98000001: 0x800202, + 0xa8000001: 0x202, + 0xb8000001: 0x808200, + 0xc8000001: 0x800200, + 0xd8000001: 0x0, + 0xe8000001: 0x8200, + 0xf8000001: 0x808002 + }, + { + 0x0: 0x40084010, + 0x1000000: 0x4000, + 0x2000000: 0x80000, + 0x3000000: 0x40080010, + 0x4000000: 0x40000010, + 0x5000000: 0x40084000, + 0x6000000: 0x40004000, + 0x7000000: 0x10, + 0x8000000: 0x84000, + 0x9000000: 0x40004010, + 0xa000000: 0x40000000, + 0xb000000: 0x84010, + 0xc000000: 0x80010, + 0xd000000: 0x0, + 0xe000000: 0x4010, + 0xf000000: 0x40080000, + 0x800000: 0x40004000, + 0x1800000: 0x84010, + 0x2800000: 0x10, + 0x3800000: 0x40004010, + 0x4800000: 0x40084010, + 0x5800000: 0x40000000, + 0x6800000: 0x80000, + 0x7800000: 0x40080010, + 0x8800000: 0x80010, + 0x9800000: 0x0, + 0xa800000: 0x4000, + 0xb800000: 0x40080000, + 0xc800000: 0x40000010, + 0xd800000: 0x84000, + 0xe800000: 0x40084000, + 0xf800000: 0x4010, + 0x10000000: 0x0, + 0x11000000: 0x40080010, + 0x12000000: 0x40004010, + 0x13000000: 0x40084000, + 0x14000000: 0x40080000, + 0x15000000: 0x10, + 0x16000000: 0x84010, + 0x17000000: 0x4000, + 0x18000000: 0x4010, + 0x19000000: 0x80000, + 0x1a000000: 0x80010, + 0x1b000000: 0x40000010, + 0x1c000000: 0x84000, + 0x1d000000: 0x40004000, + 0x1e000000: 0x40000000, + 0x1f000000: 0x40084010, + 0x10800000: 0x84010, + 0x11800000: 0x80000, + 0x12800000: 0x40080000, + 0x13800000: 0x4000, + 0x14800000: 0x40004000, + 0x15800000: 0x40084010, + 0x16800000: 0x10, + 0x17800000: 0x40000000, + 0x18800000: 0x40084000, + 0x19800000: 0x40000010, + 0x1a800000: 0x40004010, + 0x1b800000: 0x80010, + 0x1c800000: 0x0, + 0x1d800000: 0x4010, + 0x1e800000: 0x40080010, + 0x1f800000: 0x84000 + }, + { + 0x0: 0x104, + 0x100000: 0x0, + 0x200000: 0x4000100, + 0x300000: 0x10104, + 0x400000: 0x10004, + 0x500000: 0x4000004, + 0x600000: 0x4010104, + 0x700000: 0x4010000, + 0x800000: 0x4000000, + 0x900000: 0x4010100, + 0xa00000: 0x10100, + 0xb00000: 0x4010004, + 0xc00000: 0x4000104, + 0xd00000: 0x10000, + 0xe00000: 0x4, + 0xf00000: 0x100, + 0x80000: 0x4010100, + 0x180000: 0x4010004, + 0x280000: 0x0, + 0x380000: 0x4000100, + 0x480000: 0x4000004, + 0x580000: 0x10000, + 0x680000: 0x10004, + 0x780000: 0x104, + 0x880000: 0x4, + 0x980000: 0x100, + 0xa80000: 0x4010000, + 0xb80000: 0x10104, + 0xc80000: 0x10100, + 0xd80000: 0x4000104, + 0xe80000: 0x4010104, + 0xf80000: 0x4000000, + 0x1000000: 0x4010100, + 0x1100000: 0x10004, + 0x1200000: 0x10000, + 0x1300000: 0x4000100, + 0x1400000: 0x100, + 0x1500000: 0x4010104, + 0x1600000: 0x4000004, + 0x1700000: 0x0, + 0x1800000: 0x4000104, + 0x1900000: 0x4000000, + 0x1a00000: 0x4, + 0x1b00000: 0x10100, + 0x1c00000: 0x4010000, + 0x1d00000: 0x104, + 0x1e00000: 0x10104, + 0x1f00000: 0x4010004, + 0x1080000: 0x4000000, + 0x1180000: 0x104, + 0x1280000: 0x4010100, + 0x1380000: 0x0, + 0x1480000: 0x10004, + 0x1580000: 0x4000100, + 0x1680000: 0x100, + 0x1780000: 0x4010004, + 0x1880000: 0x10000, + 0x1980000: 0x4010104, + 0x1a80000: 0x10104, + 0x1b80000: 0x4000004, + 0x1c80000: 0x4000104, + 0x1d80000: 0x4010000, + 0x1e80000: 0x4, + 0x1f80000: 0x10100 + }, + { + 0x0: 0x80401000, + 0x10000: 0x80001040, + 0x20000: 0x401040, + 0x30000: 0x80400000, + 0x40000: 0x0, + 0x50000: 0x401000, + 0x60000: 0x80000040, + 0x70000: 0x400040, + 0x80000: 0x80000000, + 0x90000: 0x400000, + 0xa0000: 0x40, + 0xb0000: 0x80001000, + 0xc0000: 0x80400040, + 0xd0000: 0x1040, + 0xe0000: 0x1000, + 0xf0000: 0x80401040, + 0x8000: 0x80001040, + 0x18000: 0x40, + 0x28000: 0x80400040, + 0x38000: 0x80001000, + 0x48000: 0x401000, + 0x58000: 0x80401040, + 0x68000: 0x0, + 0x78000: 0x80400000, + 0x88000: 0x1000, + 0x98000: 0x80401000, + 0xa8000: 0x400000, + 0xb8000: 0x1040, + 0xc8000: 0x80000000, + 0xd8000: 0x400040, + 0xe8000: 0x401040, + 0xf8000: 0x80000040, + 0x100000: 0x400040, + 0x110000: 0x401000, + 0x120000: 0x80000040, + 0x130000: 0x0, + 0x140000: 0x1040, + 0x150000: 0x80400040, + 0x160000: 0x80401000, + 0x170000: 0x80001040, + 0x180000: 0x80401040, + 0x190000: 0x80000000, + 0x1a0000: 0x80400000, + 0x1b0000: 0x401040, + 0x1c0000: 0x80001000, + 0x1d0000: 0x400000, + 0x1e0000: 0x40, + 0x1f0000: 0x1000, + 0x108000: 0x80400000, + 0x118000: 0x80401040, + 0x128000: 0x0, + 0x138000: 0x401000, + 0x148000: 0x400040, + 0x158000: 0x80000000, + 0x168000: 0x80001040, + 0x178000: 0x40, + 0x188000: 0x80000040, + 0x198000: 0x1000, + 0x1a8000: 0x80001000, + 0x1b8000: 0x80400040, + 0x1c8000: 0x1040, + 0x1d8000: 0x80401000, + 0x1e8000: 0x400000, + 0x1f8000: 0x401040 + }, + { + 0x0: 0x80, + 0x1000: 0x1040000, + 0x2000: 0x40000, + 0x3000: 0x20000000, + 0x4000: 0x20040080, + 0x5000: 0x1000080, + 0x6000: 0x21000080, + 0x7000: 0x40080, + 0x8000: 0x1000000, + 0x9000: 0x20040000, + 0xa000: 0x20000080, + 0xb000: 0x21040080, + 0xc000: 0x21040000, + 0xd000: 0x0, + 0xe000: 0x1040080, + 0xf000: 0x21000000, + 0x800: 0x1040080, + 0x1800: 0x21000080, + 0x2800: 0x80, + 0x3800: 0x1040000, + 0x4800: 0x40000, + 0x5800: 0x20040080, + 0x6800: 0x21040000, + 0x7800: 0x20000000, + 0x8800: 0x20040000, + 0x9800: 0x0, + 0xa800: 0x21040080, + 0xb800: 0x1000080, + 0xc800: 0x20000080, + 0xd800: 0x21000000, + 0xe800: 0x1000000, + 0xf800: 0x40080, + 0x10000: 0x40000, + 0x11000: 0x80, + 0x12000: 0x20000000, + 0x13000: 0x21000080, + 0x14000: 0x1000080, + 0x15000: 0x21040000, + 0x16000: 0x20040080, + 0x17000: 0x1000000, + 0x18000: 0x21040080, + 0x19000: 0x21000000, + 0x1a000: 0x1040000, + 0x1b000: 0x20040000, + 0x1c000: 0x40080, + 0x1d000: 0x20000080, + 0x1e000: 0x0, + 0x1f000: 0x1040080, + 0x10800: 0x21000080, + 0x11800: 0x1000000, + 0x12800: 0x1040000, + 0x13800: 0x20040080, + 0x14800: 0x20000000, + 0x15800: 0x1040080, + 0x16800: 0x80, + 0x17800: 0x21040000, + 0x18800: 0x40080, + 0x19800: 0x21040080, + 0x1a800: 0x0, + 0x1b800: 0x21000000, + 0x1c800: 0x1000080, + 0x1d800: 0x40000, + 0x1e800: 0x20040000, + 0x1f800: 0x20000080 + }, + { + 0x0: 0x10000008, + 0x100: 0x2000, + 0x200: 0x10200000, + 0x300: 0x10202008, + 0x400: 0x10002000, + 0x500: 0x200000, + 0x600: 0x200008, + 0x700: 0x10000000, + 0x800: 0x0, + 0x900: 0x10002008, + 0xa00: 0x202000, + 0xb00: 0x8, + 0xc00: 0x10200008, + 0xd00: 0x202008, + 0xe00: 0x2008, + 0xf00: 0x10202000, + 0x80: 0x10200000, + 0x180: 0x10202008, + 0x280: 0x8, + 0x380: 0x200000, + 0x480: 0x202008, + 0x580: 0x10000008, + 0x680: 0x10002000, + 0x780: 0x2008, + 0x880: 0x200008, + 0x980: 0x2000, + 0xa80: 0x10002008, + 0xb80: 0x10200008, + 0xc80: 0x0, + 0xd80: 0x10202000, + 0xe80: 0x202000, + 0xf80: 0x10000000, + 0x1000: 0x10002000, + 0x1100: 0x10200008, + 0x1200: 0x10202008, + 0x1300: 0x2008, + 0x1400: 0x200000, + 0x1500: 0x10000000, + 0x1600: 0x10000008, + 0x1700: 0x202000, + 0x1800: 0x202008, + 0x1900: 0x0, + 0x1a00: 0x8, + 0x1b00: 0x10200000, + 0x1c00: 0x2000, + 0x1d00: 0x10002008, + 0x1e00: 0x10202000, + 0x1f00: 0x200008, + 0x1080: 0x8, + 0x1180: 0x202000, + 0x1280: 0x200000, + 0x1380: 0x10000008, + 0x1480: 0x10002000, + 0x1580: 0x2008, + 0x1680: 0x10202008, + 0x1780: 0x10200000, + 0x1880: 0x10202000, + 0x1980: 0x10200008, + 0x1a80: 0x2000, + 0x1b80: 0x202008, + 0x1c80: 0x200008, + 0x1d80: 0x0, + 0x1e80: 0x10000000, + 0x1f80: 0x10002008 + }, + { + 0x0: 0x100000, + 0x10: 0x2000401, + 0x20: 0x400, + 0x30: 0x100401, + 0x40: 0x2100401, + 0x50: 0x0, + 0x60: 0x1, + 0x70: 0x2100001, + 0x80: 0x2000400, + 0x90: 0x100001, + 0xa0: 0x2000001, + 0xb0: 0x2100400, + 0xc0: 0x2100000, + 0xd0: 0x401, + 0xe0: 0x100400, + 0xf0: 0x2000000, + 0x8: 0x2100001, + 0x18: 0x0, + 0x28: 0x2000401, + 0x38: 0x2100400, + 0x48: 0x100000, + 0x58: 0x2000001, + 0x68: 0x2000000, + 0x78: 0x401, + 0x88: 0x100401, + 0x98: 0x2000400, + 0xa8: 0x2100000, + 0xb8: 0x100001, + 0xc8: 0x400, + 0xd8: 0x2100401, + 0xe8: 0x1, + 0xf8: 0x100400, + 0x100: 0x2000000, + 0x110: 0x100000, + 0x120: 0x2000401, + 0x130: 0x2100001, + 0x140: 0x100001, + 0x150: 0x2000400, + 0x160: 0x2100400, + 0x170: 0x100401, + 0x180: 0x401, + 0x190: 0x2100401, + 0x1a0: 0x100400, + 0x1b0: 0x1, + 0x1c0: 0x0, + 0x1d0: 0x2100000, + 0x1e0: 0x2000001, + 0x1f0: 0x400, + 0x108: 0x100400, + 0x118: 0x2000401, + 0x128: 0x2100001, + 0x138: 0x1, + 0x148: 0x2000000, + 0x158: 0x100000, + 0x168: 0x401, + 0x178: 0x2100400, + 0x188: 0x2000001, + 0x198: 0x2100000, + 0x1a8: 0x0, + 0x1b8: 0x2100401, + 0x1c8: 0x100401, + 0x1d8: 0x400, + 0x1e8: 0x2000400, + 0x1f8: 0x100001 + }, + { + 0x0: 0x8000820, + 0x1: 0x20000, + 0x2: 0x8000000, + 0x3: 0x20, + 0x4: 0x20020, + 0x5: 0x8020820, + 0x6: 0x8020800, + 0x7: 0x800, + 0x8: 0x8020000, + 0x9: 0x8000800, + 0xa: 0x20800, + 0xb: 0x8020020, + 0xc: 0x820, + 0xd: 0x0, + 0xe: 0x8000020, + 0xf: 0x20820, + 0x80000000: 0x800, + 0x80000001: 0x8020820, + 0x80000002: 0x8000820, + 0x80000003: 0x8000000, + 0x80000004: 0x8020000, + 0x80000005: 0x20800, + 0x80000006: 0x20820, + 0x80000007: 0x20, + 0x80000008: 0x8000020, + 0x80000009: 0x820, + 0x8000000a: 0x20020, + 0x8000000b: 0x8020800, + 0x8000000c: 0x0, + 0x8000000d: 0x8020020, + 0x8000000e: 0x8000800, + 0x8000000f: 0x20000, + 0x10: 0x20820, + 0x11: 0x8020800, + 0x12: 0x20, + 0x13: 0x800, + 0x14: 0x8000800, + 0x15: 0x8000020, + 0x16: 0x8020020, + 0x17: 0x20000, + 0x18: 0x0, + 0x19: 0x20020, + 0x1a: 0x8020000, + 0x1b: 0x8000820, + 0x1c: 0x8020820, + 0x1d: 0x20800, + 0x1e: 0x820, + 0x1f: 0x8000000, + 0x80000010: 0x20000, + 0x80000011: 0x800, + 0x80000012: 0x8020020, + 0x80000013: 0x20820, + 0x80000014: 0x20, + 0x80000015: 0x8020000, + 0x80000016: 0x8000000, + 0x80000017: 0x8000820, + 0x80000018: 0x8020820, + 0x80000019: 0x8000020, + 0x8000001a: 0x8000800, + 0x8000001b: 0x0, + 0x8000001c: 0x20800, + 0x8000001d: 0x820, + 0x8000001e: 0x20020, + 0x8000001f: 0x8020800 + } +]; + +// Masks that select the SBOX input +const SBOX_MASK = [ + 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000, + 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f +]; + +export class DES extends BlockCipher { + keySize = 64 / 32 + ivSize = 64 / 32 + blockSize = 64 / 32 + _rBlock: number; + _lBlock: number; + _subKeys = [] + _invSubKeys = [] + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, cfg); + this._doReset() + } + + _doReset() { + // Shortcuts + var key = this._key; + var keyWords = key.words; + + // Select 56 bits according to PC1 + var keyBits = []; + for (var i = 0; i < 56; i++) { + var keyBitPos = PC1[i] - 1; + keyBits[i] = (keyWords[keyBitPos >>> 5] >>> (31 - keyBitPos % 32)) & 1; + } + + // Assemble 16 subkeys + var subKeys = this._subKeys = []; + for (var nSubKey = 0; nSubKey < 16; nSubKey++) { + // Create subkey + var subKey = subKeys[nSubKey] = []; + + // Shortcut + var bitShift = BIT_SHIFTS[nSubKey]; + + // Select 48 bits according to PC2 + for (var i = 0; i < 24; i++) { + // Select from the left 28 key bits + subKey[(i / 6) | 0] |= keyBits[((PC2[i] - 1) + bitShift) % 28] << (31 - i % 6); + + // Select from the right 28 key bits + subKey[4 + ((i / 6) | 0)] |= keyBits[28 + (((PC2[i + 24] - 1) + bitShift) % 28)] << (31 - i % 6); + } + + // Since each subkey is applied to an expanded 32-bit input, + // the subkey can be broken into 8 values scaled to 32-bits, + // which allows the key to be used without expansion + subKey[0] = (subKey[0] << 1) | (subKey[0] >>> 31); + for (var i = 1; i < 7; i++) { + subKey[i] = subKey[i] >>> ((i - 1) * 4 + 3); + } + subKey[7] = (subKey[7] << 5) | (subKey[7] >>> 27); + } + + // Compute inverse subkeys + var invSubKeys = this._invSubKeys = []; + for (var i = 0; i < 16; i++) { + invSubKeys[i] = subKeys[15 - i]; + } + } + + encryptBlock(M, offset) { + this._doCryptBlock(M, offset, this._subKeys); + } + + decryptBlock(M, offset) { + this._doCryptBlock(M, offset, this._invSubKeys); + } + + _doCryptBlock(M, offset, subKeys) { + // Get input + this._lBlock = M[offset]; + this._rBlock = M[offset + 1]; + + // Initial permutation + this.exchangeLR.call(this, 4, 0x0f0f0f0f); + this.exchangeLR.call(this, 16, 0x0000ffff); + this.exchangeRL.call(this, 2, 0x33333333); + this.exchangeRL.call(this, 8, 0x00ff00ff); + this.exchangeLR.call(this, 1, 0x55555555); + // Rounds + for (var round = 0; round < 16; round++) { + // Shortcuts + var subKey = subKeys[round]; + var lBlock = this._lBlock; + var rBlock = this._rBlock; + // Feistel function + var f = 0; + for (var i = 0; i < 8; i++) { + f |= SBOX_P[i][((rBlock ^ subKey[i]) & SBOX_MASK[i]) >>> 0]; + } + this._lBlock = rBlock; + this._rBlock = lBlock ^ f; + } + + // Undo swap from last round + var t = this._lBlock; + this._lBlock = this._rBlock; + this._rBlock = t; + // Final permutation + this.exchangeLR.call(this, 1, 0x55555555); + this.exchangeRL.call(this, 8, 0x00ff00ff); + this.exchangeRL.call(this, 2, 0x33333333); + this.exchangeLR.call(this, 16, 0x0000ffff); + this.exchangeLR.call(this, 4, 0x0f0f0f0f); + // Set output + M[offset] = this._lBlock; + M[offset + 1] = this._rBlock; + } + + // Swap bits across the left and right words + exchangeLR(offset, mask) { + var t = ((this._lBlock >>> offset) ^ this._rBlock) & mask; + this._rBlock ^= t; + this._lBlock ^= t << offset; + } + + exchangeRL(offset, mask) { + var t = ((this._rBlock >>> offset) ^ this._lBlock) & mask; + this._lBlock ^= t; + this._rBlock ^= t << offset; + } +} \ No newline at end of file diff --git a/entry/src/main/ets/MainAbility/app.ets b/crypto/src/main/ets/Encoding.ts similarity index 78% rename from entry/src/main/ets/MainAbility/app.ets rename to crypto/src/main/ets/Encoding.ts index 6907adfcab20d5da15534db1e739f3488825961d..1582ac171cb3b7e7bd84f32228ec445639bf2f31 100644 --- a/entry/src/main/ets/MainAbility/app.ets +++ b/crypto/src/main/ets/Encoding.ts @@ -13,11 +13,10 @@ * limitations under the License. */ -export default { - onCreate() { - console.info('Application onCreate') - }, - onDestroy() { - console.info('Application onDestroy') - }, -} \ No newline at end of file +import { WordArray } from './lib-WordArray'; + +export interface Encoding { + stringify(wordArray: WordArray) : string; + + parse(str: string) : WordArray; +} diff --git a/crypto/src/main/ets/KDF.ts b/crypto/src/main/ets/KDF.ts new file mode 100644 index 0000000000000000000000000000000000000000..892993faeb3d40a6851120ae4ec6336248f4c78b --- /dev/null +++ b/crypto/src/main/ets/KDF.ts @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; + +export interface KDF { + execute1(password: string, keySize: number, ivSize: number, salt?: WordArray | string) ; + +} \ No newline at end of file diff --git a/crypto/src/main/ets/Latin1.ts b/crypto/src/main/ets/Latin1.ts new file mode 100644 index 0000000000000000000000000000000000000000..604cbfedb4aa83e355e05e99c48ec63915355333 --- /dev/null +++ b/crypto/src/main/ets/Latin1.ts @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +declare function escape(s: string): string; +declare function unescape(s: string): string; + +export class Latin1 { + /** + * Converts a word array to a Latin1 string. + * + * @param wordArray The word array. + * + * @return The Latin1 string. + * + * @example + * + * let latin1String = Latin1.stringify(wordArray); + */ + public static stringify(wordArray: WordArray): string { + // Convert + const latin1Chars = []; + for (let i = 0; i < wordArray.sigBytes; i++) { + const bite = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + } + + /** + * Converts a Latin1 string to a word array. + * + * @param latin1Str The Latin1 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Latin1.parse(latin1String); + */ + public static parse(latin1Str: string): WordArray { + // Shortcut + const latin1StrLength = latin1Str.length; + + // Convert + const words: Array = []; + for (let i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + + return new WordArray(words, latin1StrLength); + } +} + +// type guard for the formatter (to ensure it has the required static methods) +const _: Encoding = Latin1; \ No newline at end of file diff --git a/crypto/src/main/ets/MyMD5.ts b/crypto/src/main/ets/MyMD5.ts new file mode 100644 index 0000000000000000000000000000000000000000..76522f4abc68a2f55ebc028fe9fcf2894f24662a --- /dev/null +++ b/crypto/src/main/ets/MyMD5.ts @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Hasher } from './AES/lib/Hasher'; +import { WordArray } from './lib-WordArray'; + +// Constants table +const T: Array = []; + +// Compute constants +for(let i = 0; i < 64; i++) { + T[i] = (Math.abs(Math.sin(i + 1)) * 0x100000000) | 0; +} + +export class MD5 extends Hasher { + public _hash!: WordArray; + + public static FF(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number { + const n = a + ((b & c) | (~b & d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + public static GG(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number { + const n = a + ((b & d) | (c & ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + public static HH(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number { + const n = a + (b ^ c ^ d) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + public static II(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number { + const n = a + (c ^ (b | ~d)) + x + t; + return ((n << s) | (n >>> (32 - s))) + b; + } + + public reset() { + // reset core values + super.reset(); + + this._hash = new WordArray([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476 + ]); + } + + public _doProcessBlock(M: Array, offset: number) { + // Swap endian + for(let i = 0; i < 16; i++) { + // Shortcuts + const offset_i = offset + i; + const M_offset_i = M[offset_i]; + + M[offset_i] = ( + (((M_offset_i << 8) | (M_offset_i >>> 24)) & 0x00ff00ff) | + (((M_offset_i << 24) | (M_offset_i >>> 8)) & 0xff00ff00) + ); + } + + // Shortcuts + const H = this._hash.words; + + const M_offset_0 = M[offset + 0]; + const M_offset_1 = M[offset + 1]; + const M_offset_2 = M[offset + 2]; + const M_offset_3 = M[offset + 3]; + const M_offset_4 = M[offset + 4]; + const M_offset_5 = M[offset + 5]; + const M_offset_6 = M[offset + 6]; + const M_offset_7 = M[offset + 7]; + const M_offset_8 = M[offset + 8]; + const M_offset_9 = M[offset + 9]; + const M_offset_10 = M[offset + 10]; + const M_offset_11 = M[offset + 11]; + const M_offset_12 = M[offset + 12]; + const M_offset_13 = M[offset + 13]; + const M_offset_14 = M[offset + 14]; + const M_offset_15 = M[offset + 15]; + + // Working variables + let a = H[0]; + let b = H[1]; + let c = H[2]; + let d = H[3]; + + // Computation + a = MD5.FF(a, b, c, d, M_offset_0, 7, T[0]); + d = MD5.FF(d, a, b, c, M_offset_1, 12, T[1]); + c = MD5.FF(c, d, a, b, M_offset_2, 17, T[2]); + b = MD5.FF(b, c, d, a, M_offset_3, 22, T[3]); + a = MD5.FF(a, b, c, d, M_offset_4, 7, T[4]); + d = MD5.FF(d, a, b, c, M_offset_5, 12, T[5]); + c = MD5.FF(c, d, a, b, M_offset_6, 17, T[6]); + b = MD5.FF(b, c, d, a, M_offset_7, 22, T[7]); + a = MD5.FF(a, b, c, d, M_offset_8, 7, T[8]); + d = MD5.FF(d, a, b, c, M_offset_9, 12, T[9]); + c = MD5.FF(c, d, a, b, M_offset_10, 17, T[10]); + b = MD5.FF(b, c, d, a, M_offset_11, 22, T[11]); + a = MD5.FF(a, b, c, d, M_offset_12, 7, T[12]); + d = MD5.FF(d, a, b, c, M_offset_13, 12, T[13]); + c = MD5.FF(c, d, a, b, M_offset_14, 17, T[14]); + b = MD5.FF(b, c, d, a, M_offset_15, 22, T[15]); + + a = MD5.GG(a, b, c, d, M_offset_1, 5, T[16]); + d = MD5.GG(d, a, b, c, M_offset_6, 9, T[17]); + c = MD5.GG(c, d, a, b, M_offset_11, 14, T[18]); + b = MD5.GG(b, c, d, a, M_offset_0, 20, T[19]); + a = MD5.GG(a, b, c, d, M_offset_5, 5, T[20]); + d = MD5.GG(d, a, b, c, M_offset_10, 9, T[21]); + c = MD5.GG(c, d, a, b, M_offset_15, 14, T[22]); + b = MD5.GG(b, c, d, a, M_offset_4, 20, T[23]); + a = MD5.GG(a, b, c, d, M_offset_9, 5, T[24]); + d = MD5.GG(d, a, b, c, M_offset_14, 9, T[25]); + c = MD5.GG(c, d, a, b, M_offset_3, 14, T[26]); + b = MD5.GG(b, c, d, a, M_offset_8, 20, T[27]); + a = MD5.GG(a, b, c, d, M_offset_13, 5, T[28]); + d = MD5.GG(d, a, b, c, M_offset_2, 9, T[29]); + c = MD5.GG(c, d, a, b, M_offset_7, 14, T[30]); + b = MD5.GG(b, c, d, a, M_offset_12, 20, T[31]); + + a = MD5.HH(a, b, c, d, M_offset_5, 4, T[32]); + d = MD5.HH(d, a, b, c, M_offset_8, 11, T[33]); + c = MD5.HH(c, d, a, b, M_offset_11, 16, T[34]); + b = MD5.HH(b, c, d, a, M_offset_14, 23, T[35]); + a = MD5.HH(a, b, c, d, M_offset_1, 4, T[36]); + d = MD5.HH(d, a, b, c, M_offset_4, 11, T[37]); + c = MD5.HH(c, d, a, b, M_offset_7, 16, T[38]); + b = MD5.HH(b, c, d, a, M_offset_10, 23, T[39]); + a = MD5.HH(a, b, c, d, M_offset_13, 4, T[40]); + d = MD5.HH(d, a, b, c, M_offset_0, 11, T[41]); + c = MD5.HH(c, d, a, b, M_offset_3, 16, T[42]); + b = MD5.HH(b, c, d, a, M_offset_6, 23, T[43]); + a = MD5.HH(a, b, c, d, M_offset_9, 4, T[44]); + d = MD5.HH(d, a, b, c, M_offset_12, 11, T[45]); + c = MD5.HH(c, d, a, b, M_offset_15, 16, T[46]); + b = MD5.HH(b, c, d, a, M_offset_2, 23, T[47]); + + a = MD5.II(a, b, c, d, M_offset_0, 6, T[48]); + d = MD5.II(d, a, b, c, M_offset_7, 10, T[49]); + c = MD5.II(c, d, a, b, M_offset_14, 15, T[50]); + b = MD5.II(b, c, d, a, M_offset_5, 21, T[51]); + a = MD5.II(a, b, c, d, M_offset_12, 6, T[52]); + d = MD5.II(d, a, b, c, M_offset_3, 10, T[53]); + c = MD5.II(c, d, a, b, M_offset_10, 15, T[54]); + b = MD5.II(b, c, d, a, M_offset_1, 21, T[55]); + a = MD5.II(a, b, c, d, M_offset_8, 6, T[56]); + d = MD5.II(d, a, b, c, M_offset_15, 10, T[57]); + c = MD5.II(c, d, a, b, M_offset_6, 15, T[58]); + b = MD5.II(b, c, d, a, M_offset_13, 21, T[59]); + a = MD5.II(a, b, c, d, M_offset_4, 6, T[60]); + d = MD5.II(d, a, b, c, M_offset_11, 10, T[61]); + c = MD5.II(c, d, a, b, M_offset_2, 15, T[62]); + b = MD5.II(b, c, d, a, M_offset_9, 21, T[63]); + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + } + + public _doFinalize(): WordArray { + // Shortcuts + const data = this._data; + const dataWords = data.words; + + const nBitsTotal = this._nDataBytes * 8; + const nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + + const nBitsTotalH = Math.floor(nBitsTotal / 0x100000000); + const nBitsTotalL = nBitsTotal; + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = ( + (((nBitsTotalH << 8) | (nBitsTotalH >>> 24)) & 0x00ff00ff) | + (((nBitsTotalH << 24) | (nBitsTotalH >>> 8)) & 0xff00ff00) + ); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = ( + (((nBitsTotalL << 8) | (nBitsTotalL >>> 24)) & 0x00ff00ff) | + (((nBitsTotalL << 24) | (nBitsTotalL >>> 8)) & 0xff00ff00) + ); + + data.sigBytes = (dataWords.length + 1) * 4; + + // Hash final blocks + this._process(); + + // Shortcuts + const hash = this._hash; + const H = hash.words; + + // Swap endian + for (let i = 0; i < 4; i++) { + // Shortcut + const H_i = H[i]; + + H[i] = (((H_i << 8) | (H_i >>> 24)) & 0x00ff00ff) | + (((H_i << 24) | (H_i >>> 8)) & 0xff00ff00); + } + + // Return final computed hash + return hash; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/MySha1.ts b/crypto/src/main/ets/MySha1.ts new file mode 100644 index 0000000000000000000000000000000000000000..841427aaf3f2c947f0acdb6c3acd4de4066df6e8 --- /dev/null +++ b/crypto/src/main/ets/MySha1.ts @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { Hasher } from './AES/lib/Hasher'; +export class SHA1 extends Hasher { + public _hash!: WordArray; + public W = []; + reset() { + super.reset(); + this._hash = new WordArray([ + 0x67452301, 0xefcdab89, + 0x98badcfe, 0x10325476, + 0xc3d2e1f0 + ]); + } + + _doProcessBlock(M: Array, offset: number) { + // Shortcut + + var H = this._hash.words; + + // Working variables + var a = H[0]; + var b = H[1]; + var c = H[2]; + var d = H[3]; + var e = H[4]; + + // Computation + for (var i = 0; i < 80; i++) { + if (i < 16) { + this.W[i] = M[offset + i] | 0; + } else { + var n = this.W[i - 3] ^ this.W[i - 8] ^ this.W[i - 14] ^ this.W[i - 16]; + this.W[i] = (n << 1) | (n >>> 31); + } + + var t = ((a << 5) | (a >>> 27)) + e + this.W[i]; + if (i < 20) { + t += ((b & c) | (~b & d)) + 0x5a827999; + } else if (i < 40) { + t += (b ^ c ^ d) + 0x6ed9eba1; + } else if (i < 60) { + t += ((b & c) | (b & d) | (c & d)) - 0x70e44324; + } else /* if (i < 80) */ { + t += (b ^ c ^ d) - 0x359d3e2a; + } + + e = d; + d = c; + c = (b << 30) | (b >>> 2); + b = a; + a = t; + } + + // Intermediate hash value + H[0] = (H[0] + a) | 0; + H[1] = (H[1] + b) | 0; + H[2] = (H[2] + c) | 0; + H[3] = (H[3] + d) | 0; + H[4] = (H[4] + e) | 0; + } + + _doFinalize () : WordArray{ + // Shortcuts + var data = this._data; + var dataWords = data.words; + + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x80 << (24 - nBitsLeft % 32); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 14] = Math.floor(nBitsTotal / 0x100000000); + dataWords[(((nBitsLeft + 64) >>> 9) << 4) + 15] = nBitsTotal; + data.sigBytes = dataWords.length * 4; + + // Hash final blocks + this._process(); + + // Return final computed hash + return this._hash; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/RC4.ts b/crypto/src/main/ets/RC4.ts new file mode 100644 index 0000000000000000000000000000000000000000..fd5164adf72a1ad3e351bbaebfd743a9e58dbc5d --- /dev/null +++ b/crypto/src/main/ets/RC4.ts @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { StreamCipher } from './StreamCipher'; +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig'; + +export const generateKeystreamWord = function generateKeystreamWord() { + // Shortcuts + var S = this._S; + var i = this._i; + var j = this._j; + + // Generate keystream word + var keystreamWord = 0; + for (var n = 0; n < 4; n++) { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + + keystreamWord |= S[(S[i] + S[j]) % 256] << (24 - n * 8); + } + + // Update counters + this._i = i; + this._j = j; + + return keystreamWord; +} + +export class RC4 extends StreamCipher { + keySize = 256 / 32 + ivSize = 0 + _S: Array + _i: number + _j: number + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, cfg); + this._doReset() + } + + _doReset() { + // Shortcuts + super.reset() + var key = this._key; + var keyWords = key.words; + var keySigBytes = key.sigBytes; + + // Init sbox + var S = this._S = []; + for (var i = 0; i < 256; i++) { + S[i] = i; + } + + // Key setup + for (var i = 0, j = 0; i < 256; i++) { + var keyByteIndex = i % keySigBytes; + var keyByte = (keyWords[keyByteIndex >>> 2] >>> (24 - (keyByteIndex % 4) * 8)) & 0xff; + + j = (j + S[i] + keyByte) % 256; + + // Swap + var t = S[i]; + S[i] = S[j]; + S[j] = t; + } + + // Counters + this._i = this._j = 0; + } + + _doProcessBlock(M, offset) { + M[offset] ^= generateKeystreamWord.call(this); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/RC4Drop.ts b/crypto/src/main/ets/RC4Drop.ts new file mode 100644 index 0000000000000000000000000000000000000000..ffc8495868e4953bda3970206d1f2b3aad23e84d --- /dev/null +++ b/crypto/src/main/ets/RC4Drop.ts @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { RC4,generateKeystreamWord } from './RC4'; +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig'; + +export class RC4Drop extends RC4 { + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, cfg); + this.cfg = Object.assign({ + drop: 192 + }, cfg); + this._doReset() + } + + _doReset() { + super._doReset(); + // Drop + for (var i = this.cfg.drop; i > 0; i--) { + generateKeystreamWord.call(this); + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/StreamCipher.ts b/crypto/src/main/ets/StreamCipher.ts new file mode 100644 index 0000000000000000000000000000000000000000..85339705a5d5b3824b8f95a7fbcae8ceb62f33ad --- /dev/null +++ b/crypto/src/main/ets/StreamCipher.ts @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Cipher } from './AES/lib/Cipher'; + +export abstract class StreamCipher extends Cipher { + blockSize = 1 + + _doFinalize() { + // Process partial blocks + this.cfg.blockSize = this.blockSize + var finalProcessedBlocks = this._process(!!'flush'); + + return finalProcessedBlocks; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/TripleDES.ts b/crypto/src/main/ets/TripleDES.ts new file mode 100644 index 0000000000000000000000000000000000000000..7c35f1255cadb4978faf2bd90092b7200a08e5c9 --- /dev/null +++ b/crypto/src/main/ets/TripleDES.ts @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { BlockCipher } from './AES/lib/BlockCipher'; +import { DES } from './DES'; +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig'; +import { WordArray } from './lib-WordArray'; + +export class TripleDES extends BlockCipher { + keySize = 192 / 32 + ivSize = 64 / 32 + blockSize = 64 / 32 + _des1 + _des2 + _des3 + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, cfg); + this._doReset() + } + + _doReset() { + // Shortcuts + var key = this._key; + var keyWords = key.words; + // Make sure the key length is valid (64, 128 or >= 192 bit) + if (keyWords.length !== 2 && keyWords.length !== 4 && keyWords.length < 6) { + throw new Error('Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.'); + } + + // Extend the key according to the keying options defined in 3DES standard + var key1 = keyWords.slice(0, 2); + var key2 = keyWords.length < 4 ? keyWords.slice(0, 2) : keyWords.slice(2, 4); + var key3 = keyWords.length < 6 ? keyWords.slice(0, 2) : keyWords.slice(4, 6); + + // Create DES instances + this._des1 = DES.createEncryptor(WordArray.create(key1)); + this._des2 = DES.createEncryptor(WordArray.create(key2)); + this._des3 = DES.createEncryptor(WordArray.create(key3)); + } + + encryptBlock(M, offset) { + this._des1.encryptBlock(M, offset); + this._des2.decryptBlock(M, offset); + this._des3.encryptBlock(M, offset); + } + + decryptBlock(M, offset) { + this._des3.decryptBlock(M, offset); + this._des2.encryptBlock(M, offset); + this._des1.decryptBlock(M, offset); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/Utf8.ts b/crypto/src/main/ets/Utf8.ts new file mode 100644 index 0000000000000000000000000000000000000000..c116bfb2363dbeb2fcea188f69221b0e097e2b74 --- /dev/null +++ b/crypto/src/main/ets/Utf8.ts @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; +import { Latin1 } from './Latin1'; + +export class Utf8 { + /** + * Converts a word array to a UTF-8 string. + * + * @param wordArray The word array. + * + * @return The UTF-8 string. + * + * @example + * + * let utf8String = Utf8.stringify(wordArray); + */ + public static stringify(wordArray: WordArray): string { + try { + return decodeURIComponent(escape(Latin1.stringify(wordArray))); + } catch(e) { + throw new Error('Malformed UTF-8 data'); + } + } + + /** + * Converts a UTF-8 string to a word array. + * + * @param utf8Str The UTF-8 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Utf8.parse(utf8String); + */ + public static parse(utf8Str: string): WordArray { + return Latin1.parse(decodeURI(encodeURIComponent(utf8Str))); + } +} + +// type guard for the formatter (to ensure it has the required static methods) +const _: Encoding = Utf8; \ No newline at end of file diff --git a/crypto/src/main/ets/Utils.ts b/crypto/src/main/ets/Utils.ts new file mode 100644 index 0000000000000000000000000000000000000000..d52249f69ec1b3655dcb8053217cf0415c10a472 --- /dev/null +++ b/crypto/src/main/ets/Utils.ts @@ -0,0 +1,37 @@ +export class Utils { + //将字符串转化为二进制的数据 + static strToBinary(str) { + var result = []; + var list = str.split(""); + for (var i = 0;i < list.length; i++) { + if (i != 0) { + //加空格,分割二进制 + result.push(" "); + } + var item = list[i]; + //将字符串转化为二进制数据 + var binaryStr = item.charCodeAt().toString(2); + result.push(binaryStr); + } + return result.join(""); + } + + //二进制转为字符串 + static binaryToStr(str) { + var result = []; + // + //通过空格来分开二进制的字符 + var list = str.split(" "); + for (var i = 0;i < list.length; i++) { + var item = list[i]; + //转为asciicode 码 + var asciiCode = parseInt(item, 2); + //转为文字 + var charValue = String.fromCharCode(asciiCode); + //添加到集合中 + result.push(charValue); + } + //返回结果 + return result.join(""); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-base64.ts b/crypto/src/main/ets/enc-base64.ts new file mode 100644 index 0000000000000000000000000000000000000000..7e76f6c1adb53da663b4c8d9c40827fdfc3c3e2b --- /dev/null +++ b/crypto/src/main/ets/enc-base64.ts @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +export class Base64 { + public static _map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + public static _reverseMap: Array | undefined = undefined; + + /** + * Converts a word array to a Base64 string. + * + * @param wordArray The word array. + * + * @return The Base64 string. + * + * @example + * + * let base64String = Base64.stringify(wordArray); + */ + public static stringify(wordArray: WordArray): string { + // Clamp excess bits + wordArray.clamp(); + + // Convert + const base64Chars = []; + for (let i = 0; i < wordArray.sigBytes; i += 3) { + const byte1 = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + const byte2 = (wordArray.words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + const byte3 = (wordArray.words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + const triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (let j = 0; (j < 4) && (i + j * 0.75 < wordArray.sigBytes); j++) { + base64Chars.push(this._map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + const paddingChar = this._map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + } + + /** + * Converts a Base64 string to a word array. + * + * @param base64Str The Base64 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Base64.parse(base64String); + */ + public static parse(base64Str: string): WordArray { + // Shortcuts + let base64StrLength = base64Str.length; + + if(this._reverseMap === undefined) { + this._reverseMap = []; + for(let j = 0; j < this._map.length; j++) { + this._reverseMap[this._map.charCodeAt(j)] = j; + } + } + + // Ignore padding + const paddingChar = this._map.charAt(64); + if(paddingChar) { + const paddingIndex = base64Str.indexOf(paddingChar); + if(paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return this.parseLoop(base64Str, base64StrLength, this._reverseMap); + } + + public static parseLoop(base64Str: string, base64StrLength: number, reverseMap: Array): WordArray { + const words: Array = []; + let nBytes = 0; + for(let i = 0; i < base64StrLength; i++) { + if(i % 4) { + const bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + const bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + words[nBytes >>> 2] |= (bits1 | bits2) << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + + return new WordArray(words, nBytes); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-base64url.ts b/crypto/src/main/ets/enc-base64url.ts new file mode 100644 index 0000000000000000000000000000000000000000..d553356b76c31ee3f2f29df39d9ccfad35c490ce --- /dev/null +++ b/crypto/src/main/ets/enc-base64url.ts @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; + +export class Base64Url { + public static _map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + public static _safe_map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; + public static _reverseMap: Array | undefined = undefined; + + /** + * Converts a word array to a Base64 string. + * + * @param {WordArray} wordArray The word array. + * + * @param {boolean} urlSafe Whether to use url safe + * + * @return {string} The Base64url string. + * + * @example + * + * let base64String = Base64.stringify(wordArray); + */ + public static stringify(wordArray: WordArray, urlSafe?: boolean): string { + if (urlSafe === undefined) { + urlSafe = true + } + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + var map = urlSafe ? this._safe_map : this._map; + + // Clamp excess bits + wordArray.clamp(); + + // Convert + var base64Chars = []; + for (var i = 0; i < sigBytes; i += 3) { + var byte1 = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + var byte2 = (words[(i + 1) >>> 2] >>> (24 - ((i + 1) % 4) * 8)) & 0xff; + var byte3 = (words[(i + 2) >>> 2] >>> (24 - ((i + 2) % 4) * 8)) & 0xff; + + var triplet = (byte1 << 16) | (byte2 << 8) | byte3; + + for (var j = 0; (j < 4) && (i + j * 0.75 < sigBytes); j++) { + base64Chars.push(map.charAt((triplet >>> (6 * (3 - j))) & 0x3f)); + } + } + + // Add padding + var paddingChar = map.charAt(64); + if (paddingChar) { + while (base64Chars.length % 4) { + base64Chars.push(paddingChar); + } + } + + return base64Chars.join(''); + } + + /** + * Converts a Base64 string to a word array. + * + * @param base64Str The Base64 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Base64.parse(base64String); + */ + public static parse(base64Str: string,urlSafe?: boolean): WordArray { + if (urlSafe === undefined) { + urlSafe = true + } + + // Shortcuts + var base64StrLength = base64Str.length; + var map = urlSafe ? this._safe_map : this._map; + var reverseMap = this._reverseMap; + + if (!reverseMap) { + reverseMap = this._reverseMap = []; + for (var j = 0; j < map.length; j++) { + reverseMap[map.charCodeAt(j)] = j; + } + } + + // Ignore padding + var paddingChar = map.charAt(64); + if (paddingChar) { + var paddingIndex = base64Str.indexOf(paddingChar); + if (paddingIndex !== -1) { + base64StrLength = paddingIndex; + } + } + + // Convert + return this.parseLoop(base64Str, base64StrLength, reverseMap); + } + + public static parseLoop(base64Str: string, base64StrLength: number, reverseMap: Array): WordArray { + var words = []; + var nBytes = 0; + for (var i = 0; i < base64StrLength; i++) { + if (i % 4) { + var bits1 = reverseMap[base64Str.charCodeAt(i - 1)] << ((i % 4) * 2); + var bits2 = reverseMap[base64Str.charCodeAt(i)] >>> (6 - (i % 4) * 2); + var bitsCombined = bits1 | bits2; + words[nBytes >>> 2] |= bitsCombined << (24 - (nBytes % 4) * 8); + nBytes++; + } + } + return new WordArray(words, nBytes); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-hex.ts b/crypto/src/main/ets/enc-hex.ts new file mode 100644 index 0000000000000000000000000000000000000000..7e234eea1c83525f4137cbaf601615cbd0379edd --- /dev/null +++ b/crypto/src/main/ets/enc-hex.ts @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +export class Hex { + /** + * Converts a word array to a hex string. + * + * @param wordArray The word array. + * + * @return The hex string. + * + * @example + * + * let hexString = Hex.stringify(wordArray); + */ + public static stringify(wordArray: WordArray): string { + // Convert + const hexChars: Array = []; + for (let i = 0; i < wordArray.sigBytes; i++) { + const bite = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + hexChars.push((bite >>> 4).toString(16)); + hexChars.push((bite & 0x0f).toString(16)); + } + + return hexChars.join(''); + } + + /** + * Converts a hex string to a word array. + * + * @param hexStr The hex string. + * + * @return The word array. + * + * @example + * + * let wordArray = Hex.parse(hexString); + */ + public static parse(hexStr: string): WordArray { + // Shortcut + const hexStrLength = hexStr.length; + + // Convert + const words: Array = []; + for (let i = 0; i < hexStrLength; i += 2) { + words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4); + } + + return new WordArray(words, hexStrLength / 2); + } +} + +// type guard for the formatter (to ensure it has the required static methods) +const _: Encoding = Hex; \ No newline at end of file diff --git a/crypto/src/main/ets/enc-latin1.ts b/crypto/src/main/ets/enc-latin1.ts new file mode 100644 index 0000000000000000000000000000000000000000..95015f595292963718dfd7c30ef4c5e3f160c8f8 --- /dev/null +++ b/crypto/src/main/ets/enc-latin1.ts @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +declare function escape(s: string): string; + +declare function unescape(s: string): string; + +export class Latin1 implements Encoding { + /** + * Converts a word array to a Latin1 string. + * + * @param wordArray The word array. + * + * @return The Latin1 string. + * + * @example + * + * let latin1String = Latin1.stringify(wordArray); + */ + public stringify(wordArray: WordArray): string { + // Convert + const latin1Chars = []; + for (let i = 0; i < wordArray.sigBytes; i++) { + const bite = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + latin1Chars.push(String.fromCharCode(bite)); + } + + return latin1Chars.join(''); + } + + /** + * Converts a Latin1 string to a word array. + * + * @param latin1Str The Latin1 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Latin1.parse(latin1String); + */ + public parse(latin1Str: string): WordArray { + // Shortcut + const latin1StrLength = latin1Str.length; + + // Convert + const words: Array = []; + for (let i = 0; i < latin1StrLength; i++) { + words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8); + } + return new WordArray(words, latin1StrLength); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-utf16.ts b/crypto/src/main/ets/enc-utf16.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa9405f8a14198cb849d78f3f822ae5bb13a27d7 --- /dev/null +++ b/crypto/src/main/ets/enc-utf16.ts @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +export class Utf16 implements Encoding { + /** + * Converts a word array to a UTF-16 BE string. + * + * @param wordArray The word array. + * + * @return The UTF-16 BE string. + * + * @example + * + * let utf16String = Utf16.stringify(wordArray); + */ + public stringify(wordArray: WordArray): string { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; + utf16Chars.push(String.fromCharCode(codePoint)); + } + return utf16Chars.join(''); + } + + /** + * Converts a UTF-16 BE string to a word array. + * + * @param utf16Str The UTF-16 BE string. + * + * @return The word array. + * + * @example + * + * let wordArray = Utf16.parse(utf16String); + */ + public parse(utf16Str: string): WordArray { + // Shortcut + var utf16StrLength = utf16Str.length; + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); + } + return WordArray.create(words, utf16StrLength * 2); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-utf16BE.ts b/crypto/src/main/ets/enc-utf16BE.ts new file mode 100644 index 0000000000000000000000000000000000000000..25bcd9581449666833ccc4b8ed880f363980ef09 --- /dev/null +++ b/crypto/src/main/ets/enc-utf16BE.ts @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +export class Utf16BE implements Encoding { + /** + * Converts a word array to a UTF-16 BE string. + * + * @param wordArray The word array. + * + * @return The UTF-16 BE string. + * + * @example + * + * let utf16String = Utf16.stringify(wordArray); + */ + public stringify(wordArray: WordArray): string { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = (words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff; + utf16Chars.push(String.fromCharCode(codePoint)); + } + return utf16Chars.join(''); + } + + /** + * Converts a UTF-16 BE string to a word array. + * + * @param utf16Str The UTF-16 BE string. + * + * @return The word array. + * + * @example + * + * let wordArray = Utf16.parse(utf16String); + */ + public parse(utf16Str: string): WordArray { + // Shortcut + var utf16StrLength = utf16Str.length; + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= utf16Str.charCodeAt(i) << (16 - (i % 2) * 16); + } + return WordArray.create(words, utf16StrLength * 2); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-utf16LE.ts b/crypto/src/main/ets/enc-utf16LE.ts new file mode 100644 index 0000000000000000000000000000000000000000..f540cadbe45b28c7b2c9968a05ea7d8d6eaebaff --- /dev/null +++ b/crypto/src/main/ets/enc-utf16LE.ts @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; + +export class Utf16LE implements Encoding { + /** + * Converts a word array to a UTF-16 LE string. + * + * @param wordArray The word array. + * + * @return The UTF-16 LE string. + * + * @example + * + * let utf16String = Utf16LE.stringify(wordArray); + */ + public stringify(wordArray: WordArray): string { + // Shortcuts + var words = wordArray.words; + var sigBytes = wordArray.sigBytes; + + // Convert + var utf16Chars = []; + for (var i = 0; i < sigBytes; i += 2) { + var codePoint = this.swapEndian((words[i >>> 2] >>> (16 - (i % 4) * 8)) & 0xffff); + utf16Chars.push(String.fromCharCode(codePoint)); + } + + return utf16Chars.join(''); + } + + /** + * Converts a UTF-16 LE string to a word array. + * + * @param utf16Str The UTF-16 LE string. + * + * @return The word array. + * + * @example + * + * let wordArray = Utf16LE.parse(utf16String); + */ + public parse(utf16Str: string): WordArray { + // Shortcut + var utf16StrLength = utf16Str.length; + + // Convert + var words = []; + for (var i = 0; i < utf16StrLength; i++) { + words[i >>> 1] |= this.swapEndian(utf16Str.charCodeAt(i) << (16 - (i % 2) * 16)); + } + + return WordArray.create(words, utf16StrLength * 2); + } + + swapEndian(word) { + return ((word << 8) & 0xff00ff00) | ((word >>> 8) & 0x00ff00ff); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/enc-utf8.ts b/crypto/src/main/ets/enc-utf8.ts new file mode 100644 index 0000000000000000000000000000000000000000..4afcbf15d9ae4c2122c6be723e29d0cfd75d2853 --- /dev/null +++ b/crypto/src/main/ets/enc-utf8.ts @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { WordArray } from './lib-WordArray'; +import { Latin1 } from './enc-latin1'; + +export class Utf8 implements Encoding { + /** + * Converts a word array to a UTF-8 string. + * + * @param wordArray The word array. + * + * @return The UTF-8 string. + * + * @example + * + * let utf8String = Utf8.stringify(wordArray); + */ + public stringify(wordArray: WordArray): string { + try { + return decodeURIComponent(encodeURI(Latin1.prototype.stringify(wordArray))); + } catch (e) { + throw new Error('Malformed UTF-8 data'); + } + } + + /** + * Converts a UTF-8 string to a word array. + * + * @param utf8Str The UTF-8 string. + * + * @return The word array. + * + * @example + * + * let wordArray = Utf8.parse(utf8String); + */ + public parse(utf8Str: string): WordArray { + return Latin1.prototype.parse(decodeURI(encodeURIComponent(utf8Str))); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/evpkdf.ts b/crypto/src/main/ets/evpkdf.ts new file mode 100644 index 0000000000000000000000000000000000000000..c15a76accd9d7fb94298a548a4665aad8d252de0 --- /dev/null +++ b/crypto/src/main/ets/evpkdf.ts @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { Hasher } from './AES/lib/Hasher'; +import { MD5 } from './MyMD5'; + +export interface OptionalEvpKDFConfig { + keySize?: number; + hasher?: typeof Hasher; + iterations?: number; +} + +export interface EvpKDFConfig extends OptionalEvpKDFConfig { + keySize: number; + hasher: typeof Hasher; + iterations: number; +} + +export class EvpKDF { + public cfg: EvpKDFConfig; + + /** + * Initializes a newly created key derivation function. + * + * @param cfg (Optional) The configuration options to use for the derivation. + * + * @example + * + * let kdf = EvpKDF.create(); + * let kdf = EvpKDF.create({ keySize: 8 }); + * let kdf = EvpKDF.create({ keySize: 8, iterations: 1000 }); + */ + constructor(cfg?: OptionalEvpKDFConfig) { + this.cfg = Object.assign({ + keySize: 128 / 32, + hasher: MD5, + iterations: 1 + }, cfg); + } + public static create(cfg?: OptionalEvpKDFConfig):EvpKDF{ + return new EvpKDF(cfg) + } + + /** + * Derives a key from a password. + * + * @param password The password. + * @param salt A salt. + * + * @return The derived key. + * + * @example + * + * let key = kdf.compute(password, salt); + */ + compute(password: WordArray | string, salt: WordArray | string): WordArray { + // Shortcut + let cfg = this.cfg; + + // Init hasher + const hasher:Hasher = new ( cfg.hasher)(); + + // Initial values + let derivedKey = WordArray.create(); + + // Shortcuts + let derivedKeyWords = derivedKey.words; + let keySize = cfg.keySize; + let iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + if (block) { + hasher.update(block); + } + var block = hasher.update(password).finalize(salt); + hasher.reset(); + + // Iterations + for (let i = 1; i < iterations; i++) { + block = hasher.finalize(block); + hasher.reset(); + } + + derivedKey.concat(block); + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/hmac.ts b/crypto/src/main/ets/hmac.ts new file mode 100644 index 0000000000000000000000000000000000000000..0c9167fe05b0dd3dcc6f3a2fdefca69c27083a15 --- /dev/null +++ b/crypto/src/main/ets/hmac.ts @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Hasher } from './AES/lib/Hasher' +import { Utf8 } from './Utf8' +import { WordArray } from './lib-WordArray' +export class HMAC{ + _hasher:Hasher + _oKey:WordArray + _iKey:WordArray + constructor(hasher:Hasher, key){ + this._hasher =hasher; + + // Convert string to WordArray, else assume WordArray already + if (typeof key == 'string') { + key = Utf8.parse(key); + } + + // Shortcuts + var hasherBlockSize = hasher.cfg.blockSize; + var hasherBlockSizeBytes = hasherBlockSize * 4; + + // Allow arbitrary length keys + if (key.sigBytes > hasherBlockSizeBytes) { + key = hasher.finalize(key); + } + + // Clamp excess bits + key.clamp(); + + // Clone key for inner and outer pads + var oKey = this._oKey = key.clone(); + var iKey = this._iKey = key.clone(); + + // Shortcuts + var oKeyWords = oKey.words; + var iKeyWords = iKey.words; + + // XOR keys with pad constants + for (var i = 0; i < hasherBlockSize; i++) { + oKeyWords[i] ^= 0x5c5c5c5c; + iKeyWords[i] ^= 0x36363636; + } + oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes; + // Set initial values + this.reset(); + } + static create(hasher:Hasher, key):HMAC{ + return new HMAC(hasher,key) + } + reset() { + // Shortcut + var hasher = this._hasher; + + // Reset + hasher.reset(); + hasher.update(this._iKey); + } + update(messageUpdate: WordArray | string):HMAC { + this._hasher.update(messageUpdate); + // Chainable + return this; + } + + /** + * Finalizes the HMAC computation. + * Note that the finalize operation is effectively a destructive, read-once operation. + * + * @param {WordArray|string} messageUpdate (Optional) A final message update. + * + * @return {WordArray} The HMAC. + * + * @example + * + * var hmac = hmacHasher.finalize(); + * var hmac = hmacHasher.finalize('message'); + * var hmac = hmacHasher.finalize(wordArray); + */ + finalize(messageUpdate: WordArray | string): WordArray { + // Shortcut + var hasher = this._hasher; + + // Compute HMAC + var innerHash = hasher.finalize(messageUpdate); + hasher.reset(); + var hmac = hasher.finalize(this._oKey.clone().concat(innerHash)); + + return hmac; + } + +} \ No newline at end of file diff --git a/crypto/src/main/ets/lib-WordArray.ts b/crypto/src/main/ets/lib-WordArray.ts new file mode 100644 index 0000000000000000000000000000000000000000..83041697931976ad87f139119b9e9adc7f89264c --- /dev/null +++ b/crypto/src/main/ets/lib-WordArray.ts @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { Encoding } from './Encoding'; +import { Hex } from './enc-Hex'; + +export class WordArray { + words: Array; + + sigBytes: number; + + /** + * Creates a word array filled with random bytes. + * + * @param nBytes The number of random bytes to generate. + * + * @return The random word array. + * + * @example + * + * let wordArray = WordArray.random(16); + */ + public static random(nBytes: number) { + const words = []; + + const r = (function(m_w: number) { + let m_z = 0x3ade68b1; + + const mask = 0xffffffff; + + return function() { + m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask; + m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask; + let result = ((m_z << 0x10) + m_w) & mask; + result /= 0x100000000; + result += 0.5; + return result * (Math.random() > .5 ? 1 : -1); + }; + }); + + for(let i = 0, rcache; i < nBytes; i += 4) { + const _r = r((rcache || Math.random()) * 0x100000000); + + rcache = _r() * 0x3ade67b7; + words.push((_r() * 0x100000000) | 0); + } + + return new WordArray(words, nBytes); + } + + /** + * Initializes a newly created word array. + * + * @param words (Optional) An array of 32-bit words. + * @param sigBytes (Optional) The number of significant bytes in the words. + * + * @example + * + * let wordArray = new WordArray(); + * let wordArray = new WordArray([0x00010203, 0x04050607]); + * let wordArray = new WordArray([0x00010203, 0x04050607], 6); + */ + constructor(words?: Array, sigBytes?: number) { + this.words = words || []; + + if(sigBytes !== undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = this.words.length * 4; + } + } + public static create(words?: Array, sigBytes?: number):WordArray{ + return new WordArray(words,sigBytes) + } + + /** + * Converts this word array to a string. + * + * @param encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex + * + * @return The stringified word array. + * + * @example + * + * let string = wordArray + ''; + * let string = wordArray.toString(); + * let string = wordArray.toString(CryptoJS.enc.Utf8); + */ + toString(encoder?: Encoding): string { + return (encoder || Hex).stringify(this); + } + + /** + * Concatenates a word array to this word array. + * + * @param wordArray The word array to append. + * + * @return This word array. + * + * @example + * + * wordArray1.concat(wordArray2); + */ + concat(wordArray: WordArray): WordArray { + // Clamp excess bits + this.clamp(); + + // Concat + if(this.sigBytes % 4) { + // Copy one byte at a time + for(let i = 0; i < wordArray.sigBytes; i++) { + const thatByte = (wordArray.words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff; + this.words[(this.sigBytes + i) >>> 2] |= thatByte << (24 - ((this.sigBytes + i) % 4) * 8); + } + } else { + // Copy one word at a time + for (let i = 0; i < wordArray.sigBytes; i += 4) { + this.words[(this.sigBytes + i) >>> 2] = wordArray.words[i >>> 2]; + } + } + this.sigBytes += wordArray.sigBytes; + + // Chainable + return this; + } + + /** + * Removes insignificant bits. + * + * @example + * + * wordArray.clamp(); + */ + clamp() { + // Clamp + this.words[this.sigBytes >>> 2] &= 0xffffffff << (32 - (this.sigBytes % 4) * 8); + this.words.length = Math.ceil(this.sigBytes / 4); + } + + /** + * Creates a copy of this word array. + * + * @return The clone. + * + * @example + * + * let clone = wordArray.clone(); + */ + clone(): WordArray { + return new WordArray(this.words.slice(0), this.sigBytes); + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/md5.ets b/crypto/src/main/ets/md5.ts similarity index 100% rename from crypto/src/main/ets/md5.ets rename to crypto/src/main/ets/md5.ts diff --git a/crypto/src/main/ets/pbkdf2.ts b/crypto/src/main/ets/pbkdf2.ts new file mode 100644 index 0000000000000000000000000000000000000000..d64be58ce25751c994135d34cf97080697a105cd --- /dev/null +++ b/crypto/src/main/ets/pbkdf2.ts @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { SHA1 } from './MySha1'; +import { MD5 } from './MyMD5'; +import { HMAC } from './hmac'; +import { WordArray } from './lib-WordArray'; +import { Hasher } from './AES/lib/Hasher'; + + +export interface OptionalPBKDF2Config { + keySize?: number; + hasher?: Hasher; + iterations?: number; +} + +export interface PBKDF2Config extends OptionalPBKDF2Config { + keySize: number; + hasher: Hasher; + iterations: number; +} +export class PBKDF2{ + public cfg: PBKDF2Config; + constructor(cfg?: OptionalPBKDF2Config) { + this.cfg = Object.assign({ + keySize: 128/32, + hasher: SHA1, + iterations: 1 + }, cfg); + } + public static create(cfg?: OptionalPBKDF2Config):PBKDF2{ + return new PBKDF2(cfg) + } + compute(password, salt):WordArray{ + // Shortcut + var cfg = this.cfg; + const hasher = new ( this.cfg.hasher)() + // Init HMAC + var hmac = HMAC.create(hasher, password); + + // Initial values + var derivedKey = WordArray.create(); + var blockIndex = WordArray.create([0x00000001]); + + // Shortcuts + var derivedKeyWords = derivedKey.words; + var blockIndexWords = blockIndex.words; + var keySize = cfg.keySize; + var iterations = cfg.iterations; + + // Generate key + while (derivedKeyWords.length < keySize) { + var block = hmac.update(salt).finalize(blockIndex); + hmac.reset(); + + // Shortcuts + var blockWords = block.words; + var blockWordsLength = blockWords.length; + + // Iterations + var intermediate = block; + for (var i = 1; i < iterations; i++) { + intermediate = hmac.finalize(intermediate); + hmac.reset(); + + // Shortcut + var intermediateWords = intermediate.words; + + // XOR intermediate with block + for (var j = 0; j < blockWordsLength; j++) { + blockWords[j] ^= intermediateWords[j]; + } + } + + derivedKey.concat(block); + blockIndexWords[0]++; + } + derivedKey.sigBytes = keySize * 4; + + return derivedKey; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/rabbit-legacy.ts b/crypto/src/main/ets/rabbit-legacy.ts new file mode 100644 index 0000000000000000000000000000000000000000..2e4287e735fb2ad98b82c880e541111edc4c05eb --- /dev/null +++ b/crypto/src/main/ets/rabbit-legacy.ts @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { StreamCipher } from './StreamCipher' +import { WordArray } from './lib-WordArray' +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig' + +const S: Array = [] +const C_: Array = [] +const G: Array = [] + +function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; +} + +export class Rabbit_Legacy extends StreamCipher { + _X: Array = [] + _C: Array = [] + _b: number = 0 + keySize = 128 / 32 + ivSize = 64/32 + blockSize = 4; + public cfg: BufferedBlockAlgorithmConfig; + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, Object.assign({ + // default: 128 / 32 + blockSize: 128 / 32, + }, cfg)); + this.cfg = cfg; + this._doReset() + + + } + + _doReset() { +// super.reset(); + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv.words.length>0) { + console.info("reset..........") + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + } + + _doProcessBlock(wordArray: Array, offset: number){ + this.doBlock(wordArray,offset) + } + + doBlock(wordArray: Array, offset: number) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + wordArray[offset + i] ^= S[i]; + } + + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/rabbit.ts b/crypto/src/main/ets/rabbit.ts new file mode 100644 index 0000000000000000000000000000000000000000..a22ad0bd208553f6e914dff4113cc78d0bf8ef91 --- /dev/null +++ b/crypto/src/main/ets/rabbit.ts @@ -0,0 +1,185 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { StreamCipher } from './StreamCipher' +import { WordArray } from './lib-WordArray' +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig' +import { Cipher } from './AES/lib/Cipher'; + +var S: Array = [] +var C_: Array = [] +var G: Array = [] + +function nextState() { + // Shortcuts + var X = this._X; + var C = this._C; + + // Save old counter values + for (var i = 0; i < 8; i++) { + C_[i] = C[i]; + } + + + // Calculate new counter values + C[0] = (C[0] + 0x4d34d34d + this._b) | 0; + C[1] = (C[1] + 0xd34d34d3 + ((C[0] >>> 0) < (C_[0] >>> 0) ? 1 : 0)) | 0; + C[2] = (C[2] + 0x34d34d34 + ((C[1] >>> 0) < (C_[1] >>> 0) ? 1 : 0)) | 0; + C[3] = (C[3] + 0x4d34d34d + ((C[2] >>> 0) < (C_[2] >>> 0) ? 1 : 0)) | 0; + C[4] = (C[4] + 0xd34d34d3 + ((C[3] >>> 0) < (C_[3] >>> 0) ? 1 : 0)) | 0; + C[5] = (C[5] + 0x34d34d34 + ((C[4] >>> 0) < (C_[4] >>> 0) ? 1 : 0)) | 0; + C[6] = (C[6] + 0x4d34d34d + ((C[5] >>> 0) < (C_[5] >>> 0) ? 1 : 0)) | 0; + C[7] = (C[7] + 0xd34d34d3 + ((C[6] >>> 0) < (C_[6] >>> 0) ? 1 : 0)) | 0; + this._b = (C[7] >>> 0) < (C_[7] >>> 0) ? 1 : 0; + + // Calculate the g-values + for (var i = 0; i < 8; i++) { + var gx = X[i] + C[i]; + + // Construct high and low argument for squaring + var ga = gx & 0xffff; + var gb = gx >>> 16; + + // Calculate high and low result of squaring + var gh = ((((ga * ga) >>> 17) + ga * gb) >>> 15) + gb * gb; + var gl = (((gx & 0xffff0000) * gx) | 0) + (((gx & 0x0000ffff) * gx) | 0); + + // High XOR low + G[i] = gh ^ gl; + } + + // Calculate new state values + X[0] = (G[0] + ((G[7] << 16) | (G[7] >>> 16)) + ((G[6] << 16) | (G[6] >>> 16))) | 0; + X[1] = (G[1] + ((G[0] << 8) | (G[0] >>> 24)) + G[7]) | 0; + X[2] = (G[2] + ((G[1] << 16) | (G[1] >>> 16)) + ((G[0] << 16) | (G[0] >>> 16))) | 0; + X[3] = (G[3] + ((G[2] << 8) | (G[2] >>> 24)) + G[1]) | 0; + X[4] = (G[4] + ((G[3] << 16) | (G[3] >>> 16)) + ((G[2] << 16) | (G[2] >>> 16))) | 0; + X[5] = (G[5] + ((G[4] << 8) | (G[4] >>> 24)) + G[3]) | 0; + X[6] = (G[6] + ((G[5] << 16) | (G[5] >>> 16)) + ((G[4] << 16) | (G[4] >>> 16))) | 0; + X[7] = (G[7] + ((G[6] << 8) | (G[6] >>> 24)) + G[5]) | 0; +} + +export class Rabbit extends StreamCipher { + _X: Array = [] + _C: Array = [] + _b: number = 0 + public cfg: BufferedBlockAlgorithmConfig; + keySize = 128 / 32 + ivSize = 64 / 32 + blockSize = 4; + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, Object.assign({ + // default: 128 / 32 + blockSize: 128 / 32, + }, cfg)); + this.cfg = cfg; + + this._doReset() + } + + _doReset() { + super.reset(); + // Shortcuts + var K = this._key.words; + var iv = this.cfg.iv; + // Swap endian + for (var i = 0; i < 4; i++) { + K[i] = (((K[i] << 8) | (K[i] >>> 24)) & 0x00ff00ff) | + (((K[i] << 24) | (K[i] >>> 8)) & 0xff00ff00); + } + + // Generate initial state values + var X = this._X = [ + K[0], (K[3] << 16) | (K[2] >>> 16), + K[1], (K[0] << 16) | (K[3] >>> 16), + K[2], (K[1] << 16) | (K[0] >>> 16), + K[3], (K[2] << 16) | (K[1] >>> 16) + ]; + + // Generate initial counter values + var C = this._C = [ + (K[2] << 16) | (K[2] >>> 16), (K[0] & 0xffff0000) | (K[1] & 0x0000ffff), + (K[3] << 16) | (K[3] >>> 16), (K[1] & 0xffff0000) | (K[2] & 0x0000ffff), + (K[0] << 16) | (K[0] >>> 16), (K[2] & 0xffff0000) | (K[3] & 0x0000ffff), + (K[1] << 16) | (K[1] >>> 16), (K[3] & 0xffff0000) | (K[0] & 0x0000ffff) + ]; + + // Carry bit + this._b = 0; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + + // Modify the counters + for (var i = 0; i < 8; i++) { + C[i] ^= X[(i + 4) & 7]; + } + + // IV setup + if (iv.words.length>0) { + // Shortcuts + var IV = iv.words; + var IV_0 = IV[0]; + var IV_1 = IV[1]; + + // Generate four subvectors + var i0 = (((IV_0 << 8) | (IV_0 >>> 24)) & 0x00ff00ff) | (((IV_0 << 24) | (IV_0 >>> 8)) & 0xff00ff00); + var i2 = (((IV_1 << 8) | (IV_1 >>> 24)) & 0x00ff00ff) | (((IV_1 << 24) | (IV_1 >>> 8)) & 0xff00ff00); + var i1 = (i0 >>> 16) | (i2 & 0xffff0000); + var i3 = (i2 << 16) | (i0 & 0x0000ffff); + + // Modify counter values + C[0] ^= i0; + C[1] ^= i1; + C[2] ^= i2; + C[3] ^= i3; + C[4] ^= i0; + C[5] ^= i1; + C[6] ^= i2; + C[7] ^= i3; + + // Iterate the system four times + for (var i = 0; i < 4; i++) { + nextState.call(this); + } + } + } + + _doProcessBlock(M: Array, offset: number) { + // Shortcut + var X = this._X; + + // Iterate the system + nextState.call(this); + + // Generate four keystream words + S[0] = X[0] ^ (X[5] >>> 16) ^ (X[3] << 16); + S[1] = X[2] ^ (X[7] >>> 16) ^ (X[5] << 16); + S[2] = X[4] ^ (X[1] >>> 16) ^ (X[7] << 16); + S[3] = X[6] ^ (X[3] >>> 16) ^ (X[1] << 16); + + for (var i = 0; i < 4; i++) { + // Swap endian + S[i] = (((S[i] << 8) | (S[i] >>> 24)) & 0x00ff00ff) | + (((S[i] << 24) | (S[i] >>> 8)) & 0xff00ff00); + + // Encrypt + M[offset + i] ^= S[i]; + } + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/ripemd160.ets b/crypto/src/main/ets/ripemd160.ts similarity index 100% rename from crypto/src/main/ets/ripemd160.ets rename to crypto/src/main/ets/ripemd160.ts diff --git a/crypto/src/main/ets/sha1.ets b/crypto/src/main/ets/sha1.ts similarity index 100% rename from crypto/src/main/ets/sha1.ets rename to crypto/src/main/ets/sha1.ts diff --git a/crypto/src/main/ets/sha224.ts b/crypto/src/main/ets/sha224.ts new file mode 100644 index 0000000000000000000000000000000000000000..c1b9f6285b7a6c7fda926590fdc7476fb94b91ea --- /dev/null +++ b/crypto/src/main/ets/sha224.ts @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 jsSHA from "jssha" + +export class sha224 { + hex_sha224(s) { + const shaObj = new jsSHA("SHA-224", "TEXT", { encoding: "UTF8" }); + shaObj.update(s); + const hash = shaObj.getHash("HEX"); + return hash; + } + + hex_hmac_sha224(k, d) { + const shaObj = new jsSHA("SHA-224", "TEXT", { + hmacKey: { value: d, format: "TEXT", encoding: "UTF8" }, + }); + shaObj.update(k); + const hmac = shaObj.getHash("HEX"); + return hmac; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/sha256.ets b/crypto/src/main/ets/sha256.ts similarity index 100% rename from crypto/src/main/ets/sha256.ets rename to crypto/src/main/ets/sha256.ts diff --git a/crypto/src/main/ets/sha3.ts b/crypto/src/main/ets/sha3.ts new file mode 100644 index 0000000000000000000000000000000000000000..f5be750009fd3646fcfd7476ab9d1da0353366d8 --- /dev/null +++ b/crypto/src/main/ets/sha3.ts @@ -0,0 +1,294 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 { WordArray } from './lib-WordArray'; +import { X64Word } from './x64_core'; +import { BufferedBlockAlgorithmConfig } from './BufferedBlockAlgorithmConfig'; +import { Hasher } from './AES/lib/Hasher'; + +var RHO_OFFSETS = []; +var PI_INDEXES = []; +var ROUND_CONSTANTS = []; + + +// Compute Constants +(function(){ + // Compute rho offset constants + var x = 1, y = 0; + for (var t = 0; t < 24; t++) { + RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64; + + var newX = y % 5; + var newY = (2 * x + 3 * y) % 5; + x = newX; + y = newY; + } + // Compute pi index constants + for (var x = 0; x < 5; x++) { + for (var y = 0; y < 5; y++) { + PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5; + } + } + + // Compute round constants + var LFSR = 0x01; + for (var i = 0; i < 24; i++) { + let roundConstantMsw: number = 0; + let roundConstantLsw: number = 0; + + for (var j = 0; j < 7; j++) { + if (LFSR & 0x01) { + var bitPosition = (1 << j) - 1; + if (bitPosition < 32) { + roundConstantLsw ^= 1 << bitPosition; + } else /* if (bitPosition >= 32) */ + { + roundConstantMsw ^= 1 << (bitPosition - 32); + } + } + + // Compute next LFSR + if (LFSR & 0x80) { + // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1 + LFSR = (LFSR << 1) ^ 0x71; + } else { + LFSR <<= 1; + } + } + if (roundConstantLsw == 0)roundConstantLsw = 1 + ROUND_CONSTANTS[i] = new X64Word(roundConstantMsw, roundConstantLsw); + } +}()); + +var T = []; + + +(function(){ + for (var i = 0; i < 25; i++) { + T[i] = new X64Word(); + } +}()); + +export class sha3 extends Hasher { + _state: any + hex_sha3(s, outputLength?: number) { + Object.assign({ blockSize: 18 }, this.cfg) + let localsha3 = Hasher._createHelper(sha3); + return localsha3.helper(s, { outputLength: outputLength }) + } + + hex_hmac_sha3(k, d, outputLength?: number) { + + if (outputLength == null || outputLength == undefined) { + outputLength = 512 + } + let hmac_sha3 = Hasher._createHmacHelper( sha3); + return hmac_sha3.helper(d, k, this.cfg).toString() + + } + + public constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig) { + super(xformMode, key, Object.assign({ blockSize: 16, outputLength: 512 }, cfg)) + this.blockSize = 18 + } + + reset() { + var state = this._state = [] + for (var i = 0; i < 25; i++) { + state[i] = new X64Word(); + } + this.cfg.blockSize = (1600 - 2 * this.cfg.outputLength) / 32; + } + + _doProcessBlock(M, offset) { + // Shortcuts + var state = this._state; + let nBlockSizeLanes = this.cfg.blockSize / 2; + // Absorb + for (var i = 0; i < nBlockSizeLanes; i++) { + // Shortcuts + let M2i = M[offset + 2 * i]; + let M2i1 = M[offset + 2 * i + 1]; + // Swap endian + M2i = ( + (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) | + (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00) + ); + + M2i1 = ( + (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) | + (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00) + ); + + // Absorb message into state + // Absorb message into state + let lane = state[i]; //M2i: 1752133229,M2i1 : 1549560425 + lane.high ^= M2i1; + lane.low ^= M2i; + + } + + // Rounds + for (var round = 0; round < 24; round++) { + // Theta + for (let x = 0; x < 5; x++) { + // Mix column lanes + var tMsw = 0, tLsw = 0; + for (var y = 0; y < 5; y++) { + let lane = state[x + 5 * y]; + tMsw ^= lane.high; + tLsw ^= lane.low; + } + + // Temporary values + var Tx = T[x]; + Tx.high = tMsw; + Tx.low = tLsw; + } + for (let x = 0; x < 5; x++) { + // Shortcuts + var Tx4 = T[(x + 4) % 5]; + var Tx1 = T[(x + 1) % 5]; + var Tx1Msw = Tx1.high; + var Tx1Lsw = Tx1.low; + + // Mix surrounding columns + let tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31)); + let tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31)); + for (let y = 0; y < 5; y++) { + let lane = state[x + 5 * y]; + lane.high ^= tMsw; + lane.low ^= tLsw; + } + } + + // Rho Pi + for (var laneIndex = 1; laneIndex < 25; laneIndex++) { + let tMsw; + let tLsw; + // Shortcuts + let lane = state[laneIndex]; + var laneMsw = lane.high; + var laneLsw = lane.low; + var rhoOffset = RHO_OFFSETS[laneIndex]; + + // Rotate lanes + if (rhoOffset < 32) { + tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset)); + tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset)); + } else /* if (rhoOffset >= 32) */ + { + tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset)); + tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset)); + } + + // Transpose lanes + var TPiLane = T[PI_INDEXES[laneIndex]]; + + TPiLane.high = tMsw; + TPiLane.low = tLsw; + } + + // Rho pi at x = y = 0 + var T0 = T[0]; + var state0 = state[0]; + T0.high = state0.high; + T0.low = state0.low; + + // Chi + for (let x = 0; x < 5; x++) { + for (let y = 0; y < 5; y++) { + // Shortcuts + let laneIndex = x + 5 * y; + let lane = state[laneIndex]; + let TLane = T[laneIndex]; + let Tx1Lane = T[((x + 1) % 5) + 5 * y]; + let Tx2Lane = T[((x + 2) % 5) + 5 * y]; + + // Mix rows + lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high); + lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low); + + } + } + + // Iota + let lane = state[0]; + var roundConstant = ROUND_CONSTANTS[round]; + lane.high ^= roundConstant.high; + lane.low ^= roundConstant.low; + + } + } + + _doFinalize() { + // Shortcuts + var data = this._data; + var dataWords = data.words; + var nBitsTotal = this._nDataBytes * 8; + var nBitsLeft = data.sigBytes * 8; + var blockSizeBits = this.cfg.blockSize * 32; + + // Add padding + dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32); + dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80; + data.sigBytes = dataWords.length * 4; + // Hash final blocks + + this._process(); + + // Shortcuts + var state = this._state + var outputLengthBytes = this.cfg.outputLength / 8; + var outputLengthLanes = outputLengthBytes / 8; + // Squeeze + var hashWords = []; + for (var i = 0; i < outputLengthLanes; i++) { + // Shortcuts + var lane = state[i]; + var laneMsw = lane.high + var laneLsw = lane.low + + // Swap endian + laneMsw = ( + (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) | + (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00) + ); + laneLsw = ( + (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) | + (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00) + ); + + // Squeeze state to retrieve hash + hashWords.push(laneLsw); + hashWords.push(laneMsw); + } + + // Return final computed hash + return new WordArray(hashWords, outputLengthBytes); + } + + clone() { + // console.log("clone date "+this._state) + var clone = Hasher.prototype.clone.call(this); + + var state = clone._state = this._state.slice(0); + for (var i = 0; i < 25; i++) { + state[i] = state[i].clone(); + } + + return clone; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/sha384.ts b/crypto/src/main/ets/sha384.ts new file mode 100644 index 0000000000000000000000000000000000000000..ce754cb9360bb06c0c32822a8209790ebded3e19 --- /dev/null +++ b/crypto/src/main/ets/sha384.ts @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 jsSHA from "jssha" + +export class sha384 { + hex_sha384(s) { + const shaObj = new jsSHA("SHA-384", "TEXT", { encoding: "UTF8" }); + shaObj.update(s); + const hash = shaObj.getHash("HEX"); + return hash; + } + + hex_hmac_sha384(k, d) { + const shaObj = new jsSHA("SHA-384", "TEXT", { + hmacKey: { value: d, format: "TEXT", encoding: "UTF8" }, + }); + shaObj.update(k); + const hmac = shaObj.getHash("HEX"); + return hmac; + } +} \ No newline at end of file diff --git a/crypto/src/main/ets/sha512.ets b/crypto/src/main/ets/sha512.ts similarity index 100% rename from crypto/src/main/ets/sha512.ets rename to crypto/src/main/ets/sha512.ts diff --git a/crypto/src/main/ets/x64_core.ts b/crypto/src/main/ets/x64_core.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c8383659d169bf149c973c7aa8d1a5efe796753 --- /dev/null +++ b/crypto/src/main/ets/x64_core.ts @@ -0,0 +1,45 @@ +import { WordArray } from "./lib-WordArray" +class X64Word { + high: number + low: number + + constructor(high?, low?) { + this.high = high; + this.low = low; + } +} + +class X64WordArray { + words: WordArray + sigBytes: number + + init(words, sigBytes) { + words = this.words = words || []; + if (sigBytes != undefined) { + this.sigBytes = sigBytes; + } else { + this.sigBytes = words.length * 8; + } + } + + toX32() { + // Shortcuts + var x64Words = this.words; + var x64WordsLength = x64Words.words.length; + + // Convert + var x32Words = []; + for (var i = 0; i < x64WordsLength; i++) { + var x64Word = x64Words[i]; + x32Words.push(x64Word.high); + x32Words.push(x64Word.low); + } + + return new WordArray(x32Words, this.sigBytes); + } +} + +export {X64Word,X64WordArray} + + + diff --git a/crypto/src/main/module.json5 b/crypto/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..96fb1947e4690be191d07feb7bb821c0a4f1d54d --- /dev/null +++ b/crypto/src/main/module.json5 @@ -0,0 +1,10 @@ +{ + "module": { + "name": "crypto", + "type": "har", + "deviceTypes": [ + "default" + ], + "uiSyntax": "ets" + } +} diff --git a/entry/build-profile.json5 b/entry/build-profile.json5 index ae58d1d0a70c602c9cfe1909b00dfec899ba1944..7dc37bb919dada5132609c409200db266559004f 100644 --- a/entry/build-profile.json5 +++ b/entry/build-profile.json5 @@ -1,5 +1,5 @@ { - "apiType": 'faMode', + "apiType": 'stageMode', "buildOption": { }, "targets": [ diff --git a/entry/hvigorfile.js b/entry/hvigorfile.js index bcec4c99653062cbf17702c40a2dd2a7b809b81a..d7720ee6a7aad5c617d1fd2f6fc8c87067bfa32c 100644 --- a/entry/hvigorfile.js +++ b/entry/hvigorfile.js @@ -1,2 +1,2 @@ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -module.exports = require('@ohos/hvigor-ohos-plugin').legacyHapTasks +module.exports = require('@ohos/hvigor-ohos-plugin').hapTasks diff --git a/entry/package-lock.json b/entry/package-lock.json index 6c55c940305c21929c798aceb85513b006b5da6f..ed8914c2e54cb7f8e542fd8a99ec7257c14d49df 100644 --- a/entry/package-lock.json +++ b/entry/package-lock.json @@ -7,25 +7,21 @@ "@ohos/crypto": { "version": "file:../crypto", "requires": { - "@ohos/crypto": "file:../crypto" + "jssha": "^3.2.0" }, "dependencies": { "@ohos/crypto": { "version": "file:../crypto", - "dev": true, - "requires": { - "@ohos/crypto": "file:../crypto" - }, "dependencies": { "@ohos/crypto": { - "version": "file:../crypto", - "dev": true, - "requires": { - "@ohos/crypto": "file:../crypto" - }, - "dependencies": {} + "version": "file:../crypto" } } + }, + "jssha": { + "version": "3.2.0", + "resolved": "https://repo.huaweicloud.com/repository/npm/jssha/-/jssha-3.2.0.tgz", + "integrity": "sha512-QuruyBENDWdN4tZwJbQq7/eAK85FqrI4oDbXjy5IBhYD+2pTJyBUWZe8ctWaCkrV0gy6AaelgOZZBMeswEa/6Q==" } } } diff --git a/entry/src/main/config.json b/entry/src/main/config.json deleted file mode 100644 index 156cc7b9e12cf0a4d4fd71df65f0458242e0989b..0000000000000000000000000000000000000000 --- a/entry/src/main/config.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "app": { - "vendor": "example", - "bundleName": "cn.openharmony.crypto-js", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "mainAbility": ".MainAbility", - "deviceType": [ - "phone" - ], - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "orientation": "unspecified", - "visible": true, - "srcPath": "MainAbility", - "name": ".MainAbility", - "srcLanguage": "ets", - "icon": "$media:icon", - "description": "$string:MainAbility_desc", - "formsEnabled": false, - "label": "$string:MainAbility_label", - "type": "page", - "launchType": "standard" - } - ], - "distro": { - "moduleType": "entry", - "installationFree": false, - "deliveryWithInstall": true, - "moduleName": "entry" - }, - "package": "com.example.entry", - "srcPath": "", - "name": ".entry", - "js": [ - { - "mode": { - "syntax": "ets", - "type": "pageAbility" - }, - "pages": [ - "pages/index" - ], - "name": ".MainAbility", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} diff --git a/entry/src/main/ets/Application/AbilityStage.ts b/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..2d79984dd6748db25fba5dfaceea19e071c6d9a8 --- /dev/null +++ b/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/entry/src/main/ets/MainAbility/MainAbility.ts b/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..3f9c66fab783c14a50b03348f3f2a90f323f6262 --- /dev/null +++ b/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 Ability from '@ohos.application.Ability' + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + console.log("[Demo] MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + console.log("[Demo] MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[Demo] MainAbility onWindowStageCreate") + + windowStage.setUIContent(this.context, "pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[Demo] MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[Demo] MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[Demo] MainAbility onBackground") + } +}; diff --git a/entry/src/main/ets/MainAbility/pages/index.ets b/entry/src/main/ets/MainAbility/pages/index.ets deleted file mode 100644 index 745b66efb3da9df3d0e63518fb9bb8586ba8c59e..0000000000000000000000000000000000000000 --- a/entry/src/main/ets/MainAbility/pages/index.ets +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the MIT License, (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://opensource.org/licenses/MIT - * - * 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 prompt from '@system.prompt'; -import { md5 } from '@ohos/crypto/' -import { sha1 } from '@ohos/crypto/' -import { sha256 } from '@ohos/crypto/' -import { sha512 } from '@ohos/crypto/' -import { ripemd160 } from '@ohos/crypto/' - -@Entry -@Component -struct Index { - build() { - Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { - Text('md5') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'md5=' + md5.prototype.hex_md5('123456') }) - console.log('md5=' + md5.prototype.hex_md5('123456')) - }) - Text('sha1') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'sha1=' + sha1.prototype.hex_sha1('123456') }) - console.log('sha1=' + sha1.prototype.hex_sha1('123456')) - }) - Text('sha256') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'sha256=' + sha256.prototype.hex_sha256('123456') }) - console.log('sha256=' + sha256.prototype.hex_sha256('123456')) - }) - Text('sha512') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'sha512=' + sha512.prototype.hex_sha512('123456') }) - console.log('sha512=' + sha512.prototype.hex_sha512('123456')) - }) - Text('ripemd160') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: "ripemd160=" + ripemd160.prototype.hex_rmd160('123456') }) - console.log("ripemd160=" + ripemd160.prototype.hex_rmd160('123456')); - }) - Text('hmac-md5') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'hmac-md5=' + md5.prototype.hex_hmac_md5('123456', '123456') }) - console.log('hmac-md5=' + md5.prototype.hex_hmac_md5('123456', '123456')) - }) - Text('hmac-sha1') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'hmac-sha1=' + sha1.prototype.hex_hmac_sha1('123456', '123456') }) - console.log('hmac-sha1=' + sha1.prototype.hex_hmac_sha1('123456', '123456')) - }) - Text('hmac-sha256') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'hmac-sha256=' + sha256.prototype.hex_hmac_sha256('123456', '123456') }) - console.log('hmac-sha256=' + sha256.prototype.hex_hmac_sha256('123456', '123456')) - }) - Text('hmac-sha512') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: 'hmac-sha512=' + sha512.prototype.hex_hmac_sha512('123456', '123456') }) - console.log('hmac-sha512=' + sha512.prototype.hex_hmac_sha512('123456', '123456')) - }) - Text('hmac-ripemd160') - .fontSize(20) - .margin(20) - .fontWeight(FontWeight.Bold) - .onClick(() => { - prompt.showToast({ message: "hmac-ripemd160=" + ripemd160.prototype.hex_hmac_rmd160('123456', '123456') }) - console.log("hmac-ripemd160=" + ripemd160.prototype.hex_hmac_rmd160('123456', '123456')); - }) - - } - .width('100%') - .height('100%') - } -} \ No newline at end of file diff --git a/entry/src/main/ets/pages/index.ets b/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b21b898841888e0a15e61386eebbc6f76eee62cd --- /dev/null +++ b/entry/src/main/ets/pages/index.ets @@ -0,0 +1,561 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 prompt from '@system.prompt'; +import { md5 } from '@ohos/crypto/' +import { sha1 } from '@ohos/crypto/' +import { sha256 } from '@ohos/crypto/' +import { sha512 } from '@ohos/crypto/' +import { ripemd160 } from '@ohos/crypto/' +import { sha224 } from '@ohos/crypto/' +import { sha384 } from '@ohos/crypto/' +import { sha3 } from '@ohos/crypto/' +import { Latin1 } from '@ohos/crypto/' +import { Hex } from '@ohos/crypto/' +import { WordArray } from '@ohos/crypto/' +import { EvpKDF } from '@ohos/crypto/' +import { Utf8 } from '@ohos/crypto/' +import { Utf16 } from '@ohos/crypto/' +import { Utf16BE } from '@ohos/crypto/' +import { Utf16LE } from '@ohos/crypto/' +import { PBKDF2 } from '@ohos/crypto/' +import { AES, CBC, NoPadding, CipherParams, PKCS7 } from '@ohos/crypto/' +import { OpenSSL } from '@ohos/crypto/'; +import { HexFormatter } from '@ohos/crypto/'; +import { BlockCipher } from '@ohos/crypto/' +import { Base64, DES, TripleDES, RC4, RC4Drop, StreamCipher, ECB, Rabbit, Rabbit_Legacy } from '@ohos/crypto/' +import { Base64Url } from '@ohos/crypto/' + +@Entry +@Component +struct Index { + scroller: Scroller = new Scroller() + + build() { + Scroll(this.scroller) { + Column() { + Text('md5') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'md5=' + md5.prototype.hex_md5('123456') }) + console.log('md5=' + md5.prototype.hex_md5('123456')) + }) + Text('sha1') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'sha1=' + sha1.prototype.hex_sha1('123456') }) + console.log('sha1=' + sha1.prototype.hex_sha1('123456')) + }) + Text('sha256') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'sha256=' + sha256.prototype.hex_sha256('123456') }) + console.log('sha256=' + sha256.prototype.hex_sha256('123456')) + }) + Text('sha224') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "sha224=" + sha224.prototype.hex_sha224('123456') }) + console.log("sha224=" + sha224.prototype.hex_sha224('123456')); + }) + Text('sha512') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'sha512=' + sha512.prototype.hex_sha512('123456') }) + console.log('sha512=' + sha512.prototype.hex_sha512('123456')) + }) + Text('sha384') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "sha384=" + sha384.prototype.hex_sha384('123456') }) + console.log("sha384=" + sha384.prototype.hex_sha384('123456')); + }) + Text('sha3') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "sha3=" + sha3.prototype.hex_sha3('123456', 512) }) + console.log("sha3=" + sha3.prototype.hex_sha3('123456', 512)); + }) + Text('ripemd160') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "ripemd160=" + ripemd160.prototype.hex_rmd160('123456') }) + console.log("ripemd160=" + ripemd160.prototype.hex_rmd160('123456')); + }) + Text('hmac-md5') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'hmac-md5=' + md5.prototype.hex_hmac_md5('123456', '123456') }) + console.log('hmac-md5=' + md5.prototype.hex_hmac_md5('123456', '123456')) + }) + Text('hmac-sha1') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'hmac-sha1=' + sha1.prototype.hex_hmac_sha1('123456', '123456') }) + console.log('hmac-sha1=' + sha1.prototype.hex_hmac_sha1('123456', '123456')) + }) + Text('hmac-sha256') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'hmac-sha256=' + sha256.prototype.hex_hmac_sha256('123456', '123456') }) + console.log('hmac-sha256=' + sha256.prototype.hex_hmac_sha256('123456', '123456')) + }) + Text('hmac-sha224') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "hmac-sha224=" + sha224.prototype.hex_hmac_sha224('123456', '123456') }) + console.log("hmac-sha224=" + sha224.prototype.hex_hmac_sha224('123456', '123456')); + }) + Text('hmac-sha512') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: 'hmac-sha512=' + sha512.prototype.hex_hmac_sha512('123456', '123456') }) + console.log('hmac-sha512=' + sha512.prototype.hex_hmac_sha512('123456', '123456')) + }) + Text('hmac-sha384') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "hmac-sha384=" + sha384.prototype.hex_hmac_sha384('123456', '123456') }) + console.log("hmac-sha384=" + sha384.prototype.hex_hmac_sha384('123456', '123456')); + }) + Text('hmac-sha3') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "hmac-sha3=" + sha3.prototype.hex_hmac_sha3('123456', '123456', 512) }) + console.log("hmac-sha3=" + sha3.prototype.hex_hmac_sha3('123456', '123456', 512)); + }) + Text('hmac-ripemd160') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + prompt.showToast({ message: "hmac-ripemd160=" + ripemd160.prototype.hex_hmac_rmd160('123456', '123456') }) + console.log("hmac-ripemd160=" + ripemd160.prototype.hex_hmac_rmd160('123456', '123456')); + }) + Text('enc-latin1-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Latin1.prototype.parse('Hello, World!') + console.log("enc-latin1-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-latin1-parse=" + wordArray.toString() }) + }) + Text('enc-latin1-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Latin1.prototype.parse('Hello, World!') + let result = Latin1.prototype.stringify(wordArray); + console.log("enc-latin1-stringify =" + result); + prompt.showToast({ message: "enc-latin1-stringify=" + result }) + }) + Text('enc-utf8-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf8.prototype.parse('0x999999') + console.log("enc-utf8-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-utf8-parse=" + wordArray.toString() }) + }) + Text('enc-utf8-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf8.prototype.parse('0x999999') + let result = Utf8.prototype.stringify(wordArray); + console.log("enc-utf8-stringify =" + result); + prompt.showToast({ message: "enc-utf8-stringify=" + result }) + }) + Text('enc-hex-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Hex.parse('0x999999') + console.log("enc-hex-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-hex-parse=" + wordArray.toString() }) + }) + Text('enc-hex-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Hex.parse('0x999999') + let result = Hex.stringify(wordArray); + console.log("enc-hex-stringify =" + result); + prompt.showToast({ message: "enc-hex-stringify=" + result }) + }) + Text('enc-utf16-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16.prototype.parse('Hello, World!') + console.log("enc-utf16-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-utf16-parse=" + wordArray.toString() }) + }) + Text('enc-utf16-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16.prototype.parse('Hello, World!') + let result = Utf16.prototype.stringify(wordArray); + console.log("enc-utf16-stringify =" + result); + prompt.showToast({ message: "enc-utf16-stringify=" + result }) + }) + Text('enc-utf16be-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16BE.prototype.parse('Hello, World!') + console.log("enc-utf16be-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-utf16be-parse=" + wordArray.toString() }) + }) + Text('enc-utf16be-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16BE.prototype.parse('Hello, World!') + let result = Utf16BE.prototype.stringify(wordArray); + console.log("enc-utf16be-stringify =" + result); + prompt.showToast({ message: "enc-utf16be-stringify=" + result }) + }) + Text('enc-utf16le-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16LE.prototype.parse('Hello, World!') + console.log("enc-utf16le-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-utf16le-parse=" + wordArray.toString() }) + }) + Text('enc-utf16le-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Utf16LE.prototype.parse('Hello, World!') + let result = Utf16LE.prototype.stringify(wordArray); + console.log("enc-utf16le-stringify =" + result); + prompt.showToast({ message: "enc-utf16le-stringify=" + result }) + }) + + Text('lib-WordArray-random') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let random: WordArray = WordArray.random(8) + prompt.showToast({ message: "WordArray-random=" + random.toString() }) + console.log("WordArray-random=" + random.toString()); + }) + Text('lib-WordArray-create') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let random: WordArray = WordArray.create() + prompt.showToast({ message: "WordArray-create=" + JSON.stringify(random) }) + console.log("WordArray-create=" + JSON.stringify(random)); + }) + Text('evpkdf-compute') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let kdf: EvpKDF = EvpKDF.create({ keySize: 128 / 32, iterations: 1 }) + let result = kdf.compute('560f1e45b', '1234',).toString() + prompt.showToast({ message: "evpkdf-compute=" + result }) + console.log("evpkdf-compute=" + result); + }) + Text('pbkdf2-compute') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let kdf: PBKDF2 = PBKDF2.create({ keySize: 128 / 32, iterations: 1 }) + let result = kdf.compute('560f1e45bf60b893', '1234',).toString() + prompt.showToast({ message: "pbkdf2-compute=" + result }) + console.log("pbkdf2-compute=" + result); + }) + Text('AES encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var aes = BlockCipher._createHelper(AES); + var value = "test00011321321321312312321" + const iv = Hex.parse('101112131415161718191a1b1c1d1e1f'); + const key = Hex.parse('000102030405060708090a0b0c0d0e0f'); + var ciphertext = aes.encrypt(value, key,{mode:CBC,padding:PKCS7,iv:iv}).toString(); + console.log("AES encrypt = " + ciphertext); + prompt.showToast({ message: 'AES encrypt =' + ciphertext }) + }) + Text('AES decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var aes = BlockCipher._createHelper(AES); + const iv = Hex.parse('101112131415161718191a1b1c1d1e1f'); + const key = Hex.parse('000102030405060708090a0b0c0d0e0f'); + var msg = aes.decrypt("dxzV163oPuT1U/2786nFDHP4dcg8W2Kj4GRgkzAwv1s=", key,{mode:CBC,padding:PKCS7,iv:iv}).toString(Utf8.prototype); + console.log("AES encrypt = " + msg); + prompt.showToast({ message: 'AES decrypt =' + msg }) + }) + Text('OpenSSL-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let ciphertext: WordArray = WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]); + let salt: WordArray = WordArray.create([0x01234567, 0x89abcdef]); + let openSSLStr: string = OpenSSL.stringify(CipherParams.create({ ciphertext: ciphertext, salt: salt })); + console.log("OpenSSL-stringify = " + openSSLStr); + prompt.showToast({ message: 'OpenSSL-stringify=' + openSSLStr }) + }) + Text('OpenSSL-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let ciphertext: WordArray = WordArray.create([0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f]); + let salt: WordArray = WordArray.create([0x01234567, 0x89abcdef]); + let openSSLStr: string = OpenSSL.stringify(CipherParams.create({ ciphertext: ciphertext, salt: salt })); + let cipherParams = OpenSSL.parse(openSSLStr); + console.log("OpenSSL-parse = " + cipherParams.ciphertext.toString()); + prompt.showToast({ message: 'OpenSSL-parse=' + cipherParams.ciphertext.toString() }) + }) + Text('format-hex-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let ciphertext: WordArray = WordArray.create([0x12345678]); + let hexStr: string = HexFormatter.stringify(CipherParams.create({ ciphertext: ciphertext })); + console.log("format-hex-stringify = " + hexStr); + prompt.showToast({ message: 'format-hex-stringify=' + hexStr }) + }) + Text('format-hex-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let hexxStr = HexFormatter.parse('0x12345678').toString(HexFormatter) + console.log("format-hex-parse = " + hexxStr); + prompt.showToast({ message: 'format-hex-parse=' + hexxStr }) + }) + Text('enc-base64-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Base64.parse('SGVsbG8sIFdvcmxkIQ==') + console.log("enc-base64-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-base64-parse=" + wordArray.toString() }) + }) + Text('enc-base64-stringify') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + let wordArray = Base64.parse('SGVsbG8sIFdvcmxkIQ==') + let result = Base64.stringify(wordArray); + console.log("enc-base64-stringify =" + result); + prompt.showToast({ message: "enc-base64-stringify=" + result }) + }) + Text('enc-base64url-parse') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var key = "u-rXsMB_aegAnzC_CJt27plLGNqOfR2EHI5o2ro1NO"; + let wordArray = Base64Url.parse(key) + console.log("enc-base64url-parse =" + wordArray.toString()); + prompt.showToast({ message: "enc-base64url-parse=" + wordArray.toString() }) + }) + Text('DES encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var des = BlockCipher._createHelper(DES); + let value = des.encrypt('hello', 'secret key 123').toString(); + console.log("DES encrypt = " + value); + prompt.showToast({ message: 'DES encrypt=' + value }) + }) + + Text('DES decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var des = BlockCipher._createHelper(DES); + let value = des.decrypt(des.encrypt('hello', 'secret key 123').toString(), 'secret key 123').toString(Utf8.prototype) + console.log("DES decrypt = " + value); + prompt.showToast({ message: 'DES decrypt=' + value }) + }) + + Text('Triple DES encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var tripleDES = BlockCipher._createHelper(TripleDES); + let value = tripleDES.encrypt('hello world', 'secret key 1234').toString(); + console.log("TripleDES encrypt= " + value); + prompt.showToast({ message: 'TripleDES encrypt=' + value }) + }) + + Text('Triple DES decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var tripleDES = BlockCipher._createHelper(TripleDES); + let value = tripleDES.decrypt(tripleDES.encrypt('hello world', 'secret key 1234').toString(), 'secret key 1234').toString(Utf8.prototype) + console.log("TripleDES decrypt = " + value); + prompt.showToast({ message: 'TripleDES decrypt=' + value }) + }) + + Text('RC4 encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rc4 = StreamCipher._createHelper(RC4); + let value = rc4.encrypt('hello world!', 'secret key 12345').toString(); + console.log("RC4 encrypt= " + value); + prompt.showToast({ message: 'RC4 encrypt=' + value }) + }) + + Text('RC4 decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rc4 = StreamCipher._createHelper(RC4); + let value = rc4.decrypt(rc4.encrypt('hello world!', 'secret key 12345').toString(), 'secret key 12345').toString(Utf8.prototype) + console.log("RC4 decrypt= " + value); + prompt.showToast({ message: 'RC4 decrypt=' + value }) + }) + + Text('RC4Drop encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rc4Drop = StreamCipher._createHelper(RC4Drop); + let value = rc4Drop.encrypt('hello world!!', 'secret key 123456', { drop: 2 }).toString(); + console.log("RC4Drop encrypt = " + value); + prompt.showToast({ message: 'RC4Drop encrypt=' + value }) + }) + + Text('RC4Drop decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rc4Drop = StreamCipher._createHelper(RC4Drop); + let value = rc4Drop.decrypt(rc4Drop.encrypt('hello world!!', 'secret key 123456', { drop: 2 }).toString(), 'secret key 123456', { drop: 2 }).toString(Utf8.prototype) + console.log("RC4Drop decrypt = " + value); + prompt.showToast({ message: 'RC4Drop decrypt=' + value }) + }) + Text('Rabbit encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rabbit = StreamCipher._createHelper(Rabbit); + let value = rabbit.encrypt('hello', 'secret key 12345').ciphertext.toString() + console.log("Rabbit encrypt= " + value); + prompt.showToast({ message: 'Rabbit encrypt= ' + value }) + }) + Text('Rabbit decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rabbit = StreamCipher._createHelper(Rabbit); + let value = rabbit.decrypt(rabbit.encrypt('hello', 'secret key 12345'),'secret key 12345').toString(Utf8.prototype) + console.log("Rabbit decrypt= " + value); + prompt.showToast({ message: 'Rabbit decrypt= ' + value }) + }) + Text('Rabbit-Legacy encrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rabbit = StreamCipher._createHelper(Rabbit_Legacy); + let value = rabbit.encrypt('hello', 'secret key 12345').ciphertext.toString() + console.log("Rabbit-Legacy encrypt= " + value); + prompt.showToast({ message: 'Rabbit-Legacy encrypt= ' + value }) + }) + Text('Rabbit-Legacy decrypt') + .fontSize(20) + .margin(20) + .fontWeight(FontWeight.Bold) + .onClick(() => { + var rabbit = StreamCipher._createHelper(Rabbit_Legacy); + let value = rabbit.decrypt(rabbit.encrypt('hello', 'secret key 12345'),'secret key 12345').toString(Utf8.prototype) + console.log("Rabbit-Legacy decrypt= " + value); + prompt.showToast({ message: 'Rabbit-Legacy decrypt= ' + value }) + }) + } + .width('100%') + .padding({ bottom: 180 }) + }.height('100%') + .scrollable(ScrollDirection.Vertical) + .scrollBarWidth(0) + .backgroundColor(Color.White) + } +} \ No newline at end of file diff --git a/entry/src/main/module.json5 b/entry/src/main/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..799679bded14b4ff071228e7d1a0bbeb19bc1975 --- /dev/null +++ b/entry/src/main/module.json5 @@ -0,0 +1,38 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/entry/src/main/resources/base/element/color.json b/entry/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/entry/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/base/profile/main_pages.json b/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/entry/src/ohosTest/config.json b/entry/src/ohosTest/config.json deleted file mode 100644 index 143c430d6d3a35bf1bfa4afb5ae2faf27039c7d0..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/config.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "app": { - "bundleName": "cn.openharmony.crypto-js", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.entry_test", - "name": ".entry_test", - "mainAbility": ".TestAbility", - "srcPath": "", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry_test", - "moduleType": "feature", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "orientation": "unspecified", - "visible": true, - "srcPath": "TestAbility", - "name": ".TestAbility", - "srcLanguage": "ets", - "icon": "$media:icon", - "description": "$string:description_TestAbility", - "formsEnabled": false, - "label": "$string:entry_TestAbility", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "mode": { - "syntax": "ets", - "type": "pageAbility" - }, - "pages": [ - "pages/index" - ], - "name": ".TestAbility", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } -} diff --git a/entry/src/ohosTest/ets/Application/AbilityStage.ts b/entry/src/ohosTest/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..522b19122ae4d4eba82630cc3251e226e6d9e6b7 --- /dev/null +++ b/entry/src/ohosTest/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class TestAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] TestAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/TestAbility/TestAbility.ts b/entry/src/ohosTest/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..92e2fb995bd7f2f42693d699aeb193d1d19c35d1 --- /dev/null +++ b/entry/src/ohosTest/ets/TestAbility/TestAbility.ts @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 Ability from '@ohos.application.Ability' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default class TestAbility extends Ability { + onCreate(want, launchParam) { + console.log('TestAbility onCreate') + var abilityDelegator: any + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments: any + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + } + + onDestroy() { + console.log('TestAbility onDestroy') + } + + onWindowStageCreate(windowStage) { + console.log('TestAbility onWindowStageCreate') + windowStage.loadContent("TestAbility/pages/index", (err, data) => { + if (err.code) { + console.error('Failed to load the content. Cause:' + JSON.stringify(err)); + return; + } + console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data)) + }); + + globalThis.abilityContext = this.context; + } + + onWindowStageDestroy() { + console.log('TestAbility onWindowStageDestroy') + } + + onForeground() { + console.log('TestAbility onForeground') + } + + onBackground() { + console.log('TestAbility onBackground') + } +}; \ No newline at end of file diff --git a/entry/src/ohosTest/ets/TestAbility/pages/index.ets b/entry/src/ohosTest/ets/TestAbility/pages/index.ets index 090ffcf246450c0ecc08a4f0008e482b4b69f61a..63cd57da862e463b639897b342c50ec1aada227d 100644 --- a/entry/src/ohosTest/ets/TestAbility/pages/index.ets +++ b/entry/src/ohosTest/ets/TestAbility/pages/index.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import router from '@system.router'; +import router from '@ohos.router'; @Entry @Component diff --git a/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts b/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..5da84c75f3a9ee08d250261511d4fbb92f0c489f --- /dev/null +++ b/entry/src/ohosTest/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the MIT License, (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://opensource.org/licenses/MIT + * + * 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 TestRunner from '@ohos.application.testRunner' +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s it', + '-s level', '-s testType', '-s size', '-s timeout', + '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams = `${targetParams} ${key} ${parameters[key]}` + } + } + return targetParams.trim() +} + +async function onAbilityCreateCallback() { + console.log("onAbilityCreateCallback"); +} + +async function addAbilityMonitorCallback(err: any) { + console.info("addAbilityMonitorCallback : " + JSON.stringify(err)) +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + console.info("OpenHarmonyTestRunner OnPrepare ") + } + + async onRun() { + console.log('OpenHarmonyTestRunner onRun run') + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + d.stdResult); + console.info('executeShellCommand : data : ' + d.exitCode); + }) + console.info('OpenHarmonyTestRunner onRun end') + } +}; \ No newline at end of file diff --git a/entry/src/ohosTest/ets/module.json5.ftl b/entry/src/ohosTest/ets/module.json5.ftl new file mode 100644 index 0000000000000000000000000000000000000000..73bc4cf36eef25035357e0c4412f3c94dd721682 --- /dev/null +++ b/entry/src/ohosTest/ets/module.json5.ftl @@ -0,0 +1,34 @@ +{ + "module": { + "name": "${moduleName}_test", + "type": "feature", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [${deviceTypes ?replace("[","")?replace("]","")}], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/entry/src/ohosTest/ets/test/Ability.test.ets b/entry/src/ohosTest/ets/test/Ability.test.ets index afe6a088bec5eebf8c3fad190d82bac661a3c4b7..d185b61af02e7a614ecd0f02ba1f0ee02009ea39 100644 --- a/entry/src/ohosTest/ets/test/Ability.test.ets +++ b/entry/src/ohosTest/ets/test/Ability.test.ets @@ -13,7 +13,7 @@ * limitations under the License. */ -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'hypium/index' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' export default function abilityTest() { describe('ActsAbilityTest', function () { diff --git a/entry/src/ohosTest/module.json5 b/entry/src/ohosTest/module.json5 new file mode 100644 index 0000000000000000000000000000000000000000..4a9da7a210292a718bb07f79c82e4dc502e32e04 --- /dev/null +++ b/entry/src/ohosTest/module.json5 @@ -0,0 +1,38 @@ +{ + "module": { + "name": "entry_test", + "type": "feature", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:entry_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "TestAbility", + "srcEntrance": "./ets/TestAbility/TestAbility.ts", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:white", + "visible": true, + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/entry/src/ohosTest/resources/base/element/color.json b/entry/src/ohosTest/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..1bbc9aa9617e97c45440e1d3d66afc1154837012 --- /dev/null +++ b/entry/src/ohosTest/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "white", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/entry/src/ohosTest/resources/base/element/string.json b/entry/src/ohosTest/resources/base/element/string.json index a0901cfced5abc1cb836b55896884b769adc7175..36d4230c53e9f5a07ae343ad8dc9808341975e3b 100644 --- a/entry/src/ohosTest/resources/base/element/string.json +++ b/entry/src/ohosTest/resources/base/element/string.json @@ -1,12 +1,16 @@ { "string": [ { - "name": "description_TestAbility", - "value": "eTS_Empty Ability" + "name": "entry_test_desc", + "value": "test ability description" }, { - "name": "entry_TestAbility", - "value": "entry_TestAbility" + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" } ] } \ No newline at end of file diff --git a/entry/src/ohosTest/resources/base/profile/test_pages.json b/entry/src/ohosTest/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..fcef82b4dfc18e28106ff9ecd1c8b48ec74d18a4 --- /dev/null +++ b/entry/src/ohosTest/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/index" + ] +} diff --git a/hvigorfile.js b/hvigorfile.js index cff9f0dfcf8cb00cca34e7f50d61380cf5496868..5f2735e3deeaf655828407544bbed9365c258278 100644 --- a/hvigorfile.js +++ b/hvigorfile.js @@ -1,2 +1,2 @@ // Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently. -module.exports = require('@ohos/hvigor-ohos-plugin').legacyAppTasks \ No newline at end of file +module.exports = require('@ohos/hvigor-ohos-plugin').appTasks \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 7256fc04c478e50369f5d95e011b8988a650dbfb..531f7968730c90bbad6a5fea3ba44ee24f0782a8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,23 @@ { - "name": "ohos_app_crypto", + "name": "ohos_app_crypto-js", "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { + "@ohos/hos-sdkmanager-common": { + "version": "1.0.2", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hos-sdkmanager-common/-/@ohos/hos-sdkmanager-common-1.0.2.tgz", + "integrity": "sha512-nai6RzsFd5tx1o5OwHxqaw+s0dTUjsdrXrwUi6b73EtHxTX6928C0xyEvd9TZ3dt3lSk2TPdSutUZWlDiW1s8A==", + "requires": { + "@ohos/sdkmanager-common": "^1.1.6" + } + }, "@ohos/hvigor": { - "version": "1.0.6", - "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor/-/@ohos/hvigor-1.0.6.tgz", - "integrity": "sha512-jjp7vpvUOMW1Nf7TdyhOtonwWHoSyBJLUiZTQqIx/GJV4UJyIqsiURUOqFwncQ4L7PDdeHuWly4uEelknYeWhg==", + "version": "1.1.3", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor/-/@ohos/hvigor-1.1.3.tgz", + "integrity": "sha512-ACVD5TE+cduiVO2BVP5+KI7BDIp9eWIZp4cxgtBR2NvIZw+/eF/e9tggf56b2WKXFOW+J/ZyN2SVlkbA6LlPhQ==", "requires": { - "@ohos/hvigor-base": "1.0.6", + "@ohos/hvigor-base": "1.1.3", "interpret": "1.4.0", "liftoff": "4.0.0", "mute-stdout": "1.0.0", @@ -19,25 +27,28 @@ } }, "@ohos/hvigor-base": { - "version": "1.0.6", - "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-base/-/@ohos/hvigor-base-1.0.6.tgz", - "integrity": "sha512-cRDnWICTxmpNiFb9clIioqP5Oik1seLCICztXVhZqultrHuxwTheCRUZrHwlpyWdkSB2Al+FFBqmSwzIgZX4IQ==", + "version": "1.1.3", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-base/-/@ohos/hvigor-base-1.1.3.tgz", + "integrity": "sha512-ZD0T1l9s9jeJ3KopehURy8rhF1E8gZ5XgtayYUVJK087p87J2qk9Zjo782oM1xZi7BrLzpNWz+w3yhwxELV5KA==", "requires": { "json5": "2.2.0", "log4js": "6.4.1", - "undertaker": "1.2.1" + "once": "1.4.0", + "pretty-hrtime": "1.0.0" } }, "@ohos/hvigor-ohos-plugin": { - "version": "1.0.6", - "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-ohos-plugin/-/@ohos/hvigor-ohos-plugin-1.0.6.tgz", - "integrity": "sha512-MAAi8uJxMzODUoSSNfBr+fU4HQ20dfQtkje9I+X4asc7qY2kAplW/q9f5XS8IOvv8zhC8OcSgsAXOAJuLMstOQ==", + "version": "1.1.3", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hvigor-ohos-plugin/-/@ohos/hvigor-ohos-plugin-1.1.3.tgz", + "integrity": "sha512-Ft2VCBnvoJoeVjsYsNMNJpNcEOsbPSSZ9LlyWXXRbGieC5x8Pjgv6nyPfC/x+Bb9d8Yum24n4fIRRE6at0z5OA==", "requires": { - "@ohos/hvigor-base": "1.0.6", - "@ohos/sdkmanager-common": "1.1.3", + "@ohos/hos-sdkmanager-common": "1.0.2", + "@ohos/hvigor-base": "1.1.3", + "@ohos/sdkmanager-common": "1.1.6", + "adm-zip": "0.5.9", "ajv": "8.10.0", - "archiver": "5.3.0", "execa": "5.1.1", + "fast-xml-parser": "4.0.3", "fs-extra": "10.0.0", "glob": "7.2.0", "iconv-lite": "0.6.3", @@ -49,7 +60,7 @@ "dependencies": { "fs-extra": { "version": "10.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/fs-extra/-/fs-extra-10.0.0.tgz", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz", "integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==", "requires": { "graceful-fs": "^4.2.0", @@ -59,19 +70,29 @@ }, "pretty-hrtime": { "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", - "integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=" + "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", + "integrity": "sha512-66hKPCr+72mlfiSjlEB1+45IjXSqvVAIy6mocupoww4tBFE9R9IhwwUGoI4G++Tc9Aq+2rxOt0RFU6gPcrte0A==" } } }, + "@ohos/hypium": { + "version": "1.0.0", + "resolved": "https://repo.harmonyos.com/npm/@ohos/hypium/-/@ohos/hypium-1.0.0.tgz", + "integrity": "sha512-NhL78mNNQXhZPTt+wfRktVJldXQ76l1GkS3N/KiNSLOFY1OC/gWeO22gp9uPmYntwLVOJm5h+ei2fe51ofyHWw==" + }, "@ohos/sdkmanager-common": { - "version": "1.1.3", - "resolved": "https://repo.harmonyos.com/npm/@ohos/sdkmanager-common/-/@ohos/sdkmanager-common-1.1.3.tgz", - "integrity": "sha512-d2uhVauDDJZIUvyyaWWoavG4N/jLyfF5IH5kEXKV6R8HNf3606H1zDQzA+UZtOfwwJFXhD9djRjnVFNB8xc7aw==" + "version": "1.1.6", + "resolved": "https://repo.harmonyos.com/npm/@ohos/sdkmanager-common/-/@ohos/sdkmanager-common-1.1.6.tgz", + "integrity": "sha512-9f3cNMQYibL6nVvNtFYcCOYojTi1aYm/WcIU3IswY+QcxveDGLich7S4OP3N78WBQuGCdbx4zU/CyfqQIz71sw==" + }, + "adm-zip": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.9.tgz", + "integrity": "sha512-s+3fXLkeeLjZ2kLjCBwQufpI5fuN+kIGBxu6530nVQZGVol0d7Y/M88/xw9HGGUcJjKf8LutN3VPRUBq6N7Ajg==" }, "ajv": { "version": "8.10.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/ajv/-/ajv-8.10.0.tgz", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.10.0.tgz", "integrity": "sha512-bzqAEZOjkrUMl2afH8dknrq5KEk2SrwdBROR+vH1EKVQTqaUbJVPdc/gEdggTMM0Se+s+Ja4ju4TlNcStKl2Hw==", "requires": { "fast-deep-equal": "^3.1.1", @@ -82,167 +103,27 @@ }, "ansi-regex": { "version": "2.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" - }, - "archiver": { - "version": "5.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/archiver/-/archiver-5.3.0.tgz", - "integrity": "sha512-iUw+oDwK0fgNpvveEsdQ0Ase6IIKztBJU2U0E9MzszMfmVVUyv1QJhS2ITW9ZCqx8dktAxVAjWWkKehuZE8OPg==", - "requires": { - "archiver-utils": "^2.1.0", - "async": "^3.2.0", - "buffer-crc32": "^0.2.1", - "readable-stream": "^3.6.0", - "readdir-glob": "^1.0.0", - "tar-stream": "^2.2.0", - "zip-stream": "^4.1.0" - } - }, - "archiver-utils": { - "version": "2.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/archiver-utils/-/archiver-utils-2.1.0.tgz", - "integrity": "sha512-bEL/yUb/fNNiNTuUz979Z0Yg5L+LzLxGJz8x79lYmR54fmTIb6ob/hNQgkQnIUDWIFjZVQwl9Xs356I6BAMHfw==", - "requires": { - "glob": "^7.1.4", - "graceful-fs": "^4.2.0", - "lazystream": "^1.0.0", - "lodash.defaults": "^4.2.0", - "lodash.difference": "^4.5.0", - "lodash.flatten": "^4.4.0", - "lodash.isplainobject": "^4.0.6", - "lodash.union": "^4.6.0", - "normalize-path": "^3.0.0", - "readable-stream": "^2.0.0" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - } - } - }, - "arr-filter": { - "version": "1.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/arr-filter/-/arr-filter-1.1.2.tgz", - "integrity": "sha1-Q/3d0JHo7xGqTEXZzcGOLf8XEe4=", - "requires": { - "make-iterator": "^1.0.0" - } - }, - "arr-flatten": { - "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/arr-flatten/-/arr-flatten-1.1.0.tgz", - "integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==" - }, - "arr-map": { - "version": "2.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/arr-map/-/arr-map-2.0.2.tgz", - "integrity": "sha1-Onc0X/wc814qkYJWAfnljy4kysQ=", - "requires": { - "make-iterator": "^1.0.0" - } + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA==" }, "array-each": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/array-each/-/array-each-1.0.1.tgz", - "integrity": "sha1-p5SvDAWrF1KEbudTofIRoFugxE8=" - }, - "array-initial": { - "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/array-initial/-/array-initial-1.1.0.tgz", - "integrity": "sha1-L6dLJnOTccOUe9enrcc74zSz15U=", - "requires": { - "array-slice": "^1.0.0", - "is-number": "^4.0.0" - } - }, - "array-last": { - "version": "1.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/array-last/-/array-last-1.3.0.tgz", - "integrity": "sha512-eOCut5rXlI6aCOS7Z7kCplKRKyiFQ6dHFBem4PwlwKeNFk2/XxTrhRh5T9PyaEWGy/NHTZWbY+nsZlNFJu9rYg==", - "requires": { - "is-number": "^4.0.0" - } + "resolved": "https://registry.npmjs.org/array-each/-/array-each-1.0.1.tgz", + "integrity": "sha512-zHjL5SZa68hkKHBFBK6DJCTtr9sfTCPCaph/L7tMSLcTFgy+zX7E+6q5UArbtOtMBCtxdICpfTCspRse+ywyXA==" }, "array-slice": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/array-slice/-/array-slice-1.1.0.tgz", + "resolved": "https://registry.npmjs.org/array-slice/-/array-slice-1.1.0.tgz", "integrity": "sha512-B1qMD3RBP7O8o0H2KbrXDyB0IccejMF15+87Lvlor12ONPRHP6gTjXMNkt/d3ZuOGbAe66hFmaCfECI24Ufp6w==" }, - "async": { - "version": "3.2.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/async/-/async-3.2.3.tgz", - "integrity": "sha512-spZRyzKL5l5BZQrr/6m/SqFdBN0q3OCI0f9rjfBzCMBIP4p75P620rR3gTmaksNOhmzgdxcaxdNfMy6anrbM0g==" - }, - "async-done": { - "version": "1.3.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/async-done/-/async-done-1.3.2.tgz", - "integrity": "sha512-uYkTP8dw2og1tu1nmza1n1CMW0qb8gWWlwqMmLb7MhBVs4BXrFziT6HXUd+/RlRA/i4H9AkofYloUbs1fwMqlw==", - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.2", - "process-nextick-args": "^2.0.0", - "stream-exhaust": "^1.0.1" - } - }, - "async-settle": { - "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/async-settle/-/async-settle-1.0.0.tgz", - "integrity": "sha1-HQqRS7Aldb7IqPOnTlCA9yssDGs=", - "requires": { - "async-done": "^1.2.2" - } - }, - "bach": { - "version": "1.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/bach/-/bach-1.2.0.tgz", - "integrity": "sha1-Szzpa/JxNPeaG0FKUcFONMO9mIA=", - "requires": { - "arr-filter": "^1.1.1", - "arr-flatten": "^1.0.1", - "arr-map": "^2.0.0", - "array-each": "^1.0.0", - "array-initial": "^1.0.0", - "array-last": "^1.1.1", - "async-done": "^1.2.2", - "async-settle": "^1.0.0", - "now-and-later": "^2.0.0" - } - }, "balanced-match": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/balanced-match/-/balanced-match-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" }, - "base64-js": { - "version": "1.5.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" - }, - "bl": { - "version": "4.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "requires": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, "brace-expansion": { "version": "1.1.11", - "resolved": "https://repo.huaweicloud.com/repository/npm/brace-expansion/-/brace-expansion-1.1.11.tgz", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "requires": { "balanced-match": "^1.0.0", @@ -251,29 +132,15 @@ }, "braces": { "version": "3.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/braces/-/braces-3.0.2.tgz", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", "requires": { "fill-range": "^7.0.1" } }, - "buffer": { - "version": "5.7.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "requires": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, - "buffer-crc32": { - "version": "0.2.13", - "resolved": "https://repo.huaweicloud.com/repository/npm/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=" - }, "call-bind": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/call-bind/-/call-bind-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", "requires": { "function-bind": "^1.1.1", @@ -282,13 +149,13 @@ }, "camelcase": { "version": "3.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/camelcase/-/camelcase-3.0.0.tgz", - "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", + "integrity": "sha512-4nhGqUkc4BqbBBB4Q6zLuD7lzzrHYrjKGeYaEji/3tFR5VdJu9v+LilhGIVe8wxEJPPOeWo7eg8dwY13TZ1BNg==" }, "cliui": { "version": "3.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/cliui/-/cliui-3.2.0.tgz", - "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha512-0yayqDxWQbqk3ojkYqUKqaAQ6AfNKeKWRNA8kR0WXzAsdHpP4BIaOmMAG87JGuO6qcobyW4GjxHd9PmhEd+T9w==", "requires": { "string-width": "^1.0.1", "strip-ansi": "^3.0.1", @@ -297,61 +164,17 @@ }, "code-point-at": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" - }, - "collection-map": { - "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/collection-map/-/collection-map-1.0.0.tgz", - "integrity": "sha1-rqDwb40mx4DCt1SUOFVEsiVa8Yw=", - "requires": { - "arr-map": "^2.0.2", - "for-own": "^1.0.0", - "make-iterator": "^1.0.0" - } - }, - "compress-commons": { - "version": "4.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/compress-commons/-/compress-commons-4.1.1.tgz", - "integrity": "sha512-QLdDLCKNV2dtoTorqgxngQCMA+gWXkM/Nwu7FpeBhk/RdkzimqC3jueb/FDmaZeXh+uby1jkBqE3xArsLBE5wQ==", - "requires": { - "buffer-crc32": "^0.2.13", - "crc32-stream": "^4.0.2", - "normalize-path": "^3.0.0", - "readable-stream": "^3.6.0" - } + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha512-RpAVKQA5T63xEj6/giIbUEtZwJ4UFIc3ZtvEkiaUERylqe8xb5IvqcgOurZLahv93CLKfxcw5YI+DZcUBRyLXA==" }, "concat-map": { "version": "0.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, - "core-util-is": { - "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" - }, - "crc-32": { - "version": "1.2.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/crc-32/-/crc-32-1.2.1.tgz", - "integrity": "sha512-Dn/xm/1vFFgs3nfrpEVScHoIslO9NZRITWGz/1E/St6u4xw99vfZzVkW0OSnzx2h9egej9xwMCEut6sqwokM/w==", - "requires": { - "exit-on-epipe": "~1.0.1", - "printj": "~1.3.1" - } - }, - "crc32-stream": { - "version": "4.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/crc32-stream/-/crc32-stream-4.0.2.tgz", - "integrity": "sha512-DxFZ/Hk473b/muq1VJ///PMNLj0ZMnzye9thBpmjpJKCc5eMgB95aK8zCGrGfQ90cWo561Te6HK9D+j4KPdM6w==", - "requires": { - "crc-32": "^1.2.0", - "readable-stream": "^3.4.0" - } + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, "cross-spawn": { "version": "7.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/cross-spawn/-/cross-spawn-7.0.3.tgz", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", "requires": { "path-key": "^3.1.0", @@ -361,7 +184,7 @@ "dependencies": { "which": { "version": "2.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/which/-/which-2.0.2.tgz", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "requires": { "isexe": "^2.0.0" @@ -369,23 +192,14 @@ } } }, - "d": { - "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "requires": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" - } - }, "date-format": { - "version": "4.0.6", - "resolved": "https://repo.huaweicloud.com/repository/npm/date-format/-/date-format-4.0.6.tgz", - "integrity": "sha512-B9vvg5rHuQ8cbUXE/RMWMyX2YA5TecT3jKF5fLtGNlzPlU7zblSPmAm2OImDbWL+LDOQ6pUm+4LOFz+ywS41Zw==" + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.11.tgz", + "integrity": "sha512-VS20KRyorrbMCQmpdl2hg5KaOUsda1RbnsJg461FfrcyCUg+pkd0b40BSW4niQyTheww4DBXQnS7HwSrKkipLw==" }, "debug": { "version": "4.3.4", - "resolved": "https://repo.huaweicloud.com/repository/npm/debug/-/debug-4.3.4.tgz", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "requires": { "ms": "2.1.2" @@ -393,86 +207,34 @@ }, "decamelize": { "version": "1.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" - }, - "default-resolution": { - "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/default-resolution/-/default-resolution-2.0.0.tgz", - "integrity": "sha1-vLgrqnKtebQmp2cy8aga1t8m1oQ=" + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==" }, "define-properties": { - "version": "1.1.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", + "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", "requires": { - "object-keys": "^1.0.12" + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" } }, "detect-file": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/detect-file/-/detect-file-1.0.0.tgz", - "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=" - }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://repo.huaweicloud.com/repository/npm/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "requires": { - "once": "^1.4.0" - } + "resolved": "https://registry.npmjs.org/detect-file/-/detect-file-1.0.0.tgz", + "integrity": "sha512-DtCOLG98P007x7wiiOmfI0fi3eIKyWiLTGJ2MDnVi/E04lWGbf+JzrRHMm0rgIIZJGtHpKpbVgLWHrv8xXpc3Q==" }, "error-ex": { "version": "1.3.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/error-ex/-/error-ex-1.3.2.tgz", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", "requires": { "is-arrayish": "^0.2.1" } }, - "es5-ext": { - "version": "0.10.59", - "resolved": "https://repo.huaweicloud.com/repository/npm/es5-ext/-/es5-ext-0.10.59.tgz", - "integrity": "sha512-cOgyhW0tIJyQY1Kfw6Kr0viu9ZlUctVchRMZ7R0HiH3dxTSp5zJDLecwxUqPUrGKMsgBI1wd1FL+d9Jxfi4cLw==", - "requires": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "next-tick": "^1.1.0" - } - }, - "es6-iterator": { - "version": "2.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", - "requires": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, - "es6-symbol": { - "version": "3.1.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "requires": { - "d": "^1.0.1", - "ext": "^1.1.2" - } - }, - "es6-weak-map": { - "version": "2.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/es6-weak-map/-/es6-weak-map-2.0.3.tgz", - "integrity": "sha512-p5um32HOTO1kP+w7PRnB+5lQ43Z6muuMuIMffvDN8ZB4GcnjLBV6zGStpbASIMk4DCAvEaamhe2zhyCb/QXXsA==", - "requires": { - "d": "1", - "es5-ext": "^0.10.46", - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.1" - } - }, "execa": { "version": "5.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/execa/-/execa-5.1.1.tgz", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", "requires": { "cross-spawn": "^7.0.3", @@ -486,47 +248,35 @@ "strip-final-newline": "^2.0.0" } }, - "exit-on-epipe": { - "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz", - "integrity": "sha512-h2z5mrROTxce56S+pnvAV890uu7ls7f1kEvVGJbw1OlFH3/mlJ5bkXu0KRyW94v37zzHPiUd55iLn3DA7TjWpw==" - }, "expand-tilde": { "version": "2.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/expand-tilde/-/expand-tilde-2.0.2.tgz", - "integrity": "sha1-l+gBqgUt8CRU3kawK/YhZCzchQI=", + "resolved": "https://registry.npmjs.org/expand-tilde/-/expand-tilde-2.0.2.tgz", + "integrity": "sha512-A5EmesHW6rfnZ9ysHQjPdJRni0SRar0tjtG5MNtm9n5TUvsYU8oozprtRD4AqHxcZWWlVuAmQo2nWKfN9oyjTw==", "requires": { "homedir-polyfill": "^1.0.1" } }, - "ext": { - "version": "1.6.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/ext/-/ext-1.6.0.tgz", - "integrity": "sha512-sdBImtzkq2HpkdRLtlLWDa6w4DX22ijZLKx8BMPUuKe1c5lbN6xwQDQCxSfxBQnHZ13ls/FH0MQZx/q/gr6FQg==", - "requires": { - "type": "^2.5.0" - }, - "dependencies": { - "type": { - "version": "2.6.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/type/-/type-2.6.0.tgz", - "integrity": "sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==" - } - } - }, "extend": { "version": "3.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/extend/-/extend-3.0.2.tgz", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" }, "fast-deep-equal": { "version": "3.1.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "fast-xml-parser": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.0.3.tgz", + "integrity": "sha512-xhQbg3a/EYNHwK0cxIG1nZmVkHX/0tWihamn5pU4Mhd9KEVE2ga8ZJiqEUgB2sApElvAATOdMTLjgqIpvYDUkQ==", + "requires": { + "strnum": "^1.0.5" + } + }, "fill-range": { "version": "7.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/fill-range/-/fill-range-7.0.1.tgz", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", "requires": { "to-regex-range": "^5.0.1" @@ -534,8 +284,8 @@ }, "find-up": { "version": "1.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/find-up/-/find-up-1.1.2.tgz", - "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha512-jvElSjyuo4EMQGoTwo1uJU5pQMwTW5lS1x05zzfJuTIyLR3zwO27LYrxNg+dlvKpGOuGy/MzBdXh80g0ve5+HA==", "requires": { "path-exists": "^2.0.0", "pinkie-promise": "^2.0.0" @@ -543,7 +293,7 @@ }, "findup-sync": { "version": "5.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/findup-sync/-/findup-sync-5.0.0.tgz", + "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-5.0.0.tgz", "integrity": "sha512-MzwXju70AuyflbgeOhzvQWAvvQdo1XL0A9bVvlXsYcFEBM87WR4OakL4OfZq+QRmr+duJubio+UtNQCPsVESzQ==", "requires": { "detect-file": "^1.0.0", @@ -554,7 +304,7 @@ }, "fined": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/fined/-/fined-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/fined/-/fined-2.0.0.tgz", "integrity": "sha512-OFRzsL6ZMHz5s0JrsEr+TpdGNCtrVtnuG3x1yzGNiQHT0yaDnXAj8V/lWcpJVrnoDpcwXcASxAZYbuXda2Y82A==", "requires": { "expand-tilde": "^2.0.2", @@ -566,36 +316,31 @@ }, "flagged-respawn": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/flagged-respawn/-/flagged-respawn-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/flagged-respawn/-/flagged-respawn-2.0.0.tgz", "integrity": "sha512-Gq/a6YCi8zexmGHMuJwahTGzXlAZAOsbCVKduWXC6TlLCjjFRlExMJc4GC2NYPYZ0r/brw9P7CpRgQmlPVeOoA==" }, "flatted": { "version": "3.2.5", - "resolved": "https://repo.huaweicloud.com/repository/npm/flatted/-/flatted-3.2.5.tgz", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.5.tgz", "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==" }, "for-in": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/for-in/-/for-in-1.0.2.tgz", - "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=" + "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", + "integrity": "sha512-7EwmXrOjyL+ChxMhmG5lnW9MPt1aIeZEwKhQzoBUdTV0N3zuwWDZYVJatDvZ2OyzPUvdIAZDsCetk3coyMfcnQ==" }, "for-own": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/for-own/-/for-own-1.0.0.tgz", - "integrity": "sha1-xjMy9BXO3EsE2/5wz4NklMU8tEs=", + "resolved": "https://registry.npmjs.org/for-own/-/for-own-1.0.0.tgz", + "integrity": "sha512-0OABksIGrxKK8K4kynWkQ7y1zounQxP+CWnyclVwj81KW3vlLlGUx57DKGcP/LH216GzqnstnPocF16Nxs0Ycg==", "requires": { "for-in": "^1.0.1" } }, - "fs-constants": { - "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/fs-constants/-/fs-constants-1.0.0.tgz", - "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" - }, "fs-extra": { - "version": "10.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/fs-extra/-/fs-extra-10.0.1.tgz", - "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", "requires": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", @@ -604,22 +349,22 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" }, "function-bind": { "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/function-bind/-/function-bind-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, "get-caller-file": { "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/get-caller-file/-/get-caller-file-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" }, "get-intrinsic": { "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/get-intrinsic/-/get-intrinsic-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", "requires": { "function-bind": "^1.1.1", @@ -629,12 +374,12 @@ }, "get-stream": { "version": "6.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/get-stream/-/get-stream-6.0.1.tgz", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==" }, "glob": { "version": "7.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/glob/-/glob-7.2.0.tgz", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", "requires": { "fs.realpath": "^1.0.0", @@ -647,7 +392,7 @@ }, "global-modules": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/global-modules/-/global-modules-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/global-modules/-/global-modules-1.0.0.tgz", "integrity": "sha512-sKzpEkf11GpOFuw0Zzjzmt4B4UZwjOcG757PPvrfhxcLFbq0wpsgpOqxpxtxFiCG4DtG93M6XRVbF2oGdev7bg==", "requires": { "global-prefix": "^1.0.1", @@ -657,8 +402,8 @@ }, "global-prefix": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/global-prefix/-/global-prefix-1.0.2.tgz", - "integrity": "sha1-2/dDxsFJklk8ZVVoy2btMsASLr4=", + "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-1.0.2.tgz", + "integrity": "sha512-5lsx1NUDHtSjfg0eHlmYvZKv8/nVqX4ckFbM+FrGcQ+04KWcWFo9P5MxPZYSzUvyzmdTbI7Eix8Q4IbELDqzKg==", "requires": { "expand-tilde": "^2.0.2", "homedir-polyfill": "^1.0.1", @@ -669,25 +414,33 @@ }, "graceful-fs": { "version": "4.2.10", - "resolved": "https://repo.huaweicloud.com/repository/npm/graceful-fs/-/graceful-fs-4.2.10.tgz", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==" }, "has": { "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/has/-/has-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", "requires": { "function-bind": "^1.1.1" } }, + "has-property-descriptors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", + "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "requires": { + "get-intrinsic": "^1.1.1" + } + }, "has-symbols": { "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/has-symbols/-/has-symbols-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" }, "homedir-polyfill": { "version": "1.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.3.tgz", "integrity": "sha512-eSmmWE5bZTK2Nou4g0AI3zZ9rswp7GRKoKXS1BLUkvPviOqs4YTN1djQIqrXy9k5gEtdLPy86JjRwsNM9tnDcA==", "requires": { "parse-passwd": "^1.0.0" @@ -695,36 +448,26 @@ }, "hosted-git-info": { "version": "2.8.9", - "resolved": "https://repo.huaweicloud.com/repository/npm/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==" }, "human-signals": { "version": "2.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/human-signals/-/human-signals-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==" }, - "hypium": { - "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/hypium/-/hypium-1.0.0.tgz", - "integrity": "sha512-nl+RQVv2AU/5FvFRhsXyWO5wh+2huhdqRZ3bszBWZzW+kpNI3AT4ydvVRYIfaQbYwV4UlX/rSc7BtFjLAezhow==" - }, "iconv-lite": { "version": "0.6.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/iconv-lite/-/iconv-lite-0.6.3.tgz", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "requires": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, - "ieee754": { - "version": "1.2.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==" - }, "inflight": { "version": "1.0.6", - "resolved": "https://repo.huaweicloud.com/repository/npm/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", "requires": { "once": "^1.3.0", "wrappy": "1" @@ -732,27 +475,27 @@ }, "inherits": { "version": "2.0.4", - "resolved": "https://repo.huaweicloud.com/repository/npm/inherits/-/inherits-2.0.4.tgz", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ini": { "version": "1.3.8", - "resolved": "https://repo.huaweicloud.com/repository/npm/ini/-/ini-1.3.8.tgz", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, "interpret": { "version": "1.4.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/interpret/-/interpret-1.4.0.tgz", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==" }, "invert-kv": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/invert-kv/-/invert-kv-1.0.0.tgz", - "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha512-xgs2NH9AE66ucSq4cNG1nhSFghr5l6tdL15Pk+jl46bmmBapgoaY/AacXyaDznAqmGL99TiLSQgO/XazFSKYeQ==" }, "is-absolute": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-absolute/-/is-absolute-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-1.0.0.tgz", "integrity": "sha512-dOWoqflvcydARa360Gvv18DZ/gRuHKi2NU/wU5X1ZFzdYfH29nkiNZsF3mp4OJ3H4yo9Mx8A/uAGNzpzPN3yBA==", "requires": { "is-relative": "^1.0.0", @@ -761,51 +504,51 @@ }, "is-arrayish": { "version": "0.2.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==" }, "is-core-module": { - "version": "2.8.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-core-module/-/is-core-module-2.8.1.tgz", - "integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.9.0.tgz", + "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", "requires": { "has": "^1.0.3" } }, "is-extglob": { "version": "2.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=" + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==" }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha512-1pqUqRjkhPJ9miNq9SwMfdvi6lBJcd6eFxvfaivQhaH3SgisfiuudvFntdKOmxuee/77l+FPjKrQjWvmPjWrRw==", "requires": { "number-is-nan": "^1.0.0" } }, "is-glob": { "version": "4.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-glob/-/is-glob-4.0.3.tgz", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "requires": { "is-extglob": "^2.1.1" } }, "is-number": { - "version": "4.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-4.0.0.tgz", - "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" }, "is-plain-object": { "version": "5.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-plain-object/-/is-plain-object-5.0.0.tgz", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==" }, "is-relative": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-relative/-/is-relative-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/is-relative/-/is-relative-1.0.0.tgz", "integrity": "sha512-Kw/ReK0iqwKeu0MITLFuj0jbPAmEiOsIwyIXvvbfa6QfmN9pkD1M+8pdk7Rl/dTKbH34/XBFMbgD4iMJhLQbGA==", "requires": { "is-unc-path": "^1.0.0" @@ -813,12 +556,12 @@ }, "is-stream": { "version": "2.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-stream/-/is-stream-2.0.1.tgz", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==" }, "is-unc-path": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-unc-path/-/is-unc-path-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/is-unc-path/-/is-unc-path-1.0.0.tgz", "integrity": "sha512-mrGpVd0fs7WWLfVsStvgF6iEJnbjDFZh9/emhRDcGWTduTfNHd9CHeUwH3gYIjdbwo4On6hunkztwOaAw0yllQ==", "requires": { "unc-path-regex": "^0.1.2" @@ -826,37 +569,32 @@ }, "is-utf8": { "version": "0.2.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-utf8/-/is-utf8-0.2.1.tgz", - "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=" + "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha512-rMYPYvCzsXywIsldgLaSoPlw5PfoB/ssr7hY4pLfcodrA5M/eArza1a9VmTiNIBNMjOGr1Ow9mTyU2o69U6U9Q==" }, "is-windows": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-windows/-/is-windows-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" }, - "isarray": { - "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" - }, "isexe": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=" + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, "isobject": { "version": "3.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=" + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==" }, "json-schema-traverse": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, "json5": { "version": "2.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/json5/-/json5-2.2.0.tgz", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.0.tgz", "integrity": "sha512-f+8cldu7X/y7RAJurMEJmdoKXGB/X550w2Nr3tTbezL6RwEE/iMcm+tZnXeoZtKuOq6ft8+CqzEkrIgx1fPoQA==", "requires": { "minimist": "^1.2.5" @@ -864,7 +602,7 @@ }, "jsonfile": { "version": "6.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/jsonfile/-/jsonfile-6.1.0.tgz", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "requires": { "graceful-fs": "^4.1.6", @@ -873,53 +611,20 @@ }, "kind-of": { "version": "6.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/kind-of/-/kind-of-6.0.3.tgz", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==" }, - "last-run": { - "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/last-run/-/last-run-1.1.1.tgz", - "integrity": "sha1-RblpQsF7HHnHchmCWbqUO+v4yls=", - "requires": { - "default-resolution": "^2.0.0", - "es6-weak-map": "^2.0.1" - } - }, - "lazystream": { - "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/lazystream/-/lazystream-1.0.1.tgz", - "integrity": "sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==", - "requires": { - "readable-stream": "^2.0.5" - }, - "dependencies": { - "readable-stream": { - "version": "2.3.7", - "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - } - } - }, "lcid": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/lcid/-/lcid-1.0.0.tgz", - "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha512-YiGkH6EnGrDGqLMITnGjXtGmNtjoXw9SVUzcaos8RBi7Ps0VBylkq+vOcY9QE5poLasPCR849ucFUkl0UzUyOw==", "requires": { "invert-kv": "^1.0.0" } }, "liftoff": { "version": "4.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/liftoff/-/liftoff-4.0.0.tgz", + "resolved": "https://registry.npmjs.org/liftoff/-/liftoff-4.0.0.tgz", "integrity": "sha512-rMGwYF8q7g2XhG2ulBmmJgWv25qBsqRbDn5gH0+wnuyeFt7QBJlHJmtg5qEdn4pN6WVAUMgXnIxytMFRX9c1aA==", "requires": { "extend": "^3.0.2", @@ -934,8 +639,8 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/load-json-file/-/load-json-file-1.1.0.tgz", - "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha512-cy7ZdNRXdablkXYNI049pthVeXFurRyb9+hA/dZzerZ0pGTx42z+y+ssxBaVV2l70t1muq5IdKhn4UtcoGUY9A==", "requires": { "graceful-fs": "^4.1.2", "parse-json": "^2.2.0", @@ -946,37 +651,12 @@ }, "lodash": { "version": "4.17.21", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash/-/lodash-4.17.21.tgz", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, - "lodash.defaults": { - "version": "4.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.defaults/-/lodash.defaults-4.2.0.tgz", - "integrity": "sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=" - }, - "lodash.difference": { - "version": "4.5.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.difference/-/lodash.difference-4.5.0.tgz", - "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=" - }, - "lodash.flatten": { - "version": "4.4.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.flatten/-/lodash.flatten-4.4.0.tgz", - "integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=" - }, - "lodash.isplainobject": { - "version": "4.0.6", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz", - "integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs=" - }, - "lodash.union": { - "version": "4.6.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/lodash.union/-/lodash.union-4.6.0.tgz", - "integrity": "sha1-SLtQiECfFvGCFmZkHETdGqrjzYg=" - }, "log4js": { "version": "6.4.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/log4js/-/log4js-6.4.1.tgz", + "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.4.1.tgz", "integrity": "sha512-iUiYnXqAmNKiIZ1XSAitQ4TmNs8CdZYTAWINARF3LjnsLN8tY5m0vRwd6uuWj/yNY0YHxeZodnbmxKFUOM2rMg==", "requires": { "date-format": "^4.0.3", @@ -988,7 +668,7 @@ }, "make-iterator": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/make-iterator/-/make-iterator-1.0.1.tgz", + "resolved": "https://registry.npmjs.org/make-iterator/-/make-iterator-1.0.1.tgz", "integrity": "sha512-pxiuXh0iVEq7VM7KMIhs5gxsfxCux2URptUQaXo4iZZJxBAzTPOLE2BumO5dbfVYq/hBJFBR/a1mFDmOx5AGmw==", "requires": { "kind-of": "^6.0.2" @@ -996,17 +676,17 @@ }, "map-cache": { "version": "0.2.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/map-cache/-/map-cache-0.2.2.tgz", - "integrity": "sha1-wyq9C9ZSXZsFFkW7TyasXcmKDb8=" + "resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz", + "integrity": "sha512-8y/eV9QQZCiyn1SprXSrCmqJN0yNRATe+PO8ztwqrvrbdRLA3eYJF0yaR0YayLWkMbsQSKWS9N2gPcGEc4UsZg==" }, "merge-stream": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/merge-stream/-/merge-stream-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==" }, "micromatch": { "version": "4.0.5", - "resolved": "https://repo.huaweicloud.com/repository/npm/micromatch/-/micromatch-4.0.5.tgz", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "requires": { "braces": "^3.0.2", @@ -1015,12 +695,12 @@ }, "mimic-fn": { "version": "2.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/mimic-fn/-/mimic-fn-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" }, "minimatch": { "version": "3.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/minimatch/-/minimatch-3.1.2.tgz", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "requires": { "brace-expansion": "^1.1.7" @@ -1028,27 +708,22 @@ }, "minimist": { "version": "1.2.6", - "resolved": "https://repo.huaweicloud.com/repository/npm/minimist/-/minimist-1.2.6.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.6.tgz", "integrity": "sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q==" }, "ms": { "version": "2.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/ms/-/ms-2.1.2.tgz", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mute-stdout": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/mute-stdout/-/mute-stdout-1.0.0.tgz", - "integrity": "sha1-WzLqB+tDyd7WEwQ0z5JvRrKn/U0=" - }, - "next-tick": { - "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==" + "resolved": "https://registry.npmjs.org/mute-stdout/-/mute-stdout-1.0.0.tgz", + "integrity": "sha512-MaSQenn0f9oxIjtCufclpV00MuYTiHaXPbdcfPIM+quMqoa8cXywjHHx4LhhIAZlXqPWMdcUpYviajfmHtHRJw==" }, "normalize-package-data": { "version": "2.5.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", "requires": { "hosted-git-info": "^2.1.4", @@ -1057,22 +732,9 @@ "validate-npm-package-license": "^3.0.1" } }, - "normalize-path": { - "version": "3.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" - }, - "now-and-later": { - "version": "2.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/now-and-later/-/now-and-later-2.0.1.tgz", - "integrity": "sha512-KGvQ0cB70AQfg107Xvs/Fbu+dGmZoTRJp2TaPwcwQm3/7PteUyN2BCgk8KBMPGBUXZdVwyWS8fDCGFygBm19UQ==", - "requires": { - "once": "^1.3.2" - } - }, "npm-run-path": { "version": "4.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/npm-run-path/-/npm-run-path-4.0.1.tgz", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", "requires": { "path-key": "^3.0.0" @@ -1080,17 +742,17 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha512-4jbtZXNAsfZbAHiiqjLPBiCl16dES1zI4Hpzzxw61Tk+loF+sBDBKx1ICKKKwIqQ7M0mFn1TmkN7euSncWgHiQ==" }, "object-keys": { "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/object-keys/-/object-keys-1.1.1.tgz", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" }, "object.assign": { "version": "4.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/object.assign/-/object.assign-4.1.2.tgz", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", "requires": { "call-bind": "^1.0.0", @@ -1101,8 +763,8 @@ }, "object.defaults": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/object.defaults/-/object.defaults-1.1.0.tgz", - "integrity": "sha1-On+GgzS0B96gbaFtiNXNKeQ1/s8=", + "resolved": "https://registry.npmjs.org/object.defaults/-/object.defaults-1.1.0.tgz", + "integrity": "sha512-c/K0mw/F11k4dEUBMW8naXUuBuhxRCfG7W+yFy8EcijU/rSmazOUd1XAEEe6bC0OuXY4HUKjTJv7xbxIMqdxrA==", "requires": { "array-each": "^1.0.1", "array-slice": "^1.0.0", @@ -1112,8 +774,8 @@ }, "object.map": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/object.map/-/object.map-1.0.1.tgz", - "integrity": "sha1-z4Plncj8wK1fQlDh94s7gb2AHTc=", + "resolved": "https://registry.npmjs.org/object.map/-/object.map-1.0.1.tgz", + "integrity": "sha512-3+mAJu2PLfnSVGHwIWubpOFLscJANBKuB/6A4CxBstc4aqwQY0FWcsppuy4jU5GSB95yES5JHSI+33AWuS4k6w==", "requires": { "for-own": "^1.0.0", "make-iterator": "^1.0.0" @@ -1121,32 +783,23 @@ }, "object.pick": { "version": "1.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/object.pick/-/object.pick-1.3.0.tgz", - "integrity": "sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c=", + "resolved": "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz", + "integrity": "sha512-tqa/UMy/CCoYmj+H5qc07qvSL9dqcs/WZENZ1JbtWBlATP+iVOe778gE6MSijnyCnORzDuX6hU+LA4SZ09YjFQ==", "requires": { "isobject": "^3.0.1" } }, - "object.reduce": { - "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/object.reduce/-/object.reduce-1.0.1.tgz", - "integrity": "sha1-b+NI8qx/oPlcpiEiZZkJaCW7A60=", - "requires": { - "for-own": "^1.0.0", - "make-iterator": "^1.0.0" - } - }, "once": { "version": "1.4.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "requires": { "wrappy": "1" } }, "onetime": { "version": "5.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/onetime/-/onetime-5.1.2.tgz", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", "requires": { "mimic-fn": "^2.1.0" @@ -1154,16 +807,16 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/os-locale/-/os-locale-1.4.0.tgz", - "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha512-PRT7ZORmwu2MEFt4/fv3Q+mEfN4zetKxufQrkShY2oGvUms9r8otu5HfdyIFHkYXjO7laNsoVGmM2MANfuTA8g==", "requires": { "lcid": "^1.0.0" } }, "parse-filepath": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/parse-filepath/-/parse-filepath-1.0.2.tgz", - "integrity": "sha1-pjISf1Oq89FYdvWHLz/6x2PWyJE=", + "resolved": "https://registry.npmjs.org/parse-filepath/-/parse-filepath-1.0.2.tgz", + "integrity": "sha512-FwdRXKCohSVeXqwtYonZTXtbGJKrn+HNyWDYVcp5yuJlesTwNH4rsmRZ+GrKAPJ5bLpRxESMeS+Rl0VCHRvB2Q==", "requires": { "is-absolute": "^1.0.0", "map-cache": "^0.2.0", @@ -1172,57 +825,57 @@ }, "parse-json": { "version": "2.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/parse-json/-/parse-json-2.2.0.tgz", - "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha512-QR/GGaKCkhwk1ePQNYDRKYZ3mwU9ypsKhB0XyFnLQdomyEqk3e8wpW3V5Jp88zbxK4n5ST1nqo+g9juTpownhQ==", "requires": { "error-ex": "^1.2.0" } }, "parse-passwd": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/parse-passwd/-/parse-passwd-1.0.0.tgz", - "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=" + "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha512-1Y1A//QUXEZK7YKz+rD9WydcE1+EuPr6ZBgKecAB8tmoW6UFv0NREVJe1p+jRxtThkcbbKkfwIbWJe/IeE6m2Q==" }, "path-exists": { "version": "2.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-exists/-/path-exists-2.1.0.tgz", - "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha512-yTltuKuhtNeFJKa1PiRzfLAU5182q1y4Eb4XCJ3PBqyzEDkAZRzBrKKBct682ls9reBVHf9udYLN5Nd+K1B9BQ==", "requires": { "pinkie-promise": "^2.0.0" } }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==" }, "path-key": { "version": "3.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-key/-/path-key-3.1.1.tgz", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==" }, "path-parse": { "version": "1.0.7", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-parse/-/path-parse-1.0.7.tgz", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" }, "path-root": { "version": "0.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-root/-/path-root-0.1.1.tgz", - "integrity": "sha1-mkpoFMrBwM1zNgqV8yCDyOpHRbc=", + "resolved": "https://registry.npmjs.org/path-root/-/path-root-0.1.1.tgz", + "integrity": "sha512-QLcPegTHF11axjfojBIoDygmS2E3Lf+8+jI6wOVmNVenrKSo3mFdSGiIgdSHenczw3wPtlVMQaFVwGmM7BJdtg==", "requires": { "path-root-regex": "^0.1.0" } }, "path-root-regex": { "version": "0.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-root-regex/-/path-root-regex-0.1.2.tgz", - "integrity": "sha1-v8zcjfWxLcUsi0PsONGNcsBLqW0=" + "resolved": "https://registry.npmjs.org/path-root-regex/-/path-root-regex-0.1.2.tgz", + "integrity": "sha512-4GlJ6rZDhQZFE0DPVKh0e9jmZ5egZfxTkp7bcRDuPlJXbAwhxcl2dINPUAsjLdejqaLsCeg8axcLjIbvBjN4pQ==" }, "path-type": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/path-type/-/path-type-1.1.0.tgz", - "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha512-S4eENJz1pkiQn9Znv33Q+deTOKmbl+jj1Fl+qiP/vYezj+S8x+J3Uo0ISrx/QoEvIlOaDWJhPaRd1flJ9HXZqg==", "requires": { "graceful-fs": "^4.1.2", "pify": "^2.0.0", @@ -1231,51 +884,41 @@ }, "picomatch": { "version": "2.3.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/picomatch/-/picomatch-2.3.1.tgz", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==" }, "pify": { "version": "2.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/pify/-/pify-2.3.0.tgz", - "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==" }, "pinkie": { "version": "2.0.4", - "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==" }, "pinkie-promise": { "version": "2.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha512-0Gni6D4UcLTbv9c57DfxDGdr41XfgUjqWZu492f0cIGr16zDU06BWP/RAEvOuo7CQ0CNjHaLlM59YJJFm3NWlw==", "requires": { "pinkie": "^2.0.0" } }, "pretty-hrtime": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz", - "integrity": "sha1-9ualItPmBwRSK/Db5oVu0g515Nw=" - }, - "printj": { - "version": "1.3.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/printj/-/printj-1.3.1.tgz", - "integrity": "sha512-GA3TdL8szPK4AQ2YnOe/b+Y1jUFwmmGMMK/qbY7VcE3Z7FU8JstbKiKRzO6CIiAKPhTO8m01NoQ0V5f3jc4OGg==" - }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.0.tgz", + "integrity": "sha512-CU2l5CYUAptUYq/671ajexQfXuxJFwwg0n243Kdkx8bTjeenedsWgu8TGHPm03vLfNtk3aTXgySKPp3Usykudw==" }, "punycode": { "version": "2.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/punycode/-/punycode-2.1.1.tgz", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" }, "read-pkg": { "version": "1.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg/-/read-pkg-1.1.0.tgz", - "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha512-7BGwRHqt4s/uVbuyoeejRn4YmFnYZiFl4AuaeXHlgZf3sONF0SOGlxs2Pw8g6hCKupo08RafIO5YXFNOKTfwsQ==", "requires": { "load-json-file": "^1.0.0", "normalize-package-data": "^2.3.2", @@ -1284,34 +927,16 @@ }, "read-pkg-up": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/read-pkg-up/-/read-pkg-up-1.0.1.tgz", - "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha512-WD9MTlNtI55IwYUS27iHh9tK3YoIVhxis8yKhLpTqWtml739uXc9NWTpxoHkfZf3+DkCCsXox94/VWZniuZm6A==", "requires": { "find-up": "^1.0.0", "read-pkg": "^1.0.0" } }, - "readable-stream": { - "version": "3.6.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/readable-stream/-/readable-stream-3.6.0.tgz", - "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - }, - "readdir-glob": { - "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/readdir-glob/-/readdir-glob-1.1.1.tgz", - "integrity": "sha512-91/k1EzZwDx6HbERR+zucygRFfiPl2zkIYZtv3Jjr6Mn7SkKcVct8aVO+sSRiGMc6fLf72du3d92/uY63YPdEA==", - "requires": { - "minimatch": "^3.0.4" - } - }, "rechoir": { "version": "0.8.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/rechoir/-/rechoir-0.8.0.tgz", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.8.0.tgz", "integrity": "sha512-/vxpCXddiX8NGfGO/mTafwjq4aFa/71pvamip0++IQk3zG8cbCj0fifNPrjjF1XMXUne91jL9OoxmdykoEtifQ==", "requires": { "resolve": "^1.20.0" @@ -1319,22 +944,22 @@ }, "require-directory": { "version": "2.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==" }, "require-from-string": { "version": "2.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/require-from-string/-/require-from-string-2.0.2.tgz", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" }, "require-main-filename": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/require-main-filename/-/require-main-filename-1.0.1.tgz", - "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", + "integrity": "sha512-IqSUtOVP4ksd1C/ej5zeEh/BIP2ajqpn8c5x+q99gvcIG/Qf0cud5raVnE/Dwd0ua9TXYDoDc0RE5hBSdz22Ug==" }, "resolve": { "version": "1.22.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/resolve/-/resolve-1.22.0.tgz", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", "integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==", "requires": { "is-core-module": "^2.8.1", @@ -1344,8 +969,8 @@ }, "resolve-dir": { "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-dir/-/resolve-dir-1.0.1.tgz", - "integrity": "sha1-eaQGRMNivoLybv/nOcm7U4IEb0M=", + "resolved": "https://registry.npmjs.org/resolve-dir/-/resolve-dir-1.0.1.tgz", + "integrity": "sha512-R7uiTjECzvOsWSfdM0QKFNBVFcK27aHOUwdvK53BcW8zqnGdYp0Fbj82cy54+2A4P2tFM22J5kRfe1R+lM/1yg==", "requires": { "expand-tilde": "^2.0.0", "global-modules": "^1.0.0" @@ -1353,7 +978,7 @@ }, "resolve-package-path": { "version": "4.0.3", - "resolved": "https://repo.huaweicloud.com/repository/npm/resolve-package-path/-/resolve-package-path-4.0.3.tgz", + "resolved": "https://registry.npmjs.org/resolve-package-path/-/resolve-package-path-4.0.3.tgz", "integrity": "sha512-SRpNAPW4kewOaNUt8VPqhJ0UMxawMwzJD8V7m1cJfdSTK9ieZwS6K7Dabsm4bmLFM96Z5Y/UznrpG5kt1im8yA==", "requires": { "path-root": "^0.1.1" @@ -1361,32 +986,27 @@ }, "rfdc": { "version": "1.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/rfdc/-/rfdc-1.3.0.tgz", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz", "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==" }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" - }, "safer-buffer": { "version": "2.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/safer-buffer/-/safer-buffer-2.1.2.tgz", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, "semver": { "version": "5.7.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/semver/-/semver-5.7.1.tgz", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" }, "set-blocking": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/set-blocking/-/set-blocking-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, "shebang-command": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-command/-/shebang-command-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", "requires": { "shebang-regex": "^3.0.0" @@ -1394,17 +1014,17 @@ }, "shebang-regex": { "version": "3.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/shebang-regex/-/shebang-regex-3.0.0.tgz", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==" }, "signal-exit": { "version": "3.0.7", - "resolved": "https://repo.huaweicloud.com/repository/npm/signal-exit/-/signal-exit-3.0.7.tgz", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "spdx-correct": { "version": "3.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-correct/-/spdx-correct-3.1.1.tgz", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.1.1.tgz", "integrity": "sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==", "requires": { "spdx-expression-parse": "^3.0.0", @@ -1413,12 +1033,12 @@ }, "spdx-exceptions": { "version": "2.3.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.3.0.tgz", "integrity": "sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==" }, "spdx-expression-parse": { "version": "3.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", "requires": { "spdx-exceptions": "^2.1.0", @@ -1427,27 +1047,22 @@ }, "spdx-license-ids": { "version": "3.0.11", - "resolved": "https://repo.huaweicloud.com/repository/npm/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.11.tgz", "integrity": "sha512-Ctl2BrFiM0X3MANYgj3CkygxhRmr9mi6xhejbdO960nF6EDJApTYpn0BQnDKlnNBULKiCN1n3w9EBkHK8ZWg+g==" }, - "stream-exhaust": { - "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/stream-exhaust/-/stream-exhaust-1.0.2.tgz", - "integrity": "sha512-b/qaq/GlBK5xaq1yrK9/zFcyRSTNxmcZwFLGSTG0mXgZl/4Z6GgiyYOXOvY7N3eEvFRAG1bkDRz5EPGSvPYQlw==" - }, "streamroller": { - "version": "3.0.6", - "resolved": "https://repo.huaweicloud.com/repository/npm/streamroller/-/streamroller-3.0.6.tgz", - "integrity": "sha512-Qz32plKq/MZywYyhEatxyYc8vs994Gz0Hu2MSYXXLD233UyPeIeRBZARIIGwFer4Mdb8r3Y2UqKkgyDghM6QCg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.1.1.tgz", + "integrity": "sha512-iPhtd9unZ6zKdWgMeYGfSBuqCngyJy1B/GPi/lTpwGpa3bajuX30GjUVd0/Tn/Xhg0mr4DOSENozz9Y06qyonQ==", "requires": { - "date-format": "^4.0.6", + "date-format": "^4.0.10", "debug": "^4.3.4", - "fs-extra": "^10.0.1" + "fs-extra": "^10.1.0" } }, "string-width": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/string-width/-/string-width-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "requires": { "code-point-at": "^1.0.0", @@ -1455,17 +1070,9 @@ "strip-ansi": "^3.0.0" } }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "requires": { - "safe-buffer": "~5.1.0" - } - }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "requires": { "ansi-regex": "^2.0.0" @@ -1473,7 +1080,7 @@ }, "strip-bom": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/strip-bom/-/strip-bom-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", "requires": { "is-utf8": "^0.2.0" @@ -1481,93 +1088,48 @@ }, "strip-final-newline": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==" }, + "strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==" + }, "supports-preserve-symlinks-flag": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==" }, - "tar-stream": { - "version": "2.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/tar-stream/-/tar-stream-2.2.0.tgz", - "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", - "requires": { - "bl": "^4.0.3", - "end-of-stream": "^1.4.1", - "fs-constants": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^3.1.1" - } - }, "to-regex-range": { "version": "5.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/to-regex-range/-/to-regex-range-5.0.1.tgz", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "requires": { "is-number": "^7.0.0" - }, - "dependencies": { - "is-number": { - "version": "7.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" - } } }, - "type": { - "version": "1.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==" - }, "unc-path-regex": { "version": "0.1.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/unc-path-regex/-/unc-path-regex-0.1.2.tgz", + "resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz", "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=" }, - "undertaker": { - "version": "1.2.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker/-/undertaker-1.2.1.tgz", - "integrity": "sha512-71WxIzDkgYk9ZS+spIB8iZXchFhAdEo2YU8xYqBYJ39DIUIqziK78ftm26eecoIY49X0J2MLhG4hr18Yp6/CMA==", - "requires": { - "arr-flatten": "^1.0.1", - "arr-map": "^2.0.0", - "bach": "^1.0.0", - "collection-map": "^1.0.0", - "es6-weak-map": "^2.0.1", - "last-run": "^1.1.0", - "object.defaults": "^1.0.0", - "object.reduce": "^1.0.0", - "undertaker-registry": "^1.0.0" - } - }, - "undertaker-registry": { - "version": "1.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/undertaker-registry/-/undertaker-registry-1.0.1.tgz", - "integrity": "sha1-XkvaMI5KiirlhPm5pDWaSZglzFA=" - }, "universalify": { "version": "2.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/universalify/-/universalify-2.0.0.tgz", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==" }, "uri-js": { "version": "4.4.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/uri-js/-/uri-js-4.4.1.tgz", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "requires": { "punycode": "^2.1.0" } }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" - }, "v8flags": { "version": "3.2.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/v8flags/-/v8flags-3.2.0.tgz", + "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.2.0.tgz", "integrity": "sha512-mH8etigqMfiGWdeXpaaqGfs6BndypxusHHcv2qSHyZkGEznCd/qAXCWWRzeowtL54147cktFOC4P5y+kl8d8Jg==", "requires": { "homedir-polyfill": "^1.0.1" @@ -1575,7 +1137,7 @@ }, "validate-npm-package-license": { "version": "3.0.4", - "resolved": "https://repo.huaweicloud.com/repository/npm/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", "requires": { "spdx-correct": "^3.0.0", @@ -1584,7 +1146,7 @@ }, "which": { "version": "1.3.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/which/-/which-1.3.1.tgz", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "requires": { "isexe": "^2.0.0" @@ -1592,12 +1154,12 @@ }, "which-module": { "version": "1.0.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/which-module/-/which-module-1.0.0.tgz", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz", "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=" }, "wrap-ansi": { "version": "2.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", "requires": { "string-width": "^1.0.1", @@ -1606,17 +1168,17 @@ }, "wrappy": { "version": "1.0.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/wrappy/-/wrappy-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "y18n": { "version": "3.2.2", - "resolved": "https://repo.huaweicloud.com/repository/npm/y18n/-/y18n-3.2.2.tgz", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz", "integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==" }, "yargs": { "version": "7.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/yargs/-/yargs-7.1.0.tgz", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz", "integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=", "requires": { "camelcase": "^3.0.0", @@ -1636,22 +1198,12 @@ }, "yargs-parser": { "version": "5.0.1", - "resolved": "https://repo.huaweicloud.com/repository/npm/yargs-parser/-/yargs-parser-5.0.1.tgz", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.1.tgz", "integrity": "sha512-wpav5XYiddjXxirPoCTUPbqM0PXvJ9hiBMvuJgInvo4/lAOTZzUprArw17q2O1P2+GHhbBr18/iQwjL5Z9BqfA==", "requires": { "camelcase": "^3.0.0", "object.assign": "^4.1.0" } - }, - "zip-stream": { - "version": "4.1.0", - "resolved": "https://repo.huaweicloud.com/repository/npm/zip-stream/-/zip-stream-4.1.0.tgz", - "integrity": "sha512-zshzwQW7gG7hjpBlgeQP9RuyPGNxvJdzR8SUM3QhxCnLjWN2E7j3dOvpeDcQoETfHx0urRS7EtmVToql7YpU4A==", - "requires": { - "archiver-utils": "^2.1.0", - "compress-commons": "^4.1.0", - "readable-stream": "^3.6.0" - } } } } diff --git a/package.json b/package.json index 48c99e88c7d98648ebbd528e6610112dd83fe1da..71a34379c7efe4a09cdcb2eeeda0c2a3ebe2c2ce 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "repository": {}, "version": "1.0.0", "dependencies": { - "@ohos/hvigor-ohos-plugin": "1.0.6", - "hypium": "^1.0.0", - "@ohos/hvigor": "1.0.6" + "@ohos/hypium": "1.0.0", + "@ohos/hvigor-ohos-plugin": "1.1.3", + "@ohos/hvigor": "1.1.3" } } diff --git a/preview/preview.gif b/preview/preview.gif index 32dac3f3ade150cc890f649767dfe0bc86e31867..5e5a8db5f1309c28d429b595e1e9d11f87527843 100644 Binary files a/preview/preview.gif and b/preview/preview.gif differ