|
1 |
| -import * as defaultCrypto from '#crypto'; |
2 |
| -import { |
3 |
| - assign, |
4 |
| - clearBuffer, |
5 |
| - compactMapArray, |
6 |
| - eachArray, |
7 |
| - hasValue, |
8 |
| - isArray, |
9 |
| - isNumber, |
10 |
| - isUndefined |
11 |
| -} from '@universalweb/acid'; |
12 |
| -import { currentCertificateVersion, currentVersion } from '../defaults.js'; |
13 |
| -import { blake3 } from './hash/blake3.js'; |
14 |
| -import { dilithium44 } from './signature/dilithium44.js'; |
15 |
| -import { dilithium44_ed25519 } from './signature/dilithium44_ed25519.js'; |
16 |
| -import { dilithium65 } from './signature/dilithium65.js'; |
17 |
| -import { dilithium87 } from './signature/dilithium87.js'; |
18 |
| -import { ed25519 } from './signature/ed25519.js'; |
19 |
| -import { kyber768 } from './keyExchange/kyber768.js'; |
20 |
| -import { kyber768Half_x25519 } from './keyExchange/kyber768Half_x25519.js'; |
21 |
| -import { kyber768_x25519 } from './keyExchange/kyber768_x25519.js'; |
22 |
| -import { kyber768_xChaCha } from './cipherSuite/Kyber768_xChaCha.js'; |
23 |
| -import { x25519 } from './keyExchange/x25519_blake3.js'; |
24 |
| -import { x25519_kyber768Half_xchacha20 } from './cipherSuite/x25519_Kyber768Half_xChaCha.js'; |
25 |
| -import { x25519_xChaCha } from './cipherSuite/x25519_xChaCha.js'; |
26 |
| -function setOption(source, option) { |
27 |
| - const { |
28 |
| - id, name: cipherName, alias |
29 |
| - } = option; |
30 |
| - if (hasValue(cipherName)) { |
31 |
| - source.set(cipherName, option); |
32 |
| - } |
33 |
| - if (hasValue(id)) { |
34 |
| - source.set(id, option); |
35 |
| - } |
36 |
| - if (hasValue(alias)) { |
37 |
| - source.set(alias, option); |
38 |
| - } |
39 |
| -} |
40 |
| -export const cipherSuites = new Map(); |
41 |
| -const cipherSuitesVersion1 = new Map(); |
42 |
| -cipherSuites.set(currentVersion, cipherSuitesVersion1); |
43 |
| -cipherSuitesVersion1.set('all', [ |
44 |
| - x25519_xChaCha, |
45 |
| - x25519_kyber768Half_xchacha20, |
46 |
| - kyber768_xChaCha |
47 |
| -]); |
48 |
| -setOption(cipherSuitesVersion1, x25519_xChaCha); |
49 |
| -setOption(cipherSuitesVersion1, x25519_kyber768Half_xchacha20); |
50 |
| -setOption(cipherSuitesVersion1, kyber768_xChaCha); |
51 |
| -export const encryptionKeypairAlgorithm = new Map(); |
52 |
| -const encryptionKeypairAlgorithmVersion1 = new Map(); |
53 |
| -encryptionKeypairAlgorithm.set(currentVersion, encryptionKeypairAlgorithmVersion1); |
54 |
| -encryptionKeypairAlgorithm.set('all', [ |
55 |
| - kyber768Half_x25519, |
56 |
| - kyber768_x25519, |
57 |
| - kyber768, |
58 |
| - x25519, |
59 |
| -]); |
60 |
| -setOption(encryptionKeypairAlgorithmVersion1, kyber768); |
61 |
| -setOption(encryptionKeypairAlgorithmVersion1, x25519); |
62 |
| -setOption(encryptionKeypairAlgorithmVersion1, kyber768Half_x25519); |
63 |
| -setOption(encryptionKeypairAlgorithmVersion1, kyber768_x25519); |
64 |
| -export function getEncryptionKeypairAlgorithm(algo = 0, version = currentCertificateVersion) { |
65 |
| - if (!hasValue(algo)) { |
66 |
| - return false; |
67 |
| - } |
68 |
| - const versionMap = encryptionKeypairAlgorithm.get(version); |
69 |
| - if (versionMap) { |
70 |
| - return versionMap.get(algo); |
71 |
| - } |
72 |
| -} |
73 |
| -export const cipherSuitesCertificates = new Map(); |
74 |
| -const cipherSuitesCertificatesVersion1 = new Map(); |
75 |
| -cipherSuitesCertificates.set(currentVersion, cipherSuitesCertificatesVersion1); |
76 |
| -cipherSuitesCertificatesVersion1.set('all', [ |
77 |
| - x25519_xChaCha, |
78 |
| - x25519_kyber768Half_xchacha20, |
79 |
| - kyber768_xChaCha |
80 |
| -]); |
81 |
| -setOption(cipherSuitesCertificatesVersion1, x25519_xChaCha); |
82 |
| -setOption(cipherSuitesCertificatesVersion1, x25519_kyber768Half_xchacha20); |
83 |
| -setOption(cipherSuitesCertificatesVersion1, kyber768_xChaCha); |
84 |
| -export function getCipherSuite(cipherSuiteName = 0, version = currentVersion) { |
85 |
| - if (!hasValue(cipherSuiteName)) { |
86 |
| - return false; |
87 |
| - } |
88 |
| - const versionMap = cipherSuites.get(version); |
89 |
| - if (versionMap) { |
90 |
| - return versionMap.get(cipherSuiteName); |
91 |
| - } |
92 |
| -} |
93 |
| -export function getCipherSuites(indexes, version = currentVersion) { |
94 |
| - if (indexes) { |
95 |
| - if (isNumber(indexes)) { |
96 |
| - return getCipherSuite(indexes, version); |
97 |
| - } else if (isArray(indexes)) { |
98 |
| - const cipherSuitesArray = compactMapArray(indexes, (value) => { |
99 |
| - const cipherSuite = getCipherSuite(value, version); |
100 |
| - if (cipherSuite) { |
101 |
| - return cipherSuite; |
102 |
| - } |
103 |
| - }); |
104 |
| - return cipherSuitesArray; |
105 |
| - } |
106 |
| - } |
107 |
| - return getCipherSuite('all', version); |
108 |
| -} |
109 |
| -export const publicKeyAlgorithms = new Map(); |
110 |
| -const publicKeyAlgorithmVersion1 = new Map(); |
111 |
| -publicKeyAlgorithms.set(1, publicKeyAlgorithmVersion1); |
112 |
| -publicKeyAlgorithmVersion1.set('all', [ |
113 |
| - ed25519, |
114 |
| - dilithium44_ed25519, |
115 |
| - dilithium44, |
116 |
| - dilithium65, |
117 |
| - dilithium87 |
118 |
| -]); |
119 |
| -setOption(publicKeyAlgorithmVersion1, ed25519); |
120 |
| -setOption(publicKeyAlgorithmVersion1, dilithium44_ed25519); |
121 |
| -setOption(publicKeyAlgorithmVersion1, dilithium44); |
122 |
| -setOption(publicKeyAlgorithmVersion1, dilithium65); |
123 |
| -setOption(publicKeyAlgorithmVersion1, dilithium87); |
124 |
| -export function getSignatureAlgorithm(publicKeyAlgorithmName = 0, version = currentVersion) { |
125 |
| - if (!hasValue(publicKeyAlgorithmName)) { |
126 |
| - return false; |
127 |
| - } |
128 |
| - const versionMap = publicKeyAlgorithms.get(version); |
129 |
| - if (versionMap) { |
130 |
| - return versionMap.get(publicKeyAlgorithmName); |
131 |
| - } |
132 |
| -} |
133 |
| -export const publicKeyCertificateAlgorithms = new Map(); |
134 |
| -const publicKeyCertificateAlgorithmsVersion1 = new Map(); |
135 |
| -publicKeyCertificateAlgorithms.set(currentVersion, publicKeyCertificateAlgorithmsVersion1); |
136 |
| -publicKeyCertificateAlgorithmsVersion1.set('all', [ |
137 |
| - ed25519, |
138 |
| - dilithium44_ed25519, |
139 |
| - dilithium44, |
140 |
| - dilithium65, |
141 |
| - dilithium87 |
142 |
| -]); |
143 |
| -setOption(publicKeyCertificateAlgorithmsVersion1, ed25519); |
144 |
| -setOption(publicKeyCertificateAlgorithmsVersion1, dilithium44_ed25519); |
145 |
| -setOption(publicKeyCertificateAlgorithmsVersion1, dilithium44); |
146 |
| -setOption(publicKeyCertificateAlgorithmsVersion1, dilithium65); |
147 |
| -setOption(publicKeyCertificateAlgorithmsVersion1, dilithium87); |
148 |
| -export function getSignatureAlgorithmByCertificate(publicKeyAlgorithmName = 0, version = currentCertificateVersion) { |
149 |
| - if (!hasValue(publicKeyAlgorithmName)) { |
150 |
| - return false; |
151 |
| - } |
152 |
| - const algoVersion = publicKeyCertificateAlgorithms.get(version); |
153 |
| - if (algoVersion) { |
154 |
| - return algoVersion.get(publicKeyAlgorithmName); |
155 |
| - } |
156 |
| -} |
157 |
| -export const hashAlgorithms = new Map(); |
158 |
| -const hashAlgorithmsVersion1 = new Map(); |
159 |
| -hashAlgorithms.set(1, hashAlgorithmsVersion1); |
160 |
| -setOption(hashAlgorithmsVersion1, blake3); |
161 |
| -export function getHashAlgorithm(hashAlgorithmName = 0, version = currentVersion) { |
162 |
| - if (!hasValue(hashAlgorithmName)) { |
163 |
| - return false; |
164 |
| - } |
165 |
| - const algoVersion = hashAlgorithms.get(version); |
166 |
| - if (algoVersion) { |
167 |
| - return algoVersion.get(hashAlgorithmName); |
168 |
| - } |
169 |
| -} |
| 1 | +export * from './signature/index.js'; |
| 2 | +export * from './hash/index.js'; |
| 3 | +export * from './keyExchange/index.js'; |
| 4 | +export * from './encryption/index.js'; |
| 5 | +export * from './cipherSuite/index.js'; |
0 commit comments