AusweisApp
 
Lade ...
Suche ...
Keine Treffer
EcUtil.h
gehe zur Dokumentation dieser Datei
1
4
5#pragma once
6
7#include <QByteArray>
8#include <QSharedPointer>
9
10#include <openssl/bn.h>
11#include <openssl/ec.h>
12#include <openssl/ecdsa.h>
13#include <openssl/evp.h>
14
15#include <functional>
16
17
18namespace governikus
19{
20
21class EcUtil
22{
23 public:
24 static QByteArray compressPoint(const QByteArray& pPoint);
25 static QByteArray point2oct(const QSharedPointer<const EC_GROUP>& pCurve, const EC_POINT* pPoint, bool pCompressed = false);
26 static QSharedPointer<EC_POINT> oct2point(const QSharedPointer<const EC_GROUP>& pCurve, const QByteArray& pCompressedData);
27
28 static QSharedPointer<EC_GROUP> create(EC_GROUP* pEcGroup);
29 static QSharedPointer<EC_KEY> create(EC_KEY* pEcKey);
30 static QSharedPointer<EC_POINT> create(EC_POINT* pEcPoint);
31 static QSharedPointer<BIGNUM> create(BIGNUM* pBigNum);
32 static QSharedPointer<EVP_PKEY> create(EVP_PKEY* pEcGroup);
33 static QSharedPointer<EVP_PKEY_CTX> create(EVP_PKEY_CTX* pEcGroup);
34
35 static QByteArray getEncodedPublicKey(const QSharedPointer<EC_KEY>& pKey, bool pCompressed = false);
36 static QSharedPointer<BIGNUM> getPrivateKey(const QSharedPointer<const EC_KEY>& pKey);
37 static QSharedPointer<EC_KEY> generateKey(const QSharedPointer<const EC_GROUP>& pCurve);
38
39 static QSharedPointer<EC_GROUP> createCurve(int pNid);
40};
41
42
43inline QSharedPointer<EC_GROUP> EcUtil::create(EC_GROUP* pEcGroup)
44{
45 static auto deleter = [](EC_GROUP* ecCurve)
46 {
47 EC_GROUP_free(ecCurve);
48 };
49
50 return QSharedPointer<EC_GROUP>(pEcGroup, deleter);
51}
52
53
54inline QSharedPointer<EC_KEY> EcUtil::create(EC_KEY* pEcKey)
55{
56 static auto deleter = [](EC_KEY* ecKey)
57 {
58 EC_KEY_free(ecKey);
59 };
60
61 return QSharedPointer<EC_KEY>(pEcKey, deleter);
62}
63
64
65inline QSharedPointer<EC_POINT> EcUtil::create(EC_POINT* pEcPoint)
66{
67 static auto deleter = [](EC_POINT* ecPoint)
68 {
69 EC_POINT_clear_free(ecPoint);
70 };
71
72 return QSharedPointer<EC_POINT>(pEcPoint, deleter);
73}
74
75
76inline QSharedPointer<BIGNUM> EcUtil::create(BIGNUM* pBigNum)
77{
78 static auto deleter = [](BIGNUM* bigNum)
79 {
80 BN_clear_free(bigNum);
81 };
82
83 return QSharedPointer<BIGNUM>(pBigNum, deleter);
84}
85
86
87inline QSharedPointer<EVP_PKEY> EcUtil::create(EVP_PKEY* pKey)
88{
89 static auto deleter = [](EVP_PKEY* key)
90 {
91 EVP_PKEY_free(key);
92 };
93
94 return QSharedPointer<EVP_PKEY>(pKey, deleter);
95}
96
97
98inline QSharedPointer<EVP_PKEY_CTX> EcUtil::create(EVP_PKEY_CTX* pCtx)
99{
100 static auto deleter = [](EVP_PKEY_CTX* ctx)
101 {
102 EVP_PKEY_CTX_free(ctx);
103 };
104
105 return QSharedPointer<EVP_PKEY_CTX>(pCtx, deleter);
106}
107
108
109} // namespace governikus
Definition EcUtil.h:22
static QByteArray point2oct(const QSharedPointer< const EC_GROUP > &pCurve, const EC_POINT *pPoint, bool pCompressed=false)
Definition EcUtil.cpp:46
static QByteArray compressPoint(const QByteArray &pPoint)
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:131
static QSharedPointer< EC_POINT > oct2point(const QSharedPointer< const EC_GROUP > &pCurve, const QByteArray &pCompressedData)
Definition EcUtil.cpp:82
static QByteArray getEncodedPublicKey(const QSharedPointer< EC_KEY > &pKey, bool pCompressed=false)
Definition EcUtil.cpp:106
static QSharedPointer< EC_GROUP > create(EC_GROUP *pEcGroup)
Definition EcUtil.h:43
static QSharedPointer< BIGNUM > getPrivateKey(const QSharedPointer< const EC_KEY > &pKey)
Definition EcUtil.cpp:119
Defines the AccessRight and AccessRole enum.
Definition CommandApdu.h:17