Skip to content

Support mbedtls crypto library #2345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from

Conversation

edison-ai
Copy link

Pull request for mbedtls crypto supporting again here.
The mbedtls source path is "lib/libmebdtls" which is same as TA's.

@@ -0,0 +1,3 @@
cflags-lib-$(CFG_CRYPTO_SIZE_OPTIMIZATION) += -Os

subdirs-y += src
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we put everything below lib/libmbedtls instead, having two different libmbedtls directories will be confusing.

The src directory will be core only we, so we could rename it to core and make this line:

subdirs-$(sm-core) += core

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be better to remove that confuse. I will update as that.

@@ -0,0 +1,29 @@
/* SPDX-License-Identifier: BSD-2-Clause */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a libmbedtls/include/mbedtls_config_kernel.h, please put the content of this file there instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I will update it.

@edison-ai
Copy link
Author

@jenswi-linaro Update. But I do not know why the patch sequences are disorder. The patch "libmbedtls: configure mbedTLS for user mode TA" should be the first.

@jforissier
Copy link
Contributor

@edison-ai it's OK, GitHub shows the commits in chronological order, which is not always parent/child order.

@edison-ai
Copy link
Author

@jforissier OK, got. Thanks your explanation.

SRCS += sha256.c
SRCS += sha512.c

srcs-y += $(addprefix ../mbedtls/library/, $(SRCS))
Copy link
Contributor

@jenswi-linaro jenswi-linaro May 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we did this in lib/libmbedtls/sub.mk.
lib/libmbedtls/sub.mk will need to be restructured a bit. We could do it a bit like:

SRCS_CRYPTO :=
SRCS_CRYPTO += aes.c
...
SRCS_X509 :=
SRCS_X509 +=  certs.c
...
SRCS_TLS :=
SRCS_TLS += debug.c
...
srcs-y += $(addprefix mbedtls/library/, $(SRCS_CRYPTO))
srcs-$(sm-$(ta-target)) += $(addprefix mbedtls/library/, $(SRCS_X509))
srcs-$(sm-$(ta-target)) += $(addprefix mbedtls/library/, $(SRCS_TLS))

It doesn't matter if a few too many files are included as it's the lib/libmbedtls/include/mbedtls_config_kernel.h and lib/libmbedtls/include/mbedtls_config_uta.h files that controls what's really compiled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter if a few too many files are included as it's the lib/libmbedtls/include/mbedtls_config_kernel.h and lib/libmbedtls/include/mbedtls_config_uta.h files that controls what's really compiled.

By that logic, why not add all the files as it's done currently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By that logic, why not add all the files as it's done currently

Fine with me, if we think it adds too much time to compiling we can address that then.

@edison-ai
Copy link
Author

edison-ai commented Jun 19, 2018

@jenswi-linaro Any update?

@jenswi-linaro
Copy link
Contributor

@edison-ai, I was actually going to ask you the same question. :-)
I'd like to get the sub.mk stuff sorted out first.

@edison-ai
Copy link
Author

@jenswi-linaro Sorry for that I had a few mistake to understand what your meaning. Of course I agree with your suggestion, and I will push a new version to refine it.

@edison-ai
Copy link
Author

Update and re-base it on newest master branch.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for "libmbedtls: support mbedTLS in kernel mode"

@@ -88,3 +88,7 @@ srcs-$(sm-$(ta-target)) += $(addprefix mbedtls/library/, $(SRCS_TLS))
cflags-lib-y += -Wno-redundant-decls
cflags-lib-y += -Wno-switch-default
cflags-lib-$(CFG_ULIBS_GPROF) += -pg

cflags-lib-$(sm-core) += -Wno-pedantic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a workaround for the "empty translation unit" errors in lib/libmbedtls/mbedtls/include/mbedtls/check_config.h, please use that instead by including that file from ib/libmbedtls/include/mbedtls_config_kernel.h just as in lib/libmbedtls/include/mbedtls_config_uta.h

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this will be better.

@jenswi-linaro
Copy link
Contributor

When compiling "libmbedtls: support mbedTLS in kernel mode", I get the following error:

lib/libmbedtls/core/tee_lmd_provider.c:559:12: error: no previous prototype for ‘crypto_rng_add_entropy’ [-Werror=missing-prototypes]
 TEE_Result crypto_rng_add_entropy(const uint8_t *inbuf __unused,
            ^~~~~~~~~~~~~~~~~~~~~~
lib/libmbedtls/core/tee_lmd_provider.c:579:12: error: no previous prototype for ‘rng_generate’ [-Werror=missing-prototypes]
 TEE_Result rng_generate(void *buffer __unused, size_t len __unused)
            ^~~~~~~~~~~~

@jenswi-linaro
Copy link
Contributor

When compiling the entire PR I get:

lib/libmbedtls/core/tee_lmd_provider.c: In function ‘crypto_acipher_rsaes_decrypt’:
lib/libmbedtls/core/tee_lmd_provider.c:1014:60: error: passing argument 5 of ‘pk_info->decrypt_func’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   lmd_res = pk_info->decrypt_func(&rsa, src, src_len, buf, &blen,
                                                            ^
lib/libmbedtls/core/tee_lmd_provider.c:1014:60: note: expected ‘size_t * {aka unsigned int *}’ but argument is of type ‘long unsigned int *’
lib/libmbedtls/core/tee_lmd_provider.c:1017:60: error: passing argument 5 of ‘pk_info->decrypt_func’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   lmd_res = pk_info->decrypt_func(&rsa, src, src_len, buf, &blen,
                                                            ^
lib/libmbedtls/core/tee_lmd_provider.c:1017:60: note: expected ‘size_t * {aka unsigned int *}’ but argument is of type ‘long unsigned int *’

@edison-ai
Copy link
Author

@jenswi-linaro For the second compiling error, I cannot reappear it on my side. Is it relative with gcc version? Which version of gcc you are using?

@jenswi-linaro
Copy link
Contributor

It's a type mismatch, blen should be of type size_t instead.

@edison-ai
Copy link
Author

@jenswi-linaro Update, I had fix the 3 issue mentioned above.

@jenswi-linaro
Copy link
Contributor

With 6e954a6 ("core: add new RNG implementation") is core/crypto/rng_*.c responsible to provide RNG. Crypto libraries should themselves use crypto_rng_read() to get random when needed. So "libmbedtls: support mbedtls PRNG function" isn't needed any longer. I suppose some internal wrapper function in mbedtls will be needed to use crypto_rng_read() instead of what's used previously.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With my comment addressed, for these commits
907b555 ("libmbedtls: support mbedtls hash algorithm")
9fc0bb5 ("libmbedtls: support mbedTLS in kernel mode")
33cffad ("libmbedtls: configure mbedTLS for different modes")
please apply:
Reviewed-by: Jens Wiklander <[email protected]>

/******************************************************************************
* Pseudo Random Number Generator
******************************************************************************/
TEE_Result __weak crypto_rng_read(void *buf __unused, size_t blen __unused)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't belong ere any more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will remove PRNG patch.

@jenswi-linaro
Copy link
Contributor

ae549da ("libmbedtls: add interfaces in mbedtls for context memory operation")
is a change to upstream and need to go via the branch import/mbedtls-2.6.1 for proper bookkeeping, I'll take care of that when we're merging the rest of these changes (I hope that you will drive the work to try to upstream this though).
As an example check out
c6672fd ("libmbedtls: refine mbedtls license header")

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for "libmbedtls: support symmetrical ciphers"

/*
* Get the Mbedtls chipher info given a TEE Algorithm "algo"
* Return
* - TEE_SUCCESS in case of success,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pointer to a valid mbedtls_cipher_definition_t on success

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix it.

#if defined(_CFG_CRYPTO_WITH_CIPHER) || defined(_CFG_CRYPTO_WITH_MAC) || \
defined(_CFG_CRYPTO_WITH_AUTHENC)
/*
* Get the Mbedtls chipher info given a TEE Algorithm "algo"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/chipher/cipher/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix it.

static const mbedtls_cipher_info_t *get_cipher_info(uint32_t algo,
size_t key_len)
{
/* Only support key_length is 128 bits of AES in Optee_os */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't make sense of this comment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should be deleted. I will fix it.

switch (algo) {
#if defined(CFG_CRYPTO_ECB)
case TEE_ALG_AES_ECB_NOPAD:
cipher_info = get_cipher_info(algo, 128);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 128 as key size?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs cipher_info to allocate context operation for mbedTLS cipher ctx. For getting cipher info, it need to know the key size. But the key size is not provided yet, it will be provided in init function. So, here, we only use 128 as a default key length. It will be ok, for the mbedtls_cipher_base_t(used for allocate context) are same for all AES operate(different key length). I will add some comments in here.

if (cipher_info == NULL)
return TEE_ERROR_NOT_SUPPORTED;

lmd_res = mbedtls_cipher_setup_info(ctx, cipher_info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now we're changing cipher_info, this deserves a comment explaining why and how it's safe.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

EMSG("update failed, res is 0x%x", -lmd_res);
return TEE_ERROR_BAD_STATE;
}
lmd_res = mbedtls_cipher_finish(ctx, dst + olen, &finish_olen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining why we're doing mbedtls_cipher_reset() and mbedtls_cipher_finish() here, same for TEE_ALG_AES_CTR below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments doesn't answer the "why".

I was looking for something like:

/*
 * Do the mbedtls_cipher_reset(), mbedtls_cipher_update(), mbedtls_cipher_finish()
 * sequence to catch and report partial blocks early.
 */

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will use the comments as you suggest.

@jenswi-linaro
Copy link
Contributor

"libmbedtls: implement two AES interfaces" need to be split up in two separate commits, one with the changes outside mbedtls and one with the stuff inside tee_lmd_provider.c. If you rather fold the tee_lmd_provider.cchanges into some other suitable commit or not is up to you.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for "libmbedtls: support mbedtls HMAC algorithm"

case TEE_ALG_AES_CMAC:
res = TEE_ERROR_NOT_SUPPORTED;
break;
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant break

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix it.

if (res == TEE_SUCCESS)
*ctx_ret = ctx;
else
crypto_mac_free_ctx(ctx, algo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's safe to call this function unless mbedtls_md_setup() has succeeded.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mbedtls_md_free will check if the freed pointer is valid or not before free it. So it does not matter to do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the second allocation fails, then we'll have a double free.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second allocation inside mbedtls_md_setup(), that is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry for not reading code clearly.

res = TEE_ERROR_NOT_SUPPORTED;
}

if (res == TEE_SUCCESS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer doing the epilogue of this function as:

    *ctx_ret = ctx;
    return TEE_SUCCESS;
err:
    free(ctx);
    return res;

It's more like it's done in the Linux kernel and also at each point where we break out we know if it's because of an error or not so doing "goto err" wouldn't be harder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can do like that. But I still want to use crypto_mac_free_ctx() for err. Because there are may allocate operation in mbedtls_md_setup(), it maybe failed in middle process. So we need to call crypto_mac_free_ctx() to free allocated memory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, as discuss above, we should use free(ctx) here.
But I find another issue, caller will call crypto_mac_free_ctx() if crypto_mac_alloc_ctx() failed. it will cause double free for ctx, look this example:

res = crypto_mac_alloc_ctx(&ctx, hmac_algo);
if (res)
goto out;
/*
* RFC 5869 section 2.1: "Note that in the extract step, 'IKM' is used
* as the HMAC input, not as the HMAC key."
* Therefore, salt is the HMAC key in the formula from section 2.2:
* "PRK = HMAC-Hash(salt, IKM)"
*/
res = crypto_mac_init(ctx, hmac_algo, salt, salt_len);
if (res != TEE_SUCCESS)
goto out;
res = crypto_mac_update(ctx, hmac_algo, ikm, ikm_len);
if (res != TEE_SUCCESS)
goto out;
res = crypto_mac_final(ctx, hmac_algo, prk, *prk_len);
if (res != TEE_SUCCESS)
goto out;
res = tee_hash_get_digest_size(hash_algo, prk_len);
out:
crypto_mac_free_ctx(ctx, hmac_algo);
return res;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling crypto_mac_free_ctx() on a ctx being NULL is harmless, it's even preferred over testing if ctx is NULL or not before calling the function.

If I would have written that function, I would have returned on the crypto_mac_alloc_ctx() error instead of doing a goto. However, this is a matter of taste so we leave that to the author.

You're free to do the function epilogue as you like, I just think what I proposed instead is less complicated.

Copy link
Author

@edison-ai edison-ai Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got, thanks for your explanation.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for "libmbedtls: support CMAC algorithm"

if (!cipher_info)
return TEE_ERROR_NOT_SUPPORTED;

lmd_res = mbedtls_cipher_setup_info(ctx, cipher_info);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please comment why it's safe to change cipher_info here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@@ -1138,8 +1143,22 @@ TEE_Result crypto_mac_alloc_ctx(void **ctx_ret, uint32_t algo)
#endif
#if defined(CFG_CRYPTO_CMAC)
case TEE_ALG_AES_CMAC:
res = TEE_ERROR_NOT_SUPPORTED;
break;
cipher_info = get_cipher_info(TEE_ALG_AES_ECB_NOPAD, 128);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why keysize 128?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment as above.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments for "libmbedtls: support mbedtls bignum functions"

assert(b != NULL);
ret = mbedtls_mpi_cmp_mpi((const mbedtls_mpi *)a,
(const mbedtls_mpi *)b);
if (ret < 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where CMP_TRILEAN() is handy, compare (pardon the pun) with:
return CMP_TRILEAN(ret, 0);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it will be better. I will fix it.

assert(a != NULL);
assert(b != NULL);
ret = mbedtls_mpi_cmp_mpi((const mbedtls_mpi *)a,
(const mbedtls_mpi *)b);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please align with the opening ( above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will fix it.

return NULL;
mbedtls_mpi_init(bn);
if (mbedtls_mpi_grow(bn, BITS_TO_LIMBS(size_bits)) != 0)
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bn leakage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I do not understand why you say it.
mbedtls_mpi_grow() will allocate a new buffer if the older is not enough, and swap them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bn is just allocated with calloc(), if we return NULL here without freeing bn we have a memory leak.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will add free(bn) here.

struct bignum *crypto_bignum_allocate(size_t size_bits __unused)
#define ciL (sizeof(mbedtls_mpi_uint)) /* chars in limb */
#define biL (ciL << 3) /* bits in limb */
#define biH (ciL << 2) /* half limb size */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This define seems unused

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, only biH is unused and I will delete it. ciL and biL are used in BITS_TO_LIMBS.

@jenswi-linaro
Copy link
Contributor

Bignum allocations should use the <mempool.h> interface to be able to guarantee that symmetric cipher operations don't fail due to out of memory. The normal heap used via malloc() and friends can't make such guarantees. This guarantee is a requirement for GP compliance.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments for "libmbedtls: support mbedtls acipher RSA function"

lmd_res = mbedtls_rsa_public(&rsa, buf, buf);
switch (lmd_res) {
case MBEDTLS_ERR_RSA_BAD_INPUT_DATA:
EMSG("mbedtls_rsa_public() returned 0x%x", -lmd_res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a debug print that if kept should be made with FMSG

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

break;
default:
/* This will result in a panic */
EMSG("mbedtls_rsa_public() returned 0x%x", -lmd_res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMSG, if kept at all

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many EMSG in this PR, do I need to change all of them to FMSG?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All which are like this one.

case 0:
break;
default:
/* This will result in a panic */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic in the calling TA

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

Split mbedTLS into 3 partitions: CRYPTO, X509 and TLS. CRYPTO is for
kernel and user mode. X509 and TLS are mainly for user mode.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Edison Ai and others added 13 commits August 30, 2018 18:19
Adds support for symmetrical ciphers. The CTS and XTS modes
are not supported in mbedTLS and will be dealt with later.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
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.

Signed-off-by: Summer Qin <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
These two implement interfaces will be used by AES-GCM algo.

Signed-off-by: Summer Qin <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Implement HMAC function which based on mbedtls.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Implement CMAC function which based on mbedtls.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Implement bignum function which based on mbedtls.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Support RSA:
	RSASSA_PKCS1_V1_5
	RSASSA_PKCS1_PSS_MGF1
	RSAES_PKCS1_V1_5
	RSAES_PKCS1_OAEP_MGF1

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
This patch will be disscuss in branch "import/mbedtls-2.6.1" first.

In NO_CRT mode, Q and P may be invalid. But Q and P will be re-filled
again if PRNG function is valid. So add judgement process if it is
in NO_CRT mode.

Signed-off-by: Summer Qin <[email protected]>
Implement DH function which based on mbedtls.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
Support mbedtls ECC: ecdh and ecdsa.

Signed-off-by: Edison Ai <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
This patch will be disscuss in branch "import/mbedtls-2.6.1" first.

1. Add clone interface for GCM and CCM to support optee os.
2. Split ccm_auth_crypt() into 3 interfaces: mbedtls_ccm_starts(),
    mbedtls_ccm_update(), mbedtls_ccm_finish(). They are used to support
    optee interfaces. mbedTLS selftest and test_suite_ccm are all pass.

Signed-off-by: Edison Ai <[email protected]>
Implement CCM function which based on mbedtls.

Signed-off-by: Shawn Shan <[email protected]>
1. Split tomcrypt into two partitions, while tomcrypt_lite will
include the algos that mbedtls does not support.
2. Rename some crypto interfaces for distinguish them with
those in crypto.c.

Signed-off-by: Edison Ai <[email protected]>
@jbech-linaro
Copy link
Contributor

In IBART there are various aborts happening so it never ends the test suite and then after 600 seconds it time out and the test fails. I've tracked this PR and I've seen the same issue showing up, but for other PR's it is not happening so I suspect this would be reproducible on a local build also.

@edison-ai
Copy link
Author

@jbech-linaro Thanks for your information, I will try to reproduce it locally.

@edison-ai
Copy link
Author

@jenswi-linaro @jforissier , Sorry not to update it as soon as possible. for I am rushing for another things. I had try several time on local with newest optee os, client and test "master" breach, and all test are passed with no errors. So I have no idea for this "IBART" failed now. Do you have any suggest?

@jenswi-linaro
Copy link
Contributor

@edison-ai, are you still stuck on IBART?

@edison-ai
Copy link
Author

@jenswi-linaro Yes, I cannot reproduce the error on my side. So, if we can start the review process, and to see if can fix the IBART problem later?

@jenswi-linaro
Copy link
Contributor

So it's ready to be reviewed again (ignoring IBART)?

@edison-ai
Copy link
Author

@jenswi-linaro Yes,I had refine all the patches according your last comment. So you can continue to review them.

@jenswi-linaro
Copy link
Contributor

For "libmbedtls: support mbedtls ccm function" please apply:
Reviewed-by: Jens Wiklander <[email protected]>

@jenswi-linaro
Copy link
Contributor

Comments for "libmbedtls: support mbedtls unsupported algorithms":

libtomcrypt_lite is entirely an mbedTLS internal thing, there's no need to create a crypto_lite api or anything like that.
If mbedTLS isn't used then libtomcrypt_lite isn't either.
There's no changes needed in core/lib/libtomcrypt/src/tee_ltc_provider.c

@jenswi-linaro
Copy link
Contributor

If not not mistaken then only thing left in the PR is to fix "libmbedtls: support mbedtls unsupported algorithms".

Then we can take care of the stuff to merge in the branch import/mbedtls-2.6.1 and finally merge this.

@edison-ai
Copy link
Author

@jenswi-linaro Sorry for not reply this so long time because I am blocked by other things.
For libtomcrypt_lite, of course, if mbedTLS isn't used then libtomcrypt_lite isn't either. So, in your opinion, I should to call tomcrypt functions directly in tee_lmd_provider.c and only build the relative tomcrypt files?
Do you mean I should push those patches on import/mbedtls-2.6.1 now?

@jenswi-linaro
Copy link
Contributor

For libtomcrypt_lite, of course, if mbedTLS isn't used then libtomcrypt_lite isn't either. So, in your opinion, I should to call tomcrypt functions directly in tee_lmd_provider.c and only build the relative tomcrypt files?

Yes, that would probably be the best. I think we can accept some shortcuts here as I assume that mbedtls sooner or later will have the missing features.

Do you mean I should push those patches on import/mbedtls-2.6.1 now?

Please create a pull request against import/mbedtls-2.6.1 for the patches that should first go into that branch.

Also, please apply the last tags and rebase on master.

@edison-ai
Copy link
Author

OK, I will try to do as it and create a new PR to import/mbedtls-2.6.1.

@edison-ai
Copy link
Author

Move this PR to #2705. Close it now.

@edison-ai edison-ai closed this Dec 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants