mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Create encrypt module
This commit is contained in:
@@ -29,12 +29,6 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/jni/CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled = false
|
||||
@@ -126,8 +120,6 @@ dependencies {
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
// Autofill
|
||||
implementation "androidx.autofill:autofill:1.1.0"
|
||||
// Crypto
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.65.01'
|
||||
// Time
|
||||
implementation 'joda-time:joda-time:2.10.6'
|
||||
// Color
|
||||
@@ -137,6 +129,8 @@ dependencies {
|
||||
// Apache Commons
|
||||
implementation 'commons-io:commons-io:2.8.0'
|
||||
implementation 'commons-codec:commons-codec:1.15'
|
||||
// Encrypt lib
|
||||
implementation project(path: ':encrypt')
|
||||
// Icon pack
|
||||
implementation project(path: ':icon-pack-classic')
|
||||
implementation project(path: ':icon-pack-material')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.kunzisoft.keepass.tests.utils
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import junit.framework.TestCase
|
||||
|
||||
class UnsignedIntTest: TestCase() {
|
||||
|
||||
@@ -21,8 +21,9 @@ package com.kunzisoft.keepass.tests.utils
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
@@ -26,17 +26,17 @@ import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.activities.dialogs.DatabaseChangedDialogFragment
|
||||
import com.kunzisoft.keepass.activities.dialogs.DatabaseChangedDialogFragment.Companion.DATABASE_CHANGED_DIALOG_TAG
|
||||
import com.kunzisoft.keepass.app.database.CipherDatabaseEntity
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Entry
|
||||
import com.kunzisoft.keepass.database.element.Group
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.node.Node
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.model.MainCredential
|
||||
import com.kunzisoft.keepass.model.SnapFileDatabaseInfo
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
||||
@@ -48,8 +48,8 @@ import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_ENTRY_HISTORY
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_DELETE_NODES_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_LOAD_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_RELOAD_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_MOVE_NODES_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_RELOAD_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_REMOVE_UNLINKED_DATA_TASK
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_RESTORE_ENTRY_HISTORY
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService.Companion.ACTION_DATABASE_SAVE
|
||||
|
||||
@@ -23,7 +23,8 @@ import android.content.ContentResolver
|
||||
import android.content.res.Resources
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.database.*
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
@@ -32,7 +33,6 @@ import com.kunzisoft.keepass.database.element.icon.IconsManager
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.exception.*
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDB
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.content.res.Resources
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.readEnum
|
||||
import com.kunzisoft.keepass.utils.writeEnum
|
||||
|
||||
|
||||
@@ -19,17 +19,17 @@
|
||||
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import com.kunzisoft.keepass.crypto.finalkey.AESKeyTransformerFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.finalkey.AESKeyTransformerFactory
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.stream.NullOutputStream
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.stream.NullOutputStream
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -22,13 +22,16 @@ package com.kunzisoft.keepass.database.element.database
|
||||
import android.content.res.Resources
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import com.kunzisoft.encrypt.CryptoUtil
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.VariantDictionary
|
||||
import com.kunzisoft.encrypt.engine.AesEngine
|
||||
import com.kunzisoft.encrypt.engine.CipherEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.database.element.DeletedObject
|
||||
@@ -39,15 +42,12 @@ import com.kunzisoft.keepass.database.element.icon.IconImageCustom
|
||||
import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeVersioned
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.security.MemoryProtectionConfig
|
||||
import com.kunzisoft.keepass.database.exception.UnknownKDF
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX.Companion.FILE_VERSION_32_3
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX.Companion.FILE_VERSION_32_4
|
||||
import com.kunzisoft.keepass.utils.StringUtil.removeSpaceChars
|
||||
import com.kunzisoft.keepass.utils.StringUtil.toHexString
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import org.apache.commons.codec.binary.Hex
|
||||
import org.w3c.dom.Node
|
||||
import java.io.File
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.database
|
||||
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryVersioned
|
||||
import com.kunzisoft.keepass.database.element.group.GroupVersioned
|
||||
@@ -27,7 +26,7 @@ import com.kunzisoft.keepass.database.element.icon.IconImageStandard
|
||||
import com.kunzisoft.keepass.database.element.icon.IconsManager
|
||||
import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.exception.DuplicateUuidDatabaseException
|
||||
import org.apache.commons.codec.binary.Hex
|
||||
import java.io.ByteArrayInputStream
|
||||
@@ -48,9 +47,9 @@ abstract class DatabaseVersioned<
|
||||
// Algorithm used to encrypt the database
|
||||
protected var algorithm: EncryptionAlgorithm? = null
|
||||
|
||||
abstract val kdfEngine: KdfEngine?
|
||||
abstract val kdfEngine: com.kunzisoft.encrypt.keyDerivation.KdfEngine?
|
||||
|
||||
abstract val kdfAvailableList: List<KdfEngine>
|
||||
abstract val kdfAvailableList: List<com.kunzisoft.encrypt.keyDerivation.KdfEngine>
|
||||
|
||||
var masterKey = ByteArray(32)
|
||||
var finalKey: ByteArray? = null
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
|
||||
class AutoType : Parcelable {
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.database.element.security.ProtectedString
|
||||
import com.kunzisoft.keepass.utils.ParcelableUtil
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import kotlin.collections.LinkedHashMap
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.kunzisoft.keepass.database.element.node.NodeId
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.element.node.Type
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import java.util.*
|
||||
|
||||
class GroupKDBX : GroupVersioned<UUID, UUID, GroupKDBX, EntryKDBX>, NodeKDBXInterface {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package com.kunzisoft.keepass.database.element.node
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
|
||||
interface NodeKDBXInterface : NodeTimeInterface {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
|
||||
abstract class DatabaseHeader {
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ package com.kunzisoft.keepass.database.file
|
||||
|
||||
import com.kunzisoft.keepass.stream.readBytesLength
|
||||
import com.kunzisoft.keepass.stream.readBytes4ToUInt
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
|
||||
@@ -19,10 +19,14 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CrsAlgorithm
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.AesKdf
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.encrypt.CrsAlgorithm
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import com.kunzisoft.encrypt.VariantDictionary
|
||||
import com.kunzisoft.encrypt.keyDerivation.AesKdf
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
@@ -31,9 +35,6 @@ import com.kunzisoft.keepass.database.element.group.GroupKDBX
|
||||
import com.kunzisoft.keepass.database.element.node.NodeKDBXInterface
|
||||
import com.kunzisoft.keepass.database.exception.VersionDatabaseException
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -20,15 +20,15 @@
|
||||
|
||||
package com.kunzisoft.keepass.database.file.input
|
||||
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDB
|
||||
import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdInt
|
||||
import com.kunzisoft.keepass.database.element.node.NodeIdUUID
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.exception.*
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeader
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDB
|
||||
|
||||
@@ -21,10 +21,14 @@ package com.kunzisoft.keepass.database.file.input
|
||||
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.StreamCipherFactory
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import com.kunzisoft.encrypt.engine.CipherEngine
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
import com.kunzisoft.encrypt.stream.StreamCipher
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.crypto.StreamCipherFactory
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.database.element.Attachment
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
@@ -45,9 +49,6 @@ import com.kunzisoft.keepass.database.file.DatabaseKDBXXML
|
||||
import com.kunzisoft.keepass.database.file.DateKDBXUtil
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.tasks.ProgressTaskUpdater
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import org.bouncycastle.crypto.StreamCipher
|
||||
import org.xmlpull.v1.XmlPullParser
|
||||
import org.xmlpull.v1.XmlPullParserException
|
||||
import org.xmlpull.v1.XmlPullParserFactory
|
||||
|
||||
@@ -19,14 +19,15 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file.output
|
||||
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDBX
|
||||
import com.kunzisoft.keepass.database.exception.DatabaseOutputException
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeader
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.utils.UnsignedLong
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import com.kunzisoft.encrypt.UnsignedLong
|
||||
import com.kunzisoft.encrypt.VariantDictionary
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
@@ -19,16 +19,16 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.file.output
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import com.kunzisoft.encrypt.stream.NullOutputStream
|
||||
import com.kunzisoft.keepass.database.element.database.DatabaseKDB
|
||||
import com.kunzisoft.keepass.database.element.group.GroupKDB
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.database.exception.DatabaseOutputException
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeader
|
||||
import com.kunzisoft.keepass.database.file.DatabaseHeaderKDB
|
||||
import com.kunzisoft.keepass.stream.LittleEndianDataOutputStream
|
||||
import com.kunzisoft.keepass.stream.NullOutputStream
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
|
||||
@@ -22,11 +22,14 @@ package com.kunzisoft.keepass.database.file.output
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
import android.util.Xml
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.crypto.CrsAlgorithm
|
||||
import com.kunzisoft.keepass.crypto.StreamCipherFactory
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.CrsAlgorithm
|
||||
import com.kunzisoft.encrypt.StreamCipherFactory
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.engine.CipherEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfFactory
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import com.kunzisoft.encrypt.stream.StreamCipher
|
||||
import com.kunzisoft.keepass.database.action.node.NodeHandler
|
||||
import com.kunzisoft.keepass.database.element.DeletedObject
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
@@ -44,8 +47,6 @@ import com.kunzisoft.keepass.database.file.DatabaseHeaderKDBX
|
||||
import com.kunzisoft.keepass.database.file.DatabaseKDBXXML
|
||||
import com.kunzisoft.keepass.database.file.DateKDBXUtil
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import org.bouncycastle.crypto.StreamCipher
|
||||
import org.joda.time.DateTime
|
||||
import org.xmlpull.v1.XmlSerializer
|
||||
import java.io.IOException
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.kunzisoft.keepass.database.element.entry.EntryKDB
|
||||
import com.kunzisoft.keepass.database.exception.DatabaseOutputException
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.keepass.utils.StringDatabaseKDBUtils
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.nio.charset.Charset
|
||||
|
||||
@@ -25,7 +25,7 @@ import com.kunzisoft.keepass.stream.dateTo5Bytes
|
||||
import com.kunzisoft.keepass.stream.uIntTo4Bytes
|
||||
import com.kunzisoft.keepass.stream.uShortTo2Bytes
|
||||
import com.kunzisoft.keepass.utils.StringDatabaseKDBUtils
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.kunzisoft.keepass.otp.OtpEntryFields
|
||||
import com.kunzisoft.keepass.settings.PreferencesUtil
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.ObjectNameResource
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -28,13 +28,13 @@ import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.SwitchPreference
|
||||
import com.kunzisoft.androidclearchroma.ChromaUtil
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.activities.dialogs.AssignMasterKeyDialogFragment
|
||||
import com.kunzisoft.keepass.activities.helpers.ReadOnlyHelper
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.database.element.Database
|
||||
import com.kunzisoft.keepass.database.element.database.CompressionAlgorithm
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.services.DatabaseTaskNotificationService
|
||||
import com.kunzisoft.keepass.settings.preference.*
|
||||
import com.kunzisoft.keepass.settings.preferencedialogfragment.*
|
||||
|
||||
@@ -23,7 +23,7 @@ import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.DialogPreference
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
|
||||
open class InputKdfNumberPreference @JvmOverloads constructor(context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
|
||||
@@ -24,7 +24,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.View
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
|
||||
|
||||
class DatabaseEncryptionAlgorithmPreferenceDialogFragmentCompat
|
||||
|
||||
@@ -25,7 +25,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import android.view.View
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfEngine
|
||||
import com.kunzisoft.keepass.settings.preferencedialogfragment.adapter.ListRadioItemAdapter
|
||||
|
||||
class DatabaseKeyDerivationPreferenceDialogFragmentCompat
|
||||
|
||||
@@ -28,7 +28,7 @@ import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.ObjectNameResource
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.view.ViewGroup
|
||||
import android.widget.RadioButton
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.ObjectNameResource
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.security.InvalidKeyException
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
import java.security.InvalidKeyException
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import com.kunzisoft.encrypt.stream.NullOutputStream
|
||||
import java.io.IOException
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
|
||||
@@ -21,7 +21,7 @@ package com.kunzisoft.keepass.stream
|
||||
|
||||
import com.kunzisoft.keepass.database.element.DateInstant
|
||||
import com.kunzisoft.keepass.utils.StringDatabaseKDBUtils.bytesToString
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
package com.kunzisoft.keepass.utils
|
||||
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.keepass.stream.uIntTo4Bytes
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
@@ -520,12 +520,6 @@
|
||||
<string name="download_finalization">Finalizing…</string>
|
||||
<string name="download_complete">Complete!</string>
|
||||
<string name="download_canceled">Canceled!</string>
|
||||
<string name="encryption_rijndael">Rijndael (AES)</string>
|
||||
<string name="encryption_twofish">Twofish</string>
|
||||
<string name="encryption_chacha20">ChaCha20</string>
|
||||
<string name="kdf_AES">AES</string>
|
||||
<string name="kdf_Argon2d">Argon2d</string>
|
||||
<string name="kdf_Argon2id">Argon2id</string>
|
||||
<string name="unit_byte">B</string>
|
||||
<string name="unit_kibibyte">KiB</string>
|
||||
<string name="unit_mebibyte">MiB</string>
|
||||
|
||||
2
encrypt/.gitignore
vendored
Normal file
2
encrypt/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build
|
||||
/.cxx
|
||||
54
encrypt/build.gradle
Normal file
54
encrypt/build.gradle
Normal file
@@ -0,0 +1,54 @@
|
||||
plugins {
|
||||
id 'com.android.library'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles "consumer-rules.pro"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path "src/main/jni/CMakeLists.txt"
|
||||
}
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
// Crypto
|
||||
implementation 'org.bouncycastle:bcprov-jdk15on:1.65.01'
|
||||
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
}
|
||||
0
encrypt/consumer-rules.pro
Normal file
0
encrypt/consumer-rules.pro
Normal file
21
encrypt/proguard-rules.pro
vendored
Normal file
21
encrypt/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tests.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
|
||||
@@ -26,8 +26,8 @@ import java.util.Random
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.crypto.finalkey.AndroidAESKeyTransformer
|
||||
import com.kunzisoft.keepass.crypto.finalkey.NativeAESKeyTransformer
|
||||
import com.kunzisoft.encrypt.finalkey.AndroidAESKeyTransformer
|
||||
import com.kunzisoft.encrypt.finalkey.NativeAESKeyTransformer
|
||||
|
||||
class AESKeyTest : TestCase() {
|
||||
private lateinit var mRand: Random
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tests.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.tests.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import com.kunzisoft.encrypt.engine.AesEngine
|
||||
import com.kunzisoft.encrypt.stream.BetterCipherInputStream
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
|
||||
import java.io.ByteArrayInputStream
|
||||
@@ -37,10 +39,7 @@ import javax.crypto.NoSuchPaddingException
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||
import com.kunzisoft.keepass.stream.BetterCipherInputStream
|
||||
import com.kunzisoft.keepass.stream.LittleEndianDataInputStream
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
|
||||
class CipherTest : TestCase() {
|
||||
private val rand = Random()
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.encrypt
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("com.example.encrypt.test", appContext.packageName)
|
||||
}
|
||||
}
|
||||
5
encrypt/src/main/AndroidManifest.xml
Normal file
5
encrypt/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.kunzisoft.encrypt">
|
||||
|
||||
</manifest>
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import java.security.Provider
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import android.os.Build
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.ChaCha20Engine
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.TwofishEngine
|
||||
import com.kunzisoft.encrypt.engine.AesEngine
|
||||
import com.kunzisoft.encrypt.engine.ChaCha20Engine
|
||||
import com.kunzisoft.encrypt.engine.CipherEngine
|
||||
import com.kunzisoft.encrypt.engine.TwofishEngine
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import java.security.NoSuchAlgorithmException
|
||||
import java.security.Security
|
||||
@@ -17,9 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
enum class CrsAlgorithm constructor(val id: UnsignedInt) {
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import com.kunzisoft.keepass.stream.NullOutputStream
|
||||
import com.kunzisoft.keepass.stream.longTo8Bytes
|
||||
import com.kunzisoft.encrypt.stream.NullOutputStream
|
||||
import com.kunzisoft.encrypt.stream.longTo8Bytes
|
||||
import java.io.IOException
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
@@ -17,16 +17,13 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.database.element.security
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import android.content.res.Resources
|
||||
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.engine.AesEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.ChaCha20Engine
|
||||
import com.kunzisoft.keepass.crypto.engine.CipherEngine
|
||||
import com.kunzisoft.keepass.crypto.engine.TwofishEngine
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.engine.AesEngine
|
||||
import com.kunzisoft.encrypt.engine.ChaCha20Engine
|
||||
import com.kunzisoft.encrypt.engine.CipherEngine
|
||||
import com.kunzisoft.encrypt.engine.TwofishEngine
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto;
|
||||
package com.kunzisoft.encrypt;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
object NativeLib {
|
||||
private var isLoaded = false
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.utils
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import android.content.res.Resources
|
||||
|
||||
@@ -17,8 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters
|
||||
import org.bouncycastle.crypto.StreamCipher
|
||||
import org.bouncycastle.crypto.engines.ChaCha7539Engine
|
||||
import org.bouncycastle.crypto.engines.Salsa20Engine
|
||||
@@ -30,7 +31,7 @@ object StreamCipherFactory {
|
||||
private val SALSA_IV = byteArrayOf(0xE8.toByte(), 0x30, 0x09, 0x4B, 0x97.toByte(), 0x20, 0x5D, 0x2A)
|
||||
|
||||
@Throws(Exception::class)
|
||||
fun getInstance(alg: CrsAlgorithm?, key: ByteArray): StreamCipher {
|
||||
fun getInstance(alg: CrsAlgorithm?, key: ByteArray): com.kunzisoft.encrypt.stream.StreamCipher {
|
||||
return when {
|
||||
alg === CrsAlgorithm.Salsa20 -> getSalsa20(key)
|
||||
alg === CrsAlgorithm.ChaCha20 -> getChaCha20(key)
|
||||
@@ -38,7 +39,7 @@ object StreamCipherFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSalsa20(key: ByteArray): StreamCipher {
|
||||
private fun getSalsa20(key: ByteArray): com.kunzisoft.encrypt.stream.StreamCipher {
|
||||
// Build stream cipher key
|
||||
val key32 = CryptoUtil.hashSha256(key)
|
||||
|
||||
@@ -48,10 +49,10 @@ object StreamCipherFactory {
|
||||
val cipher = Salsa20Engine()
|
||||
cipher.init(true, ivParam)
|
||||
|
||||
return cipher
|
||||
return StreamCipherConvert(cipher)
|
||||
}
|
||||
|
||||
private fun getChaCha20(key: ByteArray): StreamCipher {
|
||||
private fun getChaCha20(key: ByteArray): com.kunzisoft.encrypt.stream.StreamCipher {
|
||||
// Build stream cipher key
|
||||
val hash = CryptoUtil.hashSha512(key)
|
||||
val key32 = ByteArray(32)
|
||||
@@ -66,6 +67,29 @@ object StreamCipherFactory {
|
||||
val cipher = ChaCha7539Engine()
|
||||
cipher.init(true, ivParam)
|
||||
|
||||
return cipher
|
||||
return StreamCipherConvert(cipher)
|
||||
}
|
||||
|
||||
|
||||
class StreamCipherConvert(private val streamCipher: StreamCipher): com.kunzisoft.encrypt.stream.StreamCipher {
|
||||
override fun init(forEncryption: Boolean, params: CipherParameters?) {
|
||||
streamCipher.init(forEncryption, params)
|
||||
}
|
||||
|
||||
override fun getAlgorithmName(): String {
|
||||
return streamCipher.algorithmName
|
||||
}
|
||||
|
||||
override fun returnByte(byte: Byte): Byte {
|
||||
return streamCipher.returnByte(byte)
|
||||
}
|
||||
|
||||
override fun processBytes(byteArray: ByteArray?, inOff: Int, len: Int, out: ByteArray?, outOff: Int): Int {
|
||||
return streamCipher.processBytes(byteArray, inOff, len, out, outOff)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
return streamCipher.reset()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.utils
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
class UnsignedInt(private var unsignedValue: Int) {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.utils
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
class UnsignedLong(private var unsignedValue: Long) {
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.utils
|
||||
package com.kunzisoft.encrypt
|
||||
|
||||
import com.kunzisoft.keepass.crypto.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.keepass.stream.*
|
||||
import com.kunzisoft.encrypt.keyDerivation.KdfParameters
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataInputStream
|
||||
import com.kunzisoft.encrypt.stream.LittleEndianDataOutputStream
|
||||
import com.kunzisoft.encrypt.stream.bytes4ToUInt
|
||||
import com.kunzisoft.encrypt.stream.bytes64ToLong
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.IOException
|
||||
@@ -17,12 +17,12 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
package com.kunzisoft.encrypt.engine
|
||||
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
package com.kunzisoft.encrypt.engine
|
||||
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
package com.kunzisoft.encrypt.engine
|
||||
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -17,11 +17,11 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.engine
|
||||
package com.kunzisoft.encrypt.engine
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory
|
||||
import com.kunzisoft.keepass.database.element.security.EncryptionAlgorithm
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.CipherFactory
|
||||
import com.kunzisoft.encrypt.EncryptionAlgorithm
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import java.security.InvalidAlgorithmParameterException
|
||||
import java.security.InvalidKeyException
|
||||
import java.security.NoSuchAlgorithmException
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.finalkey
|
||||
package com.kunzisoft.encrypt.finalkey
|
||||
|
||||
import com.kunzisoft.keepass.crypto.CipherFactory.deviceBlacklisted
|
||||
import com.kunzisoft.encrypt.CipherFactory.deviceBlacklisted
|
||||
|
||||
object AESKeyTransformerFactory : KeyTransformer() {
|
||||
override fun transformMasterKey(seed: ByteArray?, key: ByteArray?, rounds: Long?): ByteArray? {
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.finalkey
|
||||
package com.kunzisoft.encrypt.finalkey
|
||||
|
||||
import java.io.IOException
|
||||
import java.security.InvalidKeyException
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.finalkey
|
||||
package com.kunzisoft.encrypt.finalkey
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.finalkey;
|
||||
package com.kunzisoft.encrypt.finalkey;
|
||||
|
||||
import com.kunzisoft.keepass.crypto.NativeLib;
|
||||
import com.kunzisoft.encrypt.NativeLib;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
package com.kunzisoft.encrypt.keyDerivation
|
||||
|
||||
import android.content.res.Resources
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.crypto.CryptoUtil
|
||||
import com.kunzisoft.keepass.crypto.finalkey.AESKeyTransformerFactory
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.R
|
||||
import com.kunzisoft.encrypt.CryptoUtil
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.finalkey.AESKeyTransformerFactory
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
@@ -17,13 +17,13 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
package com.kunzisoft.encrypt.keyDerivation
|
||||
|
||||
import android.content.res.Resources
|
||||
import androidx.annotation.StringRes
|
||||
import com.kunzisoft.keepass.R
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.R
|
||||
import java.io.IOException
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation;
|
||||
package com.kunzisoft.encrypt.keyDerivation;
|
||||
|
||||
import com.kunzisoft.keepass.crypto.NativeLib;
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt;
|
||||
import com.kunzisoft.encrypt.NativeLib;
|
||||
import com.kunzisoft.encrypt.UnsignedInt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -17,10 +17,10 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
package com.kunzisoft.encrypt.keyDerivation
|
||||
|
||||
import com.kunzisoft.keepass.utils.ObjectNameResource
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.ObjectNameResource
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.Serializable
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
package com.kunzisoft.encrypt.keyDerivation
|
||||
|
||||
object KdfFactory {
|
||||
var aesKdf = AesKdf()
|
||||
@@ -17,11 +17,11 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.crypto.keyDerivation
|
||||
package com.kunzisoft.encrypt.keyDerivation
|
||||
|
||||
import com.kunzisoft.keepass.stream.bytes16ToUuid
|
||||
import com.kunzisoft.keepass.stream.uuidTo16Bytes
|
||||
import com.kunzisoft.keepass.utils.VariantDictionary
|
||||
import com.kunzisoft.encrypt.VariantDictionary
|
||||
import com.kunzisoft.encrypt.stream.bytes16ToUuid
|
||||
import com.kunzisoft.encrypt.stream.uuidTo16Bytes
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.kunzisoft.encrypt.stream;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.NullCipher;
|
||||
|
||||
/**
|
||||
* This class wraps an {@code InputStream} and a cipher so that {@code read()}
|
||||
* methods return data that are read from the underlying {@code InputStream} and
|
||||
* processed by the cipher.
|
||||
* <p>
|
||||
* The cipher must be initialized for the requested operation before being used
|
||||
* by a {@code BetterCipherInputStream}. For example, if a cipher initialized for
|
||||
* decryption is used with a {@code BetterCipherInputStream}, the {@code
|
||||
* BetterCipherInputStream} tries to read the data an decrypt them before returning.
|
||||
*/
|
||||
public class BetterCipherInputStream extends FilterInputStream {
|
||||
|
||||
private final Cipher cipher;
|
||||
private static final int I_DEFAULT_BUFFER_SIZE = 8 * 1024;
|
||||
private final byte[] i_buffer;
|
||||
private int index; // index of the bytes to return from o_buffer
|
||||
private byte[] o_buffer;
|
||||
private boolean finished;
|
||||
|
||||
/**
|
||||
* Creates a new {@code BetterCipherInputStream} instance for an {@code
|
||||
* InputStream} and a cipher.
|
||||
*
|
||||
* @param is
|
||||
* the input stream to read data from.
|
||||
* @param c
|
||||
* the cipher to process the data with.
|
||||
*/
|
||||
public BetterCipherInputStream(InputStream is, Cipher c) {
|
||||
this(is, c, I_DEFAULT_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code BetterCipherInputStream} instance for an {@code
|
||||
* InputStream} and a cipher.
|
||||
*
|
||||
* @param is
|
||||
* the input stream to read data from.
|
||||
* @param c
|
||||
* the cipher to process the data with.
|
||||
* @param bufferSize
|
||||
* size to buffer output from the cipher
|
||||
*/
|
||||
public BetterCipherInputStream(InputStream is, Cipher c, int bufferSize) {
|
||||
super(is);
|
||||
this.cipher = c;
|
||||
i_buffer = new byte[bufferSize];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code BetterCipherInputStream} instance for an {@code
|
||||
* InputStream} without a cipher.
|
||||
* <p>
|
||||
* A {@code NullCipher} is created and used to process the data.
|
||||
*
|
||||
* @param is
|
||||
* the input stream to read data from.
|
||||
*/
|
||||
protected BetterCipherInputStream(InputStream is) {
|
||||
this(is, new NullCipher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next byte from this cipher input stream.
|
||||
*
|
||||
* @return the next byte, or {@code -1} if the end of the stream is reached.
|
||||
* @throws IOException
|
||||
* if an error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
if (finished) {
|
||||
return ((o_buffer == null) || (index == o_buffer.length))
|
||||
? -1
|
||||
: o_buffer[index++] & 0xFF;
|
||||
}
|
||||
if ((o_buffer != null) && (index < o_buffer.length)) {
|
||||
return o_buffer[index++] & 0xFF;
|
||||
}
|
||||
index = 0;
|
||||
o_buffer = null;
|
||||
int num_read;
|
||||
while (o_buffer == null) {
|
||||
if ((num_read = in.read(i_buffer)) == -1) {
|
||||
try {
|
||||
o_buffer = cipher.doFinal();
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
o_buffer = cipher.update(i_buffer, 0, num_read);
|
||||
}
|
||||
return read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next {@code b.length} bytes from this input stream into buffer
|
||||
* {@code b}.
|
||||
*
|
||||
* @param b
|
||||
* the buffer to be filled with data.
|
||||
* @return the number of bytes filled into buffer {@code b}, or {@code -1}
|
||||
* if the end of the stream is reached.
|
||||
* @throws IOException
|
||||
* if an error occurs.
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next {@code len} bytes from this input stream into buffer
|
||||
* {@code b} starting at offset {@code off}.
|
||||
* <p>
|
||||
* if {@code b} is {@code null}, the next {@code len} bytes are read and
|
||||
* discarded.
|
||||
*
|
||||
* @param b
|
||||
* the buffer to be filled with data.
|
||||
* @param off
|
||||
* the offset to start in the buffer.
|
||||
* @param len
|
||||
* the maximum number of bytes to read.
|
||||
* @return the number of bytes filled into buffer {@code b}, or {@code -1}
|
||||
* of the of the stream is reached.
|
||||
* @throws IOException
|
||||
* if an error occurs.
|
||||
* @throws NullPointerException
|
||||
* if the underlying input stream is {@code null}.
|
||||
*/
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (in == null) {
|
||||
throw new NullPointerException("Underlying input stream is null");
|
||||
}
|
||||
|
||||
int read_b;
|
||||
int i;
|
||||
for (i=0; i<len; i++) {
|
||||
if ((read_b = read()) == -1) {
|
||||
return (i == 0) ? -1 : i;
|
||||
}
|
||||
if (b != null) {
|
||||
b[off+i] = (byte) read_b;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips up to n bytes from this input stream.
|
||||
* <p>
|
||||
* The number of bytes skipped depends on the result of a call to
|
||||
* {@link BetterCipherInputStream#available() available}. The smaller of n and the
|
||||
* result are the number of bytes being skipped.
|
||||
*
|
||||
* @param n
|
||||
* the number of bytes that should be skipped.
|
||||
* @return the number of bytes actually skipped.
|
||||
* @throws IOException
|
||||
* if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public long skip(long n) throws IOException {
|
||||
long i = 0;
|
||||
int available = available();
|
||||
if (available < n) {
|
||||
n = available;
|
||||
}
|
||||
while ((i < n) && (read() != -1)) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available without blocking.
|
||||
*
|
||||
* @return the number of bytes available, currently zero.
|
||||
* @throws IOException
|
||||
* if an error occurs
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this {@code BetterCipherInputStream}, also closes the underlying input
|
||||
* stream and call {@code doFinal} on the cipher object.
|
||||
*
|
||||
* @throws IOException
|
||||
* if an error occurs.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
try {
|
||||
cipher.doFinal();
|
||||
} catch (GeneralSecurityException ignore) {
|
||||
//do like RI does
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this input stream supports {@code mark} and
|
||||
* {@code reset}, which it does not.
|
||||
*
|
||||
* @return false, since this input stream does not support {@code mark} and
|
||||
* {@code reset}.
|
||||
*/
|
||||
@Override
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
package com.kunzisoft.encrypt.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
package com.kunzisoft.encrypt.stream
|
||||
|
||||
import com.kunzisoft.keepass.utils.UnsignedInt
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.keepass.stream
|
||||
package com.kunzisoft.encrypt.stream
|
||||
|
||||
import java.io.IOException
|
||||
import java.io.OutputStream
|
||||
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2019 Jeremy Jamet / Kunzisoft.
|
||||
*
|
||||
* This file is part of KeePassDX.
|
||||
*
|
||||
* KeePassDX 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.
|
||||
*
|
||||
* KeePassDX 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 KeePassDX. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.kunzisoft.encrypt.stream
|
||||
|
||||
import com.kunzisoft.encrypt.UnsignedInt
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Read number of bytes defined by [length] and invoke [readBytes] each time the buffer is full or no more data to read.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.readBytes(length: Int, bufferSize: Int = DEFAULT_BUFFER_SIZE,
|
||||
readBytes: (bytesRead: ByteArray) -> Unit) {
|
||||
var bufferLength = bufferSize
|
||||
var buffer = ByteArray(bufferLength)
|
||||
|
||||
var offset = 0
|
||||
var read = 0
|
||||
while (offset < length && read != -1) {
|
||||
|
||||
// To reduce the buffer for the last bytes reads
|
||||
if (length - offset < bufferLength) {
|
||||
bufferLength = length - offset
|
||||
buffer = ByteArray(bufferLength)
|
||||
}
|
||||
read = this.read(buffer, 0, bufferLength)
|
||||
|
||||
// To get only the bytes read
|
||||
val optimizedBuffer: ByteArray = if (read >= 0 && buffer.size > read) {
|
||||
buffer.copyOf(read)
|
||||
} else {
|
||||
buffer
|
||||
}
|
||||
readBytes.invoke(optimizedBuffer)
|
||||
offset += read
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 32-bit value and return it as a long, so that it can
|
||||
* be interpreted as an unsigned integer.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.readBytes4ToUInt(): UnsignedInt {
|
||||
return bytes4ToUInt(readBytesLength(4))
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun InputStream.readBytesLength(length: Int): ByteArray {
|
||||
val buf = ByteArray(length)
|
||||
// WARNING this.read(buf, 0, length) Doesn't work
|
||||
for (i in 0 until length) {
|
||||
buf[i] = this.read().toByte()
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an unsigned 16-bit value.
|
||||
*/
|
||||
fun bytes2ToUShort(buf: ByteArray): Int {
|
||||
return ((buf[0].toInt() and 0xFF)
|
||||
+ (buf[1].toInt() and 0xFF shl 8))
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 64 bit long
|
||||
*/
|
||||
fun bytes64ToLong(buf: ByteArray): Long {
|
||||
return ((buf[0].toLong() and 0xFF)
|
||||
+ (buf[1].toLong() and 0xFF shl 8)
|
||||
+ (buf[2].toLong() and 0xFF shl 16)
|
||||
+ (buf[3].toLong() and 0xFF shl 24)
|
||||
+ (buf[4].toLong() and 0xFF shl 32)
|
||||
+ (buf[5].toLong() and 0xFF shl 40)
|
||||
+ (buf[6].toLong() and 0xFF shl 48)
|
||||
+ (buf[7].toLong() and 0xFF shl 56))
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 32-bit value.
|
||||
*/
|
||||
fun bytes4ToUInt(buf: ByteArray): UnsignedInt {
|
||||
return UnsignedInt((buf[0].toInt() and 0xFF)
|
||||
+ (buf[1].toInt() and 0xFF shl 8)
|
||||
+ (buf[2].toInt() and 0xFF shl 16)
|
||||
+ (buf[3].toInt() and 0xFF shl 24))
|
||||
}
|
||||
|
||||
fun bytes16ToUuid(buf: ByteArray): UUID {
|
||||
var lsb: Long = 0
|
||||
for (i in 15 downTo 8) {
|
||||
lsb = lsb shl 8 or (buf[i].toLong() and 0xff)
|
||||
}
|
||||
|
||||
var msb: Long = 0
|
||||
for (i in 7 downTo 0) {
|
||||
msb = msb shl 8 or (buf[i].toLong() and 0xff)
|
||||
}
|
||||
|
||||
return UUID(msb, lsb)
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a 32-bit Int value.
|
||||
*/
|
||||
fun uIntTo4Bytes(value: UnsignedInt): ByteArray {
|
||||
val buf = ByteArray(4)
|
||||
for (i in 0 until 4) {
|
||||
buf[i] = (value.toKotlinInt().ushr(8 * i) and 0xFF).toByte()
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an unsigned 16-bit value
|
||||
*/
|
||||
fun uShortTo2Bytes(value: Int): ByteArray {
|
||||
val buf = ByteArray(2)
|
||||
buf[0] = (value and 0x00FF).toByte()
|
||||
buf[1] = (value and 0xFF00 shr 8).toByte()
|
||||
return buf
|
||||
}
|
||||
|
||||
fun longTo8Bytes(value: Long): ByteArray {
|
||||
val buf = ByteArray(8)
|
||||
for (i in 0 until 8) {
|
||||
buf[i] = (value.ushr(8 * i) and 0xFF).toByte()
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
fun uuidTo16Bytes(uuid: UUID): ByteArray {
|
||||
val buf = ByteArray(16)
|
||||
for (i in 0 until 8) {
|
||||
buf[i] = (uuid.mostSignificantBits.ushr(8 * i) and 0xFF).toByte()
|
||||
}
|
||||
for (i in 8 until 16) {
|
||||
buf[i] = (uuid.leastSignificantBits.ushr(8 * i) and 0xFF).toByte()
|
||||
}
|
||||
return buf
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.kunzisoft.encrypt.stream;
|
||||
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
|
||||
/**
|
||||
* the interface stream ciphers conform to.
|
||||
*/
|
||||
public interface StreamCipher
|
||||
{
|
||||
/**
|
||||
* Initialise the cipher.
|
||||
*
|
||||
* @param forEncryption if true the cipher is initialised for
|
||||
* encryption, if false for decryption.
|
||||
* @param params the key and other data required by the cipher.
|
||||
* @exception IllegalArgumentException if the params argument is
|
||||
* inappropriate.
|
||||
*/
|
||||
public void init(boolean forEncryption, CipherParameters params)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Return the name of the algorithm the cipher implements.
|
||||
*
|
||||
* @return the name of the algorithm the cipher implements.
|
||||
*/
|
||||
public String getAlgorithmName();
|
||||
|
||||
/**
|
||||
* encrypt/decrypt a single byte returning the result.
|
||||
*
|
||||
* @param in the byte to be processed.
|
||||
* @return the result of processing the input byte.
|
||||
*/
|
||||
public byte returnByte(byte in);
|
||||
|
||||
/**
|
||||
* process a block of bytes from in putting the result into out.
|
||||
*
|
||||
* @param in the input byte array.
|
||||
* @param inOff the offset into the in array where the data to be processed starts.
|
||||
* @param len the number of bytes to be processed.
|
||||
* @param out the output buffer the processed bytes go into.
|
||||
* @param outOff the offset into the output byte array the processed data starts at.
|
||||
* @return the number of bytes produced - should always be len.
|
||||
* @exception DataLengthException if the output buffer is too small.
|
||||
*/
|
||||
public int processBytes(byte[] in, int inOff, int len, byte[] out, int outOff)
|
||||
throws DataLengthException;
|
||||
|
||||
/**
|
||||
* reset the cipher. This leaves it in the same state
|
||||
* it was at after the last init (if there was one).
|
||||
*/
|
||||
public void reset();
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void throwExceptionF(JNIEnv *env, jclass exception, const char *format, ...) {
|
||||
#define ARGON2_HASHLEN 32
|
||||
|
||||
JNIEXPORT jbyteArray
|
||||
JNICALL Java_com_kunzisoft_keepass_crypto_keyDerivation_Argon2Native_nTransformMasterKey(JNIEnv *env,
|
||||
JNICALL Java_com_kunzisoft_encrypt_keyDerivation_Argon2Native_nTransformMasterKey(JNIEnv *env,
|
||||
jobject this, jint type, jbyteArray password, jbyteArray salt, jint parallelism, jint memory,
|
||||
jint iterations, jbyteArray secretKey, jbyteArray associatedData, jint version) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user