1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! # Penis Protocol
//!
//! A cryptographic protocol that enables verifiable hashing while maintaining data confidentiality.
//! PENIS (Partially Executed Nth-round Intermediate State) allows generating SHA-256 compatible
//! hashes that can be verified without revealing the entire input data.
//!
//! ## Overview
//!
//! The protocol operates by:
//! 1. Pausing SHA-256 hash computation at a specified round (n)
//! 2. Preserving intermediate state for confidential data portions
//! 3. Allowing verification of the final hash without exposing confidential data
//!
//! ## Security Considerations
//!
//! - Always use security parameter n=40 for maximum security in production
//! - Values of n<32 are NOT recommended for sensitive data
//! - Values of n<16 are UNSAFE as they reveal unhashed data
//! - Values of n≥48 are invalid and cause implementation errors
//!
//! ## Core Components
//!
//! ### Generator
//!
//! [`PenisGenerator`] creates intermediate hash states while preserving confidentiality of specified
//! data ranges. It executes the hash computation up to the specified round n and produces verifiable
//! intermediate states.
//!
//! ```rust
//! use penis::{PenisGenerator, SecsParam, DataRange, ToBeHashed};
//!
//! // Initialize with maximum security (n=40)
//! let generator = PenisGenerator(SecsParam::new(40));
//!
//! // Prepare data with confidential ranges
//! let tbh = ToBeHashed {
//! data: b"Hello, World!".to_vec(),
//! confidentials: vec![DataRange::new(0, 5)], // Keep "Hello" confidential
//! };
//!
//! // Generate intermediate state
//! let penis = generator.execute(tbh);
//! ```
//!
//! ### Verifier
//!
//! [`PenisVerifier`] validates and completes the hash computation from intermediate states without
//! accessing the confidential data. It ensures the integrity of the final hash while maintaining
//! data privacy.
//!
//! ```ignore
//! use penis::{PenisVerifier, SecsParam, Penis};
//!
//! // Initialize with same security parameter
//! let verifier = PenisVerifier(SecsParam::new(40));
//!
//! // Resume hash computation from intermediate state
//! let final_state = verifier.resume(penis);
//! let hash = final_state.finalize();
//! ```
//!
//! ### Data Structures
//!
//! - [`Penis`]: Represents the Partially Executed Nth-round Intermediate State
//! - [`PenisBlock`]: Represents either a confidential or public block in the hash computation
//! - [`PrivateBlock`]: Contains intermediate state and partial schedule array for confidential blocks
//! - [`State`]: Represents the internal state of SHA-256 hash computation
//! - [`DataRange`]: Specifies ranges of confidential data
//! - [`ToBeHashed`]: Contains input data and confidential ranges
//! - [`SecsParam`]: Security parameters controlling the protocol behavior
//!
//! ## Best Practices
//!
//! 1. Security
//! - Use n=40 for maximum security
//! - Validate all input data
//! - Implement additional encryption for network transmission
//! - Monitor for timing attacks
//! - Keep confidential ranges minimal
//!
//! 2. Performance
//! - Pre-allocate vectors when possible
//! - Reuse generator/verifier instances
//! - Process large data in chunks
//! - Monitor memory usage
//!
//! 3. Error Handling
//! - Always check data range validity
//! - Handle all error cases appropriately
//! - Implement proper cleanup procedures
//! - Avoid leaking sensitive information in errors
//!
//! ## Example
//!
//! ```rust
//! use penis::*;
//!
//! // Initialize with maximum security
//! let secs = SecsParam::new(40);
//! let generator = PenisGenerator(secs);
//!
//! // Prepare data with confidential range
//! let data = b"Hello, World!".to_vec();
//! let confidential = DataRange::new(0, 5); // Keep "Hello" confidential
//! let tbh = ToBeHashed {
//! data,
//! confidentials: vec![confidential],
//! };
//!
//! // Validate ranges
//! tbh.check_datarange().expect("Invalid data range");
//!
//! // Generate intermediate state
//! let penis = generator.execute(tbh);
//!
//! // Encode for transmission
//! let encoded = penis.encode_sparse();
//!
//! /* --- Transmission... --- */
//!
//! let secs = SecsParam::new(40);
//! let verifier = PenisVerifier(secs);
//!
//! // Decode and verify
//! let decoded = Penis::decode_sparse(&encoded);
//! let final_state = verifier.resume(decoded);
//! let hash = final_state.finalize();
//! ```
extern crate alloc;
pub use Penis;
pub use PenisGenerator;
pub use PenisVerifier;
pub use ;