mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-25 11:39:51 +01:00
feat: new clean code
This commit is contained in:
1 parent
f7c356de1e
commit
a23d1521d1
339 files changed
+60123
No files matched your search
+27
@@ -0,0 +1,27 @@
|
||||
List of TweetNaCl.js authors
|
||||
============================
|
||||
|
||||
Format: Name (GitHub username or URL)
|
||||
|
||||
* Dmitry Chestnykh (@dchest)
|
||||
* Devi Mandiri (@devi)
|
||||
* AndSDev (@AndSDev)
|
||||
|
||||
List of authors of third-party public domain code from which TweetNaCl.js code was derived
|
||||
==========================================================================================
|
||||
|
||||
[TweetNaCl](http://tweetnacl.cr.yp.to/)
|
||||
--------------------------------------
|
||||
|
||||
* Bernard van Gastel
|
||||
* Daniel J. Bernstein <http://cr.yp.to/djb.html>
|
||||
* Peter Schwabe <http://www.cryptojedi.org/users/peter/>
|
||||
* Sjaak Smetsers <http://www.cs.ru.nl/~sjakie/>
|
||||
* Tanja Lange <http://hyperelliptic.org/tanja>
|
||||
* Wesley Janssen
|
||||
|
||||
|
||||
[Poly1305-donna](https://github.com/floodyberry/poly1305-donna)
|
||||
--------------------------------------------------------------
|
||||
|
||||
* Andrew Moon (@floodyberry)
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
TweetNaCl.js Changelog
|
||||
======================
|
||||
|
||||
v1.0.3
|
||||
------
|
||||
|
||||
***IMPORTANT BUG FIX***. Due to a bug in calculating carry in
|
||||
modulo reduction that used bit operations on integers larger than
|
||||
32 bits, `nacl.sign` or `nacl.sign.detached` could have created
|
||||
incorrect signatures.
|
||||
|
||||
This only affects signing, not verification.
|
||||
|
||||
Thanks to @valerini on GitHub for finding and reporting the bug.
|
||||
|
||||
|
||||
v1.0.2
|
||||
------
|
||||
|
||||
Exported more internal undocumented functions for
|
||||
third-party projects that rely on low-level interface,
|
||||
(something users of TweetNaCl shouldn't care about).
|
||||
|
||||
|
||||
v1.0.1
|
||||
------
|
||||
|
||||
Updated documentation and typings.
|
||||
|
||||
|
||||
v1.0.0
|
||||
------
|
||||
|
||||
No code changes from v1.0.0-rc.1.
|
||||
|
||||
|
||||
v1.0.0-rc.1
|
||||
-----------
|
||||
|
||||
* **IMPORTANT!** In previous versions, `nacl.secretbox.open`, `nacl.box.open`,
|
||||
and `nacl.box.after` returned `false` when opening failed (for example, when
|
||||
using incorrect key, nonce, or when input was maliciously or accidentally
|
||||
modified after encryption). This version instead returns `null`.
|
||||
|
||||
The usual way to check for this condition:
|
||||
|
||||
`if (!result) { ... }`
|
||||
|
||||
is correct and will continue to work.
|
||||
|
||||
However, direct comparison with `false`:
|
||||
|
||||
`if (result == false) { ... }`
|
||||
|
||||
it will no longer work and **will not detect failure**. Please check
|
||||
your code for this condition.
|
||||
|
||||
(`nacl.sign.open` always returned `null`, so it is not affected.)
|
||||
|
||||
|
||||
* Arguments type check now uses `instanceof Uint8Array` instead of `Object.prototype.toString`.
|
||||
* Removed deprecation checks for `nacl.util` (moved to a
|
||||
[separate package](https://github.com/dchest/tweetnacl-util-js) in v0.14.0).
|
||||
* Removed deprecation checks for the old signature API (changed in v0.10.0).
|
||||
* Improved benchmarking.
|
||||
|
||||
v0.14.5
|
||||
-------
|
||||
|
||||
* Fixed incomplete return types in TypeScript typings.
|
||||
* Replaced COPYING.txt with LICENSE file, which now has public domain dedication
|
||||
text from The Unlicense. License fields in package.json and bower.json have
|
||||
been set to "Unlicense". The project was and will be in the public domain --
|
||||
this change just makes it easier for automated tools to know about this fact by
|
||||
using the widely recognized and SPDX-compatible template for public domain
|
||||
dedication.
|
||||
|
||||
|
||||
v0.14.4
|
||||
-------
|
||||
|
||||
* Added TypeScript type definitions (contributed by @AndSDev).
|
||||
* Improved benchmarking code.
|
||||
|
||||
|
||||
v0.14.3
|
||||
-------
|
||||
|
||||
Fixed a bug in the fast version of Poly1305 and brought it back.
|
||||
|
||||
Thanks to @floodyberry for promptly responding and fixing the original C code:
|
||||
|
||||
> "The issue was not properly detecting if st->h was >= 2^130 - 5, coupled with
|
||||
> [testing mistake] not catching the failure. The chance of the bug affecting
|
||||
> anything in the real world is essentially zero luckily, but it's good to have
|
||||
> it fixed."
|
||||
|
||||
https://github.com/floodyberry/poly1305-donna/issues/2#issuecomment-202698577
|
||||
|
||||
|
||||
v0.14.2
|
||||
-------
|
||||
|
||||
Switched Poly1305 fast version back to original (slow) version due to a bug.
|
||||
|
||||
|
||||
v0.14.1
|
||||
-------
|
||||
|
||||
No code changes, just tweaked packaging and added COPYING.txt.
|
||||
|
||||
|
||||
v0.14.0
|
||||
-------
|
||||
|
||||
* **Breaking change!** All functions from `nacl.util` have been removed. These
|
||||
functions are no longer available:
|
||||
|
||||
nacl.util.decodeUTF8
|
||||
nacl.util.encodeUTF8
|
||||
nacl.util.decodeBase64
|
||||
nacl.util.encodeBase64
|
||||
|
||||
If want to continue using them, you can include
|
||||
<https://github.com/dchest/tweetnacl-util-js> package:
|
||||
|
||||
<script src="nacl.min.js"></script>
|
||||
<script src="nacl-util.min.js"></script>
|
||||
|
||||
or
|
||||
|
||||
var nacl = require('tweetnacl');
|
||||
nacl.util = require('tweetnacl-util');
|
||||
|
||||
However it is recommended to use better packages that have wider
|
||||
compatibility and better performance. Functions from `nacl.util` were never
|
||||
intended to be robust solution for string conversion and were included for
|
||||
convenience: cryptography library is not the right place for them.
|
||||
|
||||
Currently calling these functions will throw error pointing to
|
||||
`tweetnacl-util-js` (in the next version this error message will be removed).
|
||||
|
||||
* Improved detection of available random number generators, making it possible
|
||||
to use `nacl.randomBytes` and related functions in Web Workers without
|
||||
changes.
|
||||
|
||||
* Changes to testing (see README).
|
||||
|
||||
|
||||
v0.13.3
|
||||
-------
|
||||
|
||||
No code changes.
|
||||
|
||||
* Reverted license field in package.json to "Public domain".
|
||||
|
||||
* Fixed typo in README.
|
||||
|
||||
|
||||
v0.13.2
|
||||
-------
|
||||
|
||||
* Fixed undefined variable bug in fast version of Poly1305. No worries, this
|
||||
bug was *never* triggered.
|
||||
|
||||
* Specified CC0 public domain dedication.
|
||||
|
||||
* Updated development dependencies.
|
||||
|
||||
|
||||
v0.13.1
|
||||
-------
|
||||
|
||||
* Exclude `crypto` and `buffer` modules from browserify builds.
|
||||
|
||||
|
||||
v0.13.0
|
||||
-------
|
||||
|
||||
* Made `nacl-fast` the default version in NPM package. Now
|
||||
`require("tweetnacl")` will use fast version; to get the original version,
|
||||
use `require("tweetnacl/nacl.js")`.
|
||||
|
||||
* Cleanup temporary array after generating random bytes.
|
||||
|
||||
|
||||
v0.12.2
|
||||
-------
|
||||
|
||||
* Improved performance of curve operations, making `nacl.scalarMult`, `nacl.box`,
|
||||
`nacl.sign` and related functions up to 3x faster in `nacl-fast` version.
|
||||
|
||||
|
||||
v0.12.1
|
||||
-------
|
||||
|
||||
* Significantly improved performance of Salsa20 (~1.5x faster) and
|
||||
Poly1305 (~3.5x faster) in `nacl-fast` version.
|
||||
|
||||
|
||||
v0.12.0
|
||||
-------
|
||||
|
||||
* Instead of using the given secret key directly, TweetNaCl.js now copies it to
|
||||
a new array in `nacl.box.keyPair.fromSecretKey` and
|
||||
`nacl.sign.keyPair.fromSecretKey`.
|
||||
|
||||
|
||||
v0.11.2
|
||||
-------
|
||||
|
||||
* Added new constant: `nacl.sign.seedLength`.
|
||||
|
||||
|
||||
v0.11.1
|
||||
-------
|
||||
|
||||
* Even faster hash for both short and long inputs (in `nacl-fast`).
|
||||
|
||||
|
||||
v0.11.0
|
||||
-------
|
||||
|
||||
* Implement `nacl.sign.keyPair.fromSeed` to enable creation of sign key pairs
|
||||
deterministically from a 32-byte seed. (It behaves like
|
||||
[libsodium's](http://doc.libsodium.org/public-key_cryptography/public-key_signatures.html)
|
||||
`crypto_sign_seed_keypair`: the seed becomes a secret part of the secret key.)
|
||||
|
||||
* Fast version now has an improved hash implementation that is 2x-5x faster.
|
||||
|
||||
* Fixed benchmarks, which may have produced incorrect measurements.
|
||||
|
||||
|
||||
v0.10.1
|
||||
-------
|
||||
|
||||
* Exported undocumented `nacl.lowlevel.crypto_core_hsalsa20`.
|
||||
|
||||
|
||||
v0.10.0
|
||||
-------
|
||||
|
||||
* **Signature API breaking change!** `nacl.sign` and `nacl.sign.open` now deal
|
||||
with signed messages, and new `nacl.sign.detached` and
|
||||
`nacl.sign.detached.verify` are available.
|
||||
|
||||
Previously, `nacl.sign` returned a signature, and `nacl.sign.open` accepted a
|
||||
message and "detached" signature. This was unlike NaCl's API, which dealt with
|
||||
signed messages (concatenation of signature and message).
|
||||
|
||||
The new API is:
|
||||
|
||||
nacl.sign(message, secretKey) -> signedMessage
|
||||
nacl.sign.open(signedMessage, publicKey) -> message | null
|
||||
|
||||
Since detached signatures are common, two new API functions were introduced:
|
||||
|
||||
nacl.sign.detached(message, secretKey) -> signature
|
||||
nacl.sign.detached.verify(message, signature, publicKey) -> true | false
|
||||
|
||||
(Note that it's `verify`, not `open`, and it returns a boolean value, unlike
|
||||
`open`, which returns an "unsigned" message.)
|
||||
|
||||
* NPM package now comes without `test` directory to keep it small.
|
||||
|
||||
|
||||
v0.9.2
|
||||
------
|
||||
|
||||
* Improved documentation.
|
||||
* Fast version: increased theoretical message size limit from 2^32-1 to 2^52
|
||||
bytes in Poly1305 (and thus, secretbox and box). However this has no impact
|
||||
in practice since JavaScript arrays or ArrayBuffers are limited to 32-bit
|
||||
indexes, and most implementations won't allocate more than a gigabyte or so.
|
||||
(Obviously, there are no tests for the correctness of implementation.) Also,
|
||||
it's not recommended to use messages that large without splitting them into
|
||||
smaller packets anyway.
|
||||
|
||||
|
||||
v0.9.1
|
||||
------
|
||||
|
||||
* Initial release
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
# Important!
|
||||
|
||||
If your contribution is not trivial (not a typo fix, etc.), we can only accept
|
||||
it if you dedicate your copyright for the contribution to the public domain.
|
||||
Make sure you understand what it means (see http://unlicense.org/)! If you
|
||||
agree, please add yourself to AUTHORS.md file, and include the following text
|
||||
to your pull request description or a comment in it:
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
I dedicate any and all copyright interest in this software to the
|
||||
public domain. I make this dedication for the benefit of the public at
|
||||
large and to the detriment of my heirs and successors. I intend this
|
||||
dedication to be an overt act of relinquishment in perpetuity of all
|
||||
present and future rights to this software under copyright law.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
+494
@@ -0,0 +1,494 @@
|
||||
TweetNaCl.js
|
||||
============
|
||||
|
||||
Port of [TweetNaCl](http://tweetnacl.cr.yp.to) / [NaCl](http://nacl.cr.yp.to/)
|
||||
to JavaScript for modern browsers and Node.js. Public domain.
|
||||
|
||||
[
|
||||
](https://travis-ci.org/dchest/tweetnacl-js)
|
||||
|
||||
Demo: <https://dchest.github.io/tweetnacl-js/>
|
||||
|
||||
Documentation
|
||||
=============
|
||||
|
||||
* [Overview](#overview)
|
||||
* [Audits](#audits)
|
||||
* [Installation](#installation)
|
||||
* [Examples](#examples)
|
||||
* [Usage](#usage)
|
||||
* [Public-key authenticated encryption (box)](#public-key-authenticated-encryption-box)
|
||||
* [Secret-key authenticated encryption (secretbox)](#secret-key-authenticated-encryption-secretbox)
|
||||
* [Scalar multiplication](#scalar-multiplication)
|
||||
* [Signatures](#signatures)
|
||||
* [Hashing](#hashing)
|
||||
* [Random bytes generation](#random-bytes-generation)
|
||||
* [Constant-time comparison](#constant-time-comparison)
|
||||
* [System requirements](#system-requirements)
|
||||
* [Development and testing](#development-and-testing)
|
||||
* [Benchmarks](#benchmarks)
|
||||
* [Contributors](#contributors)
|
||||
* [Who uses it](#who-uses-it)
|
||||
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
The primary goal of this project is to produce a translation of TweetNaCl to
|
||||
JavaScript which is as close as possible to the original C implementation, plus
|
||||
a thin layer of idiomatic high-level API on top of it.
|
||||
|
||||
There are two versions, you can use either of them:
|
||||
|
||||
* `nacl.js` is the port of TweetNaCl with minimum differences from the
|
||||
original + high-level API.
|
||||
|
||||
* `nacl-fast.js` is like `nacl.js`, but with some functions replaced with
|
||||
faster versions. (Used by default when importing NPM package.)
|
||||
|
||||
|
||||
Audits
|
||||
------
|
||||
|
||||
TweetNaCl.js has been audited by [Cure53](https://cure53.de/) in January-February
|
||||
2017 (audit was sponsored by [Deletype](https://deletype.com)):
|
||||
|
||||
> The overall outcome of this audit signals a particularly positive assessment
|
||||
> for TweetNaCl-js, as the testing team was unable to find any security
|
||||
> problems in the library. It has to be noted that this is an exceptionally
|
||||
> rare result of a source code audit for any project and must be seen as a true
|
||||
> testament to a development proceeding with security at its core.
|
||||
>
|
||||
> To reiterate, the TweetNaCl-js project, the source code was found to be
|
||||
> bug-free at this point.
|
||||
>
|
||||
> [...]
|
||||
>
|
||||
> In sum, the testing team is happy to recommend the TweetNaCl-js project as
|
||||
> likely one of the safer and more secure cryptographic tools among its
|
||||
> competition.
|
||||
|
||||
[Read full audit report](https://cure53.de/tweetnacl.pdf)
|
||||
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
You can install TweetNaCl.js via a package manager:
|
||||
|
||||
[Yarn](https://yarnpkg.com/):
|
||||
|
||||
$ yarn add tweetnacl
|
||||
|
||||
[NPM](https://www.npmjs.org/):
|
||||
|
||||
$ npm install tweetnacl
|
||||
|
||||
or [download source code](https://github.com/dchest/tweetnacl-js/releases).
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
You can find usage examples in our [wiki](https://github.com/dchest/tweetnacl-js/wiki/Examples).
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
All API functions accept and return bytes as `Uint8Array`s. If you need to
|
||||
encode or decode strings, use functions from
|
||||
<https://github.com/dchest/tweetnacl-util-js> or one of the more robust codec
|
||||
packages.
|
||||
|
||||
In Node.js v4 and later `Buffer` objects are backed by `Uint8Array`s, so you
|
||||
can freely pass them to TweetNaCl.js functions as arguments. The returned
|
||||
objects are still `Uint8Array`s, so if you need `Buffer`s, you'll have to
|
||||
convert them manually; make sure to convert using copying: `Buffer.from(array)`
|
||||
(or `new Buffer(array)` in Node.js v4 or earlier), instead of sharing:
|
||||
`Buffer.from(array.buffer)` (or `new Buffer(array.buffer)` Node 4 or earlier),
|
||||
because some functions return subarrays of their buffers.
|
||||
|
||||
|
||||
### Public-key authenticated encryption (box)
|
||||
|
||||
Implements *x25519-xsalsa20-poly1305*.
|
||||
|
||||
#### nacl.box.keyPair()
|
||||
|
||||
Generates a new random key pair for box and returns it as an object with
|
||||
`publicKey` and `secretKey` members:
|
||||
|
||||
{
|
||||
publicKey: ..., // Uint8Array with 32-byte public key
|
||||
secretKey: ... // Uint8Array with 32-byte secret key
|
||||
}
|
||||
|
||||
|
||||
#### nacl.box.keyPair.fromSecretKey(secretKey)
|
||||
|
||||
Returns a key pair for box with public key corresponding to the given secret
|
||||
key.
|
||||
|
||||
#### nacl.box(message, nonce, theirPublicKey, mySecretKey)
|
||||
|
||||
Encrypts and authenticates message using peer's public key, our secret key, and
|
||||
the given nonce, which must be unique for each distinct message for a key pair.
|
||||
|
||||
Returns an encrypted and authenticated message, which is
|
||||
`nacl.box.overheadLength` longer than the original message.
|
||||
|
||||
#### nacl.box.open(box, nonce, theirPublicKey, mySecretKey)
|
||||
|
||||
Authenticates and decrypts the given box with peer's public key, our secret
|
||||
key, and the given nonce.
|
||||
|
||||
Returns the original message, or `null` if authentication fails.
|
||||
|
||||
#### nacl.box.before(theirPublicKey, mySecretKey)
|
||||
|
||||
Returns a precomputed shared key which can be used in `nacl.box.after` and
|
||||
`nacl.box.open.after`.
|
||||
|
||||
#### nacl.box.after(message, nonce, sharedKey)
|
||||
|
||||
Same as `nacl.box`, but uses a shared key precomputed with `nacl.box.before`.
|
||||
|
||||
#### nacl.box.open.after(box, nonce, sharedKey)
|
||||
|
||||
Same as `nacl.box.open`, but uses a shared key precomputed with `nacl.box.before`.
|
||||
|
||||
#### Constants
|
||||
|
||||
##### nacl.box.publicKeyLength = 32
|
||||
|
||||
Length of public key in bytes.
|
||||
|
||||
##### nacl.box.secretKeyLength = 32
|
||||
|
||||
Length of secret key in bytes.
|
||||
|
||||
##### nacl.box.sharedKeyLength = 32
|
||||
|
||||
Length of precomputed shared key in bytes.
|
||||
|
||||
##### nacl.box.nonceLength = 24
|
||||
|
||||
Length of nonce in bytes.
|
||||
|
||||
##### nacl.box.overheadLength = 16
|
||||
|
||||
Length of overhead added to box compared to original message.
|
||||
|
||||
|
||||
### Secret-key authenticated encryption (secretbox)
|
||||
|
||||
Implements *xsalsa20-poly1305*.
|
||||
|
||||
#### nacl.secretbox(message, nonce, key)
|
||||
|
||||
Encrypts and authenticates message using the key and the nonce. The nonce must
|
||||
be unique for each distinct message for this key.
|
||||
|
||||
Returns an encrypted and authenticated message, which is
|
||||
`nacl.secretbox.overheadLength` longer than the original message.
|
||||
|
||||
#### nacl.secretbox.open(box, nonce, key)
|
||||
|
||||
Authenticates and decrypts the given secret box using the key and the nonce.
|
||||
|
||||
Returns the original message, or `null` if authentication fails.
|
||||
|
||||
#### Constants
|
||||
|
||||
##### nacl.secretbox.keyLength = 32
|
||||
|
||||
Length of key in bytes.
|
||||
|
||||
##### nacl.secretbox.nonceLength = 24
|
||||
|
||||
Length of nonce in bytes.
|
||||
|
||||
##### nacl.secretbox.overheadLength = 16
|
||||
|
||||
Length of overhead added to secret box compared to original message.
|
||||
|
||||
|
||||
### Scalar multiplication
|
||||
|
||||
Implements *x25519*.
|
||||
|
||||
#### nacl.scalarMult(n, p)
|
||||
|
||||
Multiplies an integer `n` by a group element `p` and returns the resulting
|
||||
group element.
|
||||
|
||||
#### nacl.scalarMult.base(n)
|
||||
|
||||
Multiplies an integer `n` by a standard group element and returns the resulting
|
||||
group element.
|
||||
|
||||
#### Constants
|
||||
|
||||
##### nacl.scalarMult.scalarLength = 32
|
||||
|
||||
Length of scalar in bytes.
|
||||
|
||||
##### nacl.scalarMult.groupElementLength = 32
|
||||
|
||||
Length of group element in bytes.
|
||||
|
||||
|
||||
### Signatures
|
||||
|
||||
Implements [ed25519](http://ed25519.cr.yp.to).
|
||||
|
||||
#### nacl.sign.keyPair()
|
||||
|
||||
Generates new random key pair for signing and returns it as an object with
|
||||
`publicKey` and `secretKey` members:
|
||||
|
||||
{
|
||||
publicKey: ..., // Uint8Array with 32-byte public key
|
||||
secretKey: ... // Uint8Array with 64-byte secret key
|
||||
}
|
||||
|
||||
#### nacl.sign.keyPair.fromSecretKey(secretKey)
|
||||
|
||||
Returns a signing key pair with public key corresponding to the given
|
||||
64-byte secret key. The secret key must have been generated by
|
||||
`nacl.sign.keyPair` or `nacl.sign.keyPair.fromSeed`.
|
||||
|
||||
#### nacl.sign.keyPair.fromSeed(seed)
|
||||
|
||||
Returns a new signing key pair generated deterministically from a 32-byte seed.
|
||||
The seed must contain enough entropy to be secure. This method is not
|
||||
recommended for general use: instead, use `nacl.sign.keyPair` to generate a new
|
||||
key pair from a random seed.
|
||||
|
||||
#### nacl.sign(message, secretKey)
|
||||
|
||||
Signs the message using the secret key and returns a signed message.
|
||||
|
||||
#### nacl.sign.open(signedMessage, publicKey)
|
||||
|
||||
Verifies the signed message and returns the message without signature.
|
||||
|
||||
Returns `null` if verification failed.
|
||||
|
||||
#### nacl.sign.detached(message, secretKey)
|
||||
|
||||
Signs the message using the secret key and returns a signature.
|
||||
|
||||
#### nacl.sign.detached.verify(message, signature, publicKey)
|
||||
|
||||
Verifies the signature for the message and returns `true` if verification
|
||||
succeeded or `false` if it failed.
|
||||
|
||||
#### Constants
|
||||
|
||||
##### nacl.sign.publicKeyLength = 32
|
||||
|
||||
Length of signing public key in bytes.
|
||||
|
||||
##### nacl.sign.secretKeyLength = 64
|
||||
|
||||
Length of signing secret key in bytes.
|
||||
|
||||
##### nacl.sign.seedLength = 32
|
||||
|
||||
Length of seed for `nacl.sign.keyPair.fromSeed` in bytes.
|
||||
|
||||
##### nacl.sign.signatureLength = 64
|
||||
|
||||
Length of signature in bytes.
|
||||
|
||||
|
||||
### Hashing
|
||||
|
||||
Implements *SHA-512*.
|
||||
|
||||
#### nacl.hash(message)
|
||||
|
||||
Returns SHA-512 hash of the message.
|
||||
|
||||
#### Constants
|
||||
|
||||
##### nacl.hash.hashLength = 64
|
||||
|
||||
Length of hash in bytes.
|
||||
|
||||
|
||||
### Random bytes generation
|
||||
|
||||
#### nacl.randomBytes(length)
|
||||
|
||||
Returns a `Uint8Array` of the given length containing random bytes of
|
||||
cryptographic quality.
|
||||
|
||||
**Implementation note**
|
||||
|
||||
TweetNaCl.js uses the following methods to generate random bytes,
|
||||
depending on the platform it runs on:
|
||||
|
||||
* `window.crypto.getRandomValues` (WebCrypto standard)
|
||||
* `window.msCrypto.getRandomValues` (Internet Explorer 11)
|
||||
* `crypto.randomBytes` (Node.js)
|
||||
|
||||
If the platform doesn't provide a suitable PRNG, the following functions,
|
||||
which require random numbers, will throw exception:
|
||||
|
||||
* `nacl.randomBytes`
|
||||
* `nacl.box.keyPair`
|
||||
* `nacl.sign.keyPair`
|
||||
|
||||
Other functions are deterministic and will continue working.
|
||||
|
||||
If a platform you are targeting doesn't implement secure random number
|
||||
generator, but you somehow have a cryptographically-strong source of entropy
|
||||
(not `Math.random`!), and you know what you are doing, you can plug it into
|
||||
TweetNaCl.js like this:
|
||||
|
||||
nacl.setPRNG(function(x, n) {
|
||||
// ... copy n random bytes into x ...
|
||||
});
|
||||
|
||||
Note that `nacl.setPRNG` *completely replaces* internal random byte generator
|
||||
with the one provided.
|
||||
|
||||
|
||||
### Constant-time comparison
|
||||
|
||||
#### nacl.verify(x, y)
|
||||
|
||||
Compares `x` and `y` in constant time and returns `true` if their lengths are
|
||||
non-zero and equal, and their contents are equal.
|
||||
|
||||
Returns `false` if either of the arguments has zero length, or arguments have
|
||||
different lengths, or their contents differ.
|
||||
|
||||
|
||||
System requirements
|
||||
-------------------
|
||||
|
||||
TweetNaCl.js supports modern browsers that have a cryptographically secure
|
||||
pseudorandom number generator and typed arrays, including the latest versions
|
||||
of:
|
||||
|
||||
* Chrome
|
||||
* Firefox
|
||||
* Safari (Mac, iOS)
|
||||
* Internet Explorer 11
|
||||
|
||||
Other systems:
|
||||
|
||||
* Node.js
|
||||
|
||||
|
||||
Development and testing
|
||||
------------------------
|
||||
|
||||
Install NPM modules needed for development:
|
||||
|
||||
$ npm install
|
||||
|
||||
To build minified versions:
|
||||
|
||||
$ npm run build
|
||||
|
||||
Tests use minified version, so make sure to rebuild it every time you change
|
||||
`nacl.js` or `nacl-fast.js`.
|
||||
|
||||
### Testing
|
||||
|
||||
To run tests in Node.js:
|
||||
|
||||
$ npm run test-node
|
||||
|
||||
By default all tests described here work on `nacl.min.js`. To test other
|
||||
versions, set environment variable `NACL_SRC` to the file name you want to test.
|
||||
For example, the following command will test fast minified version:
|
||||
|
||||
$ NACL_SRC=nacl-fast.min.js npm run test-node
|
||||
|
||||
To run full suite of tests in Node.js, including comparing outputs of
|
||||
JavaScript port to outputs of the original C version:
|
||||
|
||||
$ npm run test-node-all
|
||||
|
||||
To prepare tests for browsers:
|
||||
|
||||
$ npm run build-test-browser
|
||||
|
||||
and then open `test/browser/test.html` (or `test/browser/test-fast.html`) to
|
||||
run them.
|
||||
|
||||
To run tests in both Node and Electron:
|
||||
|
||||
$ npm test
|
||||
|
||||
### Benchmarking
|
||||
|
||||
To run benchmarks in Node.js:
|
||||
|
||||
$ npm run bench
|
||||
$ NACL_SRC=nacl-fast.min.js npm run bench
|
||||
|
||||
To run benchmarks in a browser, open `test/benchmark/bench.html` (or
|
||||
`test/benchmark/bench-fast.html`).
|
||||
|
||||
|
||||
Benchmarks
|
||||
----------
|
||||
|
||||
For reference, here are benchmarks from MacBook Pro (Retina, 13-inch, Mid 2014)
|
||||
laptop with 2.6 GHz Intel Core i5 CPU (Intel) in Chrome 53/OS X and Xiaomi Redmi
|
||||
Note 3 smartphone with 1.8 GHz Qualcomm Snapdragon 650 64-bit CPU (ARM) in
|
||||
Chrome 52/Android:
|
||||
|
||||
| | nacl.js Intel | nacl-fast.js Intel | nacl.js ARM | nacl-fast.js ARM |
|
||||
| ------------- |:-------------:|:-------------------:|:-------------:|:-----------------:|
|
||||
| salsa20 | 1.3 MB/s | 128 MB/s | 0.4 MB/s | 43 MB/s |
|
||||
| poly1305 | 13 MB/s | 171 MB/s | 4 MB/s | 52 MB/s |
|
||||
| hash | 4 MB/s | 34 MB/s | 0.9 MB/s | 12 MB/s |
|
||||
| secretbox 1K | 1113 op/s | 57583 op/s | 334 op/s | 14227 op/s |
|
||||
| box 1K | 145 op/s | 718 op/s | 37 op/s | 368 op/s |
|
||||
| scalarMult | 171 op/s | 733 op/s | 56 op/s | 380 op/s |
|
||||
| sign | 77 op/s | 200 op/s | 20 op/s | 61 op/s |
|
||||
| sign.open | 39 op/s | 102 op/s | 11 op/s | 31 op/s |
|
||||
|
||||
(You can run benchmarks on your devices by clicking on the links at the bottom
|
||||
of the [home page](https://tweetnacl.js.org)).
|
||||
|
||||
In short, with *nacl-fast.js* and 1024-byte messages you can expect to encrypt and
|
||||
authenticate more than 57000 messages per second on a typical laptop or more than
|
||||
14000 messages per second on a $170 smartphone, sign about 200 and verify 100
|
||||
messages per second on a laptop or 60 and 30 messages per second on a smartphone,
|
||||
per CPU core (with Web Workers you can do these operations in parallel),
|
||||
which is good enough for most applications.
|
||||
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
See AUTHORS.md file.
|
||||
|
||||
|
||||
Third-party libraries based on TweetNaCl.js
|
||||
-------------------------------------------
|
||||
|
||||
* [forward-secrecy](https://github.com/alax/forward-secrecy) — Axolotl ratchet implementation
|
||||
* [nacl-stream](https://github.com/dchest/nacl-stream-js) - streaming encryption
|
||||
* [tweetnacl-auth-js](https://github.com/dchest/tweetnacl-auth-js) — implementation of [`crypto_auth`](http://nacl.cr.yp.to/auth.html)
|
||||
* [tweetnacl-sealed-box](https://github.com/whs/tweetnacl-sealed-box) — implementation of [`sealed boxes`](https://download.libsodium.org/doc/public-key_cryptography/sealed_boxes.html)
|
||||
* [chloride](https://github.com/dominictarr/chloride) - unified API for various NaCl modules
|
||||
|
||||
|
||||
Who uses it
|
||||
-----------
|
||||
|
||||
Some notable users of TweetNaCl.js:
|
||||
|
||||
* [GitHub](https://github.com)
|
||||
* [MEGA](https://github.com/meganz/webclient)
|
||||
* [Stellar](https://www.stellar.org/)
|
||||
* [miniLock](https://github.com/kaepora/miniLock)
|
||||
+2391
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
!function(i){"use strict";var v=function(r){var t,n=new Float64Array(16);if(r)for(t=0;t<r.length;t++)n[t]=r[t];return n},h=function(){throw new Error("no PRNG")},o=new Uint8Array(16),n=new Uint8Array(32);n[0]=9;var s=v(),u=v([1]),p=v([56129,1]),c=v([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),y=v([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),e=v([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),a=v([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),l=v([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function f(r,t,n,e){r[t]=n>>24&255,r[t+1]=n>>16&255,r[t+2]=n>>8&255,r[t+3]=255&n,r[t+4]=e>>24&255,r[t+5]=e>>16&255,r[t+6]=e>>8&255,r[t+7]=255&e}function w(r,t,n,e,o){var i,h=0;for(i=0;i<o;i++)h|=r[t+i]^n[e+i];return(1&h-1>>>8)-1}function b(r,t,n,e){return w(r,t,n,e,16)}function g(r,t,n,e){return w(r,t,n,e,32)}function A(r,t,n,e){!function(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,A=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=i,d=h,E=a,x=f,M=s,m=u,B=c,S=y,k=l,K=w,Y=v,L=p,T=b,z=g,R=A,P=_,N=0;N<20;N+=2)U^=(o=(T^=(o=(k^=(o=(M^=(o=U+T|0)<<7|o>>>25)+U|0)<<9|o>>>23)+M|0)<<13|o>>>19)+k|0)<<18|o>>>14,m^=(o=(d^=(o=(z^=(o=(K^=(o=m+d|0)<<7|o>>>25)+m|0)<<9|o>>>23)+K|0)<<13|o>>>19)+z|0)<<18|o>>>14,Y^=(o=(B^=(o=(E^=(o=(R^=(o=Y+B|0)<<7|o>>>25)+Y|0)<<9|o>>>23)+R|0)<<13|o>>>19)+E|0)<<18|o>>>14,P^=(o=(L^=(o=(S^=(o=(x^=(o=P+L|0)<<7|o>>>25)+P|0)<<9|o>>>23)+x|0)<<13|o>>>19)+S|0)<<18|o>>>14,U^=(o=(x^=(o=(E^=(o=(d^=(o=U+x|0)<<7|o>>>25)+U|0)<<9|o>>>23)+d|0)<<13|o>>>19)+E|0)<<18|o>>>14,m^=(o=(M^=(o=(S^=(o=(B^=(o=m+M|0)<<7|o>>>25)+m|0)<<9|o>>>23)+B|0)<<13|o>>>19)+S|0)<<18|o>>>14,Y^=(o=(K^=(o=(k^=(o=(L^=(o=Y+K|0)<<7|o>>>25)+Y|0)<<9|o>>>23)+L|0)<<13|o>>>19)+k|0)<<18|o>>>14,P^=(o=(R^=(o=(z^=(o=(T^=(o=P+R|0)<<7|o>>>25)+P|0)<<9|o>>>23)+T|0)<<13|o>>>19)+z|0)<<18|o>>>14;U=U+i|0,d=d+h|0,E=E+a|0,x=x+f|0,M=M+s|0,m=m+u|0,B=B+c|0,S=S+y|0,k=k+l|0,K=K+w|0,Y=Y+v|0,L=L+p|0,T=T+b|0,z=z+g|0,R=R+A|0,P=P+_|0,r[0]=U>>>0&255,r[1]=U>>>8&255,r[2]=U>>>16&255,r[3]=U>>>24&255,r[4]=d>>>0&255,r[5]=d>>>8&255,r[6]=d>>>16&255,r[7]=d>>>24&255,r[8]=E>>>0&255,r[9]=E>>>8&255,r[10]=E>>>16&255,r[11]=E>>>24&255,r[12]=x>>>0&255,r[13]=x>>>8&255,r[14]=x>>>16&255,r[15]=x>>>24&255,r[16]=M>>>0&255,r[17]=M>>>8&255,r[18]=M>>>16&255,r[19]=M>>>24&255,r[20]=m>>>0&255,r[21]=m>>>8&255,r[22]=m>>>16&255,r[23]=m>>>24&255,r[24]=B>>>0&255,r[25]=B>>>8&255,r[26]=B>>>16&255,r[27]=B>>>24&255,r[28]=S>>>0&255,r[29]=S>>>8&255,r[30]=S>>>16&255,r[31]=S>>>24&255,r[32]=k>>>0&255,r[33]=k>>>8&255,r[34]=k>>>16&255,r[35]=k>>>24&255,r[36]=K>>>0&255,r[37]=K>>>8&255,r[38]=K>>>16&255,r[39]=K>>>24&255,r[40]=Y>>>0&255,r[41]=Y>>>8&255,r[42]=Y>>>16&255,r[43]=Y>>>24&255,r[44]=L>>>0&255,r[45]=L>>>8&255,r[46]=L>>>16&255,r[47]=L>>>24&255,r[48]=T>>>0&255,r[49]=T>>>8&255,r[50]=T>>>16&255,r[51]=T>>>24&255,r[52]=z>>>0&255,r[53]=z>>>8&255,r[54]=z>>>16&255,r[55]=z>>>24&255,r[56]=R>>>0&255,r[57]=R>>>8&255,r[58]=R>>>16&255,r[59]=R>>>24&255,r[60]=P>>>0&255,r[61]=P>>>8&255,r[62]=P>>>16&255,r[63]=P>>>24&255}(r,t,n,e)}function _(r,t,n,e){!function(r,t,n,e){for(var o,i=255&e[0]|(255&e[1])<<8|(255&e[2])<<16|(255&e[3])<<24,h=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,a=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,f=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,s=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,u=255&e[4]|(255&e[5])<<8|(255&e[6])<<16|(255&e[7])<<24,c=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,y=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,l=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,w=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,v=255&e[8]|(255&e[9])<<8|(255&e[10])<<16|(255&e[11])<<24,p=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,b=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,A=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,_=255&e[12]|(255&e[13])<<8|(255&e[14])<<16|(255&e[15])<<24,U=0;Line truncated
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// Type definitions for TweetNaCl.js
|
||||
|
||||
export as namespace nacl;
|
||||
|
||||
declare var nacl: nacl;
|
||||
export = nacl;
|
||||
|
||||
declare namespace nacl {
|
||||
export interface BoxKeyPair {
|
||||
publicKey: Uint8Array;
|
||||
secretKey: Uint8Array;
|
||||
}
|
||||
|
||||
export interface SignKeyPair {
|
||||
publicKey: Uint8Array;
|
||||
secretKey: Uint8Array;
|
||||
}
|
||||
|
||||
export interface secretbox {
|
||||
(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
|
||||
open(box: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | null;
|
||||
readonly keyLength: number;
|
||||
readonly nonceLength: number;
|
||||
readonly overheadLength: number;
|
||||
}
|
||||
|
||||
export interface scalarMult {
|
||||
(n: Uint8Array, p: Uint8Array): Uint8Array;
|
||||
base(n: Uint8Array): Uint8Array;
|
||||
readonly scalarLength: number;
|
||||
readonly groupElementLength: number;
|
||||
}
|
||||
|
||||
namespace boxProps {
|
||||
export interface open {
|
||||
(msg: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array | null;
|
||||
after(box: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array | null;
|
||||
}
|
||||
|
||||
export interface keyPair {
|
||||
(): BoxKeyPair;
|
||||
fromSecretKey(secretKey: Uint8Array): BoxKeyPair;
|
||||
}
|
||||
}
|
||||
|
||||
export interface box {
|
||||
(msg: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
||||
before(publicKey: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
||||
after(msg: Uint8Array, nonce: Uint8Array, key: Uint8Array): Uint8Array;
|
||||
open: boxProps.open;
|
||||
keyPair: boxProps.keyPair;
|
||||
readonly publicKeyLength: number;
|
||||
readonly secretKeyLength: number;
|
||||
readonly sharedKeyLength: number;
|
||||
readonly nonceLength: number;
|
||||
readonly overheadLength: number;
|
||||
}
|
||||
|
||||
namespace signProps {
|
||||
export interface detached {
|
||||
(msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
||||
verify(msg: Uint8Array, sig: Uint8Array, publicKey: Uint8Array): boolean;
|
||||
}
|
||||
|
||||
export interface keyPair {
|
||||
(): SignKeyPair;
|
||||
fromSecretKey(secretKey: Uint8Array): SignKeyPair;
|
||||
fromSeed(secretKey: Uint8Array): SignKeyPair;
|
||||
}
|
||||
}
|
||||
|
||||
export interface sign {
|
||||
(msg: Uint8Array, secretKey: Uint8Array): Uint8Array;
|
||||
open(signedMsg: Uint8Array, publicKey: Uint8Array): Uint8Array | null;
|
||||
detached: signProps.detached;
|
||||
keyPair: signProps.keyPair;
|
||||
readonly publicKeyLength: number;
|
||||
readonly secretKeyLength: number;
|
||||
readonly seedLength: number;
|
||||
readonly signatureLength: number;
|
||||
}
|
||||
|
||||
export interface hash {
|
||||
(msg: Uint8Array): Uint8Array;
|
||||
readonly hashLength: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare interface nacl {
|
||||
randomBytes(n: number): Uint8Array;
|
||||
secretbox: nacl.secretbox;
|
||||
scalarMult: nacl.scalarMult;
|
||||
box: nacl.box;
|
||||
sign: nacl.sign;
|
||||
hash: nacl.hash;
|
||||
verify(x: Uint8Array, y: Uint8Array): boolean;
|
||||
setPRNG(fn: (x: Uint8Array, n: number) => void): void;
|
||||
}
|
||||
+1178
File diff suppressed because it is too large.
Load diff
+1
@@ -0,0 +1 @@
|
||||
!function(i){"use strict";var m=function(r,n){this.hi=0|r,this.lo=0|n},v=function(r){var n,e=new Float64Array(16);if(r)for(n=0;n<r.length;n++)e[n]=r[n];return e},a=function(){throw new Error("no PRNG")},o=new Uint8Array(16),e=new Uint8Array(32);e[0]=9;var c=v(),w=v([1]),g=v([56129,1]),y=v([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),l=v([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),t=v([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),f=v([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),s=v([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function h(r,n){return r<<n|r>>>32-n}function b(r,n){var e=255&r[n+3];return(e=(e=e<<8|255&r[n+2])<<8|255&r[n+1])<<8|255&r[n+0]}function B(r,n){var e=r[n]<<24|r[n+1]<<16|r[n+2]<<8|r[n+3],t=r[n+4]<<24|r[n+5]<<16|r[n+6]<<8|r[n+7];return new m(e,t)}function p(r,n,e){var t;for(t=0;t<4;t++)r[n+t]=255&e,e>>>=8}function S(r,n,e){r[n]=e.hi>>24&255,r[n+1]=e.hi>>16&255,r[n+2]=e.hi>>8&255,r[n+3]=255&e.hi,r[n+4]=e.lo>>24&255,r[n+5]=e.lo>>16&255,r[n+6]=e.lo>>8&255,r[n+7]=255&e.lo}function u(r,n,e,t,o){var i,a=0;for(i=0;i<o;i++)a|=r[n+i]^e[t+i];return(1&a-1>>>8)-1}function A(r,n,e,t){return u(r,n,e,t,16)}function _(r,n,e,t){return u(r,n,e,t,32)}function U(r,n,e,t,o){var i,a,f,u=new Uint32Array(16),c=new Uint32Array(16),w=new Uint32Array(16),y=new Uint32Array(4);for(i=0;i<4;i++)c[5*i]=b(t,4*i),c[1+i]=b(e,4*i),c[6+i]=b(n,4*i),c[11+i]=b(e,16+4*i);for(i=0;i<16;i++)w[i]=c[i];for(i=0;i<20;i++){for(a=0;a<4;a++){for(f=0;f<4;f++)y[f]=c[(5*a+4*f)%16];for(y[1]^=h(y[0]+y[3]|0,7),y[2]^=h(y[1]+y[0]|0,9),y[3]^=h(y[2]+y[1]|0,13),y[0]^=h(y[3]+y[2]|0,18),f=0;f<4;f++)u[4*a+(a+f)%4]=y[f]}for(f=0;f<16;f++)c[f]=u[f]}if(o){for(i=0;i<16;i++)c[i]=c[i]+w[i]|0;for(i=0;i<4;i++)c[5*i]=c[5*i]-b(t,4*i)|0,c[6+i]=c[6+i]-b(n,4*i)|0;for(i=0;i<4;i++)p(r,4*i,c[5*i]),p(r,16+4*i,c[6+i])}else for(i=0;i<16;i++)p(r,4*i,c[i]+w[i]|0)}function E(r,n,e,t){U(r,n,e,t,!1)}function x(r,n,e,t){return U(r,n,e,t,!0),0}var d=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function K(r,n,e,t,o,i,a){var f,u,c=new Uint8Array(16),w=new Uint8Array(64);if(!o)return 0;for(u=0;u<16;u++)c[u]=0;for(u=0;u<8;u++)c[u]=i[u];for(;64<=o;){for(E(w,c,a,d),u=0;u<64;u++)r[n+u]=(e?e[t+u]:0)^w[u];for(f=1,u=8;u<16;u++)f=f+(255&c[u])|0,c[u]=255&f,f>>>=8;o-=64,n+=64,e&&(t+=64)}if(0<o)for(E(w,c,a,d),u=0;u<o;u++)r[n+u]=(e?e[t+u]:0)^w[u];return 0}function Y(r,n,e,t,o){return K(r,n,null,0,e,t,o)}function L(r,n,e,t,o){var i=new Uint8Array(32);return x(i,t,o,d),Y(r,n,e,t.subarray(16),i)}function T(r,n,e,t,o,i,a){var f=new Uint8Array(32);return x(f,i,a,d),K(r,n,e,t,o,i.subarray(16),f)}function k(r,n){var e,t=0;for(e=0;e<17;e++)t=t+(r[e]+n[e]|0)|0,r[e]=255&t,t>>>=8}var z=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function R(r,n,e,t,o,i){var a,f,u,c,w=new Uint32Array(17),y=new Uint32Array(17),l=new Uint32Array(17),s=new Uint32Array(17),h=new Uint32Array(17);for(u=0;u<17;u++)y[u]=l[u]=0;for(u=0;u<16;u++)y[u]=i[u];for(y[3]&=15,y[4]&=252,y[7]&=15,y[8]&=252,y[11]&=15,y[12]&=252,y[15]&=15;0<o;){for(u=0;u<17;u++)s[u]=0;for(u=0;u<16&&u<o;++u)s[u]=e[t+u];for(s[u]=1,t+=u,o-=u,k(l,s),f=0;f<17;f++)for(u=w[f]=0;u<17;u++)w[f]=w[f]+l[u]*(u<=f?y[f-u]:320*y[f+17-u]|0)|0;for(f=0;f<17;f++)l[f]=w[f];for(u=c=0;u<16;u++)c=c+l[u]|0,l[u]=255&c,c>>>=8;for(c=c+l[16]|0,l[16]=3&c,c=5*(c>>>2)|0,u=0;u<16;u++)c=c+l[u]|0,l[u]=255&c,c>>>=8;c=c+l[16]|0,l[16]=c}for(u=0;u<17;u++)h[u]=l[u];for(k(l,z),a=0|-(l[16]>>>7),u=0;u<17;u++)l[u]^=a&(h[u]^l[u]);for(u=0;u<16;u++)s[u]=i[u+16];for(s[16]=0,k(l,s),u=0;u<16;u++)r[n+u]=l[u];return 0}function P(r,n,e,t,o,i){var a=new Uint8Array(16);return R(a,0,e,t,o,i),A(r,n,a,0)}function M(r,n,e,t,o){var i;if(e<32)return-1;for(T(r,0,n,0,e,t,o),R(r,16,r,32,e-32,r),i=0;i<16;i++)r[i]=0;return 0}function N(r,n,e,t,o){var i,a=new Uint8Array(32);if(e<32)return-1;if(L(a,0,32,t,o),0!==P(n,16,n,32,e-32,a))return-1;for(T(r,0,n,0,e,t,o),i=0;i<32;i++)r[i]=0;return 0}function O(r,n){var e;for(e=0;e<16;e++)r[e]=0|n[e]}function C(r){var n,e;for(e=0;e<16;e++)r[e]+=65536,n=Math.floor(r[e]/65536),r[(e+1)*(e<15?1:0)]+=n-1+37*(n-1)*(15===e?1:0),r[e]-=65536*n}function F(r,n,e){for(var t,o=~(e-1),i=0;i<16;i++)t=o&(r[i]^n[i]),r[i]^=t,n[i]^=t}function Z(r,n){var e,t,o,i=v(),a=v();for(e=0;e<16;e++)a[e]=n[e];for(C(a),C(a),C(a),t=0;t<2;t++){for(i[0]=a[0]-65517,e=1;e<15;e++)i[e]=a[e]-65535-(i[e-1]>>16&1),i[e-1]&=65535;i[15]=a[15]-32767-(i[14]>>16&1),o=i[15]>>16&1,i[14]&=65535,F(a,i,1-o)}for(e=0;e<16;e++)r[2*e]=255&a[e],r[2*e+1]=a[e]>>8}function G(r,n){var e=new Uint8Array(32),t=new Uint8Array(32);return Z(e,r),Z(t,n),_(e,0,t,0)}function q(r){var n=new Uint8Array(32);return Z(n,r),1&n[0]}function D(r,n){var e;for(e=0;e<16;e++)r[e]=n[2*e]+(n[2*e+1]<<8);r[15]&=32767}function I(r,n,e){var t;for(t=0;t<16;t++)r[t]=n[t]+e[t]|0}functionLine truncated
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "tweetnacl",
|
||||
"version": "1.0.3",
|
||||
"description": "Port of TweetNaCl cryptographic library to JavaScript",
|
||||
"main": "nacl-fast.js",
|
||||
"types": "nacl.d.ts",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "uglifyjs nacl.js -c -m -o nacl.min.js && uglifyjs nacl-fast.js -c -m -o nacl-fast.min.js",
|
||||
"test-node": "tape test/*.js | faucet",
|
||||
"test-node-all": "make -C test/c && tape test/*.js test/c/*.js | faucet",
|
||||
"build-test-browser": "browserify test/browser/init.js test/*.js | uglifyjs -c -m -o test/browser/_bundle.js 2>/dev/null && browserify test/browser/init.js test/*.quick.js | uglifyjs -c -m -o test/browser/_bundle-quick.js 2>/dev/null",
|
||||
"test": "npm run test-node-all",
|
||||
"bench": "node test/benchmark/bench.js",
|
||||
"lint": "eslint nacl.js nacl-fast.js test/*.js test/benchmark/*.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/dchest/tweetnacl-js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"crypto",
|
||||
"cryptography",
|
||||
"curve25519",
|
||||
"ed25519",
|
||||
"encrypt",
|
||||
"hash",
|
||||
"key",
|
||||
"nacl",
|
||||
"poly1305",
|
||||
"public",
|
||||
"salsa20",
|
||||
"signatures"
|
||||
],
|
||||
"author": "TweetNaCl-js contributors",
|
||||
"license": "Unlicense",
|
||||
"bugs": {
|
||||
"url": "https://github.com/dchest/tweetnacl-js/issues"
|
||||
},
|
||||
"homepage": "https://tweetnacl.js.org",
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3",
|
||||
"eslint": "^6.8.0",
|
||||
"faucet": "^0.0.1",
|
||||
"tap-browser-color": "^0.1.2",
|
||||
"tape": "^4.13.0",
|
||||
"tweetnacl-util": "^0.15.0",
|
||||
"uglify-js": "^3.7.5"
|
||||
},
|
||||
"browser": {
|
||||
"buffer": false,
|
||||
"crypto": false
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user