vite.crypto.Curve25519 Maven / Gradle / Ivy
package vite.crypto;
import java.util.Arrays;
public final class Curve25519 {
private static final Curve25519 instance = new Curve25519();
public static Curve25519 create() {
return instance;
}
private final org.whispersystems.curve25519.Curve25519 curve25519
= org.whispersystems.curve25519.Curve25519.getInstance(org.whispersystems.curve25519.Curve25519.JAVA);
Curve25519() {
}
public byte[] agreement(byte[] publicKey, byte[] privateKey) {
// org.whispersystems.curve25519.BaseJavaCurve25591Provider#calculateAgreement appears to be thread safe.
return curve25519.calculateAgreement(publicKey, clampPrivateKey(privateKey));
}
byte[] clampPrivateKey(byte[] privateKey) {
byte[] copy = Arrays.copyOf(privateKey, privateKey.length);
copy[0] &= 0xF8;
copy[31] &= 0x7F;
copy[31] |= 0x40;
return copy;
}
}