Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 66 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
[![Build Status](https://github.com/Devolutions/devolutions-crypto/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/Devolutions/devolutions-crypto/actions/workflows/ci.yml)
# devolutions-crypto

[![crates.io](https://img.shields.io/crates/v/devolutions-crypto.svg)](https://crates.io/crates/devolutions-crypto)
[![nuget](https://img.shields.io/nuget/v/Devolutions.Crypto.Core?style=flat&color=orange)](https://www.nuget.org/packages/Devolutions.Crypto.Core)
[![npmjs](https://img.shields.io/npm/v/%40devolutions%2Fdevolutions-crypto)](https://www.npmjs.com/package/@devolutions/devolutions-crypto)
[![pypi](https://img.shields.io/pypi/v/devolutions-crypto)](https://pypi.org/project/devolutions-crypto/)
[![kotlin](https://img.shields.io/badge/kotlin-2025.2.12-orange)](https://cloudsmith.io/~devolutions/repos/maven-public/packages/detail/maven/devolutions-crypto/2025.2.12/a=noarch;xg=devolutions/)
[![swift](https://img.shields.io/badge/swift-2025.2.12-orange)](https://github.com/Devolutions/devolutions-crypto/tree/2601b67f8347bdcf2ae4f2505e9a34940d85a3f9)
This repo contains the library used for cryptography of products used by Devolutions.
It also includes wrappers for it in different languages. The supported languages are: [Rust](src/), [C#](wrappers/csharp/), [Javascript/Typescript](wrappers/wasm/), [Kotlin](wrappers/kotlin), [Swift](wrappers/swift/), Python.
The Javascript version of the library is compiled using WebAssembly and can run in a browser.

devolutions-crypto uses the following algorithms.

* Symmetric cryptography: XChaCha20Poly1305
* Public-key cryptography: Curve25519
* Asymmetric encryption: ECIES
* Key exchange: x25519, ECDH over Curve25519
* Key derivation: Argon2id, PBKDF2-HMAC-SHA2-256
* Password Hashing: PBKDF2-HMAC-SHA2-256
* Secret Sharing: Shamir Secret sharing over GF256
* Online Ciphertext: XChaCha20-Poly1305

## License

# DevolutionsCrypto
This repo contains the library used for cryptography of products used by Devolutions.
It also includes wrappers for it in different languages.
Currently, the supported languages are: [Rust](src/), [C#](wrappers/csharp/) and [Javascript/Typescript](wrappers/wasm/), [Kotlin](wrappers/kotlin), [Swift](wrappers/swift/)
This project is licensed under:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

Python bindings are also available. You can install it with `pip3 install devolutions-crypto`, but this might not work depending on the platform. If it doesn't, you can try building it manually.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in devolutions-crypto by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Note that the Javascript version of the library is compiled using WebAssembly, so it can run in a browser.
## Local development setup

# Underlying algorithms
As of the current version:
* Symmetric cryptography uses XChaCha20Poly1305
* Asymmetric cryptography uses Curve25519
* Asymmetric encryption uses ECIES.
* Key exchange uses x25519, or ECDH over Curve25519
* Key derivation uses Argon2id or PBKDF2-HMAC-SHA2-256
* Password Hashing uses PBKDF2-HMAC-SHA2-256
* Secret Sharing uses Shamir Secret sharing over GF256
* Online Ciphertext uses XChaCha20-Poly1305
### Rust

Build the project with cargo.

# License
```
cargo build
cargo test
```

This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
### C#

at your option.
Build the rust library, then open the solution wrappers\csharp\tests\unit-tests\local\devolutions-crypto-tests\devolutions-crypto-tests.sln.

### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in devolutions-crypto by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
### WebAssembly

**Setup**

- Install the wasm32-unknown-unknown target with `rustup target add wasm32-unknown-unknown`
- Install `wasm-pack` with `cargo install wasm-pack`.

**Building**

Run `wasm_build.ps1` or `wasm_build.sh` in the wrappers/wasm folder.

Tests can then be run in the wrappers/wasm/tests folder.

```
npm install
npm run test
```

# Devolutions Crypto Header
## The devolutions-crypto header

### Example Header
| Position | Byte value |
|-----------|-------------|
| 1 | 0xD |
| 2 | 0xC |
| 3 | 0x1 |
| 4 | 0x0 |
| 5 | 0x1 |
| 6 | 0x0 |
| 7 | 0x1 |
| 8 | 0x0 |
Data generated with devolutions-crypto is prefixed with a header that describes the cryptographic type
and its properties.

This header represents :
A Curve25519 private key from Devolutions Crypto
| Bytes | Content |
|-----------|------------------------|
| 1-2 | Signature Bytes (0xDC) |
| 3-4 | Data type |
| 5-6 | Data sub type |
| 7-8 | Version |

- Signature Bytes
- The first two bytes specifies that the data is from Devolutions Crypto (DC)
- Data type
- The second two bytes (pos: 3,4 ) represents the data type.
- Data sub type
- The third two bytes (pos: 5, 6) represents the data sub type.
- Version
- The fourth two bytes (pos: 7, 8) represents the version.

## Data Type
### Data Type

| Data Types | Value | Description |
|---------------------|--------|------------------------------------------------------------------------------|
Expand All @@ -85,7 +85,7 @@ A Curve25519 private key from Devolutions Crypto
| KeyDerivation | 0x80 | Serialized key derivation parameters used to reproduce a derived secret key. |


## Sub types
### Sub types

| Key Sub Types | Value |
|---------------|--------|
Expand Down Expand Up @@ -114,7 +114,7 @@ A Curve25519 private key from Devolutions Crypto
| None | 0x00 |


## Version
### Version
| Key Version | Value | Description |
|----------------------|--------|-------------------------------------------------------------|
| Latest | 0x00 | Uses the latest version. |
Expand Down Expand Up @@ -158,35 +158,19 @@ A Curve25519 private key from Devolutions Crypto
| V1 | 0x10 | Uses version 1: XChaCha20-Poly1305 wrapped in a STREAM construction. |


# Local development setup
## Source of randomness

## Rust
All randomness used by the library comes directly from the operating system's cryptographically secure random number generator (CSPRNG). The Rust core reads from the OS through the [`getrandom`](https://crates.io/crates/getrandom) crate. The wrappers (C#, Kotlin, Swift, Python, FFI) all call this Rust core. If the OS random source is unavailable, the library returns an error or panics. It never falls back to a weaker source.

Build the project with cargo.
The underlying source depends on the platform:

```
cargo build
cargo test
```

## C#

Build the rust library, then open the solution wrappers\csharp\tests\unit-tests\local\devolutions-crypto-tests\devolutions-crypto-tests.sln.

## WebAssembly
| Platform | Source |
|-------------------------|------------------------------------------------------------|
| Linux, Android | `getrandom(2)` system call (kernel CSPRNG) |
| Windows | `ProcessPrng` (CNG, the system CSPRNG) |
| macOS | `getentropy(2)` |
| iOS | `CCRandomGenerateBytes` (CommonCrypto) |
| WebAssembly (browser) | Web Crypto `crypto.getRandomValues` |
| WebAssembly (Node.js) | Web Crypto `crypto.getRandomValues` |

**Setup**

- Install the wasm32-unknown-unknown target with `rustup target add wasm32-unknown-unknown`
- Install `wasm-pack` with `cargo install wasm-pack`.

**Building**

Run `wasm_build.ps1` or `wasm_build.sh` in the wrappers/wasm folder.

Tests can then be run in the wrappers/wasm/tests folder.

```
npm install
npm run test
```
Loading