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 /** 12 * @file coap_hashkey.c 13 * @brief Hashkey functions 14 */ 15 16 #include "coap3/coap_internal.h" 17 18 void coap_hash_impl(const unsigned char * s,size_t len,coap_key_t h)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 } 33