1c87c5fbaSopenharmony_ci/*
2c87c5fbaSopenharmony_ci * coap_hashkey.h -- definition of hash key type and helper functions
3c87c5fbaSopenharmony_ci *
4c87c5fbaSopenharmony_ci * Copyright (C) 2010-2011 Olaf Bergmann <bergmann@tzi.org>
5c87c5fbaSopenharmony_ci *
6c87c5fbaSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause
7c87c5fbaSopenharmony_ci *
8c87c5fbaSopenharmony_ci * This file is part of the CoAP library libcoap. Please see README for terms
9c87c5fbaSopenharmony_ci * of use.
10c87c5fbaSopenharmony_ci */
11c87c5fbaSopenharmony_ci
12c87c5fbaSopenharmony_ci/**
13c87c5fbaSopenharmony_ci * @file coap_hashkey_internal.h
14c87c5fbaSopenharmony_ci * @brief Definition of hash key type and helper functions
15c87c5fbaSopenharmony_ci */
16c87c5fbaSopenharmony_ci
17c87c5fbaSopenharmony_ci#ifndef COAP_HASHKEY_INTERNAL_H_
18c87c5fbaSopenharmony_ci#define COAP_HASHKEY_INTERNAL_H_
19c87c5fbaSopenharmony_ci
20c87c5fbaSopenharmony_ci#include "libcoap.h"
21c87c5fbaSopenharmony_ci#include "coap_uthash_internal.h"
22c87c5fbaSopenharmony_ci#include "coap_str.h"
23c87c5fbaSopenharmony_ci
24c87c5fbaSopenharmony_citypedef unsigned char coap_key_t[4];
25c87c5fbaSopenharmony_ci
26c87c5fbaSopenharmony_ci#ifndef coap_hash
27c87c5fbaSopenharmony_ci/**
28c87c5fbaSopenharmony_ci * Calculates a fast hash over the given string @p s of length @p len and stores
29c87c5fbaSopenharmony_ci * the result into @p h. Depending on the exact implementation, this function
30c87c5fbaSopenharmony_ci * cannot be used as one-way function to check message integrity or simlar.
31c87c5fbaSopenharmony_ci *
32c87c5fbaSopenharmony_ci * @param s   The string used for hash calculation.
33c87c5fbaSopenharmony_ci * @param len The length of @p s.
34c87c5fbaSopenharmony_ci * @param h   The result buffer to store the calculated hash key.
35c87c5fbaSopenharmony_ci */
36c87c5fbaSopenharmony_civoid coap_hash_impl(const unsigned char *s, size_t len, coap_key_t h);
37c87c5fbaSopenharmony_ci
38c87c5fbaSopenharmony_ci#define coap_hash(String,Length,Result) \
39c87c5fbaSopenharmony_ci  coap_hash_impl((String),(Length),(Result))
40c87c5fbaSopenharmony_ci
41c87c5fbaSopenharmony_ci/* This is used to control the pre-set hash-keys for resources. */
42c87c5fbaSopenharmony_ci#define COAP_DEFAULT_HASH
43c87c5fbaSopenharmony_ci#else
44c87c5fbaSopenharmony_ci#undef COAP_DEFAULT_HASH
45c87c5fbaSopenharmony_ci#endif /* coap_hash */
46c87c5fbaSopenharmony_ci
47c87c5fbaSopenharmony_ci/**
48c87c5fbaSopenharmony_ci * Calls coap_hash() with given @c coap_string_t object as parameter.
49c87c5fbaSopenharmony_ci *
50c87c5fbaSopenharmony_ci * @param Str Must contain a pointer to a coap string object.
51c87c5fbaSopenharmony_ci * @param H   A coap_key_t object to store the result.
52c87c5fbaSopenharmony_ci *
53c87c5fbaSopenharmony_ci * @hideinitializer
54c87c5fbaSopenharmony_ci */
55c87c5fbaSopenharmony_ci#define coap_str_hash(Str,H) {               \
56c87c5fbaSopenharmony_ci    assert(Str);                             \
57c87c5fbaSopenharmony_ci    memset((H), 0, sizeof(coap_key_t));      \
58c87c5fbaSopenharmony_ci    coap_hash((Str)->s, (Str)->length, (H)); \
59c87c5fbaSopenharmony_ci  }
60c87c5fbaSopenharmony_ci
61c87c5fbaSopenharmony_ci#endif /* COAP_HASHKEY_INTERNAL_H_ */
62