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