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

Added aead encrypt decrypt, hash compute compare and raw key agreement #229

Merged
merged 1 commit into from
Aug 21, 2020

Conversation

sbailey-arm
Copy link
Contributor

Bit of a big 'un but chunks of it are pretty simple and it saved adding more panics for individual operations.

Signed-off-by: Samuel Bailey samuel.bailey@arm.com

self.result_to_response(NativeResult::PsaHashCompare(result), header)
}
NativeOperation::PsaGenerateRandom(_) => {
panic!("Unsupported in this PR");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two panic!s are to pass CI. We have pending PRs for PsaGenerateRandom and ListAuthenticators, so should be immediately removed once those are merged.

Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! It is very nice to see all those new operations in 👌 A few comments but I am generally happy with this!

Cargo.toml Outdated
Comment on lines 49 to 50
[patch.crates-io]
psa-crypto = { git = "https://github.com/parallaxsecond/rust-psa-crypto" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, latest version with the helper methods has not been released on crates.io.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I will release a new version.

Attributes {
lifetime: Lifetime::Persistent,
key_type: Type::Aes,
bits: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it fine for bits to be 0 here? Similarly for other functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently! Some of the tests were taken from Mbed TLS, which used default (0) bits. I can try changing them but I'm pertty sure in some instances I ran into trouble when changing from 0 to something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that's weird. It says:

The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or 32 bytes (AES-256).

0x1f, 0x57, 0xdd, 0x3a, 0x7d, 0xfe, 0xd3, 0xc5, 0xef, 0x24, 0x1f, 0xa3, 0xf0, 0x0c, 0x5c, 0x02, 0xda, 0x98, 0x55, 0x97, 0x0d];

#[test]
fn simple_aead_encrypt_ccm() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🥳 So nice to see the end result of those tests after so much effort!

return;
}

let hash = client.hash_compute(Hash::Sha512, &MESSAGE).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You used Sha512 and not Whirlpool :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I originally used whirlpool but found we don't support it.

@@ -0,0 +1,78 @@
// Copyright 2020 Contributors to the Parsec project.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For raw key agreement can you have a test where you generate two keys pairs, do the raw agreement on each private key with the other key pair's public key and verify that the shared secret output is the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍

@@ -7,8 +7,9 @@ use derivative::Derivative;
use log::{error, trace};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to add in that file the new supported opcodes. And modify one test that is about it as well I think.

&self,
op: psa_hash_compute::Operation,
) -> Result<psa_hash_compute::Result> {
trace!("psa_hash_compute");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot the ingress there :)

@sbailey-arm sbailey-arm self-assigned this Aug 20, 2020
let shared_secret_2_then_1 = client
.raw_key_agreement(RawKeyAgreement::Ecdh, key_name_2.clone(), &public_key_1)
.unwrap();
assert_eq!(shared_secret_1_then_2, shared_secret_2_then_1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice to know it actually works 👏

Signed-off-by: Samuel Bailey <samuel.bailey@arm.com>
@hug-dev hug-dev merged commit 5cb7685 into parallaxsecond:master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants