From 97ef24340da7d3f55a39ba16b400d13f9bbe9e60 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Sun, 16 Apr 2017 12:04:59 +0200 Subject: ipcpd: Allow specifying the hash algorithm to use Currently CRC32, MD5, and SHA3 (224, 256, 384 and 512 bit) are supported. --- include/ouroboros/crc32.h | 2 ++ include/ouroboros/hash.h | 17 ++++++++++++++--- include/ouroboros/ipcp.h | 4 +++- 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/ouroboros/crc32.h b/include/ouroboros/crc32.h index dccdf7cb..800d6c4f 100644 --- a/include/ouroboros/crc32.h +++ b/include/ouroboros/crc32.h @@ -27,6 +27,8 @@ #include #include +#define CRC32_HASH_LEN 4 + void crc32(uint32_t * crc, const void * buf, size_t len); diff --git a/include/ouroboros/hash.h b/include/ouroboros/hash.h index a94b37ee..60bfbe30 100644 --- a/include/ouroboros/hash.h +++ b/include/ouroboros/hash.h @@ -28,6 +28,15 @@ #include #include +enum hash_algo { + HASH_CRC32 = 0, + HASH_MD5, + HASH_SHA3_224, + HASH_SHA3_256, + HASH_SHA3_384, + HASH_SHA3_512 +}; + #define HASH_FMT "%02x%02x%02x%02x" #define HASH_VAL(hash) \ ((*(unsigned int *) hash) & 0xFF000000) >> 24, \ @@ -35,8 +44,10 @@ ((*(unsigned int *) hash) & 0x0000FF00) >> 8, \ ((*(unsigned int *) hash) & 0x000000FF) -/* FIXME: Implement specifying algorithm */ -void get_hash(uint8_t buf[], - const char * name); +uint16_t hash_len(enum hash_algo algo); + +void str_hash(enum hash_algo algo, + void * buf, + const char * str); #endif /* OUROBOROS_LIB_HASH_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index f439f29b..4c815b83 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -24,6 +24,8 @@ #ifndef OUROBOROS_IPCP_H #define OUROBOROS_IPCP_H +#include + #include #include #include @@ -51,7 +53,7 @@ enum pol_gam { struct ipcp_config { char * dif_name; enum ipcp_type type; - uint16_t dir_hash_len; + enum hash_algo dir_hash_algo; /* Normal DIF */ uint8_t addr_size; -- cgit v1.2.3