/// NI-PoE Prove /// Assumes &#96;u^x &#61; w&#96; /// All operations are &#96;mod n&#96;. pub fn ni_poe_prove(x: &BigUint, u: &BigUint, w: &BigUint, n: &BigUint) -> ExponentProof {debug_assert!(&u.modpow(x, n) &#61;&#61; w, "invalid input");// l <- H_prime(x, u, w)let mut to_hash &#61; x.to_bytes_be();to_hash.extend(&u.to_bytes_be());to_hash.extend(&w.to_bytes_be());let l &#61; hash_prime::<_, Blake2b>(&to_hash);// q <- floor(x/l)let q &#61; x.div_floor(&l);//Prover sends Q <- u^q ∈ G to the Verifier.u.modpow(&q, n) }/// NI-PoE Verify /// Assumes &#96;u^x &#61; w&#96; /// All operations are &#96;mod n&#96;. pub fn ni_poe_verify(x: &BigUint,u: &BigUint,w: &BigUint,q: &ExponentProof,n: &BigUint, ) -> bool {// l <- H_prime(x, u, w)let mut to_hash &#61; x.to_bytes_be();to_hash.extend(&u.to_bytes_be());to_hash.extend(&w.to_bytes_be());let l &#61; hash_prime::<_, Blake2b>(&to_hash);// r <- x mod llet r &#61; x.mod_floor(&l);// Q^l u^r &#61;&#61; w&((q.modpow(&l, &n) * &u.modpow(&r, &n)) % n) &#61;&#61; w }// 基于hash值来获取prime数值。 // When the proofs are made non-interactive, using the // Fiat-Shamir heuristic the challenge is generated by hashing the previous transcript/// Hash the given numbers to a prime number. /// Currently uses only 128bits. pub fn hash_prime, D: Digest>(input: &[u8]) -> BigUint {let mut y &#61; BigUint::from_bytes_be(&D::digest(input)[..16]);while !probably_prime(&y, 20) {y &#61; BigUint::from_bytes_be(&D::digest(&y.to_bytes_be())[..16]);}y }
2. Proof of knowledge of exponentiation
2.1 有安全攻击隐患的PoKE
此时&#xff0c;verifier不需要自己计算余数rrr&#xff0c;改由prover提供。同时注意&#xff0c;此时要求discrete logarithm base ggg必须被包含在CRS中⇒\Rightarrow⇒ 存在安全攻击问题&#xff0c;不是secure protocol&#xff1a;