1 /* hashkey.h -- definition of hash key type and helper functions
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
11 * @brief definition of hash key type and helper functions
14 #ifndef _COAP_HASHKEY_H_
15 #define _COAP_HASHKEY_H_
19 typedef unsigned char coap_key_t[4];
23 * Calculates a fast hash over the given string @p s of length @p len
24 * and stores the result into @p h. Depending on the exact
25 * implementation, this function cannot be used as one-way function to
26 * check message integrity or simlar.
28 * @param s The string used for hash calculation.
29 * @param len The length of @p s.
30 * @param h The result buffer to store the calculated hash key.
32 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h);
34 #define coap_hash(String,Length,Result) \
35 coap_hash_impl((String),(Length),(Result))
37 /* This is used to control the pre-set hash-keys for resources. */
38 #define __COAP_DEFAULT_HASH
40 #undef __COAP_DEFAULT_HASH
41 #endif /* coap_hash */
44 * Calls coap_hash() with given @c str object as parameter.
46 * @param Str Must contain a pointer to a coap string object.
47 * @param H A coap_key_t object to store the result.
51 #define coap_str_hash(Str,H) { \
53 memset((H), 0, sizeof(coap_key_t)); \
54 coap_hash((H), (Str)->s, (Str)->length); \
57 #endif /* _COAP_HASHKEY_H_ */