Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / libcoap-4.1.1 / hashkey.c
1 /* hashkey.c -- 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 #include "hashkey.h"
10
11 /* Caution: When changing this, update COAP_DEFAULT_WKC_HASHKEY
12  * accordingly (see int coap_hash_path());
13  */
14 void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h)
15 {
16     size_t j;
17
18     while (len--)
19     {
20         j = sizeof(coap_key_t) - 1;
21
22         while (j)
23         {
24             h[j] = ((h[j] << 7) | (h[j - 1] >> 1)) + h[j];
25             --j;
26         }
27
28         h[0] = (h[0] << 7) + h[0] + *s++;
29     }
30 }
31