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

Trying to use vanilla psa wrapper #159

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ hacspec-hkdf = { git = "https://github.com/malishav/hacspec", branch = "aesccm"
hacspec-sha256 = { git = "https://github.com/malishav/hacspec", branch = "aesccm" }
hacspec-aes = { git = "https://github.com/malishav/hacspec", branch = "aesccm" }
hacspec-aes-ccm = { git = "https://github.com/malishav/hacspec", branch = "aesccm" }
psa-crypto = { git = "https://github.com/malishav/rust-psa-crypto", branch = "baremetal" }
psa-crypto = { git = "https://github.com/geonnave/rust-psa-crypto", branch = "have-no-std-and-baremetal-features" }
3 changes: 2 additions & 1 deletion crypto/edhoc-crypto-psa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ repository.workspace = true

[dependencies]
edhoc-consts.workspace = true
psa-crypto = { version = "0.9.2" }
psa-crypto = { version = "0.12.0" }
p256 = { version = "0.13.2", default-features = false, features = [ "ecdh" ] }

[features]
baremetal = [ "psa-crypto/baremetal" ]
12 changes: 9 additions & 3 deletions crypto/edhoc-crypto-psa/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![no_std]

use edhoc_consts::{Crypto as CryptoTrait, *};
use p256::elliptic_curve::point::DecompressPoint;
use p256::elliptic_curve::sec1::ToEncodedPoint;
use psa_crypto::operations::hash::hash_compute;
use psa_crypto::operations::{aead, key_agreement, key_management, other::generate_random};
use psa_crypto::types::algorithm::Hash;
Expand Down Expand Up @@ -174,9 +176,13 @@ impl CryptoTrait for Crypto {
private_key: &BytesP256ElemLen,
public_key: &BytesP256ElemLen,
) -> BytesP256ElemLen {
let mut peer_public_key: [u8; 33] = [0; 33];
peer_public_key[0] = 0x02; // sign does not matter for ECDH operation
peer_public_key[1..33].copy_from_slice(&public_key[..]);
let peer_public_key = p256::AffinePoint::decompress(
public_key.into(),
1.into(), /* Y coordinate choice does not matter for ECDH operation */
)
.unwrap()
.to_encoded_point(false);
let peer_public_key = peer_public_key.as_bytes();

let alg = RawKeyAgreement::Ecdh;
let mut usage_flags: UsageFlags = Default::default();
Expand Down
Loading