1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 use sha2::Digest; 16 17 /// RustCrypto implementation for SHA256 18 pub struct RustCryptoSha256; 19 20 impl crypto_provider::sha2::Sha256 for RustCryptoSha256 { sha256(input: &[u8]) -> [u8; 32]21 fn sha256(input: &[u8]) -> [u8; 32] { 22 let mut digest = sha2::Sha256::new(); 23 digest.update(input); 24 digest.finalize().into() 25 } 26 } 27 28 /// RustCrypto implementation for SHA512 29 pub struct RustCryptoSha512; 30 31 impl crypto_provider::sha2::Sha512 for RustCryptoSha512 { sha512(input: &[u8]) -> [u8; 64]32 fn sha512(input: &[u8]) -> [u8; 64] { 33 let mut digest = sha2::Sha512::new(); 34 digest.update(input); 35 digest.finalize().into() 36 } 37 } 38