AEAD (Authenticated Encryption with Additional Data)
Bindings for the crypto_aead_* APIs. See the libsodium AEAD docs for more information.
Currently, only crypto_aead_xchacha20poly1305_ietf
is exposed.
Constants
Buffer lengths (integer)
crypto_aead_xchacha20poly1305_ietf_ABYTES
crypto_aead_xchacha20poly1305_ietf_KEYBYTES
crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
crypto_aead_xchacha20poly1305_ietf_NSECBYTES
crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX
- Note this isNumber.MAX_SAFE_INTEGER
for now
crypto_aead_xchacha20poly1305_ietf_keygen
sodium.crypto_aead_xchacha20poly1305_ietf_keygen(k)
Generates a new encryption k.
k
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
.
The generated key is stored in k
.
crypto_aead_xchacha20poly1305_ietf_encrypt
var clen = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(c, m, [ad], null, npub, k)
Encrypts a message with (npub
, k
) and optional additional data ad
.
c
should be abuffer
of sizem.length + crypto_aead_xchacha20poly1305_ietf_ABYTES
m
should be abuffer
ad
is optional and should benull
or abuffer
. Included in the computation of authentication tag appended to the mnull
is in the position of the unusednsec
argument. This should always benull
npub
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTES
k
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to c
. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_decrypt
var mlen = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(m, null, c, [ad], npub, k)
Decrypts a message with (npub
, k
) and optional additional data ad
.
m
should be abuffer
of sizec.length - crypto_aead_xchacha20poly1305_ietf_ABYTES
null
is in the position of the unusednsec
argument. This should always benull
c
should be abuffer
ad
is optional and should benull
or abuffer
. Included in the computation of authentication tag appended to the mnpub
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTES
k
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to message
. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_encrypt_detached
var maclen = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt_detached(c, mac, m, [ad], null, npub, k)
Encrypts a message with (npub
, k
) and optional additional data ad
.
c
should be abuffer
of sizem.length
mac
should be abuffer
of sizecrypto_aead_xchacha20poly1305_ietf_ABYTES
m
should be abuffer
ad
is optional and should benull
or abuffer
. Included in the computation of authentication tag appended to the mnull
is in the position of the unusednsec
argument. This should always benull
npub
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTES
k
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns how many bytes were written to mac
. Note that in-place encryption is possible.
crypto_aead_xchacha20poly1305_ietf_decrypt_detached
sodium.crypto_aead_xchacha20poly1305_ietf_decrypt_detached(m, null, c, mac, [ad], npub, k)
Decrypts a message with (npub
, k
) and optional additional data ad
.
m
should be abuffer
of sizec.length
null
is in the position of the unusednsec
argument. This should always benull
c
should be abuffer
mac
should be abuffer
of sizecrypto_aead_xchacha20poly1305_ietf_ABYTES
ad
is optional and should benull
or abuffer
. Included in the computation of authentication tag appended to the mnpub
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_NPUBBYTES
k
should be abuffer
of lengthcrypto_aead_xchacha20poly1305_ietf_KEYBYTES
Returns nothing, but will throw on in case the MAC cannot be authenticated. Note that in-place encryption is possible.