lime
Lime is a C++ library implementing Open Whisper System Signal protocol
Loading...
Searching...
No Matches
lime_crypto_primitives.hpp
Go to the documentation of this file.
1/*
2 lime_crypto_primitives.hpp
3 @author Johan Pascal
4 @copyright Copyright (C) 2017 Belledonne Communications SARL
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef lime_crypto_primitives_hpp
21#define lime_crypto_primitives_hpp
22
23#include <memory>
24#include <vector>
25
26#include "lime_keys.hpp"
27#include "lime_defines.hpp"
28
29namespace lime {
30/*************************************************************************************************/
31/********************** Data Structures **********************************************************/
32/*************************************************************************************************/
33
34 void cleanBuffer(uint8_t *buffer, size_t size);
35
41 template <size_t T>
42 struct sBuffer : public std::array<uint8_t, T> {
44 ~sBuffer() {cleanBuffer(this->data(), T);};
45 };
46
47 /****************************************************************/
48 /* Key Exchange Data structures */
49 /****************************************************************/
55 template <typename Curve, lime::Xtype dataType>
56 class X : public sBuffer<static_cast<size_t>(Curve::Xsize(dataType))>{
57 public :
59 constexpr static size_t ssize(void) {return Curve::Xsize(dataType);};
61 X(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
63 X(const uint8_t * const buffer) {std::copy_n(buffer, ssize(), this->begin());}
65 X() {this->fill(0);};
67 void assign(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
68 };
69
73 template <typename Curve>
74 class Xpair {
75 private:
78 public:
81 const X<Curve, lime::Xtype::privateKey> &cprivateKey(void) const {return m_privKey;};
84 const X<Curve, lime::Xtype::publicKey> &cpublicKey(void) const {return m_pubKey;};
86 Xpair(const X<Curve, lime::Xtype::publicKey> &pub, const X<Curve, lime::Xtype::privateKey> &priv):m_pubKey(pub),m_privKey(priv) {};
87 Xpair() :m_pubKey{},m_privKey{}{};
89 bool operator==(Xpair<Curve> b) const {return (m_privKey==b.privateKey() && m_pubKey==b.publicKey());};
90
91 };
92
93 /****************************************************************/
94 /* Key Encapsulation Data structures */
95 /****************************************************************/
101 template <typename Algo, lime::Ktype dataType>
102 class K : public sBuffer<static_cast<size_t>(Algo::Ksize(dataType))>{
103 public :
105 constexpr static size_t ssize(void) {return Algo::Ksize(dataType);};
107 K(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
109 K(const uint8_t * const buffer) {std::copy_n(buffer, ssize(), this->begin());}
111 K() {this->fill(0);};
113 void assign(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
114 };
115
119 template <typename Algo>
120 class Kpair {
121 private:
124 public:
127 const K<Algo, lime::Ktype::privateKey> &cprivateKey(void) const {return m_privKey;};
130 const K<Algo, lime::Ktype::publicKey> &cpublicKey(void) const {return m_pubKey;};
132 Kpair(const K<Algo, lime::Ktype::publicKey> &pub, const K<Algo, lime::Ktype::privateKey> &priv):m_pubKey(pub),m_privKey(priv) {};
133 Kpair() :m_pubKey{},m_privKey{}{};
135 bool operator==(Kpair<Algo> b) const {return (m_privKey==b.privateKey() && m_pubKey==b.publicKey());};
136
137 };
138
139 /****************************************************************/
140 /* Digital Signature Algorithm data structures */
141 /****************************************************************/
147 template <typename Curve, lime::DSAtype dataType>
148 class DSA : public sBuffer<static_cast<size_t>(Curve::DSAsize(dataType))>{
149 public :
151 constexpr static size_t ssize(void) {return Curve::DSAsize(dataType);};
153 DSA(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
155 DSA() {this->fill(0);};
157 void assign(const std::vector<uint8_t>::const_iterator buffer) {std::copy_n(buffer, ssize(), this->begin());}
158 };
159
163 template <typename Curve>
164 class DSApair {
165 private:
168 public:
171 const DSA<Curve, lime::DSAtype::privateKey> &cprivateKey(void) const {return m_privKey;};
174 const DSA<Curve, lime::DSAtype::publicKey> &cpublicKey(void) const {return m_pubKey;};
176 DSApair(const DSA<Curve, lime::DSAtype::publicKey> &pub, const DSA<Curve, lime::DSAtype::privateKey> &priv):m_pubKey(pub),m_privKey(priv) {};
177 DSApair() :m_pubKey{},m_privKey{}{};
179 bool operator==(DSApair<Curve> b) const {return (m_privKey==b.privateKey() && m_pubKey==b.publicKey());};
180 };
181
182
183/*************************************************************************************************/
184/********************** Crypto Algo interface ****************************************************/
185/*************************************************************************************************/
186
196class RNG {
197 public:
205 virtual uint32_t randomize() = 0;
206
212 virtual void randomize(uint8_t *buffer, const size_t size) = 0;
213
214 virtual ~RNG() = default;
215}; //class RNG
216
223template <typename Curve>
225 public:
226 /* accessors */
235
236 /* set keys in context, publics and private keys directly accept Signature formatted keys which are converted to keyExchange format */
238 virtual void set_secret(const X<Curve, lime::Xtype::privateKey> &secret) = 0;
243 virtual void set_secret(const DSA<Curve, lime::DSAtype::privateKey> &secret) = 0;
245 virtual void set_selfPublic(const X<Curve, lime::Xtype::publicKey> &selfPublic) = 0;
250 virtual void set_selfPublic(const DSA<Curve, lime::DSAtype::publicKey> &selfPublic) = 0;
252 virtual void set_peerPublic(const X<Curve, lime::Xtype::publicKey> &peerPublic) = 0;
257 virtual void set_peerPublic(const DSA<Curve, lime::DSAtype::publicKey> &peerPublic) = 0;
258
264 virtual void createKeyPair(std::shared_ptr<lime::RNG> rng) = 0;
265
269 virtual void deriveSelfPublic(void) = 0;
270
274 virtual void computeSharedSecret(void) = 0;
275 virtual ~keyExchange() = default;
276}; //class keyExchange
277
283template <typename Algo>
314
320template <typename Curve>
322 public:
323 /* accessors */
328
330 virtual void set_secret(const DSA<Curve, lime::DSAtype::privateKey> &secretKey) = 0;
333
339 virtual void createKeyPair(std::shared_ptr<lime::RNG> rng) = 0;
340
344 virtual void derivePublic(void) = 0;
345
352 virtual void sign(const std::vector<uint8_t> &message, DSA<Curve, lime::DSAtype::signature> &signature) = 0;
358
367 virtual bool verify(const std::vector<uint8_t> &message, const DSA<Curve, lime::DSAtype::signature> &signature) = 0;
373
374 virtual ~Signature() = default;
375}; //class EdDSA
376
390template <typename hashAlgo>
391void HMAC(const uint8_t *const key, const size_t keySize, const uint8_t *const input, const size_t inputSize, uint8_t *hash, size_t hashSize);
392/* declare template specialisations */
393template <> void HMAC<SHA512>(const uint8_t *const key, const size_t keySize, const uint8_t *const input, const size_t inputSize, uint8_t *hash, size_t hashSize);
394
425template <typename hashAlgo>
426void HMAC_KDF(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const char *info, const size_t infoSize, uint8_t *output, size_t outputSize);
427/* declare template specialisations */
428template <> void HMAC_KDF<SHA512>(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const char * info, const size_t infoSize, uint8_t *output, size_t outputSize);
429
430
431/************************ AEAD interface *************************************/
432
448template <typename AEADAlgo>
449void AEAD_encrypt(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize,
450 const uint8_t *const plain, const size_t plainSize, const uint8_t *const AD, const size_t ADSize,
451 uint8_t *tag, const size_t tagSize, uint8_t *cipher);
452
470template <typename AEADAlgo>
471bool AEAD_decrypt(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize,
472 const uint8_t *const cipher, const size_t cipherSize, const uint8_t *const AD, const size_t ADSize,
473 const uint8_t *const tag, const size_t tagSize, uint8_t *plain);
474
475/* declare AEAD template specialisations */
476template <> void AEAD_encrypt<AES256GCM>(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize,
477 const uint8_t *const plain, const size_t plainSize, const uint8_t *const AD, const size_t ADSize,
478 uint8_t *tag, const size_t tagSize, uint8_t *cipher);
479
480template <> bool AEAD_decrypt<AES256GCM>(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize,
481 const uint8_t *const cipher, const size_t cipherSize, const uint8_t *const AD, const size_t ADSize,
482 const uint8_t *const tag, const size_t tagSize, uint8_t *plain);
483
484
485/*************************************************************************************************/
486/********************** Factory Functions ********************************************************/
487/*************************************************************************************************/
488/* Use these to instantiate an object as they will pick the correct underlying implemenation of virtual classes */
489std::shared_ptr<RNG> make_RNG();
490
491template <typename Curve>
492std::shared_ptr<keyExchange<Curve>> make_keyExchange();
493
494template <typename Curve>
495std::shared_ptr<Signature<Curve>> make_Signature();
496
497template <typename Algo>
498std::shared_ptr<KEM<Algo>> make_KEM();
499
500/*************************************************************************************************/
501/********************** Template Instanciation ***************************************************/
502/*************************************************************************************************/
503/* this templates are instanciated once in the lime_crypto_primitives.cpp file, explicitly tell anyone including this header that there is no need to re-instanciate them */
504
505#ifdef EC25519_ENABLED
506 extern template std::shared_ptr<keyExchange<C255>> make_keyExchange();
507 extern template std::shared_ptr<Signature<C255>> make_Signature();
508 extern template class X<C255, lime::Xtype::publicKey>;
509 extern template class X<C255, lime::Xtype::privateKey>;
510 extern template class X<C255, lime::Xtype::sharedSecret>;
511 extern template class Xpair<C255>;
512 extern template class DSA<C255, lime::DSAtype::publicKey>;
513 extern template class DSA<C255, lime::DSAtype::privateKey>;
514 extern template class DSA<C255, lime::DSAtype::signature>;
515 extern template class DSApair<C255>;
516#endif // EC25519_ENABLED
517
518#ifdef EC448_ENABLED
519 extern template std::shared_ptr<keyExchange<C448>> make_keyExchange();
520 extern template std::shared_ptr<Signature<C448>> make_Signature();
521 extern template class X<C448, lime::Xtype::publicKey>;
522 extern template class X<C448, lime::Xtype::privateKey>;
523 extern template class X<C448, lime::Xtype::sharedSecret>;
524 extern template class Xpair<C448>;
525 extern template class DSA<C448, lime::DSAtype::publicKey>;
526 extern template class DSA<C448, lime::DSAtype::privateKey>;
527 extern template class DSA<C448, lime::DSAtype::signature>;
528 extern template class DSApair<C448>;
529#endif // EC448_ENABLED
530
531#ifdef HAVE_BCTBXPQ
532 // Kyber512
533 extern template std::shared_ptr<KEM<K512>> make_KEM();
534 extern template class K<K512, lime::Ktype::publicKey>;
535 extern template class K<K512, lime::Ktype::privateKey>;
536 extern template class K<K512, lime::Ktype::cipherText>;
537 extern template class K<K512, lime::Ktype::sharedSecret>;
538 extern template class Kpair<K512>;
539 // MLKEM 512
540 extern template std::shared_ptr<KEM<MLK512>> make_KEM();
541 extern template class K<MLK512, lime::Ktype::publicKey>;
542 extern template class K<MLK512, lime::Ktype::privateKey>;
543 extern template class K<MLK512, lime::Ktype::cipherText>;
544 extern template class K<MLK512, lime::Ktype::sharedSecret>;
545 extern template class Kpair<MLK512>;
546 // MLKEM 1024
547 extern template std::shared_ptr<KEM<MLK1024>> make_KEM();
548 extern template class K<MLK1024, lime::Ktype::publicKey>;
549 extern template class K<MLK1024, lime::Ktype::privateKey>;
550 extern template class K<MLK1024, lime::Ktype::cipherText>;
551 extern template class K<MLK1024, lime::Ktype::sharedSecret>;
552 extern template class Kpair<MLK1024>;
553#endif //HAVE_BCTBXPQ
554} // namespace lime
555
556#endif //lime_crypto_primitives_hpp
557
558
Base buffer definition for DSA data structure.
Definition lime_crypto_primitives.hpp:148
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition lime_crypto_primitives.hpp:151
DSA()
default initialise value to 0
Definition lime_crypto_primitives.hpp:155
void assign(const std::vector< uint8_t >::const_iterator buffer)
copy from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:157
DSA(const std::vector< uint8_t >::const_iterator buffer)
contruct from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:153
Key pair structure for DSA algorithm.
Definition lime_crypto_primitives.hpp:164
DSA< Curve, lime::DSAtype::privateKey > & privateKey(void)
access the private key
Definition lime_crypto_primitives.hpp:170
const DSA< Curve, lime::DSAtype::privateKey > & cprivateKey(void) const
Definition lime_crypto_primitives.hpp:171
const DSA< Curve, lime::DSAtype::publicKey > & cpublicKey(void) const
Definition lime_crypto_primitives.hpp:174
DSApair(const DSA< Curve, lime::DSAtype::publicKey > &pub, const DSA< Curve, lime::DSAtype::privateKey > &priv)
copy construct a key pair from public and private keys (no verification on validity of keys is perfor...
Definition lime_crypto_primitives.hpp:176
bool operator==(DSApair< Curve > b) const
== operator assert that public and private keys are the same
Definition lime_crypto_primitives.hpp:179
DSA< Curve, lime::DSAtype::publicKey > & publicKey(void)
access the public key
Definition lime_crypto_primitives.hpp:173
DSApair()
Definition lime_crypto_primitives.hpp:177
Key Encapsulation Mechanism interface.
Definition lime_crypto_primitives.hpp:284
virtual void createKeyPair(Kpair< Algo > &keyPair)=0
generate a new random key pair
virtual ~KEM()=default
virtual void decaps(const K< Algo, lime::Ktype::privateKey > &privateKey, const K< Algo, lime::Ktype::cipherText > &cipherText, K< Algo, lime::Ktype::sharedSecret > &sharedSecret)=0
decapsulate a shared secret from a cipher text using a private key
virtual void encaps(const K< Algo, lime::Ktype::publicKey > &publicKey, K< Algo, lime::Ktype::cipherText > &cipherText, K< Algo, lime::Ktype::sharedSecret > &sharedSecret)=0
Generate and encapsulate a shared secret for a given public key.
Base buffer definition for KEM data structure.
Definition lime_crypto_primitives.hpp:102
K(const uint8_t *const buffer)
construct from uint8_t *
Definition lime_crypto_primitives.hpp:109
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition lime_crypto_primitives.hpp:105
K()
default initialise value to 0
Definition lime_crypto_primitives.hpp:111
void assign(const std::vector< uint8_t >::const_iterator buffer)
copy from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:113
K(const std::vector< uint8_t >::const_iterator buffer)
construct from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:107
Key pair structure for key exchange algorithm.
Definition lime_crypto_primitives.hpp:120
bool operator==(Kpair< Algo > b) const
== operator assert that public and private keys are the same
Definition lime_crypto_primitives.hpp:135
K< Algo, lime::Ktype::privateKey > & privateKey(void)
access the private key
Definition lime_crypto_primitives.hpp:126
Kpair(const K< Algo, lime::Ktype::publicKey > &pub, const K< Algo, lime::Ktype::privateKey > &priv)
copy construct a key pair from public and private keys (no verification on validity of keys is perfor...
Definition lime_crypto_primitives.hpp:132
const K< Algo, lime::Ktype::privateKey > & cprivateKey(void) const
Definition lime_crypto_primitives.hpp:127
K< Algo, lime::Ktype::publicKey > & publicKey(void)
access the public key
Definition lime_crypto_primitives.hpp:129
const K< Algo, lime::Ktype::publicKey > & cpublicKey(void) const
Definition lime_crypto_primitives.hpp:130
Kpair()
Definition lime_crypto_primitives.hpp:133
Random number generator interface.
Definition lime_crypto_primitives.hpp:196
virtual void randomize(uint8_t *buffer, const size_t size)=0
virtual uint32_t randomize()=0
Generate a 32 bits unsigned integer(used to generate keys Id) The MSbit is forced to 0 to avoid deali...
virtual ~RNG()=default
Digital Signature interface.
Definition lime_crypto_primitives.hpp:321
virtual void derivePublic(void)=0
Compute the public key using the secret already set in context.
virtual const DSA< Curve, lime::DSAtype::privateKey > get_secret(void)=0
Secret key.
virtual void sign(const std::vector< uint8_t > &message, DSA< Curve, lime::DSAtype::signature > &signature)=0
Sign a message using the key pair previously set in the object.
virtual void set_secret(const DSA< Curve, lime::DSAtype::privateKey > &secretKey)=0
Secret key.
virtual void sign(const X< Curve, lime::Xtype::publicKey > &message, DSA< Curve, lime::DSAtype::signature > &signature)=0
virtual void createKeyPair(std::shared_ptr< lime::RNG > rng)=0
generate a new random EdDSA key pair
virtual ~Signature()=default
virtual const DSA< Curve, lime::DSAtype::publicKey > get_public(void)=0
Public key.
virtual bool verify(const std::vector< uint8_t > &message, const DSA< Curve, lime::DSAtype::signature > &signature)=0
Verify a message signature using the public key previously set in the object.
virtual bool verify(const X< Curve, lime::Xtype::publicKey > &message, const DSA< Curve, lime::DSAtype::signature > &signature)=0
virtual void set_public(const DSA< Curve, lime::DSAtype::publicKey > &publicKey)=0
Public key.
Base buffer definition for Key Exchange data structure.
Definition lime_crypto_primitives.hpp:56
X()
default initialise value to 0
Definition lime_crypto_primitives.hpp:65
X(const std::vector< uint8_t >::const_iterator buffer)
construct from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:61
X(const uint8_t *const buffer)
construct from a uint8_t *
Definition lime_crypto_primitives.hpp:63
void assign(const std::vector< uint8_t >::const_iterator buffer)
copy from a std::vector<uint8_t>
Definition lime_crypto_primitives.hpp:67
static constexpr size_t ssize(void)
provide a static size function to be able to call the function not on an object
Definition lime_crypto_primitives.hpp:59
Key pair structure for key exchange algorithm.
Definition lime_crypto_primitives.hpp:74
const X< Curve, lime::Xtype::publicKey > & cpublicKey(void) const
Definition lime_crypto_primitives.hpp:84
Xpair(const X< Curve, lime::Xtype::publicKey > &pub, const X< Curve, lime::Xtype::privateKey > &priv)
copy construct a key pair from public and private keys (no verification on validity of keys is perfor...
Definition lime_crypto_primitives.hpp:86
X< Curve, lime::Xtype::publicKey > & publicKey(void)
access the public key
Definition lime_crypto_primitives.hpp:83
const X< Curve, lime::Xtype::privateKey > & cprivateKey(void) const
Definition lime_crypto_primitives.hpp:81
bool operator==(Xpair< Curve > b) const
== operator assert that public and private keys are the same
Definition lime_crypto_primitives.hpp:89
Xpair()
Definition lime_crypto_primitives.hpp:87
X< Curve, lime::Xtype::privateKey > & privateKey(void)
access the private key
Definition lime_crypto_primitives.hpp:80
Key exchange interface.
Definition lime_crypto_primitives.hpp:224
virtual void set_secret(const X< Curve, lime::Xtype::privateKey > &secret)=0
set Secret key
virtual const X< Curve, lime::Xtype::publicKey > get_selfPublic(void)=0
get Self Public key
virtual ~keyExchange()=default
virtual void set_secret(const DSA< Curve, lime::DSAtype::privateKey > &secret)=0
virtual const X< Curve, lime::Xtype::publicKey > get_peerPublic(void)=0
get Peer Public key
virtual const X< Curve, lime::Xtype::sharedSecret > get_sharedSecret(void)=0
get shared secret when exchange is completed
virtual void createKeyPair(std::shared_ptr< lime::RNG > rng)=0
generate a new random key pair
virtual void set_selfPublic(const DSA< Curve, lime::DSAtype::publicKey > &selfPublic)=0
virtual void set_selfPublic(const X< Curve, lime::Xtype::publicKey > &selfPublic)=0
set Self Public key
virtual void set_peerPublic(const DSA< Curve, lime::DSAtype::publicKey > &peerPublic)=0
virtual void set_peerPublic(const X< Curve, lime::Xtype::publicKey > &peerPublic)=0
set Peer Public key
virtual const X< Curve, lime::Xtype::privateKey > get_secret(void)=0
get Secret key
virtual void computeSharedSecret(void)=0
Perform the shared secret computation, it is then available in the object via get_sharedSecret.
virtual void deriveSelfPublic(void)=0
Compute the self public key using the secret already set in context.
Definition lime.cpp:33
std::shared_ptr< RNG > make_RNG()
Definition lime_crypto_primitives.cpp:91
bool AEAD_decrypt< AES256GCM >(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize, const uint8_t *const cipher, const size_t cipherSize, const uint8_t *const AD, const size_t ADSize, const uint8_t *const tag, const size_t tagSize, uint8_t *plain)
Definition lime_crypto_primitives.cpp:493
@ cipherText
Definition lime_keys.hpp:43
std::shared_ptr< Signature< Curve > > make_Signature()
Definition lime_crypto_primitives.cpp:427
@ signature
Definition lime_keys.hpp:49
std::shared_ptr< keyExchange< Curve > > make_keyExchange()
Definition lime_crypto_primitives.cpp:422
@ sharedSecret
Definition lime_keys.hpp:38
@ privateKey
Definition lime_keys.hpp:38
@ publicKey
Definition lime_keys.hpp:38
void AEAD_encrypt< AES256GCM >(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize, const uint8_t *const plain, const size_t plainSize, const uint8_t *const AD, const size_t ADSize, uint8_t *tag, const size_t tagSize, uint8_t *cipher)
Definition lime_crypto_primitives.cpp:480
bool AEAD_decrypt(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize, const uint8_t *const cipher, const size_t cipherSize, const uint8_t *const AD, const size_t ADSize, const uint8_t *const tag, const size_t tagSize, uint8_t *plain)
Authenticate and Decrypt using scheme given as template parameter.
Definition lime_crypto_primitives.cpp:471
void AEAD_encrypt(const uint8_t *const key, const size_t keySize, const uint8_t *const IV, const size_t IVSize, const uint8_t *const plain, const size_t plainSize, const uint8_t *const AD, const size_t ADSize, uint8_t *tag, const size_t tagSize, uint8_t *cipher)
Encrypt and tag using scheme given as template parameter.
Definition lime_crypto_primitives.cpp:463
void HMAC_KDF< SHA512 >(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const char *info, const size_t infoSize, uint8_t *output, size_t outputSize)
Definition lime_crypto_primitives.cpp:457
std::shared_ptr< KEM< Algo > > make_KEM()
void HMAC_KDF(const uint8_t *const salt, const size_t saltSize, const uint8_t *const ikm, const size_t ikmSize, const char *info, const size_t infoSize, uint8_t *output, size_t outputSize)
HKDF as described in RFC5869.
Definition lime_crypto_primitives.cpp:452
void HMAC(const uint8_t *const key, const size_t keySize, const uint8_t *const input, const size_t inputSize, uint8_t *hash, size_t hashSize)
templated HMAC
Definition lime_crypto_primitives.cpp:441
void cleanBuffer(uint8_t *buffer, size_t size)
force a buffer values to zero in a way that shall prevent the compiler from optimizing it out
Definition lime_crypto_primitives.cpp:535
void HMAC< SHA512 >(const uint8_t *const key, const size_t keySize, const uint8_t *const input, const size_t inputSize, uint8_t *hash, size_t hashSize)
Definition lime_crypto_primitives.cpp:447
auto clean fixed size buffer(std::array based)
Definition lime_crypto_primitives.hpp:42
~sBuffer()
zeroise all buffer when done
Definition lime_crypto_primitives.hpp:44