Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
uniqueSignature -> vrfSignature
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
moxie0 committed Oct 18, 2016
1 parent 40106e8 commit f596383
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 45 deletions.
6 changes: 3 additions & 3 deletions android/jni/curve25519-jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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");
}


Expand Down
Binary file modified android/libs/armeabi-v7a/libcurve25519.so
Binary file not shown.
Binary file modified android/libs/armeabi/libcurve25519.so
Binary file not shown.
Binary file modified android/libs/mips/libcurve25519.so
Binary file not shown.
Binary file modified android/libs/x86/libcurve25519.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public void testUniqueSignatures() throws Exception {
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
}
}
}

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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ public boolean verifySignature(byte[] publicKey, byte[] message, byte[] signatur
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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public boolean verifySignature(byte[] publicKey, byte[] message, byte[] signatur
* @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);
}

/**
Expand All @@ -142,18 +142,18 @@ public byte[] calculateUniqueSignature(byte[] privateKey, byte[] message) {
*
* @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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public void setRandomProvider(SecureRandomProvider provider) {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ public boolean verifySignature(byte[] publicKey, byte[] message, byte[] signatur
}

@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);
}

}

0 comments on commit f596383

Please sign in to comment.