| 99 | } |
| 100 | |
| 101 | fn challenge_scalar<F: Field>(&mut self, label: &'static [u8]) -> F { |
| 102 | // Reduce a double-width scalar to ensure a uniform distribution |
| 103 | // TODO: It assumes 32 byte field element. Make it generic |
| 104 | let mut buf = [0; 64]; |
| 105 | self.merlin.challenge_bytes(label, &mut buf); |
| 106 | let mut counter = 0; |
| 107 | loop { |
| 108 | let c = F::from_random_bytes(&buf); |
| 109 | if let Some(chal) = c { |
| 110 | if let Some(c_inv) = chal.inverse() { |
| 111 | return c_inv; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | buf[0] = counter; |
| 116 | counter += 1; |
| 117 | self.merlin.challenge_bytes(label, &mut buf); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | fn challenge_scalar_without_static_label<F: Field>(&mut self, label: &[u8]) -> F { |
| 122 | // Reduce a double-width scalar to ensure a uniform distribution |