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

drivers: crypto: hisilicon: add DH algorithm #6781

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

yuzexiyzx
Copy link
Contributor

add operation of DH algorithm, including alloc_keypair, gen_keypair and shared_secret

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/include/hpre_main.h Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
size_t key_size)
{
struct hpre_dh_msg msg = { };
TEE_Result ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

Initialize these two

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
#define HPRE_DH_TOTAL_BUF_SIZE(key_bytes) ((key_bytes) * 4)
struct hpre_dh_msg {
uint8_t *x_p; /* X and p data in order */
uintptr_t x_p_dma;
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is an integer representing a virtual address, please use vaddr_t. If it's a physical address, use paddr_t. Same below.

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

Some added conding style comments.

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/include/hpre_dh.h Outdated Show resolved Hide resolved
#include "hpre_main.h"

#include <initcall.h>
#include <hpre_main.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

swap the 2 lines (alphabetical order).
It ould be nice this change comes in a dedicated commit (e.g. drivers: crypto: hisilicon: add missing header file inclusions).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.I will seperate a dedicated commit after other comments solved.

core/drivers/crypto/hisilicon/include/hpre_dh.h Outdated Show resolved Hide resolved
#define __TEE_HPRE_DH_H__

#include <drvcrypt.h>
#include <drvcrypt_acipher.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

include also types_ext.h (paddr_t), stdint.h (uintX_t) and tee_api_types.h (TEE_result).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these head files has been already included, such as tee_api_types included in drvcrypt_acipher.h

Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking, this header file requires uintX_t and paddr_t types for the structure it defines (struct hpre_dh_msg), not resources defined in other header files. Therefore, this header file should include the required header files. From a overall view, if we (hypothetically and quite unlikely :) modify drvcrypt.h, we should not have to modify this header (hpre_dh.h) to add header file inclusions it lacks.

Note that this header file does not need drvcrypt.h and drvcrypt_acipher.h at all.

I'm sorry such comments look annoying, I think they help your implementation to be easier to maintain in the long term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comments to make the code better!I will fix this.

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Show resolved Hide resolved
@yuzexiyzx yuzexiyzx force-pushed the master branch 4 times, most recently from 1997c1c to fd3732f Compare April 17, 2024 07:21
core/drivers/crypto/hisilicon/crypto.mk Show resolved Hide resolved

#include <hpre_dh.h>
#include <hpre_main.h>
#include <rng_support.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

I would be better that source file include the header files they need. I doubt hisi_qm.h needs string.h (or malloc.h etc...), it is rather the source files that include hisi_qm.h that need string.h. Header files should not be used to include all potential header files source file need or not need. But that's only my opinion.

core/drivers/crypto/hisilicon/hpre_dh.c Outdated Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Show resolved Hide resolved
core/drivers/crypto/hisilicon/hpre_dh.c Show resolved Hide resolved
#define __TEE_HPRE_DH_H__

#include <drvcrypt.h>
#include <drvcrypt_acipher.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Strictly speaking, this header file requires uintX_t and paddr_t types for the structure it defines (struct hpre_dh_msg), not resources defined in other header files. Therefore, this header file should include the required header files. From a overall view, if we (hypothetically and quite unlikely :) modify drvcrypt.h, we should not have to modify this header (hpre_dh.h) to add header file inclusions it lacks.

Note that this header file does not need drvcrypt.h and drvcrypt_acipher.h at all.

I'm sorry such comments look annoying, I think they help your implementation to be easier to maintain in the long term.

core/drivers/crypto/hisilicon/include/hpre_dh.h Outdated Show resolved Hide resolved
@yuzexiyzx yuzexiyzx force-pushed the master branch 3 times, most recently from ef35954 to 78db31d Compare April 18, 2024 08:05
@yuzexiyzx
Copy link
Contributor Author

@jenswi-linaro @etienne-lms All comments have been solved.

Copy link
Contributor

@etienne-lms etienne-lms 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: Etienne Carriere <etienne.carriere@foss.st.com> with these 2 comments addressed.


#include <hpre_dh.h>
#include <hpre_main.h>
#include <rng_support.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

#include <malloc.h>
#include <string.h>
#include <string_ext.h>
#include <trace.h>

@@ -0,0 +1,33 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2022, HiSilicon Technologies Co., Ltd.
Copy link
Contributor

Choose a reason for hiding this comment

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

2022-2024

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image
drvcrypt.h and initcall.h is needed in dh.c. I think these head files is already included, such as trace.h is included in drvcrypt.h

Copy link
Contributor

Choose a reason for hiding this comment

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

The general rule is to include all the header files you are using. For instance if you use traces then you include <trace.h> even if it is included by another header. The reason is because relying on indirect inclusions can break if the header files change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Get it. Solved.

@yuzexiyzx yuzexiyzx force-pushed the master branch 3 times, most recently from 25405e9 to 94059cb Compare April 25, 2024 05:47
@jenswi-linaro
Copy link
Contributor

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

add operation of DH algorithm, including alloc_keypair,
gen_keypair and shared_secret

Signed-off-by: yuzexi <yuzexi@hisilicon.com>
Acked-by: Etienne Carriere <etienne.carriere@foss.st.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
@yuzexiyzx
Copy link
Contributor Author

@jforissier All comments have been solved.

@jforissier jforissier merged commit 7950274 into OP-TEE:master Apr 25, 2024
7 checks passed
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.

None yet

4 participants