]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - common/sha256.h
2 * \file mbedtls_sha256.h
4 * \brief SHA-224 and SHA-256 cryptographic hash function
6 * Copyright (C) 2006-2014, ARM Limited, All Rights Reserved
8 * This file is part of mbed TLS (https://tls.mbed.org)
10 * 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.
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.
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.
24 #ifndef MBEDTLS_SHA256_H
25 #define MBEDTLS_SHA256_H
27 #if !defined(MBEDTLS_CONFIG_FILE)
30 #include MBEDTLS_CONFIG_FILE
36 #if !defined(MBEDTLS_SHA256_ALT)
37 // Regular implementation
45 * \brief SHA-256 context structure
49 uint32_t total
[2]; /*!< number of bytes processed */
50 uint32_t state
[8]; /*!< intermediate digest state */
51 unsigned char buffer
[64]; /*!< data block being processed */
52 int is224
; /*!< 0 => SHA-256, else SHA-224 */
54 mbedtls_sha256_context
;
57 * \brief Initialize SHA-256 context
59 * \param ctx SHA-256 context to be initialized
61 void mbedtls_sha256_init( mbedtls_sha256_context
*ctx
);
64 * \brief Clear SHA-256 context
66 * \param ctx SHA-256 context to be cleared
68 void mbedtls_sha256_free( mbedtls_sha256_context
*ctx
);
71 * \brief Clone (the state of) a SHA-256 context
73 * \param dst The destination context
74 * \param src The context to be cloned
76 void mbedtls_sha256_clone( mbedtls_sha256_context
*dst
,
77 const mbedtls_sha256_context
*src
);
80 * \brief SHA-256 context setup
82 * \param ctx context to be initialized
83 * \param is224 0 = use SHA256, 1 = use SHA224
85 void mbedtls_sha256_starts( mbedtls_sha256_context
*ctx
, int is224
);
88 * \brief SHA-256 process buffer
90 * \param ctx SHA-256 context
91 * \param input buffer holding the data
92 * \param ilen length of the input data
94 void mbedtls_sha256_update( mbedtls_sha256_context
*ctx
, const unsigned char *input
,
98 * \brief SHA-256 final digest
100 * \param ctx SHA-256 context
101 * \param output SHA-224/256 checksum result
103 void mbedtls_sha256_finish( mbedtls_sha256_context
*ctx
, unsigned char output
[32] );
106 void mbedtls_sha256_process( mbedtls_sha256_context
*ctx
, const unsigned char data
[64] );
112 #else /* MBEDTLS_SHA256_ALT */
113 #include "sha256_alt.h"
114 #endif /* MBEDTLS_SHA256_ALT */
121 * \brief Output = SHA-256( input buffer )
123 * \param input buffer holding the data
124 * \param ilen length of the input data
125 * \param output SHA-224/256 checksum result
126 * \param is224 0 = use SHA256, 1 = use SHA224
128 void mbedtls_sha256( const unsigned char *input
, size_t ilen
,
129 unsigned char output
[32], int is224
);
132 * \brief Checkup routine
134 * \return 0 if successful, or 1 if the test failed
136 int mbedtls_sha256_self_test( int verbose
);
142 #endif /* mbedtls_sha256.h */