Debian Codegraph @

src/common/cryptolayer.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/common/cryptolayer.cpp`/
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 #include "cryptolayer.h"cxx . . $ `<file>/src/common/cryptolayer.h`/
5
6 #include <botan/base64.h>
7 #include <botan/data_src.h>
8 #include <botan/ed25519.h>
9 #include <botan/pubkey.h>
10 #include <botan/system_rng.h>
11 #include <botan/x509_key.h>
12 #include <cstddef>
13 #include <cstdint>
14 #include <exception>
15 #include <spdlog/spdlog.h>
16
17 void CryptoLayercxx . . $ CryptoLayer#::initcxx . . $ CryptoLayer#init(49f6e7a06ebc5aa8).()
18 {
19 privateKey_cxx . . $ CryptoLayer#privateKey_. =cxx . . $ std/unique_ptr#`operator=`(274635e25750a47f). stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<Botancxx . . $ Botan/::Ed25519_PrivateKeycxx . . $ Botan/Ed25519_PrivateKey#>(Botancxx . . $ Botan/::system_rngcxx . . $ Botan/system_rng(b97ed8aadbcb30be).());
20 }
21
22 QByteArraycxx . . $ QByteArray# CryptoLayercxx . . $ CryptoLayer#::publicKeycxx . . $ CryptoLayer#publicKey(b3c286cec66e09f4).()
23 {
24 auto key = Botancxx . . $ Botan/::X509cxx . . $ Botan/X509/::PEM_encodecxx . . $ Botan/X509/PEM_encode(7c4e95072a5f09ce).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).privateKey_cxx . . $ CryptoLayer#privateKey_.);
25 return {cxx . . $ QByteArray#QByteArray(de40a1f2d6082f12).key.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()};
26 }
27
28 void CryptoLayercxx . . $ CryptoLayer#::usePublicKeycxx . . $ CryptoLayer#usePublicKey(45672f3c6961a244).(QByteArraycxx . . $ QByteArray# const &publicKey)
29 {
30 auto keyStr = publicKey.toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).();
31 Botancxx . . $ Botan/::DataSource_Memorycxx . . $ Botan/DataSource_Memory# pubKeycxx . . $ Botan/DataSource_Memory#DataSource_Memory(c8024318075daf50).(keyStr);
32 opPublicKey_cxx . . $ CryptoLayer#opPublicKey_. =cxx . . $ std/unique_ptr#`operator=`(1b63e42eaa758a73).
33 stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Botancxx . . $ Botan/::Public_Keycxx . . $ Botan/Public_Key#>(Botancxx . . $ Botan/::X509cxx . . $ Botan/X509/::load_keycxx . . $ Botan/X509/load_key(b97a5ea5d755b16d).(pubKey));
34 }
35
36 bool CryptoLayercxx . . $ CryptoLayer#::verifycxx . . $ CryptoLayer#verify(5ad6b2491b335728).(QByteArraycxx . . $ QByteArray# const &data, QByteArraycxx . . $ QByteArray# const &signature)
37 {
38 try {
39 Botancxx . . $ Botan/::PK_Verifiercxx . . $ Botan/PK_Verifier# verifiercxx . . $ Botan/PK_Verifier#PK_Verifier(ff495d2638515976).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).opPublicKey_cxx . . $ CryptoLayer#opPublicKey_., "SHA-512"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).);
40 auto decodedSignature = Botancxx . . $ Botan/::base64_decodecxx . . $ Botan/base64_decode(49f97a1dd065e751).(signature.toStdStringcxx . . $ QByteArray#toStdString(219584694fe2b248).());
41 return verifier.verify_messagecxx . . $ Botan/PK_Verifier#verify_message(e746df55edb48ea7).(
42 reinterpret_cast<uint8_tcxx . . $ uint8_t# const *>(data.datacxx . . $ QByteArray#data(ba32b354807b2b81).()),
43 static_cast<size_t>(data.sizecxx . . $ QByteArray#size(6b0412d51016192f).()), decodedSignature.datacxx . . $ std/vector#data(258ee1c9e0a18a5c).(),
44 decodedSignature.sizecxx . . $ std/vector#size(c9b1e749b64d5edc).());
45 }
46 catch (stdcxx . . $ std/::exception const &e) {
47 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
48 }
49 return false;
50 }
51
52 QByteArraycxx . . $ QByteArray# CryptoLayercxx . . $ CryptoLayer#::signaturecxx . . $ CryptoLayer#signature(ba1ae99d10185369).(QByteArraycxx . . $ QByteArray# const &data)
53 {
54 try {
55 Botancxx . . $ Botan/::PK_Signercxx . . $ Botan/PK_Signer# signercxx . . $ Botan/PK_Signer#PK_Signer(e4ea10071da91e05).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).privateKey_cxx . . $ CryptoLayer#privateKey_., Botancxx . . $ Botan/::system_rngcxx . . $ Botan/system_rng(b97ed8aadbcb30be).(), "SHA-512"cxx . . $ std/basic_string_view#basic_string_view(837a1ee5a10cb792).);
56 auto signature = signer.sign_messagecxx . . $ Botan/PK_Signer#sign_message(abf3b91c5bf8cee7).(
57 reinterpret_cast<uint8_tcxx . . $ uint8_t# const *>(data.datacxx . . $ QByteArray#data(ba32b354807b2b81).()),
58 static_cast<size_t>(data.sizecxx . . $ QByteArray#size(6b0412d51016192f).()), Botancxx . . $ Botan/::system_rngcxx . . $ Botan/system_rng(b97ed8aadbcb30be).());
59 auto encodedSignature = Botancxx . . $ Botan/::base64_encodecxx . . $ Botan/base64_encode(7756d273e9838283).(signaturecxx . . $ std/span#span(7049a1c3b13f5ca0).);
60 return {cxx . . $ QByteArray#QByteArray(de40a1f2d6082f12).encodedSignature.c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()};
61 }
62 catch (stdcxx . . $ std/::exception const &e) {
63 SPDLOG_DEBUGcxx . . $ `<external>/13613935168682455490/spdlog.h:311:13`!(e.what());
64 }
65 return {cxx . . $ QByteArray#QByteArray(ced63f7c635d850d).};
66 }