blob: 627694f425f5b6782efcfac7175abbfe7a7f8dfa [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Simon Butchera02fe7c2016-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
Paul Bakker37ca75d2011-01-06 12:28:03 +00005 *
Manuel Pégourié-Gonnard6fb81872015-07-27 11:11:48 +02006 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02007 * 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.
Paul Bakkerb96f1542010-07-18 20:36:00 +000020 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +000021 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000022 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023#ifndef MBEDTLS_SHA512_H
24#define MBEDTLS_SHA512_H
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakker90995b52013-06-24 19:20:35 +020027#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020028#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020030#endif
Paul Bakker90995b52013-06-24 19:20:35 +020031
Rich Evans00ab4702015-02-06 13:43:58 +000032#include <stddef.h>
Manuel Pégourié-Gonnardab229102015-04-15 11:53:16 +020033#include <stdint.h>
Paul Bakker5121ce52009-01-03 21:22:43 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if !defined(MBEDTLS_SHA512_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020036// Regular implementation
37//
38
Paul Bakker407a0da2013-06-27 14:29:21 +020039#ifdef __cplusplus
40extern "C" {
41#endif
42
Paul Bakker5121ce52009-01-03 21:22:43 +000043/**
44 * \brief SHA-512 context structure
45 */
46typedef struct
47{
Paul Bakker5c2364c2012-10-01 14:41:15 +000048 uint64_t total[2]; /*!< number of bytes processed */
49 uint64_t state[8]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000050 unsigned char buffer[128]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000051 int is384; /*!< 0 => SHA-512, else SHA-384 */
52}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053mbedtls_sha512_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Paul Bakker5121ce52009-01-03 21:22:43 +000055/**
Paul Bakker5b4af392014-06-26 12:09:34 +020056 * \brief Initialize SHA-512 context
57 *
58 * \param ctx SHA-512 context to be initialized
59 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020060void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020061
62/**
63 * \brief Clear SHA-512 context
64 *
65 * \param ctx SHA-512 context to be cleared
66 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020067void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020068
69/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020070 * \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 */
75void mbedtls_sha512_clone( mbedtls_sha512_context *dst,
76 const mbedtls_sha512_context *src );
77
78/**
Paul Bakker5121ce52009-01-03 21:22:43 +000079 * \brief SHA-512 context setup
80 *
81 * \param ctx context to be initialized
82 * \param is384 0 = use SHA512, 1 = use SHA384
83 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +000085
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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020093void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020094 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000095
96/**
97 * \brief SHA-512 final digest
98 *
99 * \param ctx SHA-512 context
100 * \param output SHA-384/512 checksum result
101 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000103
Paul Bakker90995b52013-06-24 19:20:35 +0200104#ifdef __cplusplus
105}
106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#else /* MBEDTLS_SHA512_ALT */
Paul Bakkerd2681d82013-06-30 14:49:12 +0200109#include "sha512_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#endif /* MBEDTLS_SHA512_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200111
112#ifdef __cplusplus
113extern "C" {
114#endif
115
Paul Bakker5121ce52009-01-03 21:22:43 +0000116/**
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 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124void mbedtls_sha512( const unsigned char *input, size_t ilen,
Paul Bakker9e36f042013-06-30 14:34:05 +0200125 unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000126
127/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000128 * \brief Checkup routine
129 *
130 * \return 0 if successful, or 1 if the test failed
131 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200132int mbedtls_sha512_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000133
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100134/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100136
Paul Bakker5121ce52009-01-03 21:22:43 +0000137#ifdef __cplusplus
138}
139#endif
140
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200141#endif /* mbedtls_sha512.h */