Coverage Report

Created: 2025-10-10 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rnp/src/lib/crypto/kmac_botan.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2023, [MTG AG](https://www.mtg.de).
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without modification,
6
 * are permitted provided that the following conditions are met:
7
 *
8
 * 1.  Redistributions of source code must retain the above copyright notice,
9
 *     this list of conditions and the following disclaimer.
10
 *
11
 * 2.  Redistributions in binary form must reproduce the above copyright notice,
12
 *     this list of conditions and the following disclaimer in the documentation
13
 *     and/or other materials provided with the distribution.
14
 *
15
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 */
26
27
#include "kmac_botan.hpp"
28
#include "hash_botan.hpp"
29
#include "botan/mac.h"
30
31
#if defined(ENABLE_PQC_DBG_LOG)
32
#include "crypto/mem.h"
33
#endif
34
35
namespace rnp {
36
37
0
KMAC256_Botan::KMAC256_Botan() : KMAC256()
38
0
{
39
0
}
40
41
std::unique_ptr<KMAC256_Botan>
42
KMAC256_Botan::create()
43
0
{
44
0
    return std::unique_ptr<KMAC256_Botan>(new KMAC256_Botan());
45
0
}
46
47
void
48
KMAC256_Botan::compute(const std::vector<uint8_t> &ecc_key_share,
49
                       const std::vector<uint8_t> &ecc_ciphertext,
50
                       const std::vector<uint8_t> &kyber_key_share,
51
                       const std::vector<uint8_t> &kyber_ciphertext,
52
                       const pgp_pubkey_alg_t      alg_id,
53
                       std::vector<uint8_t> &      out)
54
0
{
55
0
    auto kmac = Botan::MessageAuthenticationCode::create_or_throw("KMAC-256(256)");
56
57
    /* the mapping between the KEM Combiner and the MAC interface is:
58
     * key     <> domSeparation
59
     * nonce   <> customizationString
60
     * message <> encData
61
     */
62
63
#if defined(ENABLE_PQC_DBG_LOG)
64
    RNP_LOG_U8VEC("KMAC256 domSeparation: %s", domSeparation());
65
    RNP_LOG_U8VEC("KMAC256 customizationString: %s", customizationString());
66
#endif
67
68
0
    kmac->set_key(domSeparation());
69
0
    kmac->start(customizationString()); // set nonce
70
0
    kmac->update(
71
0
      encData(ecc_key_share, ecc_ciphertext, kyber_key_share, kyber_ciphertext, alg_id));
72
0
    out = kmac->final_stdvec();
73
74
#if defined(ENABLE_PQC_DBG_LOG)
75
    RNP_LOG_U8VEC("KMAC256 Output: %s", out);
76
#endif
77
0
}
78
79
KMAC256_Botan::~KMAC256_Botan()
80
0
{
81
0
}
82
83
} // namespace rnp