| import { U8 } from './utils'; | ||
| export const ASN1 = { | ||
| // 0x04 | ||
| OCTET_STRING: (value) => { | ||
| const buffer = new U8(value.length + 2); | ||
| buffer.set([0x04, value.length], 0); | ||
| buffer.set(value, 2); | ||
| return buffer; | ||
| }, | ||
| // 0x05 | ||
| NULL: () => new U8([0x05, 0x00]), | ||
| // 0x06 | ||
| OBJECT_IDENTIFIER: (id = '') => { | ||
| const node = id.split('.').map(Number); | ||
| const buffer = []; | ||
| buffer.push(node[0] * 40 + node[1]); | ||
| for (let i = 2; i < node.length; i++) { | ||
| let n = node[i]; | ||
| if (n < 128) { | ||
| buffer.push(n); | ||
| } | ||
| else { | ||
| const bytes = [n & 0x7F]; | ||
| n >>= 7; | ||
| while (n > 0) { | ||
| bytes.unshift((n & 0x7F) | 0x80); | ||
| n >>= 7; | ||
| } | ||
| buffer.push(...bytes); | ||
| } | ||
| } | ||
| return new U8([0x06, buffer.length, ...buffer]); | ||
| }, | ||
| // 0x30 | ||
| SEQUENCE: (value) => { | ||
| const length = value.reduce((sum, v) => sum + v.length, 0); | ||
| const buffer = new U8(length + 2); | ||
| buffer.set([0x30, length], 0); | ||
| let offset = 2; | ||
| for (const v of value) { | ||
| buffer.set(v, offset); | ||
| offset += v.length; | ||
| } | ||
| return buffer; | ||
| }, | ||
| }; |
@@ -1,2 +0,2 @@ | ||
| import * as asn from 'asn1js'; | ||
| import { ASN1 } from '../../core/asn1'; | ||
| import { Counter, KitError, U8, getBIBits, joinBuffer } from '../../core/utils'; | ||
@@ -246,16 +246,12 @@ import { sha256 } from '../../hash/sha256'; | ||
| const H = hash(M); | ||
| const digestAlgorithm = new asn.Sequence({ | ||
| value: [ | ||
| new asn.ObjectIdentifier({ value: hash.OID }), | ||
| new asn.Null(), | ||
| ], | ||
| }); | ||
| const digest = new asn.OctetString({ valueHex: H }); | ||
| const DigestInfo = new asn.Sequence({ | ||
| value: [ | ||
| digestAlgorithm, | ||
| digest, | ||
| ], | ||
| }); | ||
| const T = new U8(DigestInfo.toBER(false)); | ||
| const digestAlgorithm = ASN1.SEQUENCE([ | ||
| ASN1.OBJECT_IDENTIFIER(hash.OID), | ||
| ASN1.NULL(), | ||
| ]); | ||
| const digest = ASN1.OCTET_STRING(H); | ||
| const DigestInfo = ASN1.SEQUENCE([ | ||
| digestAlgorithm, | ||
| digest, | ||
| ]); | ||
| const T = DigestInfo; | ||
| const psLen = emLen - T.length - 3; | ||
@@ -262,0 +258,0 @@ if (psLen < 8) { |
+2
-4
| { | ||
| "name": "mima-kit", | ||
| "type": "module", | ||
| "version": "0.0.14", | ||
| "version": "0.0.15", | ||
| "packageManager": "pnpm@9.9.0", | ||
@@ -42,2 +42,3 @@ "description": "mima-kit is a cryptographic suite implemented in TypeScript. The goal is to provide an easy-to-use cryptographic library. mima-kit 是一个使用 TypeScript 实现的密码学套件。目标是提供一个简单易用的密码学库。", | ||
| "xtea", | ||
| "xxtea", | ||
| "streamCipher", | ||
@@ -93,5 +94,2 @@ "zuc", | ||
| }, | ||
| "dependencies": { | ||
| "asn1js": "^3.0.5" | ||
| }, | ||
| "devDependencies": { | ||
@@ -98,0 +96,0 @@ "@antfu/eslint-config": "^2.27.3", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
800955
0.22%0
-100%47
2.17%10500
0.43%- Removed
- Removed
- Removed
- Removed
- Removed