The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

See the WNCInterface README in the Wiki tab for detailed information on this library.

Committer:
JMF
Date:
Fri Mar 24 22:26:23 2017 +0000
Revision:
29:b278b745fb4f
Parent:
12:0071cb144c7a
updated Class name of TCPSocketConnection to WncTCPSocketConnection;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 12:0071cb144c7a 1 /*
JMF 12:0071cb144c7a 2 * RFC 1186/1320 compliant MD4 implementation
JMF 12:0071cb144c7a 3 *
JMF 12:0071cb144c7a 4 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
JMF 12:0071cb144c7a 5 * SPDX-License-Identifier: Apache-2.0
JMF 12:0071cb144c7a 6 *
JMF 12:0071cb144c7a 7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
JMF 12:0071cb144c7a 8 * not use this file except in compliance with the License.
JMF 12:0071cb144c7a 9 * You may obtain a copy of the License at
JMF 12:0071cb144c7a 10 *
JMF 12:0071cb144c7a 11 * http://www.apache.org/licenses/LICENSE-2.0
JMF 12:0071cb144c7a 12 *
JMF 12:0071cb144c7a 13 * Unless required by applicable law or agreed to in writing, software
JMF 12:0071cb144c7a 14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
JMF 12:0071cb144c7a 15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
JMF 12:0071cb144c7a 16 * See the License for the specific language governing permissions and
JMF 12:0071cb144c7a 17 * limitations under the License.
JMF 12:0071cb144c7a 18 *
JMF 12:0071cb144c7a 19 * This file is part of mbed TLS (https://tls.mbed.org)
JMF 12:0071cb144c7a 20 */
JMF 12:0071cb144c7a 21 /*
JMF 12:0071cb144c7a 22 * The MD4 algorithm was designed by Ron Rivest in 1990.
JMF 12:0071cb144c7a 23 *
JMF 12:0071cb144c7a 24 * http://www.ietf.org/rfc/rfc1186.txt
JMF 12:0071cb144c7a 25 * http://www.ietf.org/rfc/rfc1320.txt
JMF 12:0071cb144c7a 26 */
JMF 12:0071cb144c7a 27
JMF 12:0071cb144c7a 28 #if !defined(MBEDTLS_CONFIG_FILE)
JMF 12:0071cb144c7a 29 #include "mbedtls/config.h"
JMF 12:0071cb144c7a 30 #else
JMF 12:0071cb144c7a 31 #include MBEDTLS_CONFIG_FILE
JMF 12:0071cb144c7a 32 #endif
JMF 12:0071cb144c7a 33
JMF 12:0071cb144c7a 34 #if defined(MBEDTLS_MD4_C)
JMF 12:0071cb144c7a 35
JMF 12:0071cb144c7a 36 #include "mbedtls/md4.h"
JMF 12:0071cb144c7a 37
JMF 12:0071cb144c7a 38 #include <string.h>
JMF 12:0071cb144c7a 39
JMF 12:0071cb144c7a 40 #if defined(MBEDTLS_SELF_TEST)
JMF 12:0071cb144c7a 41 #if defined(MBEDTLS_PLATFORM_C)
JMF 12:0071cb144c7a 42 #include "mbedtls/platform.h"
JMF 12:0071cb144c7a 43 #else
JMF 12:0071cb144c7a 44 #include <stdio.h>
JMF 12:0071cb144c7a 45 #define mbedtls_printf printf
JMF 12:0071cb144c7a 46 #endif /* MBEDTLS_PLATFORM_C */
JMF 12:0071cb144c7a 47 #endif /* MBEDTLS_SELF_TEST */
JMF 12:0071cb144c7a 48
JMF 12:0071cb144c7a 49 #if !defined(MBEDTLS_MD4_ALT)
JMF 12:0071cb144c7a 50
JMF 12:0071cb144c7a 51 /* Implementation that should never be optimized out by the compiler */
JMF 12:0071cb144c7a 52 static void mbedtls_zeroize( void *v, size_t n ) {
JMF 12:0071cb144c7a 53 volatile unsigned char *p = v; while( n-- ) *p++ = 0;
JMF 12:0071cb144c7a 54 }
JMF 12:0071cb144c7a 55
JMF 12:0071cb144c7a 56 /*
JMF 12:0071cb144c7a 57 * 32-bit integer manipulation macros (little endian)
JMF 12:0071cb144c7a 58 */
JMF 12:0071cb144c7a 59 #ifndef GET_UINT32_LE
JMF 12:0071cb144c7a 60 #define GET_UINT32_LE(n,b,i) \
JMF 12:0071cb144c7a 61 { \
JMF 12:0071cb144c7a 62 (n) = ( (uint32_t) (b)[(i) ] ) \
JMF 12:0071cb144c7a 63 | ( (uint32_t) (b)[(i) + 1] << 8 ) \
JMF 12:0071cb144c7a 64 | ( (uint32_t) (b)[(i) + 2] << 16 ) \
JMF 12:0071cb144c7a 65 | ( (uint32_t) (b)[(i) + 3] << 24 ); \
JMF 12:0071cb144c7a 66 }
JMF 12:0071cb144c7a 67 #endif
JMF 12:0071cb144c7a 68
JMF 12:0071cb144c7a 69 #ifndef PUT_UINT32_LE
JMF 12:0071cb144c7a 70 #define PUT_UINT32_LE(n,b,i) \
JMF 12:0071cb144c7a 71 { \
JMF 12:0071cb144c7a 72 (b)[(i) ] = (unsigned char) ( ( (n) ) & 0xFF ); \
JMF 12:0071cb144c7a 73 (b)[(i) + 1] = (unsigned char) ( ( (n) >> 8 ) & 0xFF ); \
JMF 12:0071cb144c7a 74 (b)[(i) + 2] = (unsigned char) ( ( (n) >> 16 ) & 0xFF ); \
JMF 12:0071cb144c7a 75 (b)[(i) + 3] = (unsigned char) ( ( (n) >> 24 ) & 0xFF ); \
JMF 12:0071cb144c7a 76 }
JMF 12:0071cb144c7a 77 #endif
JMF 12:0071cb144c7a 78
JMF 12:0071cb144c7a 79 void mbedtls_md4_init( mbedtls_md4_context *ctx )
JMF 12:0071cb144c7a 80 {
JMF 12:0071cb144c7a 81 memset( ctx, 0, sizeof( mbedtls_md4_context ) );
JMF 12:0071cb144c7a 82 }
JMF 12:0071cb144c7a 83
JMF 12:0071cb144c7a 84 void mbedtls_md4_free( mbedtls_md4_context *ctx )
JMF 12:0071cb144c7a 85 {
JMF 12:0071cb144c7a 86 if( ctx == NULL )
JMF 12:0071cb144c7a 87 return;
JMF 12:0071cb144c7a 88
JMF 12:0071cb144c7a 89 mbedtls_zeroize( ctx, sizeof( mbedtls_md4_context ) );
JMF 12:0071cb144c7a 90 }
JMF 12:0071cb144c7a 91
JMF 12:0071cb144c7a 92 void mbedtls_md4_clone( mbedtls_md4_context *dst,
JMF 12:0071cb144c7a 93 const mbedtls_md4_context *src )
JMF 12:0071cb144c7a 94 {
JMF 12:0071cb144c7a 95 *dst = *src;
JMF 12:0071cb144c7a 96 }
JMF 12:0071cb144c7a 97
JMF 12:0071cb144c7a 98 /*
JMF 12:0071cb144c7a 99 * MD4 context setup
JMF 12:0071cb144c7a 100 */
JMF 12:0071cb144c7a 101 void mbedtls_md4_starts( mbedtls_md4_context *ctx )
JMF 12:0071cb144c7a 102 {
JMF 12:0071cb144c7a 103 ctx->total[0] = 0;
JMF 12:0071cb144c7a 104 ctx->total[1] = 0;
JMF 12:0071cb144c7a 105
JMF 12:0071cb144c7a 106 ctx->state[0] = 0x67452301;
JMF 12:0071cb144c7a 107 ctx->state[1] = 0xEFCDAB89;
JMF 12:0071cb144c7a 108 ctx->state[2] = 0x98BADCFE;
JMF 12:0071cb144c7a 109 ctx->state[3] = 0x10325476;
JMF 12:0071cb144c7a 110 }
JMF 12:0071cb144c7a 111
JMF 12:0071cb144c7a 112 #if !defined(MBEDTLS_MD4_PROCESS_ALT)
JMF 12:0071cb144c7a 113 void mbedtls_md4_process( mbedtls_md4_context *ctx, const unsigned char data[64] )
JMF 12:0071cb144c7a 114 {
JMF 12:0071cb144c7a 115 uint32_t X[16], A, B, C, D;
JMF 12:0071cb144c7a 116
JMF 12:0071cb144c7a 117 GET_UINT32_LE( X[ 0], data, 0 );
JMF 12:0071cb144c7a 118 GET_UINT32_LE( X[ 1], data, 4 );
JMF 12:0071cb144c7a 119 GET_UINT32_LE( X[ 2], data, 8 );
JMF 12:0071cb144c7a 120 GET_UINT32_LE( X[ 3], data, 12 );
JMF 12:0071cb144c7a 121 GET_UINT32_LE( X[ 4], data, 16 );
JMF 12:0071cb144c7a 122 GET_UINT32_LE( X[ 5], data, 20 );
JMF 12:0071cb144c7a 123 GET_UINT32_LE( X[ 6], data, 24 );
JMF 12:0071cb144c7a 124 GET_UINT32_LE( X[ 7], data, 28 );
JMF 12:0071cb144c7a 125 GET_UINT32_LE( X[ 8], data, 32 );
JMF 12:0071cb144c7a 126 GET_UINT32_LE( X[ 9], data, 36 );
JMF 12:0071cb144c7a 127 GET_UINT32_LE( X[10], data, 40 );
JMF 12:0071cb144c7a 128 GET_UINT32_LE( X[11], data, 44 );
JMF 12:0071cb144c7a 129 GET_UINT32_LE( X[12], data, 48 );
JMF 12:0071cb144c7a 130 GET_UINT32_LE( X[13], data, 52 );
JMF 12:0071cb144c7a 131 GET_UINT32_LE( X[14], data, 56 );
JMF 12:0071cb144c7a 132 GET_UINT32_LE( X[15], data, 60 );
JMF 12:0071cb144c7a 133
JMF 12:0071cb144c7a 134 #define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
JMF 12:0071cb144c7a 135
JMF 12:0071cb144c7a 136 A = ctx->state[0];
JMF 12:0071cb144c7a 137 B = ctx->state[1];
JMF 12:0071cb144c7a 138 C = ctx->state[2];
JMF 12:0071cb144c7a 139 D = ctx->state[3];
JMF 12:0071cb144c7a 140
JMF 12:0071cb144c7a 141 #define F(x, y, z) ((x & y) | ((~x) & z))
JMF 12:0071cb144c7a 142 #define P(a,b,c,d,x,s) { a += F(b,c,d) + x; a = S(a,s); }
JMF 12:0071cb144c7a 143
JMF 12:0071cb144c7a 144 P( A, B, C, D, X[ 0], 3 );
JMF 12:0071cb144c7a 145 P( D, A, B, C, X[ 1], 7 );
JMF 12:0071cb144c7a 146 P( C, D, A, B, X[ 2], 11 );
JMF 12:0071cb144c7a 147 P( B, C, D, A, X[ 3], 19 );
JMF 12:0071cb144c7a 148 P( A, B, C, D, X[ 4], 3 );
JMF 12:0071cb144c7a 149 P( D, A, B, C, X[ 5], 7 );
JMF 12:0071cb144c7a 150 P( C, D, A, B, X[ 6], 11 );
JMF 12:0071cb144c7a 151 P( B, C, D, A, X[ 7], 19 );
JMF 12:0071cb144c7a 152 P( A, B, C, D, X[ 8], 3 );
JMF 12:0071cb144c7a 153 P( D, A, B, C, X[ 9], 7 );
JMF 12:0071cb144c7a 154 P( C, D, A, B, X[10], 11 );
JMF 12:0071cb144c7a 155 P( B, C, D, A, X[11], 19 );
JMF 12:0071cb144c7a 156 P( A, B, C, D, X[12], 3 );
JMF 12:0071cb144c7a 157 P( D, A, B, C, X[13], 7 );
JMF 12:0071cb144c7a 158 P( C, D, A, B, X[14], 11 );
JMF 12:0071cb144c7a 159 P( B, C, D, A, X[15], 19 );
JMF 12:0071cb144c7a 160
JMF 12:0071cb144c7a 161 #undef P
JMF 12:0071cb144c7a 162 #undef F
JMF 12:0071cb144c7a 163
JMF 12:0071cb144c7a 164 #define F(x,y,z) ((x & y) | (x & z) | (y & z))
JMF 12:0071cb144c7a 165 #define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x5A827999; a = S(a,s); }
JMF 12:0071cb144c7a 166
JMF 12:0071cb144c7a 167 P( A, B, C, D, X[ 0], 3 );
JMF 12:0071cb144c7a 168 P( D, A, B, C, X[ 4], 5 );
JMF 12:0071cb144c7a 169 P( C, D, A, B, X[ 8], 9 );
JMF 12:0071cb144c7a 170 P( B, C, D, A, X[12], 13 );
JMF 12:0071cb144c7a 171 P( A, B, C, D, X[ 1], 3 );
JMF 12:0071cb144c7a 172 P( D, A, B, C, X[ 5], 5 );
JMF 12:0071cb144c7a 173 P( C, D, A, B, X[ 9], 9 );
JMF 12:0071cb144c7a 174 P( B, C, D, A, X[13], 13 );
JMF 12:0071cb144c7a 175 P( A, B, C, D, X[ 2], 3 );
JMF 12:0071cb144c7a 176 P( D, A, B, C, X[ 6], 5 );
JMF 12:0071cb144c7a 177 P( C, D, A, B, X[10], 9 );
JMF 12:0071cb144c7a 178 P( B, C, D, A, X[14], 13 );
JMF 12:0071cb144c7a 179 P( A, B, C, D, X[ 3], 3 );
JMF 12:0071cb144c7a 180 P( D, A, B, C, X[ 7], 5 );
JMF 12:0071cb144c7a 181 P( C, D, A, B, X[11], 9 );
JMF 12:0071cb144c7a 182 P( B, C, D, A, X[15], 13 );
JMF 12:0071cb144c7a 183
JMF 12:0071cb144c7a 184 #undef P
JMF 12:0071cb144c7a 185 #undef F
JMF 12:0071cb144c7a 186
JMF 12:0071cb144c7a 187 #define F(x,y,z) (x ^ y ^ z)
JMF 12:0071cb144c7a 188 #define P(a,b,c,d,x,s) { a += F(b,c,d) + x + 0x6ED9EBA1; a = S(a,s); }
JMF 12:0071cb144c7a 189
JMF 12:0071cb144c7a 190 P( A, B, C, D, X[ 0], 3 );
JMF 12:0071cb144c7a 191 P( D, A, B, C, X[ 8], 9 );
JMF 12:0071cb144c7a 192 P( C, D, A, B, X[ 4], 11 );
JMF 12:0071cb144c7a 193 P( B, C, D, A, X[12], 15 );
JMF 12:0071cb144c7a 194 P( A, B, C, D, X[ 2], 3 );
JMF 12:0071cb144c7a 195 P( D, A, B, C, X[10], 9 );
JMF 12:0071cb144c7a 196 P( C, D, A, B, X[ 6], 11 );
JMF 12:0071cb144c7a 197 P( B, C, D, A, X[14], 15 );
JMF 12:0071cb144c7a 198 P( A, B, C, D, X[ 1], 3 );
JMF 12:0071cb144c7a 199 P( D, A, B, C, X[ 9], 9 );
JMF 12:0071cb144c7a 200 P( C, D, A, B, X[ 5], 11 );
JMF 12:0071cb144c7a 201 P( B, C, D, A, X[13], 15 );
JMF 12:0071cb144c7a 202 P( A, B, C, D, X[ 3], 3 );
JMF 12:0071cb144c7a 203 P( D, A, B, C, X[11], 9 );
JMF 12:0071cb144c7a 204 P( C, D, A, B, X[ 7], 11 );
JMF 12:0071cb144c7a 205 P( B, C, D, A, X[15], 15 );
JMF 12:0071cb144c7a 206
JMF 12:0071cb144c7a 207 #undef F
JMF 12:0071cb144c7a 208 #undef P
JMF 12:0071cb144c7a 209
JMF 12:0071cb144c7a 210 ctx->state[0] += A;
JMF 12:0071cb144c7a 211 ctx->state[1] += B;
JMF 12:0071cb144c7a 212 ctx->state[2] += C;
JMF 12:0071cb144c7a 213 ctx->state[3] += D;
JMF 12:0071cb144c7a 214 }
JMF 12:0071cb144c7a 215 #endif /* !MBEDTLS_MD4_PROCESS_ALT */
JMF 12:0071cb144c7a 216
JMF 12:0071cb144c7a 217 /*
JMF 12:0071cb144c7a 218 * MD4 process buffer
JMF 12:0071cb144c7a 219 */
JMF 12:0071cb144c7a 220 void mbedtls_md4_update( mbedtls_md4_context *ctx, const unsigned char *input, size_t ilen )
JMF 12:0071cb144c7a 221 {
JMF 12:0071cb144c7a 222 size_t fill;
JMF 12:0071cb144c7a 223 uint32_t left;
JMF 12:0071cb144c7a 224
JMF 12:0071cb144c7a 225 if( ilen == 0 )
JMF 12:0071cb144c7a 226 return;
JMF 12:0071cb144c7a 227
JMF 12:0071cb144c7a 228 left = ctx->total[0] & 0x3F;
JMF 12:0071cb144c7a 229 fill = 64 - left;
JMF 12:0071cb144c7a 230
JMF 12:0071cb144c7a 231 ctx->total[0] += (uint32_t) ilen;
JMF 12:0071cb144c7a 232 ctx->total[0] &= 0xFFFFFFFF;
JMF 12:0071cb144c7a 233
JMF 12:0071cb144c7a 234 if( ctx->total[0] < (uint32_t) ilen )
JMF 12:0071cb144c7a 235 ctx->total[1]++;
JMF 12:0071cb144c7a 236
JMF 12:0071cb144c7a 237 if( left && ilen >= fill )
JMF 12:0071cb144c7a 238 {
JMF 12:0071cb144c7a 239 memcpy( (void *) (ctx->buffer + left),
JMF 12:0071cb144c7a 240 (void *) input, fill );
JMF 12:0071cb144c7a 241 mbedtls_md4_process( ctx, ctx->buffer );
JMF 12:0071cb144c7a 242 input += fill;
JMF 12:0071cb144c7a 243 ilen -= fill;
JMF 12:0071cb144c7a 244 left = 0;
JMF 12:0071cb144c7a 245 }
JMF 12:0071cb144c7a 246
JMF 12:0071cb144c7a 247 while( ilen >= 64 )
JMF 12:0071cb144c7a 248 {
JMF 12:0071cb144c7a 249 mbedtls_md4_process( ctx, input );
JMF 12:0071cb144c7a 250 input += 64;
JMF 12:0071cb144c7a 251 ilen -= 64;
JMF 12:0071cb144c7a 252 }
JMF 12:0071cb144c7a 253
JMF 12:0071cb144c7a 254 if( ilen > 0 )
JMF 12:0071cb144c7a 255 {
JMF 12:0071cb144c7a 256 memcpy( (void *) (ctx->buffer + left),
JMF 12:0071cb144c7a 257 (void *) input, ilen );
JMF 12:0071cb144c7a 258 }
JMF 12:0071cb144c7a 259 }
JMF 12:0071cb144c7a 260
JMF 12:0071cb144c7a 261 static const unsigned char md4_padding[64] =
JMF 12:0071cb144c7a 262 {
JMF 12:0071cb144c7a 263 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
JMF 12:0071cb144c7a 264 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
JMF 12:0071cb144c7a 265 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
JMF 12:0071cb144c7a 266 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
JMF 12:0071cb144c7a 267 };
JMF 12:0071cb144c7a 268
JMF 12:0071cb144c7a 269 /*
JMF 12:0071cb144c7a 270 * MD4 final digest
JMF 12:0071cb144c7a 271 */
JMF 12:0071cb144c7a 272 void mbedtls_md4_finish( mbedtls_md4_context *ctx, unsigned char output[16] )
JMF 12:0071cb144c7a 273 {
JMF 12:0071cb144c7a 274 uint32_t last, padn;
JMF 12:0071cb144c7a 275 uint32_t high, low;
JMF 12:0071cb144c7a 276 unsigned char msglen[8];
JMF 12:0071cb144c7a 277
JMF 12:0071cb144c7a 278 high = ( ctx->total[0] >> 29 )
JMF 12:0071cb144c7a 279 | ( ctx->total[1] << 3 );
JMF 12:0071cb144c7a 280 low = ( ctx->total[0] << 3 );
JMF 12:0071cb144c7a 281
JMF 12:0071cb144c7a 282 PUT_UINT32_LE( low, msglen, 0 );
JMF 12:0071cb144c7a 283 PUT_UINT32_LE( high, msglen, 4 );
JMF 12:0071cb144c7a 284
JMF 12:0071cb144c7a 285 last = ctx->total[0] & 0x3F;
JMF 12:0071cb144c7a 286 padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
JMF 12:0071cb144c7a 287
JMF 12:0071cb144c7a 288 mbedtls_md4_update( ctx, (unsigned char *) md4_padding, padn );
JMF 12:0071cb144c7a 289 mbedtls_md4_update( ctx, msglen, 8 );
JMF 12:0071cb144c7a 290
JMF 12:0071cb144c7a 291 PUT_UINT32_LE( ctx->state[0], output, 0 );
JMF 12:0071cb144c7a 292 PUT_UINT32_LE( ctx->state[1], output, 4 );
JMF 12:0071cb144c7a 293 PUT_UINT32_LE( ctx->state[2], output, 8 );
JMF 12:0071cb144c7a 294 PUT_UINT32_LE( ctx->state[3], output, 12 );
JMF 12:0071cb144c7a 295 }
JMF 12:0071cb144c7a 296
JMF 12:0071cb144c7a 297 #endif /* !MBEDTLS_MD4_ALT */
JMF 12:0071cb144c7a 298
JMF 12:0071cb144c7a 299 /*
JMF 12:0071cb144c7a 300 * output = MD4( input buffer )
JMF 12:0071cb144c7a 301 */
JMF 12:0071cb144c7a 302 void mbedtls_md4( const unsigned char *input, size_t ilen, unsigned char output[16] )
JMF 12:0071cb144c7a 303 {
JMF 12:0071cb144c7a 304 mbedtls_md4_context ctx;
JMF 12:0071cb144c7a 305
JMF 12:0071cb144c7a 306 mbedtls_md4_init( &ctx );
JMF 12:0071cb144c7a 307 mbedtls_md4_starts( &ctx );
JMF 12:0071cb144c7a 308 mbedtls_md4_update( &ctx, input, ilen );
JMF 12:0071cb144c7a 309 mbedtls_md4_finish( &ctx, output );
JMF 12:0071cb144c7a 310 mbedtls_md4_free( &ctx );
JMF 12:0071cb144c7a 311 }
JMF 12:0071cb144c7a 312
JMF 12:0071cb144c7a 313 #if defined(MBEDTLS_SELF_TEST)
JMF 12:0071cb144c7a 314
JMF 12:0071cb144c7a 315 /*
JMF 12:0071cb144c7a 316 * RFC 1320 test vectors
JMF 12:0071cb144c7a 317 */
JMF 12:0071cb144c7a 318 static const char md4_test_str[7][81] =
JMF 12:0071cb144c7a 319 {
JMF 12:0071cb144c7a 320 { "" },
JMF 12:0071cb144c7a 321 { "a" },
JMF 12:0071cb144c7a 322 { "abc" },
JMF 12:0071cb144c7a 323 { "message digest" },
JMF 12:0071cb144c7a 324 { "abcdefghijklmnopqrstuvwxyz" },
JMF 12:0071cb144c7a 325 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
JMF 12:0071cb144c7a 326 { "12345678901234567890123456789012345678901234567890123456789012" \
JMF 12:0071cb144c7a 327 "345678901234567890" }
JMF 12:0071cb144c7a 328 };
JMF 12:0071cb144c7a 329
JMF 12:0071cb144c7a 330 static const unsigned char md4_test_sum[7][16] =
JMF 12:0071cb144c7a 331 {
JMF 12:0071cb144c7a 332 { 0x31, 0xD6, 0xCF, 0xE0, 0xD1, 0x6A, 0xE9, 0x31,
JMF 12:0071cb144c7a 333 0xB7, 0x3C, 0x59, 0xD7, 0xE0, 0xC0, 0x89, 0xC0 },
JMF 12:0071cb144c7a 334 { 0xBD, 0xE5, 0x2C, 0xB3, 0x1D, 0xE3, 0x3E, 0x46,
JMF 12:0071cb144c7a 335 0x24, 0x5E, 0x05, 0xFB, 0xDB, 0xD6, 0xFB, 0x24 },
JMF 12:0071cb144c7a 336 { 0xA4, 0x48, 0x01, 0x7A, 0xAF, 0x21, 0xD8, 0x52,
JMF 12:0071cb144c7a 337 0x5F, 0xC1, 0x0A, 0xE8, 0x7A, 0xA6, 0x72, 0x9D },
JMF 12:0071cb144c7a 338 { 0xD9, 0x13, 0x0A, 0x81, 0x64, 0x54, 0x9F, 0xE8,
JMF 12:0071cb144c7a 339 0x18, 0x87, 0x48, 0x06, 0xE1, 0xC7, 0x01, 0x4B },
JMF 12:0071cb144c7a 340 { 0xD7, 0x9E, 0x1C, 0x30, 0x8A, 0xA5, 0xBB, 0xCD,
JMF 12:0071cb144c7a 341 0xEE, 0xA8, 0xED, 0x63, 0xDF, 0x41, 0x2D, 0xA9 },
JMF 12:0071cb144c7a 342 { 0x04, 0x3F, 0x85, 0x82, 0xF2, 0x41, 0xDB, 0x35,
JMF 12:0071cb144c7a 343 0x1C, 0xE6, 0x27, 0xE1, 0x53, 0xE7, 0xF0, 0xE4 },
JMF 12:0071cb144c7a 344 { 0xE3, 0x3B, 0x4D, 0xDC, 0x9C, 0x38, 0xF2, 0x19,
JMF 12:0071cb144c7a 345 0x9C, 0x3E, 0x7B, 0x16, 0x4F, 0xCC, 0x05, 0x36 }
JMF 12:0071cb144c7a 346 };
JMF 12:0071cb144c7a 347
JMF 12:0071cb144c7a 348 /*
JMF 12:0071cb144c7a 349 * Checkup routine
JMF 12:0071cb144c7a 350 */
JMF 12:0071cb144c7a 351 int mbedtls_md4_self_test( int verbose )
JMF 12:0071cb144c7a 352 {
JMF 12:0071cb144c7a 353 int i;
JMF 12:0071cb144c7a 354 unsigned char md4sum[16];
JMF 12:0071cb144c7a 355
JMF 12:0071cb144c7a 356 for( i = 0; i < 7; i++ )
JMF 12:0071cb144c7a 357 {
JMF 12:0071cb144c7a 358 if( verbose != 0 )
JMF 12:0071cb144c7a 359 mbedtls_printf( " MD4 test #%d: ", i + 1 );
JMF 12:0071cb144c7a 360
JMF 12:0071cb144c7a 361 mbedtls_md4( (unsigned char *) md4_test_str[i],
JMF 12:0071cb144c7a 362 strlen( md4_test_str[i] ), md4sum );
JMF 12:0071cb144c7a 363
JMF 12:0071cb144c7a 364 if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
JMF 12:0071cb144c7a 365 {
JMF 12:0071cb144c7a 366 if( verbose != 0 )
JMF 12:0071cb144c7a 367 mbedtls_printf( "failed\n" );
JMF 12:0071cb144c7a 368
JMF 12:0071cb144c7a 369 return( 1 );
JMF 12:0071cb144c7a 370 }
JMF 12:0071cb144c7a 371
JMF 12:0071cb144c7a 372 if( verbose != 0 )
JMF 12:0071cb144c7a 373 mbedtls_printf( "passed\n" );
JMF 12:0071cb144c7a 374 }
JMF 12:0071cb144c7a 375
JMF 12:0071cb144c7a 376 if( verbose != 0 )
JMF 12:0071cb144c7a 377 mbedtls_printf( "\n" );
JMF 12:0071cb144c7a 378
JMF 12:0071cb144c7a 379 return( 0 );
JMF 12:0071cb144c7a 380 }
JMF 12:0071cb144c7a 381
JMF 12:0071cb144c7a 382 #endif /* MBEDTLS_SELF_TEST */
JMF 12:0071cb144c7a 383
JMF 12:0071cb144c7a 384 #endif /* MBEDTLS_MD4_C */