From c9e9962baaec325c44f2174e64e07ad0ebe05060 Mon Sep 17 00:00:00 2001 From: rasky Date: Fri, 24 Sep 2010 09:50:10 +0000 Subject: [PATCH] SEC: Add hash function interface git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4284 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/sec/hash.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 bertos/sec/hash.h diff --git a/bertos/sec/hash.h b/bertos/sec/hash.h new file mode 100644 index 00000000..4601e7ef --- /dev/null +++ b/bertos/sec/hash.h @@ -0,0 +1,81 @@ +/** + * \file + * + * + * \brief Generic interface for hashing algorithms. + * \author Giovanni Bajo + * + */ + +#ifndef SEC_HASH_H +#define SEC_HASH_H + +#include +#include + +typedef struct Hash +{ + void (*begin)(struct Hash *h); + void (*update)(struct Hash *h, const void *data, size_t len); + uint8_t* (*final)(struct Hash *h); + uint8_t digest_len; + uint8_t block_len; +} Hash; + +INLINE void hash_begin(Hash *h) +{ + ASSERT(h->begin); + h->begin(h); +} + +INLINE void hash_update(Hash *h, const void* data, size_t len) +{ + ASSERT(h->update); + h->update(h, data, len); +} + +INLINE uint8_t* hash_final(Hash *h) +{ + ASSERT(h->final); + return h->final(h); +} + +INLINE int hash_digest_len(Hash *h) +{ + return h->digest_len; +} + +INLINE int hash_block_len(Hash *h) +{ + return h->block_len; +} + +#endif /* SEC_HASH_H */ -- 2.25.1