RTEMS 6.1-rc1
hash.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2021 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_HASH_H
38#define _RTEMS_SCORE_HASH_H
39
41
42#include <sha256.h>
43#include <string.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
64#define HASH_CONTROL_STRING_SIZE 45
65
71typedef struct {
79
87static inline const char *_Hash_Get_string( const Hash_Control *hash )
88{
89 return &hash->chars[ 0 ];
90}
91
95typedef struct {
100
105
109 size_t index;
111
117static inline void _Hash_Initialize( Hash_Context *context )
118{
119 SHA256_Init( &context->Context );
120}
121
131static inline void _Hash_Add_data(
133 const void *begin,
134 size_t size
135)
136{
137 SHA256_Update( &context->Context, begin, size );
138}
139
147static inline void _Hash_Add_string(
149 const char *str
150)
151{
152 SHA256_Update( &context->Context, str, strlen( str ) );
153}
154
163
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* _RTEMS_SCORE_HASH_H */
This header file provides basic definitions used by the API and the implementation.
#define HASH_CONTROL_STRING_SIZE
This constant represents the size of a hash string.
Definition: hash.h:64
void _Hash_Finalize(Hash_Context *context, Hash_Control *hash)
Finalizes the hash value computation and produces the hash value.
Definition: hash.c:58
rtems_termios_device_context * context
Definition: console-config.c:62
This header file contains interfaces of the SHA256 hash algorithm support.
This type represents the context to compute a hash value.
Definition: hash.h:95
Hash_Control * hash
This member references a hash value if needed.
Definition: hash.h:104
SHA256_CTX Context
This member contains the hash algorithm context.
Definition: hash.h:99
size_t index
This member contains an index into the hash value bytes if needed.
Definition: hash.h:109
This type represents a hash value.
Definition: hash.h:71
char chars[HASH_CONTROL_STRING_SIZE]
This member contains the hash value encoded as a base64url string.
Definition: hash.h:77
Definition: sha256.h:40
unsigned size
Definition: tte.h:1