iotivity 0.9.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / libcoap-4.1.1 / hashkey.h
1 /* hashkey.h -- definition of hash key type and helper functions
2  *
3  * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use. 
7  */
8
9 /** 
10  * @file hashkey.h
11  * @brief definition of hash key type and helper functions
12  */
13
14 #ifndef _COAP_HASHKEY_H_
15 #define _COAP_HASHKEY_H_
16
17 #include "str.h"
18
19 typedef unsigned char coap_key_t[4];
20
21 #ifndef coap_hash
22 /** 
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.
27  * 
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.
31  */
32 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h);
33
34 #define coap_hash(String,Length,Result) \
35   coap_hash_impl((String),(Length),(Result))
36
37 /* This is used to control the pre-set hash-keys for resources. */
38 #define __COAP_DEFAULT_HASH
39 #else
40 #undef __COAP_DEFAULT_HASH
41 #endif /* coap_hash */
42
43 /** 
44  * Calls coap_hash() with given @c str object as parameter.
45  * 
46  * @param Str Must contain a pointer to a coap string object.
47  * @param H   A coap_key_t object to store the result.
48  * 
49  * @hideinitializer
50  */
51 #define coap_str_hash(Str,H) {                  \
52     assert(Str);                                \
53     memset((H), 0, sizeof(coap_key_t));         \
54     coap_hash((H), (Str)->s, (Str)->length);    \
55   }
56
57 #endif /* _COAP_HASHKEY_H_ */