itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 1 | #include "psa/crypto.h" |
| 2 | #include <string.h> |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 3 | #include <stdio.h> |
Jaeden Amero | db29ab5 | 2019-02-12 16:40:27 +0000 | [diff] [blame] | 4 | #include <stdlib.h> |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 5 | |
| 6 | #define ASSERT( predicate ) \ |
| 7 | do \ |
| 8 | { \ |
| 9 | if( ! ( predicate ) ) \ |
| 10 | { \ |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 11 | printf( "\tassertion failed at %s:%d - '%s'\r\n", \ |
| 12 | __FILE__, __LINE__, #predicate); \ |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 13 | goto exit; \ |
| 14 | } \ |
| 15 | } while ( 0 ) |
| 16 | |
| 17 | #define ASSERT_STATUS( actual, expected ) \ |
| 18 | do \ |
| 19 | { \ |
| 20 | if( ( actual ) != ( expected ) ) \ |
| 21 | { \ |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 22 | printf( "\tassertion failed at %s:%d - " \ |
| 23 | "actual:%d expected:%d\r\n", __FILE__, __LINE__, \ |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 24 | (psa_status_t) actual, (psa_status_t) expected ); \ |
| 25 | goto exit; \ |
| 26 | } \ |
| 27 | } while ( 0 ) |
| 28 | |
itayzafrir | 18ac331 | 2018-07-17 09:28:11 +0300 | [diff] [blame] | 29 | #if !defined(MBEDTLS_PSA_CRYPTO_C) || !defined(MBEDTLS_AES_C) || \ |
| 30 | !defined(MBEDTLS_CIPHER_MODE_CBC) || !defined(MBEDTLS_CIPHER_MODE_CTR) || \ |
| 31 | !defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) |
| 32 | int main( void ) |
| 33 | { |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 34 | printf( "MBEDTLS_PSA_CRYPTO_C and/or MBEDTLS_AES_C and/or " |
| 35 | "MBEDTLS_CIPHER_MODE_CBC and/or MBEDTLS_CIPHER_MODE_CTR " |
| 36 | "and/or MBEDTLS_CIPHER_MODE_WITH_PADDING " |
| 37 | "not defined.\r\n" ); |
itayzafrir | 18ac331 | 2018-07-17 09:28:11 +0300 | [diff] [blame] | 38 | return( 0 ); |
| 39 | } |
| 40 | #else |
| 41 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 42 | static psa_status_t set_key_policy( psa_key_handle_t key_handle, |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 43 | psa_key_usage_t key_usage, |
| 44 | psa_algorithm_t alg ) |
| 45 | { |
| 46 | psa_status_t status; |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 47 | psa_key_policy_t policy = PSA_KEY_POLICY_INIT; |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 48 | |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 49 | psa_key_policy_set_usage( &policy, key_usage, alg ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 50 | status = psa_set_key_policy( key_handle, &policy ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 51 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 52 | exit: |
| 53 | return( status ); |
| 54 | } |
| 55 | |
| 56 | static psa_status_t cipher_operation( psa_cipher_operation_t *operation, |
| 57 | const uint8_t * input, |
| 58 | size_t input_size, |
| 59 | size_t part_size, |
| 60 | uint8_t * output, |
| 61 | size_t output_size, |
| 62 | size_t *output_len ) |
| 63 | { |
| 64 | psa_status_t status; |
| 65 | size_t bytes_to_write = 0, bytes_written = 0, len = 0; |
| 66 | |
| 67 | *output_len = 0; |
| 68 | while( bytes_written != input_size ) |
| 69 | { |
| 70 | bytes_to_write = ( input_size - bytes_written > part_size ? |
| 71 | part_size : |
| 72 | input_size - bytes_written ); |
| 73 | |
| 74 | status = psa_cipher_update( operation, input + bytes_written, |
| 75 | bytes_to_write, output + *output_len, |
| 76 | output_size - *output_len, &len ); |
| 77 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 78 | |
| 79 | bytes_written += bytes_to_write; |
| 80 | *output_len += len; |
| 81 | } |
| 82 | |
| 83 | status = psa_cipher_finish( operation, output + *output_len, |
| 84 | output_size - *output_len, &len ); |
| 85 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 86 | *output_len += len; |
| 87 | |
| 88 | exit: |
| 89 | return( status ); |
| 90 | } |
| 91 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 92 | static psa_status_t cipher_encrypt( psa_key_handle_t key_handle, |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 93 | psa_algorithm_t alg, |
| 94 | uint8_t * iv, |
| 95 | size_t iv_size, |
| 96 | const uint8_t * input, |
| 97 | size_t input_size, |
| 98 | size_t part_size, |
| 99 | uint8_t * output, |
| 100 | size_t output_size, |
| 101 | size_t *output_len ) |
| 102 | { |
| 103 | psa_status_t status; |
Jaeden Amero | b281f74 | 2019-02-20 10:40:20 +0000 | [diff] [blame] | 104 | psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 105 | size_t iv_len = 0; |
| 106 | |
| 107 | memset( &operation, 0, sizeof( operation ) ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 108 | status = psa_cipher_encrypt_setup( &operation, key_handle, alg ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 109 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 110 | |
| 111 | status = psa_cipher_generate_iv( &operation, iv, iv_size, &iv_len ); |
| 112 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 113 | |
| 114 | status = cipher_operation( &operation, input, input_size, part_size, |
| 115 | output, output_size, output_len ); |
| 116 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 117 | |
| 118 | exit: |
| 119 | psa_cipher_abort( &operation ); |
| 120 | return( status ); |
| 121 | } |
| 122 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 123 | static psa_status_t cipher_decrypt( psa_key_handle_t key_handle, |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 124 | psa_algorithm_t alg, |
| 125 | const uint8_t * iv, |
| 126 | size_t iv_size, |
| 127 | const uint8_t * input, |
| 128 | size_t input_size, |
| 129 | size_t part_size, |
| 130 | uint8_t * output, |
| 131 | size_t output_size, |
| 132 | size_t *output_len ) |
| 133 | { |
| 134 | psa_status_t status; |
Jaeden Amero | b281f74 | 2019-02-20 10:40:20 +0000 | [diff] [blame] | 135 | psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 136 | |
| 137 | memset( &operation, 0, sizeof( operation ) ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 138 | status = psa_cipher_decrypt_setup( &operation, key_handle, alg ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 139 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 140 | |
| 141 | status = psa_cipher_set_iv( &operation, iv, iv_size ); |
| 142 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 143 | |
| 144 | status = cipher_operation( &operation, input, input_size, part_size, |
| 145 | output, output_size, output_len ); |
| 146 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 147 | |
| 148 | exit: |
| 149 | psa_cipher_abort( &operation ); |
| 150 | return( status ); |
| 151 | } |
| 152 | |
| 153 | static psa_status_t |
| 154 | cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( void ) |
| 155 | { |
| 156 | enum { |
| 157 | block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( PSA_KEY_TYPE_AES ), |
| 158 | key_bits = 256, |
| 159 | part_size = block_size, |
| 160 | }; |
Gilles Peskine | daea26f | 2018-08-21 14:02:45 +0200 | [diff] [blame] | 161 | const psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING; |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 162 | |
| 163 | psa_status_t status; |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 164 | psa_key_handle_t key_handle = 0; |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 165 | size_t output_len = 0; |
| 166 | uint8_t iv[block_size]; |
| 167 | uint8_t input[block_size]; |
| 168 | uint8_t encrypt[block_size]; |
| 169 | uint8_t decrypt[block_size]; |
| 170 | |
| 171 | status = psa_generate_random( input, sizeof( input ) ); |
| 172 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 173 | |
Gilles Peskine | d40c1fb | 2019-01-19 12:20:52 +0100 | [diff] [blame] | 174 | status = psa_allocate_key( &key_handle ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 175 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 176 | |
| 177 | status = set_key_policy( key_handle, |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 178 | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, |
| 179 | alg ); |
| 180 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 181 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 182 | status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits, |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 183 | NULL, 0 ); |
| 184 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 185 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 186 | status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 187 | input, sizeof( input ), part_size, |
| 188 | encrypt, sizeof( encrypt ), &output_len ); |
| 189 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 190 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 191 | status = cipher_decrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 192 | encrypt, output_len, part_size, |
| 193 | decrypt, sizeof( decrypt ), &output_len ); |
| 194 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 195 | |
| 196 | status = memcmp( input, decrypt, sizeof( input ) ); |
| 197 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 198 | |
| 199 | exit: |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 200 | psa_destroy_key( key_handle ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 201 | return( status ); |
| 202 | } |
| 203 | |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 204 | static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void ) |
| 205 | { |
| 206 | enum { |
| 207 | block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( PSA_KEY_TYPE_AES ), |
| 208 | key_bits = 256, |
| 209 | input_size = 100, |
| 210 | part_size = 10, |
| 211 | }; |
| 212 | |
Gilles Peskine | daea26f | 2018-08-21 14:02:45 +0200 | [diff] [blame] | 213 | const psa_algorithm_t alg = PSA_ALG_CBC_PKCS7; |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 214 | |
| 215 | psa_status_t status; |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 216 | psa_key_handle_t key_handle = 0; |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 217 | size_t output_len = 0; |
| 218 | uint8_t iv[block_size], input[input_size], |
| 219 | encrypt[input_size + block_size], decrypt[input_size + block_size]; |
| 220 | |
| 221 | status = psa_generate_random( input, sizeof( input ) ); |
| 222 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 223 | |
Gilles Peskine | d40c1fb | 2019-01-19 12:20:52 +0100 | [diff] [blame] | 224 | status = psa_allocate_key( &key_handle ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 225 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 226 | |
| 227 | status = set_key_policy( key_handle, |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 228 | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, |
| 229 | alg ); |
| 230 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 231 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 232 | status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits, |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 233 | NULL, 0 ); |
| 234 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 235 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 236 | status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 237 | input, sizeof( input ), part_size, |
| 238 | encrypt, sizeof( encrypt ), &output_len ); |
| 239 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 240 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 241 | status = cipher_decrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 242 | encrypt, output_len, part_size, |
| 243 | decrypt, sizeof( decrypt ), &output_len ); |
| 244 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 245 | |
| 246 | status = memcmp( input, decrypt, sizeof( input ) ); |
| 247 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 248 | |
| 249 | exit: |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 250 | psa_destroy_key( key_handle ); |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 251 | return( status ); |
| 252 | } |
| 253 | |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 254 | static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void ) |
| 255 | { |
| 256 | enum { |
| 257 | block_size = PSA_BLOCK_CIPHER_BLOCK_SIZE( PSA_KEY_TYPE_AES ), |
| 258 | key_bits = 256, |
| 259 | input_size = 100, |
| 260 | part_size = 10, |
| 261 | }; |
| 262 | const psa_algorithm_t alg = PSA_ALG_CTR; |
| 263 | |
| 264 | psa_status_t status; |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 265 | psa_key_handle_t key_handle = 0; |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 266 | size_t output_len = 0; |
| 267 | uint8_t iv[block_size], input[input_size], encrypt[input_size], |
| 268 | decrypt[input_size]; |
| 269 | |
| 270 | status = psa_generate_random( input, sizeof( input ) ); |
| 271 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 272 | |
Gilles Peskine | d40c1fb | 2019-01-19 12:20:52 +0100 | [diff] [blame] | 273 | status = psa_allocate_key( &key_handle ); |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 274 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 275 | status = set_key_policy( key_handle, |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 276 | PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, |
| 277 | alg ); |
| 278 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 279 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 280 | status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits, |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 281 | NULL, 0 ); |
| 282 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 283 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 284 | status = cipher_encrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 285 | input, sizeof( input ), part_size, |
| 286 | encrypt, sizeof( encrypt ), &output_len ); |
| 287 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 288 | |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 289 | status = cipher_decrypt( key_handle, alg, iv, sizeof( iv ), |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 290 | encrypt, output_len, part_size, |
| 291 | decrypt, sizeof( decrypt ), &output_len ); |
| 292 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 293 | |
| 294 | status = memcmp( input, decrypt, sizeof( input ) ); |
| 295 | ASSERT_STATUS( status, PSA_SUCCESS ); |
| 296 | |
| 297 | exit: |
Gilles Peskine | b0edfb5 | 2018-12-03 16:24:51 +0100 | [diff] [blame] | 298 | psa_destroy_key( key_handle ); |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 299 | return( status ); |
| 300 | } |
| 301 | |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 302 | static void cipher_examples( void ) |
| 303 | { |
| 304 | psa_status_t status; |
| 305 | |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 306 | printf( "cipher encrypt/decrypt AES CBC no padding:\r\n" ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 307 | status = cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( ); |
| 308 | if( status == PSA_SUCCESS ) |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 309 | printf( "\tsuccess!\r\n" ); |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 310 | |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 311 | printf( "cipher encrypt/decrypt AES CBC PKCS7 multipart:\r\n" ); |
itayzafrir | a2d0804 | 2018-07-12 10:27:58 +0300 | [diff] [blame] | 312 | status = cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( ); |
| 313 | if( status == PSA_SUCCESS ) |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 314 | printf( "\tsuccess!\r\n" ); |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 315 | |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 316 | printf( "cipher encrypt/decrypt AES CTR multipart:\r\n" ); |
itayzafrir | 44b09d2 | 2018-07-12 13:06:41 +0300 | [diff] [blame] | 317 | status = cipher_example_encrypt_decrypt_aes_ctr_multi( ); |
| 318 | if( status == PSA_SUCCESS ) |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 319 | printf( "\tsuccess!\r\n" ); |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 320 | } |
| 321 | |
Jaeden Amero | 44a59ab | 2019-02-11 13:24:47 +0000 | [diff] [blame] | 322 | #if defined(MBEDTLS_CHECK_PARAMS) |
| 323 | #include "mbedtls/platform_util.h" |
| 324 | void mbedtls_param_failed( const char *failure_condition, |
| 325 | const char *file, |
| 326 | int line ) |
| 327 | { |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 328 | printf( "%s:%i: Input param failed - %s\n", |
Jaeden Amero | 44a59ab | 2019-02-11 13:24:47 +0000 | [diff] [blame] | 329 | file, line, failure_condition ); |
Jaeden Amero | fa30c33 | 2018-12-21 18:42:18 +0000 | [diff] [blame] | 330 | exit( EXIT_FAILURE ); |
Jaeden Amero | 44a59ab | 2019-02-11 13:24:47 +0000 | [diff] [blame] | 331 | } |
| 332 | #endif |
| 333 | |
itayzafrir | a3ff8a6 | 2018-07-10 10:10:21 +0300 | [diff] [blame] | 334 | int main( void ) |
| 335 | { |
itayzafrir | 1036670 | 2018-07-11 13:44:41 +0300 | [diff] [blame] | 336 | ASSERT( psa_crypto_init( ) == PSA_SUCCESS ); |
| 337 | cipher_examples( ); |
| 338 | exit: |
| 339 | mbedtls_psa_crypto_free( ); |
itayzafrir | a3ff8a6 | 2018-07-10 10:10:21 +0300 | [diff] [blame] | 340 | return( 0 ); |
| 341 | } |
itayzafrir | 18ac331 | 2018-07-17 09:28:11 +0300 | [diff] [blame] | 342 | #endif /* MBEDTLS_PSA_CRYPTO_C && MBEDTLS_AES_C && MBEDTLS_CIPHER_MODE_CBC && |
| 343 | MBEDTLS_CIPHER_MODE_CTR && MBEDTLS_CIPHER_MODE_WITH_PADDING */ |