libcoap  4.1.2
hashkey.c
Go to the documentation of this file.
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
15 coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h) {
16  size_t j;
17 
18  while (len--) {
19  j = sizeof(coap_key_t)-1;
20 
21  while (j) {
22  h[j] = ((h[j] << 7) | (h[j-1] >> 1)) + h[j];
23  --j;
24  }
25 
26  h[0] = (h[0] << 7) + h[0] + *s++;
27  }
28 }
29 
void coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h)
Calculates a fast hash over the given string s of length len and stores the result into h...
Definition: hashkey.c:15
unsigned char coap_key_t[4]
Definition: hashkey.h:20
definition of hash key type and helper functions