AEZ implementation for node
This is an implementation of the AEZ authenticated-encryption scheme in JavaScript for node.
The code is based upon Yawning's implementation in Go and the reference implementation in C.
I am by no means an expert in high performance JavaScript or the underlying cryptography. So this library might be really slow.
The current version passes all test vectors generated with this hacked version of aez. But the author does not give any guarantees that the algorithm is implemented correctly for every edge case!
How to install
NPM:
npm install --save aez
yarn:
yarn add aez
How to use
NOTE: Every parameter that is not a number should be of type Buffer
(or array of Buffer
).
const aez = ;const Buffer = Buffer; const key = Buffer; // sha256 of 'my-secret-key', but you should use a key derivation function like scrypt or PBKDF2!const salt = Buffer; // some random saltconst plaintext = Buffer;const tau = 4; const cipherText = aez;console; const decryptedText = aez;console;
API
aez.encrypt(key : Buffer, nonce : Buffer, additionalData : Buffer[], tau : Number, plaintext : Buffer) : Buffer
Encrypts a plaintext buffer with the given key, nonce and additionalData.
aez.decrypt(key : Buffer, nonce : Buffer, additionalData : Buffer[], tau : Number, ciphertext : Buffer) : Buffer
Decrypts a ciphertext buffer with the given key, nonce and additionalData.
If the key is incorrect, null
is returned.
Performance
The code is not yet optimized for performance.
The following throughputs were achieved on an Intel Core i7-6500U running on linux/amd64:
$ node test/aez_benchmark.jsMessage size: 1 bytes x 18,225 ops/sec ±2.01% 60 us/op 16.3 kB/sMessage size: 32 bytes x 18,561 ops/sec ±1.88% 58 us/op 540.6 kB/sMessage size: 512 bytes x 7,669 ops/sec ±1.46% 139 us/op 3.5 MB/sMessage size: 1024 bytes x 4,804 ops/sec ±1.26% 221 us/op 4.4 MB/sMessage size: 2048 bytes x 2,607 ops/sec ±3.51% 406 us/op 4.8 MB/sMessage size: 16384 bytes x 413 ops/sec ±1.27% 2558 us/op 6.1 MB/sMessage size: 32768 bytes x 215 ops/sec ±0.62% 4910 us/op 6.4 MB/sMessage size: 65536 bytes x 109 ops/sec ±0.72% 9642 us/op 6.5 MB/sMessage size: 1024768 bytes x 7.23 ops/sec ±0.82% 140133 us/op 7.0 MB/sDone in 49.59s.