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