Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 1 | BEGIN_HEADER |
| 2 | #include "polarssl/blowfish.h" |
| 3 | END_HEADER |
| 4 | |
| 5 | BEGIN_DEPENDENCIES |
| 6 | depends_on:POLARSSL_BLOWFISH_C |
| 7 | END_DEPENDENCIES |
| 8 | |
| 9 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 10 | blowfish_encrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 11 | { |
| 12 | unsigned char key_str[100]; |
| 13 | unsigned char src_str[100]; |
| 14 | unsigned char dst_str[100]; |
| 15 | unsigned char output[100]; |
| 16 | blowfish_context ctx; |
| 17 | int key_len; |
| 18 | |
| 19 | memset(key_str, 0x00, 100); |
| 20 | memset(src_str, 0x00, 100); |
| 21 | memset(dst_str, 0x00, 100); |
| 22 | memset(output, 0x00, 100); |
| 23 | |
| 24 | key_len = unhexify( key_str, {hex_key_string} ); |
| 25 | unhexify( src_str, {hex_src_string} ); |
| 26 | |
| 27 | TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} ); |
| 28 | if( {setkey_result} == 0 ) |
| 29 | { |
| 30 | TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_ENCRYPT, src_str, output ) == 0 ); |
| 31 | hexify( dst_str, output, 8 ); |
| 32 | |
| 33 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 34 | } |
| 35 | } |
| 36 | END_CASE |
| 37 | |
| 38 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 39 | blowfish_decrypt_ecb:hex_key_string:hex_src_string:hex_dst_string:#setkey_result |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 40 | { |
| 41 | unsigned char key_str[100]; |
| 42 | unsigned char src_str[100]; |
| 43 | unsigned char dst_str[100]; |
| 44 | unsigned char output[100]; |
| 45 | blowfish_context ctx; |
| 46 | int key_len; |
| 47 | |
| 48 | memset(key_str, 0x00, 100); |
| 49 | memset(src_str, 0x00, 100); |
| 50 | memset(dst_str, 0x00, 100); |
| 51 | memset(output, 0x00, 100); |
| 52 | |
| 53 | key_len = unhexify( key_str, {hex_key_string} ); |
| 54 | unhexify( src_str, {hex_src_string} ); |
| 55 | |
| 56 | TEST_ASSERT( blowfish_setkey( &ctx, key_str, key_len * 8 ) == {setkey_result} ); |
| 57 | if( {setkey_result} == 0 ) |
| 58 | { |
| 59 | TEST_ASSERT( blowfish_crypt_ecb( &ctx, BLOWFISH_DECRYPT, src_str, output ) == 0 ); |
| 60 | hexify( dst_str, output, 8 ); |
| 61 | |
| 62 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 63 | } |
| 64 | } |
| 65 | END_CASE |
| 66 | |
| 67 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 68 | blowfish_encrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 69 | { |
| 70 | unsigned char key_str[100]; |
| 71 | unsigned char iv_str[100]; |
| 72 | unsigned char src_str[100]; |
| 73 | unsigned char dst_str[100]; |
| 74 | unsigned char output[100]; |
| 75 | blowfish_context ctx; |
| 76 | int key_len, data_len; |
| 77 | |
| 78 | memset(key_str, 0x00, 100); |
| 79 | memset(iv_str, 0x00, 100); |
| 80 | memset(src_str, 0x00, 100); |
| 81 | memset(dst_str, 0x00, 100); |
| 82 | memset(output, 0x00, 100); |
| 83 | |
| 84 | key_len = unhexify( key_str, {hex_key_string} ); |
| 85 | unhexify( iv_str, {hex_iv_string} ); |
| 86 | data_len = unhexify( src_str, {hex_src_string} ); |
| 87 | |
| 88 | blowfish_setkey( &ctx, key_str, key_len * 8 ); |
| 89 | |
| 90 | TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_ENCRYPT, data_len , iv_str, src_str, output ) == {cbc_result} ); |
| 91 | if( {cbc_result} == 0 ) |
| 92 | { |
| 93 | hexify( dst_str, output, data_len ); |
| 94 | |
| 95 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 96 | } |
| 97 | } |
| 98 | END_CASE |
| 99 | |
| 100 | BEGIN_CASE |
Paul Bakker | dbd443d | 2013-08-16 13:38:47 +0200 | [diff] [blame] | 101 | blowfish_decrypt_cbc:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string:#cbc_result |
Paul Bakker | a9379c0 | 2012-07-04 11:02:11 +0000 | [diff] [blame] | 102 | { |
| 103 | unsigned char key_str[100]; |
| 104 | unsigned char iv_str[100]; |
| 105 | unsigned char src_str[100]; |
| 106 | unsigned char dst_str[100]; |
| 107 | unsigned char output[100]; |
| 108 | blowfish_context ctx; |
| 109 | int key_len, data_len; |
| 110 | |
| 111 | memset(key_str, 0x00, 100); |
| 112 | memset(iv_str, 0x00, 100); |
| 113 | memset(src_str, 0x00, 100); |
| 114 | memset(dst_str, 0x00, 100); |
| 115 | memset(output, 0x00, 100); |
| 116 | |
| 117 | key_len = unhexify( key_str, {hex_key_string} ); |
| 118 | unhexify( iv_str, {hex_iv_string} ); |
| 119 | data_len = unhexify( src_str, {hex_src_string} ); |
| 120 | |
| 121 | blowfish_setkey( &ctx, key_str, key_len * 8 ); |
| 122 | TEST_ASSERT( blowfish_crypt_cbc( &ctx, BLOWFISH_DECRYPT, data_len , iv_str, src_str, output ) == {cbc_result} ); |
| 123 | if( {cbc_result} == 0) |
| 124 | { |
| 125 | hexify( dst_str, output, data_len ); |
| 126 | |
| 127 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 128 | } |
| 129 | } |
| 130 | END_CASE |
| 131 | |
| 132 | BEGIN_CASE |
| 133 | blowfish_encrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 134 | { |
| 135 | unsigned char key_str[100]; |
| 136 | unsigned char iv_str[100]; |
| 137 | unsigned char src_str[100]; |
| 138 | unsigned char dst_str[100]; |
| 139 | unsigned char output[100]; |
| 140 | blowfish_context ctx; |
| 141 | size_t iv_offset = 0; |
| 142 | int key_len, src_len; |
| 143 | |
| 144 | memset(key_str, 0x00, 100); |
| 145 | memset(iv_str, 0x00, 100); |
| 146 | memset(src_str, 0x00, 100); |
| 147 | memset(dst_str, 0x00, 100); |
| 148 | memset(output, 0x00, 100); |
| 149 | |
| 150 | key_len = unhexify( key_str, {hex_key_string} ); |
| 151 | unhexify( iv_str, {hex_iv_string} ); |
| 152 | src_len = unhexify( src_str, {hex_src_string} ); |
| 153 | |
| 154 | blowfish_setkey( &ctx, key_str, key_len * 8 ); |
| 155 | TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_ENCRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 ); |
| 156 | hexify( dst_str, output, src_len ); |
| 157 | |
| 158 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 159 | } |
| 160 | END_CASE |
| 161 | |
| 162 | BEGIN_CASE |
| 163 | blowfish_decrypt_cfb64:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 164 | { |
| 165 | unsigned char key_str[100]; |
| 166 | unsigned char iv_str[100]; |
| 167 | unsigned char src_str[100]; |
| 168 | unsigned char dst_str[100]; |
| 169 | unsigned char output[100]; |
| 170 | blowfish_context ctx; |
| 171 | size_t iv_offset = 0; |
| 172 | int key_len, src_len; |
| 173 | |
| 174 | memset(key_str, 0x00, 100); |
| 175 | memset(iv_str, 0x00, 100); |
| 176 | memset(src_str, 0x00, 100); |
| 177 | memset(dst_str, 0x00, 100); |
| 178 | memset(output, 0x00, 100); |
| 179 | |
| 180 | key_len = unhexify( key_str, {hex_key_string} ); |
| 181 | unhexify( iv_str, {hex_iv_string} ); |
| 182 | src_len = unhexify( src_str, {hex_src_string} ); |
| 183 | |
| 184 | blowfish_setkey( &ctx, key_str, key_len * 8 ); |
| 185 | TEST_ASSERT( blowfish_crypt_cfb64( &ctx, BLOWFISH_DECRYPT, src_len, &iv_offset, iv_str, src_str, output ) == 0 ); |
| 186 | hexify( dst_str, output, src_len ); |
| 187 | |
| 188 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 189 | } |
| 190 | END_CASE |
| 191 | |
| 192 | BEGIN_CASE |
| 193 | blowfish_encrypt_ctr:hex_key_string:hex_iv_string:hex_src_string:hex_dst_string |
| 194 | { |
| 195 | unsigned char key_str[100]; |
| 196 | unsigned char iv_str[100]; |
| 197 | unsigned char stream_str[100]; |
| 198 | unsigned char src_str[100]; |
| 199 | unsigned char dst_str[100]; |
| 200 | unsigned char output[100]; |
| 201 | blowfish_context ctx; |
| 202 | size_t iv_offset = 0; |
| 203 | int key_len, src_len; |
| 204 | |
| 205 | memset(key_str, 0x00, 100); |
| 206 | memset(iv_str, 0x00, 100); |
| 207 | memset(stream_str, 0x00, 100); |
| 208 | memset(src_str, 0x00, 100); |
| 209 | memset(dst_str, 0x00, 100); |
| 210 | memset(output, 0x00, 100); |
| 211 | |
| 212 | key_len = unhexify( key_str, {hex_key_string} ); |
| 213 | unhexify( iv_str, {hex_iv_string} ); |
| 214 | src_len = unhexify( src_str, {hex_src_string} ); |
| 215 | |
| 216 | blowfish_setkey( &ctx, key_str, key_len * 8 ); |
| 217 | TEST_ASSERT( blowfish_crypt_ctr( &ctx, src_len, &iv_offset, iv_str, stream_str, src_str, output ) == 0 ); |
| 218 | hexify( dst_str, output, src_len ); |
| 219 | |
| 220 | TEST_ASSERT( strcmp( (char *) dst_str, {hex_dst_string} ) == 0 ); |
| 221 | } |
| 222 | END_CASE |