Skip to content

Commit c3c6fd2

Browse files
committed
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.
1 parent 95b8a10 commit c3c6fd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2194
-495
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ signing.properties
2020
gradle
2121
gradlew
2222
gradlew.bat
23+
library/lib/
24+
library/obj/

library/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ dependencies {
2222
compile 'com.google.protobuf:protobuf-java:2.4.1'
2323
compile 'com.madgag:sc-light-jdk15on:1.47.0.2'
2424
compile 'com.googlecode.libphonenumber:libphonenumber:5.3'
25-
compile 'org.whispersystems:gson:2.1'
25+
compile 'org.whispersystems:gson:2.2.4'
26+
compile fileTree(dir: 'libs', include: 'armeabi.jar')
2627
}
2728

2829
android {

library/jni/Android.mk

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
LOCAL_PATH:= $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
5+
LOCAL_MODULE := libcurve25519-donna
6+
LOCAL_SRC_FILES := curve25519-donna.c
7+
8+
include $(BUILD_STATIC_LIBRARY)
9+
10+
include $(CLEAR_VARS)
11+
12+
LOCAL_MODULE := libcurve25519
13+
LOCAL_SRC_FILES := curve25519-donna-jni.c
14+
15+
LOCAL_STATIC_LIBRARIES := libcurve25519-donna
16+
17+
include $(BUILD_SHARED_LIBRARY)

library/jni/curve25519-donna-jni.c

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Copyright (C) 2013 Open Whisper Systems
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#include <string.h>
19+
#include <stdint.h>
20+
21+
#include <jni.h>
22+
#include "curve25519-donna.h"
23+
24+
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_generatePrivateKey
25+
(JNIEnv *env, jclass clazz, jbyteArray random)
26+
{
27+
uint8_t* privateKey = (uint8_t*)(*env)->GetByteArrayElements(env, random, 0);
28+
29+
privateKey[0] &= 248;
30+
privateKey[31] &= 127;
31+
privateKey[31] |= 64;
32+
33+
(*env)->ReleaseByteArrayElements(env, random, privateKey, 0);
34+
35+
return random;
36+
}
37+
38+
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_generatePublicKey
39+
(JNIEnv *env, jclass clazz, jbyteArray privateKey)
40+
{
41+
static const uint8_t basepoint[32] = {9};
42+
43+
jbyteArray publicKey = (*env)->NewByteArray(env, 32);
44+
uint8_t* publicKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, publicKey, 0);
45+
uint8_t* privateKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, privateKey, 0);
46+
47+
curve25519_donna(publicKeyBytes, privateKeyBytes, basepoint);
48+
49+
(*env)->ReleaseByteArrayElements(env, publicKey, publicKeyBytes, 0);
50+
(*env)->ReleaseByteArrayElements(env, privateKey, privateKeyBytes, 0);
51+
52+
return publicKey;
53+
}
54+
55+
JNIEXPORT jbyteArray JNICALL Java_org_whispersystems_textsecure_crypto_ecc_Curve25519_calculateAgreement
56+
(JNIEnv *env, jclass clazz, jbyteArray privateKey, jbyteArray publicKey)
57+
{
58+
jbyteArray sharedKey = (*env)->NewByteArray(env, 32);
59+
uint8_t* sharedKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, sharedKey, 0);
60+
uint8_t* privateKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, privateKey, 0);
61+
uint8_t* publicKeyBytes = (uint8_t*)(*env)->GetByteArrayElements(env, publicKey, 0);
62+
63+
curve25519_donna(sharedKeyBytes, privateKeyBytes, publicKeyBytes);
64+
65+
(*env)->ReleaseByteArrayElements(env, sharedKey, sharedKeyBytes, 0);
66+
(*env)->ReleaseByteArrayElements(env, publicKey, publicKeyBytes, 0);
67+
(*env)->ReleaseByteArrayElements(env, privateKey, privateKeyBytes, 0);
68+
69+
return sharedKey;
70+
}

0 commit comments

Comments
 (0)