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/blowfish.h" |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 3 | /* END_HEADER */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +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_BLOWFISH_C |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 7 | * END_DEPENDENCIES |
| 8 | */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 9 | |
Hanno Becker | f947c0a | 2018-12-17 14:17:10 +0000 | [diff] [blame] | 10 | /* BEGIN_CASE */ |
| 11 | void blowfish_valid_param( ) |
| 12 | { |
| 13 | TEST_VALID_PARAM( mbedtls_blowfish_free( NULL ) ); |
| 14 | } |
| 15 | /* END_CASE */ |
| 16 | |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 17 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
| 18 | void blowfish_invalid_param( ) |
| 19 | { |
| 20 | mbedtls_blowfish_context ctx; |
| 21 | unsigned char buf[16] = { 0 }; |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 22 | size_t const valid_keylength = sizeof( buf ) * 8; |
| 23 | size_t valid_mode = MBEDTLS_BLOWFISH_ENCRYPT; |
| 24 | size_t invalid_mode = 42; |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 25 | size_t off; |
| 26 | ((void) off); |
| 27 | |
| 28 | TEST_INVALID_PARAM( mbedtls_blowfish_init( NULL ) ); |
| 29 | TEST_VALID_PARAM( mbedtls_blowfish_free( NULL ) ); |
| 30 | |
| 31 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 32 | mbedtls_blowfish_setkey( NULL, |
| 33 | buf, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 34 | valid_keylength ) ); |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 35 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 36 | mbedtls_blowfish_setkey( &ctx, |
| 37 | NULL, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 38 | valid_keylength ) ); |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 39 | |
| 40 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 41 | mbedtls_blowfish_crypt_ecb( NULL, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 42 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 43 | buf, buf ) ); |
| 44 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 45 | mbedtls_blowfish_crypt_ecb( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 46 | invalid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 47 | buf, buf ) ); |
| 48 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 49 | mbedtls_blowfish_crypt_ecb( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 50 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 51 | NULL, buf ) ); |
| 52 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 53 | mbedtls_blowfish_crypt_ecb( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 54 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 55 | buf, NULL ) ); |
| 56 | |
| 57 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 58 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 59 | mbedtls_blowfish_crypt_cbc( NULL, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 60 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 61 | sizeof( buf ), |
| 62 | buf, buf, buf ) ); |
| 63 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 64 | mbedtls_blowfish_crypt_cbc( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 65 | invalid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 66 | sizeof( buf ), |
| 67 | buf, buf, buf ) ); |
| 68 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 69 | mbedtls_blowfish_crypt_cbc( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 70 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 71 | sizeof( buf ), |
| 72 | NULL, buf, buf ) ); |
| 73 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 74 | mbedtls_blowfish_crypt_cbc( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 75 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 76 | sizeof( buf ), |
| 77 | buf, NULL, buf ) ); |
| 78 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 79 | mbedtls_blowfish_crypt_cbc( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 80 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 81 | sizeof( buf ), |
| 82 | buf, buf, NULL ) ); |
| 83 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 84 | |
| 85 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 86 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 87 | mbedtls_blowfish_crypt_cfb64( NULL, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 88 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 89 | sizeof( buf ), |
| 90 | &off, buf, |
| 91 | buf, buf ) ); |
| 92 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 93 | mbedtls_blowfish_crypt_cfb64( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 94 | invalid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 95 | sizeof( buf ), |
| 96 | &off, buf, |
| 97 | buf, buf ) ); |
| 98 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 99 | mbedtls_blowfish_crypt_cfb64( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 100 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 101 | sizeof( buf ), |
| 102 | NULL, buf, |
| 103 | buf, buf ) ); |
| 104 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 105 | mbedtls_blowfish_crypt_cfb64( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 106 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 107 | sizeof( buf ), |
| 108 | &off, NULL, |
| 109 | buf, buf ) ); |
| 110 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 111 | mbedtls_blowfish_crypt_cfb64( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 112 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 113 | sizeof( buf ), |
| 114 | &off, buf, |
| 115 | NULL, buf ) ); |
| 116 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 117 | mbedtls_blowfish_crypt_cfb64( &ctx, |
Hanno Becker | 49acc64 | 2018-12-17 09:24:51 +0000 | [diff] [blame] | 118 | valid_mode, |
Hanno Becker | e38b4cd | 2018-12-12 18:46:19 +0000 | [diff] [blame] | 119 | sizeof( buf ), |
| 120 | &off, buf, |
| 121 | buf, NULL ) ); |
| 122 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 123 | |
| 124 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 125 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 126 | mbedtls_blowfish_crypt_ctr( NULL, |
| 127 | sizeof( buf ), |
| 128 | &off, |
| 129 | buf, buf, |
| 130 | buf, buf ) ); |
| 131 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 132 | mbedtls_blowfish_crypt_ctr( &ctx, |
| 133 | sizeof( buf ), |
| 134 | NULL, |
| 135 | buf, buf, |
| 136 | buf, buf ) ); |
| 137 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 138 | mbedtls_blowfish_crypt_ctr( &ctx, |
| 139 | sizeof( buf ), |
| 140 | &off, |
| 141 | NULL, buf, |
| 142 | buf, buf ) ); |
| 143 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 144 | mbedtls_blowfish_crypt_ctr( &ctx, |
| 145 | sizeof( buf ), |
| 146 | &off, |
| 147 | buf, NULL, |
| 148 | buf, buf ) ); |
| 149 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 150 | mbedtls_blowfish_crypt_ctr( &ctx, |
| 151 | sizeof( buf ), |
| 152 | &off, |
| 153 | buf, buf, |
| 154 | NULL, buf ) ); |
| 155 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_BLOWFISH_BAD_INPUT_DATA, |
| 156 | mbedtls_blowfish_crypt_ctr( &ctx, |
| 157 | sizeof( buf ), |
| 158 | &off, |
| 159 | buf, buf, |
| 160 | buf, NULL ) ); |
| 161 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 162 | |
| 163 | exit: |
| 164 | return; |
| 165 | } |
| 166 | /* END_CASE */ |
| 167 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 168 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 169 | void blowfish_encrypt_ecb( data_t * key_str, data_t * src_str, |
| 170 | data_t * hex_dst_string, int setkey_result ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 171 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 172 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 173 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 174 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 175 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 176 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 177 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 178 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 179 | TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 180 | if( setkey_result == 0 ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 181 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 182 | TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 183 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 184 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 185 | 8, hex_dst_string->len ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 186 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 187 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 188 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 189 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 190 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 191 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 192 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 193 | /* BEGIN_CASE */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 194 | void blowfish_decrypt_ecb( data_t * key_str, data_t * src_str, |
| 195 | data_t * hex_dst_string, int setkey_result ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 196 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 197 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 198 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 199 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 200 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 201 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 202 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 203 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 204 | TEST_ASSERT( mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ) == setkey_result ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 205 | if( setkey_result == 0 ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 206 | { |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 207 | TEST_ASSERT( mbedtls_blowfish_crypt_ecb( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->x, output ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 208 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 209 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 210 | 8, hex_dst_string->len ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 211 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 212 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 213 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 214 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 215 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 216 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 217 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 218 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 219 | void blowfish_encrypt_cbc( data_t * key_str, data_t * iv_str, |
| 220 | data_t * src_str, data_t * hex_dst_string, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 221 | int cbc_result ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 222 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 223 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 224 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 225 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 226 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 227 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 228 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 229 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 230 | mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 231 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 232 | TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_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] | 233 | if( cbc_result == 0 ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 234 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 235 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 236 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 237 | src_str->len, |
| 238 | hex_dst_string->len ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 239 | } |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 240 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 241 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 242 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 243 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 244 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 245 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 247 | void blowfish_decrypt_cbc( data_t * key_str, data_t * iv_str, |
| 248 | data_t * src_str, data_t * hex_dst_string, |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 249 | int cbc_result ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 250 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 251 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 252 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 253 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 254 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 255 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 256 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 257 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 258 | mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); |
| 259 | TEST_ASSERT( mbedtls_blowfish_crypt_cbc( &ctx, MBEDTLS_BLOWFISH_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] | 260 | if( cbc_result == 0) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 261 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 262 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 263 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 264 | src_str->len, |
| 265 | hex_dst_string->len ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +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_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 270 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 271 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +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 blowfish_encrypt_cfb64( data_t * key_str, data_t * iv_str, |
| 275 | data_t * src_str, data_t * hex_dst_string |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 276 | ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 277 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 278 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 279 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 280 | size_t iv_offset = 0; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 281 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 282 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 283 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 284 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 285 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 286 | mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); |
| 287 | TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_ENCRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 288 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 289 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 290 | src_str->len, |
| 291 | hex_dst_string->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 292 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 293 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 294 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 295 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 296 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 297 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 298 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 299 | void blowfish_decrypt_cfb64( data_t * key_str, data_t * iv_str, |
| 300 | data_t * src_str, data_t * hex_dst_string |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 301 | ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 302 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 303 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 304 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 305 | size_t iv_offset = 0; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 306 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 307 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 308 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 309 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 310 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 311 | mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); |
| 312 | TEST_ASSERT( mbedtls_blowfish_crypt_cfb64( &ctx, MBEDTLS_BLOWFISH_DECRYPT, src_str->len, &iv_offset, iv_str->x, src_str->x, output ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 313 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 314 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 315 | src_str->len, |
| 316 | hex_dst_string->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 317 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 318 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 319 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 320 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 321 | /* END_CASE */ |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 322 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 323 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Azim Khan | 5fcca46 | 2018-06-29 11:05:32 +0100 | [diff] [blame] | 324 | void blowfish_encrypt_ctr( data_t * key_str, data_t * iv_str, |
| 325 | data_t * src_str, data_t * hex_dst_string ) |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 326 | { |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 327 | unsigned char stream_str[100]; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 328 | unsigned char output[100]; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 329 | mbedtls_blowfish_context ctx; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 330 | size_t iv_offset = 0; |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 331 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 332 | memset(stream_str, 0x00, 100); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 333 | memset(output, 0x00, 100); |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 334 | mbedtls_blowfish_init( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 335 | |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 336 | |
Azim Khan | d30ca13 | 2017-06-09 04:32:58 +0100 | [diff] [blame] | 337 | mbedtls_blowfish_setkey( &ctx, key_str->x, key_str->len * 8 ); |
| 338 | TEST_ASSERT( mbedtls_blowfish_crypt_ctr( &ctx, src_str->len, &iv_offset, iv_str->x, stream_str, src_str->x, output ) == 0 ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 339 | |
Ronald Cron | 9fde353 | 2020-06-10 11:42:32 +0200 | [diff] [blame^] | 340 | TEST_ASSERT( mbedtls_test_hexcmp( output, hex_dst_string->x, |
| 341 | src_str->len, |
| 342 | hex_dst_string->len ) == 0 ); |
Paul Bakker | 8cfd9d8 | 2014-06-18 11:16:11 +0200 | [diff] [blame] | 343 | |
Paul Bakker | bd51b26 | 2014-07-10 15:26:12 +0200 | [diff] [blame] | 344 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 345 | mbedtls_blowfish_free( &ctx ); |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 346 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 347 | /* END_CASE */ |