https://github.com/ticesoftware/doubleratchet
Implementation of the Double Ratchet protocol in Swift based on libsodium.
https://github.com/ticesoftware/doubleratchet
tice-app tice-crypto
Last synced: about 1 year ago
JSON representation
Implementation of the Double Ratchet protocol in Swift based on libsodium.
- Host: GitHub
- URL: https://github.com/ticesoftware/doubleratchet
- Owner: TICESoftware
- License: mit
- Created: 2019-05-07T11:46:36.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2021-06-01T13:19:14.000Z (about 5 years ago)
- Last Synced: 2025-03-26T22:36:08.167Z (about 1 year ago)
- Topics: tice-app, tice-crypto
- Language: Swift
- Homepage:
- Size: 55.7 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DoubleRatchet
Implementation of the Double Ratchet protocol in Swift. The cryptographic operations are provided by libsodium entirely.
## Installation
### SPM
`.package(url: "https://github.com/TICESoftware/DoubleRatchet.git", .upToNextMajor(from: "1.0.0"))`
In order to build the library it is necessary to link libsodium. The official repository includes scripts to build binaries for specific platforms.
`swift build -Xcc -I[header search path] -Xlinker -L[binary path]`
When using Xcode you can set the header search path manually to include the libsodium header files and link the static libsodium library.
### CodoaPods
`pod 'DoubleRatchet'`
This uses `Sodium` as a dependency which includes the pre-compiled libsodium library. No further setup necessary.
## Usage
Alice and Bob calculate a shared secret using a secure channel. After that one party can start the conversation as soon as she gets to know the public key of the other one.
```swift
import DoubleRatchet
let sharedSecret: Bytes = ...
let info = "DoubleRatchetExample"
let bob = try DoubleRatchet(keyPair: nil, remotePublicKey: nil, sharedSecret: sharedSecret, maxSkip: 20, maxCache: 20, info: info)
// Bob sends his public key to Alice using another channel
// sendToAlice(bob.publicKey)
let alice = try DoubleRatchet(keyPair: nil, remotePublicKey: bob.publicKey, sharedSecret: sharedSecret, maxSkip: 20, maxCache: 20, info: info)
// Now the conversation begins
let message = "Hello, Bob!".bytes
let encryptedMessage = try alice.encrypt(plaintext: message)
let decryptedMessage = try bob.decrypt(message: encryptedMessage)
print(decryptedMessage.utf8String!) // Hello, Bob!
```