@protontech/openpgp 4.10.8 → 5.3.1

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.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31375 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43943 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43880 -0
  26. package/dist/openpgp.js +41077 -41609
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43868 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +889 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61152
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40071
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -232
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -378
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -888
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -161
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -468
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -786
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -84
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3491
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2577
  166. package/test/general/packet.js +0 -950
  167. package/test/general/signature.js +0 -1715
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
@@ -1,251 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
- const chai = require('chai');
3
-
4
- const elliptic_data = require('./elliptic_data');
5
-
6
- chai.use(require('chai-as-promised'));
7
-
8
- const expect = chai.expect;
9
- const key_data = elliptic_data.key_data;
10
- /* eslint-disable no-invalid-this */
11
- describe('Elliptic Curve Cryptography @lightweight', function () {
12
- const elliptic_curves = openpgp.crypto.publicKey.elliptic;
13
-
14
- const signature_data = {
15
- priv: new Uint8Array([
16
- 0x14, 0x2B, 0xE2, 0xB7, 0x4D, 0xBD, 0x1B, 0x22,
17
- 0x4D, 0xDF, 0x96, 0xA4, 0xED, 0x8E, 0x5B, 0xF9,
18
- 0xBD, 0xD3, 0xFE, 0xAE, 0x3F, 0xB2, 0xCF, 0xEE,
19
- 0xA7, 0xDB, 0xD0, 0x58, 0xA7, 0x47, 0xF8, 0x7C
20
- ]),
21
- pub: new Uint8Array([
22
- 0x04,
23
- 0xD3, 0x36, 0x11, 0xF9, 0xF9, 0xAB, 0x39, 0x23,
24
- 0x15, 0xB9, 0x71, 0x7B, 0x2A, 0x0B, 0xA6, 0x6D,
25
- 0x39, 0x6D, 0x64, 0x87, 0x22, 0x9A, 0xA3, 0x0A,
26
- 0x55, 0x27, 0x14, 0x2E, 0x1C, 0x61, 0xA2, 0x8A,
27
- 0xDA, 0x4E, 0x8F, 0xCE, 0x04, 0xBE, 0xE2, 0xC3,
28
- 0x82, 0x0B, 0x21, 0x4C, 0xBC, 0xED, 0x0E, 0xE2,
29
- 0xF1, 0x14, 0x33, 0x9A, 0x86, 0x5F, 0xC6, 0xF9,
30
- 0x8E, 0x95, 0x24, 0x10, 0x1F, 0x0F, 0x13, 0xE4
31
- ]),
32
- message: new Uint8Array([
33
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
35
- ]),
36
- hashed: new Uint8Array([
37
- 0xbe, 0x45, 0xcb, 0x26, 0x05, 0xbf, 0x36, 0xbe,
38
- 0xbd, 0xe6, 0x84, 0x84, 0x1a, 0x28, 0xf0, 0xfd,
39
- 0x43, 0xc6, 0x98, 0x50, 0xa3, 0xdc, 0xe5, 0xfe,
40
- 0xdb, 0xa6, 0x99, 0x28, 0xee, 0x3a, 0x89, 0x91
41
- ]),
42
- signature: {
43
- r: new Uint8Array([
44
- 0xF1, 0x78, 0x1C, 0xA5, 0x13, 0x21, 0x0C, 0xBA,
45
- 0x6F, 0x18, 0x5D, 0xB3, 0x01, 0xE2, 0x17, 0x1B,
46
- 0x67, 0x65, 0x7F, 0xC6, 0x1F, 0x50, 0x12, 0xFB,
47
- 0x2F, 0xD3, 0xA4, 0x29, 0xE3, 0xC2, 0x44, 0x9F
48
- ]),
49
- s: new Uint8Array([
50
- 0x7F, 0x08, 0x69, 0x6D, 0xBB, 0x1B, 0x9B, 0xF2,
51
- 0x62, 0x1C, 0xCA, 0x80, 0xC6, 0x15, 0xB2, 0xAE,
52
- 0x60, 0x50, 0xD1, 0xA7, 0x1B, 0x32, 0xF3, 0xB1,
53
- 0x01, 0x0B, 0xDF, 0xC6, 0xAB, 0xF0, 0xEB, 0x01
54
- ])
55
- }
56
- };
57
- describe('Basic Operations', function () {
58
- it('Creating curve from name or oid', function (done) {
59
- Object.keys(openpgp.enums.curve).forEach(function(name_or_oid) {
60
- expect(new elliptic_curves.Curve(name_or_oid)).to.exist;
61
- });
62
- Object.values(openpgp.enums.curve).forEach(function(name_or_oid) {
63
- expect(new elliptic_curves.Curve(name_or_oid)).to.exist;
64
- });
65
- done();
66
- });
67
- it('Creating KeyPair', function () {
68
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
69
- this.skip();
70
- }
71
- const names = openpgp.config.use_indutny_elliptic ? ['p256', 'p384', 'p521', 'secp256k1', 'curve25519', 'brainpoolP256r1', 'brainpoolP384r1', 'brainpoolP512r1'] :
72
- ['p256', 'p384', 'p521', 'curve25519'];
73
- return Promise.all(names.map(function (name) {
74
- const curve = new elliptic_curves.Curve(name);
75
- return curve.genKeyPair().then(keyPair => {
76
- expect(keyPair).to.exist;
77
- });
78
- }));
79
- });
80
- it('Signature verification', function (done) {
81
- expect(
82
- elliptic_curves.ecdsa.verify('p256', 8, signature_data.signature, signature_data.message, signature_data.pub, signature_data.hashed)
83
- ).to.eventually.be.true.notify(done);
84
- });
85
- it('Invalid signature', function (done) {
86
- expect(
87
- elliptic_curves.ecdsa.verify('p256', 8, signature_data.signature, signature_data.message, key_data.p256.pub, signature_data.hashed)
88
- ).to.eventually.be.false.notify(done);
89
- });
90
- it('Signature generation', function () {
91
- return elliptic_curves.ecdsa.sign('p256', 8, signature_data.message, key_data.p256.pub, key_data.p256.priv, signature_data.hashed).then(async signature => {
92
- await expect(
93
- elliptic_curves.ecdsa.verify('p256', 8, signature, signature_data.message, key_data.p256.pub, signature_data.hashed)
94
- ).to.eventually.be.true;
95
- });
96
- });
97
- it('Shared secret generation', async function () {
98
- const curve = new elliptic_curves.Curve('p256');
99
- const { sharedKey: shared1 } = await elliptic_curves.ecdh.genPrivateEphemeralKey(curve, signature_data.pub, key_data.p256.pub, key_data.p256.priv);
100
- const { sharedKey: shared2 } = await elliptic_curves.ecdh.genPrivateEphemeralKey(curve, key_data.p256.pub, signature_data.pub, signature_data.priv);
101
- expect(shared1).to.deep.equal(shared2);
102
- });
103
- });
104
- describe('ECDSA signature', function () {
105
- const verify_signature = async function (oid, hash, r, s, message, pub) {
106
- if (openpgp.util.isString(message)) {
107
- message = openpgp.util.str_to_Uint8Array(message);
108
- } else if (!openpgp.util.isUint8Array(message)) {
109
- message = new Uint8Array(message);
110
- }
111
- const ecdsa = elliptic_curves.ecdsa;
112
- return ecdsa.verify(
113
- oid, hash, { r: new Uint8Array(r), s: new Uint8Array(s) }, message, new Uint8Array(pub), await openpgp.crypto.hash.digest(hash, message)
114
- );
115
- };
116
- const verify_signature_elliptic = async function (oid, hash, r, s, message, pub) {
117
- if (openpgp.util.isString(message)) {
118
- message = openpgp.util.str_to_Uint8Array(message);
119
- } else if (!openpgp.util.isUint8Array(message)) {
120
- message = new Uint8Array(message);
121
- }
122
- const ecdsa = elliptic_curves.ecdsa;
123
- return ecdsa.ellipticVerify(
124
- new elliptic_curves.Curve(oid), { r: new Uint8Array(r), s: new Uint8Array(s) }, await openpgp.crypto.hash.digest(hash, message), new Uint8Array(pub)
125
- );
126
- };
127
- const secp256k1_point = new Uint8Array([
128
- 0x04,
129
- 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC,
130
- 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07,
131
- 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9,
132
- 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98,
133
- 0x48, 0x3A, 0xDA, 0x77, 0x26, 0xA3, 0xC4, 0x65,
134
- 0x5D, 0xA4, 0xFB, 0xFC, 0x0E, 0x11, 0x08, 0xA8,
135
- 0xFD, 0x17, 0xB4, 0x48, 0xA6, 0x85, 0x54, 0x19,
136
- 0x9C, 0x47, 0xD0, 0x8F, 0xFB, 0x10, 0xD4, 0xB8
137
- ]);
138
- const secp256k1_invalid_point = new Uint8Array([
139
- 0x04,
140
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
146
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
147
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
148
- ]);
149
- const secp256k1_invalid_point_format = new Uint8Array([
150
- 0x04,
151
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
152
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
153
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
154
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
155
- ]);
156
- it('Invalid curve oid', function () {
157
- return Promise.all([
158
- expect(verify_signature(
159
- 'invalid oid', 8, [], [], [], []
160
- )).to.be.rejectedWith(Error, /Not valid curve/),
161
- expect(verify_signature(
162
- "\x00", 8, [], [], [], []
163
- )).to.be.rejectedWith(Error, /Not valid curve/)
164
- ]);
165
- });
166
- it('Invalid public key', async function () {
167
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
168
- this.skip();
169
- }
170
- if (openpgp.util.getNodeCrypto()) {
171
- await expect(verify_signature(
172
- 'secp256k1', 8, [], [], [], []
173
- )).to.eventually.be.false;
174
- await expect(verify_signature(
175
- 'secp256k1', 8, [], [], [], secp256k1_invalid_point_format
176
- )).to.eventually.be.false;
177
- }
178
- if (openpgp.config.use_indutny_elliptic) {
179
- return Promise.all([
180
- expect(verify_signature_elliptic(
181
- 'secp256k1', 8, [], [], [], []
182
- )).to.be.rejectedWith(Error, /Unknown point format/),
183
- expect(verify_signature_elliptic(
184
- 'secp256k1', 8, [], [], [], secp256k1_invalid_point_format
185
- )).to.be.rejectedWith(Error, /Unknown point format/)
186
- ]);
187
- }
188
- });
189
- it('Invalid point', function () {
190
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
191
- this.skip();
192
- }
193
- if (openpgp.util.getNodeCrypto()) {
194
- expect(verify_signature(
195
- 'secp256k1', 8, [], [], [], secp256k1_invalid_point
196
- )).to.eventually.be.false;
197
- }
198
- if (openpgp.config.use_indutny_elliptic) {
199
- expect(verify_signature_elliptic(
200
- 'secp256k1', 8, [], [], [], secp256k1_invalid_point
201
- )).to.be.rejectedWith(Error, /Invalid elliptic public key/);
202
- }
203
- });
204
- it('Invalid signature', function (done) {
205
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
206
- this.skip();
207
- }
208
- expect(verify_signature(
209
- 'secp256k1', 8, [], [], [], secp256k1_point
210
- )).to.eventually.be.false.notify(done);
211
- });
212
-
213
- const p384_message = new Uint8Array([
214
- 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
215
- 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
216
- ]);
217
- const p384_r = new Uint8Array([
218
- 0x9D, 0x07, 0xCA, 0xA5, 0x9F, 0xBE, 0xB8, 0x76,
219
- 0xA9, 0xB9, 0x66, 0x0F, 0xA0, 0x64, 0x70, 0x5D,
220
- 0xE6, 0x37, 0x40, 0x43, 0xD0, 0x8E, 0x40, 0xA8,
221
- 0x8B, 0x37, 0x83, 0xE7, 0xBC, 0x1C, 0x4C, 0x86,
222
- 0xCB, 0x3C, 0xD5, 0x9B, 0x68, 0xF0, 0x65, 0xEB,
223
- 0x3A, 0xB6, 0xD6, 0xA6, 0xCF, 0x85, 0x3D, 0xA9
224
- ]);
225
- const p384_s = new Uint8Array([
226
- 0x32, 0x85, 0x78, 0xCC, 0xEA, 0xC5, 0x22, 0x83,
227
- 0x10, 0x73, 0x1C, 0xCF, 0x10, 0x8A, 0x52, 0x11,
228
- 0x8E, 0x49, 0x9E, 0xCF, 0x7E, 0x17, 0x18, 0xC3,
229
- 0x11, 0x11, 0xBC, 0x0F, 0x6D, 0x98, 0xE2, 0x16,
230
- 0x68, 0x58, 0x23, 0x1D, 0x11, 0xEF, 0x3D, 0x21,
231
- 0x30, 0x75, 0x24, 0x39, 0x48, 0x89, 0x03, 0xDC
232
- ]);
233
- it('Valid signature', function (done) {
234
- expect(verify_signature('p384', 8, p384_r, p384_s, p384_message, key_data.p384.pub))
235
- .to.eventually.be.true.notify(done);
236
- });
237
- it('Sign and verify message', function () {
238
- const curve = new elliptic_curves.Curve('p521');
239
- return curve.genKeyPair().then(async keyPair => {
240
- const keyPublic = new Uint8Array(keyPair.publicKey);
241
- const keyPrivate = new Uint8Array(keyPair.privateKey);
242
- const oid = curve.oid;
243
- const message = p384_message;
244
- return elliptic_curves.ecdsa.sign(oid, 10, message, keyPublic, keyPrivate, await openpgp.crypto.hash.digest(10, message)).then(async signature => {
245
- await expect(elliptic_curves.ecdsa.verify(oid, 10, signature, message, keyPublic, await openpgp.crypto.hash.digest(10, message)))
246
- .to.eventually.be.true;
247
- });
248
- });
249
- });
250
- });
251
- });
@@ -1,102 +0,0 @@
1
- const elliptic_data = {
2
- key_data: {
3
- p256: {
4
- priv: new Uint8Array([
5
- 0x2B, 0x48, 0x2B, 0xE9, 0x88, 0x74, 0xE9, 0x49,
6
- 0x1F, 0x89, 0xCC, 0xFF, 0x0A, 0x26, 0x05, 0xA2,
7
- 0x3C, 0x2A, 0x35, 0x25, 0x26, 0x11, 0xD7, 0xEA,
8
- 0xA1, 0xED, 0x29, 0x95, 0xB5, 0xE1, 0x5F, 0x1D
9
- ]),
10
- pub: new Uint8Array([
11
- 0x04,
12
- 0x80, 0x2C, 0x40, 0x76, 0x31, 0x20, 0xB6, 0x9B,
13
- 0x48, 0x3B, 0x05, 0xEB, 0x6C, 0x1E, 0x3F, 0x49,
14
- 0x84, 0xF7, 0xD2, 0xAD, 0x16, 0xA1, 0x6F, 0x62,
15
- 0xFD, 0xCA, 0xEC, 0xB4, 0xA0, 0xBD, 0x4C, 0x1A,
16
- 0x6F, 0xAA, 0xE7, 0xFD, 0xC4, 0x7D, 0x89, 0xCC,
17
- 0x06, 0xCA, 0xFE, 0xAE, 0xCD, 0x0E, 0x9E, 0x62,
18
- 0x57, 0xA4, 0xC3, 0xE7, 0x5E, 0x69, 0x10, 0xEE,
19
- 0x67, 0xC2, 0x09, 0xF9, 0xEF, 0xE7, 0x9E, 0x56
20
- ])
21
- },
22
- p384: {
23
- priv: new Uint8Array([
24
- 0xB5, 0x38, 0xDA, 0xF3, 0x77, 0x58, 0x3F, 0x94,
25
- 0x5B, 0xC2, 0xCA, 0xC6, 0xA9, 0xFC, 0xAA, 0x3F,
26
- 0x97, 0xB0, 0x54, 0x26, 0x10, 0xB4, 0xEC, 0x2A,
27
- 0xA7, 0xC1, 0xA3, 0x4B, 0xC0, 0xBD, 0xFE, 0x3E,
28
- 0xF1, 0xBE, 0x76, 0xCB, 0xE8, 0xAB, 0x3B, 0xBD,
29
- 0xB6, 0x84, 0xC7, 0x8B, 0x91, 0x2F, 0x76, 0x8B
30
- ]),
31
- pub: new Uint8Array([
32
- 0x04,
33
- 0x44, 0x83, 0xA0, 0x3E, 0x5B, 0x0A, 0x0D, 0x9B,
34
- 0xA0, 0x06, 0xDF, 0x38, 0xC7, 0x64, 0xCD, 0x62,
35
- 0x7D, 0x5E, 0x3D, 0x3B, 0x50, 0xF5, 0x06, 0xC7,
36
- 0xF7, 0x9B, 0xF0, 0xDE, 0xB1, 0x0C, 0x64, 0x74,
37
- 0x0D, 0x03, 0x67, 0x24, 0xA0, 0xFF, 0xD1, 0x3D,
38
- 0x03, 0x96, 0x48, 0xE7, 0x73, 0x5E, 0xF1, 0xC0,
39
- 0x62, 0xCC, 0x33, 0x5A, 0x2A, 0x66, 0xA7, 0xAB,
40
- 0xCA, 0x77, 0x52, 0xB8, 0xCD, 0xB5, 0x91, 0x16,
41
- 0xAF, 0x42, 0xBB, 0x79, 0x0A, 0x59, 0x51, 0x68,
42
- 0x8E, 0xEA, 0x32, 0x7D, 0x4A, 0x4A, 0xBB, 0x26,
43
- 0x13, 0xFB, 0x95, 0xC0, 0xB1, 0xA4, 0x54, 0xCA,
44
- 0xFA, 0x85, 0x8A, 0x4B, 0x58, 0x7C, 0x61, 0x39
45
- ])
46
- },
47
- p521: {
48
- priv: new Uint8Array([
49
- 0x00, 0xBB, 0x35, 0x27, 0xBC, 0xD6, 0x7E, 0x35,
50
- 0xD5, 0xC5, 0x99, 0xC9, 0xB4, 0x6C, 0xEE, 0xDE,
51
- 0x79, 0x2D, 0x77, 0xBD, 0x0A, 0x08, 0x9A, 0xC2,
52
- 0x21, 0xF8, 0x35, 0x1C, 0x49, 0x5C, 0x40, 0x11,
53
- 0xAC, 0x95, 0x2A, 0xEE, 0x91, 0x3A, 0x60, 0x5A,
54
- 0x25, 0x5A, 0x95, 0x38, 0xDC, 0xEB, 0x59, 0x8E,
55
- 0x33, 0xAD, 0xC0, 0x0B, 0x56, 0xB1, 0x06, 0x8C,
56
- 0x57, 0x48, 0xA3, 0x73, 0xDB, 0xE0, 0x19, 0x50,
57
- 0x2E, 0x79
58
- ]),
59
- pub: new Uint8Array([
60
- 0x04,
61
- 0x01, 0x0D, 0xD5, 0xCA, 0xD8, 0xB0, 0xEF, 0x9F,
62
- 0x2B, 0x7E, 0x58, 0x99, 0xDE, 0x05, 0xF6, 0xF6,
63
- 0x64, 0x6B, 0xCD, 0x59, 0x2E, 0x39, 0xB8, 0x82,
64
- 0xB3, 0x13, 0xE6, 0x7D, 0x50, 0x85, 0xC3, 0xFA,
65
- 0x93, 0xA5, 0x3F, 0x92, 0x85, 0x42, 0x36, 0xC0,
66
- 0x83, 0xC9, 0xA4, 0x38, 0xB3, 0xD1, 0x99, 0xDA,
67
- 0xE1, 0x02, 0x37, 0x7A, 0x3A, 0xC2, 0xB4, 0x55,
68
- 0xEC, 0x1C, 0x0F, 0x00, 0x97, 0xFC, 0x75, 0x93,
69
- 0xFE, 0x87, 0x00, 0x7D, 0xBE, 0x1A, 0xF5, 0xF9,
70
- 0x57, 0x5C, 0xF2, 0x50, 0x2D, 0x14, 0x32, 0xEE,
71
- 0x9B, 0xBE, 0xB3, 0x0E, 0x12, 0x2F, 0xF8, 0x85,
72
- 0x11, 0x1A, 0x4F, 0x88, 0x50, 0xA4, 0xDB, 0x37,
73
- 0xA6, 0x53, 0x5C, 0xB7, 0x87, 0xA6, 0x06, 0x21,
74
- 0x15, 0xCC, 0x12, 0xC0, 0x1C, 0x83, 0x6F, 0x7B,
75
- 0x5A, 0x8A, 0x36, 0x4E, 0x46, 0x9E, 0x54, 0x3F,
76
- 0xE2, 0xF7, 0xED, 0x63, 0xC9, 0x92, 0xA4, 0x38,
77
- 0x2B, 0x9C, 0xE2, 0xB7
78
- ])
79
- },
80
- secp256k1: {
81
- priv: new Uint8Array([
82
- 0x9E, 0xB0, 0x30, 0xD6, 0xE1, 0xCE, 0xAA, 0x0B,
83
- 0x7B, 0x8F, 0xDE, 0x5D, 0x91, 0x4D, 0xDC, 0xA0,
84
- 0xAD, 0x05, 0xAB, 0x8F, 0x87, 0x9B, 0x57, 0x48,
85
- 0xAE, 0x8A, 0xE0, 0xF9, 0x39, 0xBD, 0x24, 0x00
86
- ]),
87
- pub: new Uint8Array([
88
- 0x04,
89
- 0xA8, 0x02, 0x35, 0x2C, 0xB7, 0x24, 0x95, 0x51,
90
- 0x0A, 0x65, 0x26, 0x7D, 0xDF, 0xEA, 0x64, 0xB3,
91
- 0xA8, 0xE1, 0x4F, 0xDD, 0x12, 0x84, 0x7E, 0x59,
92
- 0xDB, 0x81, 0x0F, 0x89, 0xED, 0xFB, 0x29, 0xFB,
93
- 0x07, 0x60, 0x29, 0x7D, 0x39, 0x8F, 0xB8, 0x68,
94
- 0xF0, 0xFD, 0xA6, 0x67, 0x83, 0x55, 0x75, 0x7D,
95
- 0xB8, 0xFD, 0x0B, 0xDF, 0x76, 0xCE, 0xBC, 0x95,
96
- 0x4B, 0x92, 0x26, 0xFC, 0xAA, 0x7A, 0x7C, 0x3F
97
- ])
98
- }
99
- }
100
- };
101
-
102
- module.exports = elliptic_data;
@@ -1,5 +0,0 @@
1
- describe('Hash', function () {
2
- require('./md5.js');
3
- require('./ripemd.js');
4
- require('./sha.js');
5
- });
@@ -1,16 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../../dist/openpgp');
2
-
3
- const chai = require('chai');
4
-
5
- const { util } = openpgp;
6
- const md5 = openpgp.crypto.hash.md5;
7
- const { expect } = chai;
8
-
9
- it('MD5 with test vectors from RFC 1321', async function() {
10
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array(''))), 'MD5("") = d41d8cd98f00b204e9800998ecf8427e')).to.equal('d41d8cd98f00b204e9800998ecf8427e');
11
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array('abc'))), 'MD5("a") = 0cc175b9c0f1b6a831c399e269772661')).to.equal('900150983cd24fb0d6963f7d28e17f72');
12
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array('message digest'))), 'MD5("message digest") = f96b697d7cb7938d525a2f31aaf161d0')).to.equal('f96b697d7cb7938d525a2f31aaf161d0');
13
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array('abcdefghijklmnopqrstuvwxyz'))), 'MD5("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b')).to.equal('c3fcd3d76192e4007dfb496cca67e13b');
14
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'))), 'MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f')).to.equal('d174ab98d277d9f5a5611c2c9f419d9f');
15
- expect(util.str_to_hex(util.Uint8Array_to_str(await md5(util.str_to_Uint8Array('12345678901234567890123456789012345678901234567890123456789012345678901234567890'))), 'MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a')).to.equal('57edf4a22be3c955ac49da2e2107b67a');
16
- });
@@ -1,14 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../../dist/openpgp');
2
-
3
- const chai = require('chai');
4
-
5
- const { util } = openpgp;
6
- const rmdString = openpgp.crypto.hash.ripemd;
7
- const { expect } = chai;
8
-
9
- it("RIPE-MD 160 bits with test vectors from https://homes.esat.kuleuven.be/~bosselae/ripemd160.html", async function() {
10
- expect(util.str_to_hex(util.Uint8Array_to_str(await rmdString(util.str_to_Uint8Array(''))), 'RMDstring("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31')).to.equal('9c1185a5c5e9fc54612808977ee8f548b2258d31');
11
- expect(util.str_to_hex(util.Uint8Array_to_str(await rmdString(util.str_to_Uint8Array('a'))), 'RMDstring("a") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe')).to.equal('0bdc9d2d256b3ee9daae347be6f4dc835a467ffe');
12
- expect(util.str_to_hex(util.Uint8Array_to_str(await rmdString(util.str_to_Uint8Array('abc'))), 'RMDstring("abc") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc')).to.equal('8eb208f7e05d987a9b044a8e98c6b087f15a0bfc');
13
- expect(util.str_to_hex(util.Uint8Array_to_str(await rmdString(util.str_to_Uint8Array('message digest'))), 'RMDstring("message digest") = 5d0689ef49d2fae572b881b123a85ffa21595f36')).to.equal('5d0689ef49d2fae572b881b123a85ffa21595f36');
14
- });
@@ -1,20 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../../dist/openpgp');
2
-
3
- const chai = require('chai');
4
-
5
- const { util } = openpgp;
6
- const { hash } = openpgp.crypto;
7
- const { expect } = chai;
8
-
9
- it('SHA* with test vectors from NIST FIPS 180-2', async function() {
10
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha1(util.str_to_Uint8Array('abc'))), 'hash.sha1("abc") = a9993e364706816aba3e25717850c26c9cd0d89d')).to.equal('a9993e364706816aba3e25717850c26c9cd0d89d');
11
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha1(util.str_to_Uint8Array('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'))), 'hash.sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 84983e441c3bd26ebaae4aa1f95129e5e54670f1')).to.equal('84983e441c3bd26ebaae4aa1f95129e5e54670f1');
12
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha224(util.str_to_Uint8Array('abc'))), 'hash.sha224("abc") = 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7')).to.equal('23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7');
13
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha224(util.str_to_Uint8Array('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'))), 'hash.sha224("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525')).to.equal('75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525');
14
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha256(util.str_to_Uint8Array('abc'))), 'hash.sha256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')).to.equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad');
15
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha256(util.str_to_Uint8Array('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'))), 'hash.sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1')).to.equal('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1');
16
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha384(util.str_to_Uint8Array('abc'))), 'hash.sha384("abc") = cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7')).to.equal('cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7');
17
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha384(util.str_to_Uint8Array('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'))), 'hash.sha384("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b')).to.equal('3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b');
18
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha512(util.str_to_Uint8Array('abc'))), 'hash.sha512("abc") = ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f')).to.equal('ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f');
19
- expect(util.str_to_hex(util.Uint8Array_to_str(await hash.sha512(util.str_to_Uint8Array('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'))), 'hash.sha512("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445')).to.equal('204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445');
20
- });
@@ -1,14 +0,0 @@
1
- describe('Crypto', function () {
2
- require('./cipher');
3
- require('./hash');
4
- require('./random.js');
5
- require('./crypto.js');
6
- require('./elliptic.js');
7
- require('./ecdh.js');
8
- require('./pkcs5.js');
9
- require('./aes_kw.js');
10
- require('./eax.js');
11
- require('./ocb.js');
12
- require('./rsa.js');
13
- require('./validate.js');
14
- });
@@ -1,183 +0,0 @@
1
- // Modified by ProtonTech AG
2
-
3
- // Adapted from https://github.com/artjomb/cryptojs-extension/blob/8c61d159/test/eax.js
4
-
5
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
6
-
7
- const chai = require('chai');
8
- chai.use(require('chai-as-promised'));
9
-
10
- const expect = chai.expect;
11
-
12
- describe('Symmetric AES-OCB', function() {
13
- it('Passes all test vectors', async function() {
14
- const K = '000102030405060708090A0B0C0D0E0F';
15
- const keyBytes = openpgp.util.hex_to_Uint8Array(K);
16
-
17
- const vectors = [
18
- // From https://tools.ietf.org/html/rfc7253#appendix-A
19
- {
20
- N: 'BBAA99887766554433221100',
21
- A: '',
22
- P: '',
23
- C: '785407BFFFC8AD9EDCC5520AC9111EE6'
24
- },
25
- {
26
- N: 'BBAA99887766554433221101',
27
- A: '0001020304050607',
28
- P: '0001020304050607',
29
- C: '6820B3657B6F615A5725BDA0D3B4EB3A257C9AF1F8F03009'
30
- },
31
- {
32
- N: 'BBAA99887766554433221102',
33
- A: '0001020304050607',
34
- P: '',
35
- C: '81017F8203F081277152FADE694A0A00'
36
- },
37
- {
38
- N: 'BBAA99887766554433221103',
39
- A: '',
40
- P: '0001020304050607',
41
- C: '45DD69F8F5AAE72414054CD1F35D82760B2CD00D2F99BFA9'
42
- },
43
- {
44
- N: 'BBAA99887766554433221104',
45
- A: '000102030405060708090A0B0C0D0E0F',
46
- P: '000102030405060708090A0B0C0D0E0F',
47
- C: '571D535B60B277188BE5147170A9A22C3AD7A4FF3835B8C5701C1CCEC8FC3358'
48
- },
49
- {
50
- N: 'BBAA99887766554433221105',
51
- A: '000102030405060708090A0B0C0D0E0F',
52
- P: '',
53
- C: '8CF761B6902EF764462AD86498CA6B97'
54
- },
55
- {
56
- N: 'BBAA99887766554433221106',
57
- A: '',
58
- P: '000102030405060708090A0B0C0D0E0F',
59
- C: '5CE88EC2E0692706A915C00AEB8B2396F40E1C743F52436BDF06D8FA1ECA343D'
60
- },
61
- {
62
- N: 'BBAA99887766554433221107',
63
- A: '000102030405060708090A0B0C0D0E0F1011121314151617',
64
- P: '000102030405060708090A0B0C0D0E0F1011121314151617',
65
- C: '1CA2207308C87C010756104D8840CE1952F09673A448A122C92C62241051F57356D7F3C90BB0E07F'
66
- },
67
- {
68
- N: 'BBAA99887766554433221108',
69
- A: '000102030405060708090A0B0C0D0E0F1011121314151617',
70
- P: '',
71
- C: '6DC225A071FC1B9F7C69F93B0F1E10DE'
72
- },
73
- {
74
- N: 'BBAA99887766554433221109',
75
- A: '',
76
- P: '000102030405060708090A0B0C0D0E0F1011121314151617',
77
- C: '221BD0DE7FA6FE993ECCD769460A0AF2D6CDED0C395B1C3CE725F32494B9F914D85C0B1EB38357FF'
78
- },
79
- {
80
- N: 'BBAA9988776655443322110A',
81
- A: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F',
82
- P: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F',
83
- C: 'BD6F6C496201C69296C11EFD138A467ABD3C707924B964DEAFFC40319AF5A48540FBBA186C5553C68AD9F592A79A4240'
84
- },
85
- {
86
- N: 'BBAA9988776655443322110B',
87
- A: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F',
88
- P: '',
89
- C: 'FE80690BEE8A485D11F32965BC9D2A32'
90
- },
91
- {
92
- N: 'BBAA9988776655443322110C',
93
- A: '',
94
- P: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F',
95
- C: '2942BFC773BDA23CABC6ACFD9BFD5835BD300F0973792EF46040C53F1432BCDFB5E1DDE3BC18A5F840B52E653444D5DF'
96
- },
97
- {
98
- N: 'BBAA9988776655443322110D',
99
- A: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
100
- P: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
101
- C: 'D5CA91748410C1751FF8A2F618255B68A0A12E093FF454606E59F9C1D0DDC54B65E8628E568BAD7AED07BA06A4A69483A7035490C5769E60'
102
- },
103
- {
104
- N: 'BBAA9988776655443322110E',
105
- A: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
106
- P: '',
107
- C: 'C5CD9D1850C141E358649994EE701B68'
108
- },
109
- {
110
- N: 'BBAA9988776655443322110F',
111
- A: '',
112
- P: '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F2021222324252627',
113
- C: '4412923493C57D5DE0D700F753CCE0D1D2D95060122E9F15A5DDBFC5787E50B5CC55EE507BCB084E479AD363AC366B95A98CA5F3000B1479'
114
- }
115
- ];
116
-
117
- const cipher = 'aes128';
118
-
119
- await Promise.all(vectors.map(async vec => {
120
- const msgBytes = openpgp.util.hex_to_Uint8Array(vec.P);
121
- const nonceBytes = openpgp.util.hex_to_Uint8Array(vec.N);
122
- const headerBytes = openpgp.util.hex_to_Uint8Array(vec.A);
123
- const ctBytes = openpgp.util.hex_to_Uint8Array(vec.C);
124
-
125
- const ocb = await openpgp.crypto.ocb(cipher, keyBytes);
126
-
127
- // encryption test
128
- let ct = await ocb.encrypt(msgBytes, nonceBytes, headerBytes);
129
- expect(openpgp.util.Uint8Array_to_hex(ct)).to.equal(vec.C.toLowerCase());
130
-
131
- // decryption test with verification
132
- let pt = await ocb.decrypt(ctBytes, nonceBytes, headerBytes);
133
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.P.toLowerCase());
134
-
135
- // tampering detection test
136
- ct = await ocb.encrypt(msgBytes, nonceBytes, headerBytes);
137
- ct[2] ^= 8;
138
- pt = ocb.decrypt(ct, nonceBytes, headerBytes);
139
- await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch');
140
-
141
- // testing without additional data
142
- ct = await ocb.encrypt(msgBytes, nonceBytes, new Uint8Array());
143
- pt = await ocb.decrypt(ct, nonceBytes, new Uint8Array());
144
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.P.toLowerCase());
145
-
146
- // testing with multiple additional data
147
- ct = await ocb.encrypt(msgBytes, nonceBytes, openpgp.util.concatUint8Array([headerBytes, headerBytes, headerBytes]));
148
- pt = await ocb.decrypt(ct, nonceBytes, openpgp.util.concatUint8Array([headerBytes, headerBytes, headerBytes]));
149
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.P.toLowerCase());
150
- }));
151
- });
152
-
153
- it('Different key size test vectors', async function() {
154
- const taglen = 128;
155
- const outputs = {
156
- 128: '67E944D23256C5E0B6C61FA22FDF1EA2',
157
- 192: 'F673F2C3E7174AAE7BAE986CA9F29E17',
158
- 256: 'D90EB8E9C977C88B79DD793D7FFA161C'
159
- };
160
- const keylens = [128, 192, 256];
161
- await Promise.all(keylens.map(async keylen => {
162
- const k = new Uint8Array(keylen / 8);
163
- k[k.length - 1] = taglen;
164
-
165
- const ocb = await openpgp.crypto.ocb('aes' + keylen, k);
166
-
167
- const c = [];
168
- let n;
169
- for (let i = 0; i < 128; i++) {
170
- const s = new Uint8Array(i);
171
- n = openpgp.util.concatUint8Array([new Uint8Array(8), openpgp.util.writeNumber(3 * i + 1, 4)]);
172
- c.push(await ocb.encrypt(s, n, s));
173
- n = openpgp.util.concatUint8Array([new Uint8Array(8), openpgp.util.writeNumber(3 * i + 2, 4)]);
174
- c.push(await ocb.encrypt(s, n, new Uint8Array()));
175
- n = openpgp.util.concatUint8Array([new Uint8Array(8), openpgp.util.writeNumber(3 * i + 3, 4)]);
176
- c.push(await ocb.encrypt(new Uint8Array(), n, s));
177
- }
178
- n = openpgp.util.concatUint8Array([new Uint8Array(8), openpgp.util.writeNumber(385, 4)]);
179
- const output = await ocb.encrypt(new Uint8Array(), n, openpgp.util.concatUint8Array(c));
180
- expect(openpgp.util.Uint8Array_to_hex(output)).to.equal(outputs[keylen].toLowerCase());
181
- }));
182
- });
183
- });
@@ -1,39 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
-
3
- const expect = require('chai').expect;
4
-
5
- describe('PKCS5 padding', function() {
6
- function repeat(pattern, count) {
7
- let result = '';
8
- for (let k = 0; k < count; ++k) {
9
- result += pattern;
10
- }
11
- return result;
12
- }
13
- const pkcs5 = openpgp.crypto.pkcs5;
14
- it('Add padding', function () {
15
- let s = '';
16
- while (s.length < 16) {
17
- const r = pkcs5.encode(s);
18
- // 0..7 -> 8, 8..15 -> 16
19
- const l = Math.ceil((s.length + 1) / 8) * 8;
20
- const c = l - s.length;
21
- expect(r.length).to.equal(l);
22
- expect(c).is.at.least(1).is.at.most(8);
23
- expect(r.substr(-1)).to.equal(String.fromCharCode(c));
24
- s += ' ';
25
- }
26
- });
27
- it('Remove padding', function () {
28
- for (let k = 1; k <= 8; ++k) {
29
- const s = repeat(' ', 8 - k);
30
- const r = s + repeat(String.fromCharCode(k), k);
31
- const t = pkcs5.decode(r);
32
- expect(t).to.equal(s);
33
- }
34
- });
35
- it('Invalid padding', function () {
36
- expect(function () { pkcs5.decode(' '); }).to.throw(Error, /Invalid padding/);
37
- expect(function () { pkcs5.decode(''); }).to.throw(Error, /Invalid padding/);
38
- });
39
- });