BeRTOS
mac.h
Go to the documentation of this file.
00001 
00038 #ifndef SEC_MAC_H
00039 #define SEC_MAC_H
00040 
00041 #include <cfg/compiler.h>
00042 #include <cfg/debug.h>
00043 
00044 typedef struct Mac {
00045     uint8_t digest_len;
00046     uint8_t key_len;
00047 
00048     void (*set_key)(struct Mac *m, const void *key, size_t len);
00049     void (*begin)(struct Mac *m);
00050     void (*update)(struct Mac *m, const void *data, size_t len);
00051     uint8_t* (*final)(struct Mac *m);
00052 } Mac;
00053 
00054 INLINE void mac_set_key(Mac *m, const uint8_t* key, size_t len)
00055 {
00056     ASSERT(m->set_key);
00057     m->set_key(m, key, len);
00058 }
00059 
00060 INLINE void mac_begin(Mac *m)
00061 {
00062     ASSERT(m->begin);
00063     m->begin(m);
00064 }
00065 
00066 INLINE void mac_update(Mac *m, const void *data, size_t len)
00067 {
00068     ASSERT(m->update);
00069     m->update(m, data, len);
00070 }
00071 
00072 INLINE uint8_t* mac_final(Mac *m)
00073 {
00074     ASSERT(m->final);
00075     return m->final(m);
00076 }
00077 
00078 INLINE size_t mac_digest_len(Mac *m)
00079 {
00080     return m->digest_len;
00081 }
00082 
00083 INLINE size_t mac_key_len(Mac *m)
00084 {
00085     return m->key_len;
00086 }
00087 
00088 #endif