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
driver: crypto: hisilicon: add ECC gen_keypair and ECDH #6807
base: master
Are you sure you want to change the base?
Conversation
}; | ||
|
||
/* NID_X9_62_prime192v1 */ | ||
static uint8_t g_prime192v1_p[] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static const
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to change struct hpre_ecc_curve
to use const pointers instead or is that struct sometimes used for output too?
It would be advantageous to make this data const since it will be protected from accidental overwrite.
return false; | ||
} | ||
|
||
EMSG("Error: %s all zero", p_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like all these EMSG()
should be DMSG()
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is error msg, and we use EMSG() in other files such as dh.c
struct hpre_ecc_msg *msg = (struct hpre_ecc_msg *)info; | ||
struct hpre_sqe *sqe = (struct hpre_sqe *)bd; | ||
|
||
sqe->w0 = msg->alg_type | (0x1 << HPRE_DONE_SHIFT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use SHIFT_U32(0x1, HPRE_DONE_SHIFT)
|
||
if (msg->alg_type == HPRE_ALG_SM2_SIGN || | ||
msg->alg_type == HPRE_ALG_SM2_ENC) | ||
sqe->ext1 |= (0x1 << HPRE_SQE_SM2_KSEL_SHIFT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SHIFT_U32()
return TEE_SUCCESS; | ||
} | ||
|
||
static bool is_size_support(size_t key_bits) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key_size_is_supported()
?
return TEE_ERROR_BAD_PARAMETERS; | ||
} | ||
|
||
rand_k = (uint8_t *)malloc(size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to cast void *
return TEE_ERROR_BAD_PARAMETERS; | ||
} | ||
|
||
ecc_key = (struct ecc_keypair *)sdata->key_priv; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to cast void *
, same below.
uint32_t sm2_mlen; | ||
bool sm2_sp; | ||
union { | ||
struct hpre_ecc_dh ecc_dh; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please indent these.
#ifndef __HPRE_ECC_H__ | ||
#define __HPRE_ECC_H__ | ||
|
||
#define ECC_DH_IN_PARAM_NUM 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you expect these to be used outside hpre_ecc.c
or could they be moved into that C file?
|
||
struct hpre_ecc_msg { | ||
uint8_t *key; | ||
uintptr_t key_dma; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paddr_t
? Same below.
|
||
#ifndef __HPRE_ECC_H__ | ||
#define __HPRE_ECC_H__ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <stdbool.h>
#include <stdint.h>
#include <tee_api_type.h>
#include <types_ext.h> // for paddr_t suggested by @jenswi-linaro
.x = g_prime192v1_gx, | ||
.y = g_prime192v1_gy, | ||
.n = g_prime192v1_n, | ||
}, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
},
{
uint32_t i = 0; | ||
|
||
for (i = 0; i < size; i++) { | ||
if (data[i] > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicking: if (data[i])
err1 = HPRE_TASK_ETYPE1(sqe->w0); | ||
done = HPRE_TASK_DONE(sqe->w0); | ||
if (done != HPRE_HW_TASK_DONE || err || err1) { | ||
EMSG("HPRE do ecc fail! done=0x%x, etype=0x%x, etype1=0x%x", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EMSG("HPRE do ecc fail! done=0x%"PRIx16", etype=0x%"PRIx16", etype1=0x%"RPIx16,
static TEE_Result hpre_do_ecc_task(void *msg) | ||
{ | ||
struct hisi_qp *ecc_qp = NULL; | ||
int32_t ret = TEE_SUCCESS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum hisi_drv_status res= HISI_QM_DRVCRYPT_<smoething>;
if (!msg->key_bytes) | ||
return TEE_ERROR_BAD_PARAMETERS; | ||
|
||
ret = hpre_ecc_dh_params_alloc(msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the function return a enum hisi_drv_status
value.
|
||
curve = get_curve_from_list(key->curve); | ||
if (!curve) { | ||
EMSG("Fail to get valid curve, id %u.", key->curve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... %"PRIu32, key->curve);
Ditto at line 914.
} | ||
|
||
if (BITS_TO_BYTES(size_bits) != BITS_TO_BYTES(curve->key_bits)) { | ||
EMSG("Invalid size_bits %lu.", size_bits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... %zu.", size_bits);
Ditto at line 919.
|
||
ret = hpre_do_ecc_task(&msg); | ||
if (ret) { | ||
EMSG("Fail to do ecc key pair task! ret = 0x%x.", ret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... ret = 0x%"PRIx32, ret);
ditto at line 931.
if (ret != TEE_SUCCESS) | ||
EMSG("Hpre ecc register to crypto fail"); | ||
|
||
return ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of error, OP-TEE will only print a message and continue initialization. If you want the platform to refuse to boot (and not fallback to a software ECC implementation, you should explicitly panic here.
7f718ff
to
63a2a14
Compare
@etienne-lms Could you please tell me how to deal with warning like this? |
add ECC gen_keypair and shared secret Signed-off-by: yuzexi <yuzexi@hisilicon.com>
Hi @yuzexiyzx, -static enum hisi_drv_status hpre_ecc_dh_params_fill(struct hpre_ecc_curve *curve,
- struct hpre_ecc_msg *msg,
- struct bignum *privkey,
- struct ecc_public_key *pubkey)
+static enum hisi_drv_status
+hpre_ecc_dh_params_fill(struct hpre_ecc_curve *curve, struct hpre_ecc_msg *msg,
+ struct bignum *privkey, struct ecc_public_key *pubkey)
{ |
add ECC gen_keypair and shared secret