Debian Codegraph @

Source/Core/Common/Crypto/HMAC.cpp

raw symbols SCIP
1 // Copyright 2023 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "mbedtls/md.h"
5
6 #include "Common/Crypto/HMAC.h"
7 #include "Common/ScopeGuard.h"
8
9 namespace Common::HMAC
10 {
11 bool HMACWithSHA1(std::span<const u8> key, std::span<const u8> msg, u8* out)
12 {
13 mbedtls_md_context_t ctx;
14 Common::ScopeGuard guard{[&ctx] { mbedtls_md_free(&ctx); }};
15 mbedtls_md_init(&ctx);
16 if (mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(MBEDTLS_MD_SHA1), 1))
17 return false;
18
19 if (mbedtls_md_hmac_starts(&ctx, key.data(), key.size()) ||
20 mbedtls_md_hmac_update(&ctx, msg.data(), msg.size()) || mbedtls_md_hmac_finish(&ctx, out))
21 {
22 return false;
23 }
24
25 return true;
26 }
27 } // namespace Common::HMAC