Skip to content

Commit

Permalink
refactor: use constants instead of magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
geonnave committed Oct 25, 2023
1 parent 439c326 commit 774c8ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion consts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ mod consts {
// TODO: find a way to configure the buffer size
// need 128 to handle EAD fields, and 256 for the EAD_1 voucher
pub const MAX_MESSAGE_SIZE_LEN: usize = 128 + 64;
pub const MAX_EAD_SIZE_LEN: usize = 64;
pub type EADMessageBuffer = EdhocMessageBuffer; // TODO: make it of size MAX_EAD_SIZE_LEN

pub const MAX_EAD_SIZE_LEN: usize = 64;
pub const EAD_ZEROCONF_LABEL: u8 = 0x1; // NOTE: in lake-authz-draft-02 it is still TBD1
pub const EAD_ZEROCONF_INFO_K_1_LABEL: u8 = 0x0;
pub const EAD_ZEROCONF_INFO_IV_1_LABEL: u8 = 0x1;

pub const ID_CRED_LEN: usize = 4;
pub const SUITES_LEN: usize = 9;
Expand Down
16 changes: 14 additions & 2 deletions ead/edhoc-ead-zeroconf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,25 @@ fn compute_prk(a: &BytesP256ElemLen, g_b: &BytesP256ElemLen) -> BytesHashLen {
fn compute_k_1_iv_1(prk: &BytesHashLen) -> (BytesCcmKeyLen, BytesCcmIvLen) {
// K_1 = EDHOC-Expand(PRK, info = (0, h'', AES_CCM_KEY_LEN), length)
let mut k_1: BytesCcmKeyLen = [0x00; AES_CCM_KEY_LEN];
let k_1_buf = edhoc_kdf(prk, 0, &[0x00; MAX_KDF_CONTEXT_LEN], 0, AES_CCM_KEY_LEN);
let k_1_buf = edhoc_kdf(
prk,
EAD_ZEROCONF_INFO_K_1_LABEL,
&[0x00; MAX_KDF_CONTEXT_LEN],
0,
AES_CCM_KEY_LEN,
);
k_1[..].copy_from_slice(&k_1_buf[..AES_CCM_KEY_LEN]);

// IV_1 = EDHOC-Expand(PRK, info = (1, h'', AES_CCM_KEY_LEN), length)
let mut iv_1: BytesCcmIvLen = [0x00; AES_CCM_IV_LEN];
// NOTE (FIXME?): here we actually generate AES_CCM_KEY_LEN bytes, but then we only use AES_CCM_IV_LEN of them (next line)
let iv_1_buf = edhoc_kdf(prk, 1, &[0x00; MAX_KDF_CONTEXT_LEN], 0, AES_CCM_KEY_LEN);
let iv_1_buf = edhoc_kdf(
prk,
EAD_ZEROCONF_INFO_IV_1_LABEL,
&[0x00; MAX_KDF_CONTEXT_LEN],
0,
AES_CCM_KEY_LEN,
);
iv_1[..].copy_from_slice(&iv_1_buf[..AES_CCM_IV_LEN]);

(k_1, iv_1)
Expand Down

0 comments on commit 774c8ca

Please sign in to comment.