KHealthCertificate

irmapublickey.cpp
1/*
2 * SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6#include "irmapublickey_p.h"
7
8#include "openssl/bignum_p.h"
9
10#include <QDebug>
11#include <QFile>
12#include <QXmlStreamReader>
13
14// see https://pkg.go.dev/github.com/privacybydesign/gabi@v0.0.0-20210816093228-75a6590e506c/gabikeys#PublicKey
15
16IrmaPublicKey::IrmaPublicKey() = default;
17
18bool IrmaPublicKey::isValid() const
19{
20 return N && Z && S && std::all_of(R.begin(), R.end(), [](const auto &r) { return r.get() != nullptr; });
21}
22
23// see https://github.com/minvws/gabi/blob/idemix_origin/sysparams.go#L21
24int IrmaPublicKey::LePrime() const
25{
26 return 120;
27}
28
29int IrmaPublicKey::Lh() const
30{
31 return 256;
32}
33
34int IrmaPublicKey::Lm() const
35{
36 switch (BN_num_bits(N.get())) {
37 case 1024:
38 case 2048:
39 return 256;
40 case 4096:
41 return 512;
42 }
43 return 0;
44}
45
46int IrmaPublicKey::Lstatzk() const
47{
48 switch (BN_num_bits(N.get())) {
49 case 1024:
50 return 80;
51 case 2048:
52 case 4096:
53 return 128;
54 }
55 return 0;
56}
57
58// and https://github.com/minvws/gabi/blob/idemix_origin/sysparams.go#L60
59int IrmaPublicKey::Le() const
60{
61 return Lstatzk() + Lh() + Lm() + 5;
62}
63
64int IrmaPublicKey::LeCommit() const
65{
66 return LePrime() + Lstatzk() + Lh();
67}
68
69int IrmaPublicKey::LmCommit() const
70{
71 return Lm() + Lstatzk() + Lh();
72}
73
74
75IrmaPublicKey IrmaPublicKeyLoader::load(const QString &keyId)
76{
77 IrmaPublicKey pk;
78
79 QFile pkFile(QLatin1String(":/org.kde.khealthcertificate/nl-coronacheck/keys/") + keyId + QLatin1String(".xml"));
80 if (!pkFile.open(QFile::ReadOnly)) {
81 qWarning() << "Failed to find IRMA public key:" << keyId;
82 return pk;
83 }
84
85 QXmlStreamReader reader(&pkFile);
86 while (!reader.atEnd() && !reader.hasError()) {
87 reader.readNextStartElement();
88 if (reader.name() == QLatin1String("n")) {
89 pk.N = Bignum::fromDecimalString(reader.readElementText());
90 }
91 else if (reader.name() == QLatin1String("Z")) {
92 pk.Z = Bignum::fromDecimalString(reader.readElementText());
93 }
94 else if (reader.name() == QLatin1String("S")) {
95 pk.S = Bignum::fromDecimalString(reader.readElementText());
96 }
97 else if (reader.name() == QLatin1String("Bases")) {
98 const auto num = reader.attributes().value(QLatin1String("num")).toInt();
99 pk.R.reserve(num);
100 }
101 else if (reader.name().startsWith(QLatin1String("Base_"))) {
102 pk.R.push_back(Bignum::fromDecimalString(reader.readElementText()));
103 }
104 }
105
106 return pk;
107}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.