Permalink
Browse files

Migrate to Curve25519.

1) Generate a Curve25519 identity key.

2) Use Curve25519 ephemerals and identities for v2 3DHE agreements.

3) Initiate v2 key exchange messages.

4) Accept v1 key exchange messages.

5) TOFU Curve25519 identities.
  • Loading branch information...
moxie0 committed Nov 10, 2013
1 parent 95b8a10 commit c3c6fd2d4fc62c8a3690712eef623a0255169fd6
Showing with 2,194 additions and 495 deletions.
  1. +2 −0 .gitignore
  2. +2 −1 library/build.gradle
  3. +17 −0 library/jni/Android.mk
  4. +70 −0 library/jni/curve25519-donna-jni.c
  5. +734 −0 library/jni/curve25519-donna.c
  6. +6 −0 library/jni/curve25519-donna.h
  7. BIN library/libs/armeabi.jar
  8. BIN library/libs/libphonenumber-5.3.jar
  9. BIN library/libs/protobuf-java-2.4.1.jar
  10. BIN library/libs/sc-light-jdk15on-1.47.0.2.jar
  11. BIN library/libs/thoughtcrimegson-2.1.jar
  12. +28 −26 library/src/org/whispersystems/textsecure/crypto/IdentityKey.java
  13. +4 −4 library/src/org/whispersystems/textsecure/crypto/IdentityKeyPair.java
  14. +19 −22 library/src/org/whispersystems/textsecure/crypto/KeyPair.java
  15. +12 −92 library/src/org/whispersystems/textsecure/crypto/KeyUtil.java
  16. +17 −18 library/src/org/whispersystems/textsecure/crypto/MasterCipher.java
  17. +8 −11 library/src/org/whispersystems/textsecure/crypto/MessageCipher.java
  18. +30 −17 library/src/org/whispersystems/textsecure/crypto/PreKeyPair.java
  19. +30 −6 library/src/org/whispersystems/textsecure/crypto/PreKeyPublic.java
  20. +22 −3 library/src/org/whispersystems/textsecure/crypto/PreKeyUtil.java
  21. +24 −18 library/src/org/whispersystems/textsecure/crypto/PublicKey.java
  22. +37 −41 library/src/org/whispersystems/textsecure/crypto/SessionCipher.java
  23. +39 −37 library/src/org/whispersystems/textsecure/crypto/SharedSecretCalculator.java
  24. +85 −0 library/src/org/whispersystems/textsecure/crypto/ecc/Curve.java
  25. +75 −0 library/src/org/whispersystems/textsecure/crypto/ecc/Curve25519.java
  26. +122 −0 library/src/org/whispersystems/textsecure/crypto/ecc/CurveP256.java
  27. +41 −0 library/src/org/whispersystems/textsecure/crypto/ecc/DjbECPrivateKey.java
  28. +66 −0 library/src/org/whispersystems/textsecure/crypto/ecc/DjbECPublicKey.java
  29. +38 −0 library/src/org/whispersystems/textsecure/crypto/ecc/ECKeyPair.java
  30. +23 −0 library/src/org/whispersystems/textsecure/crypto/ecc/ECPrivateKey.java
  31. +27 −0 library/src/org/whispersystems/textsecure/crypto/ecc/ECPublicKey.java
  32. +43 −0 library/src/org/whispersystems/textsecure/crypto/ecc/NistECPrivateKey.java
  33. +63 −0 library/src/org/whispersystems/textsecure/crypto/ecc/NistECPublicKey.java
  34. +17 −0 library/src/org/whispersystems/textsecure/crypto/kdf/DerivedSecrets.java
  35. +18 −1 library/src/org/whispersystems/textsecure/crypto/kdf/HKDF.java
  36. +29 −17 library/src/org/whispersystems/textsecure/crypto/kdf/KDF.java
  37. +19 −3 library/src/org/whispersystems/textsecure/crypto/kdf/NKDF.java
  38. +3 −2 library/src/org/whispersystems/textsecure/crypto/protocol/CiphertextMessage.java
  39. +3 −1 library/src/org/whispersystems/textsecure/crypto/protocol/PreKeyBundleMessage.java
  40. +4 −1 library/src/org/whispersystems/textsecure/push/PushServiceSocket.java
  41. +6 −2 library/src/org/whispersystems/textsecure/storage/LocalKeyRecord.java
  42. +33 −5 src/org/thoughtcrime/securesms/DatabaseUpgradeActivity.java
  43. +23 −8 src/org/thoughtcrime/securesms/VerifyIdentityActivity.java
  44. +6 −2 src/org/thoughtcrime/securesms/ViewLocalIdentityActivity.java
  45. +46 −43 src/org/thoughtcrime/securesms/crypto/AsymmetricMasterCipher.java
  46. +32 −14 src/org/thoughtcrime/securesms/crypto/AsymmetricMasterSecret.java
  47. +6 −3 src/org/thoughtcrime/securesms/crypto/DecryptingQueue.java
  48. +106 −44 src/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java
  49. +4 −2 src/org/thoughtcrime/securesms/crypto/KeyExchangeInitiator.java
  50. +4 −7 src/org/thoughtcrime/securesms/crypto/KeyExchangeProcessor.java
  51. +57 −22 src/org/thoughtcrime/securesms/crypto/MasterSecretUtil.java
  52. +15 −11 src/org/thoughtcrime/securesms/crypto/protocol/KeyExchangeMessage.java
  53. +11 −3 src/org/thoughtcrime/securesms/database/IdentityDatabase.java
  54. +3 −1 src/org/thoughtcrime/securesms/service/RegistrationService.java
  55. +20 −1 src/org/thoughtcrime/securesms/transport/MmsTransport.java
  56. +21 −3 src/org/thoughtcrime/securesms/transport/PushTransport.java
  57. +24 −3 src/org/thoughtcrime/securesms/transport/SmsTransport.java
@@ -20,3 +20,5 @@ signing.properties
gradle
gradlew
gradlew.bat
library/lib/
library/obj/
@@ -22,7 +22,8 @@ dependencies {
compile 'com.google.protobuf:protobuf-java:2.4.1'
compile 'com.madgag:sc-light-jdk15on:1.47.0.2'
compile 'com.googlecode.libphonenumber:libphonenumber:5.3'
compile 'org.whispersystems:gson:2.1'
compile 'org.whispersystems:gson:2.2.4'
compile fileTree(dir: 'libs', include: 'armeabi.jar')
}
android {
@@ -0,0 +1,17 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libcurve25519-donna
LOCAL_SRC_FILES := curve25519-donna.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libcurve25519
LOCAL_SRC_FILES := curve25519-donna-jni.c
LOCAL_STATIC_LIBRARIES := libcurve25519-donna
include $(BUILD_SHARED_LIBRARY)
@@ -0,0 +1,70 @@
/**
* 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/>.
*/
#include <string.h>
#include <stdint.h>
#include <jni.h>
#include "curve25519-donna.h"
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_generatePrivateKey
(JNIEnv *env, jclass clazz, jbyteArray random)
{
uint8_t* privateKey = (uint8_t*)(*env)->GetByteArrayElements(env, random, 0);
privateKey[0] &= 248;
privateKey[31] &= 127;
privateKey[31] |= 64;
(*env)->ReleaseByteArrayElements(env, random, privateKey, 0);
return random;
}
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_generatePublicKey
(JNIEnv *env, jclass clazz, jbyteArray privateKey)
{
static const uint8_t basepoint[32] = {9};
jbyteArray publicKey = (*env)->NewByteArray(env, 32);
uint8_t* publicKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, publicKey, 0);
uint8_t* privateKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, privateKey, 0);
curve25519_donna(publicKeyBytes, privateKeyBytes, basepoint);
(*env)->ReleaseByteArrayElements(env, publicKey, publicKeyBytes, 0);
(*env)->ReleaseByteArrayElements(env, privateKey, privateKeyBytes, 0);
return publicKey;
}
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_calculateAgreement
(JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey)
{
jbyteArray sharedKey = (*env)->NewByteArray(env, 32);
uint8_t* sharedKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, sharedKey, 0);
uint8_t* privateKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, privateKey, 0);
uint8_t* publicKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, publicKey, 0);
curve25519_donna(sharedKeyBytes, privateKeyBytes, publicKeyBytes);
(*env)->ReleaseByteArrayElements(env, sharedKey, sharedKeyBytes, 0);
(*env)->ReleaseByteArrayElements(env, publicKey, publicKeyBytes, 0);
(*env)->ReleaseByteArrayElements(env, privateKey, privateKeyBytes, 0);
return sharedKey;
}
Oops, something went wrong.

0 comments on commit c3c6fd2

Please sign in to comment.