Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Make keys compatible with Java framework #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ sourceSets {

dependencies {
compile "org.whispersystems:curve25519-java:${curve25519_version}"
compile 'com.google.protobuf:protobuf-javalite:3.10.0'
compile 'com.google.protobuf:protobuf-java:3.17.3'

testCompile ('junit:junit:3.8.2')
}

protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.10.0'
artifact = 'com.google.protobuf:protoc:3.17.3'
}
generateProtoTasks {
all().each { task ->
Expand Down
12 changes: 6 additions & 6 deletions java/src/main/java/org/whispersystems/libsignal/ecc/Curve.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey priv

if (publicKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateAgreement(((DjbECPublicKey) publicKey).getPublicKey(),
((DjbECPrivateKey) privateKey).getPrivateKey());
.calculateAgreement(((DjbECPublicKey) publicKey).getEncoded(),
((DjbECPrivateKey) privateKey).getEncoded());
} else {
throw new InvalidKeyException("Unknown type: " + publicKey.getType());
}
Expand All @@ -87,7 +87,7 @@ public static boolean verifySignature(ECPublicKey signingKey, byte[] message, by

if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.verifySignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
.verifySignature(((DjbECPublicKey) signingKey).getEncoded(), message, signature);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
Expand All @@ -102,7 +102,7 @@ public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)

if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateSignature(((DjbECPrivateKey) signingKey).getPrivateKey(), message);
.calculateSignature(((DjbECPrivateKey) signingKey).getEncoded(), message);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
Expand All @@ -117,7 +117,7 @@ public static byte[] calculateVrfSignature(ECPrivateKey signingKey, byte[] messa

if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.calculateVrfSignature(((DjbECPrivateKey)signingKey).getPrivateKey(), message);
.calculateVrfSignature(((DjbECPrivateKey)signingKey).getEncoded(), message);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
Expand All @@ -132,7 +132,7 @@ public static byte[] verifyVrfSignature(ECPublicKey signingKey, byte[] message,

if (signingKey.getType() == DJB_TYPE) {
return Curve25519.getInstance(BEST)
.verifyVrfSignature(((DjbECPublicKey) signingKey).getPublicKey(), message, signature);
.verifyVrfSignature(((DjbECPublicKey) signingKey).getEncoded(), message, signature);
} else {
throw new InvalidKeyException("Unknown type: " + signingKey.getType());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2013-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
Expand All @@ -14,17 +14,29 @@ public class DjbECPrivateKey implements ECPrivateKey {
this.privateKey = privateKey;
}

@Override
public String getAlgorithm() {
return "Curve25519";
}

@Override
public String getFormat() {
return "RAW";
}

@Override
public byte[] getEncoded() {
return this.privateKey;
}

@Override
public byte[] serialize() {
return privateKey;
return this.privateKey;
}

@Override
public int getType() {
return Curve.DJB_TYPE;
}

public byte[] getPrivateKey() {
return privateKey;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2013-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
Expand All @@ -19,10 +19,25 @@ public class DjbECPublicKey implements ECPublicKey {
this.publicKey = publicKey;
}

@Override
public String getAlgorithm() {
return "Curve25519";
}

@Override
public String getFormat() {
return "RAW";
}

@Override
public byte[] getEncoded() {
return this.publicKey;
}

@Override
public byte[] serialize() {
byte[] type = {Curve.DJB_TYPE};
return ByteUtil.combine(type, publicKey);
return ByteUtil.combine(type, this.publicKey);
}

@Override
Expand All @@ -49,7 +64,4 @@ public int compareTo(ECPublicKey another) {
return new BigInteger(publicKey).compareTo(new BigInteger(((DjbECPublicKey)another).publicKey));
}

public byte[] getPublicKey() {
return publicKey;
}
}
18 changes: 11 additions & 7 deletions java/src/main/java/org/whispersystems/libsignal/ecc/ECKeyPair.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
/**
/*
* Copyright (C) 2013-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/
package org.whispersystems.libsignal.ecc;

import java.security.KeyPair;

public class ECKeyPair {

private final ECPublicKey publicKey;
private final ECPrivateKey privateKey;
private final KeyPair keyPair;

public ECKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
this.keyPair = new KeyPair(publicKey,privateKey);
}

public KeyPair getKeyPair() {
return this.keyPair;
}

public ECPublicKey getPublicKey() {
return publicKey;
return (ECPublicKey) this.keyPair.getPublic();
}

public ECPrivateKey getPrivateKey() {
return privateKey;
return (ECPrivateKey) this.keyPair.getPrivate();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
/*
* Copyright (C) 2013-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/

package org.whispersystems.libsignal.ecc;

public interface ECPrivateKey {
public byte[] serialize();
public int getType();
import java.security.PrivateKey;

public interface ECPrivateKey extends PrivateKey {
byte[] serialize();
int getType();
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/**
/*
* Copyright (C) 2013-2016 Open Whisper Systems
*
* Licensed according to the LICENSE file in this repository.
*/

package org.whispersystems.libsignal.ecc;

public interface ECPublicKey extends Comparable<ECPublicKey> {
import java.security.PublicKey;

public static final int KEY_SIZE = 33;
public interface ECPublicKey extends PublicKey, Comparable<ECPublicKey> {

public byte[] serialize();
int KEY_SIZE = 33;

public int getType();
byte[] serialize();

int getType();
}