One-Time Authentication
Bindings for the crypto_onetimeauth API. See the libsodium crypto_onetimeauth docs for more information.
Constants
Buffer lengths (integer)
crypto_onetimeauth_BYTES
crypto_onetimeauth_KEYBYTES
crypto_onetimeauth_STATEBYTES
String constants (string)
crypto_onetimeauth_PRIMITIVE
crypto_onetimeauth
sodium.crypto_onetimeauth(out, in, k)
Creates an authentication token based on a onetime k.
out
should be abuffer
of lengthcrypto_onetimauth_BYTES
in
should be abuffer
of any sizek
should be abuffer
of lengthcrypto_onetimeauth_KEYBYTES
The generated token is stored in out
.
crypto_onetimeauth_verify
var bool = sodium.crypto_onetimeauth_verify(out, in, k)
Verifies a token.
out
should be abuffer
of lengthcrypto_onetimeauth_BYTES
in
should be abuffer
of any sizek
should be abuffer
of lengthcrypto_onetimeauth_KEYBYTES
Returns true
if the token could be verified. Otherwise false
.
Instance API
crypto_onetimeauth_instance
var instance = sodium.crypto_onetimeauth_instance(k)
Creates an instance that creates a token from a onetime k and a stream of in data.
k
should be abuffer
of lengthcrypto_onetimeauth_KEYBYTES
instance.update
instance.update(in)
Updates the instance with a new piece of data.
in
should be abuffer
of any length
instance.final
instance.final(out)
Finalizes the instance.
out
should be abuffer
of lengthcrypto_onetimeauth_BYTES
The generated hash is stored in out
.
Stateful API
Replaces the above instance implementation in the N-API release
crypto_onetimeauth_init
var state = Buffer.alloc(crypto_onetimeauth_STATEBYTES)
sodium.crypto_onetimeauth_init(state, k)
Initialise a new auth state with a k.
state
must be a buffer of lengthcrypto_onetimeauth_STATEBYTES
bytesk
must be a buffer of lengthcrypto_onetimeauth_STATEBYTES
bytes
crypto_onetimeauth_update
sodium.crypto_onetimeauth_update(state, in)
Update a hash state with a given in.
state
must be a buffer of lengthcrypto_onetimeauth_STATEBYTES
bytesin
should be a abuffer
of any length
crypto_onetimeauth_final(state, out)
sodium.crypto_onetimeauth_final(state, out)
Finalize a given hash state and write the digest to out
buffer
state
must be a buffer of lengthcrypto_onetimeauth_STATEBYTES
bytesout
must be abuffer
of lengthcrypto_onetimeauth_BYTES
bytes