libcoap 4.3.4
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
16#include "coap3/coap_internal.h"
17
18void
19coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h) {
20 size_t j;
21
22 while (len--) {
23 j = sizeof(coap_key_t)-1;
24
25 while (j) {
26 h[j] = ((h[j] << 7) | (h[j-1] >> 1)) + h[j];
27 --j;
28 }
29
30 h[0] = (h[0] << 7) + h[0] + *s++;
31 }
32}
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:19
unsigned char coap_key_t[4]
Pulls together all the internal only header files.