Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * generic message digest layer demonstration program |
| 3 | * |
Manuel Pégourié-Gonnard | 6fb8187 | 2015-07-27 11:11:48 +0200 | [diff] [blame] | 4 | * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
| 6 | * |
| 7 | * This file is provided under the Apache License 2.0, or the |
| 8 | * GNU General Public License v2.0 or later. |
| 9 | * |
| 10 | * ********** |
| 11 | * Apache License 2.0: |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 12 | * |
| 13 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 14 | * not use this file except in compliance with the License. |
| 15 | * You may obtain a copy of the License at |
| 16 | * |
| 17 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 18 | * |
| 19 | * Unless required by applicable law or agreed to in writing, software |
| 20 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 21 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | * See the License for the specific language governing permissions and |
| 23 | * limitations under the License. |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 24 | * |
Bence Szépkúti | f744bd7 | 2020-06-05 13:02:18 +0200 | [diff] [blame^] | 25 | * ********** |
| 26 | * |
| 27 | * ********** |
| 28 | * GNU General Public License v2.0 or later: |
| 29 | * |
| 30 | * This program is free software; you can redistribute it and/or modify |
| 31 | * it under the terms of the GNU General Public License as published by |
| 32 | * the Free Software Foundation; either version 2 of the License, or |
| 33 | * (at your option) any later version. |
| 34 | * |
| 35 | * This program is distributed in the hope that it will be useful, |
| 36 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 | * GNU General Public License for more details. |
| 39 | * |
| 40 | * You should have received a copy of the GNU General Public License along |
| 41 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 42 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 43 | * |
| 44 | * ********** |
| 45 | * |
Manuel Pégourié-Gonnard | fe44643 | 2015-03-06 13:17:10 +0000 | [diff] [blame] | 46 | * This file is part of mbed TLS (https://tls.mbed.org) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 47 | */ |
| 48 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 49 | #if !defined(MBEDTLS_CONFIG_FILE) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 50 | #include "mbedtls/config.h" |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 51 | #else |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 52 | #include MBEDTLS_CONFIG_FILE |
Manuel Pégourié-Gonnard | cef4ad2 | 2014-04-29 12:39:06 +0200 | [diff] [blame] | 53 | #endif |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 54 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 55 | #if defined(MBEDTLS_PLATFORM_C) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 56 | #include "mbedtls/platform.h" |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 57 | #else |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 58 | #include <stdio.h> |
Andres Amaya Garcia | dabd78f | 2018-04-29 22:35:36 +0100 | [diff] [blame] | 59 | #include <stdlib.h> |
| 60 | #define mbedtls_fprintf fprintf |
| 61 | #define mbedtls_printf printf |
Manuel Pégourié-Gonnard | 3ef6a6d | 2018-12-10 14:31:45 +0100 | [diff] [blame] | 62 | #define mbedtls_exit exit |
Andres Amaya Garcia | 7d42965 | 2018-04-30 22:42:33 +0100 | [diff] [blame] | 63 | #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS |
Andres Amaya Garcia | dabd78f | 2018-04-29 22:35:36 +0100 | [diff] [blame] | 64 | #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE |
| 65 | #endif /* MBEDTLS_PLATFORM_C */ |
Rich Evans | f90016a | 2015-01-19 14:26:37 +0000 | [diff] [blame] | 66 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | #if defined(MBEDTLS_MD_C) && defined(MBEDTLS_FS_IO) |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 68 | #include "mbedtls/md.h" |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 69 | |
Rich Evans | 18b78c7 | 2015-02-11 14:06:19 +0000 | [diff] [blame] | 70 | #include <stdio.h> |
| 71 | #include <string.h> |
| 72 | #endif |
| 73 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | #if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_FS_IO) |
Rich Evans | 85b05ec | 2015-02-12 11:37:29 +0000 | [diff] [blame] | 75 | int main( void ) |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 76 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 77 | mbedtls_printf("MBEDTLS_MD_C and/or MBEDTLS_FS_IO not defined.\n"); |
Krzysztof Stachowiak | 3b0c430 | 2019-04-24 14:24:46 +0200 | [diff] [blame] | 78 | mbedtls_exit( 0 ); |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 79 | } |
| 80 | #else |
Manuel Pégourié-Gonnard | 3ef6a6d | 2018-12-10 14:31:45 +0100 | [diff] [blame] | 81 | |
Manuel Pégourié-Gonnard | 3ef6a6d | 2018-12-10 14:31:45 +0100 | [diff] [blame] | 82 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 83 | static int generic_wrapper( const mbedtls_md_info_t *md_info, char *filename, unsigned char *sum ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 84 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 85 | int ret = mbedtls_md_file( md_info, filename, sum ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 86 | |
| 87 | if( ret == 1 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 88 | mbedtls_fprintf( stderr, "failed to open: %s\n", filename ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 89 | |
| 90 | if( ret == 2 ) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 91 | mbedtls_fprintf( stderr, "failed to read: %s\n", filename ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 92 | |
| 93 | return( ret ); |
| 94 | } |
| 95 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 96 | static int generic_print( const mbedtls_md_info_t *md_info, char *filename ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 97 | { |
| 98 | int i; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | unsigned char sum[MBEDTLS_MD_MAX_SIZE]; |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 100 | |
| 101 | if( generic_wrapper( md_info, filename, sum ) != 0 ) |
| 102 | return( 1 ); |
| 103 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 104 | for( i = 0; i < mbedtls_md_get_size( md_info ); i++ ) |
| 105 | mbedtls_printf( "%02x", sum[i] ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 106 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 107 | mbedtls_printf( " %s\n", filename ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 108 | return( 0 ); |
| 109 | } |
| 110 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 111 | static int generic_check( const mbedtls_md_info_t *md_info, char *filename ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 112 | { |
| 113 | int i; |
| 114 | size_t n; |
| 115 | FILE *f; |
| 116 | int nb_err1, nb_err2; |
| 117 | int nb_tot1, nb_tot2; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 118 | unsigned char sum[MBEDTLS_MD_MAX_SIZE]; |
Paul Bakker | d1fe7aa | 2016-05-12 12:46:02 +0100 | [diff] [blame] | 119 | char line[1024]; |
Manuel Pégourié-Gonnard | 291f9af | 2013-10-28 12:51:32 +0100 | [diff] [blame] | 120 | char diff; |
Paul Bakker | d1fe7aa | 2016-05-12 12:46:02 +0100 | [diff] [blame] | 121 | #if defined(__clang_analyzer__) |
| 122 | char buf[MBEDTLS_MD_MAX_SIZE * 2 + 1] = { }; |
| 123 | #else |
| 124 | char buf[MBEDTLS_MD_MAX_SIZE * 2 + 1]; |
| 125 | #endif |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 126 | |
| 127 | if( ( f = fopen( filename, "rb" ) ) == NULL ) |
| 128 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 129 | mbedtls_printf( "failed to open: %s\n", filename ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 130 | return( 1 ); |
| 131 | } |
| 132 | |
| 133 | nb_err1 = nb_err2 = 0; |
| 134 | nb_tot1 = nb_tot2 = 0; |
| 135 | |
| 136 | memset( line, 0, sizeof( line ) ); |
| 137 | |
| 138 | n = sizeof( line ); |
| 139 | |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 140 | while( fgets( line, (int) n - 1, f ) != NULL ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 141 | { |
| 142 | n = strlen( line ); |
| 143 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 144 | if( n < (size_t) 2 * mbedtls_md_get_size( md_info ) + 4 ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 145 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 146 | mbedtls_printf("No '%s' hash found on line.\n", mbedtls_md_get_name( md_info )); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 147 | continue; |
| 148 | } |
| 149 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 150 | if( line[2 * mbedtls_md_get_size( md_info )] != ' ' || line[2 * mbedtls_md_get_size( md_info ) + 1] != ' ' ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 151 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 152 | mbedtls_printf("No '%s' hash found on line.\n", mbedtls_md_get_name( md_info )); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 153 | continue; |
| 154 | } |
| 155 | |
| 156 | if( line[n - 1] == '\n' ) { n--; line[n] = '\0'; } |
| 157 | if( line[n - 1] == '\r' ) { n--; line[n] = '\0'; } |
| 158 | |
| 159 | nb_tot1++; |
| 160 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 161 | if( generic_wrapper( md_info, line + 2 + 2 * mbedtls_md_get_size( md_info ), sum ) != 0 ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 162 | { |
| 163 | nb_err1++; |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | nb_tot2++; |
| 168 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 169 | for( i = 0; i < mbedtls_md_get_size( md_info ); i++ ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 170 | sprintf( buf + i * 2, "%02x", sum[i] ); |
| 171 | |
Manuel Pégourié-Gonnard | 291f9af | 2013-10-28 12:51:32 +0100 | [diff] [blame] | 172 | /* Use constant-time buffer comparison */ |
| 173 | diff = 0; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 174 | for( i = 0; i < 2 * mbedtls_md_get_size( md_info ); i++ ) |
Manuel Pégourié-Gonnard | 291f9af | 2013-10-28 12:51:32 +0100 | [diff] [blame] | 175 | diff |= line[i] ^ buf[i]; |
| 176 | |
| 177 | if( diff != 0 ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 178 | { |
| 179 | nb_err2++; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 180 | mbedtls_fprintf( stderr, "wrong checksum: %s\n", line + 66 ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | n = sizeof( line ); |
| 184 | } |
| 185 | |
| 186 | if( nb_err1 != 0 ) |
| 187 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 188 | mbedtls_printf( "WARNING: %d (out of %d) input files could " |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 189 | "not be read\n", nb_err1, nb_tot1 ); |
| 190 | } |
| 191 | |
| 192 | if( nb_err2 != 0 ) |
| 193 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 194 | mbedtls_printf( "WARNING: %d (out of %d) computed checksums did " |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 195 | "not match\n", nb_err2, nb_tot2 ); |
| 196 | } |
| 197 | |
Paul Bakker | 64abd83 | 2014-02-06 15:03:06 +0100 | [diff] [blame] | 198 | fclose( f ); |
| 199 | |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 200 | return( nb_err1 != 0 || nb_err2 != 0 ); |
| 201 | } |
| 202 | |
| 203 | int main( int argc, char *argv[] ) |
| 204 | { |
Andres Amaya Garcia | dabd78f | 2018-04-29 22:35:36 +0100 | [diff] [blame] | 205 | int ret = 1, i; |
| 206 | int exit_code = MBEDTLS_EXIT_FAILURE; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 207 | const mbedtls_md_info_t *md_info; |
| 208 | mbedtls_md_context_t md_ctx; |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 209 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 210 | mbedtls_md_init( &md_ctx ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 211 | |
| 212 | if( argc == 1 ) |
| 213 | { |
| 214 | const int *list; |
| 215 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 216 | mbedtls_printf( "print mode: generic_sum <mbedtls_md> <file> <file> ...\n" ); |
| 217 | mbedtls_printf( "check mode: generic_sum <mbedtls_md> -c <checksum file>\n" ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 218 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 219 | mbedtls_printf( "\nAvailable message digests:\n" ); |
| 220 | list = mbedtls_md_list(); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 221 | while( *list ) |
| 222 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 223 | md_info = mbedtls_md_info_from_type( *list ); |
| 224 | mbedtls_printf( " %s\n", mbedtls_md_get_name( md_info ) ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 225 | list++; |
| 226 | } |
| 227 | |
Paul Bakker | cce9d77 | 2011-11-18 14:26:47 +0000 | [diff] [blame] | 228 | #if defined(_WIN32) |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 229 | mbedtls_printf( "\n Press Enter to exit this program.\n" ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 230 | fflush( stdout ); getchar(); |
| 231 | #endif |
| 232 | |
Krzysztof Stachowiak | 3b0c430 | 2019-04-24 14:24:46 +0200 | [diff] [blame] | 233 | mbedtls_exit( exit_code ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Read the MD from the command line |
| 238 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 239 | md_info = mbedtls_md_info_from_string( argv[1] ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 240 | if( md_info == NULL ) |
| 241 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 242 | mbedtls_fprintf( stderr, "Message Digest '%s' not found\n", argv[1] ); |
Krzysztof Stachowiak | 3b0c430 | 2019-04-24 14:24:46 +0200 | [diff] [blame] | 243 | mbedtls_exit( exit_code ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 244 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 245 | if( mbedtls_md_setup( &md_ctx, md_info, 0 ) ) |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 246 | { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 247 | mbedtls_fprintf( stderr, "Failed to initialize context.\n" ); |
Krzysztof Stachowiak | 3b0c430 | 2019-04-24 14:24:46 +0200 | [diff] [blame] | 248 | mbedtls_exit( exit_code ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 249 | } |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 250 | |
| 251 | ret = 0; |
| 252 | if( argc == 4 && strcmp( "-c", argv[2] ) == 0 ) |
| 253 | { |
| 254 | ret |= generic_check( md_info, argv[3] ); |
| 255 | goto exit; |
| 256 | } |
| 257 | |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 258 | for( i = 2; i < argc; i++ ) |
| 259 | ret |= generic_print( md_info, argv[i] ); |
| 260 | |
Andres Amaya Garcia | dabd78f | 2018-04-29 22:35:36 +0100 | [diff] [blame] | 261 | if ( ret == 0 ) |
| 262 | exit_code = MBEDTLS_EXIT_SUCCESS; |
| 263 | |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 264 | exit: |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 265 | mbedtls_md_free( &md_ctx ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 266 | |
Krzysztof Stachowiak | 3b0c430 | 2019-04-24 14:24:46 +0200 | [diff] [blame] | 267 | mbedtls_exit( exit_code ); |
Paul Bakker | fb6c7e2 | 2011-01-21 10:21:11 +0000 | [diff] [blame] | 268 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 269 | #endif /* MBEDTLS_MD_C && MBEDTLS_FS_IO */ |