xref: /aosp_15_r20/external/tink/cc/internal/md_util.h (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2021 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 ///////////////////////////////////////////////////////////////////////////////
16 #ifndef TINK_INTERNAL_MD_UTIL_H_
17 #define TINK_INTERNAL_MD_UTIL_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "absl/strings/string_view.h"
23 #include "openssl/evp.h"
24 #include "tink/subtle/common_enums.h"
25 #include "tink/util/status.h"
26 #include "tink/util/statusor.h"
27 
28 namespace crypto {
29 namespace tink {
30 namespace internal {
31 
32 // Returns an EVP structure for a hash function type `hash_type`.
33 // Note: EVP_MD instances are sigletons owned by BoringSSL/OpenSSL.
34 util::StatusOr<const EVP_MD *> EvpHashFromHashType(
35     crypto::tink::subtle::HashType hash_type);
36 
37 // Validates whether `sig_hash` is safe to use for digital signature.
38 crypto::tink::util::Status IsHashTypeSafeForSignature(
39     crypto::tink::subtle::HashType sig_hash);
40 
41 // Returns the hash of `input` using the hash function `hasher`.
42 crypto::tink::util::StatusOr<std::string> ComputeHash(absl::string_view input,
43                                                       const EVP_MD &hasher);
44 
45 }  // namespace internal
46 }  // namespace tink
47 }  // namespace crypto
48 
49 #endif  // TINK_INTERNAL_MD_UTIL_H_
50