aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSahil Malhotra <sahil.malhotra@nxp.com>2018-06-12 16:41:22 +0530
committerJérôme Forissier <jerome.forissier@linaro.org>2018-06-19 13:17:31 +0200
commitafd1381f1b3f59835abae6e59120d1e0e3960121 (patch)
tree84a003620af10d6e015ced34c691c8d6eaed503f
parent411ec9b37bf3ff48aac118cd78f1181c4ec648d3 (diff)
core: tee: update objectSize/keySize for ECDSA/ECDH Objects
objectSize/keySize was not getting updated when an ECDSA/ECDH object was imported. Updating the ObjectSize/keySize based on the EC Curve. Fixes: https://github.com/OP-TEE/optee_os/issues/2386 Signed-off-by: Sahil Malhotra <sahil.malhotra@nxp.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
-rw-r--r--core/tee/tee_svc_cryp.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/core/tee/tee_svc_cryp.c b/core/tee/tee_svc_cryp.c
index 54bafd60..8c63463e 100644
--- a/core/tee/tee_svc_cryp.c
+++ b/core/tee/tee_svc_cryp.c
@@ -364,7 +364,7 @@ static const struct tee_cryp_obj_type_attrs tee_cryp_obj_ecc_keypair_attrs[] = {
{
.attr_id = TEE_ATTR_ECC_CURVE,
- .flags = TEE_TYPE_ATTR_REQUIRED,
+ .flags = TEE_TYPE_ATTR_REQUIRED | TEE_TYPE_ATTR_SIZE_INDICATOR,
.ops_index = ATTR_OPS_INDEX_VALUE,
RAW_DATA(struct ecc_keypair, curve)
},
@@ -1424,6 +1424,31 @@ static TEE_Result tee_svc_cryp_check_attr(enum attr_usage usage,
return TEE_SUCCESS;
}
+static TEE_Result get_ec_key_size(uint32_t curve, size_t *key_size)
+{
+ switch (curve) {
+ case TEE_ECC_CURVE_NIST_P192:
+ *key_size = 192;
+ break;
+ case TEE_ECC_CURVE_NIST_P224:
+ *key_size = 224;
+ break;
+ case TEE_ECC_CURVE_NIST_P256:
+ *key_size = 256;
+ break;
+ case TEE_ECC_CURVE_NIST_P384:
+ *key_size = 384;
+ break;
+ case TEE_ECC_CURVE_NIST_P521:
+ *key_size = 521;
+ break;
+ default:
+ return TEE_ERROR_NOT_SUPPORTED;
+ }
+
+ return TEE_SUCCESS;
+}
+
static TEE_Result tee_svc_cryp_obj_populate_type(
struct tee_obj *o,
const struct tee_cryp_obj_type_props *type_props,
@@ -1464,8 +1489,20 @@ static TEE_Result tee_svc_cryp_obj_populate_type(
* of the object
*/
if (type_props->type_attrs[idx].flags &
- TEE_TYPE_ATTR_SIZE_INDICATOR)
- obj_size += attrs[n].content.ref.length * 8;
+ TEE_TYPE_ATTR_SIZE_INDICATOR) {
+ /*
+ * For ECDSA/ECDH we need to translate curve into
+ * object size
+ */
+ if (attrs[n].attributeID == TEE_ATTR_ECC_CURVE) {
+ res = get_ec_key_size(attrs[n].content.value.a,
+ &obj_size);
+ if (res != TEE_SUCCESS)
+ return res;
+ } else {
+ obj_size += (attrs[n].content.ref.length * 8);
+ }
+ }
}
/*