1 /* 2 * coap_hashkey.h -- definition of hash key type and helper functions 3 * 4 * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org> 5 * 6 * This file is part of the CoAP library libcoap. Please see README for terms 7 * of use. 8 */ 9 10 /** 11 * @file coap_hashkey.h 12 * @brief definition of hash key type and helper functions 13 */ 14 15 #ifndef COAP_HASHKEY_H_ 16 #define COAP_HASHKEY_H_ 17 18 #include "libcoap.h" 19 #include "uthash.h" 20 #include "str.h" 21 22 typedef unsigned char coap_key_t[4]; 23 24 #ifndef coap_hash 25 /** 26 * Calculates a fast hash over the given string @p s of length @p len and stores 27 * the result into @p h. Depending on the exact implementation, this function 28 * cannot be used as one-way function to check message integrity or simlar. 29 * 30 * @param s The string used for hash calculation. 31 * @param len The length of @p s. 32 * @param h The result buffer to store the calculated hash key. 33 */ 34 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h); 35 36 #define coap_hash(String,Length,Result) \ 37 coap_hash_impl((String),(Length),(Result)) 38 39 /* This is used to control the pre-set hash-keys for resources. */ 40 #define COAP_DEFAULT_HASH 41 #else 42 #undef COAP_DEFAULT_HASH 43 #endif /* coap_hash */ 44 45 /** 46 * Calls coap_hash() with given @c coap_string_t object as parameter. 47 * 48 * @param Str Must contain a pointer to a coap string object. 49 * @param H A coap_key_t object to store the result. 50 * 51 * @hideinitializer 52 */ 53 #define coap_str_hash(Str,H) { \ 54 assert(Str); \ 55 memset((H), 0, sizeof(coap_key_t)); \ 56 coap_hash((Str)->s, (Str)->length, (H)); \ 57 } 58 59 #endif /* COAP_HASHKEY_H_ */ 60