test_suite_camellia.function 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. BEGIN_HEADER
  2. #include <polarssl/camellia.h>
  3. END_HEADER
  4. BEGIN_DEPENDENCIES
  5. depends_on:POLARSSL_CAMELLIA_C
  6. END_DEPENDENCIES
  7. BEGIN_CASE
  8. camellia_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:setkey_result
  9. {
  10. unsigned char key_str[100];
  11. unsigned char src_str[100];
  12. unsigned char dst_str[100];
  13. unsigned char output[100];
  14. camellia_context ctx;
  15. int key_len;
  16. memset(key_str, 0x00, 100);
  17. memset(src_str, 0x00, 100);
  18. memset(dst_str, 0x00, 100);
  19. memset(output, 0x00, 100);
  20. key_len = unhexify( key_str, {hex_key_string} );
  21. unhexify( src_str, {hex_src_string} );
  22. TEST_ASSERT( camellia_setkey_enc( &ctx, key_str, key_len * 8 ) == {setkey_result} );
  23. if( {setkey_result} == 0 )
  24. {
  25. TEST_ASSERT( camellia_crypt_ecb( &ctx, CAMELLIA_ENCRYPT, src_str, output ) == 0 );
  26. hexify( dst_str, output, 16 );
  27. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  28. }
  29. }
  30. END_CASE
  31. BEGIN_CASE
  32. camellia_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:setkey_result
  33. {
  34. unsigned char key_str[100];
  35. unsigned char src_str[100];
  36. unsigned char dst_str[100];
  37. unsigned char output[100];
  38. camellia_context ctx;
  39. int key_len;
  40. memset(key_str, 0x00, 100);
  41. memset(src_str, 0x00, 100);
  42. memset(dst_str, 0x00, 100);
  43. memset(output, 0x00, 100);
  44. key_len = unhexify( key_str, {hex_key_string} );
  45. unhexify( src_str, {hex_src_string} );
  46. TEST_ASSERT( camellia_setkey_dec( &ctx, key_str, key_len * 8 ) == {setkey_result} );
  47. if( {setkey_result} == 0 )
  48. {
  49. TEST_ASSERT( camellia_crypt_ecb( &ctx, CAMELLIA_DECRYPT, src_str, output ) == 0 );
  50. hexify( dst_str, output, 16 );
  51. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  52. }
  53. }
  54. END_CASE
  55. BEGIN_CASE
  56. camellia_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:cbc_result
  57. {
  58. unsigned char key_str[100];
  59. unsigned char iv_str[100];
  60. unsigned char src_str[100];
  61. unsigned char dst_str[100];
  62. unsigned char output[100];
  63. camellia_context ctx;
  64. int key_len, data_len;
  65. memset(key_str, 0x00, 100);
  66. memset(iv_str, 0x00, 100);
  67. memset(src_str, 0x00, 100);
  68. memset(dst_str, 0x00, 100);
  69. memset(output, 0x00, 100);
  70. key_len = unhexify( key_str, {hex_key_string} );
  71. unhexify( iv_str, {hex_iv_string} );
  72. data_len = unhexify( src_str, {hex_src_string} );
  73. camellia_setkey_enc( &ctx, key_str, key_len * 8 );
  74. TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_ENCRYPT, data_len, iv_str, src_str, output) == {cbc_result} );
  75. if( {cbc_result} == 0 )
  76. {
  77. hexify( dst_str, output, data_len );
  78. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  79. }
  80. }
  81. END_CASE
  82. BEGIN_CASE
  83. camellia_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:cbc_result
  84. {
  85. unsigned char key_str[100];
  86. unsigned char iv_str[100];
  87. unsigned char src_str[100];
  88. unsigned char dst_str[100];
  89. unsigned char output[100];
  90. camellia_context ctx;
  91. int key_len, data_len;
  92. memset(key_str, 0x00, 100);
  93. memset(iv_str, 0x00, 100);
  94. memset(src_str, 0x00, 100);
  95. memset(dst_str, 0x00, 100);
  96. memset(output, 0x00, 100);
  97. key_len = unhexify( key_str, {hex_key_string} );
  98. unhexify( iv_str, {hex_iv_string} );
  99. data_len = unhexify( src_str, {hex_src_string} );
  100. camellia_setkey_dec( &ctx, key_str, key_len * 8 );
  101. TEST_ASSERT( camellia_crypt_cbc( &ctx, CAMELLIA_DECRYPT, data_len, iv_str, src_str, output ) == {cbc_result} );
  102. if( {cbc_result} == 0 )
  103. {
  104. hexify( dst_str, output, data_len );
  105. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  106. }
  107. }
  108. END_CASE
  109. BEGIN_CASE
  110. camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
  111. {
  112. unsigned char key_str[100];
  113. unsigned char iv_str[100];
  114. unsigned char src_str[100];
  115. unsigned char dst_str[100];
  116. unsigned char output[100];
  117. camellia_context ctx;
  118. size_t iv_offset = 0;
  119. int key_len;
  120. memset(key_str, 0x00, 100);
  121. memset(iv_str, 0x00, 100);
  122. memset(src_str, 0x00, 100);
  123. memset(dst_str, 0x00, 100);
  124. memset(output, 0x00, 100);
  125. key_len = unhexify( key_str, {hex_key_string} );
  126. unhexify( iv_str, {hex_iv_string} );
  127. unhexify( src_str, {hex_src_string} );
  128. camellia_setkey_enc( &ctx, key_str, key_len * 8 );
  129. TEST_ASSERT( camellia_crypt_cfb128( &ctx, CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
  130. hexify( dst_str, output, 16 );
  131. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  132. }
  133. END_CASE
  134. BEGIN_CASE
  135. camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string
  136. {
  137. unsigned char key_str[100];
  138. unsigned char iv_str[100];
  139. unsigned char src_str[100];
  140. unsigned char dst_str[100];
  141. unsigned char output[100];
  142. camellia_context ctx;
  143. size_t iv_offset = 0;
  144. int key_len;
  145. memset(key_str, 0x00, 100);
  146. memset(iv_str, 0x00, 100);
  147. memset(src_str, 0x00, 100);
  148. memset(dst_str, 0x00, 100);
  149. memset(output, 0x00, 100);
  150. key_len = unhexify( key_str, {hex_key_string} );
  151. unhexify( iv_str, {hex_iv_string} );
  152. unhexify( src_str, {hex_src_string} );
  153. camellia_setkey_enc( &ctx, key_str, key_len * 8 );
  154. TEST_ASSERT( camellia_crypt_cfb128( &ctx, CAMELLIA_DECRYPT, 16, &iv_offset, iv_str, src_str, output ) == 0 );
  155. hexify( dst_str, output, 16 );
  156. TEST_ASSERT( strcasecmp( (char *) dst_str, {hex_dst_string} ) == 0 );
  157. }
  158. END_CASE
  159. BEGIN_CASE
  160. camellia_selftest:
  161. {
  162. TEST_ASSERT( camellia_self_test( 0 ) == 0 );
  163. }
  164. END_CASE