Skip to content

Commit

Permalink
Adapt to changes in name generation in zcbor 0.8.0
Browse files Browse the repository at this point in the history
Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
  • Loading branch information
oyvindronningstad committed Jan 12, 2024
1 parent c0d0515 commit f1443b4
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 189 deletions.
38 changes: 19 additions & 19 deletions src/edhoc/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,36 +255,36 @@ enum err cert_c509_verify(struct const_byte_array *cert,
TRY_EXPECT(cbor_decode_cert(cert->ptr, cert->len, &c, &decode_len), 0);

PRINT_MSG("CBOR certificate parsed.\n");
PRINTF("Certificate type: %d\n", c._cert_type);
PRINT_ARRAY("issuer", c._cert_issuer.value,
(uint32_t)c._cert_issuer.len);
PRINTF("validity_not_before: %d\n", c._cert_validity_not_before);
PRINTF("validity_not_after: %d\n", c._cert_validity_not_after);
PRINT_ARRAY("subject", c._cert_subject.value,
(uint32_t)c._cert_subject.len);
PRINT_ARRAY("PK", c._cert_pk.value, (uint32_t)c._cert_pk.len);
PRINTF("extensions: %d\n", c._cert_extensions);
PRINTF("Certificate type: %d\n", c.cert_type);
PRINT_ARRAY("issuer", c.cert_issuer.value,
(uint32_t)c.cert_issuer.len);
PRINTF("validity_not_before: %d\n", c.cert_validity_not_before);
PRINTF("validity_not_after: %d\n", c.cert_validity_not_after);
PRINT_ARRAY("subject", c.cert_subject.value,
(uint32_t)c.cert_subject.len);
PRINT_ARRAY("PK", c.cert_pk.value, (uint32_t)c.cert_pk.len);
PRINTF("extensions: %d\n", c.cert_extensions);
PRINTF("issuer_signature_algorithm: %d\n",
c._cert_issuer_signature_algorithm);
PRINT_ARRAY("Signature", c._cert_signature.value,
(uint32_t)c._cert_signature.len);
c.cert_issuer_signature_algorithm);
PRINT_ARRAY("Signature", c.cert_signature.value,
(uint32_t)c.cert_signature.len);

/*get the CA's public key*/
struct byte_array root_pk;
TRY(ca_pk_get(cred_array, c._cert_issuer.value, &root_pk));
TRY(ca_pk_get(cred_array, c.cert_issuer.value, &root_pk));

/*verify the certificates signature*/
struct const_byte_array m = BYTE_ARRAY_INIT(
cert->ptr, cert->len - 2 - (uint32_t)c._cert_signature.len);
cert->ptr, cert->len - 2 - (uint32_t)c.cert_signature.len);
struct const_byte_array sgn = BYTE_ARRAY_INIT(
c._cert_signature.value, (uint32_t)c._cert_signature.len);
c.cert_signature.value, (uint32_t)c.cert_signature.len);

TRY(verify((enum sign_alg)c._cert_issuer_signature_algorithm, &root_pk,
TRY(verify((enum sign_alg)c.cert_issuer_signature_algorithm, &root_pk,
&m, &sgn, verified));

TRY(_memcpy_s(pk->ptr, pk->len, c._cert_pk.value,
(uint32_t)c._cert_pk.len));
pk->len = (uint32_t)c._cert_pk.len;
TRY(_memcpy_s(pk->ptr, pk->len, c.cert_pk.value,
(uint32_t)c.cert_pk.len));
pk->len = (uint32_t)c.cert_pk.len;

return ok;
}
Expand Down
30 changes: 15 additions & 15 deletions src/edhoc/edhoc_cose.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ enum err cose_enc_structure_encode(const struct byte_array *context,
{
struct edhoc_enc_structure enc_structure;

enc_structure._edhoc_enc_structure_context.value = context->ptr;
enc_structure._edhoc_enc_structure_context.len = context->len;
enc_structure._edhoc_enc_structure_external_aad.value =
enc_structure.edhoc_enc_structure_context.value = context->ptr;
enc_structure.edhoc_enc_structure_context.len = context->len;
enc_structure.edhoc_enc_structure_external_aad.value =
external_aad->ptr;
enc_structure._edhoc_enc_structure_external_aad.len = external_aad->len;
enc_structure.edhoc_enc_structure_external_aad.len = external_aad->len;

/* NULL protected with zero size is acceptable from EDHOC point of view,
* but CBOR encoder does not accept NULL as input argument.
Expand All @@ -44,15 +44,15 @@ enum err cose_enc_structure_encode(const struct byte_array *context,
if (0 != protected->len) {
return wrong_parameter;
} else {
enc_structure._edhoc_enc_structure_protected.value =
enc_structure.edhoc_enc_structure_protected.value =
(const uint8_t *)&dummy_buffer;
}
} else {
enc_structure._edhoc_enc_structure_protected.value =
enc_structure.edhoc_enc_structure_protected.value =
protected->ptr;
}

enc_structure._edhoc_enc_structure_protected.len = protected->len;
enc_structure.edhoc_enc_structure_protected.len = protected->len;

size_t payload_len_out;
TRY_EXPECT(cbor_encode_edhoc_enc_structure(out->ptr, out->len,
Expand All @@ -71,14 +71,14 @@ enum err cose_sig_structure_encode(const struct byte_array *context,
{
struct sig_structure sig_structure;

sig_structure._sig_structure_context.value = context->ptr;
sig_structure._sig_structure_context.len = context->len;
sig_structure._sig_structure_protected.value = protected->ptr;
sig_structure._sig_structure_protected.len = protected->len;
sig_structure._sig_structure_external_aad.value = external_aad->ptr;
sig_structure._sig_structure_external_aad.len = external_aad->len;
sig_structure._sig_structure_payload.value = payload->ptr;
sig_structure._sig_structure_payload.len = payload->len;
sig_structure.sig_structure_context.value = context->ptr;
sig_structure.sig_structure_context.len = context->len;
sig_structure.sig_structure_protected.value = protected->ptr;
sig_structure.sig_structure_protected.len = protected->len;
sig_structure.sig_structure_external_aad.value = external_aad->ptr;
sig_structure.sig_structure_external_aad.len = external_aad->len;
sig_structure.sig_structure_payload.value = payload->ptr;
sig_structure.sig_structure_payload.len = payload->len;

size_t payload_len_out;
TRY_EXPECT(cbor_encode_sig_structure(out->ptr, out->len, &sig_structure,
Expand Down
10 changes: 5 additions & 5 deletions src/edhoc/hkdf_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum err create_hkdf_info(uint8_t label, struct byte_array *context,
{
struct info info;

info._info_label = label;
info.info_label = label;

/* NULL context with zero size is acceptable from EDHOC point of view,
* but CBOR encoder does not accept NULL as input argument.
Expand All @@ -39,16 +39,16 @@ enum err create_hkdf_info(uint8_t label, struct byte_array *context,
if (0 != context->len) {
return wrong_parameter;
} else {
info._info_context.value =
info.info_context.value =
(const uint8_t *)&dummy_buffer;
}
} else {
info._info_context.value = context->ptr;
info.info_context.value = context->ptr;
}

info._info_context.len = context->len;
info.info_context.len = context->len;

info._info_length = okm_len;
info.info_length = okm_len;

size_t payload_len_out = 0;
TRY_EXPECT(cbor_encode_info(out->ptr, out->len, &info,
Expand Down
52 changes: 26 additions & 26 deletions src/edhoc/initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ static inline enum err msg2_parse(struct byte_array *msg2,
struct m2 m;

TRY_EXPECT(cbor_decode_m2(msg2->ptr, msg2->len, &m, &decode_len), 0);
TRY(_memcpy_s(g_y->ptr, g_y->len, m._m2_G_Y_CIPHERTEXT_2.value,
TRY(_memcpy_s(g_y->ptr, g_y->len, m.m2_G_Y_CIPHERTEXT_2.value,
g_y->len));
PRINT_ARRAY("g_y", g_y->ptr, g_y->len);

TRY(_memcpy_s(ciphertext2->ptr, ciphertext2->len,
m._m2_G_Y_CIPHERTEXT_2.value + g_y->len,
(uint32_t)(m._m2_G_Y_CIPHERTEXT_2.len - g_y->len)));
m.m2_G_Y_CIPHERTEXT_2.value + g_y->len,
(uint32_t)(m.m2_G_Y_CIPHERTEXT_2.len - g_y->len)));

ciphertext2->len = (uint32_t)m._m2_G_Y_CIPHERTEXT_2.len - g_y->len;
ciphertext2->len = (uint32_t)m.m2_G_Y_CIPHERTEXT_2.len - g_y->len;
PRINT_ARRAY("ciphertext2", ciphertext2->ptr, ciphertext2->len);

if (m._m2_C_R_choice == _m2_C_R_int) {
TRY(encode_int(&m._m2_C_R_int, 1, c_r));
if (m.m2_C_R_choice == m2_C_R_int_c) {
TRY(encode_int(&m.m2_C_R_int, 1, c_r));
} else {
TRY(_memcpy_s(c_r->ptr, c_r->len, m._m2_C_R_bstr.value,
(uint32_t)m._m2_C_R_bstr.len));
c_r->len = (uint32_t)m._m2_C_R_bstr.len;
TRY(_memcpy_s(c_r->ptr, c_r->len, m.m2_C_R_bstr.value,
(uint32_t)m.m2_C_R_bstr.len));
c_r->len = (uint32_t)m.m2_C_R_bstr.len;
}
PRINT_ARRAY("C_R_raw", c_r->ptr, c_r->len);

Expand All @@ -84,46 +84,46 @@ enum err msg1_gen(const struct edhoc_initiator_context *c,
struct message_1 m1;

/*METHOD_CORR*/
m1._message_1_METHOD = (int32_t)c->method;
m1.message_1_METHOD = (int32_t)c->method;

/*SUITES_I*/
if (c->suites_i.len == 1) {
/* only one suite, encode into int */
m1._message_1_SUITES_I_choice = _message_1_SUITES_I_int;
m1._message_1_SUITES_I_int = c->suites_i.ptr[0];
m1.message_1_SUITES_I_choice = message_1_SUITES_I_int_c;
m1.message_1_SUITES_I_int = c->suites_i.ptr[0];
} else if (c->suites_i.len > 1) {
/* more than one suites, encode into array */
m1._message_1_SUITES_I_choice = _SUITES_I__suite;
m1._SUITES_I__suite_suite_count = c->suites_i.len;
m1.message_1_SUITES_I_choice = SUITES_I_suite_l_c;
m1.SUITES_I_suite_l_suite_count = c->suites_i.len;
for (uint32_t i = 0; i < c->suites_i.len; i++) {
m1._SUITES_I__suite_suite[i] = c->suites_i.ptr[i];
m1.SUITES_I_suite_l_suite[i] = c->suites_i.ptr[i];
}
}

/* G_X ephemeral public key */
m1._message_1_G_X.value = c->g_x.ptr;
m1._message_1_G_X.len = c->g_x.len;
m1.message_1_G_X.value = c->g_x.ptr;
m1.message_1_G_X.len = c->g_x.len;

/* C_I connection ID of the initiator*/
PRINT_ARRAY("C_I", c->c_i.ptr, c->c_i.len);
if (c->c_i.len == 1 &&
((0x00 <= c->c_i.ptr[0] && c->c_i.ptr[0] < 0x18) ||
(0x1F < c->c_i.ptr[0] && c->c_i.ptr[0] <= 0x37))) {
m1._message_1_C_I_choice = _message_1_C_I_int;
TRY(decode_int(&c->c_i, &m1._message_1_C_I_int));
m1.message_1_C_I_choice = message_1_C_I_int_c;
TRY(decode_int(&c->c_i, &m1.message_1_C_I_int));
} else {
m1._message_1_C_I_choice = _message_1_C_I_bstr;
m1._message_1_C_I_bstr.value = c->c_i.ptr;
m1._message_1_C_I_bstr.len = c->c_i.len;
m1.message_1_C_I_choice = message_1_C_I_bstr_c;
m1.message_1_C_I_bstr.value = c->c_i.ptr;
m1.message_1_C_I_bstr.len = c->c_i.len;
}

if (c->ead_1.len != 0) {
/* ead_1 unprotected opaque auxiliary data */
m1._message_1_ead_1.value = c->ead_1.ptr;
m1._message_1_ead_1.len = c->ead_1.len;
m1._message_1_ead_1_present = true;
m1.message_1_ead_1.value = c->ead_1.ptr;
m1.message_1_ead_1.len = c->ead_1.len;
m1.message_1_ead_1_present = true;
} else {
m1._message_1_ead_1_present = false;
m1.message_1_ead_1_present = false;
}

size_t payload_len_out;
Expand Down
78 changes: 39 additions & 39 deletions src/edhoc/plaintext_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ static enum err id_cred_x_encode(enum id_cred_x_label label, int algo,
switch (label) {
case kid:
//todo update that to v15
map._id_cred_x_map_kid_present = true;
map._id_cred_x_map_kid._id_cred_x_map_kid_choice =
_id_cred_x_map_kid_int;
map._id_cred_x_map_kid._id_cred_x_map_kid_int =
map.id_cred_x_map_kid_present = true;
map.id_cred_x_map_kid.id_cred_x_map_kid_choice =
id_cred_x_map_kid_int_c;
map.id_cred_x_map_kid.id_cred_x_map_kid_int =
*((const int32_t *)id);
break;
case x5chain:
map._id_cred_x_map_x5chain_present = true;
map._id_cred_x_map_x5chain._id_cred_x_map_x5chain.value = id;
map._id_cred_x_map_x5chain._id_cred_x_map_x5chain.len = id_len;
map.id_cred_x_map_x5chain_present = true;
map.id_cred_x_map_x5chain.id_cred_x_map_x5chain.value = id;
map.id_cred_x_map_x5chain.id_cred_x_map_x5chain.len = id_len;
break;
case x5t:
map._id_cred_x_map_x5t_present = true;
map._id_cred_x_map_x5t._id_cred_x_map_x5t_alg_choice =
_id_cred_x_map_x5t_alg_int;
map._id_cred_x_map_x5t._id_cred_x_map_x5t_alg_int = algo;
map._id_cred_x_map_x5t._id_cred_x_map_x5t_hash.value = id;
map._id_cred_x_map_x5t._id_cred_x_map_x5t_hash.len = id_len;
map.id_cred_x_map_x5t_present = true;
map.id_cred_x_map_x5t.id_cred_x_map_x5t_alg_choice =
id_cred_x_map_x5t_alg_int_c;
map.id_cred_x_map_x5t.id_cred_x_map_x5t_alg_int = algo;
map.id_cred_x_map_x5t.id_cred_x_map_x5t_hash.value = id;
map.id_cred_x_map_x5t.id_cred_x_map_x5t_hash.len = id_len;
break;
default:
break;
Expand All @@ -86,55 +86,55 @@ enum err plaintext_split(struct byte_array *ptxt, struct byte_array *id_cred_x,
0);

/*ID_CRED_x*/
if (p._plaintext_ID_CRED_x_choice == _plaintext_ID_CRED_x__map) {
if (p._plaintext_ID_CRED_x__map._map_x5chain_present) {
if (p.plaintext_ID_CRED_x_choice == plaintext_ID_CRED_x_map_m_c) {
if (p.plaintext_ID_CRED_x_map_m.map_x5chain_present) {
PRINT_MSG(
"ID_CRED of the other party has label x5chain\n");
TRY(id_cred_x_encode(
x5chain, 0,
p._plaintext_ID_CRED_x__map._map_x5chain
._map_x5chain.value,
(uint32_t)p._plaintext_ID_CRED_x__map
._map_x5chain._map_x5chain.len,
p.plaintext_ID_CRED_x_map_m.map_x5chain
.map_x5chain.value,
(uint32_t)p.plaintext_ID_CRED_x_map_m
.map_x5chain.map_x5chain.len,
id_cred_x));
}
if (p._plaintext_ID_CRED_x__map._map_x5t_present) {
if (p.plaintext_ID_CRED_x_map_m.map_x5t_present) {
PRINT_MSG("ID_CRED of the other party has label x5t\n");
TRY(id_cred_x_encode(
x5t,
p._plaintext_ID_CRED_x__map._map_x5t
._map_x5t_alg_int,
p._plaintext_ID_CRED_x__map._map_x5t
._map_x5t_hash.value,
(uint32_t)p._plaintext_ID_CRED_x__map._map_x5t
._map_x5t_hash.len,
p.plaintext_ID_CRED_x_map_m.map_x5t
.map_x5t_alg_int,
p.plaintext_ID_CRED_x_map_m.map_x5t
.map_x5t_hash.value,
(uint32_t)p.plaintext_ID_CRED_x_map_m.map_x5t
.map_x5t_hash.len,
id_cred_x));
}
} else {
/*Note that if ID_CRED_x contains a single 'kid' parameter,
i.e., ID_CRED_R = { 4 : kid_x }, only the byte string kid_x
is conveyed in the plaintext encoded as a bstr or int*/
if (p._plaintext_ID_CRED_x_choice ==
_plaintext_ID_CRED_x__map) {
if (p.plaintext_ID_CRED_x_choice ==
plaintext_ID_CRED_x_map_m_c) {
TRY(id_cred_x_encode(
kid, 0, p._plaintext_ID_CRED_x_bstr.value,
(uint32_t)p._plaintext_ID_CRED_x_bstr.len,
kid, 0, p.plaintext_ID_CRED_x_bstr.value,
(uint32_t)p.plaintext_ID_CRED_x_bstr.len,
id_cred_x));

} else {
int _kid = p._plaintext_ID_CRED_x_int;
int _kid = p.plaintext_ID_CRED_x_int;
TRY(id_cred_x_encode(kid, 0, &_kid, 1, id_cred_x));
}
}
TRY(_memcpy_s(sign_or_mac->ptr, sign_or_mac->len,
p._plaintext_SGN_or_MAC_x.value,
(uint32_t)p._plaintext_SGN_or_MAC_x.len));
sign_or_mac->len = (uint32_t)p._plaintext_SGN_or_MAC_x.len;

if (p._plaintext_AD_x_present == true) {
TRY(_memcpy_s(ad->ptr, ad->len, p._plaintext_AD_x.value,
(uint32_t)p._plaintext_AD_x.len));
ad->len = (uint32_t)p._plaintext_AD_x.len;
p.plaintext_SGN_or_MAC_x.value,
(uint32_t)p.plaintext_SGN_or_MAC_x.len));
sign_or_mac->len = (uint32_t)p.plaintext_SGN_or_MAC_x.len;

if (p.plaintext_AD_x_present == true) {
TRY(_memcpy_s(ad->ptr, ad->len, p.plaintext_AD_x.value,
(uint32_t)p.plaintext_AD_x.len));
ad->len = (uint32_t)p.plaintext_AD_x.len;
} else {
if (ad->len) {
ad->len = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/edhoc/plaintext_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ enum err id_cred2kid(const struct byte_array *id_cred, struct byte_array *kid)
&decode_len),
0);

if (map._id_cred_x_map_kid_present) {
if (map.id_cred_x_map_kid_present) {
TRY_EXPECT(
cbor_encode_int_type_i(
kid->ptr, kid->len,
&map._id_cred_x_map_kid._id_cred_x_map_kid_int,
&map.id_cred_x_map_kid.id_cred_x_map_kid_int,
&payload_len_out),
ZCBOR_SUCCESS);
kid->len = (uint32_t)payload_len_out;
Expand Down
Loading

0 comments on commit f1443b4

Please sign in to comment.