threshold-elgamal 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,381 @@
1
+ [threshold-elgamal](README.md) / Exports
2
+
3
+ # threshold-elgamal
4
+
5
+ ## Table of contents
6
+
7
+ ### Type Aliases
8
+
9
+ - [EncryptedMessage](modules.md#encryptedmessage)
10
+ - [KeyPair](modules.md#keypair)
11
+ - [Parameters](modules.md#parameters)
12
+ - [PartyKeyPair](modules.md#partykeypair)
13
+
14
+ ### Functions
15
+
16
+ - [combineDecryptionShares](modules.md#combinedecryptionshares)
17
+ - [combinePublicKeys](modules.md#combinepublickeys)
18
+ - [createDecryptionShare](modules.md#createdecryptionshare)
19
+ - [decrypt](modules.md#decrypt)
20
+ - [encrypt](modules.md#encrypt)
21
+ - [generateKeyShares](modules.md#generatekeyshares)
22
+ - [generateParameters](modules.md#generateparameters)
23
+ - [generateSingleKeyShare](modules.md#generatesinglekeyshare)
24
+ - [getRandomBigIntegerInRange](modules.md#getrandombigintegerinrange)
25
+ - [multiplyEncryptedValues](modules.md#multiplyencryptedvalues)
26
+ - [thresholdDecrypt](modules.md#thresholddecrypt)
27
+
28
+ ## Type Aliases
29
+
30
+ ### EncryptedMessage
31
+
32
+ Ƭ **EncryptedMessage**: `Object`
33
+
34
+ #### Type declaration
35
+
36
+ | Name | Type |
37
+ | :------ | :------ |
38
+ | `c1` | `bigint` |
39
+ | `c2` | `bigint` |
40
+
41
+ #### Defined in
42
+
43
+ [types.ts:1](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/types.ts#L1)
44
+
45
+ ___
46
+
47
+ ### KeyPair
48
+
49
+ Ƭ **KeyPair**: `Object`
50
+
51
+ #### Type declaration
52
+
53
+ | Name | Type |
54
+ | :------ | :------ |
55
+ | `privateKey` | `bigint` |
56
+ | `publicKey` | `bigint` |
57
+
58
+ #### Defined in
59
+
60
+ [types.ts:13](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/types.ts#L13)
61
+
62
+ ___
63
+
64
+ ### Parameters
65
+
66
+ Ƭ **Parameters**: `Object`
67
+
68
+ #### Type declaration
69
+
70
+ | Name | Type |
71
+ | :------ | :------ |
72
+ | `generator` | `bigint` |
73
+ | `prime` | `bigint` |
74
+ | `privateKey` | `bigint` |
75
+ | `publicKey` | `bigint` |
76
+
77
+ #### Defined in
78
+
79
+ [types.ts:6](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/types.ts#L6)
80
+
81
+ ___
82
+
83
+ ### PartyKeyPair
84
+
85
+ Ƭ **PartyKeyPair**: `Object`
86
+
87
+ #### Type declaration
88
+
89
+ | Name | Type |
90
+ | :------ | :------ |
91
+ | `partyPrivateKey` | `bigint` |
92
+ | `partyPublicKey` | `bigint` |
93
+
94
+ #### Defined in
95
+
96
+ [types.ts:18](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/types.ts#L18)
97
+
98
+ ## Functions
99
+
100
+ ### combineDecryptionShares
101
+
102
+ ▸ **combineDecryptionShares**(`decryptionShares`, `prime`): `bigint`
103
+
104
+ Combines partial decryptions from multiple parties into a single decryption factor.
105
+
106
+ #### Parameters
107
+
108
+ | Name | Type | Description |
109
+ | :------ | :------ | :------ |
110
+ | `decryptionShares` | `bigint`[] | An array of partial decryption results. |
111
+ | `prime` | `bigint` | The prime modulus used in the ElGamal system. |
112
+
113
+ #### Returns
114
+
115
+ `bigint`
116
+
117
+ The combined decryption factor.
118
+
119
+ #### Defined in
120
+
121
+ [thresholdElgamal.ts:129](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L129)
122
+
123
+ ___
124
+
125
+ ### combinePublicKeys
126
+
127
+ ▸ **combinePublicKeys**(`publicKeys`, `prime`): `bigint`
128
+
129
+ Combines multiple public keys into a single public key.
130
+
131
+ #### Parameters
132
+
133
+ | Name | Type | Description |
134
+ | :------ | :------ | :------ |
135
+ | `publicKeys` | `bigint`[] | An array of public keys to combine. |
136
+ | `prime` | `bigint` | The prime modulus used in the ElGamal system. |
137
+
138
+ #### Returns
139
+
140
+ `bigint`
141
+
142
+ The combined public key.
143
+
144
+ #### Defined in
145
+
146
+ [thresholdElgamal.ts:103](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L103)
147
+
148
+ ___
149
+
150
+ ### createDecryptionShare
151
+
152
+ ▸ **createDecryptionShare**(`encryptedMessage`, `partyPrivateKey`, `prime`): `bigint`
153
+
154
+ Performs a partial decryption on a ciphertext using an individual's private key share.
155
+
156
+ #### Parameters
157
+
158
+ | Name | Type | Description |
159
+ | :------ | :------ | :------ |
160
+ | `encryptedMessage` | [`EncryptedMessage`](modules.md#encryptedmessage) | The encrypted secret. |
161
+ | `partyPrivateKey` | `bigint` | The private key share of the decrypting party. |
162
+ | `prime` | `bigint` | The prime modulus used in the ElGamal system. |
163
+
164
+ #### Returns
165
+
166
+ `bigint`
167
+
168
+ The result of the partial decryption.
169
+
170
+ #### Defined in
171
+
172
+ [thresholdElgamal.ts:116](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L116)
173
+
174
+ ___
175
+
176
+ ### decrypt
177
+
178
+ ▸ **decrypt**(`encryptedMessage`, `prime`, `privateKey`): `number`
179
+
180
+ Decrypts an ElGamal encrypted secret.
181
+
182
+ #### Parameters
183
+
184
+ | Name | Type | Description |
185
+ | :------ | :------ | :------ |
186
+ | `encryptedMessage` | [`EncryptedMessage`](modules.md#encryptedmessage) | - |
187
+ | `prime` | `bigint` | The prime number used in the encryption system. |
188
+ | `privateKey` | `bigint` | The private key used for decryption. |
189
+
190
+ #### Returns
191
+
192
+ `number`
193
+
194
+ The decrypted secret as an integer.
195
+
196
+ #### Defined in
197
+
198
+ [elgamal.ts:77](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/elgamal.ts#L77)
199
+
200
+ ___
201
+
202
+ ### encrypt
203
+
204
+ ▸ **encrypt**(`secret`, `prime`, `generator`, `publicKey`): [`EncryptedMessage`](modules.md#encryptedmessage)
205
+
206
+ Encrypts a secret using ElGamal encryption.
207
+
208
+ #### Parameters
209
+
210
+ | Name | Type | Description |
211
+ | :------ | :------ | :------ |
212
+ | `secret` | `number` | The secret to be encrypted. |
213
+ | `prime` | `bigint` | The prime number used in the encryption system. |
214
+ | `generator` | `bigint` | The generator used in the encryption system. |
215
+ | `publicKey` | `bigint` | The public key used for encryption. |
216
+
217
+ #### Returns
218
+
219
+ [`EncryptedMessage`](modules.md#encryptedmessage)
220
+
221
+ The encrypted secret, consisting of two BigIntegers (c1 and c2).
222
+
223
+ #### Defined in
224
+
225
+ [elgamal.ts:51](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/elgamal.ts#L51)
226
+
227
+ ___
228
+
229
+ ### generateKeyShares
230
+
231
+ ▸ **generateKeyShares**(`n`, `threshold`, `primeBits?`): [`PartyKeyPair`](modules.md#partykeypair)[]
232
+
233
+ Generates key shares for a threshold ElGamal cryptosystem.
234
+
235
+ #### Parameters
236
+
237
+ | Name | Type | Default value | Description |
238
+ | :------ | :------ | :------ | :------ |
239
+ | `n` | `number` | `undefined` | The total number of key shares. |
240
+ | `threshold` | `number` | `undefined` | The minimum number of key shares required for decryption. |
241
+ | `primeBits` | ``2048`` \| ``3072`` \| ``4096`` | `2048` | The bit length of the prime modulus (default: 2048). |
242
+
243
+ #### Returns
244
+
245
+ [`PartyKeyPair`](modules.md#partykeypair)[]
246
+
247
+ An array of key shares, each containing a private and public key share.
248
+
249
+ #### Defined in
250
+
251
+ [thresholdElgamal.ts:83](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L83)
252
+
253
+ ___
254
+
255
+ ### generateParameters
256
+
257
+ ▸ **generateParameters**(`primeBits?`): [`Parameters`](modules.md#parameters)
258
+
259
+ Generates the parameters for the ElGamal encryption, including the prime, generator,
260
+ and key pair (public and private keys).
261
+
262
+ #### Parameters
263
+
264
+ | Name | Type | Default value | Description |
265
+ | :------ | :------ | :------ | :------ |
266
+ | `primeBits` | ``2048`` \| ``3072`` \| ``4096`` | `2048` | The bit length for the prime number. Supports 2048, 3072, or 4096 bits. |
267
+
268
+ #### Returns
269
+
270
+ [`Parameters`](modules.md#parameters)
271
+
272
+ The generated parameters including the prime, generator, publicKey, and privateKey.
273
+
274
+ #### Defined in
275
+
276
+ [elgamal.ts:14](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/elgamal.ts#L14)
277
+
278
+ ___
279
+
280
+ ### generateSingleKeyShare
281
+
282
+ ▸ **generateSingleKeyShare**(`index`, `threshold`, `primeBits?`): [`PartyKeyPair`](modules.md#partykeypair)
283
+
284
+ Generates a single key share for a participant in a threshold ElGamal cryptosystem.
285
+
286
+ #### Parameters
287
+
288
+ | Name | Type | Default value | Description |
289
+ | :------ | :------ | :------ | :------ |
290
+ | `index` | `number` | `undefined` | The unique index of the participant (starting from 1). |
291
+ | `threshold` | `number` | `undefined` | The minimum number of key shares required for decryption. |
292
+ | `primeBits` | ``2048`` \| ``3072`` \| ``4096`` | `2048` | The bit length of the prime modulus (default: 2048). |
293
+
294
+ #### Returns
295
+
296
+ [`PartyKeyPair`](modules.md#partykeypair)
297
+
298
+ The key share containing a private and public key share for the participant.
299
+
300
+ #### Defined in
301
+
302
+ [thresholdElgamal.ts:56](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L56)
303
+
304
+ ___
305
+
306
+ ### getRandomBigIntegerInRange
307
+
308
+ ▸ **getRandomBigIntegerInRange**(`min`, `max`): `bigint`
309
+
310
+ Generates a random bigint within a specified range.
311
+
312
+ #### Parameters
313
+
314
+ | Name | Type | Description |
315
+ | :------ | :------ | :------ |
316
+ | `min` | `bigint` | The minimum value (inclusive). |
317
+ | `max` | `bigint` | The maximum value (exclusive). |
318
+
319
+ #### Returns
320
+
321
+ `bigint`
322
+
323
+ A random bigint within the specified range.
324
+
325
+ #### Defined in
326
+
327
+ [utils.ts:11](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/utils.ts#L11)
328
+
329
+ ___
330
+
331
+ ### multiplyEncryptedValues
332
+
333
+ ▸ **multiplyEncryptedValues**(`value1`, `value2`, `prime`): [`EncryptedMessage`](modules.md#encryptedmessage)
334
+
335
+ Performs homomorphic multiplication on two encrypted values, allowing for encrypted arithmetic operations.
336
+
337
+ #### Parameters
338
+
339
+ | Name | Type | Description |
340
+ | :------ | :------ | :------ |
341
+ | `value1` | [`EncryptedMessage`](modules.md#encryptedmessage) | The first encrypted value. |
342
+ | `value2` | [`EncryptedMessage`](modules.md#encryptedmessage) | The second encrypted value. |
343
+ | `prime` | `bigint` | The prime modulus used in the encryption system. |
344
+
345
+ #### Returns
346
+
347
+ [`EncryptedMessage`](modules.md#encryptedmessage)
348
+
349
+ The result of the multiplication, as a new encrypted message.
350
+
351
+ #### Defined in
352
+
353
+ [utils.ts:33](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/utils.ts#L33)
354
+
355
+ ___
356
+
357
+ ### thresholdDecrypt
358
+
359
+ ▸ **thresholdDecrypt**(`encryptedMessage`, `combinedDecryptionShares`, `prime`): `number`
360
+
361
+ Decrypts an encrypted secret using the combined partial decryptions in a threshold ElGamal scheme.
362
+
363
+ #### Parameters
364
+
365
+ | Name | Type | Description |
366
+ | :------ | :------ | :------ |
367
+ | `encryptedMessage` | `Object` | The encrypted secret components. |
368
+ | `encryptedMessage.c1` | `bigint` | - |
369
+ | `encryptedMessage.c2` | `bigint` | - |
370
+ | `combinedDecryptionShares` | `bigint` | The combined partial decryptions from all parties. |
371
+ | `prime` | `bigint` | The prime modulus used in the ElGamal system. |
372
+
373
+ #### Returns
374
+
375
+ `number`
376
+
377
+ The decrypted secret, assuming it was small enough to be directly encrypted.
378
+
379
+ #### Defined in
380
+
381
+ [thresholdElgamal.ts:148](https://github.com/Tenemo/threshold-elgamal/blob/fc2a22a1ff8f83d6af5a428644410ebc8517f4e1/src/thresholdElgamal.ts#L148)
@@ -0,0 +1,161 @@
1
+ import path from 'path';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ // eslint-disable-next-line import/namespace
5
+ import { FlatCompat } from '@eslint/eslintrc';
6
+ import eslintJs from '@eslint/js';
7
+ import errorOnlyPlugin from 'eslint-plugin-only-error';
8
+ import prettierPluginRecommended from 'eslint-plugin-prettier/recommended';
9
+ import globals from 'globals';
10
+
11
+ const OFF = 0;
12
+ const ERROR = 2;
13
+
14
+ const __filename = fileURLToPath(import.meta.url);
15
+ const __dirname = path.dirname(__filename);
16
+
17
+ const compat = new FlatCompat({
18
+ baseDirectory: __dirname,
19
+ });
20
+
21
+ export default [
22
+ ...compat.config({
23
+ extends: ['plugin:import/errors', 'plugin:import/warnings'],
24
+ parser: '@typescript-eslint/parser',
25
+ parserOptions: {
26
+ parser: '@typescript-eslint/parser',
27
+ sourceType: 'module',
28
+ ecmaFeatures: {
29
+ jsx: true,
30
+ },
31
+ project: './tsconfig.json',
32
+ ecmaVersion: 2021,
33
+ },
34
+ plugins: ['only-error'],
35
+ settings: {
36
+ react: {
37
+ version: 'detect',
38
+ },
39
+ 'import/resolver': {
40
+ typescript: {},
41
+ },
42
+ },
43
+ }),
44
+ prettierPluginRecommended,
45
+ {
46
+ files: ['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.mjs'],
47
+ rules: {
48
+ ...eslintJs.configs.recommended.rules,
49
+ 'arrow-parens': [ERROR, 'always', { requireForBlockBody: false }],
50
+ 'no-restricted-exports': OFF,
51
+ 'no-shadow': OFF, // duplicated by @typescript-eslint/no-shadow
52
+
53
+ // @typescript-eslint/eslint-plugin
54
+ '@typescript-eslint/no-use-before-define': ERROR,
55
+ '@typescript-eslint/no-shadow': ERROR,
56
+ '@typescript-eslint/explicit-module-boundary-types': ERROR,
57
+ '@typescript-eslint/unbound-method': ERROR,
58
+ '@typescript-eslint/explicit-function-return-type': [
59
+ ERROR,
60
+ {
61
+ allowExpressions: true,
62
+ allowTypedFunctionExpressions: true,
63
+ },
64
+ ],
65
+ '@typescript-eslint/consistent-type-definitions': ['error', 'type'],
66
+
67
+ // eslint-plugin-prettier
68
+ 'prettier/prettier': [
69
+ ERROR,
70
+ {
71
+ useTabs: false,
72
+ semi: true,
73
+ singleQuote: true,
74
+ jsxSingleQuote: false,
75
+ trailingComma: 'all',
76
+ arrowParens: 'always',
77
+ endOfLine: 'lf',
78
+ },
79
+ ],
80
+
81
+ // eslint-plugin-import
82
+ 'import/no-extraneous-dependencies': [
83
+ ERROR,
84
+ { devDependencies: true },
85
+ ],
86
+ 'import/prefer-default-export': OFF,
87
+ 'import/extensions': [
88
+ ERROR,
89
+ 'ignorePackages',
90
+ {
91
+ js: 'never',
92
+ jsx: 'never',
93
+ ts: 'never',
94
+ tsx: 'never',
95
+ },
96
+ ],
97
+ 'import/order': [
98
+ 'error',
99
+ {
100
+ 'newlines-between': 'always',
101
+ alphabetize: { order: 'asc', caseInsensitive: true },
102
+ pathGroupsExcludedImportTypes: ['builtin'],
103
+ },
104
+ ],
105
+ },
106
+ plugins: {
107
+ 'only-error': errorOnlyPlugin,
108
+ },
109
+ linterOptions: {
110
+ reportUnusedDisableDirectives: true,
111
+ },
112
+ languageOptions: {
113
+ globals: {
114
+ ...globals.browser,
115
+ ...globals.node,
116
+ ...globals.es2021,
117
+ ...globals.commonjs,
118
+ },
119
+ },
120
+ },
121
+ ...compat.config({
122
+ extends: [
123
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking', // adds @typescript-eslint plugin
124
+ 'plugin:@typescript-eslint/stylistic-type-checked',
125
+ 'plugin:import/typescript',
126
+ ],
127
+ overrides: [
128
+ {
129
+ files: ['**/*.mjs', '**/*.js', '**/*.jsx', 'eslint.config.mjs'],
130
+ rules: {
131
+ '@typescript-eslint/no-unsafe-assignment': OFF,
132
+ '@typescript-eslint/no-unsafe-member-access': OFF,
133
+ '@typescript-eslint/no-unsafe-call': OFF,
134
+ },
135
+ },
136
+ ],
137
+ }),
138
+ {
139
+ files: ['**/*.scss.d.ts'],
140
+ rules: {
141
+ 'prettier/prettier': OFF,
142
+ '@typescript-eslint/consistent-type-definitions': OFF,
143
+ },
144
+ },
145
+ {
146
+ files: ['**/*.spec.tsx'],
147
+ rules: {
148
+ '@typescript-eslint/ban-ts-comment': OFF,
149
+ '@typescript-eslint/no-unsafe-return': OFF,
150
+ },
151
+ },
152
+ {
153
+ ignores: [
154
+ 'node_modules/*',
155
+ '.tmp/*',
156
+ 'coverage/*',
157
+ 'dist/*',
158
+ '**/*.html',
159
+ ],
160
+ },
161
+ ];
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "threshold-elgamal",
3
+ "version": "0.1.0",
4
+ "author": "Piotr Piech <piotr@piech.dev>",
5
+ "license": "MIT",
6
+ "description": "threshold-elgamal",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Tenemo/threshold-elgamal.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Tenemo/threshold-elgamal/issues"
15
+ },
16
+ "homepage": "https://github.com/Tenemo/threshold-elgamal#readme",
17
+ "scripts": {
18
+ "example": "tsx ./example/example",
19
+ "eslint": "eslint . -c eslint.config.js",
20
+ "eslint:fix": "eslint . --fix -c eslint.config.js",
21
+ "tsc": "tsc",
22
+ "prebuild": "npm run eslint && npm run tsc && npm run test && rimraf dist",
23
+ "build": "tsc --project tsconfig.build.json",
24
+ "build:skip": "tsc --project tsconfig.build.json",
25
+ "test": "vitest --watch=false --reporter=verbose",
26
+ "test:watch": "vitest --watch=true --reporter=verbose",
27
+ "pretypedoc": "rimraf docs",
28
+ "typedoc": "typedoc --plugin typedoc-plugin-markdown src --out docs",
29
+ "prepublish": "npm run prebuild",
30
+ "publish": "npm publish"
31
+ },
32
+ "engines": {
33
+ "node": ">=20.11.0"
34
+ },
35
+ "type": "module",
36
+ "devDependencies": {
37
+ "@eslint/eslintrc": "^3.0.2",
38
+ "@eslint/js": "^8.57.0",
39
+ "@types/eslint": "^8.56.7",
40
+ "@types/eslint-plugin-prettier": "^3.1.3",
41
+ "@types/node": "^20.12.5",
42
+ "@types/npm": "^7.19.3",
43
+ "@types/prettier": "^2.7.3",
44
+ "@typescript-eslint/eslint-plugin": "^7.5.0",
45
+ "@typescript-eslint/parser": "^7.5.0",
46
+ "eslint": "^8.57.0",
47
+ "eslint-config-prettier": "^9.1.0",
48
+ "eslint-import-resolver-typescript": "^3.6.1",
49
+ "eslint-plugin-import": "^2.29.1",
50
+ "eslint-plugin-only-error": "^1.0.2",
51
+ "eslint-plugin-prettier": "^5.1.3",
52
+ "globals": "^15.0.0",
53
+ "prettier": "^3.2.5",
54
+ "prettier-eslint": "^16.3.0",
55
+ "rimraf": "^5.0.5",
56
+ "tsx": "^4.7.2",
57
+ "typedoc": "^0.25.13",
58
+ "typedoc-plugin-markdown": "^3.17.1",
59
+ "typescript": "^5.4.4",
60
+ "vitest": "^1.4.0"
61
+ },
62
+ "dependencies": {
63
+ "bigint-mod-arith": "^3.3.1",
64
+ "random-bigint": "^0.0.1"
65
+ },
66
+ "keywords": [
67
+ "cryptography",
68
+ "security",
69
+ "encryption",
70
+ "elgamal",
71
+ "threshold-encryption",
72
+ "public-key-encryption",
73
+ "cryptographic-algorithm",
74
+ "distributed-cryptography",
75
+ "secure-communication",
76
+ "typescript-cryptography",
77
+ "data-protection",
78
+ "privacy",
79
+ "key-management",
80
+ "secret-sharing"
81
+ ]
82
+ }
@@ -0,0 +1,44 @@
1
+ /*
2
+ The GROUPS object defines cryptographic parameters for different levels
3
+ of finite field Diffie-Hellman (FFDHE) key exchanges.
4
+
5
+ The parameters are standardized in RFC 7919 to ensure security,
6
+ interoperability, and a balance between computational efficiency
7
+ and resistance against cryptographic attacks.
8
+
9
+ Each subgroup (ffdhe2048, ffdhe3072, ffdhe4096) corresponds to a security
10
+ level, with larger primes offering stronger security but requiring more processing power.
11
+
12
+ Reference: https://datatracker.ietf.org/doc/rfc7919/
13
+ */
14
+ export const GROUPS = {
15
+ // Parameters for 2048-bit prime modulus group
16
+ ffdhe2048: {
17
+ primeBits: 2048, // Size of the prime in bits, default security level suitable for current applications
18
+ prime: 32317006071311007300153513477825163362488057133489075174588434139269806834136210002792056362640164685458556357935330816928829023080573472625273554742461245741026202527916572972862706300325263428213145766931414223654220941111348629991657478268034230553086349050635557712219187890332729569696129743856241741236237225197346402691855797767976823014625397933058015226858730761197532436467475855460715043896844940366130497697812854295958659597567051283852132784468522925504568272879113720098931873959143374175837826000278034973198552060607533234122603254684088120031105907484281003994966956119696956248629032338072839127039n,
19
+ generator: 2n, // A small, primitive root modulo prime, used to generate public keys
20
+ // Same as `prime` in this context, used for modulo operations in encryption/decryption
21
+ modulus:
22
+ 16158503035655503650076756738912581681244028566744537587294217069634903417068105001396028181320082342729278178967665408464414511540286736312636777371230622870513101263958286486431353150162631714106572883465707111827110470555674314995828739134017115276543174525317778856109593945166364784848064871928120870618118612598673201345927898883988411507312698966529007613429365380598766218233737927730357521948422470183065248848906427147979329798783525641926066392234261462752284136439556860049465936979571687087918913000139017486599276030303766617061301627342044060015552953742140501997483478059848478124314516169036419563519n,
23
+ symmetricEquivalentBitsSecurity: 103, // The estimated security level equivalent to symmetric key cryptography
24
+ },
25
+ // Parameters for 3072-bit prime modulus group
26
+ ffdhe3072: {
27
+ primeBits: 3072, // Provides higher security/complexity level
28
+ prime: 5809605995369958062758586654274580047791722104970656507438869740087793294939022179753100900150316602414836960597893531254315756065700170507943025794723871619068282822579148207659984331724286057133800207014820356957933334364535176201393094406964280368146360322417397201921556656310696298417414318434929392806928868314831784332237038568260988712237196665742900353512788403877776568945491183287529096888884348887176901995757588549340219807606149955056871781046117195453427070254533858964729101754281121787330325506574928503501334937579191349178901801866451262831560570379780282604068262795024384318599710948857446185134652829941527736472860172354516733867877780829051346167153594329592339252295871976889069885964128038593002336846153522149026229984394781638501125312676451837144945451331832522946684620954184360294871798125320434686136230055213248587935623124338652624786221871129902570119964134282018641257113252046271726747647n,
29
+ generator: 2n,
30
+ modulus:
31
+ 2904802997684979031379293327137290023895861052485328253719434870043896647469511089876550450075158301207418480298946765627157878032850085253971512897361935809534141411289574103829992165862143028566900103507410178478966667182267588100696547203482140184073180161208698600960778328155348149208707159217464696403464434157415892166118519284130494356118598332871450176756394201938888284472745591643764548444442174443588450997878794274670109903803074977528435890523058597726713535127266929482364550877140560893665162753287464251750667468789595674589450900933225631415780285189890141302034131397512192159299855474428723092567326414970763868236430086177258366933938890414525673083576797164796169626147935988444534942982064019296501168423076761074513114992197390819250562656338225918572472725665916261473342310477092180147435899062660217343068115027606624293967811562169326312393110935564951285059982067141009320628556626023135863373823n,
32
+
33
+ symmetricEquivalentBitsSecurity: 125,
34
+ },
35
+ // Parameters for 4096-bit prime modulus group
36
+ ffdhe4096: {
37
+ primeBits: 4096, // High security/complexity level
38
+ prime: 1044388881413152506673611132423542708364181673367771525125030890756881099188024532056304793061869328458723091803972939229793654985168401497491717574483844225116618212565649899896238061528255690984013755361148305106047581812557457571303413897964307070369153233034916545609049161117676542252417034306148432734874401682098205055813065377495410934435776008569464677021023433005437163880753068613673525551966829473007537177831003494630326494021352410947409155250518131329542947165352164089215019548909074312164647627938366550236314760864116934087960021077839688388383033906117940935023026686459274599124189299486771919466921436930468113859003854695674493896608503326776616230412252016237753188005160515672431703429026925450722225213972891936880551722374424500117253400391608019951133386097176734162660461073160502839490488652900367939577292447038637156268014222959401811270825513710710113193757653852931049810187522670964988718456427706279024201400130351029277257873323362974483425793829163819060563081096261611614988801585554385004830748976181157545121697905898543562330970182151097394600286811868072516047394404389555706298311761588649133904051123770516767707951778179308436153604841663369568605395358405635911568855382987714763476172799n,
39
+ generator: 2n,
40
+ modulus:
41
+ 522194440706576253336805566211771354182090836683885762562515445378440549594012266028152396530934664229361545901986469614896827492584200748745858787241922112558309106282824949948119030764127845492006877680574152553023790906278728785651706948982153535184576616517458272804524580558838271126208517153074216367437200841049102527906532688747705467217888004284732338510511716502718581940376534306836762775983414736503768588915501747315163247010676205473704577625259065664771473582676082044607509774454537156082323813969183275118157380432058467043980010538919844194191516953058970467511513343229637299562094649743385959733460718465234056929501927347837246948304251663388308115206126008118876594002580257836215851714513462725361112606986445968440275861187212250058626700195804009975566693048588367081330230536580251419745244326450183969788646223519318578134007111479700905635412756855355056596878826926465524905093761335482494359228213853139512100700065175514638628936661681487241712896914581909530281540548130805807494400792777192502415374488090578772560848952949271781165485091075548697300143405934036258023697202194777853149155880794324566952025561885258383853975889089654218076802420831684784302697679202817955784427691493857381738086399n,
42
+ symmetricEquivalentBitsSecurity: 150,
43
+ },
44
+ } as const;