blob: 2a6d34c014af83f786cf79c33daf277f62835c25 [file] [log] [blame]
SimonB15942102016-04-25 21:34:49 +01001#line 1 "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>
28typedef UINT32 uint32_t;
Nicholas Wilson733676b2015-11-14 13:09:01 +000029#define strncasecmp _strnicmp
30#define strcasecmp _stricmp
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000031#else
Manuel Pégourié-Gonnard93866642015-06-22 19:21:23 +020032#include <stdint.h>
Paul Bakkerb3dcbc12011-03-13 16:57:25 +000033#endif
34
Paul Bakker19343182013-08-16 13:31:10 +020035#include <string.h>
36
Janos Follath8ca53b52016-10-05 10:57:49 +010037#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
38#include <unistd.h>
39#endif
SimonB0269dad2016-02-17 23:34:30 +000040
Manuel Pégourié-Gonnard40597ce2020-07-28 10:53:06 +020041#if defined(MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN)
42#include <sanitizer/msan_interface.h>
43
44/* Use macros to avoid messing up with origin tracking */
45#define TEST_CF_SECRET __msan_allocated_memory
46// void __msan_allocated_memory(const volatile void* data, size_t size);
47#define TEST_CF_PUBLIC __msan_unpoison
48// void __msan_unpoison(const volatile void *a, size_t size);
49
50#else /* MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN */
51
52#define TEST_CF_SECRET(ptr, size)
53#define TEST_CF_PUBLIC(ptr, size)
54
55#endif /* MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN */
56
SimonB0269dad2016-02-17 23:34:30 +000057/*----------------------------------------------------------------------------*/
SimonB8ca7bc42016-04-17 23:24:50 +010058/* Constants */
SimonB0269dad2016-02-17 23:34:30 +000059
SimonB8ca7bc42016-04-17 23:24:50 +010060#define DEPENDENCY_SUPPORTED 0
61#define DEPENDENCY_NOT_SUPPORTED 1
62
63#define KEY_VALUE_MAPPING_FOUND 0
64#define KEY_VALUE_MAPPING_NOT_FOUND -1
65
66#define DISPATCH_TEST_SUCCESS 0
67#define DISPATCH_TEST_FN_NOT_FOUND 1
68#define DISPATCH_INVALID_TEST_DATA 2
69#define DISPATCH_UNSUPPORTED_SUITE 3
SimonB0269dad2016-02-17 23:34:30 +000070
71
72/*----------------------------------------------------------------------------*/
73/* Macros */
74
75#define TEST_ASSERT( TEST ) \
76 do { \
77 if( ! (TEST) ) \
78 { \
SimonB31a6c492016-05-02 21:32:44 +010079 test_fail( #TEST, __LINE__, __FILE__ ); \
SimonB0269dad2016-02-17 23:34:30 +000080 goto exit; \
81 } \
82 } while( 0 )
83
Rich Evans4c091142015-02-02 12:04:10 +000084#define assert(a) if( !( a ) ) \
85{ \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020086 mbedtls_fprintf( stderr, "Assertion Failed at %s:%d - %s\n", \
Rich Evans4c091142015-02-02 12:04:10 +000087 __FILE__, __LINE__, #a ); \
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088 mbedtls_exit( 1 ); \
Rich Evans4c091142015-02-02 12:04:10 +000089}
90
Ronald Croneb5d0e92020-04-06 10:34:22 +020091#if defined(__GNUC__)
92/* Test if arg and &(arg)[0] have the same type. This is true if arg is
93 * an array but not if it's a pointer. */
94#define IS_ARRAY_NOT_POINTER( arg ) \
95 ( ! __builtin_types_compatible_p( __typeof__( arg ), \
96 __typeof__( &( arg )[0] ) ) )
97#else
98/* On platforms where we don't know how to implement this check,
99 * omit it. Oh well, a non-portable check is better than nothing. */
100#define IS_ARRAY_NOT_POINTER( arg ) 1
101#endif
102
103/* A compile-time constant with the value 0. If `const_expr` is not a
104 * compile-time constant with a nonzero value, cause a compile-time error. */
105#define STATIC_ASSERT_EXPR( const_expr ) \
106 ( 0 && sizeof( struct { int STATIC_ASSERT : 1 - 2 * ! ( const_expr ); } ) )
107/* Return the scalar value `value` (possibly promoted). This is a compile-time
108 * constant if `value` is. `condition` must be a compile-time constant.
109 * If `condition` is false, arrange to cause a compile-time error. */
110#define STATIC_ASSERT_THEN_RETURN( condition, value ) \
111 ( STATIC_ASSERT_EXPR( condition ) ? 0 : ( value ) )
112
113#define ARRAY_LENGTH_UNSAFE( array ) \
114 ( sizeof( array ) / sizeof( *( array ) ) )
115/** Return the number of elements of a static or stack array.
116 *
117 * \param array A value of array (not pointer) type.
118 *
119 * \return The number of elements of the array.
120 */
121#define ARRAY_LENGTH( array ) \
122 ( STATIC_ASSERT_THEN_RETURN( IS_ARRAY_NOT_POINTER( array ), \
123 ARRAY_LENGTH_UNSAFE( array ) ) )
124
125
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000126/*
127 * 32-bit integer manipulation macros (big endian)
128 */
Paul Bakker5c2364c2012-10-01 14:41:15 +0000129#ifndef GET_UINT32_BE
130#define GET_UINT32_BE(n,b,i) \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000131{ \
Paul Bakker5c2364c2012-10-01 14:41:15 +0000132 (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
133 | ( (uint32_t) (b)[(i) + 1] << 16 ) \
134 | ( (uint32_t) (b)[(i) + 2] << 8 ) \
135 | ( (uint32_t) (b)[(i) + 3] ); \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000136}
137#endif
138
Paul Bakker5c2364c2012-10-01 14:41:15 +0000139#ifndef PUT_UINT32_BE
140#define PUT_UINT32_BE(n,b,i) \
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000141{ \
142 (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
143 (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
144 (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
145 (b)[(i) + 3] = (unsigned char) ( (n) ); \
146}
147#endif
148
SimonB0269dad2016-02-17 23:34:30 +0000149
150/*----------------------------------------------------------------------------*/
SimonB8ca7bc42016-04-17 23:24:50 +0100151/* Global variables */
152
Andres Amaya Garcia3f50f512017-10-01 16:42:29 +0100153
154static struct
155{
156 int failed;
157 const char *test;
158 const char *filename;
159 int line_no;
160}
161test_info;
SimonB8ca7bc42016-04-17 23:24:50 +0100162
163
164/*----------------------------------------------------------------------------*/
Hanno Becker47deec42017-07-24 12:27:09 +0100165/* Helper flags for complex dependencies */
166
167/* Indicates whether we expect mbedtls_entropy_init
168 * to initialize some strong entropy source. */
169#if defined(MBEDTLS_TEST_NULL_ENTROPY) || \
170 ( !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \
171 ( !defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \
172 defined(MBEDTLS_HAVEGE_C) || \
173 defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \
174 defined(ENTROPY_NV_SEED) ) )
Hanno Beckerd4a872e2017-09-07 08:09:33 +0100175#define ENTROPY_HAVE_STRONG
Hanno Becker47deec42017-07-24 12:27:09 +0100176#endif
177
178
179/*----------------------------------------------------------------------------*/
SimonB0269dad2016-02-17 23:34:30 +0000180/* Helper Functions */
181
Simon Butcher638dceb2018-10-03 16:17:41 +0100182void test_fail( const char *test, int line_no, const char* filename )
183{
184 test_info.failed = 1;
185 test_info.test = test;
186 test_info.line_no = line_no;
187 test_info.filename = filename;
188}
189
Janos Follath8ca53b52016-10-05 10:57:49 +0100190#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
191static int redirect_output( FILE** out_stream, const char* path )
192{
193 int stdout_fd = dup( fileno( *out_stream ) );
194
195 if( stdout_fd == -1 )
196 {
197 return -1;
198 }
199
200 fflush( *out_stream );
201 fclose( *out_stream );
202 *out_stream = fopen( path, "w" );
203
204 if( *out_stream == NULL )
205 {
Andres Amaya Garcia97a184b2018-11-26 21:23:28 +0000206 close( stdout_fd );
Janos Follath8ca53b52016-10-05 10:57:49 +0100207 return -1;
208 }
209
210 return stdout_fd;
211}
212
213static int restore_output( FILE** out_stream, int old_fd )
214{
215 fflush( *out_stream );
216 fclose( *out_stream );
217
218 *out_stream = fdopen( old_fd, "w" );
219 if( *out_stream == NULL )
220 {
221 return -1;
222 }
223
224 return 0;
225}
Simon Butchere0192962016-10-12 23:07:30 +0100226
Janos Follathe709f7c2016-10-13 11:26:29 +0100227static void close_output( FILE* out_stream )
Simon Butchere0192962016-10-12 23:07:30 +0100228{
Janos Follathe709f7c2016-10-13 11:26:29 +0100229 fclose( out_stream );
Simon Butchere0192962016-10-12 23:07:30 +0100230}
Janos Follath8ca53b52016-10-05 10:57:49 +0100231#endif /* __unix__ || __APPLE__ __MACH__ */
232
Simon Butcher638dceb2018-10-03 16:17:41 +0100233int unhexify( unsigned char *obuf, const char *ibuf )
Paul Bakker367dae42009-06-28 21:50:27 +0000234{
235 unsigned char c, c2;
Rich Evans4c091142015-02-02 12:04:10 +0000236 int len = strlen( ibuf ) / 2;
SimonB0269dad2016-02-17 23:34:30 +0000237 assert( strlen( ibuf ) % 2 == 0 ); /* must be even number of bytes */
Paul Bakker367dae42009-06-28 21:50:27 +0000238
Rich Evans4c091142015-02-02 12:04:10 +0000239 while( *ibuf != 0 )
Paul Bakker367dae42009-06-28 21:50:27 +0000240 {
241 c = *ibuf++;
242 if( c >= '0' && c <= '9' )
243 c -= '0';
244 else if( c >= 'a' && c <= 'f' )
245 c -= 'a' - 10;
246 else if( c >= 'A' && c <= 'F' )
247 c -= 'A' - 10;
248 else
249 assert( 0 );
250
251 c2 = *ibuf++;
252 if( c2 >= '0' && c2 <= '9' )
253 c2 -= '0';
254 else if( c2 >= 'a' && c2 <= 'f' )
255 c2 -= 'a' - 10;
256 else if( c2 >= 'A' && c2 <= 'F' )
257 c2 -= 'A' - 10;
258 else
259 assert( 0 );
260
261 *obuf++ = ( c << 4 ) | c2;
262 }
263
264 return len;
265}
266
Simon Butcher638dceb2018-10-03 16:17:41 +0100267void hexify( unsigned char *obuf, const unsigned char *ibuf, int len )
Paul Bakker367dae42009-06-28 21:50:27 +0000268{
269 unsigned char l, h;
270
Rich Evans42914452015-02-02 12:09:25 +0000271 while( len != 0 )
Paul Bakker367dae42009-06-28 21:50:27 +0000272 {
Rich Evans42914452015-02-02 12:09:25 +0000273 h = *ibuf / 16;
274 l = *ibuf % 16;
Paul Bakker367dae42009-06-28 21:50:27 +0000275
276 if( h < 10 )
277 *obuf++ = '0' + h;
278 else
279 *obuf++ = 'a' + h - 10;
280
281 if( l < 10 )
282 *obuf++ = '0' + l;
283 else
284 *obuf++ = 'a' + l - 10;
285
286 ++ibuf;
287 len--;
288 }
289}
Paul Bakker9dcc3222011-03-08 14:16:06 +0000290
291/**
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200292 * Allocate and zeroize a buffer.
293 *
294 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
295 *
296 * For convenience, dies if allocation fails.
297 */
298static unsigned char *zero_alloc( size_t len )
299{
300 void *p;
Rich Evans42914452015-02-02 12:09:25 +0000301 size_t actual_len = ( len != 0 ) ? len : 1;
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200302
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200303 p = mbedtls_calloc( 1, actual_len );
Paul Bakker4d0cfe82014-07-10 14:37:36 +0200304 assert( p != NULL );
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200305
306 memset( p, 0x00, actual_len );
307
308 return( p );
309}
310
311/**
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200312 * Allocate and fill a buffer from hex data.
313 *
314 * The buffer is sized exactly as needed. This allows to detect buffer
315 * overruns (including overreads) when running the test suite under valgrind.
316 *
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200317 * If the size if zero, a pointer to a zeroized 1-byte buffer is returned.
318 *
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200319 * For convenience, dies if allocation fails.
320 */
Simon Butcher638dceb2018-10-03 16:17:41 +0100321unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200322{
323 unsigned char *obuf;
324
Rich Evans42914452015-02-02 12:09:25 +0000325 *olen = strlen( ibuf ) / 2;
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200326
Manuel Pégourié-Gonnard0dc5e0d2014-06-13 21:09:26 +0200327 if( *olen == 0 )
328 return( zero_alloc( *olen ) );
329
Manuel Pégourié-Gonnard7551cb92015-05-26 16:04:06 +0200330 obuf = mbedtls_calloc( 1, *olen );
Paul Bakker4d0cfe82014-07-10 14:37:36 +0200331 assert( obuf != NULL );
Manuel Pégourié-Gonnard3d49b9d2014-06-06 14:48:09 +0200332
333 (void) unhexify( obuf, ibuf );
334
335 return( obuf );
336}
337
338/**
Paul Bakker9dcc3222011-03-08 14:16:06 +0000339 * This function just returns data from rand().
Paul Bakker997bbd12011-03-13 15:45:42 +0000340 * Although predictable and often similar on multiple
341 * runs, this does not result in identical random on
342 * each run. So do not use this if the results of a
343 * test depend on the random data that is generated.
Paul Bakker9dcc3222011-03-08 14:16:06 +0000344 *
345 * rng_state shall be NULL.
346 */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000347static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000348{
Paul Bakkerf96f7b62014-04-30 16:02:38 +0200349#if !defined(__OpenBSD__)
Paul Bakkera3d195c2011-11-27 21:07:34 +0000350 size_t i;
351
Paul Bakker9dcc3222011-03-08 14:16:06 +0000352 if( rng_state != NULL )
353 rng_state = NULL;
354
Paul Bakkera3d195c2011-11-27 21:07:34 +0000355 for( i = 0; i < len; ++i )
356 output[i] = rand();
Paul Bakkerf96f7b62014-04-30 16:02:38 +0200357#else
358 if( rng_state != NULL )
359 rng_state = NULL;
360
361 arc4random_buf( output, len );
362#endif /* !OpenBSD */
Paul Bakkera3d195c2011-11-27 21:07:34 +0000363
364 return( 0 );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000365}
366
367/**
368 * This function only returns zeros
369 *
370 * rng_state shall be NULL.
371 */
Simon Butcher638dceb2018-10-03 16:17:41 +0100372int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000373{
374 if( rng_state != NULL )
375 rng_state = NULL;
376
Paul Bakkera3d195c2011-11-27 21:07:34 +0000377 memset( output, 0, len );
378
Paul Bakker9dcc3222011-03-08 14:16:06 +0000379 return( 0 );
380}
381
382typedef struct
383{
384 unsigned char *buf;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000385 size_t length;
Paul Bakker997bbd12011-03-13 15:45:42 +0000386} rnd_buf_info;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000387
388/**
389 * This function returns random based on a buffer it receives.
390 *
Paul Bakker997bbd12011-03-13 15:45:42 +0000391 * rng_state shall be a pointer to a rnd_buf_info structure.
Manuel Pégourié-Gonnarde670f902015-10-30 09:23:19 +0100392 *
Paul Bakker997bbd12011-03-13 15:45:42 +0000393 * The number of bytes released from the buffer on each call to
394 * the random function is specified by per_call. (Can be between
395 * 1 and 4)
Paul Bakker9dcc3222011-03-08 14:16:06 +0000396 *
397 * After the buffer is empty it will return rand();
398 */
Simon Butcher638dceb2018-10-03 16:17:41 +0100399int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000400{
Paul Bakker997bbd12011-03-13 15:45:42 +0000401 rnd_buf_info *info = (rnd_buf_info *) rng_state;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000402 size_t use_len;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000403
404 if( rng_state == NULL )
Paul Bakkera3d195c2011-11-27 21:07:34 +0000405 return( rnd_std_rand( NULL, output, len ) );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000406
Paul Bakkera3d195c2011-11-27 21:07:34 +0000407 use_len = len;
408 if( len > info->length )
409 use_len = info->length;
Paul Bakker997bbd12011-03-13 15:45:42 +0000410
Paul Bakkera3d195c2011-11-27 21:07:34 +0000411 if( use_len )
Paul Bakker9dcc3222011-03-08 14:16:06 +0000412 {
Paul Bakkera3d195c2011-11-27 21:07:34 +0000413 memcpy( output, info->buf, use_len );
414 info->buf += use_len;
415 info->length -= use_len;
Paul Bakker9dcc3222011-03-08 14:16:06 +0000416 }
417
Paul Bakkera3d195c2011-11-27 21:07:34 +0000418 if( len - use_len > 0 )
419 return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
420
421 return( 0 );
Paul Bakker9dcc3222011-03-08 14:16:06 +0000422}
Paul Bakker997bbd12011-03-13 15:45:42 +0000423
424/**
425 * Info structure for the pseudo random function
426 *
427 * Key should be set at the start to a test-unique value.
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000428 * Do not forget endianness!
Paul Bakker997bbd12011-03-13 15:45:42 +0000429 * State( v0, v1 ) should be set to zero.
430 */
431typedef struct
432{
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000433 uint32_t key[16];
Paul Bakker997bbd12011-03-13 15:45:42 +0000434 uint32_t v0, v1;
435} rnd_pseudo_info;
436
437/**
438 * This function returns random based on a pseudo random function.
439 * This means the results should be identical on all systems.
440 * Pseudo random is based on the XTEA encryption algorithm to
441 * generate pseudorandom.
442 *
443 * rng_state shall be a pointer to a rnd_pseudo_info structure.
444 */
Simon Butcher638dceb2018-10-03 16:17:41 +0100445int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker997bbd12011-03-13 15:45:42 +0000446{
447 rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000448 uint32_t i, *k, sum, delta=0x9E3779B9;
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100449 unsigned char result[4], *out = output;
Paul Bakker997bbd12011-03-13 15:45:42 +0000450
451 if( rng_state == NULL )
Paul Bakkera3d195c2011-11-27 21:07:34 +0000452 return( rnd_std_rand( NULL, output, len ) );
Paul Bakker997bbd12011-03-13 15:45:42 +0000453
Paul Bakkerb3dcbc12011-03-13 16:57:25 +0000454 k = info->key;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000455
456 while( len > 0 )
Paul Bakker997bbd12011-03-13 15:45:42 +0000457 {
Paul Bakker40dd5302012-05-15 15:02:38 +0000458 size_t use_len = ( len > 4 ) ? 4 : len;
Paul Bakkera3d195c2011-11-27 21:07:34 +0000459 sum = 0;
460
Paul Bakkera3d195c2011-11-27 21:07:34 +0000461 for( i = 0; i < 32; i++ )
462 {
Rich Evans42914452015-02-02 12:09:25 +0000463 info->v0 += ( ( ( info->v1 << 4 ) ^ ( info->v1 >> 5 ) )
464 + info->v1 ) ^ ( sum + k[sum & 3] );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000465 sum += delta;
Rich Evans42914452015-02-02 12:09:25 +0000466 info->v1 += ( ( ( info->v0 << 4 ) ^ ( info->v0 >> 5 ) )
467 + info->v0 ) ^ ( sum + k[( sum>>11 ) & 3] );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000468 }
469
Paul Bakker5c2364c2012-10-01 14:41:15 +0000470 PUT_UINT32_BE( info->v0, result, 0 );
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100471 memcpy( out, result, use_len );
Paul Bakkera3d195c2011-11-27 21:07:34 +0000472 len -= use_len;
Manuel Pégourié-Gonnard217a29c2014-01-03 11:59:09 +0100473 out += 4;
Paul Bakker997bbd12011-03-13 15:45:42 +0000474 }
475
Paul Bakkera3d195c2011-11-27 21:07:34 +0000476 return( 0 );
Paul Bakker997bbd12011-03-13 15:45:42 +0000477}
SimonB0269dad2016-02-17 23:34:30 +0000478