Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 2 | #include "mbedtls/camellia.h" |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 3 | /* END_HEADER */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 4 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 5 | /* BEGIN_DEPENDENCIES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 6 | * depends_on:MBEDTLS_CAMELLIA_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 7 | * END_DEPENDENCIES |
| 8 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 9 | |
Hanno Becker | 7578837 | 2018-12-12 18:02:18 +0000 | [diff] [blame] | 10 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
| 11 | void camellia_invalid_param( ) |
| 12 | { |
| 13 | mbedtls_camellia_context ctx; |
| 14 | unsigned char buf[16] = { 0 }; |
| 15 | size_t off; |
| 16 | ((void) off); |
| 17 | |
| 18 | TEST_INVALID_PARAM( mbedtls_camellia_init( NULL ) ); |
| 19 | TEST_VALID_PARAM( mbedtls_camellia_free( NULL ) ); |
| 20 | |
| 21 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 22 | mbedtls_camellia_setkey_enc( NULL, |
| 23 | buf, |
| 24 | 128 ) ); |
| 25 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 26 | mbedtls_camellia_setkey_enc( &ctx, |
| 27 | NULL, |
| 28 | 128 ) ); |
| 29 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 30 | mbedtls_camellia_setkey_enc( &ctx, |
| 31 | buf, |
| 32 | 42 ) ); |
| 33 | |
| 34 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 35 | mbedtls_camellia_setkey_dec( NULL, |
| 36 | buf, |
| 37 | 128 ) ); |
| 38 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 39 | mbedtls_camellia_setkey_dec( &ctx, |
| 40 | NULL, |
| 41 | 128 ) ); |
| 42 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 43 | mbedtls_camellia_setkey_dec( &ctx, |
| 44 | buf, |
| 45 | 42 ) ); |
| 46 | |
| 47 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 48 | mbedtls_camellia_crypt_ecb( NULL, |
| 49 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 50 | buf, buf ) ); |
| 51 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 52 | mbedtls_camellia_crypt_ecb( &ctx, |
| 53 | 42, |
| 54 | buf, buf ) ); |
| 55 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 56 | mbedtls_camellia_crypt_ecb( &ctx, |
| 57 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 58 | NULL, buf ) ); |
| 59 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 60 | mbedtls_camellia_crypt_ecb( &ctx, |
| 61 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 62 | buf, NULL ) ); |
| 63 | |
| 64 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 65 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 66 | mbedtls_camellia_crypt_cbc( NULL, |
| 67 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 68 | sizeof( buf ), |
| 69 | buf, buf, buf ) ); |
| 70 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 71 | mbedtls_camellia_crypt_cbc( &ctx, |
| 72 | 42, |
| 73 | sizeof( buf ), |
| 74 | buf, buf, buf ) ); |
| 75 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 76 | mbedtls_camellia_crypt_cbc( &ctx, |
| 77 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 78 | sizeof( buf ), |
| 79 | NULL, buf, buf ) ); |
| 80 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 81 | mbedtls_camellia_crypt_cbc( &ctx, |
| 82 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 83 | sizeof( buf ), |
| 84 | buf, NULL, buf ) ); |
| 85 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 86 | mbedtls_camellia_crypt_cbc( &ctx, |
| 87 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 88 | sizeof( buf ), |
| 89 | buf, buf, NULL ) ); |
| 90 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 91 | |
| 92 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 93 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 94 | mbedtls_camellia_crypt_cfb128( NULL, |
| 95 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 96 | sizeof( buf ), |
| 97 | &off, buf, |
| 98 | buf, buf ) ); |
| 99 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 100 | mbedtls_camellia_crypt_cfb128( &ctx, |
| 101 | 42, |
| 102 | sizeof( buf ), |
| 103 | &off, buf, |
| 104 | buf, buf ) ); |
| 105 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 106 | mbedtls_camellia_crypt_cfb128( &ctx, |
| 107 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 108 | sizeof( buf ), |
| 109 | NULL, buf, |
| 110 | buf, buf ) ); |
| 111 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 112 | mbedtls_camellia_crypt_cfb128( &ctx, |
| 113 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 114 | sizeof( buf ), |
| 115 | &off, NULL, |
| 116 | buf, buf ) ); |
| 117 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 118 | mbedtls_camellia_crypt_cfb128( &ctx, |
| 119 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 120 | sizeof( buf ), |
| 121 | &off, buf, |
| 122 | NULL, buf ) ); |
| 123 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 124 | mbedtls_camellia_crypt_cfb128( &ctx, |
| 125 | MBEDTLS_CAMELLIA_ENCRYPT, |
| 126 | sizeof( buf ), |
| 127 | &off, buf, |
| 128 | buf, NULL ) ); |
| 129 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 130 | |
| 131 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 132 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 133 | mbedtls_camellia_crypt_ctr( NULL, |
| 134 | sizeof( buf ), |
| 135 | &off, |
| 136 | buf, buf, |
| 137 | buf, buf ) ); |
| 138 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 139 | mbedtls_camellia_crypt_ctr( &ctx, |
| 140 | sizeof( buf ), |
| 141 | NULL, |
| 142 | buf, buf, |
| 143 | buf, buf ) ); |
| 144 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 145 | mbedtls_camellia_crypt_ctr( &ctx, |
| 146 | sizeof( buf ), |
| 147 | &off, |
| 148 | NULL, buf, |
| 149 | buf, buf ) ); |
| 150 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 151 | mbedtls_camellia_crypt_ctr( &ctx, |
| 152 | sizeof( buf ), |
| 153 | &off, |
| 154 | buf, NULL, |
| 155 | buf, buf ) ); |
| 156 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 157 | mbedtls_camellia_crypt_ctr( &ctx, |
| 158 | sizeof( buf ), |
| 159 | &off, |
| 160 | buf, buf, |
| 161 | NULL, buf ) ); |
| 162 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA, |
| 163 | mbedtls_camellia_crypt_ctr( &ctx, |
| 164 | sizeof( buf ), |
| 165 | &off, |
| 166 | buf, buf, |
| 167 | buf, NULL ) ); |
| 168 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 169 | |
| 170 | exit: |
| 171 | return; |
| 172 | } |
| 173 | /* END_CASE */ |
| 174 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 175 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 176 | void camellia_encrypt_ecb( data_t * key_str, data_t * src_str, |
| 177 | data_t * hex_dst_string, int setkey_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 178 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 179 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 180 | mbedtls_camellia_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 181 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 182 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 183 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 184 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 185 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 186 | TEST_ASSERT( mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 187 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 188 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 189 | TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 190 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 191 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 192 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 193 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 194 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 195 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 196 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 197 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 198 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 199 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 200 | void camellia_decrypt_ecb( data_t * key_str, data_t * src_str, |
| 201 | data_t * hex_dst_string, int setkey_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 202 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 203 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 204 | mbedtls_camellia_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 205 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 206 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 207 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 208 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 209 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 210 | TEST_ASSERT( mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 211 | if( setkey_result == 0 ) |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 212 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 213 | TEST_ASSERT( mbedtls_camellia_crypt_ecb( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 214 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 215 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); |
Paul Bakker | 2b222c8 | 2009-07-27 21:03:45 +0000 | [diff] [blame] | 216 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 217 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 218 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 219 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 220 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 221 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 222 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 224 | void camellia_encrypt_cbc( data_t * key_str, data_t * iv_str, |
| 225 | data_t * src_str, data_t * hex_dst_string, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 226 | int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 227 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 228 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | mbedtls_camellia_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 230 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 231 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 232 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 233 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 234 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 235 | mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 236 | TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, src_str->len, iv_str->x, src_str->x, output) == cbc_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 237 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 238 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 239 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 240 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 241 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 242 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 243 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 244 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 245 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 246 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 247 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 248 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 249 | void camellia_decrypt_cbc( data_t * key_str, data_t * iv_str, |
| 250 | data_t * src_str, data_t * hex_dst_string, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 251 | int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 252 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 253 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 254 | mbedtls_camellia_context ctx; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 255 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 256 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 257 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 258 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 259 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 260 | mbedtls_camellia_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); |
| 261 | TEST_ASSERT( mbedtls_camellia_crypt_cbc( &ctx, MBEDTLS_CAMELLIA_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 262 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 263 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 264 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 265 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, src_str->len, hex_dst_string->len ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 266 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 267 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 268 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 269 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 270 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 271 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 272 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 273 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 274 | void camellia_encrypt_cfb128( data_t * key_str, data_t * iv_str, |
| 275 | data_t * src_str, |
| 276 | data_t * hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 277 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 278 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 279 | mbedtls_camellia_context ctx; |
Paul Bakker | 1ef71df | 2011-06-09 14:14:58 +0000 | [diff] [blame] | 280 | size_t iv_offset = 0; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 281 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 282 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 283 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 284 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 285 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 286 | mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 287 | TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 288 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 289 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 290 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 291 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 292 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 293 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 294 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 295 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 296 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 297 | void camellia_decrypt_cfb128( data_t * key_str, data_t * iv_str, |
| 298 | data_t * src_str, |
| 299 | data_t * hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 300 | { |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 301 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 302 | mbedtls_camellia_context ctx; |
Paul Bakker | 1ef71df | 2011-06-09 14:14:58 +0000 | [diff] [blame] | 303 | size_t iv_offset = 0; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 304 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 305 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 306 | mbedtls_camellia_init( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 307 | |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 308 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 309 | mbedtls_camellia_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 310 | TEST_ASSERT( mbedtls_camellia_crypt_cfb128( &ctx, MBEDTLS_CAMELLIA_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 311 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 312 | TEST_ASSERT( hexcmp( output, hex_dst_string->x, 16, hex_dst_string->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 313 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 314 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 315 | mbedtls_camellia_free( &ctx ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 316 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 317 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 318 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 319 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Azim Khan | f1aaec9 | 2017-05-30 14:23:15 +0100 | [diff] [blame] | 320 | void camellia_selftest( ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 321 | { |
Andres AG | 93012e8 | 2016-09-09 09:10:28 +0100 | [diff] [blame] | 322 | TEST_ASSERT( mbedtls_camellia_self_test( 1 ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 323 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 324 | /* END_CASE */ |