Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"polynomial",
"univariate-polynomial-iop-zerotest",
"halo2-trials",
"[Rfc1321]message-digest-v5-hash",
"[Sha97]shamir-secret-sharing",
"[Fel87]feldman-verifiable-secret-sharing",
"[Sch91]schnorr-discrete-log-proof-of-knowledge",
Expand All @@ -28,3 +29,4 @@ rand_core = "0.6.4"
rand = "0.8.5"
rand_chacha = "0.3.1"
simba = "0.8.1"
itertools = "0.12.1"
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cd Cryptography-Research && cargo test
```

## References
- **\[Sha97\]**: Shamir's secret sharing https://apps.dtic.mil/sti/pdfs/ADA069397.pdf.
- **\[Fel87\]**: Feldman's verifiable secret sharing https://www.zkdocs.com/docs/zkdocs/protocol-primitives/verifiable-secret-sharing/
- **\[Sch91\]**: Schnorr's DLog PoK https://www.zkdocs.com/docs/zkdocs/zero-knowledge-protocols/schnorr/
- **\[Sha97\]**: [Shamir's secret sharing](https://apps.dtic.mil/sti/pdfs/ADA069397.pdf)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add blank lines around the list for better Markdown formatting.

+ 
- **\[Sha97\]**: [Shamir's secret sharing](https://apps.dtic.mil/sti/pdfs/ADA069397.pdf)
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **\[Sha97\]**: [Shamir's secret sharing](https://apps.dtic.mil/sti/pdfs/ADA069397.pdf)
**\[Sha97\]**: [Shamir's secret sharing](https://apps.dtic.mil/sti/pdfs/ADA069397.pdf)

- **\[Fel87\]**: [Feldman's verifiable secret sharing](https://www.zkdocs.com/docs/zkdocs/protocol-primitives/verifiable-secret-sharing/)
- **\[Sch91\]**: [Schnorr's DLog PoK](https://www.zkdocs.com/docs/zkdocs/zero-knowledge-protocols/schnorr/)
- **\[rfc1321\]**: [Message Digest v5 hashing function](https://datatracker.ietf.org/doc/html/rfc1321)
7 changes: 7 additions & 0 deletions [rfc1321]message-digest-v5-hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
edition = "2021"
name = "message-digest-5"
version = "0.1.0"

[dependencies]
itertools = { workspace = true }
5 changes: 5 additions & 0 deletions [rfc1321]message-digest-v5-hash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Message Digest version 5

See associated info at: [here](https://hackmd.io/@sraj/zk-hashfunc-comparison)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving the link text to be more descriptive than "here" to enhance document readability.

- See associated info at: [here](https://hackmd.io/@sraj/zk-hashfunc-comparison)
+ See associated info at: [Comparative Analysis of Hash Functions](https://hackmd.io/@sraj/zk-hashfunc-comparison)

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
See associated info at: [here](https://hackmd.io/@sraj/zk-hashfunc-comparison)
See associated info at: [Comparative Analysis of Hash Functions](https://hackmd.io/@sraj/zk-hashfunc-comparison)


## References
80 changes: 80 additions & 0 deletions [rfc1321]message-digest-v5-hash/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/// A generalized trait for hashing systems using
/// a Merkle–Damgård construction
trait MerkleDamgard {
type InternalState;
type Chunk;
type HashOutput;

/// An MD-compliant input padding logic
fn pad_input(message: &[u8]) -> Vec<Self::Chunk>;

/// Compressor step to consume a chunk and affect the state
fn apply_compressor(state: &mut Self::InternalState, chunk: Self::Chunk);

/// Final output producer
fn finalize() -> Self::HashOutput;
Comment on lines +3 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the trait MerkleDamgard is public if it is intended to be used outside this module.

- trait MerkleDamgard {
+ pub trait MerkleDamgard {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
trait MerkleDamgard {
type InternalState;
type Chunk;
type HashOutput;
/// An MD-compliant input padding logic
fn pad_input(message: &[u8]) -> Vec<Self::Chunk>;
/// Compressor step to consume a chunk and affect the state
fn apply_compressor(state: &mut Self::InternalState, chunk: Self::Chunk);
/// Final output producer
fn finalize() -> Self::HashOutput;
pub trait MerkleDamgard {
type InternalState;
type Chunk;
type HashOutput;
/// An MD-compliant input padding logic
fn pad_input(message: &[u8]) -> Vec<Self::Chunk>;
/// Compressor step to consume a chunk and affect the state
fn apply_compressor(state: &mut Self::InternalState, chunk: Self::Chunk);
/// Final output producer
fn finalize() -> Self::HashOutput;

}

struct MessageDigestV5 {
round_constants: [u32; 64],
shift_amounts: [u32; 64],
initialization_state: [u32; 4],
}

impl MessageDigestV5 {
#[rustfmt::skip]
pub fn new() -> Self {
// The table formula function:
// K[i] = floor(2^32 * abs(sin(i))
fn round_constant_generator(i: u32) -> u32 {
let x: f64 = i as f64;
let sin_eval = x.sin().abs();

// note: 4294967296 == 2^32
(4294967296.0 * sin_eval) as u32
}

Self {
round_constants: (0..64)
.map(|x| round_constant_generator(x+1))
.collect::<Vec<u32>>()[0..64]
.try_into()
.unwrap(),
shift_amounts: [
[7, 12, 17, 22].into_iter().cycle().take(16).collect::<Vec<u32>>(),
[5, 9, 14, 20].into_iter().cycle().take(16).collect::<Vec<u32>>(),
[4, 11, 16, 23].into_iter().cycle().take(16).collect::<Vec<u32>>(),
[6, 10, 15, 21].into_iter().cycle().take(16).collect::<Vec<u32>>()
].concat()[0..64]
.try_into()
.unwrap(),
initialization_state: [0x67452301u32, 0xefcdab89u32, 0x98badcfeu32, 0x10325476u32],
}
}
}

impl MerkleDamgard for MessageDigestV5 {
type InternalState = [u32; 4];
type Chunk = u32;
type HashOutput = [u32; 4];

fn pad_input(message: &[u8]) -> Vec<Self::Chunk> {
todo!()
}

fn apply_compressor(state: &mut Self::InternalState, chunk: Self::Chunk) {
todo!()
}

fn finalize() -> Self::HashOutput {
todo!()
}
Comment on lines +61 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete the implementations of pad_input, apply_compressor, and finalize methods or provide detailed TODO comments explaining the intended next steps.

Would you like assistance in implementing these methods or should I open a GitHub issue to track this task?

}

#[cfg(test)]
mod tests {
#[test]
fn two() {
assert!(2 == 2);
}
Comment on lines +76 to +79
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test function two only checks a trivial condition. Consider adding more comprehensive tests that cover the functionality of MessageDigestV5.

Would you like me to help generate more detailed unit tests?

}