• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 void
coap_hash_impl(const unsigned char * s,size_t len,coap_key_t h)14 coap_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 
29