2020-05-22 13:18:41 +00:00
/*
* Copyright ( c ) 2013 - 2020 , The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
* See full license text in LICENSE file at top of project tree
*/
2019-05-14 15:42:25 +00:00
# ifndef BLINDING_H__
# define BLINDING_H__
# include <inttypes.h>
# include <string>
2019-05-14 18:42:10 +00:00
# include <vector>
2019-05-14 15:42:25 +00:00
# include "Identity.h"
namespace i2p
{
namespace data
{
class BlindedPublicKey // for encrypted LS2
{
public :
2019-09-06 15:02:19 +00:00
BlindedPublicKey ( std : : shared_ptr < const IdentityEx > identity , bool clientAuth = false ) ;
2020-03-01 10:25:50 +00:00
BlindedPublicKey ( const std : : string & b33 ) ; // from b33 without .b32.i2p
2019-05-14 15:42:25 +00:00
std : : string ToB33 ( ) const ;
const uint8_t * GetPublicKey ( ) const { return m_PublicKey . data ( ) ; } ;
size_t GetPublicKeyLen ( ) const { return m_PublicKey . size ( ) ; } ;
SigningKeyType GetSigType ( ) const { return m_SigType ; } ;
SigningKeyType GetBlindedSigType ( ) const { return m_BlindedSigType ; } ;
2019-09-23 17:42:15 +00:00
bool IsValid ( ) const { return GetSigType ( ) ; } ; // signature type 0 means invalid
2019-05-14 15:42:25 +00:00
void GetSubcredential ( const uint8_t * blinded , size_t len , uint8_t * subcredential ) const ; // 32 bytes
2020-03-01 10:25:50 +00:00
size_t GetBlindedKey ( const char * date , uint8_t * blindedKey ) const ; // date is 8 chars "YYYYMMDD", return public key length
size_t BlindPrivateKey ( const uint8_t * priv , const char * date , uint8_t * blindedPriv , uint8_t * blindedPub ) const ; // date is 8 chars "YYYYMMDD", return public key length
2019-05-14 15:42:25 +00:00
i2p : : data : : IdentHash GetStoreHash ( const char * date = nullptr ) const ; // date is 8 chars "YYYYMMDD", use current if null
private :
void GetCredential ( uint8_t * credential ) const ; // 32 bytes
2020-03-01 10:25:50 +00:00
void GenerateAlpha ( const char * date , uint8_t * seed ) const ; // 64 bytes, date is 8 chars "YYYYMMDD"
2019-05-14 15:42:25 +00:00
void H ( const std : : string & p , const std : : vector < std : : pair < const uint8_t * , size_t > > & bufs , uint8_t * hash ) const ;
private :
std : : vector < uint8_t > m_PublicKey ;
i2p : : data : : SigningKeyType m_SigType , m_BlindedSigType ;
2019-09-06 15:02:19 +00:00
bool m_IsClientAuth = false ;
2019-05-14 15:42:25 +00:00
} ;
}
}
# endif