blob: ad219ab63ffd795b994aa97e00b24c9de3a53dbc [file] [log] [blame]
Azim Khanec024482017-05-09 17:20:21 +01001#line 2 "suites/helpers.function"
SimonB0269dad2016-02-17 23:34:30 +00002/*----------------------------------------------------------------------------*/
3/* Headers */
4
Simon Butcheredb7fd92016-05-17 13:35:51 +01005#include <stdlib.h>
6
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02007#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00008#include "mbedtls/platform.h"
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +02009#else
Rich Evans00ab4702015-02-06 13:43:58 +000010#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020011#define mbedtls_fprintf fprintf
Simon Butcher25731362016-09-30 13:11:29 +010012#define mbedtls_snprintf snprintf
13#define mbedtls_calloc calloc
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020014#define mbedtls_free free
15#define mbedtls_exit exit
Simon Butcherb2d5dd12016-04-27 13:35:37 +010016#define mbedtls_time time
17#define mbedtls_time_t time_t
Janos Follath55abc212016-04-18 18:18:48 +010018#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
19#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +020020#endif
21
SimonB0269dad2016-02-17 23:34:30 +000022#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
23#include "mbedtls/memory_buffer_alloc.h"
24#endif
25
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000026#ifdef _MSC_VER
27#include <basetsd.h>
Azim Khan0fa35042018-06-22 11:34:33 +010028typedef UINT8 uint8_t;
29typedef INT32 int32_t;
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000030typedef UINT32 uint32_t;
Nicholas Wilson733676b2015-11-14 13:09:01 +000031#define strncasecmp _strnicmp
32#define strcasecmp _stricmp
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000033#else
Manuel Pégourié-Gonnard93866642015-06-22 19:21:23 +020034#include <stdint.h>
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000035#endif
36
Paul Bakker19343182013-08-16 13:31:10 +020037#include <string.h>
38
Janos Follath8ca53b52016-10-05 10:57:49 +010039#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
40#include <unistd.h>
Nicholas Wilson2682edf2017-12-05 12:08:15 +000041#include <strings.h>
Janos Follath8ca53b52016-10-05 10:57:49 +010042#endif
SimonB0269dad2016-02-17 23:34:30 +000043
Azim Khand30ca132017-06-09 04:32:58 +010044/* Type for Hex parameters */
Azim Khan5fcca462018-06-29 11:05:32 +010045typedef struct data_tag
Azim Khand30ca132017-06-09 04:32:58 +010046{
47 uint8_t * x;
48 uint32_t len;
Azim Khan5fcca462018-06-29 11:05:32 +010049} data_t;
Azim Khand30ca132017-06-09 04:32:58 +010050
SimonB0269dad2016-02-17 23:34:30 +000051/*----------------------------------------------------------------------------*/
Azim Khan62a5d7d2018-06-29 10:02:54 +010052/* Status and error constants */
SimonB0269dad2016-02-17 23:34:30 +000053
Azim Khan62a5d7d2018-06-29 10:02:54 +010054#define DEPENDENCY_SUPPORTED 0 /* Dependency supported by build */
55#define KEY_VALUE_MAPPING_FOUND 0 /* Integer expression found */
56#define DISPATCH_TEST_SUCCESS 0 /* Test dispatch successful */
SimonB8ca7bc42016-04-17 23:24:50 +010057
Azim Khan62a5d7d2018-06-29 10:02:54 +010058#define KEY_VALUE_MAPPING_NOT_FOUND -1 /* Integer expression not found */
59#define DEPENDENCY_NOT_SUPPORTED -2 /* Dependency not supported */
60#define DISPATCH_TEST_FN_NOT_FOUND -3 /* Test function not found */
61#define DISPATCH_INVALID_TEST_DATA -4 /* Invalid test parameter type.
62 Only int, string, binary data
63 and integer expressions are
64 allowed */
65#define DISPATCH_UNSUPPORTED_SUITE -5 /* Test suite not supported by the
66 build */
SimonB0269dad2016-02-17 23:34:30 +000067
68
69/*----------------------------------------------------------------------------*/
70/* Macros */
71
Gilles Peskine8954d0c2018-09-27 13:51:25 +020072/** Evaluate an expression and fail the test case if it is false.
73 *
74 * Failing the test means:
75 * - Mark this test case as failed.
76 * - Print a message identifying the failure.
77 * - Jump to the \c exit label.
78 *
79 * This macro expands to an instruction, not an expression.
80 * It may jump to the \c exit label.
81 *
82 * \param TEST The expression to evaluate.
83 */
SimonB0269dad2016-02-17 23:34:30 +000084#define TEST_ASSERT( TEST ) \
85 do { \
86 if( ! (TEST) ) \
87 { \
SimonB31a6c492016-05-02 21:32:44 +010088 test_fail( #TEST, __LINE__, __FILE__ ); \
SimonB0269dad2016-02-17 23:34:30 +000089 goto exit; \
90 } \
91 } while( 0 )
92
Rich Evans4c091142015-02-02 12:04:10 +000093#define assert(a) if( !( a ) ) \
94{ \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020095 mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
Rich Evans4c091142015-02-02 12:04:10 +000096 __FILE__, __LINE__, #a ); \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020097 mbedtls_exit( 1 ); \
Rich Evans4c091142015-02-02 12:04:10 +000098}
99
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000100/*
101 * 32-bit integer manipulation macros (big endian)
102 */
Paul Bakker5c2364c2012-10-01 14:41:15 +0000103#ifndef GET_UINT32_BE
104#define GET_UINT32_BE(n,b,i) \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000105{ \
Paul Bakker5c2364c2012-10-01 14:41:15 +0000106 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
107 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
108 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
109 | ( (uint32_t) (b)[(i) + 3] ); \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000110}
111#endif
112
Paul Bakker5c2364c2012-10-01 14:41:15 +0000113#ifndef PUT_UINT32_BE
114#define PUT_UINT32_BE(n,b,i) \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000115{ \
116 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
117 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
118 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
119 (b)[(i) + 3] = (unsigned char) ( (n) ); \
120}
121#endif
122
SimonB0269dad2016-02-17 23:34:30 +0000123
124/*----------------------------------------------------------------------------*/
SimonB8ca7bc42016-04-17 23:24:50 +0100125/* Global variables */
126
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100127
128static struct
129{
130 int failed;
131 const char *test;
132 const char *filename;
133 int line_no;
134}
135test_info;
SimonB8ca7bc42016-04-17 23:24:50 +0100136
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400137#if defined(MBEDTLS_PLATFORM_C)
Andrzej Kurek1152fa82018-04-13 05:15:17 -0400138mbedtls_platform_context platform_ctx;
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400139#endif
SimonB8ca7bc42016-04-17 23:24:50 +0100140
141/*----------------------------------------------------------------------------*/
Hanno Becker47deec42017-07-24 12:27:09 +0100142/* Helper flags for complex dependencies */
143
144/* Indicates whether we expect mbedtls_entropy_init
145 * to initialize some strong entropy source. */
146#if defined(MBEDTLS_TEST_NULL_ENTROPY) || \
147 ( !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
148 ( !defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \
149 defined(MBEDTLS_HAVEGE_C) || \
150 defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
151 defined(ENTROPY_NV_SEED) ) )
Hanno Beckerd4a872e2017-09-07 08:09:33 +0100152#define ENTROPY_HAVE_STRONG
Hanno Becker47deec42017-07-24 12:27:09 +0100153#endif
154
155
156/*----------------------------------------------------------------------------*/
SimonB0269dad2016-02-17 23:34:30 +0000157/* Helper Functions */
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400158static int platform_setup()
159{
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400160 int ret = 0;
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400161#if defined(MBEDTLS_PLATFORM_C)
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400162 ret = mbedtls_platform_setup( &platform_ctx );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400163#endif /* MBEDTLS_PLATFORM_C */
Andrzej Kurekf13ca952018-04-18 04:14:31 -0400164 return( ret );
Andrzej Kurek32a675f2018-04-13 06:16:04 -0400165}
166
167static void platform_teardown()
168{
169#if defined(MBEDTLS_PLATFORM_C)
170 mbedtls_platform_teardown( &platform_ctx );
171#endif /* MBEDTLS_PLATFORM_C */
172}
SimonB0269dad2016-02-17 23:34:30 +0000173
Janos Follath8ca53b52016-10-05 10:57:49 +0100174#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
175static int redirect_output( FILE** out_stream, const char* path )
176{
177 int stdout_fd = dup( fileno( *out_stream ) );
178
179 if( stdout_fd == -1 )
180 {
181 return -1;
182 }
183
184 fflush( *out_stream );
185 fclose( *out_stream );
186 *out_stream = fopen( path, "w" );
187
188 if( *out_stream == NULL )
189 {
190 return -1;
191 }
192
193 return stdout_fd;
194}
195
196static int restore_output( FILE** out_stream, int old_fd )
197{
198 fflush( *out_stream );
199 fclose( *out_stream );
200
201 *out_stream = fdopen( old_fd, "w" );
202 if( *out_stream == NULL )
203 {
204 return -1;
205 }
206
207 return 0;
208}
Simon Butchere0192962016-10-12 23:07:30 +0100209
Janos Follathe709f7c2016-10-13 11:26:29 +0100210static void close_output( FILE* out_stream )
Simon Butchere0192962016-10-12 23:07:30 +0100211{
Janos Follathe709f7c2016-10-13 11:26:29 +0100212 fclose( out_stream );
Simon Butchere0192962016-10-12 23:07:30 +0100213}
Janos Follath8ca53b52016-10-05 10:57:49 +0100214#endif /* __unix__ || __APPLE__ __MACH__ */
215
Rich Evans4c091142015-02-02 12:04:10 +0000216static int unhexify( unsigned char *obuf, const char *ibuf )
Paul Bakker367dae42009-06-28 21:50:27 +0000217{
218 unsigned char c, c2;
Rich Evans4c091142015-02-02 12:04:10 +0000219 int len = strlen( ibuf ) / 2;
SimonB0269dad2016-02-17 23:34:30 +0000220 assert( strlen( ibuf ) % 2 == 0 ); /* must be even number of bytes */
Paul Bakker367dae42009-06-28 21:50:27 +0000221
Rich Evans4c091142015-02-02 12:04:10 +0000222 while( *ibuf != 0 )
Paul Bakker367dae42009-06-28 21:50:27 +0000223 {
224 c = *ibuf++;
225 if( c >= '0' && c <= '9' )
226 c -= '0';
227 else if( c >= 'a' && c <= 'f' )
228 c -= 'a' - 10;
229 else if( c >= 'A' && c <= 'F' )
230 c -= 'A' - 10;
231 else
232 assert( 0 );
233
234 c2 = *ibuf++;
235 if( c2 >= '0' && c2 <= '9' )
236 c2 -= '0';
237 else if( c2 >= 'a' && c2 <= 'f' )
238 c2 -= 'a' - 10;
239 else if( c2 >= 'A' && c2 <= 'F' )
240 c2 -= 'A' - 10;
241 else
242 assert( 0 );
243
244 *obuf++ = ( c << 4 ) | c2;
245 }
246
247 return len;
248}
249
Rich Evans42914452015-02-02 12:09:25 +0000250static void hexify( unsigned char *obuf, const unsigned char *ibuf, int len )
Paul Bakker367dae42009-06-28 21:50:27 +0000251{
252 unsigned char l, h;
253
Rich Evans42914452015-02-02 12:09:25 +0000254 while( len != 0 )
Paul Bakker367dae42009-06-28 21:50:27 +0000255 {
Rich Evans42914452015-02-02 12:09:25 +0000256 h = *ibuf / 16;
257 l = *ibuf % 16;
Paul Bakker367dae42009-06-28 21:50:27 +0000258
259 if( h < 10 )
260 *obuf++ = '0' + h;
261 else
262 *obuf++ = 'a' + h - 10;
263
264 if( l < 10 )
265 *obuf++ = '0' + l;
266 else
267 *obuf++ = 'a' + l - 10;
268
269 ++ibuf;
270 len--;
271 }
272}
Paul Bakker9dcc3222011-03-08 14:16:06 +0000273
274/**
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200275 * Allocate and zeroize a buffer.
276 *
277 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
278 *
279 * For convenience, dies if allocation fails.
280 */
281static unsigned char *zero_alloc( size_t len )
282{
283 void *p;
Rich Evans42914452015-02-02 12:09:25 +0000284 size_t actual_len = ( len != 0 ) ? len : 1;
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200285
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200286 p = mbedtls_calloc( 1, actual_len );
Paul Bakker4d0cfe82014-07-10 14:37:36 +0200287 assert( p != NULL );
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200288
289 memset( p, 0x00, actual_len );
290
291 return( p );
292}
293
294/**
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200295 * Allocate and fill a buffer from hex data.
296 *
297 * The buffer is sized exactly as needed. This allows to detect buffer
298 * overruns (including overreads) when running the test suite under valgrind.
299 *
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200300 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
301 *
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200302 * For convenience, dies if allocation fails.
303 */
304static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
305{
306 unsigned char *obuf;
307
Rich Evans42914452015-02-02 12:09:25 +0000308 *olen = strlen( ibuf ) / 2;
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200309
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200310 if( *olen == 0 )
311 return( zero_alloc( *olen ) );
312
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200313 obuf = mbedtls_calloc( 1, *olen );
Paul Bakker4d0cfe82014-07-10 14:37:36 +0200314 assert( obuf != NULL );
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200315
316 (void) unhexify( obuf, ibuf );
317
318 return( obuf );
319}
320
321/**
Paul Bakker9dcc3222011-03-08 14:16:06 +0000322 * This function just returns data from rand().
Paul Bakker997bbd12011-03-13 15:45:42 +0000323 * Although predictable and often similar on multiple
324 * runs, this does not result in identical random on
325 * each run. So do not use this if the results of a
326 * test depend on the random data that is generated.
Paul Bakker9dcc3222011-03-08 14:16:06 +0000327 *
328 * rng_state shall be NULL.
329 */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000330static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000331{
Paul Bakkerf96f7b62014-04-30 16:02:38 +0200332#if !defined(__OpenBSD__)
Paul Bakkera3d195c2011-11-27 21:07:34 +0000333 size_t i;
334
Paul Bakker9dcc3222011-03-08 14:16:06 +0000335 if( rng_state != NULL )
336 rng_state = NULL;
337
Paul Bakkera3d195c2011-11-27 21:07:34 +0000338 for( i = 0; i < len; ++i )
339 output[i] = rand();
Paul Bakkerf96f7b62014-04-30 16:02:38 +0200340#else
341 if( rng_state != NULL )
342 rng_state = NULL;
343
344 arc4random_buf( output, len );
345#endif /* !OpenBSD */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000346
347 return( 0 );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000348}
349
350/**
351 * This function only returns zeros
352 *
353 * rng_state shall be NULL.
354 */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000355static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000356{
357 if( rng_state != NULL )
358 rng_state = NULL;
359
Paul Bakkera3d195c2011-11-27 21:07:34 +0000360 memset( output, 0, len );
361
Paul Bakker9dcc3222011-03-08 14:16:06 +0000362 return( 0 );
363}
364
365typedef struct
366{
367 unsigned char *buf;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000368 size_t length;
Paul Bakker997bbd12011-03-13 15:45:42 +0000369} rnd_buf_info;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000370
371/**
372 * This function returns random based on a buffer it receives.
373 *
Paul Bakker997bbd12011-03-13 15:45:42 +0000374 * rng_state shall be a pointer to a rnd_buf_info structure.
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100375 *
Paul Bakker997bbd12011-03-13 15:45:42 +0000376 * The number of bytes released from the buffer on each call to
377 * the random function is specified by per_call. (Can be between
378 * 1 and 4)
Paul Bakker9dcc3222011-03-08 14:16:06 +0000379 *
380 * After the buffer is empty it will return rand();
381 */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000382static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000383{
Paul Bakker997bbd12011-03-13 15:45:42 +0000384 rnd_buf_info *info = (rnd_buf_info *) rng_state;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000385 size_t use_len;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000386
387 if( rng_state == NULL )
Paul Bakkera3d195c2011-11-27 21:07:34 +0000388 return( rnd_std_rand( NULL, output, len ) );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000389
Paul Bakkera3d195c2011-11-27 21:07:34 +0000390 use_len = len;
391 if( len > info->length )
392 use_len = info->length;
Paul Bakker997bbd12011-03-13 15:45:42 +0000393
Paul Bakkera3d195c2011-11-27 21:07:34 +0000394 if( use_len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000395 {
Paul Bakkera3d195c2011-11-27 21:07:34 +0000396 memcpy( output, info->buf, use_len );
397 info->buf += use_len;
398 info->length -= use_len;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000399 }
400
Paul Bakkera3d195c2011-11-27 21:07:34 +0000401 if( len - use_len > 0 )
402 return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
403
404 return( 0 );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000405}
Paul Bakker997bbd12011-03-13 15:45:42 +0000406
407/**
408 * Info structure for the pseudo random function
409 *
410 * Key should be set at the start to a test-unique value.
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000411 * Do not forget endianness!
Paul Bakker997bbd12011-03-13 15:45:42 +0000412 * State( v0, v1 ) should be set to zero.
413 */
414typedef struct
415{
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000416 uint32_t key[16];
Paul Bakker997bbd12011-03-13 15:45:42 +0000417 uint32_t v0, v1;
418} rnd_pseudo_info;
419
420/**
421 * This function returns random based on a pseudo random function.
422 * This means the results should be identical on all systems.
423 * Pseudo random is based on the XTEA encryption algorithm to
424 * generate pseudorandom.
425 *
426 * rng_state shall be a pointer to a rnd_pseudo_info structure.
427 */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000428static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker997bbd12011-03-13 15:45:42 +0000429{
430 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000431 uint32_t i, *k, sum, delta=0x9E3779B9;
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100432 unsigned char result[4], *out = output;
Paul Bakker997bbd12011-03-13 15:45:42 +0000433
434 if( rng_state == NULL )
Paul Bakkera3d195c2011-11-27 21:07:34 +0000435 return( rnd_std_rand( NULL, output, len ) );
Paul Bakker997bbd12011-03-13 15:45:42 +0000436
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000437 k = info->key;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000438
439 while( len > 0 )
Paul Bakker997bbd12011-03-13 15:45:42 +0000440 {
Paul Bakker40dd5302012-05-15 15:02:38 +0000441 size_t use_len = ( len > 4 ) ? 4 : len;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000442 sum = 0;
443
Paul Bakkera3d195c2011-11-27 21:07:34 +0000444 for( i = 0; i < 32; i++ )
445 {
Rich Evans42914452015-02-02 12:09:25 +0000446 info->v0 += ( ( ( info->v1 << 4 ) ^ ( info->v1 >> 5 ) )
447 + info->v1 ) ^ ( sum + k[sum & 3] );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000448 sum += delta;
Rich Evans42914452015-02-02 12:09:25 +0000449 info->v1 += ( ( ( info->v0 << 4 ) ^ ( info->v0 >> 5 ) )
450 + info->v0 ) ^ ( sum + k[( sum>>11 ) & 3] );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000451 }
452
Paul Bakker5c2364c2012-10-01 14:41:15 +0000453 PUT_UINT32_BE( info->v0, result, 0 );
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100454 memcpy( out, result, use_len );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000455 len -= use_len;
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100456 out += 4;
Paul Bakker997bbd12011-03-13 15:45:42 +0000457 }
458
Paul Bakkera3d195c2011-11-27 21:07:34 +0000459 return( 0 );
Paul Bakker997bbd12011-03-13 15:45:42 +0000460}
SimonB0269dad2016-02-17 23:34:30 +0000461
Simon Butcherd96924d2016-05-06 00:22:18 +0100462static void test_fail( const char *test, int line_no, const char* filename )
SimonB0269dad2016-02-17 23:34:30 +0000463{
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100464 test_info.failed = 1;
465 test_info.test = test;
466 test_info.line_no = line_no;
467 test_info.filename = filename;
SimonB0269dad2016-02-17 23:34:30 +0000468}
Azim Khan3499a9e2017-05-30 00:06:49 +0100469
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100470int hexcmp( uint8_t * a, uint8_t * b, uint32_t a_len, uint32_t b_len )
Azim Khan3499a9e2017-05-30 00:06:49 +0100471{
472 int ret = 0;
473 uint32_t i = 0;
474
475 if ( a_len != b_len )
Mohammad Azim Khand2d01122018-07-18 17:48:37 +0100476 return( -1 );
Azim Khan3499a9e2017-05-30 00:06:49 +0100477
478 for( i = 0; i < a_len; i++ )
479 {
480 if ( a[i] != b[i] )
481 {
482 ret = -1;
483 break;
484 }
485 }
486 return ret;
487}
488