https://github.com/ticesoftware/androidx3dh
https://github.com/ticesoftware/androidx3dh
kotlin tice-app tice-crypto
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ticesoftware/androidx3dh
- Owner: TICESoftware
- License: mit
- Created: 2020-03-30T09:13:03.000Z (about 6 years ago)
- Default Branch: main
- Last Pushed: 2023-08-24T07:47:17.000Z (almost 3 years ago)
- Last Synced: 2025-03-05T11:16:13.111Z (over 1 year ago)
- Topics: kotlin, tice-app, tice-crypto
- Language: Kotlin
- Homepage:
- Size: 159 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AndroidX3DH
This package implements the X3DH key agreement protocol in Swift. The cryptographic operations are provided by libsodium entirely. Libsodium is integrated via Lazysodium.
## Installation
### Jitpack
To integrate the library via jitpack add the jitpack repository to your root `build.gradle` file:
```
allprojects {
repositories {
...
maven { url "https://dl.bintray.com/terl/lazysodium-maven" }
maven { url 'https://jitpack.io' }
}
}
```
You can then add the dependency to your app's `build.gradle` file where `$VERSION` specifies the specific version of the library:
```
dependencies {
implementation 'com.github.TICESoftware:AndroidX3DH:$VERSION'
implementation 'com.github.TICESoftware:AndroidHKDF:1.0.0'
implementation "com.goterl:lazysodium-android:4.1.0@aar"
implementation 'net.java.dev.jna:jna:5.5.0@aar'
}
```
# Usage
Alice needs to retrieve some public keys from Bob that he has made public previously. She then calculates a shared secret and sends some information to Bob so that he can calculcate the shared secret on his side as well.
```kotlin
val preKeySigner = // ... Signing the key is not part of this library
val prekeySignatureVerifier = // ... and neither is verification
val bob = X3DH()
val bobIdentityKeyPair = bob.generateIdentityKeyPair()
val bobSignedPrekeyPair = bob.generateSignedPrekeyPair { /* Signer */ }
val bobOneTimePrekeyPairs = bob.generateOneTimePrekeyPairs(2)
val alice = X3DH()
val aliceIdentityKeyPair = alice.generateIdentityKeyPair()
val aliceSignedPrekey = alice.generateSignedPrekeyPair { /* Signer */ }
// [Alice fetches bob's prekey bundle ...]
val keyAgreementInitiation = alice.initiateKeyAgreement(bobIdentityKeyPair.publicKey, bobSignedPrekeyPair.keyPair.publicKey, bobSignedPrekeyPair.signature, bobOneTimePrekeyPairs.first().publicKey, aliceIdentityKeyPair, aliceSignedPrekey.keyPair.publicKey, { /* Verifier */ }, info)
// [Alice sends identity key, ephemeral key and used one-time prekey to bob ...]
val sharedSecret = bob.sharedSecretFromKeyAgreement(aliceIdentityKeyPair.publicKey, keyAgreementInitiation.ephemeralPublicKey, bobOneTimePrekeyPairs.first(), bobIdentityKeyPair, bobSignedPrekeyPair.keyPair, info)
```