Crypto API Reference
Contents
Crypto API Reference#
The Crypto APIs provide an abstraction layer of cryptography functions.
ED25519 Keypair#
-
struct ed25519_keypair_t#
Ed25519 Keypair.
Random Bytes#
-
void iota_crypto_randombytes(uint8_t *const buf, const size_t len)#
Fill-in random bytes into the given byte buffer.
- Parameters
buf – [out] A buffer holds random bytes
len – [in] The length of the buffer
ED25519 keypair#
-
void iota_crypto_keypair(uint8_t const seed[], ed25519_keypair_t *keypair)#
Derives key pair from a given ed25519 seed.
- Parameters
seed – [in] A given seed with length of the ed25519 seed
keypair – [out] A keypair derived from the seed
ED25519 Signature#
-
int iota_crypto_sign(uint8_t const priv_key[], uint8_t msg[], size_t msg_len, uint8_t signature[])#
Signs message by the given ed25519 private key.
- Parameters
priv_key – [in] The ed25519 private key
msg – [in] A byte buffer holds the message data
msg_len – [in] The length of the message
signature – [out] The output signature
- Returns
int 0 on successful
-
int iota_crypto_sign_open(uint8_t msg[], size_t msg_len, uint8_t const pub_key[], uint8_t signature[])#
Verify if the signature is valid with the message and public key.
- Parameters
msg – [in] A byte buffer holds the message data
msg_len – [in] The length of the message
pub_key – [in] The ed25519 public key
signature – [in] The ed25519 signature
- Returns
int 0 if valid and -1 if invalid
HMAC-SHA-256#
-
int iota_crypto_hmacsha256(uint8_t const secret_key[], uint8_t msg[], size_t msg_len, uint8_t auth[])#
HMAC-SHA-256 hash computation.
- Parameters
secret_key – [in] The private/secret key
msg – [in] A buffer holds message data
msg_len – [in] The length of message
auth – [out] The output authentication
- Returns
int 0 on successful
HMAC-SHA-512#
-
int iota_crypto_hmacsha512(uint8_t const secret_key[], uint8_t msg[], size_t msg_len, uint8_t auth[])#
HMAC-SHA-512 hash computation.
- Parameters
secret_key – [in] The private/secret key
msg – [in] A buffer holds message data
msg_len – [in] The length of message
auth – [out] The output authentication
- Returns
int 0 on successful
SHA-256#
-
int iota_crypto_sha256(uint8_t const msg[], size_t msg_len, uint8_t hash[])#
SHA-256 computation.
- Parameters
msg – [in] The message
msg_len – [in] The length of message
hash – [out] The output hash
- Returns
int 0 on success
SHA-512#
-
int iota_crypto_sha512(uint8_t const msg[], size_t msg_len, uint8_t hash[])#
SHA-512 computation.
- Parameters
msg – [in] The message
msg_len – [in] The length of the message
hash – [out] The output hash
- Returns
int 0 on success
Blake2b#
-
int iota_blake2b_sum(uint8_t const msg[], size_t msg_len, uint8_t out[], size_t out_len)#
Blake2b hash computation.
- Parameters
msg – [in] The message to hash
msg_len – [in] The length of message
out – [out] An output hash
out_len – [out] The length of output hash
- Returns
int 0 on success
-
void *iota_blake2b_new_state()#
Create Blake2b state object which is needed for partially hash calculations.
- Returns
void* A pointer to the Blake2b state
-
void iota_blake2b_free_state(void *state)#
Free Blake2b state object.
- Parameters
state – [in] The state of hash function
-
int iota_blake2b_init(void *state, size_t out_len)#
Initialize Blake2b hash function.
- Parameters
state – [in] The state of hash function
out_len – [out] The length of output hash
- Returns
int 0 on success
-
int iota_blake2b_update(void *state, uint8_t const data[], size_t data_len)#
Provide additional data to hash in Blake2b hash function.
- Parameters
state – [in] The state of hash function
data – [in] The data to hash
data_len – [in] The length of data
- Returns
int 0 on success
-
int iota_blake2b_final(void *state, uint8_t out[], size_t out_len)#
Finalize Blake2b hash function.
- Parameters
state – [in] The state of hash function
out – [out] An output hash
out_len – [out] The length of output hash
- Returns
int 0 on success
PBKDF2 HMAC#
-
int iota_crypto_pbkdf2_hmac_sha512(char const pwd[], size_t pwd_len, char const salt[], size_t salt_len, int32_t iterations, uint8_t dk[], size_t dk_len)#
PBKDF2 HMAC SHA512 computation.
Ref: https://datatracker.ietf.org/doc/html/rfc2898#section-5.2
- Parameters
pwd – [in] The password buffer, an octet string
pwd_len – [in] The length of password
salt – [in] The salt buffer, an octet string
salt_len – [in] The length of salt
iterations – [in] The iteration counter, must be bigger than 0
dk – [out] The derived key
dk_len – [in] The length of derived key
- Returns
int 0 on success