blob: 6c61cc36e3c38b5b9042d40bfc551fa6d7bfeec9 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002 * \file mbedtls_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é-Gonnarda658a402015-01-23 09:45:19 +00006 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00007 *
Manuel Pégourié-Gonnardfe446432015-03-06 13:17:10 +00008 * This file is part of mbed TLS (https://tls.mbed.org)
Paul Bakkerb96f1542010-07-18 20:36:00 +00009 *
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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#define MBEDTLS_ERR_SHA512_FILE_IO_ERROR -0x007A /**< Read/write error in file. */
Paul Bakker5c2364c2012-10-01 14:41:15 +000037
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020038#if !defined(MBEDTLS_SHA512_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020039// Regular implementation
40//
41
Paul Bakker407a0da2013-06-27 14:29:21 +020042#ifdef __cplusplus
43extern "C" {
44#endif
45
Paul Bakker5121ce52009-01-03 21:22:43 +000046/**
47 * \brief SHA-512 context structure
48 */
49typedef struct
50{
Paul Bakker5c2364c2012-10-01 14:41:15 +000051 uint64_t total[2]; /*!< number of bytes processed */
52 uint64_t state[8]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000053 unsigned char buffer[128]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000054 int is384; /*!< 0 => SHA-512, else SHA-384 */
55}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020056mbedtls_sha512_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000057
Paul Bakker5121ce52009-01-03 21:22:43 +000058/**
Paul Bakker5b4af392014-06-26 12:09:34 +020059 * \brief Initialize SHA-512 context
60 *
61 * \param ctx SHA-512 context to be initialized
62 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020063void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020064
65/**
66 * \brief Clear SHA-512 context
67 *
68 * \param ctx SHA-512 context to be cleared
69 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020070void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020071
72/**
Paul Bakker5121ce52009-01-03 21:22:43 +000073 * \brief SHA-512 context setup
74 *
75 * \param ctx context to be initialized
76 * \param is384 0 = use SHA512, 1 = use SHA384
77 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +000079
80/**
81 * \brief SHA-512 process buffer
82 *
83 * \param ctx SHA-512 context
84 * \param input buffer holding the data
85 * \param ilen length of the input data
86 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020087void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020088 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000089
90/**
91 * \brief SHA-512 final digest
92 *
93 * \param ctx SHA-512 context
94 * \param output SHA-384/512 checksum result
95 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
Paul Bakker5121ce52009-01-03 21:22:43 +000097
Paul Bakker90995b52013-06-24 19:20:35 +020098#ifdef __cplusplus
99}
100#endif
101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102#else /* MBEDTLS_SHA512_ALT */
Paul Bakkerd2681d82013-06-30 14:49:12 +0200103#include "sha512_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200104#endif /* MBEDTLS_SHA512_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200105
106#ifdef __cplusplus
107extern "C" {
108#endif
109
Paul Bakker5121ce52009-01-03 21:22:43 +0000110/**
111 * \brief Output = SHA-512( input buffer )
112 *
113 * \param input buffer holding the data
114 * \param ilen length of the input data
115 * \param output SHA-384/512 checksum result
116 * \param is384 0 = use SHA512, 1 = use SHA384
117 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200118void mbedtls_sha512( const unsigned char *input, size_t ilen,
Paul Bakker9e36f042013-06-30 14:34:05 +0200119 unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000120
121/**
122 * \brief Output = SHA-512( file contents )
123 *
124 * \param path input file name
125 * \param output SHA-384/512 checksum result
126 * \param is384 0 = use SHA512, 1 = use SHA384
127 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128 * \return 0 if successful, or MBEDTLS_ERR_SHA512_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000129 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130int mbedtls_sha512_file( const char *path, unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000131
132/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 * \brief Checkup routine
134 *
135 * \return 0 if successful, or 1 if the test failed
136 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200137int mbedtls_sha512_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000138
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100139/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100141
Paul Bakker5121ce52009-01-03 21:22:43 +0000142#ifdef __cplusplus
143}
144#endif
145
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200146#endif /* mbedtls_sha512.h */