1 /**
2  * \file sha512.h
3  *
4  * \brief SHA-384 and SHA-512 cryptographic hash function
5  *
6  *  Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
7  *  SPDX-License-Identifier: Apache-2.0
8  *
9  *  Licensed under the Apache License, Version 2.0 (the "License"); you may
10  *  not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  *
13  *  http://www.apache.org/licenses/LICENSE-2.0
14  *
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17  *  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  *
21  *  This file is part of mbed TLS (https://tls.mbed.org)
22  */
23 #ifndef MBEDTLS_SHA512_H
24 #define MBEDTLS_SHA512_H
25 
26 #if !defined(MBEDTLS_CONFIG_FILE)
27 #include "config.h"
28 #else
29 #include MBEDTLS_CONFIG_FILE
30 #endif
31 
32 #include <stddef.h>
33 #include <stdint.h>
34 
35 #if !defined(MBEDTLS_SHA512_ALT)
36 // Regular implementation
37 //
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 /**
44  * \brief          SHA-512 context structure
45  */
46 typedef struct
47 {
48     uint64_t total[2];          /*!< number of bytes processed  */
49     uint64_t state[8];          /*!< intermediate digest state  */
50     unsigned char buffer[128];  /*!< data block being processed */
51     int is384;                  /*!< 0 => SHA-512, else SHA-384 */
52 }
53 mbedtls_sha512_context;
54 
55 /**
56  * \brief          Initialize SHA-512 context
57  *
58  * \param ctx      SHA-512 context to be initialized
59  */
60 void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
61 
62 /**
63  * \brief          Clear SHA-512 context
64  *
65  * \param ctx      SHA-512 context to be cleared
66  */
67 void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
68 
69 /**
70  * \brief          Clone (the state of) a SHA-512 context
71  *
72  * \param dst      The destination context
73  * \param src      The context to be cloned
74  */
75 void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
76                            const mbedtls_sha512_context *src );
77 
78 /**
79  * \brief          SHA-512 context setup
80  *
81  * \param ctx      context to be initialized
82  * \param is384    0 = use SHA512, 1 = use SHA384
83  */
84 void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
85 
86 /**
87  * \brief          SHA-512 process buffer
88  *
89  * \param ctx      SHA-512 context
90  * \param input    buffer holding the  data
91  * \param ilen     length of the input data
92  */
93 void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
94                     size_t ilen );
95 
96 /**
97  * \brief          SHA-512 final digest
98  *
99  * \param ctx      SHA-512 context
100  * \param output   SHA-384/512 checksum result
101  */
102 void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
103 
104 #ifdef __cplusplus
105 }
106 #endif
107 
108 #else  /* MBEDTLS_SHA512_ALT */
109 #include "sha512_alt.h"
110 #endif /* MBEDTLS_SHA512_ALT */
111 
112 #ifdef __cplusplus
113 extern "C" {
114 #endif
115 
116 /**
117  * \brief          Output = SHA-512( input buffer )
118  *
119  * \param input    buffer holding the  data
120  * \param ilen     length of the input data
121  * \param output   SHA-384/512 checksum result
122  * \param is384    0 = use SHA512, 1 = use SHA384
123  */
124 void mbedtls_sha512( const unsigned char *input, size_t ilen,
125              unsigned char output[64], int is384 );
126 
127 /**
128  * \brief          Checkup routine
129  *
130  * \return         0 if successful, or 1 if the test failed
131  */
132 int mbedtls_sha512_self_test( int verbose );
133 
134 /* Internal use */
135 void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* mbedtls_sha512.h */
142