sodium-native

sodium-native

  • Get Started
  • API
  • Github

›API

Get Started

  • Introduction
  • Projects using sodium-native

API

  • Compatibility
  • API
  • Memory Protection
  • Generating Random Data
  • Helpers
  • Padding
  • Signing
  • Generic Hashing
  • Public/Secret Key Box Encryption
  • Sealed Box Encryption
  • Secret Key Box Encryption
  • AEAD (Authenticated Encryption with Additional Data)
  • Non-Authenticated Streaming Encryption
  • Authentication
  • Stream Encryption
  • One-Time Authentication
  • Password Hashing
  • Key Exchange
  • Diffie-Hellman
  • Finite Field Arithmetic
  • Short Hashes
  • Key Derivation
  • SHA
  • License

Non-Authenticated Streaming Encryption

Bindings for the crypto_stream API. See the libsodium crypto_stream docs for more information.

Constants

Buffer lengths (integer)

  • crypto_stream_NONCEBYTES
  • crypto_stream_KEYBYTES
  • crypto_stream_xor_STATEBYTES

String constants (string)

  • crypto_stream_PRIMITIVE

crypto_stream

sodium-native sodium-javascript

sodium.crypto_stream(c, n, k)

Generates random data based on a nonce n and key k into the c.

  • c should be a buffer of any size
  • n should be a buffer of length crypto_stream_NONCEBYTES
  • k should be a secret k of length crypto_stream_KEYBYTES

The generated data is stored in c.


crypto_stream_xor

sodium-native sodium-javascript

sodium.crypto_stream_xor(c, m, n, k)

Encrypts, but not authenticates, a m based on a nonce n and key k

  • c should be a buffer of length m.length
  • m should be a buffer of any size
  • n should be a buffer of length crypto_stream_NONCEBYTES
  • k should be a secret k of length crypto_stream_KEYBYTES

The encrypted data is stored in c. To decrypt, swap c and m. Also supports in-place encryption where you use the same buffer as c and m.

Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor if you want to encrypt/decrypt with ChaCha20 instead.


crypto_stream_chacha20_xor

sodium-native

sodium.crypto_stream_chacha20_xor(c, m, n, k)

Encrypts, but not authenticates, a m based on a nonce n and key k

  • c should be a buffer of length m.length
  • m should be a buffer of any size
  • n should be a buffer of length crypto_stream_chacha20_NONCEBYTES
  • k should be a secret k of length crypto_stream_chacha20_KEYBYTES

The encrypted data is stored in c. To decrypt, swap c and m. Also supports in-place encryption where you use the same buffer as c and m.

Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor if you want to encrypt/decrypt with ChaCha20 instead.


Instance API

crypto_stream_xor_instance

sodium-native sodium-javascript

var instance = sodium.crypto_stream_xor_instance(n, k)

A streaming instance to the crypto_stream_xor API. Pass a nonce n and key k in the constructor.

Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor_instance if you want to encrypt/decrypt with ChaCha20 instead.

crypto_stream_chacha20_xor_instance

sodium-native

var instance = sodium.crypto_stream_chacha20_xor_instance(n, k)

A streaming instance to the crypto_stream_xor API. Pass a nonce n and key k in the constructor.

Encryption defaults to XSalsa20, use crypto_stream_chacha20_xor_instance if you want to encrypt/decrypt with ChaCha20 instead.

instance.update

instance.update(c, m)

Encrypts the next m.

instance.final

instance.final()

Finalizes the stream. Zeros out internal state.

Stateful API

Replaces the above instance implementation in the N-API release

crypto_stream_xor_init

sodium-native

var state = Buffer.alloc(crypto_stream_xor_STATEBYTES)

sodium.crypto_stream_xor_init(state, n, k)

Initialise a new xor state with a nonce n and key k.

  • state must be a buffer of length crypto_stream_xor_STATEBYTES bytes
  • n is must be buffer of crypto_stream_NONCEBYTES bytes
  • k is must be buffer of crypto_stream_KEYBYTES bytes

crypto_stream_xor_update

sodium-native

sodium.crypto_stream_xor_update(state, c, m)

Encrypt a message m and xor the result into ciphertext c. Update a hash state with a given input.

  • state must be a buffer of length crypto_stream_xor_STATEBYTES bytes
  • m should be a buffer
  • c should be a buffer of length m.byteLength bytes

crypto_stream_xor_final(state, out)

sodium-native

sodium.crypto_stream_xor_final(state)

Finalize a given xor state, zeroing out the state.

  • state must be a buffer of length crypto_stream_xor_STATEBYTES bytes

crypto_stream_chacha20_xor_init

sodium-native

var state = Buffer.alloc(crypto_stream_chacha20_xor_STATEBYTES)

sodium.crypto_stream_chacha20_xor_init(state, n, k)

Initialise a new xor state with a nonce n and key k.

  • state must be a buffer of length crypto_stream_chacha20_xor_STATEBYTES bytes
  • n is must be buffer of crypto_stream_chacha20_NONCEBYTES bytes
  • k is must be buffer of crypto_stream_chacha20_KEYBYTES bytes

crypto_stream_chacha20_xor_update

sodium-native

sodium.crypto_stream_chacha20_xor_update(state, c, m)

Encrypt a message m and xor the result into ciphertext c. Update a hash state with a given input.

  • state must be a buffer of length crypto_stream_chacha20_xor_STATEBYTES bytes
  • m should be a buffer
  • c should be a buffer of length m.byteLength bytes

crypto_stream_chacha20_xor_final(state, out)

sodium-native

sodium.crypto_stream_chacha20_xor_final(state)

Finalize a given xor state, zeroing out the state.

  • state must be a buffer of length crypto_stream_chacha20_xor_STATEBYTES bytes
← AEAD (Authenticated Encryption with Additional Data)Authentication →
  • Constants
  • crypto_stream
  • crypto_stream_xor
  • crypto_stream_chacha20_xor
  • Instance API
  • crypto_stream_xor_instance
  • crypto_stream_chacha20_xor_instance
  • instance.update
  • instance.final
  • Stateful API
  • crypto_stream_xor_init
  • crypto_stream_xor_update
  • crypto_stream_xor_final(state, out)
  • crypto_stream_chacha20_xor_init
  • crypto_stream_chacha20_xor_update
  • crypto_stream_chacha20_xor_final(state, out)
Docs
Get StartedAPI
Community
LibsodiumHyperdivisionHyperdivision on Twitter
More
GitHubStar
Copyright © 2020 Hyperdivision