AusweisApp2
Lade ...
Suche ...
Keine Treffer
EcUtil.h
gehe zur Dokumentation dieser Datei
1
7#pragma once
8
9#include <QByteArray>
10#include <QSharedPointer>
11
12#include <openssl/bn.h>
13#include <openssl/ec.h>
14#include <openssl/ecdsa.h>
15#include <openssl/evp.h>
16
17#include <functional>
18
19namespace governikus
20{
21
22class EcUtil
23{
24 public:
25 static QByteArray point2oct(const QSharedPointer<const EC_GROUP>& pCurve, const EC_POINT* pPoint, bool pCompressed = false);
26
27 static QSharedPointer<EC_POINT> oct2point(const QSharedPointer<const EC_GROUP>& pCurve, const QByteArray& pCompressedData);
28
29 static QSharedPointer<EC_GROUP> create(EC_GROUP* pEcGroup);
30
31#if OPENSSL_VERSION_NUMBER < 0x30000000L
32 static QSharedPointer<EC_KEY> create(EC_KEY* pEcKey);
33#endif
34
35 static QSharedPointer<EC_POINT> create(EC_POINT* pEcPoint);
36
37 static QSharedPointer<BIGNUM> create(BIGNUM* pBigNum);
38
39 static QSharedPointer<EVP_PKEY> create(EVP_PKEY* pEcGroup);
40
41 static QSharedPointer<EVP_PKEY_CTX> create(EVP_PKEY_CTX* pEcGroup);
42
43#if OPENSSL_VERSION_NUMBER >= 0x30000000L
44 static QByteArray getEncodedPublicKey(const QSharedPointer<EVP_PKEY>& pKey);
45 static QSharedPointer<BIGNUM> getPrivateKey(const QSharedPointer<const EVP_PKEY>& pKey);
46 static QSharedPointer<OSSL_PARAM> create(const std::function<bool(OSSL_PARAM_BLD* pBuilder)>& pFunc);
47 static QSharedPointer<EVP_PKEY> generateKey(const QSharedPointer<const EC_GROUP>& pCurve);
48#else
49 static QSharedPointer<EC_KEY> generateKey(const QSharedPointer<const EC_GROUP>& pCurve);
50#endif
51
52 static QSharedPointer<EC_GROUP> createCurve(int pNid);
53};
54
55
56inline QSharedPointer<EC_GROUP> EcUtil::create(EC_GROUP* pEcGroup)
57{
58 static auto deleter = [](EC_GROUP* ecCurve)
59 {
60 EC_GROUP_free(ecCurve);
61 };
62
63 return QSharedPointer<EC_GROUP>(pEcGroup, deleter);
64}
65
66
67#if OPENSSL_VERSION_NUMBER < 0x30000000L
68inline QSharedPointer<EC_KEY> EcUtil::create(EC_KEY* pEcKey)
69{
70 static auto deleter = [](EC_KEY* ecKey)
71 {
72 EC_KEY_free(ecKey);
73 };
74
75 return QSharedPointer<EC_KEY>(pEcKey, deleter);
76}
77
78
79#endif
80
81inline QSharedPointer<EC_POINT> EcUtil::create(EC_POINT* pEcPoint)
82{
83 static auto deleter = [](EC_POINT* ecPoint)
84 {
85 EC_POINT_clear_free(ecPoint);
86 };
87
88 return QSharedPointer<EC_POINT>(pEcPoint, deleter);
89}
90
91
92inline QSharedPointer<BIGNUM> EcUtil::create(BIGNUM* pBigNum)
93{
94 static auto deleter = [](BIGNUM* bigNum)
95 {
96 BN_clear_free(bigNum);
97 };
98
99 return QSharedPointer<BIGNUM>(pBigNum, deleter);
100}
101
102
103inline QSharedPointer<EVP_PKEY> EcUtil::create(EVP_PKEY* pKey)
104{
105 static auto deleter = [](EVP_PKEY* key)
106 {
107 EVP_PKEY_free(key);
108 };
109
110 return QSharedPointer<EVP_PKEY>(pKey, deleter);
111}
112
113
114inline QSharedPointer<EVP_PKEY_CTX> EcUtil::create(EVP_PKEY_CTX* pCtx)
115{
116 static auto deleter = [](EVP_PKEY_CTX* ctx)
117 {
118 EVP_PKEY_CTX_free(ctx);
119 };
120
121 return QSharedPointer<EVP_PKEY_CTX>(pCtx, deleter);
122}
123
124
125} // namespace governikus
Definition: EcUtil.h:23
static QByteArray point2oct(const QSharedPointer< const EC_GROUP > &pCurve, const EC_POINT *pPoint, bool pCompressed=false)
Definition: EcUtil.cpp:31
static QSharedPointer< EC_GROUP > createCurve(int pNid)
Definition: EcUtil.cpp:19
static QSharedPointer< EC_KEY > generateKey(const QSharedPointer< const EC_GROUP > &pCurve)
Definition: EcUtil.cpp:222
static QSharedPointer< EC_POINT > oct2point(const QSharedPointer< const EC_GROUP > &pCurve, const QByteArray &pCompressedData)
Definition: EcUtil.cpp:67
static QSharedPointer< EC_GROUP > create(EC_GROUP *pEcGroup)
Definition: EcUtil.h:56
Implementation of GeneralAuthenticate response APDUs.
Definition: CommandApdu.h:16