You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix various inconsistencies in OU implementation (#6)
* Fix various inconsistencies in OU implementation
Critical: enforce m < p plaintext bound (not m < n); remove Ciphertext::Mul
which was missing mod n reduction; fix stream format to preserve leading-zero
bytes and distinguish empty from zero plaintext.
Security: validate gcd(r,n)=1 for encryption nonce; privatize PrivateKey
fields; replace safe prime generation with standard primes (not required by
OU, 473x slower at 2048 bits); migrate decryption modpow to crypto-bigint
BoxedMontyForm for constant-time exponentiation.
Correctness: add gcd(g,n)=1 generator check; precompute l_gp_inv and p²
in PrivateKey, eliminating runtime mod_inverse and repeated p² allocation;
add Plaintext type with checked_add to surface homomorphic overflow.
API: remove Ciphertext::Deref and unvalidated From<&[u8]>; replace glob
re-exports with explicit items; cap untrusted block_count at 4M; extract
parse_blocks(); make homomorphic_add_packed pub.
* Fix cargo clippy errors
* Remove unnecessary cast to usize
Copy file name to clipboardExpand all lines: README.md
+67-25Lines changed: 67 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,53 +1,99 @@
1
1
# Okuchi
2
2
3
-
A pure Rust implementation of the **Okamoto–Uchiyama** cryptosystem - a probabilistic public-key scheme whose security relies on the hardness of factoring and discrete logarithms modulo a composite number.
3
+
A pure-Rust implementation of the **Okamoto-Uchiyama (OU)** cryptosystem: a
4
+
probabilistic public-key encryption scheme with additive homomorphism, whose
5
+
security relies on the hardness of factoring `n = p²q` and computing discrete
6
+
logarithms modulo `p²`.
4
7
5
8
**Okuchi** is a portmanteau of **Ok**amoto and **Uchi**yama.
6
9
10
+
---
11
+
7
12
## ⚠️ Important Notice
8
13
9
-
The project is evolving and should be treated as a **work in progress**.
10
-
Breaking changes, redesigns, or API removals may occur without notice.
14
+
This implementation is **experimental**, **incomplete**, and **not audited** by
15
+
any external security professionals. It may contain defects, conceptual
16
+
mistakes, side-channel vulnerabilities, insecure parameter choices, or other
17
+
issues that could compromise confidentiality, integrity, or availability of
18
+
data.
19
+
20
+
The project is a **work in progress**. Breaking changes, API removals, or
21
+
redesigns may occur without notice.
11
22
12
-
This implementation is (still) **experimental**, **incomplete**, and **not audited** by any external security professionals.
13
-
It may contain defects, conceptual mistakes, side-channel vulnerabilities, insecure parameter choices, or other issues that could compromise confidentiality, integrity, or availability of data.
23
+
**Do not use Okuchi in production systems, high-risk environments, or anywhere
24
+
security or correctness is critical.**
14
25
15
-
**Do not use Okuchi in production systems, high-risk environments, or anywhere security or correctness is critical.**
26
+
If you choose to use this code despite these warnings, you do so entirely at
27
+
your own risk. No guarantees, explicit or implied, are made regarding
28
+
correctness, security, or fitness for any purpose. The author(s) assume no
29
+
liability for any damages or consequences resulting from use or misuse of this
30
+
software.
16
31
17
-
If you choose to use this code despite these warnings, **you do so entirely at your own risk**. No guarantees - explicit or implied - are made regarding performance, correctness, security, or fitness for any purpose.
18
-
The author(s) **assume no liability** for any damages, losses, or consequences resulting from the use, misuse, or inability to use this software.
32
+
---
19
33
20
34
## Goals
21
35
22
-
- Provide a correct, readable and safe Rust implementation of the **OU** cryptosystem
36
+
- Provide a correct, readable, and safe Rust implementation of the OU
37
+
cryptosystem
23
38
- Serve as a reference for learning and experimentation
24
-
- Maintain minimal dependencies and clear internal structure
39
+
- Maintain minimal dependencies and a clear internal structure
40
+
41
+
This project does **not** aim to be a hardened or production-quality
42
+
cryptographic library.
43
+
44
+
---
45
+
46
+
## Features
47
+
48
+
-**Probabilistic encryption**: two encryptions of the same plaintext produce
49
+
distinct ciphertexts
50
+
-**Additive homomorphism**: `E(m1) * E(m2) mod n` decrypts to
51
+
`(m1 + m2) mod p`, without decrypting either operand
52
+
-**Stream API**: encrypt and decrypt arbitrary-length byte sequences via
53
+
automatic block splitting and reassembly
54
+
-**Validated plaintext type**: [`Plaintext`] enforces the OU plaintext bound
55
+
at construction and provides checked addition for safe homomorphic
56
+
accumulation
57
+
-**Zeroize on drop**: secret key material (`p`, `q`, derived constants) is
58
+
zeroed when the key is dropped
25
59
26
-
This project **does not** aim to be a hardened or production-quality cryptographic library.
60
+
---
61
+
62
+
## Security Notes
63
+
64
+
- The minimum enforced key size is **512 bits** (testing only). Use **2048
65
+
bits or larger** for any non-trivial use.
66
+
- The modular exponentiation `c^(p-1) mod p²` in decryption is routed through
67
+
`crypto-bigint` Montgomery form for constant-time guarantees. All other
68
+
big-integer operations (`num-bigint-dig`) are **variable-time** and may leak
69
+
information about secret values through timing.
70
+
- No formal audit has been performed. Do not deploy in adversarial environments.
71
+
72
+
---
27
73
28
74
## Usage
29
75
30
-
As mentioned above, until the library matures and receives proper review, usage should be limited to:
0 commit comments