UNPKG

22.2 kBJavaScriptView Raw
1function nacl_cooked(nacl_raw) {
2 'use strict';
3 var exports = {};
4
5 //---------------------------------------------------------------------------
6 // Horrifying UTF-8 and hex codecs
7
8 function encode_utf8(s) {
9 return encode_latin1(unescape(encodeURIComponent(s)));
10 }
11
12 function encode_latin1(s) {
13 var result = new Uint8Array(s.length);
14 for (var i = 0; i < s.length; i++) {
15 var c = s.charCodeAt(i);
16 if ((c & 0xff) !== c) throw {message: "Cannot encode string in Latin1", str: s};
17 result[i] = (c & 0xff);
18 }
19 return result;
20 }
21
22 function decode_utf8(bs) {
23 return decodeURIComponent(escape(decode_latin1(bs)));
24 }
25
26 function decode_latin1(bs) {
27 var encoded = [];
28 for (var i = 0; i < bs.length; i++) {
29 encoded.push(String.fromCharCode(bs[i]));
30 }
31 return encoded.join('');
32 }
33
34 function to_hex(bs) {
35 var encoded = [];
36 for (var i = 0; i < bs.length; i++) {
37 encoded.push("0123456789abcdef"[(bs[i] >> 4) & 15]);
38 encoded.push("0123456789abcdef"[bs[i] & 15]);
39 }
40 return encoded.join('');
41 }
42
43 function from_hex(s) {
44 var result = new Uint8Array(s.length / 2);
45 for (var i = 0; i < s.length / 2; i++) {
46 result[i] = parseInt(s.substr(2*i,2),16);
47 }
48 return result;
49 }
50
51 //---------------------------------------------------------------------------
52 // Allocation
53
54 function MALLOC(nbytes) {
55 var result = nacl_raw._malloc(nbytes);
56 if (result === 0) {
57 throw {message: "malloc() failed", nbytes: nbytes};
58 }
59 return result;
60 }
61
62 function FREE(pointer) {
63 nacl_raw._free(pointer);
64 }
65
66 //---------------------------------------------------------------------------
67
68 function injectBytes(bs, leftPadding) {
69 var p = leftPadding || 0;
70 var address = MALLOC(bs.length + p);
71 nacl_raw.HEAPU8.set(bs, address + p);
72 for (var i = address; i < address + p; i++) {
73 nacl_raw.HEAPU8[i] = 0;
74 }
75 return address;
76 }
77
78 function check_injectBytes(function_name, what, thing, expected_length, leftPadding) {
79 check_length(function_name, what, thing, expected_length);
80 return injectBytes(thing, leftPadding);
81 }
82
83 function extractBytes(address, length) {
84 var result = new Uint8Array(length);
85 result.set(nacl_raw.HEAPU8.subarray(address, address + length));
86 return result;
87 }
88
89 //---------------------------------------------------------------------------
90
91 function check(function_name, result) {
92 if (result !== 0) {
93 throw {message: "nacl_raw." + function_name + " signalled an error"};
94 }
95 }
96
97 function check_length(function_name, what, thing, expected_length) {
98 if (thing.length !== expected_length) {
99 throw {message: "nacl." + function_name + " expected " +
100 expected_length + "-byte " + what + " but got length " + thing.length};
101 }
102 }
103
104 function Target(length) {
105 this.length = length;
106 this.address = MALLOC(length);
107 }
108
109 Target.prototype.extractBytes = function (offset) {
110 var result = extractBytes(this.address + (offset || 0), this.length - (offset || 0));
111 FREE(this.address);
112 this.address = null;
113 return result;
114 };
115
116 function free_all(addresses) {
117 for (var i = 0; i < addresses.length; i++) {
118 FREE(addresses[i]);
119 }
120 }
121
122 //---------------------------------------------------------------------------
123 // Randomness
124
125 function random_bytes(count) {
126 var bs = new Target(count);
127 nacl_raw._randombytes_buf(bs.address, count);
128 return bs.extractBytes();
129 }
130
131 nacl_raw._randombytes_stir();
132
133 //---------------------------------------------------------------------------
134 // Boxing
135
136 function crypto_box_keypair() {
137 var pk = new Target(nacl_raw._crypto_box_publickeybytes());
138 var sk = new Target(nacl_raw._crypto_box_secretkeybytes());
139 check("_crypto_box_keypair", nacl_raw._crypto_box_keypair(pk.address, sk.address));
140 return {boxPk: pk.extractBytes(), boxSk: sk.extractBytes()};
141 }
142
143 function crypto_box_random_nonce() {
144 return random_bytes(nacl_raw._crypto_box_noncebytes());
145 }
146
147 function crypto_box(msg, nonce, pk, sk) {
148 var m = injectBytes(msg, nacl_raw._crypto_box_zerobytes());
149 var na = check_injectBytes("crypto_box", "nonce", nonce, nacl_raw._crypto_box_noncebytes());
150 var pka = check_injectBytes("crypto_box", "pk", pk, nacl_raw._crypto_box_publickeybytes());
151 var ska = check_injectBytes("crypto_box", "sk", sk, nacl_raw._crypto_box_secretkeybytes());
152 var c = new Target(msg.length + nacl_raw._crypto_box_zerobytes());
153 check("_crypto_box", nacl_raw._crypto_box(c.address, m, c.length, 0, na, pka, ska));
154 free_all([m, na, pka, ska]);
155 return c.extractBytes(nacl_raw._crypto_box_boxzerobytes());
156 }
157
158 function crypto_box_open(ciphertext, nonce, pk, sk) {
159 var c = injectBytes(ciphertext, nacl_raw._crypto_box_boxzerobytes());
160 var na = check_injectBytes("crypto_box_open",
161 "nonce", nonce, nacl_raw._crypto_box_noncebytes());
162 var pka = check_injectBytes("crypto_box_open",
163 "pk", pk, nacl_raw._crypto_box_publickeybytes());
164 var ska = check_injectBytes("crypto_box_open",
165 "sk", sk, nacl_raw._crypto_box_secretkeybytes());
166 var m = new Target(ciphertext.length + nacl_raw._crypto_box_boxzerobytes());
167 check("_crypto_box_open", nacl_raw._crypto_box_open(m.address, c, m.length, 0, na, pka, ska));
168 free_all([c, na, pka, ska]);
169 return m.extractBytes(nacl_raw._crypto_box_zerobytes());
170 }
171
172 function crypto_box_precompute(pk, sk) {
173 var pka = check_injectBytes("crypto_box_precompute",
174 "pk", pk, nacl_raw._crypto_box_publickeybytes());
175 var ska = check_injectBytes("crypto_box_precompute",
176 "sk", sk, nacl_raw._crypto_box_secretkeybytes());
177 var k = new Target(nacl_raw._crypto_box_beforenmbytes());
178 check("_crypto_box_beforenm",
179 nacl_raw._crypto_box_beforenm(k.address, pka, ska));
180 free_all([pka, ska]);
181 return {boxK: k.extractBytes()};
182 }
183
184 function crypto_box_precomputed(msg, nonce, state) {
185 var m = injectBytes(msg, nacl_raw._crypto_box_zerobytes());
186 var na = check_injectBytes("crypto_box_precomputed",
187 "nonce", nonce, nacl_raw._crypto_box_noncebytes());
188 var ka = check_injectBytes("crypto_box_precomputed",
189 "boxK", state.boxK, nacl_raw._crypto_box_beforenmbytes());
190 var c = new Target(msg.length + nacl_raw._crypto_box_zerobytes());
191 check("_crypto_box_afternm",
192 nacl_raw._crypto_box_afternm(c.address, m, c.length, 0, na, ka));
193 free_all([m, na, ka]);
194 return c.extractBytes(nacl_raw._crypto_box_boxzerobytes());
195 }
196
197 function crypto_box_open_precomputed(ciphertext, nonce, state) {
198 var c = injectBytes(ciphertext, nacl_raw._crypto_box_boxzerobytes());
199 var na = check_injectBytes("crypto_box_open_precomputed",
200 "nonce", nonce, nacl_raw._crypto_box_noncebytes());
201 var ka = check_injectBytes("crypto_box_open_precomputed",
202 "boxK", state.boxK, nacl_raw._crypto_box_beforenmbytes());
203 var m = new Target(ciphertext.length + nacl_raw._crypto_box_boxzerobytes());
204 check("_crypto_box_open_afternm",
205 nacl_raw._crypto_box_open_afternm(m.address, c, m.length, 0, na, ka));
206 free_all([c, na, ka]);
207 return m.extractBytes(nacl_raw._crypto_box_zerobytes());
208 }
209
210 //---------------------------------------------------------------------------
211 // Hashing
212
213 function crypto_hash(bs) {
214 var address = injectBytes(bs);
215 var hash = new Target(nacl_raw._crypto_hash_bytes());
216 check("_crypto_hash", nacl_raw._crypto_hash(hash.address, address, bs.length, 0));
217 FREE(address);
218 return hash.extractBytes();
219 }
220
221 function crypto_hash_sha256(bs) {
222 var address = injectBytes(bs);
223 var hash = new Target(nacl_raw._crypto_hash_sha256_bytes());
224 check("_crypto_hash_sha256",
225 nacl_raw._crypto_hash_sha256(hash.address, address, bs.length, 0));
226 FREE(address);
227 return hash.extractBytes();
228 }
229
230 function crypto_hash_string(s) {
231 return crypto_hash(encode_utf8(s));
232 }
233
234 //---------------------------------------------------------------------------
235 // Symmetric-key encryption
236
237 function crypto_stream_random_nonce() {
238 return random_bytes(nacl_raw._crypto_stream_noncebytes());
239 }
240
241 function crypto_stream(len, nonce, key) {
242 var na = check_injectBytes("crypto_stream",
243 "nonce", nonce, nacl_raw._crypto_stream_noncebytes());
244 var ka = check_injectBytes("crypto_stream",
245 "key", key, nacl_raw._crypto_stream_keybytes());
246 var out = new Target(len);
247 check("_crypto_stream", nacl_raw._crypto_stream(out.address, len, 0, na, ka));
248 free_all([na, ka]);
249 return out.extractBytes();
250 }
251
252 function crypto_stream_xor(msg, nonce, key) {
253 var na = check_injectBytes("crypto_stream_xor",
254 "nonce", nonce, nacl_raw._crypto_stream_noncebytes());
255 var ka = check_injectBytes("crypto_stream_xor",
256 "key", key, nacl_raw._crypto_stream_keybytes());
257 var ma = injectBytes(msg);
258 var out = new Target(msg.length);
259 check("_crypto_stream_xor",
260 nacl_raw._crypto_stream_xor(out.address, ma, msg.length, 0, na, ka));
261 free_all([na, ka, ma]);
262 return out.extractBytes();
263 }
264
265 //---------------------------------------------------------------------------
266 // One-time authentication
267
268 function crypto_onetimeauth(msg, key) {
269 var ka = check_injectBytes("crypto_onetimeauth",
270 "key", key, nacl_raw._crypto_onetimeauth_keybytes());
271 var ma = injectBytes(msg);
272 var authenticator = new Target(nacl_raw._crypto_onetimeauth_bytes());
273 check("_crypto_onetimeauth",
274 nacl_raw._crypto_onetimeauth(authenticator.address, ma, msg.length, 0, ka));
275 free_all([ka, ma]);
276 return authenticator.extractBytes();
277 }
278
279 function crypto_onetimeauth_verify(authenticator, msg, key) {
280 if (authenticator.length != nacl_raw._crypto_onetimeauth_bytes()) return false;
281 var ka = check_injectBytes("crypto_onetimeauth_verify",
282 "key", key, nacl_raw._crypto_onetimeauth_keybytes());
283 var ma = injectBytes(msg);
284 var aa = injectBytes(authenticator);
285 var result = nacl_raw._crypto_onetimeauth_verify(aa, ma, msg.length, 0, ka);
286 free_all([ka, ma, aa]);
287 return (result == 0);
288 }
289
290 //---------------------------------------------------------------------------
291 // Authentication
292
293 function crypto_auth(msg, key) {
294 var ka = check_injectBytes("crypto_auth", "key", key, nacl_raw._crypto_auth_keybytes());
295 var ma = injectBytes(msg);
296 var authenticator = new Target(nacl_raw._crypto_auth_bytes());
297 check("_crypto_auth", nacl_raw._crypto_auth(authenticator.address, ma, msg.length, 0, ka));
298 free_all([ka, ma]);
299 return authenticator.extractBytes();
300 }
301
302 function crypto_auth_verify(authenticator, msg, key) {
303 if (authenticator.length != nacl_raw._crypto_auth_bytes()) return false;
304 var ka = check_injectBytes("crypto_auth_verify",
305 "key", key, nacl_raw._crypto_auth_keybytes());
306 var ma = injectBytes(msg);
307 var aa = injectBytes(authenticator);
308 var result = nacl_raw._crypto_auth_verify(aa, ma, msg.length, 0, ka);
309 free_all([ka, ma, aa]);
310 return (result == 0);
311 }
312
313 //---------------------------------------------------------------------------
314 // Authenticated symmetric-key encryption
315
316 function crypto_secretbox_random_nonce() {
317 return random_bytes(nacl_raw._crypto_secretbox_noncebytes());
318 }
319
320 function crypto_secretbox(msg, nonce, key) {
321 var m = injectBytes(msg, nacl_raw._crypto_secretbox_zerobytes());
322 var na = check_injectBytes("crypto_secretbox",
323 "nonce", nonce, nacl_raw._crypto_secretbox_noncebytes());
324 var ka = check_injectBytes("crypto_secretbox",
325 "key", key, nacl_raw._crypto_secretbox_keybytes());
326 var c = new Target(msg.length + nacl_raw._crypto_secretbox_zerobytes());
327 check("_crypto_secretbox", nacl_raw._crypto_secretbox(c.address, m, c.length, 0, na, ka));
328 free_all([m, na, ka]);
329 return c.extractBytes(nacl_raw._crypto_secretbox_boxzerobytes());
330 }
331
332 function crypto_secretbox_open(ciphertext, nonce, key) {
333 var c = injectBytes(ciphertext, nacl_raw._crypto_secretbox_boxzerobytes());
334 var na = check_injectBytes("crypto_secretbox_open",
335 "nonce", nonce, nacl_raw._crypto_secretbox_noncebytes());
336 var ka = check_injectBytes("crypto_secretbox_open",
337 "key", key, nacl_raw._crypto_secretbox_keybytes());
338 var m = new Target(ciphertext.length + nacl_raw._crypto_secretbox_boxzerobytes());
339 check("_crypto_secretbox_open",
340 nacl_raw._crypto_secretbox_open(m.address, c, m.length, 0, na, ka));
341 free_all([c, na, ka]);
342 return m.extractBytes(nacl_raw._crypto_secretbox_zerobytes());
343 }
344
345 //---------------------------------------------------------------------------
346 // Boxing with ephemeral keys
347
348 function crypto_box_seal(msg, pk) {
349 var m = injectBytes(msg);
350 var pka = check_injectBytes("crypto_box_seal",
351 "pk", pk, nacl_raw._crypto_box_publickeybytes());
352 var c = new Target(msg.length + nacl_raw._crypto_box_sealbytes());
353 check("_crypto_box_seal", nacl_raw._crypto_box_seal(c.address, m, msg.length, 0, pka));
354 free_all([m, pka]);
355 return c.extractBytes();
356 }
357
358 function crypto_box_seal_open(ciphertext, pk, sk) {
359 var c = injectBytes(ciphertext);
360 var pka = check_injectBytes("crypto_box_seal_open",
361 "pk", pk, nacl_raw._crypto_box_publickeybytes());
362 var ska = check_injectBytes("crypto_box_seal_open",
363 "sk", sk, nacl_raw._crypto_box_secretkeybytes());
364 var m = new Target(ciphertext.length - nacl_raw._crypto_box_sealbytes());
365 check("_crypto_box_seal_open",
366 nacl_raw._crypto_box_seal_open(m.address, c, ciphertext.length, 0, pka, ska));
367 free_all([c, pka, ska]);
368 return m.extractBytes();
369 }
370
371 //---------------------------------------------------------------------------
372 // Signing
373
374 function crypto_sign_keypair() {
375 var pk = new Target(nacl_raw._crypto_sign_publickeybytes());
376 var sk = new Target(nacl_raw._crypto_sign_secretkeybytes());
377 check("_crypto_sign_keypair", nacl_raw._crypto_sign_keypair(pk.address, sk.address));
378 return {signPk: pk.extractBytes(), signSk: sk.extractBytes()};
379 }
380
381 function crypto_sign(msg, sk) {
382 var ma = injectBytes(msg);
383 var ska = check_injectBytes("crypto_sign", "sk", sk, nacl_raw._crypto_sign_secretkeybytes());
384 var sm = new Target(msg.length + nacl_raw._crypto_sign_bytes());
385 var smlen = new Target(8);
386 check("_crypto_sign",
387 nacl_raw._crypto_sign(sm.address, smlen.address, ma, msg.length, 0, ska));
388 free_all([ma, ska]);
389 sm.length = nacl_raw.HEAPU32[smlen.address >> 2];
390 FREE(smlen.address);
391 return sm.extractBytes();
392 }
393
394 function crypto_sign_detached(msg, sk) {
395 // WARNING: Experimental. Works for ed25519 but not necessarily other implementations.
396 var signed_msg = crypto_sign(msg, sk);
397 return signed_msg.subarray(0, nacl_raw._crypto_sign_bytes());
398 }
399
400 function crypto_sign_open(sm, pk) {
401 var sma = injectBytes(sm);
402 var pka = check_injectBytes("crypto_sign_open",
403 "pk", pk, nacl_raw._crypto_sign_publickeybytes());
404 var m = new Target(sm.length);
405 var mlen = new Target(8);
406 if (nacl_raw._crypto_sign_open(m.address, mlen.address, sma, sm.length, 0, pka) === 0) {
407 free_all([sma, pka]);
408 m.length = nacl_raw.HEAPU32[mlen.address >> 2];
409 FREE(mlen.address);
410 return m.extractBytes();
411 } else {
412 free_all([sma, pka, m.address, mlen.address]);
413 return null;
414 }
415 }
416
417 function crypto_sign_verify_detached(detached_signature, msg, pk) {
418 // WARNING: Experimental. Works for ed25519 but not necessarily other implementations.
419 var signed_msg = new Uint8Array(detached_signature.length + msg.length);
420 signed_msg.set(detached_signature, 0);
421 signed_msg.set(msg, detached_signature.length);
422 return crypto_sign_open(signed_msg, pk) !== null;
423 }
424
425 //---------------------------------------------------------------------------
426 // Keys
427
428 function crypto_sign_seed_keypair(bs) {
429 var seeda = check_injectBytes("crypto_sign_seed_keypair",
430 "seed", bs, nacl_raw._crypto_sign_secretkeybytes() / 2);
431 var pk = new Target(nacl_raw._crypto_sign_publickeybytes());
432 var sk = new Target(nacl_raw._crypto_sign_secretkeybytes());
433 check("_crypto_sign_seed_keypair",
434 nacl_raw._crypto_sign_seed_keypair(pk.address, sk.address, seeda));
435 FREE(seeda);
436 return {signPk: pk.extractBytes(), signSk: sk.extractBytes()};
437 }
438
439 function crypto_box_seed_keypair(bs) {
440 var hash = new Uint8Array(crypto_hash(bs));
441 return crypto_box_keypair_from_raw_sk(hash.subarray(0,
442 nacl_raw._crypto_box_secretkeybytes()));
443 }
444
445 function crypto_box_keypair_from_raw_sk(sk) {
446 return {boxPk: crypto_scalarmult_base(sk), boxSk: sk};
447 }
448
449 //---------------------------------------------------------------------------
450 // Scalarmult
451
452 function crypto_scalarmult(n,p) {
453 var na = check_injectBytes("crypto_scalarmult", "n", n,
454 nacl_raw._crypto_scalarmult_curve25519_scalarbytes());
455 var pa = check_injectBytes("crypto_scalarmult", "p", p,
456 nacl_raw._crypto_scalarmult_curve25519_bytes());
457 var q = new Target(nacl_raw._crypto_scalarmult_curve25519_bytes());
458 check("_crypto_scalarmult_curve25519",
459 nacl_raw._crypto_scalarmult_curve25519(q.address, na, pa));
460 FREE(na);
461 FREE(pa);
462 return q.extractBytes();
463 }
464
465 function crypto_scalarmult_base(n) {
466 var na = check_injectBytes("crypto_scalarmult_base", "n", n,
467 nacl_raw._crypto_scalarmult_curve25519_scalarbytes());
468 var q = new Target(nacl_raw._crypto_scalarmult_curve25519_bytes());
469 check("_crypto_scalarmult_curve25519_base",
470 nacl_raw._crypto_scalarmult_curve25519_base(q.address, na));
471 FREE(na);
472 return q.extractBytes();
473 }
474
475 //---------------------------------------------------------------------------
476
477 exports.crypto_auth_BYTES = nacl_raw._crypto_auth_bytes();
478 exports.crypto_auth_KEYBYTES = nacl_raw._crypto_auth_keybytes();
479 exports.crypto_box_BEFORENMBYTES = nacl_raw._crypto_box_beforenmbytes();
480 exports.crypto_box_BOXZEROBYTES = nacl_raw._crypto_box_boxzerobytes();
481 exports.crypto_box_NONCEBYTES = nacl_raw._crypto_box_noncebytes();
482 exports.crypto_box_PUBLICKEYBYTES = nacl_raw._crypto_box_publickeybytes();
483 exports.crypto_box_SECRETKEYBYTES = nacl_raw._crypto_box_secretkeybytes();
484 exports.crypto_box_ZEROBYTES = nacl_raw._crypto_box_zerobytes();
485 exports.crypto_hash_BYTES = nacl_raw._crypto_hash_bytes();
486 exports.crypto_hash_sha256_BYTES = nacl_raw._crypto_hash_sha256_bytes();
487 // exports.crypto_hashblocks_BLOCKBYTES = nacl_raw._crypto_hashblocks_blockbytes();
488 // exports.crypto_hashblocks_STATEBYTES = nacl_raw._crypto_hashblocks_statebytes();
489 exports.crypto_onetimeauth_BYTES = nacl_raw._crypto_onetimeauth_bytes();
490 exports.crypto_onetimeauth_KEYBYTES = nacl_raw._crypto_onetimeauth_keybytes();
491 exports.crypto_secretbox_BOXZEROBYTES = nacl_raw._crypto_secretbox_boxzerobytes();
492 exports.crypto_secretbox_KEYBYTES = nacl_raw._crypto_secretbox_keybytes();
493 exports.crypto_secretbox_NONCEBYTES = nacl_raw._crypto_secretbox_noncebytes();
494 exports.crypto_secretbox_ZEROBYTES = nacl_raw._crypto_secretbox_zerobytes();
495 exports.crypto_sign_BYTES = nacl_raw._crypto_sign_bytes();
496 exports.crypto_sign_PUBLICKEYBYTES = nacl_raw._crypto_sign_publickeybytes();
497 exports.crypto_sign_SECRETKEYBYTES = nacl_raw._crypto_sign_secretkeybytes();
498 // exports.crypto_stream_BEFORENMBYTES = nacl_raw._crypto_stream_beforenmbytes();
499 exports.crypto_stream_KEYBYTES = nacl_raw._crypto_stream_keybytes();
500 exports.crypto_stream_NONCEBYTES = nacl_raw._crypto_stream_noncebytes();
501 exports.crypto_scalarmult_SCALARBYTES = nacl_raw._crypto_scalarmult_curve25519_scalarbytes();
502 exports.crypto_scalarmult_BYTES = nacl_raw._crypto_scalarmult_curve25519_bytes();
503
504 exports.encode_utf8 = encode_utf8;
505 exports.encode_latin1 = encode_latin1;
506 exports.decode_utf8 = decode_utf8;
507 exports.decode_latin1 = decode_latin1;
508 exports.to_hex = to_hex;
509 exports.from_hex = from_hex;
510
511 exports.random_bytes = random_bytes;
512
513 exports.crypto_box_keypair = crypto_box_keypair;
514 exports.crypto_box_random_nonce = crypto_box_random_nonce;
515 exports.crypto_box = crypto_box;
516 exports.crypto_box_open = crypto_box_open;
517 exports.crypto_box_precompute = crypto_box_precompute;
518 exports.crypto_box_precomputed = crypto_box_precomputed;
519 exports.crypto_box_open_precomputed = crypto_box_open_precomputed;
520
521 exports.crypto_stream_random_nonce = crypto_stream_random_nonce;
522 exports.crypto_stream = crypto_stream;
523 exports.crypto_stream_xor = crypto_stream_xor;
524
525 exports.crypto_onetimeauth = crypto_onetimeauth;
526 exports.crypto_onetimeauth_verify = crypto_onetimeauth_verify;
527
528 exports.crypto_auth = crypto_auth;
529 exports.crypto_auth_verify = crypto_auth_verify;
530
531 exports.crypto_secretbox_random_nonce = crypto_secretbox_random_nonce;
532 exports.crypto_secretbox = crypto_secretbox;
533 exports.crypto_secretbox_open = crypto_secretbox_open;
534
535 exports.crypto_box_seal = crypto_box_seal;
536 exports.crypto_box_seal_open = crypto_box_seal_open;
537
538 exports.crypto_sign_keypair = crypto_sign_keypair;
539 exports.crypto_sign = crypto_sign;
540 exports.crypto_sign_detached = crypto_sign_detached;
541 exports.crypto_sign_open = crypto_sign_open;
542 exports.crypto_sign_verify_detached = crypto_sign_verify_detached;
543
544 exports.crypto_hash = crypto_hash;
545 exports.crypto_hash_sha256 = crypto_hash_sha256;
546 exports.crypto_hash_string = crypto_hash_string;
547
548 exports.crypto_sign_seed_keypair = crypto_sign_seed_keypair;
549 exports.crypto_box_seed_keypair = crypto_box_seed_keypair;
550 exports.crypto_box_keypair_from_raw_sk = crypto_box_keypair_from_raw_sk;
551 // Backwards-compatibility:
552 exports.crypto_sign_keypair_from_seed = crypto_sign_seed_keypair;
553 exports.crypto_box_keypair_from_seed = crypto_box_seed_keypair;
554
555 exports.crypto_scalarmult = crypto_scalarmult;
556 exports.crypto_scalarmult_base = crypto_scalarmult_base;
557
558 return exports;
559}