blob: 542dc990bf8ab62ece3107e220cceeebd22ce771 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butcher5b331b92016-01-03 16:14:14 +00002 * \file sha512.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakkerf3b86c12011-01-27 15:24:17 +00004 * \brief SHA-384 and SHA-512 cryptographic hash function
Darryl Greena40a1012018-01-05 15:33:17 +00005 */
6/*
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02007 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02008 * SPDX-License-Identifier: Apache-2.0
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); you may
11 * not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000021 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000022 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000023 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020024#ifndef MBEDTLS_SHA512_H
25#define MBEDTLS_SHA512_H
Paul Bakker5121ce52009-01-03 21:22:43 +000026
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020027#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020028#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020029#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020031#endif
Paul Bakker90995b52013-06-24 19:20:35 +020032
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020034#include <stdint.h>
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#if !defined(MBEDTLS_SHA512_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020037// Regular implementation
38//
39
Paul Bakker407a0da2013-06-27 14:29:21 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Paul Bakker5121ce52009-01-03 21:22:43 +000044/**
45 * \brief SHA-512 context structure
46 */
47typedef struct
48{
Paul Bakker5c2364c2012-10-01 14:41:15 +000049 uint64_t total[2]; /*!< number of bytes processed */
50 uint64_t state[8]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000051 unsigned char buffer[128]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000052 int is384; /*!< 0 => SHA-512, else SHA-384 */
53}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020054mbedtls_sha512_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000055
Paul Bakker5121ce52009-01-03 21:22:43 +000056/**
Paul Bakker5b4af392014-06-26 12:09:34 +020057 * \brief Initialize SHA-512 context
58 *
59 * \param ctx SHA-512 context to be initialized
60 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020062
63/**
64 * \brief Clear SHA-512 context
65 *
66 * \param ctx SHA-512 context to be cleared
67 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020071 * \brief Clone (the state of) a SHA-512 context
72 *
73 * \param dst The destination context
74 * \param src The context to be cloned
75 */
76void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
77 const mbedtls_sha512_context *src );
78
79/**
Paul Bakker5121ce52009-01-03 21:22:43 +000080 * \brief SHA-512 context setup
81 *
82 * \param ctx context to be initialized
83 * \param is384 0 = use SHA512, 1 = use SHA384
84 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020085void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +000086
87/**
88 * \brief SHA-512 process buffer
89 *
90 * \param ctx SHA-512 context
91 * \param input buffer holding the data
92 * \param ilen length of the input data
93 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020094void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020095 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000096
97/**
98 * \brief SHA-512 final digest
99 *
100 * \param ctx SHA-512 context
101 * \param output SHA-384/512 checksum result
102 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200103void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
Paul Bakker90995b52013-06-24 19:20:35 +0200105#ifdef __cplusplus
106}
107#endif
108
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#else /* MBEDTLS_SHA512_ALT */
Paul Bakkerd2681d82013-06-30 14:49:12 +0200110#include "sha512_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111#endif /* MBEDTLS_SHA512_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200112
113#ifdef __cplusplus
114extern "C" {
115#endif
116
Paul Bakker5121ce52009-01-03 21:22:43 +0000117/**
118 * \brief Output = SHA-512( input buffer )
119 *
120 * \param input buffer holding the data
121 * \param ilen length of the input data
122 * \param output SHA-384/512 checksum result
123 * \param is384 0 = use SHA512, 1 = use SHA384
124 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200125void mbedtls_sha512( const unsigned char *input, size_t ilen,
Paul Bakker9e36f042013-06-30 14:34:05 +0200126 unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000127
128/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 * \brief Checkup routine
130 *
131 * \return 0 if successful, or 1 if the test failed
132 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133int mbedtls_sha512_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000134
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100135/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100137
Paul Bakker5121ce52009-01-03 21:22:43 +0000138#ifdef __cplusplus
139}
140#endif
141
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142#endif /* mbedtls_sha512.h */