libcoap  4.2.1
coap_hashkey.c
Go to the documentation of this file.
1 /* coap_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 "coap_internal.h"
10 
11 void
12 coap_hash_impl(const unsigned char *s, unsigned int len, coap_key_t h) {
13  size_t j;
14 
15  while (len--) {
16  j = sizeof(coap_key_t)-1;
17 
18  while (j) {
19  h[j] = ((h[j] << 7) | (h[j-1] >> 1)) + h[j];
20  --j;
21  }
22 
23  h[0] = (h[0] << 7) + h[0] + *s++;
24  }
25 }
26 
unsigned char coap_key_t[4]
Definition: coap_hashkey.h:22
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: coap_hashkey.c:12
Pulls together all the internal only header files.