Commit 856ccd7
authored
fix!: remove node-forge dependency from @libp2p/crypto (#2355)
TLDR: the bundle size has been reduced by about 1/3rd
- parsing/creating PEM/pkix/pkcs1 files is now done by asn1.js
- Streaming AES-CTR ciphers are now in [@libp2p/aes-ctr](https://github.com/libp2p/js-libp2p-aes-ctr)
- RSA encryption/decryption and PEM import/export are now in [@libp2p/rsa](https://github.com/libp2p/js-libp2p-rsa)
## AES-CTR
WebCrypto [doesn't support streaming ciphers](w3c/webcrypto#73).
We have a node-forge-backed shim that allows using streaming AES-CTR in browsers but we don't use it anywhere, so this has been split out into it's own module as `@libp2p/aes-ctr`.
## RSA encrypt/decrypt
This was added to `@libp2p/crypto` to [support webrtc-stardust](libp2p/js-libp2p-crypto#125 (comment)) but that effort didn't go anywhere and we don't use these methods anywhere else in the stack.
For reasons lost to the mists of time, we chose to use a [padding algorithm](https://github.com/libp2p/js-libp2p-crypto/blob/3d0fd234deb73984ddf0f7c9959bbca92194926a/src/keys/rsa.ts#L59) that WebCrypto doesn't support so node-forge (or some other userland implemenation) will always be necessary in browsers, so these ops have been pulled out into `@libp2p/rsa` which people can use if they need it.
This is now done by manipulating the asn1 structures directly.
## PEM/pkix/pkcs1
The previous PEM import/export is also ported to `@libp2p/crypto-rsa` because it seems to handle more weird edge cases introduced by OpenSSL.
These could be handled in `@libp2p/crypto` eventually but for now it at least supports round-tripping it's own PEM files.
Fixes #2086
BREAKING CHANGE: Legacy RSA operations are now in @libp2p/rsa, streaming AES-CTR ciphers are in @libp2p/aes-ctr1 parent ddaa59a commit 856ccd7
24 files changed
Lines changed: 515 additions & 829 deletions
File tree
- packages/crypto
- src
- aes
- keys
- test
- aes
- fixtures
- keys
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | 54 | | |
59 | 55 | | |
60 | 56 | | |
| |||
69 | 65 | | |
70 | 66 | | |
71 | 67 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 68 | + | |
76 | 69 | | |
77 | 70 | | |
78 | 71 | | |
| |||
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
95 | | - | |
| 88 | + | |
| 89 | + | |
96 | 90 | | |
97 | | - | |
98 | 91 | | |
99 | | - | |
| 92 | + | |
100 | 93 | | |
101 | 94 | | |
102 | 95 | | |
| |||
106 | 99 | | |
107 | 100 | | |
108 | 101 | | |
109 | | - | |
110 | 102 | | |
111 | 103 | | |
112 | 104 | | |
113 | 105 | | |
114 | 106 | | |
115 | | - | |
| 107 | + | |
| 108 | + | |
116 | 109 | | |
117 | 110 | | |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | | - | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 14 | | |
20 | 15 | | |
21 | 16 | | |
22 | 17 | | |
23 | 18 | | |
24 | 19 | | |
| 20 | + | |
25 | 21 | | |
26 | 22 | | |
27 | 23 | | |
| |||
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 148 | + | |
| 149 | + | |
151 | 150 | | |
152 | | - | |
153 | | - | |
154 | | - | |
| 151 | + | |
| 152 | + | |
155 | 153 | | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | | - | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
130 | 128 | | |
131 | 129 | | |
132 | 130 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | 131 | | |
161 | 132 | | |
162 | 133 | | |
| |||
0 commit comments