xref: /freebsd/crypto/libecc/include/libecc/hash/sha512.h (revision f0865ec9906d5a18fa2a3b61381f22ce16e606ad)
1 /*
2  *  Copyright (C) 2017 - This file is part of libecc project
3  *
4  *  Authors:
5  *      Ryad BENADJILA <ryadbenadjila@gmail.com>
6  *      Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
7  *      Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
8  *
9  *  Contributors:
10  *      Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
11  *      Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
12  *
13  *  This software is licensed under a dual BSD and GPL v2 license.
14  *  See LICENSE file at the root folder of the project.
15  */
16 #include <libecc/lib_ecc_config.h>
17 #ifdef WITH_HASH_SHA512
18 
19 #ifndef __SHA512_H__
20 #define __SHA512_H__
21 
22 #include <libecc/words/words.h>
23 #include <libecc/utils/utils.h>
24 #include <libecc/hash/sha2.h>
25 #include <libecc/hash/sha512_core.h>
26 
27 #define SHA512_STATE_SIZE   SHA512_CORE_STATE_SIZE
28 #define SHA512_BLOCK_SIZE   SHA512_CORE_BLOCK_SIZE
29 #define SHA512_DIGEST_SIZE  SHA512_CORE_DIGEST_SIZE
30 #define SHA512_DIGEST_SIZE_BITS  512
31 
32 /* Compute max hash digest and block sizes */
33 #ifndef MAX_DIGEST_SIZE
34 #define MAX_DIGEST_SIZE 0
35 #endif
36 #if (MAX_DIGEST_SIZE < SHA512_DIGEST_SIZE)
37 #undef MAX_DIGEST_SIZE
38 #define MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
39 #endif
40 
41 #ifndef MAX_DIGEST_SIZE_BITS
42 #define MAX_DIGEST_SIZE_BITS    0
43 #endif
44 #if (MAX_DIGEST_SIZE_BITS < SHA512_DIGEST_SIZE_BITS)
45 #undef MAX_DIGEST_SIZE_BITS
46 #define MAX_DIGEST_SIZE_BITS SHA512_DIGEST_SIZE_BITS
47 #endif
48 
49 #ifndef MAX_BLOCK_SIZE
50 #define MAX_BLOCK_SIZE	0
51 #endif
52 #if (MAX_BLOCK_SIZE < SHA512_BLOCK_SIZE)
53 #undef MAX_BLOCK_SIZE
54 #define MAX_BLOCK_SIZE SHA512_BLOCK_SIZE
55 #endif
56 
57 #define SHA512_HASH_MAGIC ((word_t)(0x5539012b32097312ULL))
58 #define SHA512_HASH_CHECK_INITIALIZED(A, ret, err) \
59 	MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == SHA512_HASH_MAGIC), ret, err)
60 
61 typedef sha512_core_context sha512_context;
62 
63 ATTRIBUTE_WARN_UNUSED_RET int sha512_init(sha512_context *ctx);
64 ATTRIBUTE_WARN_UNUSED_RET int sha512_update(sha512_context *ctx, const u8 *input, u32 ilen);
65 ATTRIBUTE_WARN_UNUSED_RET int sha512_final(sha512_context *ctx, u8 output[SHA512_DIGEST_SIZE]);
66 ATTRIBUTE_WARN_UNUSED_RET int sha512_scattered(const u8 **inputs, const u32 *ilens,
67 		     u8 output[SHA512_DIGEST_SIZE]);
68 ATTRIBUTE_WARN_UNUSED_RET int sha512(const u8 *input, u32 ilen, u8 output[SHA512_DIGEST_SIZE]);
69 
70 #endif /* __SHA512_H__ */
71 #endif /* WITH_HASH_SHA512 */
72