Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BytesKeyEC2: Prepare curve validation #328

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion shared/src/cred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,29 @@ pub type BufferCred = EdhocBuffer<192>; // arbitrary size
pub type BufferKid = EdhocBuffer<16>; // variable size, up to 16 bytes
pub type BufferIdCred = EdhocBuffer<192>; // variable size, can contain either the contents of a BufferCred or a BufferKid
pub type BytesKeyAES128 = [u8; 16];
pub type BytesKeyEC2 = [u8; 32];

#[derive(Debug, Copy, Clone, PartialEq)]
pub struct BytesKeyEC2(BytesP256ElemLen);

impl TryFrom<BytesP256ElemLen> for BytesKeyEC2 {
type Error = EDHOCError;

fn try_from(value: BytesP256ElemLen) -> Result<Self, Self::Error> {
// Not performing any validation yet
Ok(Self(value))
}
}

// This is convenient in particular while transitioning away from `pub type BytesKeyEC2 = [u8;
// 32]`, because try_into was a common way to get it.
impl TryFrom<&[u8]> for BytesKeyEC2 {
type Error = EDHOCError;

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
let slice: BytesP256ElemLen = value.try_into().map_err(|_| EDHOCError::ParsingError)?;
slice.try_into()
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
#[repr(C)]
Expand Down
Loading