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