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