XChaCha20-Ploy1305 support

This commit is contained in:
Matéo Duparc 2021-10-17 13:46:10 +02:00
parent a377b61240
commit e47d9f4548
Signed by: hardcoresushi
GPG Key ID: 007F84120107191E
7 changed files with 58 additions and 5 deletions

@ -1 +1 @@
Subproject commit f0e45c7b7e428f13667edd3b8d73501e15322a04
Subproject commit bd5d53f50eb274ed084e9f363ccfbe30d9061039

View File

@ -4,7 +4,8 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import android.view.View
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import sushi.hardcore.droidfs.databinding.ActivityCreateBinding
import sushi.hardcore.droidfs.explorers.ExplorerActivity
@ -29,6 +30,25 @@ class CreateActivity : VolumeActionActivity() {
createVolume()
true
}
binding.spinnerXchacha.adapter = ArrayAdapter(
this@CreateActivity,
android.R.layout.simple_spinner_item,
resources.getStringArray(R.array.encryption_cipher)
).apply {
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
}
binding.spinnerXchacha.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
if (position == 1) {
ColoredAlertDialogBuilder(this@CreateActivity)
.setTitle(R.string.warning)
.setMessage(R.string.xchacha_warning)
.setPositiveButton(R.string.ok, null)
.show()
}
}
override fun onNothingSelected(parent: AdapterView<*>?) {}
}
binding.buttonCreate.setOnClickListener {
createVolume()
}
@ -112,7 +132,12 @@ class CreateActivity : VolumeActionActivity() {
}
}
if (goodDirectory) {
if (GocryptfsVolume.createVolume(currentVolumePath, password, false, GocryptfsVolume.ScryptDefaultLogN, ConstValues.creator)) {
val xchacha = when (binding.spinnerXchacha.selectedItemPosition) {
0 -> 0
1 -> 1
else -> -1
}
if (GocryptfsVolume.createVolume(currentVolumePath, password, false, xchacha, GocryptfsVolume.ScryptDefaultLogN, ConstValues.creator)) {
var returnedHash: ByteArray? = null
if (checkboxSavePassword.isChecked){
returnedHash = ByteArray(GocryptfsVolume.KeyLen)

View File

@ -30,7 +30,7 @@ class GocryptfsVolume(var sessionID: Int) {
const val KeyLen = 32
const val ScryptDefaultLogN = 16
const val DefaultBS = 4096
external fun createVolume(root_cipher_dir: String, password: CharArray, plainTextNames: Boolean, logN: Int, creator: String): Boolean
external fun createVolume(root_cipher_dir: String, password: CharArray, plainTextNames: Boolean, xchacha: Int, logN: Int, creator: String): Boolean
external fun init(root_cipher_dir: String, password: CharArray?, givenHash: ByteArray?, returnedHash: ByteArray?): Int
external fun changePassword(root_cipher_dir: String, old_password: CharArray?, givenHash: ByteArray?, new_password: CharArray, returnedHash: ByteArray?): Boolean

View File

@ -33,6 +33,7 @@ JNIEXPORT jboolean JNICALL
Java_sushi_hardcore_droidfs_GocryptfsVolume_00024Companion_createVolume(JNIEnv *env, jclass clazz,
jstring jroot_cipher_dir, jcharArray jpassword,
jboolean plainTextNames,
jint xchacha,
jint logN,
jstring jcreator) {
const char* root_cipher_dir = (*env)->GetStringUTFChars(env, jroot_cipher_dir, NULL);
@ -45,7 +46,7 @@ Java_sushi_hardcore_droidfs_GocryptfsVolume_00024Companion_createVolume(JNIEnv *
jcharArray_to_charArray(jchar_password, password, password_len);
GoSlice go_password = {password, password_len, password_len};
GoUint8 result = gcf_create_volume(gofilename, go_password, plainTextNames, logN, gocreator);
GoUint8 result = gcf_create_volume(gofilename, go_password, plainTextNames, xchacha, logN, gocreator);
(*env)->ReleaseStringUTFChars(env, jroot_cipher_dir, root_cipher_dir);
(*env)->ReleaseStringUTFChars(env, jcreator, creator);

View File

@ -59,6 +59,24 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dp"
android:gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/encryption_cipher_label"/>
<Spinner
android:id="@+id/spinner_xchacha"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<include layout="@layout/checkboxes_section"/>
<TextView

View File

@ -1,4 +1,10 @@
<resources>
<string-array name="encryption_cipher">
<item>AES-GCM</item>
<item>XChaCha20-Poly1305</item>
<item>@string/auto</item>
</string-array>
<string-array name="sort_orders_entries">
<item>Name</item>
<item>Size</item>

View File

@ -206,4 +206,7 @@
<string name="camera_optimization">Camera optimization</string>
<string name="maximize_quality">Maximize quality</string>
<string name="minimize_latency">Minimize latency</string>
<string name="auto">Auto</string>
<string name="xchacha_warning">XChaCha20-Poly1305 is only supported since gocryptfs v2.2.0. Older versions won\'t be able to open a volume based on this cipher.</string>
<string name="encryption_cipher_label">Encryption cipher:</string>
</resources>