Bence Szépkúti | 8697465 | 2020-06-15 11:59:37 +0200 | [diff] [blame] | 1 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 2 | * Copyright The Mbed TLS Contributors |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +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. |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 18 | #include <test/constant_flow.h> |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 19 | #include <test/helpers.h> |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 20 | #include <test/macros.h> |
| 21 | #include <string.h> |
| 22 | |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 23 | /*----------------------------------------------------------------------------*/ |
| 24 | /* Static global variables */ |
| 25 | |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 26 | #if defined(MBEDTLS_PLATFORM_C) |
| 27 | static mbedtls_platform_context platform_ctx; |
| 28 | #endif |
| 29 | |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 30 | mbedtls_test_info_t mbedtls_test_info; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 31 | |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 32 | /*----------------------------------------------------------------------------*/ |
| 33 | /* Helper Functions */ |
| 34 | |
Ronald Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 35 | int mbedtls_test_platform_setup( void ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 36 | { |
| 37 | int ret = 0; |
| 38 | #if defined(MBEDTLS_PLATFORM_C) |
| 39 | ret = mbedtls_platform_setup( &platform_ctx ); |
| 40 | #endif /* MBEDTLS_PLATFORM_C */ |
| 41 | return( ret ); |
| 42 | } |
| 43 | |
Ronald Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 44 | void mbedtls_test_platform_teardown( void ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 45 | { |
| 46 | #if defined(MBEDTLS_PLATFORM_C) |
| 47 | mbedtls_platform_teardown( &platform_ctx ); |
| 48 | #endif /* MBEDTLS_PLATFORM_C */ |
| 49 | } |
| 50 | |
Gilles Peskine | 881447d | 2022-12-08 15:24:52 +0100 | [diff] [blame] | 51 | int mbedtls_test_ascii2uc(const char c, unsigned char *uc) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 52 | { |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 53 | if( ( c >= '0' ) && ( c <= '9' ) ) |
| 54 | *uc = c - '0'; |
| 55 | else if( ( c >= 'a' ) && ( c <= 'f' ) ) |
| 56 | *uc = c - 'a' + 10; |
| 57 | else if( ( c >= 'A' ) && ( c <= 'F' ) ) |
| 58 | *uc = c - 'A' + 10; |
| 59 | else |
| 60 | return( -1 ); |
| 61 | |
| 62 | return( 0 ); |
| 63 | } |
| 64 | |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 65 | void mbedtls_test_fail( const char *test, int line_no, const char* filename ) |
| 66 | { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 67 | if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ) |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 68 | { |
| 69 | /* We've already recorded the test as having failed. Don't |
| 70 | * overwrite any previous information about the failure. */ |
| 71 | return; |
| 72 | } |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 73 | mbedtls_test_info.result = MBEDTLS_TEST_RESULT_FAILED; |
| 74 | mbedtls_test_info.test = test; |
| 75 | mbedtls_test_info.line_no = line_no; |
| 76 | mbedtls_test_info.filename = filename; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 79 | void mbedtls_test_skip( const char *test, int line_no, const char* filename ) |
| 80 | { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 81 | mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SKIPPED; |
| 82 | mbedtls_test_info.test = test; |
| 83 | mbedtls_test_info.line_no = line_no; |
| 84 | mbedtls_test_info.filename = filename; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 85 | } |
| 86 | |
Chris Jones | a5ab765 | 2021-02-02 16:20:45 +0000 | [diff] [blame] | 87 | void mbedtls_test_set_step( unsigned long step ) |
| 88 | { |
| 89 | mbedtls_test_info.step = step; |
| 90 | } |
| 91 | |
Gilles Peskine | ca6e8aa | 2022-11-09 21:08:44 +0100 | [diff] [blame] | 92 | #if defined(MBEDTLS_BIGNUM_C) |
| 93 | unsigned mbedtls_test_case_uses_negative_0 = 0; |
| 94 | #endif |
| 95 | |
Chris Jones | a5ab765 | 2021-02-02 16:20:45 +0000 | [diff] [blame] | 96 | void mbedtls_test_info_reset( void ) |
| 97 | { |
| 98 | mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SUCCESS; |
| 99 | mbedtls_test_info.step = (unsigned long)( -1 ); |
| 100 | mbedtls_test_info.test = 0; |
| 101 | mbedtls_test_info.line_no = 0; |
| 102 | mbedtls_test_info.filename = 0; |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 103 | memset( mbedtls_test_info.line1, 0, sizeof( mbedtls_test_info.line1 ) ); |
| 104 | memset( mbedtls_test_info.line2, 0, sizeof( mbedtls_test_info.line2 ) ); |
Gilles Peskine | ca6e8aa | 2022-11-09 21:08:44 +0100 | [diff] [blame] | 105 | #if defined(MBEDTLS_BIGNUM_C) |
| 106 | mbedtls_test_case_uses_negative_0 = 0; |
| 107 | #endif |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int mbedtls_test_equal( const char *test, int line_no, const char* filename, |
| 111 | unsigned long long value1, unsigned long long value2 ) |
| 112 | { |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 113 | TEST_CF_PUBLIC( &value1, sizeof( value1 ) ); |
| 114 | TEST_CF_PUBLIC( &value2, sizeof( value2 ) ); |
| 115 | |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 116 | if( value1 == value2 ) |
| 117 | return( 1 ); |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 118 | |
Gilles Peskine | 89615ee | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 119 | if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ) |
| 120 | { |
| 121 | /* We've already recorded the test as having failed. Don't |
| 122 | * overwrite any previous information about the failure. */ |
| 123 | return( 0 ); |
| 124 | } |
| 125 | mbedtls_test_fail( test, line_no, filename ); |
| 126 | (void) mbedtls_snprintf( mbedtls_test_info.line1, |
| 127 | sizeof( mbedtls_test_info.line1 ), |
| 128 | "lhs = 0x%016llx = %lld", |
| 129 | value1, (long long) value1 ); |
| 130 | (void) mbedtls_snprintf( mbedtls_test_info.line2, |
| 131 | sizeof( mbedtls_test_info.line2 ), |
| 132 | "rhs = 0x%016llx = %lld", |
| 133 | value2, (long long) value2 ); |
| 134 | return( 0 ); |
Chris Jones | a5ab765 | 2021-02-02 16:20:45 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 137 | int mbedtls_test_le_u( const char *test, int line_no, const char* filename, |
| 138 | unsigned long long value1, unsigned long long value2 ) |
| 139 | { |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 140 | TEST_CF_PUBLIC( &value1, sizeof( value1 ) ); |
| 141 | TEST_CF_PUBLIC( &value2, sizeof( value2 ) ); |
| 142 | |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 143 | if( value1 <= value2 ) |
| 144 | return( 1 ); |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 145 | |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 146 | if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ) |
| 147 | { |
| 148 | /* We've already recorded the test as having failed. Don't |
| 149 | * overwrite any previous information about the failure. */ |
| 150 | return( 0 ); |
| 151 | } |
| 152 | mbedtls_test_fail( test, line_no, filename ); |
| 153 | (void) mbedtls_snprintf( mbedtls_test_info.line1, |
| 154 | sizeof( mbedtls_test_info.line1 ), |
| 155 | "lhs = 0x%016llx = %llu", |
| 156 | value1, value1 ); |
| 157 | (void) mbedtls_snprintf( mbedtls_test_info.line2, |
| 158 | sizeof( mbedtls_test_info.line2 ), |
| 159 | "rhs = 0x%016llx = %llu", |
| 160 | value2, value2 ); |
| 161 | return( 0 ); |
| 162 | } |
| 163 | |
| 164 | int mbedtls_test_le_s( const char *test, int line_no, const char* filename, |
| 165 | long long value1, long long value2 ) |
| 166 | { |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 167 | TEST_CF_PUBLIC( &value1, sizeof( value1 ) ); |
| 168 | TEST_CF_PUBLIC( &value2, sizeof( value2 ) ); |
| 169 | |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 170 | if( value1 <= value2 ) |
| 171 | return( 1 ); |
Gilles Peskine | bdc7b8b | 2022-09-20 18:31:30 +0200 | [diff] [blame] | 172 | |
Gilles Peskine | d146542 | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 173 | if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED ) |
| 174 | { |
| 175 | /* We've already recorded the test as having failed. Don't |
| 176 | * overwrite any previous information about the failure. */ |
| 177 | return( 0 ); |
| 178 | } |
| 179 | mbedtls_test_fail( test, line_no, filename ); |
| 180 | (void) mbedtls_snprintf( mbedtls_test_info.line1, |
| 181 | sizeof( mbedtls_test_info.line1 ), |
| 182 | "lhs = 0x%016llx = %lld", |
| 183 | (unsigned long long) value1, value1 ); |
| 184 | (void) mbedtls_snprintf( mbedtls_test_info.line2, |
| 185 | sizeof( mbedtls_test_info.line2 ), |
| 186 | "rhs = 0x%016llx = %lld", |
| 187 | (unsigned long long) value2, value2 ); |
| 188 | return( 0 ); |
| 189 | } |
| 190 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 191 | int mbedtls_test_unhexify( unsigned char *obuf, |
| 192 | size_t obufmax, |
| 193 | const char *ibuf, |
| 194 | size_t *len ) |
| 195 | { |
| 196 | unsigned char uc, uc2; |
| 197 | |
| 198 | *len = strlen( ibuf ); |
| 199 | |
| 200 | /* Must be even number of bytes. */ |
| 201 | if ( ( *len ) & 1 ) |
| 202 | return( -1 ); |
| 203 | *len /= 2; |
| 204 | |
| 205 | if ( (*len) > obufmax ) |
| 206 | return( -1 ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 207 | |
| 208 | while( *ibuf != 0 ) |
| 209 | { |
Gilles Peskine | 881447d | 2022-12-08 15:24:52 +0100 | [diff] [blame] | 210 | if ( mbedtls_test_ascii2uc( *(ibuf++), &uc ) != 0 ) |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 211 | return( -1 ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 212 | |
Gilles Peskine | 881447d | 2022-12-08 15:24:52 +0100 | [diff] [blame] | 213 | if ( mbedtls_test_ascii2uc( *(ibuf++), &uc2 ) != 0 ) |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 214 | return( -1 ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 215 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 216 | *(obuf++) = ( uc << 4 ) | uc2; |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 219 | return( 0 ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Ronald Cron | 72d628f | 2020-06-08 17:05:57 +0200 | [diff] [blame] | 222 | void mbedtls_test_hexify( unsigned char *obuf, |
| 223 | const unsigned char *ibuf, |
| 224 | int len ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 225 | { |
| 226 | unsigned char l, h; |
| 227 | |
| 228 | while( len != 0 ) |
| 229 | { |
| 230 | h = *ibuf / 16; |
| 231 | l = *ibuf % 16; |
| 232 | |
| 233 | if( h < 10 ) |
| 234 | *obuf++ = '0' + h; |
| 235 | else |
| 236 | *obuf++ = 'a' + h - 10; |
| 237 | |
| 238 | if( l < 10 ) |
| 239 | *obuf++ = '0' + l; |
| 240 | else |
| 241 | *obuf++ = 'a' + l - 10; |
| 242 | |
| 243 | ++ibuf; |
| 244 | len--; |
| 245 | } |
| 246 | } |
| 247 | |
Ronald Cron | 690f3eb | 2020-06-10 10:42:18 +0200 | [diff] [blame] | 248 | unsigned char *mbedtls_test_zero_alloc( size_t len ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 249 | { |
| 250 | void *p; |
| 251 | size_t actual_len = ( len != 0 ) ? len : 1; |
| 252 | |
| 253 | p = mbedtls_calloc( 1, actual_len ); |
| 254 | TEST_HELPER_ASSERT( p != NULL ); |
| 255 | |
| 256 | memset( p, 0x00, actual_len ); |
| 257 | |
| 258 | return( p ); |
| 259 | } |
| 260 | |
Ronald Cron | a256c70 | 2020-06-10 10:53:11 +0200 | [diff] [blame] | 261 | unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 262 | { |
| 263 | unsigned char *obuf; |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 264 | size_t len; |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 265 | |
| 266 | *olen = strlen( ibuf ) / 2; |
| 267 | |
| 268 | if( *olen == 0 ) |
Ronald Cron | 690f3eb | 2020-06-10 10:42:18 +0200 | [diff] [blame] | 269 | return( mbedtls_test_zero_alloc( *olen ) ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 270 | |
| 271 | obuf = mbedtls_calloc( 1, *olen ); |
| 272 | TEST_HELPER_ASSERT( obuf != NULL ); |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 273 | TEST_HELPER_ASSERT( mbedtls_test_unhexify( obuf, *olen, ibuf, &len ) == 0 ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 274 | |
| 275 | return( obuf ); |
| 276 | } |
| 277 | |
Ronald Cron | de70b16 | 2020-06-10 11:03:08 +0200 | [diff] [blame] | 278 | int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b, |
| 279 | uint32_t a_len, uint32_t b_len ) |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 280 | { |
| 281 | int ret = 0; |
| 282 | uint32_t i = 0; |
| 283 | |
| 284 | if( a_len != b_len ) |
| 285 | return( -1 ); |
| 286 | |
| 287 | for( i = 0; i < a_len; i++ ) |
| 288 | { |
| 289 | if( a[i] != b[i] ) |
| 290 | { |
| 291 | ret = -1; |
| 292 | break; |
| 293 | } |
| 294 | } |
| 295 | return ret; |
| 296 | } |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 297 | |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 298 | #if defined(MBEDTLS_TEST_HOOKS) |
| 299 | void mbedtls_test_err_add_check( int high, int low, |
| 300 | const char *file, int line ) |
| 301 | { |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 302 | /* Error codes are always negative (a value of zero is a success) however |
| 303 | * their positive opposites can be easier to understand. The following |
| 304 | * examples given in comments have been made positive for ease of |
| 305 | * understanding. The structure of an error code is such: |
| 306 | * |
Chris Jones | abded0e | 2021-04-12 15:44:47 +0100 | [diff] [blame] | 307 | * shhhhhhhhlllllll |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 308 | * |
| 309 | * s = sign bit. |
Chris Jones | 4f91d8d | 2021-04-23 12:07:25 +0100 | [diff] [blame] | 310 | * h = high level error code (includes high level module ID (bits 12..14) |
| 311 | * and module-dependent error code (bits 7..11)). |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 312 | * l = low level error code. |
| 313 | */ |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 314 | if ( high > -0x1000 && high != 0 ) |
| 315 | /* high < 0001000000000000 |
Chris Jones | 4f91d8d | 2021-04-23 12:07:25 +0100 | [diff] [blame] | 316 | * No high level module ID bits are set. |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 317 | */ |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 318 | { |
Chris Jones | fe285f5 | 2021-02-08 12:32:41 +0000 | [diff] [blame] | 319 | mbedtls_test_fail( "'high' is not a high-level error code", |
| 320 | line, file ); |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 321 | } |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 322 | else if ( high < -0x7F80 ) |
| 323 | /* high > 0111111110000000 |
Chris Jones | 860f509 | 2021-04-26 16:31:16 +0100 | [diff] [blame] | 324 | * Error code is greater than the largest allowed high level module ID. |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 325 | */ |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 326 | { |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 327 | mbedtls_test_fail( "'high' error code is greater than 15 bits", |
| 328 | line, file ); |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 329 | } |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 330 | else if ( ( high & 0x7F ) != 0 ) |
| 331 | /* high & 0000000001111111 |
| 332 | * Error code contains low level error code bits. |
| 333 | */ |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 334 | { |
Chris Jones | fe285f5 | 2021-02-08 12:32:41 +0000 | [diff] [blame] | 335 | mbedtls_test_fail( "'high' contains a low-level error code", |
| 336 | line, file ); |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 337 | } |
Chris Jones | e11e814 | 2021-04-22 15:28:56 +0100 | [diff] [blame] | 338 | else if ( low < -0x007F ) |
| 339 | /* low > 0000000001111111 |
| 340 | * Error code contains high or module level error code bits. |
| 341 | */ |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 342 | { |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 343 | mbedtls_test_fail( "'low' error code is greater than 7 bits", |
| 344 | line, file ); |
Chris Jones | a203c38 | 2021-01-29 14:56:20 +0000 | [diff] [blame] | 345 | } |
| 346 | else if ( low > 0 ) |
| 347 | { |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 348 | mbedtls_test_fail( "'low' error code is greater than zero", |
| 349 | line, file ); |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | #endif /* MBEDTLS_TEST_HOOKS */ |