Skip to content
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

crypto: introduce CFG_CRYPTO_HW_PBKDF2 #6216

Merged
merged 1 commit into from
Sep 13, 2023
Merged

crypto: introduce CFG_CRYPTO_HW_PBKDF2 #6216

merged 1 commit into from
Sep 13, 2023

Conversation

loubaihui
Copy link

We add a new pbkdf2 implementation.

@loubaihui loubaihui changed the title core: add a new pbkdf2 implementation crypto: add a new pbkdf2 implementation Aug 3, 2023
@jenswi-linaro
Copy link
Contributor

How about just:

--- a/core/tee/sub.mk
+++ b/core/tee/sub.mk
@@ -21,7 +21,9 @@ srcs-y += entry_std.c
 srcs-y += tee_cryp_utl.c
 srcs-$(CFG_CRYPTO_HKDF) += tee_cryp_hkdf.c
 srcs-$(CFG_CRYPTO_CONCAT_KDF) += tee_cryp_concat_kdf.c
+ifneq($(CFG_CRYPTO_HW_PBKDF2),y)
 srcs-$(CFG_CRYPTO_PBKDF2) += tee_cryp_pbkdf2.c
+endif
 
 ifeq ($(CFG_WITH_USER_TA),y)
 srcs-y += tee_obj.c

instead?

We should also document the CFG_CRYPTO_HW_PBKDF2 flag, probably in mk/config.mk

@loubaihui
Copy link
Author

How about just:

--- a/core/tee/sub.mk
+++ b/core/tee/sub.mk
@@ -21,7 +21,9 @@ srcs-y += entry_std.c
 srcs-y += tee_cryp_utl.c
 srcs-$(CFG_CRYPTO_HKDF) += tee_cryp_hkdf.c
 srcs-$(CFG_CRYPTO_CONCAT_KDF) += tee_cryp_concat_kdf.c
+ifneq($(CFG_CRYPTO_HW_PBKDF2),y)
 srcs-$(CFG_CRYPTO_PBKDF2) += tee_cryp_pbkdf2.c
+endif
 
 ifeq ($(CFG_WITH_USER_TA),y)
 srcs-y += tee_obj.c

instead?

We should also document the CFG_CRYPTO_HW_PBKDF2 flag, probably in mk/config.mk

Sounds great, according to your suggestions, we made the revision.

@@ -112,3 +112,4 @@ TEE_Result tee_cryp_pbkdf2(uint32_t hash_id, const uint8_t *password,
crypto_mac_free_ctx(hmac_parms.ctx);
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.

Unrelated change.

@@ -42,4 +42,5 @@ srcs-$(CFG_CRYPTO_ECB) += sm4-ecb.c
srcs-$(CFG_CRYPTO_CBC) += sm4-cbc.c
srcs-$(CFG_CRYPTO_CTR) += sm4-ctr.c
srcs-$(CFG_CRYPTO_XTS) += sm4-xts.c
srcs-$(CFG_CRYPTO_HW_PBKDF2) += pbkdf2_hw.c
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 pbkdf2_hw.c or pbkdf2_support.h is needed at all. The hardware implementation can just implement the tee_cryp_pbkdf2()

Copy link
Author

Choose a reason for hiding this comment

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

Is that mean:
If the two files are not needed, the hardware implementation also put in tee_cryp_pbkdf2.c and use CFG_CRYPTO_HW_PBKDF2 to distinguish?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, a hardware non-stubbed implementation is provided in some other file.
It doesn't make sense to use a stubbed hardware implementation when a working software version is available.

Copy link
Author

@loubaihui loubaihui Sep 1, 2023

Choose a reason for hiding this comment

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

The hardware implementation will be different from the current software, we will use different hash algorithm etc.
So, I think the pbkdf2_hw.c and pbkdf2_support.h is necessary, specific implementation of hw_pbkdf2() function will be added in core/ drivers/crypto @jenswi-linaro

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean that the same input will yield different results? I don't see how a stubbed implementation helps against that.

Copy link
Author

@loubaihui loubaihui Sep 4, 2023

Choose a reason for hiding this comment

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

Do you mean that the same input will yield different results? I don't see how a stubbed implementation helps against that.

I'm sorry for misunderstanding your previous comment. Now, I got it and the PR is ready for another round of review. @jenswi-linaro


#Enable a hardware pbkdf2 function
#By default use standard pbkdf2 implementation
CFG_CRYPTO_HW_PBKDF2 ?= n
Copy link
Contributor

Choose a reason for hiding this comment

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

@jforissier, would it make sense to add a:

$(eval $(call cfg-depends-all,CFG_CRYPTO_HW_PBKDF2,CFG_CRYPTO_PBKDF2))

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree

mk/config.mk Outdated
@@ -1038,3 +1038,7 @@ CFG_TA_OPTEE_CORE_API_COMPAT_1_1 ?= n
# - PerInstance/AttestationTest#
# Note that this violates GP requirements of HMAC size range.
CFG_HMAC_64_1024_RANGE ?= n

#Enable a hardware pbkdf2 function
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 space after #, the same on the line below.

Copy link
Author

Choose a reason for hiding this comment

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

Modifications are made.

mk/config.mk Outdated

# Enable a hardware pbkdf2 function
CFG_CRYPTO_HW_PBKDF2 ?= y
$(eval $(call cfg-depends-all,CFG_CRYPTO_HW_PBKDF2,CFG_CRYPTO_PBKDF2))
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 newline character at the end of the file to avoid this ugly warning from git.

mk/config.mk Outdated
@@ -1038,3 +1038,7 @@ CFG_TA_OPTEE_CORE_API_COMPAT_1_1 ?= n
# - PerInstance/AttestationTest#
# Note that this violates GP requirements of HMAC size range.
CFG_HMAC_64_1024_RANGE ?= n

# Enable a hardware pbkdf2 function
CFG_CRYPTO_HW_PBKDF2 ?= y
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value should be n.

Copy link
Author

Choose a reason for hiding this comment

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

OK

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.

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

@loubaihui
Copy link
Author

@jenswi-linaro @jforissier

@jforissier
Copy link
Contributor

jforissier commented Sep 11, 2023

@loubaihui the code looks good to me so please add:

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

However I would like the commit description changed because it does not add a new implementation, just a config flag to support a hardware implementation. How about:

crypto: introduce CFG_CRYPTO_HW_PBKDF2

Add a new configuration flag to support hardware implementation of
PBKDF2.

Add a new configuration flag to support hardware implementation of
PBKDF2.

Signed-off-by: loubaihui <loubaihui1@huawei.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
@loubaihui
Copy link
Author

@loubaihui the code looks good to me so please add:

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>

However I would like the commit description changed because it does not add a new implementation, just a config flag to support a hardware implementation. How about:

crypto: introduce CFG_CRYPTO_HW_PBKDF2

Add a new configuration flag to support hardware implementation of
PBKDF2.

Ok, thanks! @jforissier

@jforissier
Copy link
Contributor

The CI error with "QEMUv8, Xen" is unrelated to this PR, and probably caused by insufficient disk space. This will be addressed separately. Therefore I am merging this, thanks @loubaihui.

@jforissier jforissier merged commit aae9733 into OP-TEE:master Sep 13, 2023
6 of 7 checks passed
@loubaihui loubaihui changed the title crypto: add a new pbkdf2 implementation crypto: introduce CFG_CRYPTO_HW_PBKDF2 Sep 15, 2023
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.

4 participants