xref: /aosp_15_r20/system/nvram/core/crypto.h (revision 7ba4dab5cc5e3c8f3eb594dcf3b33f99d9214aee)
1*7ba4dab5SXin Li /*
2*7ba4dab5SXin Li  * Copyright (C) 2016 The Android Open Source Project
3*7ba4dab5SXin Li  *
4*7ba4dab5SXin Li  * Licensed under the Apache License, Version 2.0 (the "License");
5*7ba4dab5SXin Li  * you may not use this file except in compliance with the License.
6*7ba4dab5SXin Li  * You may obtain a copy of the License at
7*7ba4dab5SXin Li  *
8*7ba4dab5SXin Li  *      http://www.apache.org/licenses/LICENSE-2.0
9*7ba4dab5SXin Li  *
10*7ba4dab5SXin Li  * Unless required by applicable law or agreed to in writing, software
11*7ba4dab5SXin Li  * distributed under the License is distributed on an "AS IS" BASIS,
12*7ba4dab5SXin Li  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*7ba4dab5SXin Li  * See the License for the specific language governing permissions and
14*7ba4dab5SXin Li  * limitations under the License.
15*7ba4dab5SXin Li  */
16*7ba4dab5SXin Li 
17*7ba4dab5SXin Li #ifndef NVRAM_CORE_CRYPTO_H_
18*7ba4dab5SXin Li #define NVRAM_CORE_CRYPTO_H_
19*7ba4dab5SXin Li 
20*7ba4dab5SXin Li extern "C" {
21*7ba4dab5SXin Li #include <stddef.h>
22*7ba4dab5SXin Li #include <stdint.h>
23*7ba4dab5SXin Li }  // extern "C"
24*7ba4dab5SXin Li 
25*7ba4dab5SXin Li namespace nvram {
26*7ba4dab5SXin Li namespace crypto {
27*7ba4dab5SXin Li 
28*7ba4dab5SXin Li // Size of a SHA-256 digest in bytes.
29*7ba4dab5SXin Li constexpr size_t kSHA256DigestSize = 32;
30*7ba4dab5SXin Li 
31*7ba4dab5SXin Li // Computes the SHA-256 digest of the |data_size| input bytes stored at |data|.
32*7ba4dab5SXin Li // The digest is written to |digest|, which is a buffer of size |digest_size|.
33*7ba4dab5SXin Li // Note that |digest_size| doesn't have to match SHA-256's output size of 32
34*7ba4dab5SXin Li // bytes. If it doesn't the digest is truncated or zero-padded as necessary.
35*7ba4dab5SXin Li //
36*7ba4dab5SXin Li // Returns true if the digest was computed successfully, false otherwise.
37*7ba4dab5SXin Li void SHA256(const uint8_t* data,
38*7ba4dab5SXin Li             size_t data_size,
39*7ba4dab5SXin Li             uint8_t* digest,
40*7ba4dab5SXin Li             size_t digest_size);
41*7ba4dab5SXin Li 
42*7ba4dab5SXin Li }  // namespace crypto
43*7ba4dab5SXin Li }  // namespace nvram
44*7ba4dab5SXin Li 
45*7ba4dab5SXin Li #endif  // NVRAM_CORE_CRYPTO_H_
46