Bindings

Refer to the Monocypher manual for details on the arguments. They are one-to-one mappings and return the expected values, e.g. crypto_check returns a boolean representing whether the signature is valid, crypto_verify16 returns whether the two byte strings match, etc. Additionally they are easier to use since you don’t have to pass in the accompanying length for each parameter.

All parameters which are expected to be uint8_t[] or uint8_t[K] in the Monocypher API can receive a bytes-like object as input. They also check that buffers are the right size. It is your responsibility to ensure that valid buffers are passed in. This also means you can wipe secrets:

secret_key = bytearray(32)
open('secret.txt', mode='rb').readinto(secret_key)

crypto_sign(secret_key, b'hello world!')
crypto_wipe(secret_key)
assert bytes(secret_key) == bytes(32)

However, there are some pitfalls in the name of convenience – e.g., if you use crypto_from_eddsa_private(), it returns a bytes object containing the derived X25519 private key – if you need that much control over memory, you probably know what you’re doing anyways.

monocypher.bindings.crypto_argon2i(password, salt, hash_size=64, nb_blocks=100000, nb_iterations=3, key=b'', ad=b'')
monocypher.bindings.crypto_blake2b(msg, key=b'', hash_size=64)
monocypher.bindings.crypto_blake2b_final(ctx)
monocypher.bindings.crypto_blake2b_init(key=b'', hash_size=64)
monocypher.bindings.crypto_blake2b_update(ctx, msg)
monocypher.bindings.crypto_check(sig, public_key, msg)
monocypher.bindings.crypto_from_eddsa_private(eddsa)
monocypher.bindings.crypto_from_eddsa_public(eddsa)
monocypher.bindings.crypto_key_exchange(your_secret_key, their_public_key)
monocypher.bindings.crypto_key_exchange_public_key(your_secret_key)
monocypher.bindings.crypto_lock(key, nonce, msg, ad=b'')
Returns:

(bytes(mac), bytes(ciphertext))

monocypher.bindings.crypto_sign(secret_key, msg)
monocypher.bindings.crypto_sign_public_key(secret_key)
monocypher.bindings.crypto_unlock(key, mac, nonce, ciphertext, ad=b'')
Returns:

None or bytes(msg)

monocypher.bindings.crypto_verify16(a, b)
monocypher.bindings.crypto_verify32(a, b)
monocypher.bindings.crypto_verify64(a, b)
monocypher.bindings.crypto_wipe(buf)
monocypher.bindings.crypto_x25519(your_secret_key, their_public_key)
monocypher.bindings.crypto_x25519_public_key(your_secret_key)