1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

Changes after code review

Signed-off-by: TRodziewicz <tomasz.rodziewicz@mobica.com>
This commit is contained in:
TRodziewicz
2021-05-25 15:15:57 +02:00
parent caf2ae04b8
commit 062f353804
15 changed files with 29 additions and 179 deletions

View File

@ -1,10 +1,11 @@
Remove MBEDTLS_CHECK_PARAMS option
----------------------------------
This change affects the way of how parameters are validated.
This change does not affect users who use the default configuration; it only
affects users who enabled that option.
The option `MBEDTLS_CHECK_PARAMS` (disabled by default) enables certain kinds of
“parameter validation”. It covers two kinds of validations:
The option `MBEDTLS_CHECK_PARAMS` (disabled by default) enabled certain kinds
of “parameter validation”. It covered two kinds of validations:
- In some functions that require a valid pointer, “parameter validation” checks
that the pointer is non-null. With the feature disabled, a null pointer is not
@ -14,34 +15,17 @@ runtime crash. 90% of the uses of the feature are of this kind.
checks that the value is a valid one. With the feature disabled, an invalid
value causes a silent default to one of the valid values.
The default reaction to a failed check is to call a function mbedtls_param_failed
which the application must provide. If this function returns, its caller returns
an error `MBEDTLS_ERR_xxx_BAD_INPUT_DATA`.
The default reaction to a failed check was to call a function
`mbedtls_param_failed()` which the application had to provide. If this function
returned, its caller returned an error `MBEDTLS_ERR_xxx_BAD_INPUT_DATA`.
This feature is only used in some classic (non-PSA) cryptography modules. It is
not used in X.509, TLS or in PSA crypto, and it has not been implemented in all
This feature was only used in some classic (non-PSA) cryptography modules. It was
not used in X.509, TLS or in PSA crypto, and it was not implemented in all
classic crypto modules.
Removal of `MBEDTLS_CHECK_PARAMS` and all dependent features means changing
code that does something like this:
```
#if MBEDTLS_CHECK_PARAMS
#define VALIDATE(cond) do {if(cond) return BAD_INPUT_DATA;} while (0)
#else
#define VALIDATE(cond) do {} while (0)
#endif
...
VALIDATE(coin == HEADS || coin == TAILS);
VALIDATE(data != NULL);
if (coin == HEADS) heads();
else tails();
```
to something like this:
```
if (coin == HEADS) heads();
else if (coin == TAILS) tails();
else return BAD_INPUT_DATA;
```
This feature has been removed. The library no longer checks for NULL pointers;
checks for enum-like arguments will be kept or re-introduced on a case-by-case
basis, but their presence will no longer be dependent on a compile-time option.
Validation of enum-like values is somewhat useful, but not extremely important,
because the parameters concerned are usually constants in applications.