snarkvm_console_algorithms/poseidon/hash_to_scalar.rs
// Copyright 2024 Aleo Network Foundation
// This file is part of the snarkVM library.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use super::*;
impl<E: Environment, const RATE: usize> HashToScalar for Poseidon<E, RATE> {
type Input = Field<E>;
type Output = Scalar<E>;
/// Returns a scalar from hashing the input.
/// This method uses truncation (up to data bits) to project onto the scalar field.
#[inline]
fn hash_to_scalar(&self, input: &[Self::Input]) -> Result<Self::Output> {
// Hash the input to the base field.
let output = self.hash(input)?;
// Convert the output to the scalar field,
// truncating to the size in data bits (1 bit less than the MODULUS) of the scalar.
Ok(Self::Output::from_field_lossy(&output))
}
}