Library for Bert van Dam's book "ARM MICROCONTROLLERS" For all chapters with internet.

Dependencies:   mbed

Committer:
ICTFBI
Date:
Fri Oct 16 14:28:26 2015 +0000
Revision:
0:4edb816d21e1
Pre-update 16-10-15

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ICTFBI 0:4edb816d21e1 1 /*
ICTFBI 0:4edb816d21e1 2 * \file sha1.h
ICTFBI 0:4edb816d21e1 3 *
ICTFBI 0:4edb816d21e1 4 * Copyright (C) 2006-2010, Paul Bakker <polarssl_maintainer at polarssl.org>
ICTFBI 0:4edb816d21e1 5 * All rights reserved.
ICTFBI 0:4edb816d21e1 6 *
ICTFBI 0:4edb816d21e1 7 * This program is free software; you can redistribute it and/or modify
ICTFBI 0:4edb816d21e1 8 * it under the terms of the GNU General Public License as published by
ICTFBI 0:4edb816d21e1 9 * the Free Software Foundation; either version 2 of the License, or
ICTFBI 0:4edb816d21e1 10 * (at your option) any later version.
ICTFBI 0:4edb816d21e1 11 *
ICTFBI 0:4edb816d21e1 12 * This program is distributed in the hope that it will be useful,
ICTFBI 0:4edb816d21e1 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ICTFBI 0:4edb816d21e1 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ICTFBI 0:4edb816d21e1 15 * GNU General Public License for more details.
ICTFBI 0:4edb816d21e1 16 *
ICTFBI 0:4edb816d21e1 17 * You should have received a copy of the GNU General Public License along
ICTFBI 0:4edb816d21e1 18 * with this program; if not, write to the Free Software Foundation, Inc.,
ICTFBI 0:4edb816d21e1 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ICTFBI 0:4edb816d21e1 20 */
ICTFBI 0:4edb816d21e1 21 #ifndef POLARSSL_SHA1_H
ICTFBI 0:4edb816d21e1 22 #define POLARSSL_SHA1_H
ICTFBI 0:4edb816d21e1 23
ICTFBI 0:4edb816d21e1 24 /*
ICTFBI 0:4edb816d21e1 25 * \brief SHA-1 context structure
ICTFBI 0:4edb816d21e1 26 */
ICTFBI 0:4edb816d21e1 27 typedef struct
ICTFBI 0:4edb816d21e1 28 {
ICTFBI 0:4edb816d21e1 29 unsigned long total[2]; /*!< number of bytes processed */
ICTFBI 0:4edb816d21e1 30 unsigned long state[5]; /*!< intermediate digest state */
ICTFBI 0:4edb816d21e1 31 unsigned char buffer[64]; /*!< data block being processed */
ICTFBI 0:4edb816d21e1 32
ICTFBI 0:4edb816d21e1 33 unsigned char ipad[64]; /*!< HMAC: inner padding */
ICTFBI 0:4edb816d21e1 34 unsigned char opad[64]; /*!< HMAC: outer padding */
ICTFBI 0:4edb816d21e1 35 }
ICTFBI 0:4edb816d21e1 36 sha1_context;
ICTFBI 0:4edb816d21e1 37
ICTFBI 0:4edb816d21e1 38 #ifdef __cplusplus
ICTFBI 0:4edb816d21e1 39 extern "C" {
ICTFBI 0:4edb816d21e1 40 #endif
ICTFBI 0:4edb816d21e1 41
ICTFBI 0:4edb816d21e1 42 /*
ICTFBI 0:4edb816d21e1 43 * \brief SHA-1 context setup
ICTFBI 0:4edb816d21e1 44 *
ICTFBI 0:4edb816d21e1 45 * \param ctx context to be initialized
ICTFBI 0:4edb816d21e1 46 */
ICTFBI 0:4edb816d21e1 47 void sha1_starts( sha1_context *ctx );
ICTFBI 0:4edb816d21e1 48
ICTFBI 0:4edb816d21e1 49 /*
ICTFBI 0:4edb816d21e1 50 * \brief SHA-1 process buffer
ICTFBI 0:4edb816d21e1 51 *
ICTFBI 0:4edb816d21e1 52 * \param ctx SHA-1 context
ICTFBI 0:4edb816d21e1 53 * \param input buffer holding the data
ICTFBI 0:4edb816d21e1 54 * \param ilen length of the input data
ICTFBI 0:4edb816d21e1 55 */
ICTFBI 0:4edb816d21e1 56 void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen );
ICTFBI 0:4edb816d21e1 57
ICTFBI 0:4edb816d21e1 58 /*
ICTFBI 0:4edb816d21e1 59 * \brief SHA-1 final digest
ICTFBI 0:4edb816d21e1 60 *
ICTFBI 0:4edb816d21e1 61 * \param ctx SHA-1 context
ICTFBI 0:4edb816d21e1 62 * \param output SHA-1 checksum result
ICTFBI 0:4edb816d21e1 63 */
ICTFBI 0:4edb816d21e1 64 void sha1_finish( sha1_context *ctx, unsigned char output[20] );
ICTFBI 0:4edb816d21e1 65
ICTFBI 0:4edb816d21e1 66 /*
ICTFBI 0:4edb816d21e1 67 * \brief Output = SHA-1( input buffer )
ICTFBI 0:4edb816d21e1 68 *
ICTFBI 0:4edb816d21e1 69 * \param input buffer holding the data
ICTFBI 0:4edb816d21e1 70 * \param ilen length of the input data
ICTFBI 0:4edb816d21e1 71 * \param output SHA-1 checksum result
ICTFBI 0:4edb816d21e1 72 */
ICTFBI 0:4edb816d21e1 73 void sha1( const unsigned char *input, int ilen, unsigned char output[20] );
ICTFBI 0:4edb816d21e1 74
ICTFBI 0:4edb816d21e1 75 #if 0 //No need for that
ICTFBI 0:4edb816d21e1 76 /*
ICTFBI 0:4edb816d21e1 77 * \brief Output = SHA-1( file contents )
ICTFBI 0:4edb816d21e1 78 *
ICTFBI 0:4edb816d21e1 79 * \param path input file name
ICTFBI 0:4edb816d21e1 80 * \param output SHA-1 checksum result
ICTFBI 0:4edb816d21e1 81 *
ICTFBI 0:4edb816d21e1 82 * \return 0 if successful, 1 if fopen failed,
ICTFBI 0:4edb816d21e1 83 * or 2 if fread failed
ICTFBI 0:4edb816d21e1 84 */
ICTFBI 0:4edb816d21e1 85 int sha1_file( const char *path, unsigned char output[20] );
ICTFBI 0:4edb816d21e1 86 #endif
ICTFBI 0:4edb816d21e1 87
ICTFBI 0:4edb816d21e1 88 /*
ICTFBI 0:4edb816d21e1 89 * \brief SHA-1 HMAC context setup
ICTFBI 0:4edb816d21e1 90 *
ICTFBI 0:4edb816d21e1 91 * \param ctx HMAC context to be initialized
ICTFBI 0:4edb816d21e1 92 * \param key HMAC secret key
ICTFBI 0:4edb816d21e1 93 * \param keylen length of the HMAC key
ICTFBI 0:4edb816d21e1 94 */
ICTFBI 0:4edb816d21e1 95 void sha1_hmac_starts( sha1_context *ctx, const unsigned char *key, int keylen );
ICTFBI 0:4edb816d21e1 96
ICTFBI 0:4edb816d21e1 97 /*
ICTFBI 0:4edb816d21e1 98 * \brief SHA-1 HMAC process buffer
ICTFBI 0:4edb816d21e1 99 *
ICTFBI 0:4edb816d21e1 100 * \param ctx HMAC context
ICTFBI 0:4edb816d21e1 101 * \param input buffer holding the data
ICTFBI 0:4edb816d21e1 102 * \param ilen length of the input data
ICTFBI 0:4edb816d21e1 103 */
ICTFBI 0:4edb816d21e1 104 void sha1_hmac_update( sha1_context *ctx, const unsigned char *input, int ilen );
ICTFBI 0:4edb816d21e1 105
ICTFBI 0:4edb816d21e1 106 /*
ICTFBI 0:4edb816d21e1 107 * \brief SHA-1 HMAC final digest
ICTFBI 0:4edb816d21e1 108 *
ICTFBI 0:4edb816d21e1 109 * \param ctx HMAC context
ICTFBI 0:4edb816d21e1 110 * \param output SHA-1 HMAC checksum result
ICTFBI 0:4edb816d21e1 111 */
ICTFBI 0:4edb816d21e1 112 void sha1_hmac_finish( sha1_context *ctx, unsigned char output[20] );
ICTFBI 0:4edb816d21e1 113
ICTFBI 0:4edb816d21e1 114 /*
ICTFBI 0:4edb816d21e1 115 * \brief SHA-1 HMAC context reset
ICTFBI 0:4edb816d21e1 116 *
ICTFBI 0:4edb816d21e1 117 * \param ctx HMAC context to be reset
ICTFBI 0:4edb816d21e1 118 */
ICTFBI 0:4edb816d21e1 119 void sha1_hmac_reset( sha1_context *ctx );
ICTFBI 0:4edb816d21e1 120
ICTFBI 0:4edb816d21e1 121 /*
ICTFBI 0:4edb816d21e1 122 * \brief Output = HMAC-SHA-1( hmac key, input buffer )
ICTFBI 0:4edb816d21e1 123 *
ICTFBI 0:4edb816d21e1 124 * \param key HMAC secret key
ICTFBI 0:4edb816d21e1 125 * \param keylen length of the HMAC key
ICTFBI 0:4edb816d21e1 126 * \param input buffer holding the data
ICTFBI 0:4edb816d21e1 127 * \param ilen length of the input data
ICTFBI 0:4edb816d21e1 128 * \param output HMAC-SHA-1 result
ICTFBI 0:4edb816d21e1 129 */
ICTFBI 0:4edb816d21e1 130 void sha1_hmac( const unsigned char *key, int keylen,
ICTFBI 0:4edb816d21e1 131 const unsigned char *input, int ilen,
ICTFBI 0:4edb816d21e1 132 unsigned char output[20] );
ICTFBI 0:4edb816d21e1 133
ICTFBI 0:4edb816d21e1 134 /*
ICTFBI 0:4edb816d21e1 135 * \brief Checkup routine
ICTFBI 0:4edb816d21e1 136 *
ICTFBI 0:4edb816d21e1 137 * \return 0 if successful, or 1 if the test failed
ICTFBI 0:4edb816d21e1 138 */
ICTFBI 0:4edb816d21e1 139 int sha1_self_test( int verbose );
ICTFBI 0:4edb816d21e1 140
ICTFBI 0:4edb816d21e1 141 #ifdef __cplusplus
ICTFBI 0:4edb816d21e1 142 }
ICTFBI 0:4edb816d21e1 143 #endif
ICTFBI 0:4edb816d21e1 144
ICTFBI 0:4edb816d21e1 145 #endif /* sha1.h */