Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Cipher API multi-part AEAD demonstration. |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 3 | * |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 4 | * This program AEAD-encrypts a message, using the algorithm and key size |
| 5 | * specified on the command line, using the multi-part API. |
| 6 | * |
Manuel Pégourié-Gonnard | 6fdc9e8 | 2022-01-31 13:27:39 +0100 | [diff] [blame] | 7 | * It comes with a companion program psa/aead_demo.c, which does the same |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 8 | * operations with the PSA Crypto API. The goal is that comparing the two |
| 9 | * programs will help people migrating to the PSA Crypto API. |
| 10 | * |
| 11 | * When used with multi-part AEAD operations, the `mbedtls_cipher_context` |
| 12 | * serves a triple purpose (1) hold the key, (2) store the algorithm when no |
| 13 | * operation is active, and (3) save progress information for the current |
| 14 | * operation. With PSA those roles are held by disinct objects: (1) a |
| 15 | * psa_key_id_t to hold the key, a (2) psa_algorithm_t to represent the |
| 16 | * algorithm, and (3) a psa_operation_t for multi-part progress. |
| 17 | * |
| 18 | * On the other hand, with PSA, the algorithms encodes the desired tag length; |
| 19 | * with Cipher the desired tag length needs to be tracked separately. |
| 20 | * |
Manuel Pégourié-Gonnard | 6fdc9e8 | 2022-01-31 13:27:39 +0100 | [diff] [blame] | 21 | * This program and its companion psa/aead_demo.c illustrate this by doing the |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 22 | * same sequence of multi-part AEAD computation with both APIs; looking at the |
| 23 | * two side by side should make the differences and similarities clear. |
| 24 | */ |
| 25 | |
| 26 | /* |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 27 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 28 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 29 | */ |
| 30 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 31 | /* First include Mbed TLS headers to get the Mbed TLS configuration and |
| 32 | * platform definitions that we'll use in this program. Also include |
| 33 | * standard C headers for functions we'll use here. */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 34 | #include "mbedtls/build_info.h" |
| 35 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 36 | #include "mbedtls/cipher.h" |
| 37 | |
Michael Schuster | 4595e68 | 2024-06-01 21:00:33 +0200 | [diff] [blame] | 38 | #include <test/helpers.h> |
| 39 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 40 | #include <stdlib.h> |
| 41 | #include <stdio.h> |
| 42 | #include <string.h> |
| 43 | |
| 44 | /* If the build options we need are not enabled, compile a placeholder. */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 45 | #if !defined(MBEDTLS_CIPHER_C) || \ |
| 46 | !defined(MBEDTLS_AES_C) || !defined(MBEDTLS_GCM_C) || \ |
| 47 | !defined(MBEDTLS_CHACHAPOLY_C) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 48 | int main(void) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 49 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 50 | printf("MBEDTLS_MD_C and/or " |
| 51 | "MBEDTLS_AES_C and/or MBEDTLS_GCM_C and/or " |
| 52 | "MBEDTLS_CHACHAPOLY_C not defined\r\n"); |
| 53 | return 0; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 54 | } |
| 55 | #else |
| 56 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 57 | /* The real program starts here. */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 58 | |
Manuel Pégourié-Gonnard | 64754e1 | 2022-02-08 11:21:14 +0100 | [diff] [blame] | 59 | const char usage[] = |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 60 | "Usage: cipher_aead_demo [aes128-gcm|aes256-gcm|aes128-gcm_8|chachapoly]"; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 61 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 62 | /* Dummy data for encryption: IV/nonce, additional data, 2-part message */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 63 | const unsigned char iv1[12] = { 0x00 }; |
| 64 | const unsigned char add_data1[] = { 0x01, 0x02 }; |
| 65 | const unsigned char msg1_part1[] = { 0x03, 0x04 }; |
| 66 | const unsigned char msg1_part2[] = { 0x05, 0x06, 0x07 }; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 67 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 68 | /* Dummy data (2nd message) */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 69 | const unsigned char iv2[12] = { 0x10 }; |
| 70 | const unsigned char add_data2[] = { 0x11, 0x12 }; |
| 71 | const unsigned char msg2_part1[] = { 0x13, 0x14 }; |
| 72 | const unsigned char msg2_part2[] = { 0x15, 0x16, 0x17 }; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 73 | |
Manuel Pégourié-Gonnard | 48bae02 | 2022-02-08 11:14:58 +0100 | [diff] [blame] | 74 | /* Maximum total size of the messages */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 75 | #define MSG1_SIZE (sizeof(msg1_part1) + sizeof(msg1_part2)) |
| 76 | #define MSG2_SIZE (sizeof(msg2_part1) + sizeof(msg2_part2)) |
| 77 | #define MSG_MAX_SIZE (MSG1_SIZE > MSG2_SIZE ? MSG1_SIZE : MSG2_SIZE) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 78 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 79 | /* Dummy key material - never do this in production! |
| 80 | * 32-byte is enough to all the key size supported by this program. */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 81 | const unsigned char key_bytes[32] = { 0x2a }; |
| 82 | |
Manuel Pégourié-Gonnard | 340808c | 2022-02-08 11:15:26 +0100 | [diff] [blame] | 83 | /* Run an Mbed TLS function and bail out if it fails. |
| 84 | * A string description of the error code can be recovered with: |
| 85 | * programs/util/strerror <value> */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 86 | #define CHK(expr) \ |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 87 | do \ |
| 88 | { \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 89 | ret = (expr); \ |
| 90 | if (ret != 0) \ |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 91 | { \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 92 | printf("Error %d at line %d: %s\n", \ |
| 93 | ret, \ |
| 94 | __LINE__, \ |
| 95 | #expr); \ |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 96 | goto exit; \ |
| 97 | } \ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 98 | } while (0) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 99 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 100 | /* |
| 101 | * Prepare encryption material: |
| 102 | * - interpret command-line argument |
| 103 | * - set up key |
| 104 | * - outputs: context and tag length, which together hold all the information |
| 105 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 106 | static int aead_prepare(const char *info, |
| 107 | mbedtls_cipher_context_t *ctx, |
| 108 | size_t *tag_len) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 109 | { |
| 110 | int ret; |
| 111 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 112 | /* Convert arg to type + tag_len */ |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 113 | mbedtls_cipher_type_t type; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 114 | if (strcmp(info, "aes128-gcm") == 0) { |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 115 | type = MBEDTLS_CIPHER_AES_128_GCM; |
| 116 | *tag_len = 16; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 117 | } else if (strcmp(info, "aes256-gcm") == 0) { |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 118 | type = MBEDTLS_CIPHER_AES_256_GCM; |
| 119 | *tag_len = 16; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 120 | } else if (strcmp(info, "aes128-gcm_8") == 0) { |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 121 | type = MBEDTLS_CIPHER_AES_128_GCM; |
| 122 | *tag_len = 8; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 123 | } else if (strcmp(info, "chachapoly") == 0) { |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 124 | type = MBEDTLS_CIPHER_CHACHA20_POLY1305; |
| 125 | *tag_len = 16; |
| 126 | } else { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 127 | puts(usage); |
| 128 | return MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 131 | /* Prepare context for the given type */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 132 | CHK(mbedtls_cipher_setup(ctx, |
| 133 | mbedtls_cipher_info_from_type(type))); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 134 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 135 | /* Import key */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 136 | int key_len = mbedtls_cipher_get_key_bitlen(ctx); |
| 137 | CHK(mbedtls_cipher_setkey(ctx, key_bytes, key_len, MBEDTLS_ENCRYPT)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 138 | |
| 139 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 140 | return ret; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 143 | /* |
| 144 | * Print out some information. |
| 145 | * |
| 146 | * All of this information was present in the command line argument, but his |
| 147 | * function demonstrates how each piece can be recovered from (ctx, tag_len). |
| 148 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 149 | static void aead_info(const mbedtls_cipher_context_t *ctx, size_t tag_len) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 150 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 151 | mbedtls_cipher_type_t type = mbedtls_cipher_get_type(ctx); |
| 152 | const mbedtls_cipher_info_t *info = mbedtls_cipher_info_from_type(type); |
| 153 | const char *ciph = mbedtls_cipher_info_get_name(info); |
| 154 | int key_bits = mbedtls_cipher_get_key_bitlen(ctx); |
| 155 | mbedtls_cipher_mode_t mode = mbedtls_cipher_get_cipher_mode(ctx); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 156 | |
| 157 | const char *mode_str = mode == MBEDTLS_MODE_GCM ? "GCM" |
| 158 | : mode == MBEDTLS_MODE_CHACHAPOLY ? "ChachaPoly" |
| 159 | : "???"; |
| 160 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 161 | printf("%s, %d, %s, %u\n", |
| 162 | ciph, key_bits, mode_str, (unsigned) tag_len); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 165 | /* |
| 166 | * Encrypt a 2-part message. |
| 167 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 168 | static int aead_encrypt(mbedtls_cipher_context_t *ctx, size_t tag_len, |
| 169 | const unsigned char *iv, size_t iv_len, |
| 170 | const unsigned char *ad, size_t ad_len, |
| 171 | const unsigned char *part1, size_t part1_len, |
| 172 | const unsigned char *part2, size_t part2_len) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 173 | { |
| 174 | int ret; |
| 175 | size_t olen; |
Manuel Pégourié-Gonnard | ae1bae8 | 2022-02-08 11:36:28 +0100 | [diff] [blame] | 176 | #define MAX_TAG_LENGTH 16 |
| 177 | unsigned char out[MSG_MAX_SIZE + MAX_TAG_LENGTH]; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 178 | unsigned char *p = out; |
| 179 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 180 | CHK(mbedtls_cipher_set_iv(ctx, iv, iv_len)); |
| 181 | CHK(mbedtls_cipher_reset(ctx)); |
| 182 | CHK(mbedtls_cipher_update_ad(ctx, ad, ad_len)); |
| 183 | CHK(mbedtls_cipher_update(ctx, part1, part1_len, p, &olen)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 184 | p += olen; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 185 | CHK(mbedtls_cipher_update(ctx, part2, part2_len, p, &olen)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 186 | p += olen; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 187 | CHK(mbedtls_cipher_finish(ctx, p, &olen)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 188 | p += olen; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 189 | CHK(mbedtls_cipher_write_tag(ctx, p, tag_len)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 190 | p += tag_len; |
| 191 | |
| 192 | olen = p - out; |
Michael Schuster | 4595e68 | 2024-06-01 21:00:33 +0200 | [diff] [blame] | 193 | mbedtls_test_print_buf("out", out, olen); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 194 | |
| 195 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 196 | return ret; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 197 | } |
| 198 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 199 | /* |
| 200 | * AEAD demo: set up key/alg, print out info, encrypt messages. |
| 201 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 202 | static int aead_demo(const char *info) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 203 | { |
| 204 | int ret = 0; |
| 205 | |
| 206 | mbedtls_cipher_context_t ctx; |
| 207 | size_t tag_len; |
| 208 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 209 | mbedtls_cipher_init(&ctx); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 210 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 211 | CHK(aead_prepare(info, &ctx, &tag_len)); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 212 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 213 | aead_info(&ctx, tag_len); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 214 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 215 | CHK(aead_encrypt(&ctx, tag_len, |
| 216 | iv1, sizeof(iv1), add_data1, sizeof(add_data1), |
| 217 | msg1_part1, sizeof(msg1_part1), |
| 218 | msg1_part2, sizeof(msg1_part2))); |
| 219 | CHK(aead_encrypt(&ctx, tag_len, |
| 220 | iv2, sizeof(iv2), add_data2, sizeof(add_data2), |
| 221 | msg2_part1, sizeof(msg2_part1), |
| 222 | msg2_part2, sizeof(msg2_part2))); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 223 | |
| 224 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 225 | mbedtls_cipher_free(&ctx); |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 226 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 227 | return ret; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | /* |
| 232 | * Main function |
| 233 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 234 | int main(int argc, char **argv) |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 235 | { |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 236 | /* Check usage */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 237 | if (argc != 2) { |
| 238 | puts(usage); |
| 239 | return 1; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 240 | } |
| 241 | |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 242 | int ret; |
| 243 | |
| 244 | /* Run the demo */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 245 | CHK(aead_demo(argv[1])); |
Manuel Pégourié-Gonnard | 248b385 | 2022-01-31 12:56:39 +0100 | [diff] [blame] | 246 | |
| 247 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 248 | return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; |
Manuel Pégourié-Gonnard | 7d5ef17 | 2022-01-27 13:09:13 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | #endif |