This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
/
sha384.h
79 lines (69 loc) · 2.37 KB
/
sha384.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2017 - This file is part of libecc project
*
* Authors:
* Ryad BENADJILA <ryadbenadjila@gmail.com>
* Arnaud EBALARD <arnaud.ebalard@ssi.gouv.fr>
* Jean-Pierre FLORI <jean-pierre.flori@ssi.gouv.fr>
*
* Contributors:
* Nicolas VIVET <nicolas.vivet@ssi.gouv.fr>
* Karim KHALFALLAH <karim.khalfallah@ssi.gouv.fr>
*
* This software is licensed under a dual BSD and GPL v2 license.
* See LICENSE file at the root folder of the project.
*/
#include "../lib_ecc_config.h"
#ifdef WITH_HASH_SHA384
#ifndef __SHA384_H__
#define __SHA384_H__
#include "../words/words.h"
#include "../utils/utils.h"
#include "sha2.h"
#define SHA384_STATE_SIZE 8
#define SHA384_BLOCK_SIZE 128
#define SHA384_DIGEST_SIZE 48
#define SHA384_DIGEST_SIZE_BITS 384
/* Compute max hash digest and block sizes */
#ifndef MAX_DIGEST_SIZE
#define MAX_DIGEST_SIZE 0
#endif
#if (MAX_DIGEST_SIZE < SHA384_DIGEST_SIZE)
#undef MAX_DIGEST_SIZE
#define MAX_DIGEST_SIZE SHA384_DIGEST_SIZE
#endif
#ifndef MAX_DIGEST_SIZE_BITS
#define MAX_DIGEST_SIZE_BITS 0
#endif
#if (MAX_DIGEST_SIZE_BITS < SHA384_DIGEST_SIZE_BITS)
#undef MAX_DIGEST_SIZE_BITS
#define MAX_DIGEST_SIZE_BITS SHA384_DIGEST_SIZE_BITS
#endif
#ifndef MAX_BLOCK_SIZE
#define MAX_BLOCK_SIZE 0
#endif
#if (MAX_BLOCK_SIZE < SHA384_BLOCK_SIZE)
#undef MAX_BLOCK_SIZE
#define MAX_BLOCK_SIZE SHA384_BLOCK_SIZE
#endif
#define SHA384_HASH_MAGIC ((word_t)(0x9227239b32098412ULL))
#define SHA384_HASH_CHECK_INITIALIZED(A, ret, err) \
MUST_HAVE((((void *)(A)) != NULL) && ((A)->magic == SHA384_HASH_MAGIC), ret, err)
typedef struct {
/* Number of bytes processed on 128 bits */
u64 sha384_total[2];
/* Internal state */
u64 sha384_state[SHA384_STATE_SIZE];
/* Internal buffer to handle updates in a block */
u8 sha384_buffer[SHA384_BLOCK_SIZE];
/* Initialization magic value */
word_t magic;
} sha384_context;
ATTRIBUTE_WARN_UNUSED_RET int sha384_init(sha384_context *ctx);
ATTRIBUTE_WARN_UNUSED_RET int sha384_update(sha384_context *ctx, const u8 *input, u32 ilen);
ATTRIBUTE_WARN_UNUSED_RET int sha384_final(sha384_context *ctx, u8 output[SHA384_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int sha384_scattered(const u8 **inputs, const u32 *ilens,
u8 output[SHA384_DIGEST_SIZE]);
ATTRIBUTE_WARN_UNUSED_RET int sha384(const u8 *input, u32 ilen, u8 output[SHA384_DIGEST_SIZE]);
#endif /* __SHA384_H__ */
#endif /* WITH_HASH_SHA384 */