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 asymmetric encrypt and decrypt to psa-crypto and psa-crypto-sys #37

Merged
merged 1 commit into from
Jul 6, 2020

Conversation

sbailey-arm
Copy link
Contributor

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

Signed-off-by: Samuel Bailey <samuel.bailey@arm.com>
@sbailey-arm sbailey-arm force-pushed the add-asym-encryption branch from a8192a5 to b93fd93 Compare July 3, 2020 14:54
@sbailey-arm sbailey-arm marked this pull request as ready for review July 3, 2020 15:38
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.

This all look very good, thanks a lot! Just one remark.

@@ -88,6 +88,10 @@ pub fn PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) == 1 }
}

pub unsafe fn PSA_ALG_IS_RSA_OAEP(alg: psa_algorithm_t) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

I think this one can be safe because it can only return 1 or 0 with no unspecified behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did wonder about this one. I put unsafe because although it can only return 0 or 1, if you give it an unsupported input, the value it returns doesn't necessarily tell you that (because it can be either 0 or 1), so you couldn't trust it.

Copy link
Member

Choose a reason for hiding this comment

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

I see what you mean that, you could give it a value that is not one of the recognised possible algorithm value for psa_algorithm_t, and the result would not really make sense.
In my opinion, psa_algorithm_t being just a typedef for u32, you are allowed to call this function with any u32 value and for all these values, the function will always return true or false and never exhibit an unsafe behaviour.

I guess the problem is what you define as safe/unsafe :/

This is mostly bikeshedding at this point, so please ignore, it is not really important, and it is perfectly fine with unsafe 👌

Comment on lines +368 to +370
match unsafe { psa_crypto_sys::PSA_EXPORT_KEY_OUTPUT_SIZE(key_type.try_into()?, bits) } {
0 => Err(Error::NotSupported),
size => Ok(size),
Copy link
Member

Choose a reason for hiding this comment

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

🙆‍♂️

@hug-dev hug-dev requested review from ionut-arm and egrimley-arm July 3, 2020 15:52
@hug-dev hug-dev added the enhancement New feature or request label Jul 3, 2020
@ionut-arm ionut-arm merged commit 44486bb into parallaxsecond:master Jul 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants