libcoap 4.3.0
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 * SPDX-License-Identifier: BSD-2-Clause
6 *
7 * This file is part of the CoAP library libcoap. Please see
8 * README for terms of use.
9 */
10
11#include "coap3/coap_internal.h"
12
13void
14coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h) {
15 size_t j;
16
17 while (len--) {
18 j = sizeof(coap_key_t)-1;
19
20 while (j) {
21 h[j] = ((h[j] << 7) | (h[j-1] >> 1)) + h[j];
22 --j;
23 }
24
25 h[0] = (h[0] << 7) + h[0] + *s++;
26 }
27}
28
void coap_hash_impl(const unsigned char *s, size_t 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:14
unsigned char coap_key_t[4]
Definition: coap_hashkey.h:24
Pulls together all the internal only header files.