From: rasky Date: Fri, 24 Sep 2010 13:56:31 +0000 (+0000) Subject: SEC: add interface for message authentication codes. X-Git-Tag: 2.6.0~100 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8e03a3e8faf92d278f20a66a6d302fab790d6991;p=bertos.git SEC: add interface for message authentication codes. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4301 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/sec/mac.h b/bertos/sec/mac.h new file mode 100644 index 00000000..2fac40b8 --- /dev/null +++ b/bertos/sec/mac.h @@ -0,0 +1,88 @@ +/** + * \file + * + * + * \brief Generic interface for message authentication algorithms. + * \author Giovanni Bajo + * + */ + +#ifndef SEC_MAC_H +#define SEC_MAC_H + +#include +#include + +typedef struct Mac { + uint8_t digest_len; + uint8_t key_len; + + void (*set_key)(struct Mac *m, const uint8_t* key, size_t len); + void (*begin)(struct Mac *m); + void (*update)(struct Mac *m, const uint8_t *data, size_t len); + uint8_t* (*final)(struct Mac *m); +} Mac; + +INLINE void mac_set_key(Mac *m, const uint8_t* key, size_t len) +{ + ASSERT(m->set_key); + m->set_key(m, key, len); +} + +INLINE void mac_begin(Mac *m) +{ + ASSERT(m->begin); + m->begin(m); +} + +INLINE void mac_update(Mac *m, const void *data, size_t len) +{ + ASSERT(m->update); + m->update(m, data, len); +} + +INLINE uint8_t* mac_final(Mac *m) +{ + ASSERT(m->final); + return m->final(m); +} + +INLINE size_t mac_digest_len(Mac *m) +{ + return m->digest_len; +} + +INLINE size_t mac_key_len(Mac *m) +{ + return m->key_len; +} + +#endif