Skip to main content

stealth_lib/
hasher.rs

1//! Legacy hasher module for backwards compatibility.
2//!
3//! # Deprecated
4//!
5//! This module is deprecated. Use [`crate::hash::MimcHasher`] instead.
6//!
7//! ## Migration
8//!
9//! ```ignore
10//! // Old code:
11//! use stealth_lib::hasher::Hasher;
12//! let hash = Hasher::mimc_sponge(left, right, key);
13//!
14//! // New code:
15//! use stealth_lib::MimcHasher;
16//! let hasher = MimcHasher::default();
17//! let hash = hasher.mimc_sponge(left, right, key);
18//! ```
19
20#![allow(missing_docs)]
21#![allow(deprecated)]
22
23use crate::hash::MimcHasher;
24
25/// Legacy Hasher struct.
26///
27/// # Deprecated
28///
29/// Use [`MimcHasher`] instead.
30#[deprecated(since = "1.0.0", note = "Use crate::hash::MimcHasher instead")]
31pub struct Hasher;
32
33impl Hasher {
34    /// MiMC-Feistel permutation (legacy API).
35    #[deprecated(since = "1.0.0", note = "Use MimcHasher methods instead")]
36    #[allow(dead_code)]
37    fn mimc_feistel(il: u128, ir: u128, k: u128) -> (u128, u128) {
38        let hasher = MimcHasher::default();
39        // This is a simplified version - the actual implementation is in MimcHasher
40        let mut last_l = il;
41        let mut last_r = ir;
42        let p = hasher.field_prime();
43
44        for _i in 0..hasher.num_rounds() {
45            let mask = last_r.wrapping_add(k).wrapping_rem(p);
46            let mask = mask.wrapping_add(0).wrapping_rem(p); // Simplified
47            let mask2 = mask.wrapping_mul(mask).wrapping_rem(p);
48            let mask4 = mask2.wrapping_mul(mask2).wrapping_rem(p);
49            let mask5 = mask4.wrapping_mul(mask).wrapping_rem(p);
50
51            let temp = last_r;
52            last_r = last_l.wrapping_add(mask5).wrapping_rem(p);
53            last_l = temp;
54        }
55
56        (last_l, last_r)
57    }
58
59    /// MiMC sponge hash (legacy API).
60    ///
61    /// # Deprecated
62    ///
63    /// Use [`MimcHasher::mimc_sponge`] instead.
64    #[deprecated(since = "1.0.0", note = "Use MimcHasher::mimc_sponge instead")]
65    pub fn mimc_sponge(left: u128, right: u128, k: u128) -> u128 {
66        MimcHasher::default().mimc_sponge(left, right, k)
67    }
68}