quantacipher 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantacipher-0.1.1/PKG-INFO +8 -0
- quantacipher-0.1.1/pyproject.toml +19 -0
- quantacipher-0.1.1/quantacipher-core/Cargo.toml +17 -0
- quantacipher-0.1.1/quantacipher-core/README.md +45 -0
- quantacipher-0.1.1/quantacipher-core/src/error.rs +48 -0
- quantacipher-0.1.1/quantacipher-core/src/lib.rs +130 -0
- quantacipher-0.1.1/quantacipher-python/.gitignore +4 -0
- quantacipher-0.1.1/quantacipher-python/Cargo.lock +496 -0
- quantacipher-0.1.1/quantacipher-python/Cargo.toml +17 -0
- quantacipher-0.1.1/quantacipher-python/README.md +12 -0
- quantacipher-0.1.1/quantacipher-python/quantacipher/__init__.py +109 -0
- quantacipher-0.1.1/quantacipher-python/src/lib.rs +61 -0
- quantacipher-0.1.1/quantacipher-python/test.py +39 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.0,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "quantacipher"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Zero-trust PQC encryption library for Python"
|
|
9
|
+
authors = [{ name = "QuantaLabs" }]
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
urls = { Repository = "https://github.com/xaexaex/quantacipher" }
|
|
12
|
+
dependencies = [
|
|
13
|
+
"requests>=2.0.0"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool]
|
|
17
|
+
|
|
18
|
+
[tool.maturin]
|
|
19
|
+
manifest-path = "quantacipher-python/Cargo.toml"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "quantacipher-core"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Zero-trust PQC (Kyber) encryption core"
|
|
6
|
+
repository = "https://github.com/xaexaex/quantacipher"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = ["QuantaLabs"]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
base64 = "0.21"
|
|
13
|
+
aes-gcm = "0.10"
|
|
14
|
+
pqc_kyber = "0.7.1"
|
|
15
|
+
rand = "0.8"
|
|
16
|
+
# Note: getrandom is removed from here so we don't force 'js' feature on Python builds.
|
|
17
|
+
# It will use the OS default rng (or WASM rng if provided in the wrapper).
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# QuantaCipher 🔐
|
|
2
|
+
|
|
3
|
+
Zero-Trust Post-Quantum Cryptography (PQC) SDK for the Enterprise.
|
|
4
|
+
Built on top of the NIST-standardized Kyber algorithm to protect your infrastructure against "Store Now, Decrypt Later" quantum attacks.
|
|
5
|
+
|
|
6
|
+
## Ecosystem
|
|
7
|
+
|
|
8
|
+
- **`quantacipher-core`**: The underlying pure Rust cryptographic implementation.
|
|
9
|
+
- **`quantacipher-sdk`**: The Node.js / TypeScript SDK.
|
|
10
|
+
- **`quantacipher`**: The native Python bindings.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
- **Quantum-Resistant**: Uses FIPS-standardized Kyber key encapsulation.
|
|
14
|
+
- **Zero-Trust**: Keys are generated and retained client-side; only encrypted payloads touch the network.
|
|
15
|
+
- **Cross-Platform**: Compile once in Rust, use flawlessly in JS/TS and Python.
|
|
16
|
+
|
|
17
|
+
## Quickstart
|
|
18
|
+
|
|
19
|
+
### Python
|
|
20
|
+
```bash
|
|
21
|
+
pip install quantacipher
|
|
22
|
+
```
|
|
23
|
+
```python
|
|
24
|
+
import quantacipher
|
|
25
|
+
|
|
26
|
+
keys = quantacipher.generate_keypair()
|
|
27
|
+
ciphertext = quantacipher.secure_encrypt("Top Secret Data", keys["publicKey"])
|
|
28
|
+
plaintext = quantacipher.secure_decrypt(ciphertext, keys["privateKey"])
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### JS/TS (Node.js)
|
|
32
|
+
```bash
|
|
33
|
+
npm install quantacipher-sdk
|
|
34
|
+
```
|
|
35
|
+
```typescript
|
|
36
|
+
import { QuantaCipher } from 'quantacipher-sdk';
|
|
37
|
+
|
|
38
|
+
const sdk = new QuantaCipher({ apiKey: 'your_api_key' });
|
|
39
|
+
const keys = sdk.generateKeypair();
|
|
40
|
+
const ciphertext = sdk.encryptSecure("Top Secret Data", keys.publicKey);
|
|
41
|
+
const plaintext = sdk.decryptSecure(ciphertext, keys.privateKey);
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Commercial & Enterprise Use
|
|
45
|
+
QuantaCipher SDKs are open-source and free to use. To manage API keys, audit logs, and scale your cryptography, check out our [Enterprise SaaS Platform](https://quantacipher.com).
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
use std::fmt;
|
|
2
|
+
|
|
3
|
+
#[derive(Debug)]
|
|
4
|
+
pub enum QuantaCipherError {
|
|
5
|
+
KeygenFailed,
|
|
6
|
+
EncapsulationFailed,
|
|
7
|
+
DecapsulationFailed,
|
|
8
|
+
EncryptionFailed,
|
|
9
|
+
DecryptionFailed,
|
|
10
|
+
InvalidPublicKeyLength,
|
|
11
|
+
InvalidPrivateKeyLength,
|
|
12
|
+
InvalidCiphertextLength,
|
|
13
|
+
InvalidPayloadFormat,
|
|
14
|
+
DecodeError(base64::DecodeError),
|
|
15
|
+
Utf8Error(std::string::FromUtf8Error),
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
impl fmt::Display for QuantaCipherError {
|
|
19
|
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
20
|
+
match self {
|
|
21
|
+
Self::KeygenFailed => write!(f, "Kyber keygen failed"),
|
|
22
|
+
Self::EncapsulationFailed => write!(f, "Kyber encapsulation failed"),
|
|
23
|
+
Self::DecapsulationFailed => write!(f, "Kyber decapsulation failed (wrong key?)"),
|
|
24
|
+
Self::EncryptionFailed => write!(f, "AES-GCM encryption failed"),
|
|
25
|
+
Self::DecryptionFailed => write!(f, "AES-GCM decryption failed (tampered data or wrong key?)"),
|
|
26
|
+
Self::InvalidPublicKeyLength => write!(f, "Invalid public key length"),
|
|
27
|
+
Self::InvalidPrivateKeyLength => write!(f, "Invalid private key length"),
|
|
28
|
+
Self::InvalidCiphertextLength => write!(f, "Invalid Kyber ciphertext length"),
|
|
29
|
+
Self::InvalidPayloadFormat => write!(f, "Invalid payload format"),
|
|
30
|
+
Self::DecodeError(e) => write!(f, "Base64 decode error: {}", e),
|
|
31
|
+
Self::Utf8Error(e) => write!(f, "UTF-8 decode error: {}", e),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
impl std::error::Error for QuantaCipherError {}
|
|
37
|
+
|
|
38
|
+
impl From<base64::DecodeError> for QuantaCipherError {
|
|
39
|
+
fn from(err: base64::DecodeError) -> Self {
|
|
40
|
+
QuantaCipherError::DecodeError(err)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
impl From<std::string::FromUtf8Error> for QuantaCipherError {
|
|
45
|
+
fn from(err: std::string::FromUtf8Error) -> Self {
|
|
46
|
+
QuantaCipherError::Utf8Error(err)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
pub mod error;
|
|
2
|
+
|
|
3
|
+
use aes_gcm::{
|
|
4
|
+
aead::{Aead, AeadCore, KeyInit, OsRng},
|
|
5
|
+
Aes256Gcm, Key,
|
|
6
|
+
};
|
|
7
|
+
use base64::{engine::general_purpose, Engine as _};
|
|
8
|
+
use pqc_kyber::*;
|
|
9
|
+
use rand::rngs::OsRng as RandOsRng;
|
|
10
|
+
|
|
11
|
+
pub use error::QuantaCipherError;
|
|
12
|
+
|
|
13
|
+
/// Generates a base64 encoded Kyber-1024 keypair (publicKey, privateKey)
|
|
14
|
+
pub fn generate_keypair() -> Result<(String, String), QuantaCipherError> {
|
|
15
|
+
let mut rng = RandOsRng;
|
|
16
|
+
let keys = keypair(&mut rng).map_err(|_| QuantaCipherError::KeygenFailed)?;
|
|
17
|
+
|
|
18
|
+
let b64_public = general_purpose::STANDARD.encode(&keys.public);
|
|
19
|
+
let b64_private = general_purpose::STANDARD.encode(&keys.secret);
|
|
20
|
+
|
|
21
|
+
Ok((b64_public, b64_private))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Encrypts data in Vault Mode (ephemeral keypair, permanently sealed)
|
|
25
|
+
pub fn vault_encrypt(plaintext: &str) -> Result<String, QuantaCipherError> {
|
|
26
|
+
let mut rng = RandOsRng;
|
|
27
|
+
|
|
28
|
+
let keys = keypair(&mut rng).map_err(|_| QuantaCipherError::KeygenFailed)?;
|
|
29
|
+
|
|
30
|
+
let (kyber_ciphertext, shared_secret) =
|
|
31
|
+
encapsulate(&keys.public, &mut rng).map_err(|_| QuantaCipherError::EncapsulationFailed)?;
|
|
32
|
+
|
|
33
|
+
let aes_key = Key::<Aes256Gcm>::from_slice(&shared_secret);
|
|
34
|
+
let cipher = Aes256Gcm::new(aes_key);
|
|
35
|
+
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
|
36
|
+
|
|
37
|
+
let aes_ciphertext = cipher
|
|
38
|
+
.encrypt(&nonce, plaintext.as_bytes())
|
|
39
|
+
.map_err(|_| QuantaCipherError::EncryptionFailed)?;
|
|
40
|
+
|
|
41
|
+
let b64_kyber_ct = general_purpose::STANDARD.encode(kyber_ciphertext);
|
|
42
|
+
let b64_nonce = general_purpose::STANDARD.encode(nonce.as_slice());
|
|
43
|
+
let b64_aes_ct = general_purpose::STANDARD.encode(aes_ciphertext);
|
|
44
|
+
|
|
45
|
+
Ok(format!("QZ_VAULT_V1:{}:{}:{}", b64_kyber_ct, b64_nonce, b64_aes_ct))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Encrypts data using the recipient's Base64 Kyber public key
|
|
49
|
+
pub fn secure_encrypt(plaintext: &str, public_key_b64: &str) -> Result<String, QuantaCipherError> {
|
|
50
|
+
let mut rng = RandOsRng;
|
|
51
|
+
|
|
52
|
+
let public_key_bytes = general_purpose::STANDARD
|
|
53
|
+
.decode(public_key_b64)
|
|
54
|
+
.map_err(QuantaCipherError::DecodeError)?;
|
|
55
|
+
|
|
56
|
+
if public_key_bytes.len() != KYBER_PUBLICKEYBYTES {
|
|
57
|
+
return Err(QuantaCipherError::InvalidPublicKeyLength);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let mut pk = [0u8; KYBER_PUBLICKEYBYTES];
|
|
61
|
+
pk.copy_from_slice(&public_key_bytes);
|
|
62
|
+
|
|
63
|
+
let (kyber_ciphertext, shared_secret) =
|
|
64
|
+
encapsulate(&pk, &mut rng).map_err(|_| QuantaCipherError::EncapsulationFailed)?;
|
|
65
|
+
|
|
66
|
+
let aes_key = Key::<Aes256Gcm>::from_slice(&shared_secret);
|
|
67
|
+
let cipher = Aes256Gcm::new(aes_key);
|
|
68
|
+
let nonce = Aes256Gcm::generate_nonce(&mut OsRng);
|
|
69
|
+
|
|
70
|
+
let aes_ciphertext = cipher
|
|
71
|
+
.encrypt(&nonce, plaintext.as_bytes())
|
|
72
|
+
.map_err(|_| QuantaCipherError::EncryptionFailed)?;
|
|
73
|
+
|
|
74
|
+
let b64_kyber_ct = general_purpose::STANDARD.encode(kyber_ciphertext);
|
|
75
|
+
let b64_nonce = general_purpose::STANDARD.encode(nonce.as_slice());
|
|
76
|
+
let b64_aes_ct = general_purpose::STANDARD.encode(aes_ciphertext);
|
|
77
|
+
|
|
78
|
+
Ok(format!("QZ_SECURE_V1:{}:{}:{}", b64_kyber_ct, b64_nonce, b64_aes_ct))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/// Decrypts data using the user's Base64 Kyber private key
|
|
82
|
+
pub fn secure_decrypt(ciphertext_payload: &str, private_key_b64: &str) -> Result<String, QuantaCipherError> {
|
|
83
|
+
if !ciphertext_payload.starts_with("QZ_SECURE_V1:") {
|
|
84
|
+
return Err(QuantaCipherError::InvalidPayloadFormat);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let parts: Vec<&str> = ciphertext_payload.splitn(4, ':').collect();
|
|
88
|
+
if parts.len() != 4 {
|
|
89
|
+
return Err(QuantaCipherError::InvalidPayloadFormat);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let kyber_ct_bytes = general_purpose::STANDARD.decode(parts[1]).map_err(QuantaCipherError::DecodeError)?;
|
|
93
|
+
let nonce_bytes = general_purpose::STANDARD.decode(parts[2]).map_err(QuantaCipherError::DecodeError)?;
|
|
94
|
+
let aes_ct_bytes = general_purpose::STANDARD.decode(parts[3]).map_err(QuantaCipherError::DecodeError)?;
|
|
95
|
+
let private_key_bytes = general_purpose::STANDARD.decode(private_key_b64).map_err(QuantaCipherError::DecodeError)?;
|
|
96
|
+
|
|
97
|
+
if private_key_bytes.len() != KYBER_SECRETKEYBYTES {
|
|
98
|
+
return Err(QuantaCipherError::InvalidPrivateKeyLength);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let mut sk = [0u8; KYBER_SECRETKEYBYTES];
|
|
102
|
+
sk.copy_from_slice(&private_key_bytes);
|
|
103
|
+
|
|
104
|
+
if kyber_ct_bytes.len() != KYBER_CIPHERTEXTBYTES {
|
|
105
|
+
return Err(QuantaCipherError::InvalidCiphertextLength);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let mut kyber_ct = [0u8; KYBER_CIPHERTEXTBYTES];
|
|
109
|
+
kyber_ct.copy_from_slice(&kyber_ct_bytes);
|
|
110
|
+
|
|
111
|
+
let shared_secret = decapsulate(&kyber_ct, &sk).map_err(|_| QuantaCipherError::DecapsulationFailed)?;
|
|
112
|
+
|
|
113
|
+
let aes_key = Key::<Aes256Gcm>::from_slice(&shared_secret);
|
|
114
|
+
let cipher = Aes256Gcm::new(aes_key);
|
|
115
|
+
|
|
116
|
+
if nonce_bytes.len() != 12 {
|
|
117
|
+
return Err(QuantaCipherError::InvalidPayloadFormat); // Nonce length
|
|
118
|
+
}
|
|
119
|
+
let nonce = aes_gcm::Nonce::from_slice(&nonce_bytes);
|
|
120
|
+
|
|
121
|
+
let plaintext_bytes = cipher
|
|
122
|
+
.decrypt(nonce, aes_ct_bytes.as_ref())
|
|
123
|
+
.map_err(|_| QuantaCipherError::DecryptionFailed)?;
|
|
124
|
+
|
|
125
|
+
String::from_utf8(plaintext_bytes).map_err(QuantaCipherError::Utf8Error)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
pub fn get_version() -> String {
|
|
129
|
+
"3.0.0-dual-mode-pqc".to_string()
|
|
130
|
+
}
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "aead"
|
|
7
|
+
version = "0.5.2"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"crypto-common",
|
|
12
|
+
"generic-array",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[[package]]
|
|
16
|
+
name = "aes"
|
|
17
|
+
version = "0.8.4"
|
|
18
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
19
|
+
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"cfg-if",
|
|
22
|
+
"cipher",
|
|
23
|
+
"cpufeatures",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[[package]]
|
|
27
|
+
name = "aes-gcm"
|
|
28
|
+
version = "0.10.3"
|
|
29
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
30
|
+
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
|
|
31
|
+
dependencies = [
|
|
32
|
+
"aead",
|
|
33
|
+
"aes",
|
|
34
|
+
"cipher",
|
|
35
|
+
"ctr",
|
|
36
|
+
"ghash",
|
|
37
|
+
"subtle",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[[package]]
|
|
41
|
+
name = "autocfg"
|
|
42
|
+
version = "1.5.1"
|
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
44
|
+
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
|
45
|
+
|
|
46
|
+
[[package]]
|
|
47
|
+
name = "base64"
|
|
48
|
+
version = "0.21.7"
|
|
49
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
50
|
+
checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567"
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "bitflags"
|
|
54
|
+
version = "2.13.0"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8"
|
|
57
|
+
|
|
58
|
+
[[package]]
|
|
59
|
+
name = "cfg-if"
|
|
60
|
+
version = "1.0.4"
|
|
61
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
62
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
63
|
+
|
|
64
|
+
[[package]]
|
|
65
|
+
name = "cipher"
|
|
66
|
+
version = "0.4.4"
|
|
67
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
68
|
+
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
|
|
69
|
+
dependencies = [
|
|
70
|
+
"crypto-common",
|
|
71
|
+
"inout",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[[package]]
|
|
75
|
+
name = "cpufeatures"
|
|
76
|
+
version = "0.2.17"
|
|
77
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
78
|
+
checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280"
|
|
79
|
+
dependencies = [
|
|
80
|
+
"libc",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[[package]]
|
|
84
|
+
name = "crypto-common"
|
|
85
|
+
version = "0.1.7"
|
|
86
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
+
checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"generic-array",
|
|
90
|
+
"rand_core",
|
|
91
|
+
"typenum",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[[package]]
|
|
95
|
+
name = "ctr"
|
|
96
|
+
version = "0.9.2"
|
|
97
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
98
|
+
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
|
|
99
|
+
dependencies = [
|
|
100
|
+
"cipher",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "generic-array"
|
|
105
|
+
version = "0.14.7"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"typenum",
|
|
110
|
+
"version_check",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[[package]]
|
|
114
|
+
name = "getrandom"
|
|
115
|
+
version = "0.2.17"
|
|
116
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
117
|
+
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
|
118
|
+
dependencies = [
|
|
119
|
+
"cfg-if",
|
|
120
|
+
"libc",
|
|
121
|
+
"wasi",
|
|
122
|
+
]
|
|
123
|
+
|
|
124
|
+
[[package]]
|
|
125
|
+
name = "ghash"
|
|
126
|
+
version = "0.5.1"
|
|
127
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
128
|
+
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
|
|
129
|
+
dependencies = [
|
|
130
|
+
"opaque-debug",
|
|
131
|
+
"polyval",
|
|
132
|
+
]
|
|
133
|
+
|
|
134
|
+
[[package]]
|
|
135
|
+
name = "heck"
|
|
136
|
+
version = "0.4.1"
|
|
137
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
138
|
+
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
|
139
|
+
|
|
140
|
+
[[package]]
|
|
141
|
+
name = "indoc"
|
|
142
|
+
version = "2.0.7"
|
|
143
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
144
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
145
|
+
dependencies = [
|
|
146
|
+
"rustversion",
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
[[package]]
|
|
150
|
+
name = "inout"
|
|
151
|
+
version = "0.1.4"
|
|
152
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
153
|
+
checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
|
|
154
|
+
dependencies = [
|
|
155
|
+
"generic-array",
|
|
156
|
+
]
|
|
157
|
+
|
|
158
|
+
[[package]]
|
|
159
|
+
name = "libc"
|
|
160
|
+
version = "0.2.186"
|
|
161
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
162
|
+
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
|
163
|
+
|
|
164
|
+
[[package]]
|
|
165
|
+
name = "lock_api"
|
|
166
|
+
version = "0.4.14"
|
|
167
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
168
|
+
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
|
|
169
|
+
dependencies = [
|
|
170
|
+
"scopeguard",
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
[[package]]
|
|
174
|
+
name = "memoffset"
|
|
175
|
+
version = "0.9.1"
|
|
176
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
177
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
178
|
+
dependencies = [
|
|
179
|
+
"autocfg",
|
|
180
|
+
]
|
|
181
|
+
|
|
182
|
+
[[package]]
|
|
183
|
+
name = "once_cell"
|
|
184
|
+
version = "1.21.4"
|
|
185
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
186
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
187
|
+
|
|
188
|
+
[[package]]
|
|
189
|
+
name = "opaque-debug"
|
|
190
|
+
version = "0.3.1"
|
|
191
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
192
|
+
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
|
|
193
|
+
|
|
194
|
+
[[package]]
|
|
195
|
+
name = "parking_lot"
|
|
196
|
+
version = "0.12.5"
|
|
197
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
198
|
+
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
|
|
199
|
+
dependencies = [
|
|
200
|
+
"lock_api",
|
|
201
|
+
"parking_lot_core",
|
|
202
|
+
]
|
|
203
|
+
|
|
204
|
+
[[package]]
|
|
205
|
+
name = "parking_lot_core"
|
|
206
|
+
version = "0.9.12"
|
|
207
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
208
|
+
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
|
|
209
|
+
dependencies = [
|
|
210
|
+
"cfg-if",
|
|
211
|
+
"libc",
|
|
212
|
+
"redox_syscall",
|
|
213
|
+
"smallvec",
|
|
214
|
+
"windows-link",
|
|
215
|
+
]
|
|
216
|
+
|
|
217
|
+
[[package]]
|
|
218
|
+
name = "polyval"
|
|
219
|
+
version = "0.6.2"
|
|
220
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
221
|
+
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
|
|
222
|
+
dependencies = [
|
|
223
|
+
"cfg-if",
|
|
224
|
+
"cpufeatures",
|
|
225
|
+
"opaque-debug",
|
|
226
|
+
"universal-hash",
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
[[package]]
|
|
230
|
+
name = "portable-atomic"
|
|
231
|
+
version = "1.13.1"
|
|
232
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
233
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
234
|
+
|
|
235
|
+
[[package]]
|
|
236
|
+
name = "ppv-lite86"
|
|
237
|
+
version = "0.2.21"
|
|
238
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
239
|
+
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
|
240
|
+
dependencies = [
|
|
241
|
+
"zerocopy",
|
|
242
|
+
]
|
|
243
|
+
|
|
244
|
+
[[package]]
|
|
245
|
+
name = "pqc_kyber"
|
|
246
|
+
version = "0.7.1"
|
|
247
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
248
|
+
checksum = "1b23e1823e8a78ad67990c5cb843d5eba75ab3b8a44d041f3814fde89463dc6f"
|
|
249
|
+
dependencies = [
|
|
250
|
+
"rand_core",
|
|
251
|
+
]
|
|
252
|
+
|
|
253
|
+
[[package]]
|
|
254
|
+
name = "proc-macro2"
|
|
255
|
+
version = "1.0.106"
|
|
256
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
257
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
258
|
+
dependencies = [
|
|
259
|
+
"unicode-ident",
|
|
260
|
+
]
|
|
261
|
+
|
|
262
|
+
[[package]]
|
|
263
|
+
name = "pyo3"
|
|
264
|
+
version = "0.20.3"
|
|
265
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
266
|
+
checksum = "53bdbb96d49157e65d45cc287af5f32ffadd5f4761438b527b055fb0d4bb8233"
|
|
267
|
+
dependencies = [
|
|
268
|
+
"cfg-if",
|
|
269
|
+
"indoc",
|
|
270
|
+
"libc",
|
|
271
|
+
"memoffset",
|
|
272
|
+
"parking_lot",
|
|
273
|
+
"portable-atomic",
|
|
274
|
+
"pyo3-build-config",
|
|
275
|
+
"pyo3-ffi",
|
|
276
|
+
"pyo3-macros",
|
|
277
|
+
"unindent",
|
|
278
|
+
]
|
|
279
|
+
|
|
280
|
+
[[package]]
|
|
281
|
+
name = "pyo3-build-config"
|
|
282
|
+
version = "0.20.3"
|
|
283
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
284
|
+
checksum = "deaa5745de3f5231ce10517a1f5dd97d53e5a2fd77aa6b5842292085831d48d7"
|
|
285
|
+
dependencies = [
|
|
286
|
+
"once_cell",
|
|
287
|
+
"target-lexicon",
|
|
288
|
+
]
|
|
289
|
+
|
|
290
|
+
[[package]]
|
|
291
|
+
name = "pyo3-ffi"
|
|
292
|
+
version = "0.20.3"
|
|
293
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
294
|
+
checksum = "62b42531d03e08d4ef1f6e85a2ed422eb678b8cd62b762e53891c05faf0d4afa"
|
|
295
|
+
dependencies = [
|
|
296
|
+
"libc",
|
|
297
|
+
"pyo3-build-config",
|
|
298
|
+
]
|
|
299
|
+
|
|
300
|
+
[[package]]
|
|
301
|
+
name = "pyo3-macros"
|
|
302
|
+
version = "0.20.3"
|
|
303
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
304
|
+
checksum = "7305c720fa01b8055ec95e484a6eca7a83c841267f0dd5280f0c8b8551d2c158"
|
|
305
|
+
dependencies = [
|
|
306
|
+
"proc-macro2",
|
|
307
|
+
"pyo3-macros-backend",
|
|
308
|
+
"quote",
|
|
309
|
+
"syn",
|
|
310
|
+
]
|
|
311
|
+
|
|
312
|
+
[[package]]
|
|
313
|
+
name = "pyo3-macros-backend"
|
|
314
|
+
version = "0.20.3"
|
|
315
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
316
|
+
checksum = "7c7e9b68bb9c3149c5b0cade5d07f953d6d125eb4337723c4ccdb665f1f96185"
|
|
317
|
+
dependencies = [
|
|
318
|
+
"heck",
|
|
319
|
+
"proc-macro2",
|
|
320
|
+
"pyo3-build-config",
|
|
321
|
+
"quote",
|
|
322
|
+
"syn",
|
|
323
|
+
]
|
|
324
|
+
|
|
325
|
+
[[package]]
|
|
326
|
+
name = "quantacipher-core"
|
|
327
|
+
version = "0.1.0"
|
|
328
|
+
dependencies = [
|
|
329
|
+
"aes-gcm",
|
|
330
|
+
"base64",
|
|
331
|
+
"pqc_kyber",
|
|
332
|
+
"rand",
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
[[package]]
|
|
336
|
+
name = "quantacipher-python"
|
|
337
|
+
version = "0.1.1"
|
|
338
|
+
dependencies = [
|
|
339
|
+
"pyo3",
|
|
340
|
+
"quantacipher-core",
|
|
341
|
+
]
|
|
342
|
+
|
|
343
|
+
[[package]]
|
|
344
|
+
name = "quote"
|
|
345
|
+
version = "1.0.45"
|
|
346
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
347
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
348
|
+
dependencies = [
|
|
349
|
+
"proc-macro2",
|
|
350
|
+
]
|
|
351
|
+
|
|
352
|
+
[[package]]
|
|
353
|
+
name = "rand"
|
|
354
|
+
version = "0.8.6"
|
|
355
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
356
|
+
checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a"
|
|
357
|
+
dependencies = [
|
|
358
|
+
"libc",
|
|
359
|
+
"rand_chacha",
|
|
360
|
+
"rand_core",
|
|
361
|
+
]
|
|
362
|
+
|
|
363
|
+
[[package]]
|
|
364
|
+
name = "rand_chacha"
|
|
365
|
+
version = "0.3.1"
|
|
366
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
367
|
+
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
368
|
+
dependencies = [
|
|
369
|
+
"ppv-lite86",
|
|
370
|
+
"rand_core",
|
|
371
|
+
]
|
|
372
|
+
|
|
373
|
+
[[package]]
|
|
374
|
+
name = "rand_core"
|
|
375
|
+
version = "0.6.4"
|
|
376
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
377
|
+
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
|
378
|
+
dependencies = [
|
|
379
|
+
"getrandom",
|
|
380
|
+
]
|
|
381
|
+
|
|
382
|
+
[[package]]
|
|
383
|
+
name = "redox_syscall"
|
|
384
|
+
version = "0.5.18"
|
|
385
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
386
|
+
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
|
|
387
|
+
dependencies = [
|
|
388
|
+
"bitflags",
|
|
389
|
+
]
|
|
390
|
+
|
|
391
|
+
[[package]]
|
|
392
|
+
name = "rustversion"
|
|
393
|
+
version = "1.0.22"
|
|
394
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
395
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
396
|
+
|
|
397
|
+
[[package]]
|
|
398
|
+
name = "scopeguard"
|
|
399
|
+
version = "1.2.0"
|
|
400
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
401
|
+
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
|
402
|
+
|
|
403
|
+
[[package]]
|
|
404
|
+
name = "smallvec"
|
|
405
|
+
version = "1.15.2"
|
|
406
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
407
|
+
checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90"
|
|
408
|
+
|
|
409
|
+
[[package]]
|
|
410
|
+
name = "subtle"
|
|
411
|
+
version = "2.6.1"
|
|
412
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
413
|
+
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
|
414
|
+
|
|
415
|
+
[[package]]
|
|
416
|
+
name = "syn"
|
|
417
|
+
version = "2.0.118"
|
|
418
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
419
|
+
checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
|
|
420
|
+
dependencies = [
|
|
421
|
+
"proc-macro2",
|
|
422
|
+
"quote",
|
|
423
|
+
"unicode-ident",
|
|
424
|
+
]
|
|
425
|
+
|
|
426
|
+
[[package]]
|
|
427
|
+
name = "target-lexicon"
|
|
428
|
+
version = "0.12.16"
|
|
429
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
430
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
431
|
+
|
|
432
|
+
[[package]]
|
|
433
|
+
name = "typenum"
|
|
434
|
+
version = "1.20.1"
|
|
435
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
436
|
+
checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
|
|
437
|
+
|
|
438
|
+
[[package]]
|
|
439
|
+
name = "unicode-ident"
|
|
440
|
+
version = "1.0.24"
|
|
441
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
442
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
443
|
+
|
|
444
|
+
[[package]]
|
|
445
|
+
name = "unindent"
|
|
446
|
+
version = "0.2.4"
|
|
447
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
448
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
449
|
+
|
|
450
|
+
[[package]]
|
|
451
|
+
name = "universal-hash"
|
|
452
|
+
version = "0.5.1"
|
|
453
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
454
|
+
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
|
|
455
|
+
dependencies = [
|
|
456
|
+
"crypto-common",
|
|
457
|
+
"subtle",
|
|
458
|
+
]
|
|
459
|
+
|
|
460
|
+
[[package]]
|
|
461
|
+
name = "version_check"
|
|
462
|
+
version = "0.9.5"
|
|
463
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
464
|
+
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
|
465
|
+
|
|
466
|
+
[[package]]
|
|
467
|
+
name = "wasi"
|
|
468
|
+
version = "0.11.1+wasi-snapshot-preview1"
|
|
469
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
470
|
+
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
471
|
+
|
|
472
|
+
[[package]]
|
|
473
|
+
name = "windows-link"
|
|
474
|
+
version = "0.2.1"
|
|
475
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
476
|
+
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
477
|
+
|
|
478
|
+
[[package]]
|
|
479
|
+
name = "zerocopy"
|
|
480
|
+
version = "0.8.52"
|
|
481
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
482
|
+
checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f"
|
|
483
|
+
dependencies = [
|
|
484
|
+
"zerocopy-derive",
|
|
485
|
+
]
|
|
486
|
+
|
|
487
|
+
[[package]]
|
|
488
|
+
name = "zerocopy-derive"
|
|
489
|
+
version = "0.8.52"
|
|
490
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
491
|
+
checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930"
|
|
492
|
+
dependencies = [
|
|
493
|
+
"proc-macro2",
|
|
494
|
+
"quote",
|
|
495
|
+
"syn",
|
|
496
|
+
]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "quantacipher-python"
|
|
3
|
+
version = "0.1.1"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
description = "Zero-trust PQC (Kyber) encryption Python bindings"
|
|
6
|
+
repository = "https://github.com/xaexaex/quantacipher"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
authors = ["QuantaLabs"]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
|
|
11
|
+
[lib]
|
|
12
|
+
name = "_quantacipher_core"
|
|
13
|
+
crate-type = ["cdylib"]
|
|
14
|
+
|
|
15
|
+
[dependencies]
|
|
16
|
+
pyo3 = { version = "0.20", features = ["extension-module"] }
|
|
17
|
+
quantacipher-core = { path = "../quantacipher-core" }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# QuantaCipher
|
|
2
|
+
|
|
3
|
+
Zero-Trust Post-Quantum Cryptography library for Python.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install quantacipher
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commercial & Enterprise Use
|
|
12
|
+
To manage API keys, audit logs, and scale your cryptography, check out our Enterprise SaaS Platform at https://quantacipher.com.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import time
|
|
2
|
+
import requests
|
|
3
|
+
import _quantacipher_core
|
|
4
|
+
|
|
5
|
+
def generate_keypair():
|
|
6
|
+
"""Generates a Kyber-1024 keypair (raw core function)"""
|
|
7
|
+
return _quantacipher_core.generate_keypair()
|
|
8
|
+
|
|
9
|
+
def vault_encrypt(plaintext: str) -> str:
|
|
10
|
+
"""Encrypts in vault mode (raw core function)"""
|
|
11
|
+
return _quantacipher_core.vault_encrypt(plaintext)
|
|
12
|
+
|
|
13
|
+
def secure_encrypt(plaintext: str, public_key_b64: str) -> str:
|
|
14
|
+
"""Encrypts in secure mode (raw core function)"""
|
|
15
|
+
return _quantacipher_core.secure_encrypt(plaintext, public_key_b64)
|
|
16
|
+
|
|
17
|
+
def secure_decrypt(ciphertext_payload: str, private_key_b64: str) -> str:
|
|
18
|
+
"""Decrypts secure mode payload (raw core function)"""
|
|
19
|
+
return _quantacipher_core.secure_decrypt(ciphertext_payload, private_key_b64)
|
|
20
|
+
|
|
21
|
+
def get_version() -> str:
|
|
22
|
+
return _quantacipher_core.get_version()
|
|
23
|
+
|
|
24
|
+
class QuantaCipher:
|
|
25
|
+
"""
|
|
26
|
+
QuantaCipher SDK Client
|
|
27
|
+
Provides zero-trust encryption and automatic Gateway integration.
|
|
28
|
+
"""
|
|
29
|
+
def __init__(self, api_key: str, gateway_url: str = 'http://localhost:4000/api/v1/ingest'):
|
|
30
|
+
self.api_key = api_key
|
|
31
|
+
self.gateway_url = gateway_url
|
|
32
|
+
|
|
33
|
+
def generate_keypair(self) -> dict:
|
|
34
|
+
"""
|
|
35
|
+
Generates a Kyber-1024 keypair locally.
|
|
36
|
+
The private key NEVER leaves this call.
|
|
37
|
+
"""
|
|
38
|
+
return _quantacipher_core.generate_keypair()
|
|
39
|
+
|
|
40
|
+
def encrypt_vault(self, plaintext: str) -> str:
|
|
41
|
+
"""
|
|
42
|
+
VAULT MODE: Encrypts data using an ephemeral Kyber-1024 keypair locally.
|
|
43
|
+
"""
|
|
44
|
+
print(f"[QuantaCipher SDK v{get_version()}] VAULT MODE: Sealing with ephemeral Kyber-1024...")
|
|
45
|
+
return _quantacipher_core.vault_encrypt(plaintext)
|
|
46
|
+
|
|
47
|
+
def vault_data(self, plaintext: str, metadata: dict = None) -> dict:
|
|
48
|
+
"""
|
|
49
|
+
Encrypts in VAULT MODE and sends to the gateway.
|
|
50
|
+
One-liner for permanent zero-trust sealing.
|
|
51
|
+
"""
|
|
52
|
+
ciphertext = self.encrypt_vault(plaintext)
|
|
53
|
+
return self.send_to_gateway(ciphertext, metadata)
|
|
54
|
+
|
|
55
|
+
def encrypt_secure(self, plaintext: str, public_key_b64: str) -> str:
|
|
56
|
+
"""
|
|
57
|
+
SECURE MODE: Encrypts data using the caller's Kyber public key locally.
|
|
58
|
+
"""
|
|
59
|
+
print("[QuantaCipher SDK] SECURE MODE: Encrypting with user public key (Kyber-1024)...")
|
|
60
|
+
return _quantacipher_core.secure_encrypt(plaintext, public_key_b64)
|
|
61
|
+
|
|
62
|
+
def decrypt_secure(self, ciphertext_payload: str, private_key_b64: str) -> str:
|
|
63
|
+
"""
|
|
64
|
+
SECURE MODE: Decrypts locally using the user's PRIVATE key.
|
|
65
|
+
"""
|
|
66
|
+
print("[QuantaCipher SDK] SECURE MODE: Decrypting locally with user private key...")
|
|
67
|
+
return _quantacipher_core.secure_decrypt(ciphertext_payload, private_key_b64)
|
|
68
|
+
|
|
69
|
+
def secure_data(self, plaintext: str, public_key_b64: str, metadata: dict = None) -> dict:
|
|
70
|
+
"""
|
|
71
|
+
Encrypts in SECURE MODE and sends to the gateway.
|
|
72
|
+
Only the user (who holds private_key) can decrypt later.
|
|
73
|
+
"""
|
|
74
|
+
ciphertext = self.encrypt_secure(plaintext, public_key_b64)
|
|
75
|
+
return self.send_to_gateway(ciphertext, metadata)
|
|
76
|
+
|
|
77
|
+
def send_to_gateway(self, ciphertext: str, metadata: dict = None) -> dict:
|
|
78
|
+
"""
|
|
79
|
+
Transmits the Kyber ciphertext to the Gateway to issue a cryptographic receipt.
|
|
80
|
+
"""
|
|
81
|
+
if metadata is None:
|
|
82
|
+
metadata = {}
|
|
83
|
+
|
|
84
|
+
print(f"[QuantaCipher SDK] Tunneling to Gateway → {self.gateway_url}")
|
|
85
|
+
headers = {
|
|
86
|
+
'x-api-key': self.api_key,
|
|
87
|
+
'Content-Type': 'application/json'
|
|
88
|
+
}
|
|
89
|
+
payload = {
|
|
90
|
+
'ciphertext': ciphertext,
|
|
91
|
+
'metadata': metadata,
|
|
92
|
+
'timestamp': int(time.time() * 1000)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
response = requests.post(self.gateway_url, json=payload, headers=headers)
|
|
97
|
+
response.raise_for_status()
|
|
98
|
+
data = response.json()
|
|
99
|
+
return data.get('receipt')
|
|
100
|
+
except requests.exceptions.HTTPError as e:
|
|
101
|
+
error_msg = f"HTTP {response.status_code}"
|
|
102
|
+
try:
|
|
103
|
+
err_data = response.json()
|
|
104
|
+
error_msg = err_data.get('error', err_data.get('message', error_msg))
|
|
105
|
+
except Exception:
|
|
106
|
+
pass
|
|
107
|
+
raise Exception(f"QuantaCipher Gateway Error: {error_msg}")
|
|
108
|
+
except Exception as e:
|
|
109
|
+
raise Exception(f"QuantaCipher Network Error: {str(e)}")
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
use pyo3::prelude::*;
|
|
2
|
+
use pyo3::exceptions::PyValueError;
|
|
3
|
+
use quantacipher_core::{
|
|
4
|
+
generate_keypair as core_generate_keypair,
|
|
5
|
+
vault_encrypt as core_vault_encrypt,
|
|
6
|
+
secure_encrypt as core_secure_encrypt,
|
|
7
|
+
secure_decrypt as core_secure_decrypt,
|
|
8
|
+
get_version as core_get_version,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/// Generates a keypair and returns it as a dictionary
|
|
12
|
+
#[pyfunction]
|
|
13
|
+
fn generate_keypair() -> PyResult<PyObject> {
|
|
14
|
+
let (public, private) = core_generate_keypair()
|
|
15
|
+
.map_err(|e| PyValueError::new_err(format!("QuantaCipher Error: {}", e)))?;
|
|
16
|
+
|
|
17
|
+
Python::with_gil(|py| {
|
|
18
|
+
let dict = pyo3::types::PyDict::new(py);
|
|
19
|
+
dict.set_item("publicKey", public)?;
|
|
20
|
+
dict.set_item("privateKey", private)?;
|
|
21
|
+
dict.set_item("algorithm", "Kyber-1024")?;
|
|
22
|
+
dict.set_item("version", "1.0")?;
|
|
23
|
+
Ok(dict.into())
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Vault encrypt
|
|
28
|
+
#[pyfunction]
|
|
29
|
+
fn vault_encrypt(plaintext: &str) -> PyResult<String> {
|
|
30
|
+
core_vault_encrypt(plaintext)
|
|
31
|
+
.map_err(|e| PyValueError::new_err(format!("QuantaCipher Error: {}", e)))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// Secure encrypt
|
|
35
|
+
#[pyfunction]
|
|
36
|
+
fn secure_encrypt(plaintext: &str, public_key_b64: &str) -> PyResult<String> {
|
|
37
|
+
core_secure_encrypt(plaintext, public_key_b64)
|
|
38
|
+
.map_err(|e| PyValueError::new_err(format!("QuantaCipher Error: {}", e)))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Secure decrypt
|
|
42
|
+
#[pyfunction]
|
|
43
|
+
fn secure_decrypt(ciphertext_payload: &str, private_key_b64: &str) -> PyResult<String> {
|
|
44
|
+
core_secure_decrypt(ciphertext_payload, private_key_b64)
|
|
45
|
+
.map_err(|e| PyValueError::new_err(format!("QuantaCipher Error: {}", e)))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[pyfunction]
|
|
49
|
+
fn get_version() -> PyResult<String> {
|
|
50
|
+
Ok(core_get_version())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[pymodule]
|
|
54
|
+
fn _quantacipher_core(_py: Python, m: &PyModule) -> PyResult<()> {
|
|
55
|
+
m.add_function(wrap_pyfunction!(generate_keypair, m)?)?;
|
|
56
|
+
m.add_function(wrap_pyfunction!(vault_encrypt, m)?)?;
|
|
57
|
+
m.add_function(wrap_pyfunction!(secure_encrypt, m)?)?;
|
|
58
|
+
m.add_function(wrap_pyfunction!(secure_decrypt, m)?)?;
|
|
59
|
+
m.add_function(wrap_pyfunction!(get_version, m)?)?;
|
|
60
|
+
Ok(())
|
|
61
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from quantacipher import QuantaCipher
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
print("=== QuantaCipher Python SDK Test ===")
|
|
5
|
+
|
|
6
|
+
# 1. Initialize the SDK
|
|
7
|
+
sdk = QuantaCipher(api_key="qz_test_demo123")
|
|
8
|
+
|
|
9
|
+
print("Version:", sdk.generate_keypair()["version"])
|
|
10
|
+
|
|
11
|
+
# 2. Test Secure Mode (Local Encryption & Decryption)
|
|
12
|
+
keys = sdk.generate_keypair()
|
|
13
|
+
print("\n[+] Generated Keypair:")
|
|
14
|
+
print(" PublicKey:", keys["publicKey"][:30] + "...")
|
|
15
|
+
print(" PrivateKey:", keys["privateKey"][:30] + "...")
|
|
16
|
+
|
|
17
|
+
message = "Zero Trust Enterprise Data"
|
|
18
|
+
print("\n[+] Encrypting message in Secure Mode:", message)
|
|
19
|
+
ciphertext = sdk.encrypt_secure(message, keys["publicKey"])
|
|
20
|
+
print(" Ciphertext:", ciphertext[:40] + "...")
|
|
21
|
+
|
|
22
|
+
print("\n[+] Decrypting payload locally...")
|
|
23
|
+
plaintext = sdk.decrypt_secure(ciphertext, keys["privateKey"])
|
|
24
|
+
print(" Decrypted:", plaintext)
|
|
25
|
+
|
|
26
|
+
assert plaintext == message, "Decryption failed!"
|
|
27
|
+
|
|
28
|
+
# 3. Test Vault Mode with Gateway
|
|
29
|
+
print("\n[+] Testing Vault Mode Gateway Integration...")
|
|
30
|
+
try:
|
|
31
|
+
receipt = sdk.vault_data("My highly sensitive compliance data", {"source": "python_test_script"})
|
|
32
|
+
print(" [✔] Gateway Receipt Received!")
|
|
33
|
+
print(" Receipt ID:", receipt["id"])
|
|
34
|
+
print(" Algorithm:", receipt["encryptionScheme"])
|
|
35
|
+
except Exception as e:
|
|
36
|
+
print(" [!] Gateway Test Failed (is the Gateway running on port 4000?):", str(e))
|
|
37
|
+
|
|
38
|
+
print("\n[✔] Python SDK Test Completed!")
|
|
39
|
+
|