start working on hashes api

This commit is contained in:
Jakub Sztandera 2016-07-26 11:54:37 +01:00
parent f91684f3c8
commit 1cc9e705f9
3 changed files with 46 additions and 1 deletions

View file

@ -16,7 +16,7 @@ LDLIBS =
TARGET_LIB = mulithash.a TARGET_LIB = mulithash.a
TARGET_BIN = multihash TARGET_BIN = multihash
SRCS = errors.c SRCS = errors.c hashes.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
all: $(TARGET_LIB) $(TARGET_BIN) all: $(TARGET_LIB) $(TARGET_BIN)

43
hashes.c Normal file
View file

@ -0,0 +1,43 @@
/* vim: set ts=8 sw=8 noexpandtab: */
// list of avaliable hash functions.
typedef enum {
MH_H_SHA1,
MH_H_SHA2_256,
MH_H_SHA2_512,
MH_H_SHA3_512,
MH_H_SHA3_384,
MH_H_SHA3_256,
MH_H_SHA3_224,
MH_H_SHAKE_128,
MH_H_SHAKE_256,
MH_H_BLAKE2B,
MH_H_BLAKE2S,
HM_H_COUNT // number of hash functions
} mh_hash;
// returns default size in bytes of given hash function
int mh_hash_default_size(mh_hash hash);
// returns wire format code of given hash function
int mh_hash_code(mh_hash hash);
typedef struct {
mh_hash hash;
int code;
int length;
} mh_hashinfo
// decodes code info hash info, leaves length field zeroed
mh_error mh_hashinfo_from_code(int code, mh_hashinfo *hinfo);
// decodes bytes into hashinfo
mh_error mh_hashinfo_from_bytes(char bytes[2], mh_hashinfo *hinfo);

2
hashes.h Normal file
View file

@ -0,0 +1,2 @@
/* vim: set ts=8 sw=8 noexpandtab: */