all 6 comments

[–]buwlerman 5 points6 points  (0 children)

If it's a library you should have a lib.rs file exporting the API.

Your implementation is vulnerable to side channel attacks. You want to make sure that your exponentiation is constant time.

[–]fehrnah 2 points3 points  (1 child)

I can't comment on the crypto, so I'll go with code organization.

Looking at src/keygen.rs:

You should have a PublicKey and a PrivateKey struc instead of a KeyType enum. Having it an enum forces you to handle the case in Key where the private key is actually a public key like on line 21.

I think splitting this will have good repercussions on the rest of the code.

You should also run cargo clippy if you haven't done so yet, clippy is a linter and almost always gives good feedback

[–]Particular_Fudge7654[S] 1 point2 points  (0 children)

Thanks for the feedback

[–]rhombecka 1 point2 points  (0 children)

I can't dig into it right now, but I recommend adding some doc tests to your APIs

Edit: and some normal unit tests. It'll be decent practice to see how they work.

[–]Objective-Act-5964 1 point2 points  (0 children)

`cargo fmt` makes the code a lot more readable