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
21namespace governikus
22{
23
24class 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 static QSharedPointer<EC_KEY> create(EC_KEY* pEcKey);
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 static QSharedPointer<EC_KEY> generateKey(const QSharedPointer<const EC_GROUP>& pCurve);
44
45 static QSharedPointer<EC_GROUP> createCurve(int pNid);
46};
47
48
49inline QSharedPointer<EC_GROUP> EcUtil::create(EC_GROUP* pEcGroup)
50{
51 static auto deleter = [](EC_GROUP* ecCurve)
52 {
53 EC_GROUP_free(ecCurve);
54 };
55
56 return QSharedPointer<EC_GROUP>(pEcGroup, deleter);
57}
58
59
60inline QSharedPointer<EC_KEY> EcUtil::create(EC_KEY* pEcKey)
61{
62 static auto deleter = [](EC_KEY* ecKey)
63 {
64 EC_KEY_free(ecKey);
65 };
66
67 return QSharedPointer<EC_KEY>(pEcKey, deleter);
68}
69
70
71inline QSharedPointer<EC_POINT> EcUtil::create(EC_POINT* pEcPoint)
72{
73 static auto deleter = [](EC_POINT* ecPoint)
74 {
75 EC_POINT_clear_free(ecPoint);
76 };
77
78 return QSharedPointer<EC_POINT>(pEcPoint, deleter);
79}
80
81
82inline QSharedPointer<BIGNUM> EcUtil::create(BIGNUM* pBigNum)
83{
84 static auto deleter = [](BIGNUM* bigNum)
85 {
86 BN_clear_free(bigNum);
87 };
88
89 return QSharedPointer<BIGNUM>(pBigNum, deleter);
90}
91
92
93inline QSharedPointer<EVP_PKEY> EcUtil::create(EVP_PKEY* pKey)
94{
95 static auto deleter = [](EVP_PKEY* key)
96 {
97 EVP_PKEY_free(key);
98 };
99
100 return QSharedPointer<EVP_PKEY>(pKey, deleter);
101}
102
103
104inline QSharedPointer<EVP_PKEY_CTX> EcUtil::create(EVP_PKEY_CTX* pCtx)
105{
106 static auto deleter = [](EVP_PKEY_CTX* ctx)
107 {
108 EVP_PKEY_CTX_free(ctx);
109 };
110
111 return QSharedPointer<EVP_PKEY_CTX>(pCtx, deleter);
112}
113
114
115} // namespace governikus
Definition EcUtil.h:25
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:91
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:49
Implementation of GeneralAuthenticate response APDUs.
Definition CommandApdu.h:16