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

Schnorr signature #6

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Schnorr signature #6

wants to merge 13 commits into from

Conversation

gtillem
Copy link
Collaborator

@gtillem gtillem commented Oct 29, 2020

PR for the implementation of Schnorr signatures. The code implements a variant of Schnorr signatures, EdDSA on AltBabyJubJub curve using Blake2 hash functions.

The signing algorithm has two variants: One with the raw message, i.e., the message is not hashed before signing, and one with message hashing.

@gtillem gtillem requested review from mvdbos and vnermolaev October 29, 2020 09:23
import java.security.SecureRandom
import kotlin.random.Random.Default.nextBytes

enum class Hash{
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this not already defined somewhere in the lib? because Alexei did one of this hashes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not, afaik. But I removed this outside of this class and defined as an enum with other supported hash functions. Because, in the future, Mimc or Poseidon can be used here.

@vnermolaev
Copy link
Collaborator

Please see spotlessApply task in zk-notary to format your code.

In general, very usefu, looking forward to embedd this in into the zk-notary!

Copy link
Collaborator

@mvdbos mvdbos left a comment

Choose a reason for hiding this comment

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

First of all: nice work! really cool to have this.

I have only two minor comments for now.

One question: I see some of Victor's comments marked as resolved, but no code changed for it. Is that the result of agreement between you outside GitHub comments? I have +1'd the ones I feel still need to be addressed.

Finally, I agree with Victor that this would be a good time to 'upgrade' the build of this project a bit with both Junit5 and Spotless. Alternatively do it directly after in a separate PR. It is easily copied from the ZK Notary project. I can help with that.


return Signature(rPoint, s)
}

fun signHashedMessage(msgBytes: ByteArray) : Signature {
fun signHashedMessage(msgBytes: ByteArray): Signature {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This now also only supports messages of MAX_MESSAGE_SIZE. What is the added value above the raw version then? Why don't we make it support any length? That should be possible with Blake2s, right?

import org.junit.jupiter.api.Test
import java.math.BigInteger

import kotlin.system.measureNanoTime

class SchnorrSignatureTest {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to see more tests (preferably one parametrized test) that use test vectors that prove that this is really a conforming implementation. Are there test vectors we can get from somewhere? Possibly not for this specific curve, but I think vectors exist for Secp256k1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added tests with test vectors. I used the message values from Zinc and from Corda EdDSA, which are smaller than 32 bytes. I also needed to add a setter function for keys and remove seed generation out of the signing function to be able to compare the generated values with the test vectors.

/**
* Implementation of Schnorr signatures
* This implementation uses AltBabyJubJub curve and Blake2 hash
*/

class SchnorrSignature (
class SchnorrSignature(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you already looked at how to integrate this into Corda through/as a Security Provider? I thought to be able to do that, the Signature implementation has to be a SignatureSpi:

 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
 * for the {@code Signature} class, which is used to provide the
 * functionality of a digital signature algorithm. Digital signatures are used
 * for authentication and integrity assurance of digital data.
 *.
 * <p> All the abstract methods in this class must be implemented by each
 * cryptographic service provider who wishes to supply the implementation
 * of a particular signature algorithm.

And this would also require you to make the keys as standard keys: java.security.PublicKey and java.security.PrivateKey.

That said, I am not a specialist in this area, I just looked at where Corda gets its supported signature schemes from and how they are used. Perhaps you have found another, easier way in which the current API you designed can be used.

Warning: 'Expected performance impact from inlining is insignificant.
Inlining works best for functions with parameters of functional types'.

So removed inline prefix.
@mvdbos mvdbos force-pushed the schnorr-signature branch from c4e0e1e to 4283283 Compare October 30, 2020 14:56
@alexeykoren
Copy link
Contributor

Maybe also update readme file?

@gtillem
Copy link
Collaborator Author

gtillem commented Nov 4, 2020

Maybe also update readme file?

Updated it now!

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.

4 participants