blob: 448c272b7ae887c53292cfa28ac5972ed9815899 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02002 * \file mbedtls_sha1.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Paul Bakker37ca75d2011-01-06 12:28:03 +00004 * \brief SHA-1 cryptographic hash function
5 *
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_SHA1_H
25#define MBEDTLS_SHA1_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 Bakkerfa6a6202013-10-28 18:48:30 +010035#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
Paul Bakker5c2364c2012-10-01 14:41:15 +000036#include <basetsd.h>
37typedef UINT32 uint32_t;
38#else
39#include <inttypes.h>
40#endif
41
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042#define MBEDTLS_ERR_SHA1_FILE_IO_ERROR -0x0076 /**< Read/write error in file. */
Paul Bakker69e095c2011-12-10 21:55:01 +000043
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#if !defined(MBEDTLS_SHA1_ALT)
Paul Bakker90995b52013-06-24 19:20:35 +020045// Regular implementation
46//
47
Paul Bakker407a0da2013-06-27 14:29:21 +020048#ifdef __cplusplus
49extern "C" {
50#endif
51
Paul Bakker5121ce52009-01-03 21:22:43 +000052/**
53 * \brief SHA-1 context structure
54 */
55typedef struct
56{
Paul Bakker5c2364c2012-10-01 14:41:15 +000057 uint32_t total[2]; /*!< number of bytes processed */
58 uint32_t state[5]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000059 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000060}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061mbedtls_sha1_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-1 context
65 *
66 * \param ctx SHA-1 context to be initialized
67 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020068void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020069
70/**
71 * \brief Clear SHA-1 context
72 *
73 * \param ctx SHA-1 context to be cleared
74 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020076
77/**
Paul Bakker5121ce52009-01-03 21:22:43 +000078 * \brief SHA-1 context setup
79 *
80 * \param ctx context to be initialized
81 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020082void mbedtls_sha1_starts( mbedtls_sha1_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +000083
84/**
85 * \brief SHA-1 process buffer
86 *
87 * \param ctx SHA-1 context
88 * \param input buffer holding the data
89 * \param ilen length of the input data
90 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020091void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen );
Paul Bakker5121ce52009-01-03 21:22:43 +000092
93/**
94 * \brief SHA-1 final digest
95 *
96 * \param ctx SHA-1 context
97 * \param output SHA-1 checksum result
98 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000100
Paul Bakker90995b52013-06-24 19:20:35 +0200101/* Internal use */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] );
Paul Bakker90995b52013-06-24 19:20:35 +0200103
104#ifdef __cplusplus
105}
106#endif
107
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200108#else /* MBEDTLS_SHA1_ALT */
Paul Bakker90995b52013-06-24 19:20:35 +0200109#include "sha1_alt.h"
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200110#endif /* MBEDTLS_SHA1_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-1( input buffer )
118 *
119 * \param input buffer holding the data
120 * \param ilen length of the input data
121 * \param output SHA-1 checksum result
122 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200123void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000124
125/**
126 * \brief Output = SHA-1( file contents )
127 *
128 * \param path input file name
129 * \param output SHA-1 checksum result
130 *
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131 * \return 0 if successful, or MBEDTLS_ERR_SHA1_FILE_IO_ERROR
Paul Bakker5121ce52009-01-03 21:22:43 +0000132 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200133int mbedtls_sha1_file( const char *path, unsigned char output[20] );
Paul Bakker5121ce52009-01-03 21:22:43 +0000134
135/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000136 * \brief Checkup routine
137 *
138 * \return 0 if successful, or 1 if the test failed
139 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200140int mbedtls_sha1_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000141
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_sha1.h */