-
Notifications
You must be signed in to change notification settings - Fork 258
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
Implementation of serde traits? #310
Comments
Perhaps before |
The lack of serializable/deserializable state is enough of a blocker for me at this point that I'd be willing to take a stab at this with some guidance. It's been recommended that I consider using the compress functions directly but there are some complications to this for me given my lack of cryptographic knowledge and the extensive use of various traits that make it hard to understand how to properly finalize the output:
It looks like i would end up implementing my own janky half-assed versions of To get me started, I would have to know at which level to implement |
I just realized that the block isn't directly related to the state array size. It may be best just to have something like
And just leave slice correctness checking up to the implementation. Or maybe there's a better way to do it with
Though things get a little fuzzy for me when trying to wrap my head around Though come to think of it they also differ in integer size so it might have to be |
fn serialize_state(&mut self) -> &[u8]; This assumes the state is internally represented contiguously as bytes, which may not be the case.
Serializing to some sort of fixed-sized byte array would probably make the most sense. Note that doesn't necessarily have to be a pub trait SerializableState {
type Serialization: AsRef<[u8]> + AsMut<[u8]>;
fn serialize_state(&mut self) -> &Self::Serialization;
fn from_serialized_state(&Self::Serialization) -> Self;
} Then when it comes time to impl the trait, use an array type like |
RustCrypto/traits#1369 has landed which provides some initial serialization support |
It's much worse than leaking unprocessed data. I'd expect serialzied state breaks the primitives in "most" ways. It's fine if used in non-adversarial ways of course, like if the same signer makes a lot of signatures on the same data, but it's broken if say a serialized state were passed to a remote signer. It needs serious warnings.
|
Just FYI but it seems this PR finishes the "serializable state" issue and with it I was able to finally capture the hasher state and restore it. Code example here: https://github.com/wiktor-k/hasher-test/blob/main/src/main.rs |
Going to close this as completed then by way of Despite earlier comments, I don't think it makes sense to conflate
|
A way to serialize state of the
Sm3
hash function was requested in #304. Do we want to implement theserde
traits for hash functions (behind an optional feature)? It may be useful in some cases for transferring state for partially hashed messages.Reasons against it:
serde
traits somewhat restricts our freedom of changing inner representation of hash functions. Currently all functions have the same state representation regardless of target architecture or available CPU features, but it may change in future.Currently I am leaning towards the "against" position, but I think it's worth to discuss it nevertheless.
The text was updated successfully, but these errors were encountered: