Skip to content

Commit 47c0547

Browse files
committed
docs: add cluster key vs secret key
1 parent a7f7c8e commit 47c0547

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

README.rst

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ This library provides cryptographic operations that are compatible with nilDB no
4949
| | | | (prime modulus 2^32 + 15 for both) | |
5050
+-------------+-----------+------------------------------------------+------------------------------+
5151

52+
Key Types and Thresholds
53+
------------------------
54+
The library provides two main types of keys:
55+
56+
1. **SecretKey**: Used for operations within a single node or across multiple nodes. It contains cryptographic material for encryption, decryption, and other operations. The `SecretKey` uses blinding masks, which are held only by the client. This ensures that even if all servers in the cluster collude, the client retains ultimate control over their data.
57+
58+
2. **ClusterKey**: Represents a cluster configuration without cryptographic material. It is used for managing multi-node clusters. Unlike the `SecretKey`, the `ClusterKey` does not use blinding masks, meaning the servers hold shares of the data.
59+
60+
Thresholds are supported for summation operations in multi-node clusters. A threshold specifies the minimum number of nodes required to reconstruct the original data. For example, Shamir's secret sharing is used when a threshold is set, ensuring that data can only be reconstructed if the required number of shares is available.
61+
5262
Installation and Usage
5363
----------------------
5464
The library can be imported in the usual ways:
@@ -58,19 +68,49 @@ The library can be imported in the usual ways:
5868
import nilql
5969
from nilql import *
6070
61-
Example
62-
^^^^^^^^
63-
An example workflow that demonstrates use of the library is presented below:
71+
Examples and Usage
72+
------------------
73+
74+
Generating Keys
75+
^^^^^^^^^^^^^^^
76+
77+
To generate a `SecretKey` for a single-node cluster:
78+
79+
.. code-block:: python
80+
81+
from nilql import SecretKey
82+
83+
cluster = {'nodes': [{}]}
84+
secret_key = SecretKey.generate(cluster, {'store': True})
85+
86+
For a multi-node (e.g., 3) cluster with a threshold:
6487

6588
.. code-block:: python
6689
67-
import nilql
6890
cluster = {'nodes': [{}, {}, {}]}
69-
secret_key = nilql.SecretKey.generate(cluster, {'store': True})
91+
secret_key = SecretKey.generate(cluster, {'sum': True}, threshold=2)
92+
93+
Encrypting and Decrypting Data
94+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
96+
Encrypting and decrypting an integer:
97+
98+
.. code-block:: python
99+
70100
plaintext = 123
71101
ciphertext = nilql.encrypt(secret_key, plaintext)
72102
decrypted = nilql.decrypt(secret_key, ciphertext)
73-
assert(plaintext == decrypted)
103+
assert plaintext == decrypted
104+
105+
Encrypting and decrypting a string:
106+
107+
.. code-block:: python
108+
109+
plaintext = "hello"
110+
ciphertext = nilql.encrypt(secret_key, plaintext)
111+
decrypted = nilql.decrypt(secret_key, ciphertext)
112+
assert plaintext == decrypted
113+
74114
75115
Development
76116
-----------

0 commit comments

Comments
 (0)