PolarSSL v1.3.9
test_suite_xtea.c
Go to the documentation of this file.
1 #if !defined(POLARSSL_CONFIG_FILE)
2 #include <polarssl/config.h>
3 #else
4 #include POLARSSL_CONFIG_FILE
5 #endif
6 
7 #ifdef POLARSSL_XTEA_C
8 
9 #include <polarssl/xtea.h>
10 #endif /* POLARSSL_XTEA_C */
11 
12 
13 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
14 #include "polarssl/memory.h"
15 #endif
16 
17 #if defined(POLARSSL_PLATFORM_C)
18 #include "polarssl/platform.h"
19 #else
20 #define polarssl_malloc malloc
21 #define polarssl_free free
22 #endif
23 
24 #ifdef _MSC_VER
25 #include <basetsd.h>
26 typedef UINT32 uint32_t;
27 #else
28 #include <inttypes.h>
29 #endif
30 
31 #include <assert.h>
32 #include <stdlib.h>
33 #include <string.h>
34 
35 /*
36  * 32-bit integer manipulation macros (big endian)
37  */
38 #ifndef GET_UINT32_BE
39 #define GET_UINT32_BE(n,b,i) \
40 { \
41  (n) = ( (uint32_t) (b)[(i) ] << 24 ) \
42  | ( (uint32_t) (b)[(i) + 1] << 16 ) \
43  | ( (uint32_t) (b)[(i) + 2] << 8 ) \
44  | ( (uint32_t) (b)[(i) + 3] ); \
45 }
46 #endif
47 
48 #ifndef PUT_UINT32_BE
49 #define PUT_UINT32_BE(n,b,i) \
50 { \
51  (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
52  (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
53  (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
54  (b)[(i) + 3] = (unsigned char) ( (n) ); \
55 }
56 #endif
57 
58 static int unhexify(unsigned char *obuf, const char *ibuf)
59 {
60  unsigned char c, c2;
61  int len = strlen(ibuf) / 2;
62  assert(!(strlen(ibuf) %1)); // must be even number of bytes
63 
64  while (*ibuf != 0)
65  {
66  c = *ibuf++;
67  if( c >= '0' && c <= '9' )
68  c -= '0';
69  else if( c >= 'a' && c <= 'f' )
70  c -= 'a' - 10;
71  else if( c >= 'A' && c <= 'F' )
72  c -= 'A' - 10;
73  else
74  assert( 0 );
75 
76  c2 = *ibuf++;
77  if( c2 >= '0' && c2 <= '9' )
78  c2 -= '0';
79  else if( c2 >= 'a' && c2 <= 'f' )
80  c2 -= 'a' - 10;
81  else if( c2 >= 'A' && c2 <= 'F' )
82  c2 -= 'A' - 10;
83  else
84  assert( 0 );
85 
86  *obuf++ = ( c << 4 ) | c2;
87  }
88 
89  return len;
90 }
91 
92 static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
93 {
94  unsigned char l, h;
95 
96  while (len != 0)
97  {
98  h = (*ibuf) / 16;
99  l = (*ibuf) % 16;
100 
101  if( h < 10 )
102  *obuf++ = '0' + h;
103  else
104  *obuf++ = 'a' + h - 10;
105 
106  if( l < 10 )
107  *obuf++ = '0' + l;
108  else
109  *obuf++ = 'a' + l - 10;
110 
111  ++ibuf;
112  len--;
113  }
114 }
115 
123 static unsigned char *zero_alloc( size_t len )
124 {
125  void *p;
126  size_t actual_len = len != 0 ? len : 1;
127 
128  p = polarssl_malloc( actual_len );
129  assert( p != NULL );
130 
131  memset( p, 0x00, actual_len );
132 
133  return( p );
134 }
135 
146 static unsigned char *unhexify_alloc( const char *ibuf, size_t *olen )
147 {
148  unsigned char *obuf;
149 
150  *olen = strlen(ibuf) / 2;
151 
152  if( *olen == 0 )
153  return( zero_alloc( *olen ) );
154 
155  obuf = polarssl_malloc( *olen );
156  assert( obuf != NULL );
157 
158  (void) unhexify( obuf, ibuf );
159 
160  return( obuf );
161 }
162 
172 static int rnd_std_rand( void *rng_state, unsigned char *output, size_t len )
173 {
174 #if !defined(__OpenBSD__)
175  size_t i;
176 
177  if( rng_state != NULL )
178  rng_state = NULL;
179 
180  for( i = 0; i < len; ++i )
181  output[i] = rand();
182 #else
183  if( rng_state != NULL )
184  rng_state = NULL;
185 
186  arc4random_buf( output, len );
187 #endif /* !OpenBSD */
188 
189  return( 0 );
190 }
191 
197 static int rnd_zero_rand( void *rng_state, unsigned char *output, size_t len )
198 {
199  if( rng_state != NULL )
200  rng_state = NULL;
201 
202  memset( output, 0, len );
203 
204  return( 0 );
205 }
206 
207 typedef struct
208 {
209  unsigned char *buf;
210  size_t length;
211 } rnd_buf_info;
212 
224 static int rnd_buffer_rand( void *rng_state, unsigned char *output, size_t len )
225 {
226  rnd_buf_info *info = (rnd_buf_info *) rng_state;
227  size_t use_len;
228 
229  if( rng_state == NULL )
230  return( rnd_std_rand( NULL, output, len ) );
231 
232  use_len = len;
233  if( len > info->length )
234  use_len = info->length;
235 
236  if( use_len )
237  {
238  memcpy( output, info->buf, use_len );
239  info->buf += use_len;
240  info->length -= use_len;
241  }
242 
243  if( len - use_len > 0 )
244  return( rnd_std_rand( NULL, output + use_len, len - use_len ) );
245 
246  return( 0 );
247 }
248 
256 typedef struct
257 {
258  uint32_t key[16];
259  uint32_t v0, v1;
261 
270 static int rnd_pseudo_rand( void *rng_state, unsigned char *output, size_t len )
271 {
272  rnd_pseudo_info *info = (rnd_pseudo_info *) rng_state;
273  uint32_t i, *k, sum, delta=0x9E3779B9;
274  unsigned char result[4], *out = output;
275 
276  if( rng_state == NULL )
277  return( rnd_std_rand( NULL, output, len ) );
278 
279  k = info->key;
280 
281  while( len > 0 )
282  {
283  size_t use_len = ( len > 4 ) ? 4 : len;
284  sum = 0;
285 
286  for( i = 0; i < 32; i++ )
287  {
288  info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5)) + info->v1) ^ (sum + k[sum & 3]);
289  sum += delta;
290  info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5)) + info->v0) ^ (sum + k[(sum>>11) & 3]);
291  }
292 
293  PUT_UINT32_BE( info->v0, result, 0 );
294  memcpy( out, result, use_len );
295  len -= use_len;
296  out += 4;
297  }
298 
299  return( 0 );
300 }
301 
302 
303 #include <stdio.h>
304 #include <string.h>
305 
306 #if defined(POLARSSL_PLATFORM_C)
307 #include "polarssl/platform.h"
308 #else
309 #define polarssl_printf printf
310 #define polarssl_malloc malloc
311 #define polarssl_free free
312 #endif
313 
314 static int test_errors = 0;
315 
316 #ifdef POLARSSL_XTEA_C
317 
318 #define TEST_SUITE_ACTIVE
319 
320 static int test_assert( int correct, const char *test )
321 {
322  if( correct )
323  return( 0 );
324 
325  test_errors++;
326  if( test_errors == 1 )
327  printf( "FAILED\n" );
328  printf( " %s\n", test );
329 
330  return( 1 );
331 }
332 
333 #define TEST_ASSERT( TEST ) \
334  do { test_assert( (TEST) ? 1 : 0, #TEST ); \
335  if( test_errors) goto exit; \
336  } while (0)
337 
338 int verify_string( char **str )
339 {
340  if( (*str)[0] != '"' ||
341  (*str)[strlen( *str ) - 1] != '"' )
342  {
343  printf( "Expected string (with \"\") for parameter and got: %s\n", *str );
344  return( -1 );
345  }
346 
347  (*str)++;
348  (*str)[strlen( *str ) - 1] = '\0';
349 
350  return( 0 );
351 }
352 
353 int verify_int( char *str, int *value )
354 {
355  size_t i;
356  int minus = 0;
357  int digits = 1;
358  int hex = 0;
359 
360  for( i = 0; i < strlen( str ); i++ )
361  {
362  if( i == 0 && str[i] == '-' )
363  {
364  minus = 1;
365  continue;
366  }
367 
368  if( ( ( minus && i == 2 ) || ( !minus && i == 1 ) ) &&
369  str[i - 1] == '0' && str[i] == 'x' )
370  {
371  hex = 1;
372  continue;
373  }
374 
375  if( ! ( ( str[i] >= '0' && str[i] <= '9' ) ||
376  ( hex && ( ( str[i] >= 'a' && str[i] <= 'f' ) ||
377  ( str[i] >= 'A' && str[i] <= 'F' ) ) ) ) )
378  {
379  digits = 0;
380  break;
381  }
382  }
383 
384  if( digits )
385  {
386  if( hex )
387  *value = strtol( str, NULL, 16 );
388  else
389  *value = strtol( str, NULL, 10 );
390 
391  return( 0 );
392  }
393 
394 
395 
396  printf( "Expected integer for parameter and got: %s\n", str );
397  return( -1 );
398 }
399 
400 void test_suite_xtea_encrypt_ecb( char *hex_key_string, char *hex_src_string,
401  char *hex_dst_string )
402 {
403  unsigned char key_str[100];
404  unsigned char src_str[100];
405  unsigned char dst_str[100];
406  unsigned char output[100];
407  xtea_context ctx;
408 
409  memset(key_str, 0x00, 100);
410  memset(src_str, 0x00, 100);
411  memset(dst_str, 0x00, 100);
412  memset(output, 0x00, 100);
413 
414  unhexify( key_str, hex_key_string );
415  unhexify( src_str, hex_src_string );
416 
417  xtea_setup( &ctx, key_str );
418  TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_ENCRYPT, src_str, output ) == 0 );
419  hexify( dst_str, output, 8 );
420 
421  TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
422 
423 exit:
424  return;
425 }
426 
427 void test_suite_xtea_decrypt_ecb( char *hex_key_string, char *hex_src_string,
428  char *hex_dst_string )
429 {
430  unsigned char key_str[100];
431  unsigned char src_str[100];
432  unsigned char dst_str[100];
433  unsigned char output[100];
434  xtea_context ctx;
435 
436  memset(key_str, 0x00, 100);
437  memset(src_str, 0x00, 100);
438  memset(dst_str, 0x00, 100);
439  memset(output, 0x00, 100);
440 
441  unhexify( key_str, hex_key_string );
442  unhexify( src_str, hex_src_string );
443 
444  xtea_setup( &ctx, key_str );
445  TEST_ASSERT( xtea_crypt_ecb( &ctx, XTEA_DECRYPT, src_str, output ) == 0 );
446  hexify( dst_str, output, 8 );
447 
448  TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
449 
450 exit:
451  return;
452 }
453 
454 void test_suite_xtea_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
455  char *hex_src_string, char *hex_dst_string )
456 {
457  unsigned char key_str[100];
458  unsigned char src_str[100];
459  unsigned char dst_str[100];
460  unsigned char iv_str[100];
461  unsigned char output[100];
462  size_t len;
463  xtea_context ctx;
464 
465  memset(key_str, 0x00, 100);
466  memset(src_str, 0x00, 100);
467  memset(dst_str, 0x00, 100);
468  memset(iv_str, 0x00, 100);
469  memset(output, 0x00, 100);
470 
471  unhexify( key_str, hex_key_string );
472  unhexify( iv_str, hex_iv_string );
473  len = unhexify( src_str, hex_src_string );
474 
475  xtea_setup( &ctx, key_str );
476  TEST_ASSERT( xtea_crypt_cbc( &ctx, XTEA_ENCRYPT, len, iv_str,
477  src_str, output ) == 0 );
478  hexify( dst_str, output, len );
479 
480  TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
481 
482 exit:
483  return;
484 }
485 
486 void test_suite_xtea_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
487  char *hex_src_string, char *hex_dst_string )
488 {
489  unsigned char key_str[100];
490  unsigned char src_str[100];
491  unsigned char dst_str[100];
492  unsigned char iv_str[100];
493  unsigned char output[100];
494  size_t len;
495  xtea_context ctx;
496 
497  memset(key_str, 0x00, 100);
498  memset(src_str, 0x00, 100);
499  memset(dst_str, 0x00, 100);
500  memset(iv_str, 0x00, 100);
501  memset(output, 0x00, 100);
502 
503  unhexify( key_str, hex_key_string );
504  unhexify( iv_str, hex_iv_string );
505  len = unhexify( src_str, hex_src_string );
506 
507  xtea_setup( &ctx, key_str );
508  TEST_ASSERT( xtea_crypt_cbc( &ctx, XTEA_DECRYPT, len, iv_str,
509  src_str, output ) == 0 );
510  hexify( dst_str, output, len );
511 
512  TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
513 
514 exit:
515  return;
516 }
517 
518 #ifdef POLARSSL_SELF_TEST
519 void test_suite_xtea_selftest()
520 {
521  TEST_ASSERT( xtea_self_test( 0 ) == 0 );
522 
523 exit:
524  return;
525 }
526 #endif /* POLARSSL_SELF_TEST */
527 
528 
529 #endif /* POLARSSL_XTEA_C */
530 
531 
532 int dep_check( char *str )
533 {
534  if( str == NULL )
535  return( 1 );
536 
537  if( strcmp( str, "POLARSSL_SELF_TEST" ) == 0 )
538  {
539 #if defined(POLARSSL_SELF_TEST)
540  return( 0 );
541 #else
542  return( 1 );
543 #endif
544  }
545 
546 
547  return( 1 );
548 }
549 
550 int dispatch_test(int cnt, char *params[50])
551 {
552  int ret;
553  ((void) cnt);
554  ((void) params);
555 
556 #if defined(TEST_SUITE_ACTIVE)
557  if( strcmp( params[0], "xtea_encrypt_ecb" ) == 0 )
558  {
559 
560  char *param1 = params[1];
561  char *param2 = params[2];
562  char *param3 = params[3];
563 
564  if( cnt != 4 )
565  {
566  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
567  return( 2 );
568  }
569 
570  if( verify_string( &param1 ) != 0 ) return( 2 );
571  if( verify_string( &param2 ) != 0 ) return( 2 );
572  if( verify_string( &param3 ) != 0 ) return( 2 );
573 
574  test_suite_xtea_encrypt_ecb( param1, param2, param3 );
575  return ( 0 );
576 
577  return ( 3 );
578  }
579  else
580  if( strcmp( params[0], "xtea_decrypt_ecb" ) == 0 )
581  {
582 
583  char *param1 = params[1];
584  char *param2 = params[2];
585  char *param3 = params[3];
586 
587  if( cnt != 4 )
588  {
589  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 4 );
590  return( 2 );
591  }
592 
593  if( verify_string( &param1 ) != 0 ) return( 2 );
594  if( verify_string( &param2 ) != 0 ) return( 2 );
595  if( verify_string( &param3 ) != 0 ) return( 2 );
596 
597  test_suite_xtea_decrypt_ecb( param1, param2, param3 );
598  return ( 0 );
599 
600  return ( 3 );
601  }
602  else
603  if( strcmp( params[0], "xtea_encrypt_cbc" ) == 0 )
604  {
605 
606  char *param1 = params[1];
607  char *param2 = params[2];
608  char *param3 = params[3];
609  char *param4 = params[4];
610 
611  if( cnt != 5 )
612  {
613  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
614  return( 2 );
615  }
616 
617  if( verify_string( &param1 ) != 0 ) return( 2 );
618  if( verify_string( &param2 ) != 0 ) return( 2 );
619  if( verify_string( &param3 ) != 0 ) return( 2 );
620  if( verify_string( &param4 ) != 0 ) return( 2 );
621 
622  test_suite_xtea_encrypt_cbc( param1, param2, param3, param4 );
623  return ( 0 );
624 
625  return ( 3 );
626  }
627  else
628  if( strcmp( params[0], "xtea_decrypt_cbc" ) == 0 )
629  {
630 
631  char *param1 = params[1];
632  char *param2 = params[2];
633  char *param3 = params[3];
634  char *param4 = params[4];
635 
636  if( cnt != 5 )
637  {
638  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 5 );
639  return( 2 );
640  }
641 
642  if( verify_string( &param1 ) != 0 ) return( 2 );
643  if( verify_string( &param2 ) != 0 ) return( 2 );
644  if( verify_string( &param3 ) != 0 ) return( 2 );
645  if( verify_string( &param4 ) != 0 ) return( 2 );
646 
647  test_suite_xtea_decrypt_cbc( param1, param2, param3, param4 );
648  return ( 0 );
649 
650  return ( 3 );
651  }
652  else
653  if( strcmp( params[0], "xtea_selftest" ) == 0 )
654  {
655  #ifdef POLARSSL_SELF_TEST
656 
657 
658  if( cnt != 1 )
659  {
660  fprintf( stderr, "\nIncorrect argument count (%d != %d)\n", cnt, 1 );
661  return( 2 );
662  }
663 
664 
665  test_suite_xtea_selftest( );
666  return ( 0 );
667  #endif /* POLARSSL_SELF_TEST */
668 
669  return ( 3 );
670  }
671  else
672 
673  {
674  fprintf( stdout, "FAILED\nSkipping unknown test function '%s'\n", params[0] );
675  fflush( stdout );
676  return( 1 );
677  }
678 #else
679  return( 3 );
680 #endif
681  return( ret );
682 }
683 
684 int get_line( FILE *f, char *buf, size_t len )
685 {
686  char *ret;
687 
688  ret = fgets( buf, len, f );
689  if( ret == NULL )
690  return( -1 );
691 
692  if( strlen( buf ) && buf[strlen(buf) - 1] == '\n' )
693  buf[strlen(buf) - 1] = '\0';
694  if( strlen( buf ) && buf[strlen(buf) - 1] == '\r' )
695  buf[strlen(buf) - 1] = '\0';
696 
697  return( 0 );
698 }
699 
700 int parse_arguments( char *buf, size_t len, char *params[50] )
701 {
702  int cnt = 0, i;
703  char *cur = buf;
704  char *p = buf, *q;
705 
706  params[cnt++] = cur;
707 
708  while( *p != '\0' && p < buf + len )
709  {
710  if( *p == '\\' )
711  {
712  p++;
713  p++;
714  continue;
715  }
716  if( *p == ':' )
717  {
718  if( p + 1 < buf + len )
719  {
720  cur = p + 1;
721  params[cnt++] = cur;
722  }
723  *p = '\0';
724  }
725 
726  p++;
727  }
728 
729  // Replace newlines, question marks and colons in strings
730  for( i = 0; i < cnt; i++ )
731  {
732  p = params[i];
733  q = params[i];
734 
735  while( *p != '\0' )
736  {
737  if( *p == '\\' && *(p + 1) == 'n' )
738  {
739  p += 2;
740  *(q++) = '\n';
741  }
742  else if( *p == '\\' && *(p + 1) == ':' )
743  {
744  p += 2;
745  *(q++) = ':';
746  }
747  else if( *p == '\\' && *(p + 1) == '?' )
748  {
749  p += 2;
750  *(q++) = '?';
751  }
752  else
753  *(q++) = *(p++);
754  }
755  *q = '\0';
756  }
757 
758  return( cnt );
759 }
760 
761 int main()
762 {
763  int ret, i, cnt, total_errors = 0, total_tests = 0, total_skipped = 0;
764  const char *filename = "/builddir/build/BUILD/polarssl-1.3.9/tests/suites/test_suite_xtea.data";
765  FILE *file;
766  char buf[5000];
767  char *params[50];
768 
769 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
770  unsigned char alloc_buf[1000000];
771  memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) );
772 #endif
773 
774  file = fopen( filename, "r" );
775  if( file == NULL )
776  {
777  fprintf( stderr, "Failed to open\n" );
778  return( 1 );
779  }
780 
781  while( !feof( file ) )
782  {
783  int skip = 0;
784 
785  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
786  break;
787  fprintf( stdout, "%s%.66s", test_errors ? "\n" : "", buf );
788  fprintf( stdout, " " );
789  for( i = strlen( buf ) + 1; i < 67; i++ )
790  fprintf( stdout, "." );
791  fprintf( stdout, " " );
792  fflush( stdout );
793 
794  total_tests++;
795 
796  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
797  break;
798  cnt = parse_arguments( buf, strlen(buf), params );
799 
800  if( strcmp( params[0], "depends_on" ) == 0 )
801  {
802  for( i = 1; i < cnt; i++ )
803  if( dep_check( params[i] ) != 0 )
804  skip = 1;
805 
806  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
807  break;
808  cnt = parse_arguments( buf, strlen(buf), params );
809  }
810 
811  if( skip == 0 )
812  {
813  test_errors = 0;
814  ret = dispatch_test( cnt, params );
815  }
816 
817  if( skip == 1 || ret == 3 )
818  {
819  total_skipped++;
820  fprintf( stdout, "----\n" );
821  fflush( stdout );
822  }
823  else if( ret == 0 && test_errors == 0 )
824  {
825  fprintf( stdout, "PASS\n" );
826  fflush( stdout );
827  }
828  else if( ret == 2 )
829  {
830  fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
831  fclose(file);
832  exit( 2 );
833  }
834  else
835  total_errors++;
836 
837  if( ( ret = get_line( file, buf, sizeof(buf) ) ) != 0 )
838  break;
839  if( strlen(buf) != 0 )
840  {
841  fprintf( stderr, "Should be empty %d\n", (int) strlen(buf) );
842  return( 1 );
843  }
844  }
845  fclose(file);
846 
847  fprintf( stdout, "\n----------------------------------------------------------------------------\n\n");
848  if( total_errors == 0 )
849  fprintf( stdout, "PASSED" );
850  else
851  fprintf( stdout, "FAILED" );
852 
853  fprintf( stdout, " (%d / %d tests (%d skipped))\n",
854  total_tests - total_errors, total_tests, total_skipped );
855 
856 #if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
857 #if defined(POLARSSL_MEMORY_DEBUG)
858  memory_buffer_alloc_status();
859 #endif
861 #endif
862 
863  return( total_errors != 0 );
864 }
865 
866 
int dispatch_test(int cnt, char *params[50])
Memory allocation layer (Deprecated to platform layer)
#define PUT_UINT32_BE(n, b, i)
int dep_check(char *str)
Info structure for the pseudo random function.
void memory_buffer_alloc_free(void)
Free the mutex for thread-safety and clear remaining memory.
static int rnd_buffer_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a buffer it receives.
int get_line(FILE *f, char *buf, size_t len)
static int unhexify(unsigned char *obuf, const char *ibuf)
Configuration options (set of defines)
PolarSSL Platform abstraction layer.
static int test_assert(int correct, const char *test)
int xtea_crypt_ecb(xtea_context *ctx, int mode, const unsigned char input[8], unsigned char output[8])
XTEA cipher function.
static int test_errors
int memory_buffer_alloc_init(unsigned char *buf, size_t len)
Initialize use of stack-based memory allocator.
#define TEST_ASSERT(TEST)
static unsigned char * unhexify_alloc(const char *ibuf, size_t *olen)
Allocate and fill a buffer from hex data.
void xtea_setup(xtea_context *ctx, const unsigned char key[16])
XTEA key schedule.
int main()
static void hexify(unsigned char *obuf, const unsigned char *ibuf, int len)
static int rnd_pseudo_rand(void *rng_state, unsigned char *output, size_t len)
This function returns random based on a pseudo random function.
XTEA block cipher (32-bit)
#define XTEA_DECRYPT
Definition: xtea.h:46
#define XTEA_ENCRYPT
Definition: xtea.h:45
static int rnd_std_rand(void *rng_state, unsigned char *output, size_t len)
This function just returns data from rand().
static unsigned char * zero_alloc(size_t len)
Allocate and zeroize a buffer.
int verify_string(char **str)
#define polarssl_malloc
int xtea_crypt_cbc(xtea_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
XTEA CBC cipher function.
int parse_arguments(char *buf, size_t len, char *params[50])
unsigned char * buf
XTEA context structure.
Definition: xtea.h:61
int verify_int(char *str, int *value)
int xtea_self_test(int verbose)
Checkup routine.
static int rnd_zero_rand(void *rng_state, unsigned char *output, size_t len)
This function only returns zeros.