oc_obt:internal funcs for gen OSCORE ctxid/secret
@@ -307,6 +307,41 @@ oc_obt_load_state(void)
}
#endif /* OC_PKI */
+#ifdef OC_OSCORE
+static void
+gen_oscore_secret(uint8_t *secret)
+{
+ int i = 0;
+ while (i < OSCORE_MASTER_SECRET_LEN) {
+ unsigned int r = oc_random_value();
+ size_t copy_len = (sizeof(r) < (unsigned)(OSCORE_MASTER_SECRET_LEN - i))
+ ? sizeof(r)
+ : (unsigned)OSCORE_MASTER_SECRET_LEN - i;
+ memcpy(&secret[i], &r, copy_len);
+ i += copy_len;
+ }
+}
+
+static void
+gen_oscore_ctxid(uint8_t *id, bool group)
+{
+ int i = 0;
+ while (i < OSCORE_CTXID_LEN) {
+ unsigned int r1 = oc_random_value(), r2 = oc_random_value();
+ size_t copy_len = (sizeof(r1) < (unsigned)(OSCORE_CTXID_LEN - i))
+ ? sizeof(r1)
+ : (unsigned)OSCORE_CTXID_LEN - i;
+ memcpy(&id[i], &r2, copy_len);
+ i += copy_len;
+ }
+ if (group) {
+ id[0] = 0x02;
+ } else {
+ id[0] = 0x01;
+ }
+}
+#endif /* OC_OSCORE */
+
struct list
{
struct list *next;
@@ -1012,27 +1047,9 @@ device2oscore_RFPRO(int status, void *data)
p->switch_dos = NULL;
if (status >= 0) {
- int i = 0;
- while (i < OSCORE_CTXID_LEN) {
- unsigned int r1 = oc_random_value(), r2 = oc_random_value();
- size_t copy_len = (sizeof(r1) < (unsigned)(OSCORE_CTXID_LEN - i))
- ? sizeof(r1)
- : (unsigned)OSCORE_CTXID_LEN - i;
- memcpy(&p->sendid[i], &r1, copy_len);
- memcpy(&p->recvid[i], &r2, copy_len);
- i += copy_len;
- }
- p->sendid[0] = p->recvid[0] = 0x01;
-
- i = 0;
- while (i < OSCORE_MASTER_SECRET_LEN) {
- unsigned int r = oc_random_value();
- size_t copy_len = (sizeof(r) < (unsigned)(OSCORE_MASTER_SECRET_LEN - i))
- ? sizeof(r)
- : (unsigned)OSCORE_MASTER_SECRET_LEN - i;
- memcpy(&p->secret[i], &r, copy_len);
- i += copy_len;
- }
+ gen_oscore_ctxid(p->sendid, false);
+ gen_oscore_ctxid(p->recvid, false);
+ gen_oscore_secret(p->secret);
char d2uuid[OC_UUID_LEN];
oc_uuid_to_str(&p->device2->uuid, d2uuid, OC_UUID_LEN);
@@ -1096,6 +1113,8 @@ device1oscore_RFPRO(int status, void *data)
if (!p->switch_dos) {
free_oscoreprov_ctx(p, -1);
}
+ } else {
+ free_oscoreprov_ctx(p, -1);
}
}
