Commit Graph

114 Commits

Author SHA1 Message Date
Kevin Bracey
a967a58ed3 [baremetal] Avoid narrow loop counters etc
Use `uint_fast8_t` instead of `unsigned char` in various loop-type
situations. This avoids the need for a 16 or 32-bit system to insert
explicit narrow-to-8-bit instructions.

Not the result of an exhaustive source analysis, rather inspecting
the disassembly output for a cut-down Cortex-M0+ build looking for
UXTB etc instructions, so there could well be more in the complete
configuration.

Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-11-06 10:56:16 +02:00
Shelly Liberman
8176022b22 Restore tinycrypt implementation of regularize_k()
The fix is required to prevent array overrun

Signed-off-by: Shelly Liberman <shelly.liberman@arm.com>
2020-10-26 17:35:49 +02:00
Andrzej Kurek
b04208151b
tinycrypt: make asm optimizations optional for baremetal
Disable asm optimizations for strict armcc baremetal builds.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-10-14 19:42:23 +02:00
Andrzej Kurek
db0e50ea70
Introduce MBEDTLS_OPTIMIZE_TINYCRYPT_ASM
Make the ASM optimizations in tinycrypt optional.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-10-14 14:32:50 +02:00
Andrzej Kurek
7e62c31097
Guard the tinycrypt code with MBEDTLS_USE_TINYCRYPT
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-10-14 12:02:40 +02:00
Kevin Bracey
8b2014bdb6 Add .syntax divided markers
Old GCC (pre-5?) natively use divided syntax, so we must put it back
after changing it.

More recent GCCs natively use unified syntax, and themselves are
surrounding our blocks with divided/unified directives for backwards
compatibility, so we don't need to restore for those.

Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-13 10:24:39 +03:00
Kevin Bracey
045e576e02 Adjust fixed-time arithmetic to not use boolean ops
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
99c64e142e Use builtin CLZ
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
3be252e252 vli_isZero and vli_clear assembly
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
4aea62569b More GCC assembly
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
06060330d8 Add GCC vli_rshift1 assembly
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
0a1884bba4 Use GCC extended assembler
Naked functions and basic assembler don't seem to work reliably - basic
assembler is assumed to not change registers or memory, and there does
not appear to be any special handling of naked functions in this regard.

Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
e0f88d5140 Add GCC/Clang muladd assembly
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
84f31d3eaa Optimise muladd more
Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Kevin Bracey
1959c18c69 tinycrypt: Add ARM assembler optimisations
For ARM Compiler 5 only, provide assembler versions of vli_add, vli_sub,
vli_rshift1 and muladd.

Signed-off-by: Kevin Bracey <kevin.bracey@arm.com>
2020-10-12 18:09:04 +03:00
Shelly Liberman
05beb9ac70 replace user rand by platform rand in ecc delays
Signed-off-by: Shelly Liberman <shelly.liberman@arm.com>
2020-09-16 18:58:50 +03:00
Piotr Nowicki
305a5ec496 Checking in critical places if secured memset() and memcpy() was successful
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
2020-08-12 15:22:20 +02:00
Piotr Nowicki
a6348edc23 Checking in critical places if the mbedtls_platform_zeroize() was successful
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
2020-08-12 15:12:20 +02:00
Andrzej Kurek
cf3e35cc58
Revert a part of sensitive information duplication from tinycrypt
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-07-15 22:32:30 -04:00
Andrzej Kurek
45e719983f
Minor formatting and cosmetic changes
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-07-08 10:09:44 -04:00
Andrzej Kurek
ca60937cf9
Add buffer and context clearing upon suspected FI
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-07-08 09:25:49 -04:00
Andrzej Kurek
0919b142b6
Formatting changes
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-07-06 15:28:59 -04:00
Andrzej Kurek
74f7d0f03d
Duplicate sensitive buffer and buffer length information
Detect FI attacks on buffer pointers and buffer lengths.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-07-06 14:28:12 -04:00
Andrzej Kurek
3a0df03364
Increase the Hamming distance of uECC_generate_random_int returns
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-06-12 06:32:13 -04:00
Andrzej Kurek
090365fe60
Improve the usage of uECC_RNG_Function
Since the mbed TLS implementation of rng wrapper returns the size of random
data generated upon success - check for it explicitly.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-06-08 11:00:51 -04:00
Andrzej Kurek
478b05c34c
Merge pull request #3355 from AndrzejKurek/fi_error_codes
Change the default value of status variables to an error
2020-06-08 08:57:33 +01:00
Andrzej Kurek
fd56f409b3
Change the default value of status variables to an error
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-06-05 12:26:07 -04:00
Andrzej Kurek
0da03c70e9
Merge pull request #3379 from AndrzejKurek/fi_check_loops
Add flow control to tinycrypt verification
2020-06-01 17:05:41 +01:00
Andrzej Kurek
e601bcee00
Add flow control to tinycrypt verification
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2020-06-01 07:31:15 -04:00
Piotr Nowicki
f0ab6d62ac Added some descriptions of functions
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
2020-05-27 15:35:44 +02:00
Piotr Nowicki
1a9d33e8c8 Start comparison from a random location in the uECC_vli_equal.
This increases security and increases resistance to the side channel leakage.

Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
2020-05-27 15:34:49 +02:00
Arto Kinnunen
10a2ffde5d Merge remote-tracking branch 'upstream/pr/2945' into baremetal
* upstream/pr/2945:
  Rename macro MBEDTLS_MAX_RAND_DELAY
  Update signature of mbedtls_platform_random_delay
  Replace mbedtls_platform_enforce_volatile_reads 2
  Replace mbedtls_platform_enforce_volatile_reads
  Add more variation to random delay countermeasure
  Add random  delay to enforce_volatile_reads
  Update comments of mbedtls_platform_random_delay
  Follow Mbed TLS coding style
  Add random delay function to platform_utils
2020-01-17 11:21:16 +02:00
Arto Kinnunen
ac6d226939 Update signature of mbedtls_platform_random_delay
Skip parameter and return value from mbedtls_platform_random_delay
to make it more resistant for FI attacks.
2020-01-09 10:19:07 +02:00
Simon Butcher
01d78fcefe Merge remote-tracking branch 'public/pr/2971' into baremetal 2020-01-08 18:10:44 +00:00
Arto Kinnunen
e91f0dc905 Replace mbedtls_platform_enforce_volatile_reads
Replace function mbedtls_platform_enforce_volatile_reads() with
mbedtls_platform_random_delay().
2020-01-07 10:47:58 +02:00
Teppo Järvelin
c2fa3eaa81 Removed dead code after optimization in tinycrypt 2020-01-05 12:02:37 +02:00
Teppo Järvelin
0b1d7d946d Coverity fix: dead error condition removed from ecc.c 2020-01-05 12:02:04 +02:00
Simon Butcher
1b370a63ec Merge remote-tracking branch 'public/pr/2960' into baremetal 2019-12-27 18:18:22 +00:00
Manuel Pégourié-Gonnard
a4b421819b Fix way to access the RNG for ECDSA counter-measures
Duplicating the g_rng_function variable in ecc_dsa.c means it's not the same
as set in ecc.c, resulting if no randomisation here. The proper way to access
the RNG function from outside ecc.c is uECC_get_rng(), so use that.

This is a side-port of upstream commit
87d74dd8d64a99aaa188961fe763d0841c5abfef

I've verified that there are no other occurrences (the duplication of
g_rng_function in ecc_dh.c had already been removed earlier when centralising
projective coordinate randomisation to mult_safer()).
2019-12-18 10:29:58 +01:00
Simon Butcher
e76c638d6f Merge remote-tracking branch 'public/pr/2925' into baremetal 2019-12-13 14:51:29 +00:00
Manuel Pégourié-Gonnard
645896e0ea Fix undefined order of volatile access
Found by the IAR compiler.

While at it, make 'diff' non-volatile in uECC_check_curve_integrity(), as
there is no good reason to make it volatile, and making it volatile only
increases the code size and the burden of defining access ordering.
2019-12-05 16:02:17 +01:00
Simon Butcher
5b45c6e1b3 Merge remote-tracking branch 'public/pr/2932' into baremetal 2019-12-05 14:32:31 +00:00
Jarno Lamsa
83d7881cec Make VS compiler happy
It doesn't seem to like using unary - to unsigned values.
2019-12-04 14:40:57 +02:00
Manuel Pégourié-Gonnard
231bf52691 Fix indentation level in one place 2019-11-28 12:22:43 +01:00
Manuel Pégourié-Gonnard
e1cb8846e7 Add loop integrity check to curve param check
Also make the reference result static const while at it.
2019-11-28 12:21:34 +01:00
Manuel Pégourié-Gonnard
5c3066a4f6 Add double-checking in some critical places 2019-11-27 13:01:10 +01:00
Manuel Pégourié-Gonnard
98e1fe0796 Add flow control in uECC_vli_equal loop 2019-11-27 12:52:54 +01:00
Manuel Pégourié-Gonnard
9d6a535ba1 Return and propagate UECC_FAULT_DETECTED
This commit first changes the return convention of EccPoint_mult_safer() so
that it properly reports when faults are detected. Then all functions that
call it need to be changed to (1) follow the same return convention and (2)
properly propagate UECC_FAULT_DETECTED when it occurs.

Here's the reverse call graph from EccPoint_mult_safer() to the rest of the
library (where return values are translated to the MBEDTLS_ERR_ space) and test
functions (where expected return values are asserted explicitly).

EccPoint_mult_safer()
    EccPoint_compute_public_key()
        uECC_compute_public_key()
            pkparse.c
            tests/suites/test_suite_pkparse.function
        uECC_make_key_with_d()
        uECC_make_key()
            ssl_cli.c
            ssl_srv.c
            tests/suites/test_suite_pk.function
            tests/suites/test_suite_tinycrypt.function
    uECC_shared_secret()
        ssl_tls.c
        tests/suites/test_suite_tinycrypt.function
    uECC_sign_with_k()
        uECC_sign()
            pk.c
            tests/suites/test_suite_tinycrypt.function

Note: in uECC_sign_with_k() a test for uECC_vli_isZero(p) is suppressed
because it is redundant with a more thorough test (point validity) done at the
end of EccPoint_mult_safer(). This redundancy was introduced in a previous
commit but not noticed earlier.
2019-11-26 12:54:06 +01:00
Manuel Pégourié-Gonnard
4d6186beb0 Rename ATTACK_DETECTED to FAULT_DETECTED
We don't know for sure it's an attack, it could be the hardware failing
randomly as well.
2019-11-26 12:54:06 +01:00
Manuel Pégourié-Gonnard
2b90961b8d Add integrity check for curve parameters
We don't really need a secure hash for that, something like CRC32 would
probably be enough - but we have SHA-256 handy, not CRC32, so use that for the
sake of simplicity.
2019-11-26 12:54:06 +01:00