BeRTOS
|
00001 00038 #ifndef SEC_HASH_H 00039 #define SEC_HASH_H 00040 00041 #include <cfg/compiler.h> 00042 #include <cfg/debug.h> 00043 00044 typedef struct Hash 00045 { 00046 void (*begin)(struct Hash *h); 00047 void (*update)(struct Hash *h, const void *data, size_t len); 00048 uint8_t* (*final)(struct Hash *h); 00049 uint8_t digest_len; 00050 uint8_t block_len; 00051 } Hash; 00052 00056 INLINE void hash_begin(Hash *h) 00057 { 00058 ASSERT(h->begin); 00059 h->begin(h); 00060 } 00061 00065 INLINE void hash_update(Hash *h, const void* data, size_t len) 00066 { 00067 ASSERT(h->update); 00068 h->update(h, data, len); 00069 } 00070 00081 INLINE uint8_t* hash_final(Hash *h) 00082 { 00083 ASSERT(h->final); 00084 return h->final(h); 00085 } 00086 00090 INLINE int hash_digest_len(Hash *h) 00091 { 00092 return h->digest_len; 00093 } 00094 00095 /* 00096 * Return the internal block length in bytes. 00097 * 00098 * Hash functions operate on a fixed-size block. This information is useful 00099 * for composite functions like HMAC to adjust their internal operations. 00100 */ 00101 INLINE int hash_block_len(Hash *h) 00102 { 00103 return h->block_len; 00104 } 00105 00106 #endif /* SEC_HASH_H */