sha512.h
Go to the documentation of this file.
1 /**
2  * @file sha512.h
3  * @brief SHA-512 (Secure Hash Algorithm 512)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _SHA512_H
32 #define _SHA512_H
33 
34 //Dependencies
35 #include "core/crypto.h"
36 
37 //Application specific context
38 #ifndef SHA512_PRIVATE_CONTEXT
39  #define SHA512_PRIVATE_CONTEXT
40 #endif
41 
42 //SHA-512 block size
43 #define SHA512_BLOCK_SIZE 128
44 //SHA-512 digest size
45 #define SHA512_DIGEST_SIZE 64
46 //Minimum length of the padding string
47 #define SHA512_MIN_PAD_SIZE 17
48 //Common interface for hash algorithms
49 #define SHA512_HASH_ALGO (&sha512HashAlgo)
50 
51 //C++ guard
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 
57 /**
58  * @brief SHA-512 algorithm context
59  **/
60 
61 typedef struct
62 {
63  union
64  {
65  uint64_t h[8];
66  uint8_t digest[64];
67  };
68  union
69  {
70  uint64_t w[16];
71  uint8_t buffer[128];
72  };
73  size_t size;
74  uint64_t totalSize;
77 
78 
79 //SHA-512 related constants
80 extern const uint8_t SHA512_OID[9];
81 extern const HashAlgo sha512HashAlgo;
82 
83 //SHA-512 related functions
84 error_t sha512Compute(const void *data, size_t length, uint8_t *digest);
85 void sha512Init(Sha512Context *context);
86 void sha512Update(Sha512Context *context, const void *data, size_t length);
87 void sha512Final(Sha512Context *context, uint8_t *digest);
88 void sha512ProcessBlock(Sha512Context *context);
89 
90 //C++ guard
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif
General definitions for cryptographic algorithms.
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
uint8_t h
Definition: ndp.h:302
void sha512ProcessBlock(Sha512Context *context)
Process message in 16-word blocks.
#define SHA512_PRIVATE_CONTEXT
Definition: sha512.h:39
error_t sha512Compute(const void *data, size_t length, uint8_t *digest)
Digest a message using SHA-512.
void sha512Init(Sha512Context *context)
Initialize SHA-512 message digest context.
void sha512Final(Sha512Context *context, uint8_t *digest)
Finish the SHA-512 message digest.
const HashAlgo sha512HashAlgo
Definition: sha512.c:100
void sha512Update(Sha512Context *context, const void *data, size_t length)
Update the SHA-512 context with a portion of the message being hashed.
const uint8_t SHA512_OID[9]
Definition: sha512.c:97
Common interface for hash algorithms.
Definition: crypto.h:1014
SHA-512 algorithm context.
Definition: sha512.h:62
uint64_t totalSize
Definition: sha512.h:74
size_t size
Definition: sha512.h:73
uint8_t length
Definition: tcp.h:368