Closed shelby3 closed 7 years ago
Thanks for code review! Can you please send a pull request?
Don't forget to run benchmarks:
$ npm run bench
$ NACL_SRC=nacl-fast.min.js npm run bench
because JavaScript VMs are very sensitive to such little tweaks.
I will do it if ever I am set up to do that. At the moment, I am simply reading through the code and also separating various functions into modular libraries, because I experimenting with organizing the code to be more modular so I could in theory use the components separately, which is of course risky as it wouldn't leverage your tests (so I may rethink this strategy). Please feel free to do it before I do.
Thanks!
Regarding your last point, I have another open source library in the works, written in TypeScript, which is more modular (not in sense of npm modules, I'd still like to preserve it as a whole library):
├── crypto
│ ├── aead
│ │ ├── chacha20poly1305.bench.ts
│ │ ├── chacha20poly1305.test.ts
│ │ ├── chacha20poly1305.ts
│ │ ├── gcm.bench.ts
│ │ ├── gcm.test.ts
│ │ ├── gcm.ts
│ │ └── index.ts
│ ├── auth
│ │ ├── cmac.bench.ts
│ │ ├── cmac.test.ts
│ │ ├── cmac.ts
│ │ ├── hmac.test.ts
│ │ ├── hmac.ts
│ │ ├── poly1305.bench.ts
│ │ ├── poly1305.test.ts
│ │ └── poly1305.ts
│ ├── cipher
│ │ ├── aes.bench.ts
│ │ ├── aes.test.ts
│ │ ├── aes.ts
│ │ ├── chacha.bench.ts
│ │ ├── chacha.test.ts
│ │ ├── chacha.ts
│ │ ├── ctr.bench.ts
│ │ ├── ctr.test.ts
│ │ ├── ctr.ts
│ │ ├── index.ts
│ │ ├── salsa20.bench.ts
│ │ ├── salsa20.test.ts
│ │ ├── salsa20.ts
│ │ ├── xsalsa20.bench.ts
│ │ ├── xsalsa20.test.ts
│ │ └── xsalsa20.ts
│ ├── constanttime.test.ts
│ ├── constanttime.ts
│ ├── dh
│ │ ├── dh.bench.ts
│ │ ├── dh.test.ts
│ │ ├── dh.ts
│ │ ├── x25519.bench.ts
│ │ ├── x25519.test.ts
│ │ └── x25519.ts
│ ├── hash
│ │ ├── blake2s.bench.ts
│ │ ├── blake2s.test.ts
│ │ ├── blake2s.ts
│ │ ├── index.ts
│ │ ├── sha224.test.ts
│ │ ├── sha224.ts
│ │ ├── sha256.bench.ts
│ │ ├── sha256.test.ts
│ │ ├── sha256.ts
│ │ ├── sha3.bench.ts
│ │ ├── sha3.test.ts
│ │ ├── sha3.ts
│ │ ├── sha384.test.ts
│ │ ├── sha384.ts
│ │ ├── sha512.bench.ts
│ │ ├── sha512.test.ts
│ │ └── sha512.ts
│ ├── kdf
│ │ ├── hkdf.bench.ts
│ │ ├── hkdf.test.ts
│ │ ├── hkdf.ts
│ │ ├── pbkdf2.bench.ts
│ │ ├── pbkdf2.test.ts
│ │ ├── pbkdf2.ts
│ │ ├── scrypt.bench.ts
│ │ ├── scrypt.test.ts
│ │ └── scrypt.ts
│ ├── keyagreement
│ │ ├── cecpq1.bench.ts
│ │ ├── cecpq1.test.ts
│ │ ├── cecpq1.ts
│ │ ├── concat.ts
│ │ ├── index.ts
│ │ ├── newhope.bench.ts
│ │ ├── newhope.test.ts
│ │ ├── newhope.ts
│ │ ├── newhopeaessha.bench.ts
│ │ ├── newhopeaessha.test.ts
│ │ ├── newhopeaessha.ts
│ │ ├── x25519ka.bench.ts
│ │ ├── x25519ka.test.ts
│ │ └── x25519ka.ts
│ ├── nacl
│ │ ├── box.ts
│ │ ├── secretbox.bench.ts
│ │ ├── secretbox.test.ts
│ │ └── secretbox.ts
│ ├── protocol
│ │ ├── srp.bench.ts
│ │ ├── srp.test.ts
│ │ ├── srp.ts
│ │ ├── tss.bench.ts
│ │ ├── tss.test.ts
│ │ └── tss.ts
│ ├── random
│ │ ├── drbg
│ │ │ ├── chachadrbg.bench.ts
│ │ │ ├── chachadrbg.ts
│ │ │ ├── hmacdrbg.bench.ts
│ │ │ └── hmacdrbg.ts
│ │ ├── index.test.ts
│ │ ├── index.ts
│ │ └── source
│ │ ├── browser.ts
│ │ ├── index.ts
│ │ ├── node.ts
│ │ ├── system.test.ts
│ │ └── system.ts
│ └── sign
│ ├── ed25519.bench.ts
│ ├── ed25519.test.ts
│ └── ed25519.ts
├── datastruct
│ ├── bytereader.bench.ts
│ ├── bytereader.test.ts
│ ├── bytereader.ts
│ ├── bytewriter.bench.ts
│ ├── bytewriter.test.ts
│ └── bytewriter.ts
├── encoding
│ ├── base64.bench.ts
│ ├── base64.test.ts
│ ├── base64.ts
│ ├── binary.test.ts
│ ├── binary.ts
│ ├── cbor.bench.ts
│ ├── cbor.test.ts
│ ├── cbor.ts
│ ├── hex.bench.ts
│ ├── hex.test.ts
│ ├── hex.ts
│ ├── utf8.bench.ts
│ ├── utf8.test.ts
│ └── utf8.ts
├── math
│ ├── bigint.test.ts
│ ├── bigint.ts
│ ├── gf256.bench.ts
│ ├── gf256.test.ts
│ ├── gf256.ts
│ ├── int.test.ts
│ └── int.ts
└── utils
├── benchmark.ts
├── bytes.bench.ts
├── bytes.test.ts
├── bytes.ts
└── wipe.ts
18 directories, 135 files
However, the point of this library is to keep it a one-file TweetNaCl.c-like that you could even compare to the original (https://tweetnacl.js.org/diff -- this is an old version, though, with bugs).
The values are being loaded from a
Uint8Array
, thus they are already masked by0xff
.