Skip to content

Commit e1d2058

Browse files
authored
Merge pull request #137 from MatrixAI/feature-update-reference
Feature update reference, branch renaming
2 parents 29df2ce + dbb619d commit e1d2058

File tree

12 files changed

+848
-4
lines changed

12 files changed

+848
-4
lines changed

docs/reference/architecture.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
### Node ID
44

5-
In order to interact with other nodes, PolyKey uses a unique node ID identifier.
5+
In order to interact with other nodes, Polykey uses a unique node ID identifier.
66
Currently, the fingerprint of the root public key of a keynode is calculated
7-
using a sha256 has function and is then transformed into base64 encoding to
7+
using a SHA256 hash function and is then transformed into base64 encoding to
88
obtain a keynode’s Node ID. This will consistently produce a string of 44
99
characters. In the future, PolyKey will used an ed25519 public key directly
1010
encoded using base64 to create the Node ID. As the signature of ed25519 keys can

docs/reference/architecture/DES.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Symmetric Data Encapsulation Scheme (DES)
2+
3+
Polykey’s state is completely stored in the database. This means everything
4+
critical to the system's function—keys, metadata, and configurations—is written
5+
to disk. To ensure the security and integrity of this data, we encrypt the
6+
database using a **32-byte Data Encryption Key (DB Key)** and the
7+
**XChaCha20-Poly1305** symmetric encryption algorithm, provided by
8+
**libsodium**.
9+
10+
## Why We Use Symmetric Encryption
11+
12+
Encryption is non-negotiable for a system like Polykey, where data security is a
13+
core priority. Symmetric encryption is used for:
14+
15+
- **Confidentiality** - Ensuring database contents are only accessible to the
16+
rightful owner.
17+
- **Integrity** - Preventing unauthorized tampering by detecting any
18+
modifications.
19+
- **Performance** - Symmetric encryption is significantly faster than asymmetric
20+
encryption for large datasets.
21+
22+
## Database Encryption Key (DB Key)
23+
24+
### **How the DB Key Works**
25+
26+
The DB Key is a **randomly generated 32-byte key** that encrypts all database
27+
content. This key is stored on disk, but never in plaintext—it is always
28+
encrypted before being written to storage.
29+
30+
The DB Key is used to encrypt and decrypt the entire database, meaning that
31+
without it, **all data in the system is inaccessible**.
32+
33+
### **Why the DB Key is Not Derived from the Root Key**
34+
35+
A common approach in cryptographic systems is to derive all keys from a single
36+
root key. However, this is not how Polykey manages database encryption. The DB
37+
Key is independent from the root key for the following reasons:
38+
39+
1. **Key Rotation & Flexibility**
40+
If the root key were used to derive the DB Key, changing the root key would
41+
require re-encrypting the entire database. This would be a **catastrophic**
42+
operation in terms of efficiency and usability. Instead, by keeping the DB
43+
Key separate, the database can remain encrypted even when the root key is
44+
changed.
45+
46+
2. **Minimizing Attack Surfaces**
47+
If an attacker compromises the root key, they still cannot access the
48+
database contents without the DB Key. This adds an extra layer of security.
49+
50+
3. **Persistence Across Keypair Changes**
51+
In Polykey, root keypairs can be swapped out periodically for security
52+
reasons (like how passwords should be rotated). By decoupling the DB Key, the
53+
database encryption remains stable across key rotations.
54+
55+
## Encryption Algorithm: XChaCha20-Poly1305
56+
57+
Polykey uses **XChaCha20-Poly1305**, a widely respected symmetric encryption
58+
scheme known for its:
59+
60+
- **256-bit key size** - Strong encryption without performance tradeoffs.
61+
- **192-bit nonce** - Ensures nonce reuse attacks are virtually impossible.
62+
- **Authenticated encryption** - Includes integrity checks, so any unauthorized
63+
modifications are detected.
64+
65+
### **Why XChaCha20-Poly1305?**
66+
67+
1. **Nonce Misuse Resistance**
68+
Unlike AES-GCM, which has strict nonce reuse requirements, XChaCha20 allows
69+
for random nonce generation with no risk of catastrophic failures.
70+
71+
2. **High Performance**
72+
Stream ciphers like XChaCha20 are significantly faster than block ciphers
73+
like AES in many scenarios, making them well-suited for encrypting large
74+
datasets.
75+
76+
3. **Compatibility with Libsodium**
77+
Libsodium is a battle-tested cryptographic library that provides a simple and
78+
secure implementation of XChaCha20-Poly1305, reducing the risk of
79+
implementation errors.
80+
81+
## Key Rotation & Secure Storage
82+
83+
### **Key Rotation Strategy**
84+
85+
Regular key rotation is a fundamental security practice. However, since
86+
re-encrypting an entire database is computationally expensive, Polykey manages
87+
key rotations in a way that minimizes disruption:
88+
89+
1. **The DB Key is swapped periodically** - This reduces long-term key exposure.
90+
2. **New keys are securely generated and encrypted using KEM (Key Encapsulation
91+
Mechanism)** - This ensures a smooth transition without exposing old
92+
encrypted data.
93+
3. **Polykey handles the transition automatically** - Users do not need to worry
94+
about database re-encryption when keypairs are rotated.
95+
96+
### **How the DB Key is Stored**
97+
98+
The DB Key is **never stored in plaintext**. Instead, it is encrypted and saved
99+
as a **JWE (JSON Web Encryption) file**. This file is securely managed to ensure
100+
that only authorized nodes can decrypt and use it.
101+
102+
## Security Considerations
103+
104+
- **Loss of the DB Key = Complete Data Loss**
105+
If the encrypted DB Key is lost, **all data within Polykey is permanently
106+
inaccessible**. Users must ensure backups are properly managed.
107+
108+
- **Frequent Key Rotation is Good Practice**
109+
Regularly rotating the DB Key prevents long-term exposure and mitigates risks
110+
from potential future cryptographic weaknesses.
111+
112+
- **Secure Backup Management is Critical**
113+
Since Polykey does not store plaintext recovery keys, **users must securely
114+
back up their 24-word recovery code** to ensure they can regain access if
115+
needed.
116+
117+
## Conclusion
118+
119+
The **Symmetric Data Encapsulation Scheme (DES)** is a critical component of
120+
Polykey's security model. By leveraging XChaCha20-Poly1305 for high-speed
121+
encryption and ensuring the **DB Key remains independent from the root key**,
122+
Polykey maintains a **balance between security, performance, and usability**.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import DocCardList from '@theme/DocCardList';
2+
3+
# Architecture
4+
5+
<DocCardList />
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Elliptic Curve Integrated Encryption Scheme (ECIES)
2+
3+
## Overview
4+
5+
Polykey's security model is built around **Elliptic Curve Integrated Encryption
6+
Scheme (ECIES)**. ECIES is a hybrid cryptosystem that combines the efficiency of
7+
symmetric encryption with the security of asymmetric encryption, making it ideal
8+
for key exchange and encrypted communication.
9+
10+
At its core, ECIES allows secure communication between parties without requiring
11+
them to share a secret key in advance. Instead, it uses elliptic curve
12+
cryptography (ECC) to derive a shared secret dynamically, ensuring both
13+
confidentiality and authenticity.
14+
15+
## Why Polykey Uses ECIES
16+
17+
Polykey leverages ECIES because it provides:
18+
19+
- **Strong security**: ECC-based key exchange ensures forward secrecy.
20+
- **Efficient performance**: ECC is computationally faster than RSA at
21+
equivalent security levels.
22+
- **Hybrid encryption**: Uses symmetric encryption for bulk data and asymmetric
23+
encryption for key exchange.
24+
- **Secure key encapsulation**: Keys are encrypted in a way that prevents
25+
exposure during transmission.
26+
27+
## How ECIES Works
28+
29+
ECIES works by using Elliptic Curve Diffie-Hellman (ECDH) for key exchange and a
30+
symmetric cipher for encryption.
31+
32+
The encryption process follows these steps:
33+
34+
1. **Key Exchange**:
35+
36+
- The sender generates a temporary ephemeral key pair.
37+
- The sender derives a shared secret using their ephemeral private key and the
38+
recipient's public key.
39+
40+
2. **Key Derivation**:
41+
42+
- The shared secret is used to generate encryption keys through a Key Derivation
43+
Function (KDF).
44+
45+
3. **Encryption**:
46+
47+
- A symmetric encryption algorithm (e.g., XChaCha20-Poly1305 ) encrypts the
48+
plaintext.
49+
- An authentication tag is generated to prevent tampering.
50+
51+
4. **Transmission**:
52+
53+
- The ciphertext, ephemeral public key, and authentication tag are sent to the
54+
recipient.
55+
56+
5. **Decryption**:
57+
58+
- The recipient uses their private key to derive the shared secret.
59+
- The symmetric key is reconstructed using the same KDF.
60+
- The ciphertext is decrypted, and authenticity is verified.
61+
62+
## ECIES in Polykey
63+
64+
Polykey uses ECIES as the foundation for secure communication, storage, and key
65+
management. Specifically, it is used for:
66+
67+
- **Key Encapsulation Mechanism (KEM)**: Encapsulating encryption keys for
68+
secure storage.
69+
- **Node-to-Node Communication**: Establishing secure tunnels between Polykey
70+
nodes.
71+
- **Key Exchange**: Securely transferring symmetric encryption keys for
72+
encrypted storage.
73+
74+
### Key Encapsulation and Secure Storage
75+
76+
Polykey encrypts sensitive keys using ECIES-based encapsulation. This means:
77+
78+
- The Data Encryption Key (DB Key) is never stored in plaintext.
79+
- The DB Key is wrapped using ECIES before being saved.
80+
- Only an authenticated node with the correct private key can unwrap the DB Key
81+
and decrypt the database.
82+
83+
### Secure Messaging Between Nodes
84+
85+
When Polykey nodes communicate, they exchange keys using ECIES. This allows them
86+
to:
87+
88+
- Establish a secure session without pre-sharing a secret key.
89+
- Prevent man-in-the-middle attacks by ensuring only authorized nodes can
90+
decrypt messages.
91+
- Authenticate each other using their public-private key pairs.
92+
93+
## Why ECIES is Preferred Over RSA
94+
95+
Historically, RSA-based encryption was the standard for key exchange, but ECIES
96+
provides several advantages:
97+
98+
| Feature | ECIES (ECC) | RSA |
99+
| ------------------- | ----------- | ----------------------------- |
100+
| **Key Size (bits)** | 256 | 2048 |
101+
| **Security Level** | Stronger | Weaker at equivalent key size |
102+
| **Performance** | Faster | Slower |
103+
| **Key Exchange** | Supported | Not ideal for key exchange |
104+
105+
Because ECIES achieves the same level of security as RSA with much smaller key
106+
sizes, it is the preferred choice for modern cryptographic systems like Polykey.
107+
108+
## Future-Proofing Against Quantum Attacks
109+
110+
Polykey is designed to evolve with cryptographic advancements. While ECIES is
111+
secure today, quantum computers could potentially break ECC in the future. When
112+
quantum-resistant encryption becomes practical, Polykey will migrate to a
113+
Post-Quantum Integrated Encryption Scheme (PQIES).
114+
115+
## Conclusion
116+
117+
ECIES is at the heart of Polykey's encryption model, providing secure,
118+
efficient, and scalable key exchange. By combining elliptic curve cryptography
119+
with hybrid encryption techniques, Polykey ensures strong security, efficient
120+
performance, and forward secrecy.
121+
122+
Polykey's implementation of ECIES allows:
123+
124+
- Secure key exchange without pre-shared secrets.
125+
- Confidential and authenticated communication between nodes.
126+
- Safe and efficient key storage using encapsulated encryption.
127+
128+
As cryptographic standards evolve, Polykey remains committed to using the most
129+
secure and performant encryption schemes available.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Encryption Algorithms and Security Considerations
2+
3+
## Overview
4+
5+
Polykey's security model is built on modern cryptographic principles to ensure
6+
confidentiality, integrity, and authentication across all operations. This
7+
document outlines the encryption algorithms Polykey employs, their strengths,
8+
and key security considerations for maintaining a secure system.
9+
10+
## Encryption Algorithms Used in Polykey
11+
12+
Polykey integrates a hybrid cryptosystem, combining symmetric and asymmetric
13+
cryptographic algorithms for optimal security and performance.
14+
15+
### Symmetric Encryption
16+
17+
- **AES-GCM (Advanced Encryption Standard - Galois/Counter Mode)**
18+
- Used for encrypting data at rest and in transit.
19+
- Provides both encryption and authentication in a single step.
20+
- 256-bit key length for strong security.
21+
- Resistant to padding oracle attacks due to its authenticated encryption
22+
structure.
23+
24+
### Asymmetric Encryption
25+
26+
- **X25519 (Elliptic Curve Diffie-Hellman)**
27+
28+
- Used for key exchange and secure session establishment.
29+
- Based on Curve25519, which is efficient and resistant to side-channel
30+
attacks.
31+
- Provides forward secrecy by generating ephemeral session keys.
32+
33+
- **Ed25519 (Elliptic Curve Digital Signature Algorithm)**
34+
- Used for signing and verifying messages and transactions.
35+
- Strong resistance to side-channel attacks.
36+
- Deterministic signatures prevent nonce-related vulnerabilities.
37+
38+
### Key Encapsulation Mechanism (KEM)
39+
40+
- **ECIES (Elliptic Curve Integrated Encryption Scheme)**
41+
- Facilitates secure encryption of symmetric keys during key exchange.
42+
- Uses elliptic curve cryptography for efficient and secure key wrapping.
43+
- Ensures confidentiality and authenticity of the exchanged key.
44+
45+
## Security Considerations
46+
47+
### 1. Key Management
48+
49+
- **Recovery Codes:** Users must securely store their 24-word recovery code, as
50+
Polykey does not store private keys.
51+
- **Key Rotation:** Regular key rotation mitigates the risk of long-term key
52+
exposure.
53+
- **Secure Storage:** Encrypted key material must be stored in a secure
54+
environment to prevent unauthorized access.
55+
56+
### 2. Forward Secrecy
57+
58+
- Polykey ensures forward secrecy through ephemeral key exchange using X25519.
59+
- If a private key is compromised, past communications remain secure.
60+
61+
### 3. Authentication & Integrity
62+
63+
- Digital signatures (Ed25519) ensure data authenticity and prevent tampering.
64+
- Authenticated encryption (AES-GCM) guarantees data integrity.
65+
66+
### 4. Resistance to Quantum Threats
67+
68+
- While current encryption methods are secure, future quantum computing
69+
advancements may break classical cryptography.
70+
- Polykey's roadmap includes exploring post-quantum cryptographic alternatives.
71+
72+
### 5. Attack Surface Reduction
73+
74+
- Minimizing reliance on outdated cryptographic algorithms.
75+
- Eliminating common cryptographic pitfalls such as RSA-based key exchanges,
76+
which are vulnerable to decryption with modern computing power.
77+
78+
## Conclusion
79+
80+
Polykey employs a combination of AES-GCM, X25519, Ed25519, and ECIES to ensure
81+
strong security across all cryptographic operations. By following best practices
82+
in key management, forward secrecy, and attack surface reduction, Polykey
83+
maintains a robust security posture. Future updates may incorporate post-quantum
84+
cryptographic schemes to address emerging threats.

0 commit comments

Comments
 (0)