blob: 2b74d06d0821b7fae54a07fb7102296b87997be6 [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é-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_SHA1_H
24#define MBEDTLS_SHA1_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 Bakker5c2364c2012-10-01 14:41:15 +000034
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035#if !defined(MBEDTLS_SHA1_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-1 context structure
45 */
46typedef struct
47{
Paul Bakker5c2364c2012-10-01 14:41:15 +000048 uint32_t total[2]; /*!< number of bytes processed */
49 uint32_t state[5]; /*!< intermediate digest state */
Paul Bakker5121ce52009-01-03 21:22:43 +000050 unsigned char buffer[64]; /*!< data block being processed */
Paul Bakker5121ce52009-01-03 21:22:43 +000051}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020052mbedtls_sha1_context;
Paul Bakker5121ce52009-01-03 21:22:43 +000053
Paul Bakker5121ce52009-01-03 21:22:43 +000054/**
Paul Bakker5b4af392014-06-26 12:09:34 +020055 * \brief Initialize SHA-1 context
56 *
57 * \param ctx SHA-1 context to be initialized
58 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020059void mbedtls_sha1_init( mbedtls_sha1_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020060
61/**
62 * \brief Clear SHA-1 context
63 *
64 * \param ctx SHA-1 context to be cleared
65 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020066void mbedtls_sha1_free( mbedtls_sha1_context *ctx );
Paul Bakker5b4af392014-06-26 12:09:34 +020067
68/**
Manuel Pégourié-Gonnard16d412f2015-07-06 15:26:26 +020069 * \brief Clone (the state of) a SHA-1 context
70 *
71 * \param dst The destination context
72 * \param src The context to be cloned
73 */
74void mbedtls_sha1_clone( mbedtls_sha1_context *dst,
75 const mbedtls_sha1_context *src );
76
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/**
Paul Bakker5121ce52009-01-03 21:22:43 +0000126 * \brief Checkup routine
127 *
128 * \return 0 if successful, or 1 if the test failed
129 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130int mbedtls_sha1_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +0000131
Paul Bakker5121ce52009-01-03 21:22:43 +0000132#ifdef __cplusplus
133}
134#endif
135
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200136#endif /* mbedtls_sha1.h */