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 pbkdf2 algorithm #7180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LeiSen62
Copy link
Contributor

Add pbkdf2 algorithm for hisilicon SEC driver

static enum hisi_drv_status sec_pbkdf2_parse_sqe(void *bd, void *msg __unused)
{
struct hisi_sec_sqe *sqe = bd;
uint16_t done;
Copy link
Contributor

Choose a reason for hiding this comment

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

= 0
Ditto at line 63.

{
struct hisi_qp *qp;
TEE_Result res = 0;
int32_t ret;
Copy link
Contributor

Choose a reason for hiding this comment

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

	struct hisi_qp *qp = NULL;
	TEE_Result res = TEE_ERROR_SUCCESS;
	enum hisi_drv_status ret = <something>;

size_t dk_len)
{
size_t t_num, hash_len, time;
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.

	size_t t_num = 0;
	size_t hash_len = 0;
	size_t time = 0;
	TEE_Result ret = TEE_ERROR_GENERIC;

return TEE_ERROR_NOT_SUPPORTED;
}

t_num = dk_len / hash_len + (dk_len % hash_len ? 1 : 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

t_num = ROUNDUP_DIV(dk_len, hash_len);


done = SEC_GET_FIELD(sqe->type2.done_flag, SEC_DONE_MASK, 0);
if (done != SEC_HW_TASK_DONE || sqe->type2.error_type) {
EMSG("SEC do pbkdf2 fail! done=0x%x, etype=0x%x",
Copy link
Contributor

Choose a reason for hiding this comment

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

... done=0x%"PRIx16", etype=0x%"PRIx8
Ditto at line 67.


if ((alg < TEE_ALG_HMAC_SHA384 || alg > TEE_ALG_HMAC_SHA512) &&
(password_len > (SEC_MAX_PASSWORD_LEN / 2))) {
EMSG("Password_len %lu does not match alg 0x%x",
Copy link
Contributor

Choose a reason for hiding this comment

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

%zu and %"PRIx32: "Password_len %zu does not match alg 0x%"PRIx32

uint8_t *derived_key, size_t derived_key_len)
{
struct sec_pbkdf2_msg *msg = NULL;
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.

= TEE_ERROR_GENERIC

msg = malloc(sizeof(*msg));
if (!msg) {
EMSG("Fail to malloc msg");
return TEE_ERROR_STORAGE_NO_SPACE;
Copy link
Contributor

Choose a reason for hiding this comment

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

TEE_ERROR_OUT_OF_MEMORY
FYI TEE_ERROR_STORAGE_NO_SPACE relates to the secure storage space.

TEE_Result ret;

#ifndef CFG_CRYPTO_HW_PBKDF2_WITH_EFUSE
if (!password) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer if (!IS_ENABLED(CFG_CRYPTO_HW_PBKDF2_WITH_EFUSE) && !password)

sqe->type2.pass_word_len = (uint16_t)pbkdf2_msg->key_len;
sqe->type2.dk_len = (uint16_t)pbkdf2_msg->out_len;

#ifdef CFG_CRYPTO_HW_PBKDF2_WITH_EFUSE
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer use if (IS_ENABLED(CFG_CRYPTO_HW_PBKDF2_WITH_EFUSE))
Ditto at line 94.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All review comments have been modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @etienne-lms, If it's okay, can you give me an Acked-by?

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.

Nitpicking minor comments on commit message:
s/pbkdf2/PBKDF2/g (header line and body)
s/hisilicon/Hisilicon/
Add a period (.) after "... driver".

With these (and the 2 below) addressed: Acked-by: Etienne Carriere <[email protected]>.
(edited)

msg->derive_type = SEC_HMAC_SM3;
break;
default:
EMSG("Invalid hamc alg type 0x%x", alg);
Copy link
Contributor

Choose a reason for hiding this comment

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

s/0x%x/0x%"PRIx32"/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (ret)
return ret;

msg = malloc(sizeof(*msg));
Copy link
Contributor

Choose a reason for hiding this comment

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

it is recommended to use calloc().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,@etienne-lms ,All review comments have been modified.

Add pbkdf2 algorithm for hisilicon SEC driver.

Signed-off-by: leisen <[email protected]>
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.

2 participants