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