blob: 55112ddb2efa4400ad6918f662d3240619ee716e [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>
Paul Bakker23986e52011-04-24 08:57:21 +000034
Paul Bakker5121ce52009-01-03 21:22:43 +000035#if defined(_MSC_VER) || defined(__WATCOMC__)
Paul Bakker5c2364c2012-10-01 14:41:15 +000036 typedef unsigned __int64 uint64_t;
Paul Bakker5121ce52009-01-03 21:22:43 +000037#else
Paul Bakker5c2364c2012-10-01 14:41:15 +000038 #include <inttypes.h>
Paul Bakker5121ce52009-01-03 21:22:43 +000039#endif
40
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020041#define MBEDTLS_ERR_SHA512_FILE_IO_ERROR -0x007A /**< Read/write error in file. */
Paul Bakker5c2364c2012-10-01 14:41:15 +000042
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020043#if !defined(MBEDTLS_SHA512_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020044// Regular implementation
45//
46
Paul Bakker407a0da2013-06-27 14:29:21 +020047#ifdef __cplusplus
48extern "C" {
49#endif
50
Paul Bakker5121ce52009-01-03 21:22:43 +000051/**
52 * \brief SHA-512 context structure
53 */
54typedef struct
55{
Paul Bakker5c2364c2012-10-01 14:41:15 +000056 uint64_t total[2]; /*!< number of bytes processed */
57 uint64_t state[8]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000058 unsigned char buffer[128]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000059 int is384; /*!< 0 => SHA-512, else SHA-384 */
60}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061mbedtls_sha512_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000062
Paul Bakker5121ce52009-01-03 21:22:43 +000063/**
Paul Bakker5b4af392014-06-26 12:09:34 +020064 * \brief Initialize SHA-512 context
65 *
66 * \param ctx SHA-512 context to be initialized
67 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068void mbedtls_sha512_init( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
71 * \brief Clear SHA-512 context
72 *
73 * \param ctx SHA-512 context to be cleared
74 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075void mbedtls_sha512_free( mbedtls_sha512_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020076
77/**
Paul Bakker5121ce52009-01-03 21:22:43 +000078 * \brief SHA-512 context setup
79 *
80 * \param ctx context to be initialized
81 * \param is384 0 = use SHA512, 1 = use SHA384
82 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020083void mbedtls_sha512_starts( mbedtls_sha512_context *ctx, int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +000084
85/**
86 * \brief SHA-512 process buffer
87 *
88 * \param ctx SHA-512 context
89 * \param input buffer holding the data
90 * \param ilen length of the input data
91 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020092void mbedtls_sha512_update( mbedtls_sha512_context *ctx, const unsigned char *input,
Paul Bakkerb9e4e2c2014-05-01 14:18:25 +020093 size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000094
95/**
96 * \brief SHA-512 final digest
97 *
98 * \param ctx SHA-512 context
99 * \param output SHA-384/512 checksum result
100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200101void mbedtls_sha512_finish( mbedtls_sha512_context *ctx, unsigned char output[64] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000102
Paul Bakker90995b52013-06-24 19:20:35 +0200103#ifdef __cplusplus
104}
105#endif
106
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200107#else /* MBEDTLS_SHA512_ALT */
Paul Bakkerd2681d82013-06-30 14:49:12 +0200108#include "sha512_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200109#endif /* MBEDTLS_SHA512_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200110
111#ifdef __cplusplus
112extern "C" {
113#endif
114
Paul Bakker5121ce52009-01-03 21:22:43 +0000115/**
116 * \brief Output = SHA-512( input buffer )
117 *
118 * \param input buffer holding the data
119 * \param ilen length of the input data
120 * \param output SHA-384/512 checksum result
121 * \param is384 0 = use SHA512, 1 = use SHA384
122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123void mbedtls_sha512( const unsigned char *input, size_t ilen,
Paul Bakker9e36f042013-06-30 14:34:05 +0200124 unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000125
126/**
127 * \brief Output = SHA-512( file contents )
128 *
129 * \param path input file name
130 * \param output SHA-384/512 checksum result
131 * \param is384 0 = use SHA512, 1 = use SHA384
132 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133 * \return 0 if successful, or MBEDTLS_ERR_SHA512_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135int mbedtls_sha512_file( const char *path, unsigned char output[64], int is384 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
137/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 * \brief Checkup routine
139 *
140 * \return 0 if successful, or 1 if the test failed
141 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200142int mbedtls_sha512_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000143
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100144/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200145void mbedtls_sha512_process( mbedtls_sha512_context *ctx, const unsigned char data[128] );
Paul Bakker1bd3ae82013-03-13 10:26:44 +0100146
Paul Bakker5121ce52009-01-03 21:22:43 +0000147#ifdef __cplusplus
148}
149#endif
150
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200151#endif /* mbedtls_sha512.h */