mirror of
https://github.com/signalapp/libsignal.git
synced 2026-05-10 09:02:05 +02:00
Remove some unused util functions from Java library
The only function Android imports from KeyHelper is generateRegistrationId
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
package org.whispersystems.libsignal.util;
|
||||
|
||||
public abstract class ByteArrayComparator {
|
||||
|
||||
protected int compare(byte[] left, byte[] right) {
|
||||
for (int i = 0, j = 0; i < left.length && j < right.length; i++, j++) {
|
||||
int a = (left[i] & 0xff);
|
||||
int b = (right[j] & 0xff);
|
||||
|
||||
if (a != b) {
|
||||
return a - b;
|
||||
}
|
||||
}
|
||||
|
||||
return left.length - right.length;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package org.whispersystems.libsignal.util;
|
||||
|
||||
import org.whispersystems.libsignal.IdentityKey;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
public class IdentityKeyComparator extends ByteArrayComparator implements Comparator<IdentityKey> {
|
||||
|
||||
@Override
|
||||
public int compare(IdentityKey first, IdentityKey second) {
|
||||
return compare(first.getPublicKey().serialize(), second.getPublicKey().serialize());
|
||||
}
|
||||
}
|
||||
@@ -27,18 +27,6 @@ public class KeyHelper {
|
||||
|
||||
private KeyHelper() {}
|
||||
|
||||
/**
|
||||
* Generate an identity key pair. Clients should only do this once,
|
||||
* at install time.
|
||||
*
|
||||
* @return the generated IdentityKeyPair.
|
||||
*/
|
||||
public static IdentityKeyPair generateIdentityKeyPair() {
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
IdentityKey publicKey = new IdentityKey(keyPair.getPublicKey());
|
||||
return new IdentityKeyPair(publicKey, keyPair.getPrivateKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a registration ID. Clients should only do this once,
|
||||
* at install time.
|
||||
@@ -60,78 +48,4 @@ public class KeyHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getRandomSequence(int max) {
|
||||
try {
|
||||
return SecureRandom.getInstance("SHA1PRNG").nextInt(max);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a list of PreKeys. Clients should do this at install time, and
|
||||
* subsequently any time the list of PreKeys stored on the server runs low.
|
||||
* <p>
|
||||
* PreKey IDs are shorts, so they will eventually be repeated. Clients should
|
||||
* store PreKeys in a circular buffer, so that they are repeated as infrequently
|
||||
* as possible.
|
||||
*
|
||||
* @param start The starting PreKey ID, inclusive.
|
||||
* @param count The number of PreKeys to generate.
|
||||
* @return the list of generated PreKeyRecords.
|
||||
*/
|
||||
public static List<PreKeyRecord> generatePreKeys(int start, int count) {
|
||||
List<PreKeyRecord> results = new LinkedList<>();
|
||||
|
||||
start--;
|
||||
|
||||
for (int i=0;i<count;i++) {
|
||||
results.add(new PreKeyRecord(((start + i) % (Medium.MAX_VALUE-1)) + 1, Curve.generateKeyPair()));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a signed PreKey
|
||||
*
|
||||
* @param identityKeyPair The local client's identity key pair.
|
||||
* @param signedPreKeyId The PreKey id to assign the generated signed PreKey
|
||||
*
|
||||
* @return the generated signed PreKey
|
||||
* @throws InvalidKeyException when the provided identity key is invalid
|
||||
*/
|
||||
public static SignedPreKeyRecord generateSignedPreKey(IdentityKeyPair identityKeyPair, int signedPreKeyId)
|
||||
throws InvalidKeyException
|
||||
{
|
||||
ECKeyPair keyPair = Curve.generateKeyPair();
|
||||
byte[] signature = Curve.calculateSignature(identityKeyPair.getPrivateKey(), keyPair.getPublicKey().serialize());
|
||||
|
||||
return new SignedPreKeyRecord(signedPreKeyId, System.currentTimeMillis(), keyPair, signature);
|
||||
}
|
||||
|
||||
|
||||
public static ECKeyPair generateSenderSigningKey() {
|
||||
return Curve.generateKeyPair();
|
||||
}
|
||||
|
||||
public static byte[] generateSenderKey() {
|
||||
try {
|
||||
byte[] key = new byte[32];
|
||||
SecureRandom.getInstance("SHA1PRNG").nextBytes(key);
|
||||
|
||||
return key;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int generateSenderKeyId() {
|
||||
try {
|
||||
return SecureRandom.getInstance("SHA1PRNG").nextInt(Integer.MAX_VALUE);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user