Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
Simon Butcher | a02fe7c | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 2 | * \file md4.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief MD4 message digest algorithm (hash function) |
| 5 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 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. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 20 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 21 | * This file is part of mbed TLS (https://tls.mbed.org) |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 22 | * |
| 23 | * \warning MD4 is considered a weak message digest and its use constitutes a |
| 24 | * security risk. We recommend considering stronger message |
| 25 | * digests instead. |
| 26 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 27 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 28 | #ifndef MBEDTLS_MD4_H |
| 29 | #define MBEDTLS_MD4_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 30 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 31 | #if !defined(MBEDTLS_CONFIG_FILE) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 32 | #include "config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 33 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 34 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 35 | #endif |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 36 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 37 | #include <stddef.h> |
Manuel Pégourié-Gonnard | ab22910 | 2015-04-15 11:53:16 +0200 | [diff] [blame] | 38 | #include <stdint.h> |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 39 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 40 | #if !defined(MBEDTLS_MD4_ALT) |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 41 | // Regular implementation |
| 42 | // |
| 43 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 44 | #ifdef __cplusplus |
| 45 | extern "C" { |
| 46 | #endif |
| 47 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 48 | /** |
| 49 | * \brief MD4 context structure |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 50 | * |
| 51 | * \warning MD4 is considered a weak message digest and its use |
| 52 | * constitutes a security risk. We recommend considering |
| 53 | * stronger message digests instead. |
| 54 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 55 | */ |
| 56 | typedef struct |
| 57 | { |
Paul Bakker | 5c2364c | 2012-10-01 14:41:15 +0000 | [diff] [blame] | 58 | uint32_t total[2]; /*!< number of bytes processed */ |
| 59 | uint32_t state[4]; /*!< intermediate digest state */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 60 | unsigned char buffer[64]; /*!< data block being processed */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 61 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 62 | mbedtls_md4_context; |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 63 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 64 | /** |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 65 | * \brief Initialize MD4 context |
| 66 | * |
| 67 | * \param ctx MD4 context to be initialized |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 68 | * |
| 69 | * \warning MD4 is considered a weak message digest and its use |
| 70 | * constitutes a security risk. We recommend considering |
| 71 | * stronger message digests instead. |
| 72 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 73 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | void mbedtls_md4_init( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 75 | |
| 76 | /** |
| 77 | * \brief Clear MD4 context |
| 78 | * |
| 79 | * \param ctx MD4 context to be cleared |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 80 | * |
| 81 | * \warning MD4 is considered a weak message digest and its use |
| 82 | * constitutes a security risk. We recommend considering |
| 83 | * stronger message digests instead. |
| 84 | * |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 85 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 86 | void mbedtls_md4_free( mbedtls_md4_context *ctx ); |
Paul Bakker | 5b4af39 | 2014-06-26 12:09:34 +0200 | [diff] [blame] | 87 | |
| 88 | /** |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 89 | * \brief Clone (the state of) an MD4 context |
| 90 | * |
| 91 | * \param dst The destination context |
| 92 | * \param src The context to be cloned |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 93 | * |
| 94 | * \warning MD4 is considered a weak message digest and its use |
| 95 | * constitutes a security risk. We recommend considering |
| 96 | * stronger message digests instead. |
| 97 | * |
Manuel Pégourié-Gonnard | 16d412f | 2015-07-06 15:26:26 +0200 | [diff] [blame] | 98 | */ |
| 99 | void mbedtls_md4_clone( mbedtls_md4_context *dst, |
| 100 | const mbedtls_md4_context *src ); |
| 101 | |
| 102 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | * \brief MD4 context setup |
| 104 | * |
| 105 | * \param ctx context to be initialized |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 106 | * |
| 107 | * \warning MD4 is considered a weak message digest and its use |
| 108 | * constitutes a security risk. We recommend considering |
| 109 | * stronger message digests instead. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 111 | void mbedtls_md4_starts( mbedtls_md4_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * \brief MD4 process buffer |
| 115 | * |
| 116 | * \param ctx MD4 context |
| 117 | * \param input buffer holding the data |
| 118 | * \param ilen length of the input data |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 119 | * |
| 120 | * \warning MD4 is considered a weak message digest and its use |
| 121 | * constitutes a security risk. We recommend considering |
| 122 | * stronger message digests instead. |
| 123 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 124 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 125 | void mbedtls_md4_update( mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * \brief MD4 final digest |
| 129 | * |
| 130 | * \param ctx MD4 context |
| 131 | * \param output MD4 checksum result |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 132 | * |
| 133 | * \warning MD4 is considered a weak message digest and its use |
| 134 | * constitutes a security risk. We recommend considering |
| 135 | * stronger message digests instead. |
| 136 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 137 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 138 | void mbedtls_md4_finish( mbedtls_md4_context *ctx, unsigned char output[16] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 139 | |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 140 | #ifdef __cplusplus |
| 141 | } |
| 142 | #endif |
| 143 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 144 | #else /* MBEDTLS_MD4_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 145 | #include "md4_alt.h" |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 146 | #endif /* MBEDTLS_MD4_ALT */ |
Paul Bakker | 90995b5 | 2013-06-24 19:20:35 +0200 | [diff] [blame] | 147 | |
| 148 | #ifdef __cplusplus |
| 149 | extern "C" { |
| 150 | #endif |
| 151 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 152 | /** |
| 153 | * \brief Output = MD4( input buffer ) |
| 154 | * |
| 155 | * \param input buffer holding the data |
| 156 | * \param ilen length of the input data |
| 157 | * \param output MD4 checksum result |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 158 | * |
| 159 | * \warning MD4 is considered a weak message digest and its use |
| 160 | * constitutes a security risk. We recommend considering |
| 161 | * stronger message digests instead. |
| 162 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 163 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 164 | void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | |
| 166 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 167 | * \brief Checkup routine |
| 168 | * |
| 169 | * \return 0 if successful, or 1 if the test failed |
Hanno Becker | 15e4951 | 2017-09-25 14:53:51 +0100 | [diff] [blame] | 170 | * |
| 171 | * \warning MD4 is considered a weak message digest and its use |
| 172 | * constitutes a security risk. We recommend considering |
| 173 | * stronger message digests instead. |
| 174 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 175 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 176 | int mbedtls_md4_self_test( int verbose ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 177 | |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 178 | /* Internal use */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 179 | void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] ); |
Paul Bakker | 1bd3ae8 | 2013-03-13 10:26:44 +0100 | [diff] [blame] | 180 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 181 | #ifdef __cplusplus |
| 182 | } |
| 183 | #endif |
| 184 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 185 | #endif /* mbedtls_md4.h */ |