From 6445ea5f13850f42c3952bd06a2369317683ed88 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Thu, 8 Jan 2015 13:48:49 -0800 Subject: Break project up into Java and Android build/test. --- .../org/whispersystems/libaxolotl/ecc/Curve.java | 78 ----------------- .../whispersystems/libaxolotl/ecc/Curve25519.java | 98 ---------------------- .../libaxolotl/ecc/DjbECPrivateKey.java | 41 --------- .../libaxolotl/ecc/DjbECPublicKey.java | 66 --------------- .../whispersystems/libaxolotl/ecc/ECKeyPair.java | 37 -------- .../libaxolotl/ecc/ECPrivateKey.java | 23 ----- .../whispersystems/libaxolotl/ecc/ECPublicKey.java | 27 ------ 7 files changed, 370 deletions(-) delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/Curve.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/Curve25519.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPrivateKey.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/DjbECPublicKey.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/ECKeyPair.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/ECPrivateKey.java delete mode 100644 src/main/java/org/whispersystems/libaxolotl/ecc/ECPublicKey.java (limited to 'src/main/java/org/whispersystems/libaxolotl/ecc') 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 . - */ -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 . - */ -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 . - */ - -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 . - */ - -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 . - */ - -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 . - */ - -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 . - */ - -package org.whispersystems.libaxolotl.ecc; - -public interface ECPublicKey extends Comparable { - - public static final int KEY_SIZE = 33; - - public byte[] serialize(); - - public int getType(); -} -- cgit v1.2.3