aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/whispersystems/libaxolotl/ecc
diff options
context:
space:
mode:
authorMoxie Marlinspike <moxie@thoughtcrime.org>2015-01-08 13:48:49 -0800
committerMoxie Marlinspike <moxie@thoughtcrime.org>2015-01-08 14:09:01 -0800
commit6445ea5f13850f42c3952bd06a2369317683ed88 (patch)
treef2bb37c8cf4710ff6a6a37a3e7e702c5a21ca504 /src/main/java/org/whispersystems/libaxolotl/ecc
parenta4d8f7f6a4c4e9e89db35f299e558dceee2362a1 (diff)
Break project up into Java and Android build/test.
Diffstat (limited to 'src/main/java/org/whispersystems/libaxolotl/ecc')
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java78
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java98
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPrivateKey.java41
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPublicKey.java66
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/ECKeyPair.java37
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/ECPrivateKey.java23
-rw-r--r--src/main/java/org/whispersystems/libaxolotl/ecc/ECPublicKey.java27
7 files changed, 0 insertions, 370 deletions
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java b/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java
deleted file mode 100644
index 66b8cc3a..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.whispersystems.libaxolotl.ecc;
-
-import org.whispersystems.libaxolotl.InvalidKeyException;
-
-public class Curve {
-
- public static final int DJB_TYPE = 0x05;
-
- public static ECKeyPair generateKeyPair() {
- return Curve25519.generateKeyPair();
- }
-
- public static ECPublicKey decodePoint(byte[] bytes, int offset)
- throws InvalidKeyException
- {
- int type = bytes[offset];
-
- if (type == DJB_TYPE) {
- return Curve25519.decodePoint(bytes, offset);
- } else {
- throw new InvalidKeyException("Unknown key type: " + type);
- }
- }
-
- public static ECPrivateKey decodePrivatePoint(byte[] bytes) {
- return new DjbECPrivateKey(bytes);
- }
-
- public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey)
- throws InvalidKeyException
- {
- if (publicKey.getType() != privateKey.getType()) {
- throw new InvalidKeyException("Public and private keys must be of the same type!");
- }
-
- if (publicKey.getType() == DJB_TYPE) {
- return Curve25519.calculateAgreement(publicKey, privateKey);
- } else {
- throw new InvalidKeyException("Unknown type: " + publicKey.getType());
- }
- }
-
- public static boolean verifySignature(ECPublicKey signingKey, byte[] message, byte[] signature)
- throws InvalidKeyException
- {
- if (signingKey.getType() == DJB_TYPE) {
- return Curve25519.verifySignature(signingKey, message, signature);
- } else {
- throw new InvalidKeyException("Unknown type: " + signingKey.getType());
- }
- }
-
- public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)
- throws InvalidKeyException
- {
- if (signingKey.getType() == DJB_TYPE) {
- return Curve25519.calculateSignature(signingKey, message);
- } else {
- throw new InvalidKeyException("Unknown type: " + signingKey.getType());
- }
- }
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java b/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java
deleted file mode 100644
index 685a4a11..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.whispersystems.libaxolotl.ecc;
-
-import org.whispersystems.libaxolotl.InvalidKeyException;
-
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-
-public class Curve25519 {
-
- static {
- System.loadLibrary("curve25519");
-
- try {
- random = SecureRandom.getInstance("SHA1PRNG");
- } catch (NoSuchAlgorithmException e) {
- throw new AssertionError(e);
- }
- }
-
- private static final SecureRandom random;
-
- private static native byte[] calculateAgreement(byte[] ourPrivate, byte[] theirPublic);
- private static native byte[] generatePublicKey(byte[] privateKey);
- private static native byte[] generatePrivateKey(byte[] random);
-
- private static native byte[] calculateSignature(byte[] random, byte[] privateKey, byte[] message);
- private static native boolean verifySignature(byte[] publicKey, byte[] message, byte[] signature);
-
- public static ECKeyPair generateKeyPair() {
- byte[] privateKey = generatePrivateKey();
- byte[] publicKey = generatePublicKey(privateKey);
-
- return new ECKeyPair(new DjbECPublicKey(publicKey), new DjbECPrivateKey(privateKey));
- }
-
- static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey) {
- return calculateAgreement(((DjbECPrivateKey)privateKey).getPrivateKey(),
- ((DjbECPublicKey)publicKey).getPublicKey());
- }
-
- static byte[] calculateSignature(ECPrivateKey privateKey, byte[] message) {
- byte[] random = getRandom(64);
- return calculateSignature(random, ((DjbECPrivateKey)privateKey).getPrivateKey(), message);
- }
-
- static boolean verifySignature(ECPublicKey publicKey, byte[] message, byte[] signature) {
- return verifySignature(((DjbECPublicKey)publicKey).getPublicKey(), message, signature);
- }
-
- static ECPublicKey decodePoint(byte[] encoded, int offset)
- throws InvalidKeyException
- {
- int type = encoded[offset] & 0xFF;
- byte[] keyBytes = new byte[32];
- System.arraycopy(encoded, offset+1, keyBytes, 0, keyBytes.length);
-
- if (type != Curve.DJB_TYPE) {
- throw new InvalidKeyException("Bad key type: " + type);
- }
-
- return new DjbECPublicKey(keyBytes);
- }
-
- private static byte[] generatePrivateKey() {
- byte[] privateKey = new byte[32];
- random.nextBytes(privateKey);
-
- return generatePrivateKey(privateKey);
- }
-
- private static byte[] getRandom(int size) {
- try {
- byte[] random = new byte[size];
- SecureRandom.getInstance("SHA1PRNG").nextBytes(random);
-
- return random;
- } catch (NoSuchAlgorithmException e) {
- throw new AssertionError(e);
- }
- }
-
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPrivateKey.java b/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPrivateKey.java
deleted file mode 100644
index ecb55b4e..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPrivateKey.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.whispersystems.libaxolotl.ecc;
-
-public class DjbECPrivateKey implements ECPrivateKey {
-
- private final byte[] privateKey;
-
- DjbECPrivateKey(byte[] privateKey) {
- this.privateKey = privateKey;
- }
-
- @Override
- public byte[] serialize() {
- return privateKey;
- }
-
- @Override
- public int getType() {
- return Curve.DJB_TYPE;
- }
-
- public byte[] getPrivateKey() {
- return privateKey;
- }
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPublicKey.java b/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPublicKey.java
deleted file mode 100644
index 9f66d439..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPublicKey.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.whispersystems.libaxolotl.ecc;
-
-import org.whispersystems.libaxolotl.util.ByteUtil;
-
-import java.math.BigInteger;
-import java.util.Arrays;
-
-public class DjbECPublicKey implements ECPublicKey {
-
- private final byte[] publicKey;
-
- DjbECPublicKey(byte[] publicKey) {
- this.publicKey = publicKey;
- }
-
- @Override
- public byte[] serialize() {
- byte[] type = {Curve.DJB_TYPE};
- return ByteUtil.combine(type, publicKey);
- }
-
- @Override
- public int getType() {
- return Curve.DJB_TYPE;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other == null) return false;
- if (!(other instanceof DjbECPublicKey)) return false;
-
- DjbECPublicKey that = (DjbECPublicKey)other;
- return Arrays.equals(this.publicKey, that.publicKey);
- }
-
- @Override
- public int hashCode() {
- return Arrays.hashCode(publicKey);
- }
-
- @Override
- public int compareTo(ECPublicKey another) {
- return new BigInteger(publicKey).compareTo(new BigInteger(((DjbECPublicKey)another).publicKey));
- }
-
- public byte[] getPublicKey() {
- return publicKey;
- }
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/ECKeyPair.java b/src/main/java/org/whispersystems/libaxolotl/ecc/ECKeyPair.java
deleted file mode 100644
index bcaec927..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/ECKeyPair.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.whispersystems.libaxolotl.ecc;
-
-public class ECKeyPair {
-
- private final ECPublicKey publicKey;
- private final ECPrivateKey privateKey;
-
- public ECKeyPair(ECPublicKey publicKey, ECPrivateKey privateKey) {
- this.publicKey = publicKey;
- this.privateKey = privateKey;
- }
-
- public ECPublicKey getPublicKey() {
- return publicKey;
- }
-
- public ECPrivateKey getPrivateKey() {
- return privateKey;
- }
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/ECPrivateKey.java b/src/main/java/org/whispersystems/libaxolotl/ecc/ECPrivateKey.java
deleted file mode 100644
index 922057de..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/ECPrivateKey.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.whispersystems.libaxolotl.ecc;
-
-public interface ECPrivateKey {
- public byte[] serialize();
- public int getType();
-}
diff --git a/src/main/java/org/whispersystems/libaxolotl/ecc/ECPublicKey.java b/src/main/java/org/whispersystems/libaxolotl/ecc/ECPublicKey.java
deleted file mode 100644
index 12576807..00000000
--- a/src/main/java/org/whispersystems/libaxolotl/ecc/ECPublicKey.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * Copyright (C) 2013 Open Whisper Systems
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package org.whispersystems.libaxolotl.ecc;
-
-public interface ECPublicKey extends Comparable<ECPublicKey> {
-
- public static final int KEY_SIZE = 33;
-
- public byte[] serialize();
-
- public int getType();
-}