Module sodium

Types

SodiumError* = object of Exception
  Source
GenericHash* = tuple[state: string, out_len: int]
  Source

Consts

libsodium_fn* = "libsodium.so.18"
  Source

Procs

proc randombytes*(size: int): string
  Source
proc randombytes_stir*() {.sodium_import.}
Reseeds the pseudorandom number generator - if supported.   Source
proc memcmp*(a, b: string): bool
Constant-time test for equality   Source
proc is_zero*(data: string): bool
Returns true if a byte string contains only zeros. Time constant for a given length.   Source
proc bin2hex*(data: string): string
  Source
proc hex2bin*(data: string; ignore = ""): string
  Source
proc crypto_secretbox_easy*(key: string; msg: string): string
Encrypt + sign a variable len string with a preshared key A random nonce is generated from /dev/urandom and prepended to the output   Source
proc crypto_secretbox_open_easy*(key: string; bulk: string): string
Decrypt + sign a variable len string with a preshared key A nonce is expected at the beginning of the input string   Source
proc crypto_auth*(message, key: string): string
  Source
proc crypto_auth_verify*(mac, message, key: string): bool
  Source
proc verify_message*(key: string; msg: string; signature: string)
verify a message signed using ed25519 if the signature is not provided, it is assumed that it is found at the beginning of the message   Source
proc sign_message*(key, message: string): string
sign a message using ed25519   Source
proc crypto_box_keypair*(): (CryptoBoxPublicKey, CryptoBoxSecretKey)
  Source
proc crypto_box_easy*(message, nonce: string; public_key: CryptoBoxPublicKey;
                     secret_key: CryptoBoxSecretKey): string
  Source
proc crypto_box_open_easy*(ciphertext, nonce: string;
                          public_key: CryptoBoxPublicKey;
                          secret_key: CryptoBoxSecretKey): string
  Source
proc crypto_sign_keypair*(): (PublicKey, SecretKey)
Generate a random public and secret key   Source
proc crypto_sign_seed_keypair*(seed: string): (PublicKey, SecretKey)
Deterministically generate a public and secret key from a seed   Source
proc crypto_sign_detached*(secret_key: SecretKey; message: string): string
  Source
proc crypto_sign_verify_detached*(public_key: PublicKey; message, signature: string)
  Source
proc crypto_sign_ed25519_sk_to_seed*(secret_key: SecretKey): string
Extract the seed from a secret key   Source
proc crypto_sign_ed25519_sk_to_pk*(secret_key: SecretKey): PublicKey
Extract the public key from a secret key   Source
proc crypto_box_seal*(message: string; public_key: PublicKey): string
Encrypt a message using the receiver public key   Source
proc crypto_box_seal_open*(ciphertext: string; public_key: PublicKey;
                          secret_key: SecretKey): string
Decrypt a ciphertext using a public and secret key   Source
proc crypto_generichash*(data: string;
                        hashlen: int = crypto_generichash_BYTES().int;
                        key: string = nil): string
Generate a hash of "data" of len "hashlen" using an optional key hashlen defaults to crypto_generichash_BYTES   Source
proc new_generic_hash*(key: string; out_len: int = crypto_generichash_BYTES().int): GenericHash
Create a new multipart hash, returns a GenericHash. The GenericHash is to be updated with .update() Upon calling .finalize() on it it will return a hash value of length "out_len"   Source
proc update*(self: GenericHash; data: string)
Update the multipart hash with more data   Source
proc finalize*(self: GenericHash): string
Finish the multipart hash and return the hash value as a string   Source
proc crypto_shorthash*(data: string; key: ShortHashKey): string
Hash optimized for short inputs   Source
proc generate_key_for_short_hash*(): ShortHashKey
  Source
proc crypto_scalarmult_base*(secret_key: string): string
  Source
proc crypto_scalarmult*(secret_key, public_key: string): string
Compute a shared secret given a secret key and another user's public key. The Sodium library recommends not using the shared secred directly, rather a hash of the shared secred concatenated with the public keys from both users   Source
proc crypto_onetimeauth*(message, key: string): string
One-time authentication using Poly1305 Warning: Use unpredictable, secret, unique keys   Source
proc crypto_onetimeauth_verify*(tok, message, key: string): bool
Verify onetimeauth   Source

Templates

template zeroed*(length: int): expr
Return a zeroed string   Source