@stablelib/chacha20poly1305
Advanced tools
Comparing version 0.0.2 to 0.1.2
@@ -18,3 +18,3 @@ // Copyright (C) 2016 Dmitry Chestnykh | ||
/** | ||
* ChaCha20-Poly1305 Authenticated Encryption with Additional Data. | ||
* ChaCha20-Poly1305 Authenticated Encryption with Associated Data. | ||
* | ||
@@ -41,3 +41,3 @@ * Defined in RFC7539. | ||
/** | ||
* Encrypts and authenticates plaintext, authenticates additional data, | ||
* Encrypts and authenticates plaintext, authenticates associated data, | ||
* and returns sealed ciphertext, which includes authentication tag. | ||
@@ -53,3 +53,3 @@ * | ||
*/ | ||
seal(nonce: Uint8Array, plaintext: Uint8Array, additionalData?: Uint8Array, | ||
seal(nonce: Uint8Array, plaintext: Uint8Array, associatedData?: Uint8Array, | ||
dst?: Uint8Array): Uint8Array { | ||
@@ -92,3 +92,3 @@ if (nonce.length > 16) { | ||
this._authenticate(result.subarray(result.length - this.tagLength, result.length), | ||
authKey, result.subarray(0, result.length - this.tagLength), additionalData); | ||
authKey, result.subarray(0, result.length - this.tagLength), associatedData); | ||
@@ -103,3 +103,3 @@ // Cleanup. | ||
* Authenticates sealed ciphertext (which includes authentication tag) and | ||
* additional data, decrypts ciphertext and returns decrypted plaintext. | ||
* associated data, decrypts ciphertext and returns decrypted plaintext. | ||
* | ||
@@ -115,3 +115,3 @@ * RFC7539 specifies 12 bytes for nonce. It may be this 12-byte nonce | ||
*/ | ||
open(nonce: Uint8Array, sealed: Uint8Array, additionalData?: Uint8Array, | ||
open(nonce: Uint8Array, sealed: Uint8Array, associatedData?: Uint8Array, | ||
dst?: Uint8Array): Uint8Array | null { | ||
@@ -143,3 +143,3 @@ if (nonce.length > 16) { | ||
this._authenticate(calculatedTag, authKey, | ||
sealed.subarray(0, sealed.length - this.tagLength), additionalData); | ||
sealed.subarray(0, sealed.length - this.tagLength), associatedData); | ||
@@ -180,3 +180,3 @@ // Constant-time compare tags and return null if they differ. | ||
private _authenticate(tagOut: Uint8Array, authKey: Uint8Array, | ||
ciphertext: Uint8Array, additionalData?: Uint8Array) { | ||
ciphertext: Uint8Array, associatedData?: Uint8Array) { | ||
@@ -186,7 +186,7 @@ // Initialize Poly1305 with authKey. | ||
// Authenticate padded additional data. | ||
if (additionalData) { | ||
h.update(additionalData); | ||
if (additionalData.length % 16 > 0) { | ||
h.update(ZEROS.subarray(additionalData.length % 16)); | ||
// Authenticate padded associated data. | ||
if (associatedData) { | ||
h.update(associatedData); | ||
if (associatedData.length % 16 > 0) { | ||
h.update(ZEROS.subarray(associatedData.length % 16)); | ||
} | ||
@@ -201,7 +201,7 @@ } | ||
// Authenticate length of additional data. | ||
// Authenticate length of associated data. | ||
// XXX: can avoid allocation here? | ||
const length = new Uint8Array(8); | ||
if (additionalData) { | ||
writeUint64LE(additionalData.length, length); | ||
if (associatedData) { | ||
writeUint64LE(associatedData.length, length); | ||
} | ||
@@ -208,0 +208,0 @@ h.update(length); |
@@ -6,3 +6,3 @@ import { AEAD } from "@stablelib/aead"; | ||
/** | ||
* ChaCha20-Poly1305 Authenticated Encryption with Additional Data. | ||
* ChaCha20-Poly1305 Authenticated Encryption with Associated Data. | ||
* | ||
@@ -20,3 +20,3 @@ * Defined in RFC7539. | ||
/** | ||
* Encrypts and authenticates plaintext, authenticates additional data, | ||
* Encrypts and authenticates plaintext, authenticates associated data, | ||
* and returns sealed ciphertext, which includes authentication tag. | ||
@@ -32,6 +32,6 @@ * | ||
*/ | ||
seal(nonce: Uint8Array, plaintext: Uint8Array, additionalData?: Uint8Array, dst?: Uint8Array): Uint8Array; | ||
seal(nonce: Uint8Array, plaintext: Uint8Array, associatedData?: Uint8Array, dst?: Uint8Array): Uint8Array; | ||
/** | ||
* Authenticates sealed ciphertext (which includes authentication tag) and | ||
* additional data, decrypts ciphertext and returns decrypted plaintext. | ||
* associated data, decrypts ciphertext and returns decrypted plaintext. | ||
* | ||
@@ -47,5 +47,5 @@ * RFC7539 specifies 12 bytes for nonce. It may be this 12-byte nonce | ||
*/ | ||
open(nonce: Uint8Array, sealed: Uint8Array, additionalData?: Uint8Array, dst?: Uint8Array): Uint8Array | null; | ||
open(nonce: Uint8Array, sealed: Uint8Array, associatedData?: Uint8Array, dst?: Uint8Array): Uint8Array | null; | ||
clean(): this; | ||
private _authenticate(tagOut, authKey, ciphertext, additionalData?); | ||
private _authenticate(tagOut, authKey, ciphertext, associatedData?); | ||
} |
@@ -15,3 +15,3 @@ // Copyright (C) 2016 Dmitry Chestnykh | ||
/** | ||
* ChaCha20-Poly1305 Authenticated Encryption with Additional Data. | ||
* ChaCha20-Poly1305 Authenticated Encryption with Associated Data. | ||
* | ||
@@ -34,3 +34,3 @@ * Defined in RFC7539. | ||
/** | ||
* Encrypts and authenticates plaintext, authenticates additional data, | ||
* Encrypts and authenticates plaintext, authenticates associated data, | ||
* and returns sealed ciphertext, which includes authentication tag. | ||
@@ -46,3 +46,3 @@ * | ||
*/ | ||
ChaCha20Poly1305.prototype.seal = function (nonce, plaintext, additionalData, dst) { | ||
ChaCha20Poly1305.prototype.seal = function (nonce, plaintext, associatedData, dst) { | ||
if (nonce.length > 16) { | ||
@@ -79,3 +79,3 @@ throw new Error("ChaCha20Poly1305: incorrect nonce length"); | ||
// subarray of result. | ||
this._authenticate(result.subarray(result.length - this.tagLength, result.length), authKey, result.subarray(0, result.length - this.tagLength), additionalData); | ||
this._authenticate(result.subarray(result.length - this.tagLength, result.length), authKey, result.subarray(0, result.length - this.tagLength), associatedData); | ||
// Cleanup. | ||
@@ -87,3 +87,3 @@ wipe_1.wipe(counter); | ||
* Authenticates sealed ciphertext (which includes authentication tag) and | ||
* additional data, decrypts ciphertext and returns decrypted plaintext. | ||
* associated data, decrypts ciphertext and returns decrypted plaintext. | ||
* | ||
@@ -99,3 +99,3 @@ * RFC7539 specifies 12 bytes for nonce. It may be this 12-byte nonce | ||
*/ | ||
ChaCha20Poly1305.prototype.open = function (nonce, sealed, additionalData, dst) { | ||
ChaCha20Poly1305.prototype.open = function (nonce, sealed, associatedData, dst) { | ||
if (nonce.length > 16) { | ||
@@ -121,3 +121,3 @@ throw new Error("ChaCha20Poly1305: incorrect nonce length"); | ||
var calculatedTag = new Uint8Array(this.tagLength); | ||
this._authenticate(calculatedTag, authKey, sealed.subarray(0, sealed.length - this.tagLength), additionalData); | ||
this._authenticate(calculatedTag, authKey, sealed.subarray(0, sealed.length - this.tagLength), associatedData); | ||
// Constant-time compare tags and return null if they differ. | ||
@@ -149,10 +149,10 @@ if (!constant_time_1.equal(calculatedTag, sealed.subarray(sealed.length - this.tagLength, sealed.length))) { | ||
}; | ||
ChaCha20Poly1305.prototype._authenticate = function (tagOut, authKey, ciphertext, additionalData) { | ||
ChaCha20Poly1305.prototype._authenticate = function (tagOut, authKey, ciphertext, associatedData) { | ||
// Initialize Poly1305 with authKey. | ||
var h = new poly1305_1.Poly1305(authKey); | ||
// Authenticate padded additional data. | ||
if (additionalData) { | ||
h.update(additionalData); | ||
if (additionalData.length % 16 > 0) { | ||
h.update(ZEROS.subarray(additionalData.length % 16)); | ||
// Authenticate padded associated data. | ||
if (associatedData) { | ||
h.update(associatedData); | ||
if (associatedData.length % 16 > 0) { | ||
h.update(ZEROS.subarray(associatedData.length % 16)); | ||
} | ||
@@ -165,7 +165,7 @@ } | ||
} | ||
// Authenticate length of additional data. | ||
// Authenticate length of associated data. | ||
// XXX: can avoid allocation here? | ||
var length = new Uint8Array(8); | ||
if (additionalData) { | ||
binary_1.writeUint64LE(additionalData.length, length); | ||
if (associatedData) { | ||
binary_1.writeUint64LE(associatedData.length, length); | ||
} | ||
@@ -172,0 +172,0 @@ h.update(length); |
{ | ||
"name": "@stablelib/chacha20poly1305", | ||
"version": "0.0.2", | ||
"version": "0.1.2", | ||
"description": "ChaCha20-Poly1305 AEAD (RFC 7539)", | ||
@@ -18,3 +18,3 @@ "main": "./dist/chacha20poly1305.js", | ||
"dependencies": { | ||
"@stablelib/aead": "^0.0.1", | ||
"@stablelib/aead": "^0.1.2", | ||
"@stablelib/binary": "^0.0.1", | ||
@@ -21,0 +21,0 @@ "@stablelib/chacha": "^0.0.1", |
+ Added@stablelib/aead@0.1.2(transitive)
- Removed@stablelib/aead@0.0.1(transitive)
Updated@stablelib/aead@^0.1.2