2016-08-01 15:33:32 +00:00
|
|
|
#ifndef MH_HULTIHASH_H
|
|
|
|
#define MH_HULTIHASH_H
|
|
|
|
|
2016-08-10 13:46:15 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-02-13 14:32:55 +00:00
|
|
|
/**
|
|
|
|
* Functions for working with a multihash.
|
|
|
|
* A multihash is a hash with a prefix "code" that
|
|
|
|
* helps determine what type of hash this is.
|
|
|
|
* code name
|
|
|
|
* 0x00 identity
|
|
|
|
* 0x11 sha1
|
|
|
|
* 0x12 sha2-256
|
|
|
|
* 0x13 sha2-512
|
|
|
|
* 0x14 sha3-512
|
|
|
|
* 0x15 sha3-384
|
|
|
|
* 0x16 sha3-256
|
|
|
|
* 0x17 sha3-224
|
|
|
|
* 0x18 shake-128
|
|
|
|
* 0x19 shake-256
|
|
|
|
* 0x40 blake2b
|
|
|
|
* 0x41 blake2s
|
|
|
|
* # 0x0400-0x040f reserved for application specific functions
|
|
|
|
* # 0x14 formerly had the name "sha3", now deprecated
|
|
|
|
*/
|
|
|
|
|
2016-11-07 22:05:49 +00:00
|
|
|
/**
|
|
|
|
* returns hash code or error (which is < 0)
|
|
|
|
* @param mh the multihash
|
|
|
|
* @param len the length of the multihash
|
|
|
|
* @returns errors ( < 0 ) or the multihash
|
|
|
|
*/
|
2016-08-10 13:46:15 +00:00
|
|
|
int mh_multihash_hash(const unsigned char *multihash, size_t len);
|
2016-08-01 15:33:32 +00:00
|
|
|
|
2016-11-07 22:05:49 +00:00
|
|
|
/***
|
|
|
|
* returns the length of the multihash's data section
|
|
|
|
* @param mh the multihash
|
|
|
|
* @param len the length of the multihash
|
|
|
|
* @returns the length of the data section, or an error if < 0
|
|
|
|
*/
|
2016-08-10 13:46:15 +00:00
|
|
|
int mh_multihash_length(const unsigned char *multihash, size_t len);
|
|
|
|
|
2016-11-07 22:05:49 +00:00
|
|
|
/**
|
|
|
|
* gives access to raw digest inside multihash buffer
|
|
|
|
* @param multihash the multihash
|
|
|
|
* @param len the length
|
|
|
|
* @param digest the results
|
|
|
|
* @returns error if less than zero, otherwise 0
|
|
|
|
*/
|
2016-12-15 17:41:14 +00:00
|
|
|
int mh_multihash_digest(const unsigned char *multihash, size_t len,
|
2016-10-23 15:28:49 +00:00
|
|
|
unsigned char **digest, size_t *digest_len);
|
2016-08-10 13:46:15 +00:00
|
|
|
|
2016-11-07 22:05:49 +00:00
|
|
|
/**
|
|
|
|
* determine the size of the multihash given the data size
|
|
|
|
* @param code currently not used
|
|
|
|
* @param hash_len the data size
|
|
|
|
* @returns hash_len + 2 (until the code parameter (varint) is added
|
|
|
|
*/
|
2016-08-15 16:46:39 +00:00
|
|
|
int mh_new_length(int code, size_t digest_len);
|
2016-08-10 13:46:15 +00:00
|
|
|
|
2016-11-07 22:05:49 +00:00
|
|
|
/***
|
|
|
|
* create a multihash based on some data
|
|
|
|
* @param buffer where to put the multihash
|
|
|
|
* @param code the code
|
|
|
|
* @param digest the data within the multihash
|
|
|
|
* @returns error (if < 0) or 0
|
|
|
|
*/
|
2016-11-14 13:11:21 +00:00
|
|
|
int mh_new(unsigned char* buffer, int code, const unsigned char *digest,
|
2016-08-15 16:46:39 +00:00
|
|
|
size_t digest_len);
|
2016-08-01 15:33:32 +00:00
|
|
|
|
|
|
|
#endif /* end of include guard */
|