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