Skip to content

Commit

Permalink
crypto: rename struct x25519_keypair
Browse files Browse the repository at this point in the history
Since X25519 and X448 have the same key pair structure,
so we rename struct x25519_keypair as struct montgomery_keypair.

Signed-off-by: loubaihui <loubaihui1@huawei.com>
Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
  • Loading branch information
bhLou committed Jul 25, 2023
1 parent a012b99 commit 5a4578e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
7 changes: 4 additions & 3 deletions core/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,20 +834,21 @@ TEE_Result crypto_acipher_sm2_kep_derive(struct ecc_keypair *my_key __unused,
#endif

#if !defined(CFG_CRYPTO_X25519)
TEE_Result crypto_acipher_alloc_x25519_keypair(struct x25519_keypair *key
TEE_Result crypto_acipher_alloc_x25519_keypair(struct montgomery_keypair *key
__unused,
size_t key_size_bits __unused)
{
return TEE_ERROR_NOT_IMPLEMENTED;
}

TEE_Result crypto_acipher_gen_x25519_key(struct x25519_keypair *key __unused,
TEE_Result crypto_acipher_gen_x25519_key(struct montgomery_keypair
*key __unused,
size_t key_size __unused)
{
return TEE_ERROR_NOT_IMPLEMENTED;
}

TEE_Result crypto_acipher_x25519_shared_secret(struct x25519_keypair
TEE_Result crypto_acipher_x25519_shared_secret(struct montgomery_keypair
*private_key __unused,
void *public_key __unused,
void *secret __unused,
Expand Down
8 changes: 4 additions & 4 deletions core/include/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct ecc_keypair {
const struct crypto_ecc_keypair_ops *ops; /* Key Operations */
};

struct x25519_keypair {
struct montgomery_keypair {
uint8_t *priv; /* Private value */
uint8_t *pub; /* Public value */
};
Expand Down Expand Up @@ -208,7 +208,7 @@ TEE_Result crypto_acipher_alloc_ecc_keypair(struct ecc_keypair *s,
uint32_t key_type,
size_t key_size_bits);
void crypto_acipher_free_ecc_public_key(struct ecc_public_key *s);
TEE_Result crypto_acipher_alloc_x25519_keypair(struct x25519_keypair *s,
TEE_Result crypto_acipher_alloc_x25519_keypair(struct montgomery_keypair *s,
size_t key_size_bits);
TEE_Result crypto_acipher_alloc_ed25519_keypair(struct ed25519_keypair *s,
size_t key_size_bits);
Expand All @@ -224,7 +224,7 @@ TEE_Result crypto_acipher_gen_dsa_key(struct dsa_keypair *key, size_t key_size);
TEE_Result crypto_acipher_gen_dh_key(struct dh_keypair *key, struct bignum *q,
size_t xbits, size_t key_size);
TEE_Result crypto_acipher_gen_ecc_key(struct ecc_keypair *key, size_t key_size);
TEE_Result crypto_acipher_gen_x25519_key(struct x25519_keypair *key,
TEE_Result crypto_acipher_gen_x25519_key(struct montgomery_keypair *key,
size_t key_size);
TEE_Result crypto_acipher_gen_ed25519_key(struct ed25519_keypair *key,
size_t key_size);
Expand Down Expand Up @@ -296,7 +296,7 @@ TEE_Result crypto_acipher_sm2_pke_decrypt(struct ecc_keypair *key,
TEE_Result crypto_acipher_sm2_pke_encrypt(struct ecc_public_key *key,
const uint8_t *src, size_t src_len,
uint8_t *dst, size_t *dst_len);
TEE_Result crypto_acipher_x25519_shared_secret(struct x25519_keypair
TEE_Result crypto_acipher_x25519_shared_secret(struct montgomery_keypair
*private_key,
void *public_key, void *secret,
unsigned long *secret_len);
Expand Down
6 changes: 3 additions & 3 deletions core/lib/libtomcrypt/x25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/* X25519 key is an octet string of 32 bytes */
#define X25519_KEY_SIZE_BYTES UL(32)

TEE_Result crypto_acipher_alloc_x25519_keypair(struct x25519_keypair *key,
TEE_Result crypto_acipher_alloc_x25519_keypair(struct montgomery_keypair *key,
size_t key_size)
{
size_t key_size_bytes = key_size / 8;
Expand All @@ -41,7 +41,7 @@ TEE_Result crypto_acipher_alloc_x25519_keypair(struct x25519_keypair *key,
return TEE_SUCCESS;
}

TEE_Result crypto_acipher_gen_x25519_key(struct x25519_keypair *key,
TEE_Result crypto_acipher_gen_x25519_key(struct montgomery_keypair *key,
size_t key_size)
{
curve25519_key ltc_tmp_key = { };
Expand All @@ -65,7 +65,7 @@ TEE_Result crypto_acipher_gen_x25519_key(struct x25519_keypair *key,
return TEE_SUCCESS;
}

TEE_Result crypto_acipher_x25519_shared_secret(struct x25519_keypair
TEE_Result crypto_acipher_x25519_shared_secret(struct montgomery_keypair
*private_key,
void *public_key,
void *secret,
Expand Down
10 changes: 5 additions & 5 deletions core/tee/tee_svc_cryp.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ const struct tee_cryp_obj_type_attrs tee_cryp_obj_x25519_keypair_attrs[] = {
.attr_id = TEE_ATTR_X25519_PRIVATE_VALUE,
.flags = TEE_TYPE_ATTR_REQUIRED,
.ops_index = ATTR_OPS_INDEX_25519,
RAW_DATA(struct x25519_keypair, priv)
RAW_DATA(struct montgomery_keypair, priv)
},

{
.attr_id = TEE_ATTR_X25519_PUBLIC_VALUE,
.flags = TEE_TYPE_ATTR_REQUIRED,
.ops_index = ATTR_OPS_INDEX_25519,
RAW_DATA(struct x25519_keypair, pub)
RAW_DATA(struct montgomery_keypair, pub)
},
};

Expand Down Expand Up @@ -635,7 +635,7 @@ static const struct tee_cryp_obj_type_props tee_cryp_obj_props[] = {
tee_cryp_obj_sm2_keypair_attrs),

PROP(TEE_TYPE_X25519_KEYPAIR, 1, 256, 256,
sizeof(struct x25519_keypair),
sizeof(struct montgomery_keypair),
tee_cryp_obj_x25519_keypair_attrs),

PROP(TEE_TYPE_ED25519_PUBLIC_KEY, 1, 256, 256,
Expand Down Expand Up @@ -2186,15 +2186,15 @@ tee_svc_obj_generate_key_x25519(struct tee_obj *o,
uint32_t param_count)
{
TEE_Result res = TEE_ERROR_GENERIC;
struct x25519_keypair *tee_x25519_key = NULL;
struct montgomery_keypair *tee_x25519_key = NULL;

/* Copy the present attributes into the obj before starting */
res = tee_svc_cryp_obj_populate_type(o, type_props, params,
param_count);
if (res != TEE_SUCCESS)
return res;

tee_x25519_key = (struct x25519_keypair *)o->attr;
tee_x25519_key = (struct montgomery_keypair *)o->attr;

res = crypto_acipher_gen_x25519_key(tee_x25519_key, key_size);
if (res != TEE_SUCCESS)
Expand Down

0 comments on commit 5a4578e

Please sign in to comment.