Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/libecc/src/examples/hash/hash.h
2066 views
1
/*
2
* Copyright (C) 2021 - This file is part of libecc project
3
*
4
* Authors:
5
* Ryad BENADJILA <[email protected]>
6
* Arnaud EBALARD <[email protected]>
7
*
8
* This software is licensed under a dual BSD and GPL v2 license.
9
* See LICENSE file at the root folder of the project.
10
*/
11
#ifndef __HASH_HASH_H__
12
#define __HASH_HASH_H__
13
14
15
/*
16
* NOTE: we include libsig for the libecc
17
* hash algorithms.
18
*/
19
#include <libecc/libec.h>
20
21
/* MD-2 */
22
#include "md2.h"
23
/* MD-4 */
24
#include "md4.h"
25
/* MD-5 */
26
#include "md5.h"
27
/* SHA-0 */
28
#include "sha0.h"
29
/* SHA-1 */
30
#include "sha1.h"
31
/* MDC-2 */
32
#include "mdc2.h"
33
/* GOSTR34-11-94 source code */
34
#include "gostr34_11_94.h"
35
36
/****************************************************/
37
/****************************************************/
38
/****************************************************/
39
typedef enum {
40
/* libecc native hashes: we map our enum on them */
41
HASH_UNKNOWN_HASH_ALG = UNKNOWN_HASH_ALG,
42
HASH_SHA224 = SHA224,
43
HASH_SHA256 = SHA256,
44
HASH_SHA384 = SHA384,
45
HASH_SHA512 = SHA512,
46
HASH_SHA512_224 = SHA512_224,
47
HASH_SHA512_256 = SHA512_256,
48
HASH_SHA3_224 = SHA3_224,
49
HASH_SHA3_256 = SHA3_256,
50
HASH_SHA3_384 = SHA3_384,
51
HASH_SHA3_512 = SHA3_512,
52
HASH_SM3 = SM3,
53
HASH_STREEBOG256 = STREEBOG256,
54
HASH_STREEBOG512 = STREEBOG512,
55
HASH_SHAKE256 = SHAKE256,
56
HASH_RIPEMD160 = RIPEMD160,
57
HASH_BELT_HASH = BELT_HASH,
58
HASH_BASH224 = BASH224,
59
HASH_BASH256 = BASH256,
60
HASH_BASH384 = BASH384,
61
HASH_BASH512 = BASH512,
62
/* Deprecated hash algorithms not supported by libecc
63
* (for security reasons).
64
* XXX: NOTE: These algorithms are here as a playground e.g.
65
* to test some backward compatibility of cryptographic cipher suites,
66
* please DO NOT use them in production code!
67
*/
68
HASH_MD2,
69
HASH_MD4,
70
HASH_MD5,
71
HASH_SHA0,
72
HASH_SHA1,
73
HASH_MDC2_PADDING1,
74
HASH_MDC2_PADDING2,
75
HASH_GOST34_11_94_NORM,
76
HASH_GOST34_11_94_RFC4357,
77
} gen_hash_alg_type;
78
79
/* Our generic hash context */
80
typedef union {
81
/* libecc native hashes */
82
hash_context hctx;
83
/* MD2 */
84
md2_context md2ctx;
85
/* MD4 */
86
md4_context md4ctx;
87
/* MD5 */
88
md5_context md5ctx;
89
/* SHA-0 */
90
sha0_context sha0ctx;
91
/* SHA-1 */
92
sha1_context sha1ctx;
93
/* MDC2 */
94
mdc2_context mdc2ctx;
95
/* GOSTR34-11-94 */
96
gostr34_11_94_context gostr34_11_94ctx;
97
} gen_hash_context;
98
99
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_get_hash_sizes(gen_hash_alg_type gen_hash_type, u8 *hlen, u8 *block_size);
100
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_init(gen_hash_context *ctx, gen_hash_alg_type gen_hash_type);
101
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_update(gen_hash_context *ctx, const u8 *chunk, u32 chunklen, gen_hash_alg_type gen_hash_type);
102
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_final(gen_hash_context *ctx, u8 *output, gen_hash_alg_type gen_hash_type);
103
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_hfunc(const u8 *input, u32 ilen, u8 *digest, gen_hash_alg_type gen_hash_type);
104
ATTRIBUTE_WARN_UNUSED_RET int gen_hash_hfunc_scattered(const u8 **input, const u32 *ilen, u8 *digest, gen_hash_alg_type gen_hash_type);
105
106
#endif /* __HASH_HASH_H__ */
107
108