aboutsummaryrefslogtreecommitdiff
path: root/core/crypto
AgeCommit message (Collapse)Author
2019-03-28core: crypto.c: don't use _CFG_CRYPTO_WITH_ACIPHERJens Wiklander
Uses CFG_CRYPTO_RSA, CFG_CRYPTO_DSA, CFG_CRYPTO_DH and CFG_CRYPTO_ECC to tell if bignum functions needs to be stubbed instead of relying on _CFG_CRYPTO_WITH_ACIPHER which is about to be removed. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-22core: add encrypt key length in AES encrypt APISummer Qin
Adds size of expanded AES encryption key to crypto_aes_expand_enc_key() and crypto_aes_enc_block() to make the functions more safe to call. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Summer Qin <summer.qin@arm.com> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-22core: crypto: move AES-CTS wrappers from libtomcrypt/ to crypto/Jens Wiklander
Moves the AES-CTS implementation from LTC wrapper to core/crypto. The AES-CTS implementation can be overridden in a crypto library by setting CFG_CRYPTO_CTS_FROM_CRYPTOLIB:=y Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-11core: crypto: introduce struct crypto_authenc_opsJens Wiklander
Uses struct crypto_authenc_ops pointer in crypto context for authenc ciphers (AES-GCM and AES-CCM) as a glue layer instead of a switch(algo) in each cryto_authenc_*() function. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-11core: crypto: introduce struct crypto_cipher_opsJens Wiklander
Uses struct crypto_cipher_ops pointer in crypto context for ciphers as a glue layer instead of a switch(algo) in each crypto_cipher_*() function. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-11core: crypto: introduce struct crypto_mac_opsJens Wiklander
Uses struct crypto_mac_ops pointer in crypto context for MACs as a glue layer instead of a switch(algo) in each crypto_mac_*() function. Moves CBC-MAC implementation from LTC wrapper to core/crypto. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-11core: implement crypto_cipher_get_block_size()Jens Wiklander
Prior to this patch only the prototype and a stub of crypto_cipher_get_block_size() was available. With this patch replace the stub with an implementation. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-03-11core: crypto: introduce struct crypto_hash_opsJens Wiklander
Uses struct crypto_hash_ops pointer in crypto context for hashes as a glue layer instead of a switch(algo) in each crypto_hash_*() function. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-02-25libutils: remove buf_compare_ct()Jerome Forissier
Now that we have consttime_memcmp(), buf_compare_ct() is redundant. Every time buf_compare_ct() is used, consttime_memcmp() may be used instead. This commit removes buf_compare_ct(). A compatibility wrapper is kept in <string_ext.h> to avoid knowingly breaking the build of any TA that may use it. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2019-02-25core: add VA overflow check in shdr_alloc_and_copy()Jerome Forissier
Make sure that no address overflow can occur when shdr_alloc_and_copy() copies the signed header. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reported-by: Bastien Simondi <bsimondi@netflix.com> [2.4] Reviewed-by: Joakim Bech <joakim.bech@linaro.org>
2019-01-21core: add missing return(s) in shdr_alloc_and_copyJoakim Bech
Fixes: "Incorrect error handling in shdr_alloc_and_copy (x2)" as reported by Riscure. Signed-off-by: Joakim Bech <joakim.bech@linaro.org> Tested-by: Joakim Bech <joakim.bech@linaro.org> (QEMU v7, v8) Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reported-by: Riscure <inforequest@riscure.com> Reported-by: Alyssa Milburn <a.a.milburn@vu.nl> Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
2018-06-18Remove get_rng_array()Jens Wiklander
Removes get_rng_array() in favor of crypto_rng_read() which always uses the configured RNG implementation to draw random. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-06-18core: add new RNG implementationJens Wiklander
Adds a new cryptographically secure pseudo random number generator known as Fortuna. The implementation is based on the description in [0]. This implementation replaces the implementation in LTC which was used until now. Gathering of entropy has been refined with crypto_rng_add_event() to better match how entropy is added to Fortuna. A enum crypto_rng_src identifies the source of the event. The source also controls how the event is added. There are two options available, queue it in a circular buffer for later processing or adding it directly to a pool. The former option is suitable when being called from an interrupt handler or some other place where RPC to normal world is forbidden. plat_prng_add_jitter_entropy_norpc() is removed and plat_prng_add_jitter_entropy() is updated to use this new entropy source scheme. The configuration of LTC is simplified by this, now PRNG is always drawn via prng_mpa_desc. plat_rng_init() takes care of initializing the PRNG in order to allow platforms to override or enhance the Fortuna integration. [0] Link:https://www.schneier.com/academic/paperfiles/fortuna.pdf Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-02-09core: crypto.c: crypto_*_free_ctx() stubs should allow NULL contextJerome Forissier
Update the crypto_*_free_ctx() functions so that they do nothing when passed a NULL ctx. Allows for easier error handling. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-01-11core: crypto.h manages authenc context memoryJens Wiklander
To ease integration with other crypto libraries change the authenc context interface in crypto.h to manage the memory used for the authenc context. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-01-11core: crypto.h manages cipher context memoryJens Wiklander
To ease integration with other crypto libraries change the cipher context interface in crypto.h to manage the memory used for the cipher context. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-01-11core: crypto.h manages mac context memoryJens Wiklander
To ease integration with other crypto libraries change the mac context interface in crypto.h to manage the memory used for the mac context. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-01-11core: crypto.h manages hash context memoryJens Wiklander
To ease integration with other crypto libraries change the hash context interface in crypto.h to manage the memory used for the hash context. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2018-01-10Add SPDX license identifiersJerome Forissier
Adds one SPDX-License-Identifier line [1] to each source files that contains license text. Generated by [2]: spdxify.py --add-spdx optee_os/ The scancode tool [3] was used to double check the license matching code in the Python script. All the licenses detected by scancode are either detected by spdxify.py, or have no SPDX identifier, or are false matches. Link: [1] https://spdx.org/licenses/ Link: [2] https://github.com/jforissier/misc/blob/f7b56c8/spdxify.py Link: [3] https://github.com/nexB/scancode-toolkit Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Joakim Bech <joakim.bech@linaro.org>
2018-01-10Reformat copyright/license header in files with an SPDX IDJerome Forissier
Some files were committed with an SPDX license identifier before the rules were defined [1]. Reformat them accordingly. [1] documentation/copyright_and_license_headers.rst Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Acked-by: Joakim Bech <joakim.bech@linaro.org>
2017-12-07core: crypto: add struct shdr helper functionsJens Wiklander
Adds struct shdr helper functions to allocate and verify a struct shdr. Reviewed-by: Volodymyr Babchuk <vlad.babchuk@gmail.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-27core/crypto/crypto.c: fix compile errors when _CFG_CRYPTO_WITH_CIPHER=nJerome Forissier
Although _CFG_CRYPTO_WITH_CIPHER=n does not seem to be a valid configuration (both the REE and RPMB FS use AES and at least one has to be enabled currently), fix build errors triggered by: make _CFG_CRYPTO_WITH_CIPHER=n \ out/arm-plat-vexpress/core/crypto/crypto.o Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-24core: crypto: AES-GCM: internal_aes_gcm_{enc,dec}()Jens Wiklander
Adds internal_aes_gcm_enc() and internal_aes_gcm_dec() for encrypting/decrypting a complete message with an external expanded key. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-24core: crypto: AES-GCM: separate encryption keyJens Wiklander
Separates the AES (CTR) encryption key from the rest of the context to allow more efficient key handling. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-24core: crypto: AES-GCM: remove tomcrypt.h dependencyJens Wiklander
Removes tomcrypt.h dependency by replacing the "symmetric_key skey" field in struct internal_aes_gcm_ctx with a raw key. Replaces calls to the LTC functions aes_setup() and aes_ecb_encrypt() with calls to crypto_aes_expand_enc_key() and crypto_aes_enc_block() respectively. Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-24core: AES-GCM: import table based GF-multJens Wiklander
Imports table based GF multiplication from mbed TLS. Sets CFG_AES_GCM_TABLE_BASED to default y unless CFG_CRYPTO_WITH_CE is y, then CFG_AES_GCM_TABLE_BASED forced n. With tables performance is on HiKey960 (CFG_CRYPTO_WITH_CE=n): xtest --aes-perf -m GCM (CFG_AES_GCM_TABLE_BASED=n) min=69.27us max=86.458us mean=70.5695us stddev=0.955826us (cv 1.35445%) (13.8383MiB/s) (CFG_AES_GCM_TABLE_BASED=y) min=41.666us max=53.646us mean=42.138us stddev=0.621345us (cv 1.47455%) (23.1753MiB/s) Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-20core: crypto: add new AES-GCM implementationJens Wiklander
Adds a new AES-GCM implementation optimized for hardware acceleration. This implementation is enabled by default, to use the implementation in libTomCrypt instead set CFG_CRYPTO_AES_GCM_FROM_CRYPTOLIB=y. Tested-by: Jerome Forissier <jerome.forissier@linaro.org> (HiKey960) Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14core: move crypto_authenc_*() from LTCJens Wiklander
* Moves crypto_authenc_*() from LTC to core/crypto/crypto.c * Defines <crypto/aes-gcm.h> and <crypto/aes-ccm.h> and implements the functions in core/lib/libtomcrypt/src/tee_ltc_provider.c based on the old implementations of crypto_authenc_*(). Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14core: rename to <crypto/crypto.h>Jens Wiklander
Renames core/include/tee/tee_cryp_provider.h to core/include/crypto/crypto.h Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct acipher_ops with function interfaceJens Wiklander
Adds crypto_acipher_*() replacing struct acipher_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct bignum_ops with function interfaceJens Wiklander
Adds crypto_bignum_*() replacing struct bignum_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct authenc_ops with function interfaceJens Wiklander
Adds crypto_authenc_*() replacing struct authenc_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct mac_ops with function interfaceJens Wiklander
Adds mac_cipher_get_ctx_size(), mac_cipher_init(), mac_cipher_update() and mac_cipher_final() replacing struct mac_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct cipher_ops with function interfaceJens Wiklander
Adds crypto_cipher_get_ctx_size(), crypto_cipher_init(), crypto_cipher_update(), crypto_cipher_final() and crypto_cipher_get_block_size() replacing struct cipher_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
2017-11-14Replace struct hash_ops with function interfaceJens Wiklander
Adds crypto_hash_get_ctx_size(), crypto_hash_init(), crypto_hash_update() and crypto_hash_final() replacing struct hash_ops in crypto_ops. Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>