summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/g/dcrypto/dcrypto.h7
-rw-r--r--chip/g/dcrypto/p256.c6
2 files changed, 9 insertions, 4 deletions
diff --git a/chip/g/dcrypto/dcrypto.h b/chip/g/dcrypto/dcrypto.h
index fbc4beb583..fdc03c1361 100644
--- a/chip/g/dcrypto/dcrypto.h
+++ b/chip/g/dcrypto/dcrypto.h
@@ -145,8 +145,13 @@ int DCRYPTO_p256_base_point_mul(p256_int *out_x, p256_int *out_y,
int DCRYPTO_p256_point_mul(p256_int *out_x, p256_int *out_y,
const p256_int *n, const p256_int *in_x,
const p256_int *in_y);
+/*
+ * Produce uniform private key from seed.
+ * If x or y is NULL, the public key part is not computed.
+ * Returns !0 on success.
+ */
int DCRYPTO_p256_key_from_bytes(p256_int *x, p256_int *y, p256_int *d,
- const uint8_t key_bytes[P256_NBYTES]);
+ const uint8_t bytes[P256_NBYTES]);
/* P256 based integration encryption (DH+AES128+SHA256). */
/* Authenticated data may be provided, where the first auth_data_len
* bytes of in will be authenticated but not encrypted. */
diff --git a/chip/g/dcrypto/p256.c b/chip/g/dcrypto/p256.c
index 18ff5eb07f..ab60c91cdc 100644
--- a/chip/g/dcrypto/p256.c
+++ b/chip/g/dcrypto/p256.c
@@ -16,14 +16,14 @@ static const p256_int p256_one = P256_ONE;
int DCRYPTO_p256_key_from_bytes(p256_int *x, p256_int *y, p256_int *d,
const uint8_t key_bytes[P256_NBYTES])
{
- int result;
p256_int key;
p256_from_bin(key_bytes, &key);
if (p256_cmp(&SECP256r1_nMin2, &key) < 0)
return 0;
p256_add(&key, &p256_one, d);
- result = dcrypto_p256_base_point_mul(d, x, y);
dcrypto_memset(&key, 0, sizeof(key));
- return result;
+ if (x == NULL || y == NULL)
+ return 1;
+ return dcrypto_p256_base_point_mul(d, x, y);
}