-
Notifications
You must be signed in to change notification settings - Fork 64
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
Improve ssi-crypto
.
#642
base: main
Are you sure you want to change the base?
Improve ssi-crypto
.
#642
Conversation
666717c
to
25af31b
Compare
eb5bf82
to
24e098f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the changes to the algorithms casing really that important? I understand it's not exactly idiomatic, but at the same time they're essentially acronyms so it doesn't matter that much, it's additional breaking changes, and it makes this PR harder to review
No its not important, but it's the convention and I feel like it's now or never to make breaking changes. I can make that in another PR, but would that really help? Alternatively I can revert the names for the |
crates/bbs/src/lib.rs
Outdated
// pub struct | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// pub struct |
/// Key type. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[non_exhaustive] | ||
pub enum EcdsaKeyType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curve instead of KeyType?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went back and forth between KeyType and Curve 😅 If you prefer Curve I'll use that instead.
crates/claims/crates/jws/src/lib.rs
Outdated
// let padding; | ||
// let hashed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// let padding; | |
// let hashed; |
|
||
/// ECDSA using secp256k1 (K-256) and SHA-256, with or without recovery bit. | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub enum AnyES { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub enum AnyES { | |
pub enum AnyES256K { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I intend to remove what's in the static
module. Those types are used by the Data Integrity libs, but now that we have low-level Signer
and Verifier
traits we'll be able to use the Algorithm
type directly. Also I feel like defining static types for crypto algorithm is RustCrypto's job, not ssi-crypto
's.
bytes.push(0x04); | ||
bytes.extend(x); | ||
bytes.extend(y); | ||
Self::from_k256_sec1_bytes(&bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW you can use k256::EncodedPoint::from_untagged_bytes
or from_affine_coordinates
to avoid messing around with SEC1 tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the key conversion functions are coming straight from ssi_jwk
.
avoid messing around with SEC1 tags
Oh that's what the 0x04
is? Yeah that's why I did change anything, I wasn't sure what format that was.
use super::KeyType; | ||
|
||
#[derive(Clone, ZeroizeOnDrop)] | ||
pub struct SymmetricKey(Box<[u8]>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Box<[u8]> instead of Vec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vec
provides more capabilities like resizing that we don't need here. So to me the question is more "Why Vec when Box<[u8]> is enough"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in most applications an owned slice will be a Vec, so we're adding unnecessary overhead by requiring conversion between Box<[u8]> and Vec.
Additional capabilities on a Vec don't actually cause any issues right? There's just an extra byte of memory used to store the capacity of the slice.
Conversion from Vec to Box<[u8]> requires shrinking the Vec to capacity, manually dropping and reading the vec into a new buffer. I'm not an expert but I think that also implies that the original Vec buffer is not reused and therefore not zeroized. So overall I think it makes more sense to take ownership of the Vec. I was wrong about that part, the Box manually drops the original buffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RustCrypo always use fixed-length arrays, not Vec
, so I'm not worried about shrinking stuff. But it's true that many functions are expecting Vec
s so I'm not going to fight for it, I'll remove the Box<[u8]>
s.
crates/crypto/src/options.rs
Outdated
*<Box<dyn Send + Sync + Any>>::downcast(t).unwrap() | ||
} | ||
|
||
#[allow(clippy::borrowed_box)] | ||
fn downcast_ref<T: 'static>(t: &Box<dyn Send + Sync + Any>) -> &T { | ||
t.downcast_ref().unwrap() | ||
} | ||
|
||
#[allow(clippy::borrowed_box)] | ||
fn downcast_mut<T: 'static>(t: &mut Box<dyn Send + Sync + Any>) -> &mut T { | ||
t.downcast_mut().unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave comments describing why the unwrap won't ever panic.
efae969
to
b25caac
Compare
Description
Improves the
ssi-crypto
library:ring
), where algorithms can be selected at run time instead of compile time.JwsSigner
).The important changes are in the
ssi-crypto
library. The only reason why there are so many changes in other files is because I renamed a few algorithm variants to follow Rust naming conventions, and merged thessi-crypto
error types into one.Tested