1 /** 2 * \file sha1.h 3 * 4 * \brief SHA-1 cryptographic hash function 5 * 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved 7 * 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. 20 * 21 * This file is part of mbed TLS (https://tls.mbed.org) 22 */ 23 #ifndef MBEDTLS_SHA1_H 24 #define MBEDTLS_SHA1_H 25 26 #if !defined(MBEDTLS_CONFIG_FILE) 27 #include "config.h" 28 #else 29 #include MBEDTLS_CONFIG_FILE 30 #endif 31 32 #include <stddef.h> 33 #include <stdint.h> 34 35 #if !defined(MBEDTLS_SHA1_ALT) 36 // Regular implementation 37 // 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** 44 * \brief SHA-1 context structure 45 */ 46 typedef struct 47 { 48 uint32_t total[2]; /*!< number of bytes processed */ 49 uint32_t state[5]; /*!< intermediate digest state */ 50 unsigned char buffer[64]; /*!< data block being processed */ 51 } 52 mbedtls_sha1_context; 53 54 /** 55 * \brief Initialize SHA-1 context 56 * 57 * \param ctx SHA-1 context to be initialized 58 */ 59 void mbedtls_sha1_init( mbedtls_sha1_context *ctx ); 60 61 /** 62 * \brief Clear SHA-1 context 63 * 64 * \param ctx SHA-1 context to be cleared 65 */ 66 void mbedtls_sha1_free( mbedtls_sha1_context *ctx ); 67 68 /** 69 * \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 */ 74 void mbedtls_sha1_clone( mbedtls_sha1_context *dst, 75 const mbedtls_sha1_context *src ); 76 77 /** 78 * \brief SHA-1 context setup 79 * 80 * \param ctx context to be initialized 81 */ 82 void mbedtls_sha1_starts( mbedtls_sha1_context *ctx ); 83 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 */ 91 void mbedtls_sha1_update( mbedtls_sha1_context *ctx, const unsigned char *input, size_t ilen ); 92 93 /** 94 * \brief SHA-1 final digest 95 * 96 * \param ctx SHA-1 context 97 * \param output SHA-1 checksum result 98 */ 99 void mbedtls_sha1_finish( mbedtls_sha1_context *ctx, unsigned char output[20] ); 100 101 /* Internal use */ 102 void mbedtls_sha1_process( mbedtls_sha1_context *ctx, const unsigned char data[64] ); 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #else /* MBEDTLS_SHA1_ALT */ 109 #include "sha1_alt.h" 110 #endif /* MBEDTLS_SHA1_ALT */ 111 112 #ifdef __cplusplus 113 extern "C" { 114 #endif 115 116 /** 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 */ 123 void mbedtls_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] ); 124 125 /** 126 * \brief Checkup routine 127 * 128 * \return 0 if successful, or 1 if the test failed 129 */ 130 int mbedtls_sha1_self_test( int verbose ); 131 132 #ifdef __cplusplus 133 } 134 #endif 135 136 #endif /* mbedtls_sha1.h */ 137