KeyEncoding: Clean up and reorganize to match style

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland
2017-08-09 02:51:08 -05:00
parent c3afe5be2c
commit f0f9192aed
3 changed files with 85 additions and 71 deletions
@@ -1,7 +1,5 @@
package com.wireguard.crypto;
import android.util.Base64;
import java.security.SecureRandom;
/**
@@ -11,7 +9,7 @@ import java.security.SecureRandom;
public class Keypair {
private static byte[] generatePrivateKey() {
final SecureRandom secureRandom = new SecureRandom();
final byte[] privateKey = new byte[KeyEncoding.WG_KEY_LEN];
final byte[] privateKey = new byte[KeyEncoding.KEY_LENGTH];
secureRandom.nextBytes(privateKey);
privateKey[0] &= 248;
privateKey[31] &= 127;
@@ -20,7 +18,7 @@ public class Keypair {
}
private static byte[] generatePublicKey(byte[] privateKey) {
final byte[] publicKey = new byte[KeyEncoding.WG_KEY_LEN];
final byte[] publicKey = new byte[KeyEncoding.KEY_LENGTH];
Curve25519.eval(publicKey, 0, privateKey, null);
return publicKey;
}