Skip to content

Commit 94a7220

Browse files
committed
README
1 parent 86d7025 commit 94a7220

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

README.md

+21-14
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ OAEP is Optimal Asymmetric Encryption Padding.
7878
Use if you need KEM (encrypt/decrypt).
7979

8080
```ts
81+
import * as rsa from 'micro-rsa-dsa-dh/rsa.js';
8182
const alice = rsa.keygen(2048);
8283
const oaep = rsa.OAEP(sha256, rsa.mgf1(sha256));
8384
const msg = new Uint8Array([1, 2, 3]);
@@ -90,6 +91,7 @@ deepStrictEqual(oaep.decrypt(alice.privateKey, encrypted), msg);
9091
Use if you need signatures (sign/verify).
9192

9293
```ts
94+
import * as rsa from 'micro-rsa-dsa-dh/rsa.js';
9395
const alice = rsa.keygen(2048);
9496
const pss = rsa.PSS(sha256, rsa.mgf1(sha256));
9597
const msg = new Uint8Array([1, 2, 3]);
@@ -104,6 +106,7 @@ This is old standard, OAEP/PSS is better.
104106
Signatures:
105107

106108
```ts
109+
import * as rsa from 'micro-rsa-dsa-dh/rsa.js';
107110
const alice = rsa.keygen(2048);
108111
const pkcs = rsa.PKCS1_SHA256;
109112
const msg = new Uint8Array([1, 2, 3]);
@@ -116,6 +119,7 @@ KEM (vulnerable [[1]](https://crypto.stackexchange.com/questions/12688/can-you-e
116119
):
117120

118121
```ts
122+
import * as rsa from 'micro-rsa-dsa-dh/rsa.js';
119123
const alice = rsa.keygen(2048);
120124
const pkcs = rsa.PKCS1_KEM;
121125
const msg = new Uint8Array([1, 2, 3]);
@@ -132,16 +136,17 @@ Same as ECDH, seems safe if pre-defined groups are used. Cons:
132136
- Using custom non-standard groups can make algorithm weak
133137

134138
```ts
135-
const nobleDH = rsa.DH('modp18');
136-
const alicePriv = nobleDH.randomPrivateKey();
137-
const alicePub = nobleDH.getPublicKey(alicePriv);
139+
import { DH, DHGroups } from 'micro-rsa-dsa-dh/dh.js';
140+
const dh = DH('modp18');
141+
const alicePriv = dh.randomPrivateKey();
142+
const alicePub = dh.getPublicKey(alicePriv);
138143

139-
const bobPriv = nobleDH.randomPrivateKey();
140-
const bobPub = nobleDH.getPublicKey(bobPriv);
144+
const bobPriv = dh.randomPrivateKey();
145+
const bobPub = dh.getPublicKey(bobPriv);
141146

142147
deepStrictEqual(
143-
nobleDH.getSharedSecret(alicePriv, bobPub),
144-
nobleDH.getSharedSecret(bobPriv, alicePub)
148+
dh.getSharedSecret(alicePriv, bobPub),
149+
dh.getSharedSecret(bobPriv, alicePub)
145150
);
146151
```
147152

@@ -158,28 +163,29 @@ Same as ECDSA, but with big numbers. Cons:
158163
- Harder to protect from timing attacks
159164

160165
```ts
166+
import * as dsa from 'micro-rsa-dsa-dh/dsa.js';
161167
// 1. Params
162168
// Carol generates random params
163-
const carolParams = rsa.genDSAParams(2048, 256, sha256, 1);
169+
const carolParams = dsa.genDSAParams(2048, 256, sha256, 1);
164170
// Instead of sending primes to Alice and Bob (which can be insecure), she sends seed
165171
// This ensures that params are not constructed primes, but generated randomly:
166172
// Alice and Bob can use these params without trusting Carol.
167173
const seed = carolParams.domainParameterSeed;
168174

169-
const aliceParams = rsa.genDSAParams(2048, 256, sha256, 1, seed);
175+
const aliceParams = dsa.genDSAParams(2048, 256, sha256, 1, seed);
170176
deepStrictEqual(aliceParams, carolParams); // Same params as Carol!
171177

172-
const bobParams = rsa.genDSAParams(2048, 256, sha256, 1, seed);
178+
const bobParams = dsa.genDSAParams(2048, 256, sha256, 1, seed);
173179
deepStrictEqual(aliceParams, bobParams); // Now Bob has same params too!
174180

175181
// 2. Keys
176-
const aliceDSA = rsa.DSA(aliceParams);
182+
const aliceDSA = dsa.DSA(aliceParams);
177183
const alicePrivKey = aliceDSA.randomPrivateKey();
178184
const alicePubKey = aliceDSA.getPublicKey(alicePrivKey); // Alice generates public key and sends to Bob
179185
const msg = new Uint8Array([1, 2, 3, 4, 5]);
180186
const sig = aliceDSA.sign(alicePrivKey, msg); // Alice signs message
181187

182-
const bobDSA = rsa.DSA(bobParams);
188+
const bobDSA = dsa.DSA(bobParams);
183189
// Now Bob can verify that message was sent by Alice (and not Carol for example).
184190
deepStrictEqual(bobDSA.verify(alicePubKey, msg, sig), true);
185191
```
@@ -189,9 +195,10 @@ deepStrictEqual(bobDSA.verify(alicePubKey, msg, sig), true);
189195
Mostly for educational purpose: almost nobody uses it.
190196

191197
```ts
198+
import { ElGamal, genElGamalParams } from 'micro-rsa-dsa-dh/elgamal.js';
192199
// NOTE: this is super slow! 512: 1s, 1024: 20s, 2048: 1046s
193-
const params = rsa.genElGamalParams(512);
194-
const elgamal = rsa.ElGamal(params);
200+
const params = genElGamalParams(512);
201+
const elgamal = ElGamal(params);
195202

196203
const alicePriv = elgamal.randomPrivateKey();
197204
const alicePub = elgamal.getPublicKey(alicePriv);

0 commit comments

Comments
 (0)