uniqueSignature -> vrfSignature
// FREEBIE
This commit is contained in:
parent
40106e80ea
commit
f596383883
@ -100,7 +100,7 @@ JNIEXPORT jboolean JNICALL Java_org_whispersystems_curve25519_NativeCurve25519Pr
|
||||
return result;
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519Provider_calculateUniqueSignature
|
||||
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519Provider_calculateVrfSignature
|
||||
(JNIEnv *env, jobject obj, jbyteArray random, jbyteArray privateKey, jbyteArray message)
|
||||
{
|
||||
jbyteArray signature = (*env)->NewByteArray(env, 96);
|
||||
@ -121,7 +121,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519
|
||||
else (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/AssertionError"), "Signature failed!");
|
||||
}
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519Provider_verifyUniqueSignature
|
||||
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519Provider_verifyVrfSignature
|
||||
(JNIEnv *env, jobject obj, jbyteArray publicKey, jbyteArray message, jbyteArray signature)
|
||||
{
|
||||
uint8_t* signatureBytes = (uint8_t*)(*env)->GetByteArrayElements(env, signature, 0);
|
||||
@ -140,7 +140,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_curve25519_NativeCurve25519
|
||||
(*env)->ReleaseByteArrayElements(env, vrf, vrfBytes, 0);
|
||||
|
||||
if (result == 0) return vrf;
|
||||
else (*env)->ThrowNew(env, (*env)->FindClass(env, "org/whispersystems/curve25519/UniqueSignatureVerificationFailedException"), "Invalid signature");
|
||||
else (*env)->ThrowNew(env, (*env)->FindClass(env, "org/whispersystems/curve25519/VrfSignatureVerificationFailedException"), "Invalid signature");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -29,17 +29,17 @@ public class NativeCurve25519Test extends Curve25519Test {
|
||||
byte[] message = new byte[i];
|
||||
random.nextBytes(message);
|
||||
|
||||
byte[] signature = getInstance().calculateUniqueSignature(keys.getPrivateKey(), message);
|
||||
byte[] vrf = getInstance().verifyUniqueSignature(keys.getPublicKey(), message, signature);
|
||||
byte[] signature = getInstance().calculateVrfSignature(keys.getPrivateKey(), message);
|
||||
byte[] vrf = getInstance().verifyVrfSignature(keys.getPublicKey(), message, signature);
|
||||
|
||||
assertFalse(getInstance().verifySignature(keys.getPublicKey(), message, signature));
|
||||
|
||||
message[Math.abs(random.nextInt()) % message.length] ^= 0x01;
|
||||
|
||||
try {
|
||||
getInstance().verifyUniqueSignature(keys.getPublicKey(), message, signature);
|
||||
getInstance().verifyVrfSignature(keys.getPublicKey(), message, signature);
|
||||
throw new AssertionError("Should have failed");
|
||||
} catch (UniqueSignatureVerificationFailedException e) {
|
||||
} catch (VrfSignatureVerificationFailedException e) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
@ -47,8 +47,8 @@ public class NativeCurve25519Test extends Curve25519Test {
|
||||
|
||||
public void testUniqueSignatureVector() throws Exception {
|
||||
Curve25519KeyPair keys = new Curve25519KeyPair(PUBLIC_KEY, PRIVATE_KEY);
|
||||
byte[] signature = getInstance().calculateUniqueSignature(keys.getPrivateKey(), MESSAGE);
|
||||
byte[] vrf = getInstance().verifyUniqueSignature(keys.getPublicKey(), MESSAGE, signature);
|
||||
byte[] signature = getInstance().calculateVrfSignature(keys.getPrivateKey(), MESSAGE);
|
||||
byte[] vrf = getInstance().verifyVrfSignature(keys.getPublicKey(), MESSAGE, signature);
|
||||
|
||||
assertTrue(Arrays.equals(vrf, VRF));
|
||||
}
|
||||
|
||||
@ -73,12 +73,12 @@ abstract class BaseJavaCurve25519Provider implements Curve25519Provider {
|
||||
return curve_sigs.curve25519_verify(sha512provider, signature, publicKey, message, message.length) == 0;
|
||||
}
|
||||
|
||||
public byte[] calculateUniqueSignature(byte[] random, byte[] privateKey, byte[] message) {
|
||||
public byte[] calculateVrfSignature(byte[] random, byte[] privateKey, byte[] message) {
|
||||
throw new AssertionError("NYI");
|
||||
}
|
||||
|
||||
public byte[] verifyUniqueSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws UniqueSignatureVerificationFailedException
|
||||
public byte[] verifyVrfSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws VrfSignatureVerificationFailedException
|
||||
{
|
||||
throw new AssertionError("NYI");
|
||||
}
|
||||
|
||||
@ -124,13 +124,13 @@ public class Curve25519 {
|
||||
* @param message The message to sign.
|
||||
* @return A 96-byte signature.
|
||||
*/
|
||||
public byte[] calculateUniqueSignature(byte[] privateKey, byte[] message) {
|
||||
public byte[] calculateVrfSignature(byte[] privateKey, byte[] message) {
|
||||
if (privateKey == null || privateKey.length != 32) {
|
||||
throw new IllegalArgumentException("Invalid private key!");
|
||||
}
|
||||
|
||||
byte[] random = provider.getRandom(64);
|
||||
return provider.calculateUniqueSignature(random, privateKey, message);
|
||||
return provider.calculateVrfSignature(random, privateKey, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,18 +142,18 @@ public class Curve25519 {
|
||||
*
|
||||
* @return The vrf for this signature.
|
||||
*/
|
||||
public byte[] verifyUniqueSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws UniqueSignatureVerificationFailedException
|
||||
public byte[] verifyVrfSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws VrfSignatureVerificationFailedException
|
||||
{
|
||||
if (publicKey == null || publicKey.length != 32) {
|
||||
throw new IllegalArgumentException("Invalid public key!");
|
||||
}
|
||||
|
||||
if (message == null || signature == null || signature.length != 96) {
|
||||
throw new UniqueSignatureVerificationFailedException("Invalid message or signature format");
|
||||
throw new VrfSignatureVerificationFailedException("Invalid message or signature format");
|
||||
}
|
||||
|
||||
return provider.verifyUniqueSignature(publicKey, message, signature);
|
||||
return provider.verifyVrfSignature(publicKey, message, signature);
|
||||
}
|
||||
|
||||
private static Curve25519Provider constructNativeProvider(SecureRandomProvider random) throws NoSuchProviderException {
|
||||
|
||||
@ -18,9 +18,9 @@ interface Curve25519Provider {
|
||||
|
||||
byte[] calculateSignature(byte[] random, byte[] privateKey, byte[] message);
|
||||
boolean verifySignature(byte[] publicKey, byte[] message, byte[] signature);
|
||||
byte[] calculateUniqueSignature(byte[] random, byte[] privateKey, byte[] message);
|
||||
byte[] verifyUniqueSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws UniqueSignatureVerificationFailedException;
|
||||
byte[] calculateVrfSignature(byte[] random, byte[] privateKey, byte[] message);
|
||||
byte[] verifyVrfSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws VrfSignatureVerificationFailedException;
|
||||
|
||||
byte[] getRandom(int length);
|
||||
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
package org.whispersystems.curve25519;
|
||||
|
||||
public class UniqueSignatureVerificationFailedException extends Exception {
|
||||
|
||||
public UniqueSignatureVerificationFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UniqueSignatureVerificationFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UniqueSignatureVerificationFailedException(Exception exception) {
|
||||
super(exception);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package org.whispersystems.curve25519;
|
||||
|
||||
public class VrfSignatureVerificationFailedException extends Exception {
|
||||
|
||||
public VrfSignatureVerificationFailedException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public VrfSignatureVerificationFailedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public VrfSignatureVerificationFailedException(Exception exception) {
|
||||
super(exception);
|
||||
}
|
||||
}
|
||||
@ -73,11 +73,11 @@ class NativeCurve25519Provider implements Curve25519Provider {
|
||||
public native boolean verifySignature(byte[] publicKey, byte[] message, byte[] signature);
|
||||
|
||||
@Override
|
||||
public native byte[] calculateUniqueSignature(byte[] random, byte[] privateKey, byte[] message);
|
||||
public native byte[] calculateVrfSignature(byte[] random, byte[] privateKey, byte[] message);
|
||||
|
||||
@Override
|
||||
public native byte[] verifyUniqueSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws UniqueSignatureVerificationFailedException;
|
||||
public native byte[] verifyVrfSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws VrfSignatureVerificationFailedException;
|
||||
|
||||
private native boolean smokeCheck(int dummy);
|
||||
|
||||
|
||||
@ -64,15 +64,15 @@ public class OpportunisticCurve25519Provider implements Curve25519Provider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] calculateUniqueSignature(byte[] random, byte[] privateKey, byte[] message) {
|
||||
return delegate.calculateUniqueSignature(random, privateKey, message);
|
||||
public byte[] calculateVrfSignature(byte[] random, byte[] privateKey, byte[] message) {
|
||||
return delegate.calculateVrfSignature(random, privateKey, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] verifyUniqueSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws UniqueSignatureVerificationFailedException
|
||||
public byte[] verifyVrfSignature(byte[] publicKey, byte[] message, byte[] signature)
|
||||
throws VrfSignatureVerificationFailedException
|
||||
{
|
||||
return delegate.verifyUniqueSignature(publicKey, message, signature);
|
||||
return delegate.verifyVrfSignature(publicKey, message, signature);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user