[Nuvoton] Fix crypto AC management
1. For SHA AC, use atomic flag to manage its ownership.
   (1) Nuvoton SHA AC doesn't support SHA context save & restore, so S/W
       SHA fallback has been supported before. To make non-blocking 'acquire'
       semantics clearer, introduce 'try_acquire' to substitute for 'acquire'.
   (2) No biting CPU due to mechanism above.
   (3) No deadlock due to mechanism above.
2. For AES/DES/ECC AC, change to mutex to manage their ownership.
   (1) Change crypto-misc.c to crypto-misc.cpp to utilize C++ SingletonPtr
       which guarantees thread-safe mutex construct-on-first-use.
   (2) With change to crypto-misc.cpp, add 'extern "C"' modifier to CRYPTO_IRQHandler()
       to avoid name mangling in C++.
   (3) No priority inversion because mutex has osMutexPrioInherit attribute
       bit set.
   (4) No deadlock because these AC are all locked for a short sequence
       of operations rather than the whole lifetime of mbedtls context.
   (5) For double mbedtls_internal_ecp_init() issue, it has been fixed in upper
       mbedtls layer. So no need to change ecc init/free flow.
ls
1 parent b16b1db commit ca4467508642f7fa1c7b54806155d178a8b53f83
@ccli8 ccli8 authored on 5 Dec 2018
Showing 16 changed files
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/aes/aes_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/des/des_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/ecp/ecp_internal_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha1_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha256_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_M480/sha/sha512_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/aes/aes_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/des/des_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha1_alt.c
View
features/mbedtls/targets/TARGET_NUVOTON/TARGET_NUC472/sha/sha256_alt.c
View
targets/TARGET_NUVOTON/TARGET_M480/crypto/crypto-misc.c 100644 → 0
View
targets/TARGET_NUVOTON/TARGET_M480/crypto/crypto-misc.cpp 0 → 100644
View
targets/TARGET_NUVOTON/TARGET_M480/crypto/crypto-misc.h
View
targets/TARGET_NUVOTON/TARGET_NUC472/crypto/crypto-misc.c 100644 → 0
View
targets/TARGET_NUVOTON/TARGET_NUC472/crypto/crypto-misc.cpp 0 → 100644
View
targets/TARGET_NUVOTON/TARGET_NUC472/crypto/crypto-misc.h