xref: /aosp_15_r20/system/keymint/boringssl/src/sha256.rs (revision 9860b7637a5f185913c70aa0caabe3ecb78441e4)
1*9860b763SAndroid Build Coastguard Worker // Copyright 2023, The Android Open Source Project
2*9860b763SAndroid Build Coastguard Worker //
3*9860b763SAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9860b763SAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9860b763SAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9860b763SAndroid Build Coastguard Worker //
7*9860b763SAndroid Build Coastguard Worker //     http://www.apache.org/licenses/LICENSE-2.0
8*9860b763SAndroid Build Coastguard Worker //
9*9860b763SAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9860b763SAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9860b763SAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9860b763SAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9860b763SAndroid Build Coastguard Worker // limitations under the License.
14*9860b763SAndroid Build Coastguard Worker 
15*9860b763SAndroid Build Coastguard Worker //! This crate implements the IKeystoreSecurityLevel interface.
16*9860b763SAndroid Build Coastguard Worker 
17*9860b763SAndroid Build Coastguard Worker //! BoringSSL-based implementation of SHA-256.
18*9860b763SAndroid Build Coastguard Worker use kmr_common::{crypto, Error};
19*9860b763SAndroid Build Coastguard Worker 
20*9860b763SAndroid Build Coastguard Worker /// [`crypto::Sha256`] implementation based on BoringSSL.
21*9860b763SAndroid Build Coastguard Worker pub struct BoringSha256;
22*9860b763SAndroid Build Coastguard Worker 
23*9860b763SAndroid Build Coastguard Worker impl crypto::Sha256 for BoringSha256 {
hash(&self, data: &[u8]) -> Result<[u8; 32], Error>24*9860b763SAndroid Build Coastguard Worker     fn hash(&self, data: &[u8]) -> Result<[u8; 32], Error> {
25*9860b763SAndroid Build Coastguard Worker         Ok(openssl::sha::sha256(data))
26*9860b763SAndroid Build Coastguard Worker     }
27*9860b763SAndroid Build Coastguard Worker }
28