lcx_hash.h Previous Back to the files list Hash functions. More... Data Structures struct cx_hash_info_t Hash description. More... struct cx_hash_header_s Common message digest context, used as abstract type. More... Macros #define CX_HASH_MAX_BLOCK_COUNT 65535 Typedefs typedef enum cx_md_e cx_md_t Convenience type. More... typedef struct cx_hash_header_s cx_hash_t Convenience type. More... Enumerations enum cx_md_e { CX_NONE = 0, CX_RIPEMD160 = 1, CX_SHA224 = 2, CX_SHA256 = 3, CX_SHA384 = 4, CX_SHA512 = 5, CX_KECCAK = 6, CX_SHA3 = 7, CX_GROESTL = 8, CX_BLAKE2B = 9, CX_SHAKE128 = 10, CX_SHAKE256 = 11, CX_SHA3_256 = 12, CX_SHA3_512 = 13 } Message digest algorithm identifiers. More... Functions size_t cx_hash_get_size (const cx_hash_t *ctx) cx_err_t cx_hash_no_throw (cx_hash_t *hash, uint32_t mode, const uint8_t *in, size_t len, uint8_t *out, size_t out_len) Hashes data according to the specified algorithm. More... static int cx_hash (cx_hash_t *hash, int mode, const unsigned char *in, unsigned int len, unsigned char *out, unsigned int out_len) Hashes data according to the specified algorithm. More... cx_err_t cx_hash_init (cx_hash_t *hash, cx_md_t hash_id) Initializes a hash context. More... cx_err_t cx_hash_init_ex (cx_hash_t *hash, cx_md_t hash_id, size_t output_size) Initializes a hash context. More... cx_err_t cx_hash_update (cx_hash_t *hash, const uint8_t *in, size_t in_len) Adds more data to hash. More... cx_err_t cx_hash_final (cx_hash_t *hash, uint8_t *digest) Finalizes the hash. More... Detailed Description Hash functions. A hash function maps data of arbitrary size to a bit array of a fixed size, called the message digest. Various hash functions are available: BLAKE2B GROESTL KECCAK (Pre SHA3) RIPEMD-160 SHAKE-128 SHAKE-256 SHA224 SHA256 SHA3 SHA384 SHA3_256 SHA3_512 SHA512 Macro Definition Documentation CX_HASH_MAX_BLOCK_COUNT #define CX_HASH_MAX_BLOCK_COUNT 65535 Typedef Documentation cx_hash_t typedef struct cx_hash_header_s cx_hash_t Convenience type. See cx_hash_header_s. cx_md_t typedef enum cx_md_e cx_md_t Convenience type. See cx_md_e. Enumeration Type Documentation cx_md_e enum cx_md_e Message digest algorithm identifiers. EnumeratorCX_NONE No message digest algorithm. CX_RIPEMD160 RIPEMD160 digest. CX_SHA224 SHA224 digest. CX_SHA256 SHA256 digest. CX_SHA384 SHA384 digest. CX_SHA512 SHA512 digest. CX_KECCAK Keccak (pre-SHA3) digest. CX_SHA3 SHA3 Digest. CX_GROESTL Groestl digest. CX_BLAKE2B Blake digest. CX_SHAKE128 SHAKE-128 digest. CX_SHAKE256 SHAKE-256 digest. CX_SHA3_256 SHA3-256 digest. CX_SHA3_512 SHA3-512 digest. Function Documentation cx_hash() static int cx_hash ( cx_hash_t * hash, int mode, const unsigned char * in, unsigned int len, unsigned char * out, unsigned int out_len ) Hashes data according to the specified algorithm. This function throws an exception if the computation doesn't succeed. WarningIt is recommended to use cx_hash_no_throw rather than this function. Parameters [in]hashPointer to the hash context. Shall be in RAM. Should be called with a cast. [in]modeCrypto flag. Supported flag: CX_LAST. If set: the structure is not modified after finishing if out is not NULL, the message digest is stored in out the context is NOT automatically re-initialized. [in]inInput data to be hashed. [in]lenLength of the input data. [out]outBuffer where to store the message digest: NULL (ignored) if CX_LAST is NOT set message digest if CX_LAST is set [out]out_lenThe size of the output buffer or 0 if out is NULL. If buffer is too small to store the hash an exception is thrown. ReturnsLength of the digest. Exceptions INVALID_PARAMETER CX_INVALID_PARAMETER cx_hash_final() cx_err_t cx_hash_final ( cx_hash_t * hash, uint8_t * digest ) Finalizes the hash. A call to this function is equivalent to: cx_hash_no_throw(hash, CX_LAST, NULL, 0, out, out_len). Parameters [in]hashPointer to the hash context. [out]digestThe message digest. ReturnsError code: CX_OK on success cx_hash_get_size() size_t cx_hash_get_size ( const cx_hash_t * ctx) cx_hash_init() cx_err_t cx_hash_init ( cx_hash_t * hash, cx_md_t hash_id ) Initializes a hash context. Parameters [out]hashPointer to the context to be initialized. The context shall be in RAM. [in]hash_idMessage digest algorithm identifier. ReturnsError code: CX_OK on success CX_INVALID_PARAMETER cx_hash_init_ex() cx_err_t cx_hash_init_ex ( cx_hash_t * hash, cx_md_t hash_id, size_t output_size ) Initializes a hash context. It initializes a hash context with a chosen output length (typically for eXtendable Output Functions (XOF)). Parameters [out]hashPointer to the context to be initialized. The context shall be in RAM. [in]hash_idHash algorithm identifier. Typically: CX_BLAKE2B CX_GROESTL CX_SHAKE128 CX_SHAKE256 [in]output_sizeLength of the output. ReturnsError code: CX_OK on success CX_INVALID_PARAMETER cx_hash_no_throw() cx_err_t cx_hash_no_throw ( cx_hash_t * hash, uint32_t mode, const uint8_t * in, size_t len, uint8_t * out, size_t out_len ) Hashes data according to the specified algorithm. Parameters [in]hashPointer to the hash context. Shall be in RAM. Should be called with a cast. [in]modeCrypto flag. Supported flag: CX_LAST. If set: the structure is not modified after finishing if out is not NULL, the message digest is stored in out the context is NOT automatically re-initialized. [in]inInput data to be hashed. [in]lenLength of the input data. [out]outBuffer where to store the message digest: NULL (ignored) if CX_LAST is NOT set message digest if CX_LAST is set [out]out_lenThe size of the output buffer or 0 if out is NULL. If buffer is too small to store the hash an error is returned. ReturnsError code: CX_OK on success INVALID_PARAMETER CX_INVALID_PARAMETER cx_hash_update() cx_err_t cx_hash_update ( cx_hash_t * hash, const uint8_t * in, size_t in_len ) Adds more data to hash. A call to this function is equivalent to: cx_hash_no_throw(hash, 0, in, in_len, NULL, 0). Parameters [out]hashPointer to the hash context. [in]inInput data to add to the context. [in]in_lenLength of the input data. ReturnsError code: CX_OK on success CX_INVALID_PARAMETER INVALID_PARAMETER Previous Back to the files list Did you find this page helpful? How would you improve this page for developers? I am a developer. Contributors will be chosen randomly to receive rewards. Check this box to send your email and participate. Ledger collects your email address to send you rewards for your contribution to improve the Developer Portal documentation. Learn more about how we manage your data and your rights. By providing your email address, you consent that Ledger may contact you for rewards delivery purposes. If you are part of the randomly selected contributors, we will send you an email to ask for your physical address and if necessary, ask you for additional information on the suggestion you made. Your information will only be available to Ledger and will be retained for no longer than 90 days. It may be transferred to non-European countries that ensure an adequate level of protection or under the standard contractual clauses adopted by the EU Commission. Please note that you may withdraw your consent at any time, access your data and request their rectification or deletion. You may also request the limitation of the processing of your data. To exercise your rights or for any question on the processing of your data, please contact LEDGER’s Data Protection Officer here. If nevertheless you believe LEDGER did not adequately address your concerns and mishandled your data, you may lodge a complaint with the personal data protection authority of your country.