Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UnsignedCoin Class Reference

#include <bank.h>

Inheritance diagram for UnsignedCoin:

Public Member Functions

 UnsignedCoin ()
 
 UnsignedCoin (BIGNUM *bnCoinID)
 
 ~UnsignedCoin ()
 
void Clear ()
 
void Set (const BIGNUM *bnCoinID)
 
void Random (int nCoinLength)
 
BIGNUM * ID ()
 
boolean GenerateCoinNumber (BIGNUM *bnNumber, const PublicBank &bank)
 
void Dump ()
 
void WriteBIO (BIO *bio)
 
void ReadBIO (BIO *bio)
 

Protected Attributes

BIGNUM * m_bnCoinID
 

Detailed Description

Definition at line 116 of file bank.h.

Constructor & Destructor Documentation

UnsignedCoin::UnsignedCoin ( )
inline

Definition at line 121 of file bank.h.

122  { m_bnCoinID=NULL; }
BIGNUM * m_bnCoinID
Definition: bank.h:119
UnsignedCoin::UnsignedCoin ( BIGNUM *  bnCoinID)
inline

Definition at line 123 of file bank.h.

124  { m_bnCoinID=BN_dup(bnCoinID); }
BIGNUM * m_bnCoinID
Definition: bank.h:119
UnsignedCoin::~UnsignedCoin ( )
inline

Definition at line 125 of file bank.h.

126  { BN_free(m_bnCoinID); }
BIGNUM * m_bnCoinID
Definition: bank.h:119

Member Function Documentation

void UnsignedCoin::Clear ( )
inline

Definition at line 127 of file bank.h.

128  {
129  BN_free(m_bnCoinID);
130  m_bnCoinID=NULL;
131  }
BIGNUM * m_bnCoinID
Definition: bank.h:119
void UnsignedCoin::Dump ( )
inline

Definition at line 177 of file bank.h.

178  {
179  DumpNumber("coin= ",m_bnCoinID);
180  }
void DumpNumber(BIO *out, const char *szTitle, const BIGNUM *bn, const char *szTrailer=_NL)
BIGNUM * m_bnCoinID
Definition: bank.h:119
boolean UnsignedCoin::GenerateCoinNumber ( BIGNUM *  bnNumber,
const PublicBank bank 
)
inline

Definition at line 150 of file bank.h.

151  {
152  int nCoinLength=BN_num_bytes(m_bnCoinID);
153  int nDigestIterations=(bank.PrimeLength()-nCoinLength)/DIGEST_LENGTH;
154 
155  if(nCoinLength != bank.CoinLength())
156  return false;
157 
158  unsigned char *xplusd=
159  static_cast<unsigned char *>(alloca(bank.PrimeLength()));
160 
161  // generate y=x|hash(x)
162  memset(xplusd,'\0',nCoinLength);
163  BN_bn2bin(m_bnCoinID,xplusd);
164 
165  for(int n=0 ; n < nDigestIterations ; ++n)
166  SHA1(xplusd,nCoinLength+DIGEST_LENGTH*n,
167  &xplusd[nCoinLength+DIGEST_LENGTH*n]);
168 
169  HexDump("x|hash(x)=",xplusd,
170  nCoinLength+nDigestIterations*DIGEST_LENGTH);
171 
172  BN_bin2bn(xplusd,nCoinLength+nDigestIterations*DIGEST_LENGTH,bnNumber);
173  DumpNumber("y= ",bnNumber);
174 
175  return true;
176  }
void DumpNumber(BIO *out, const char *szTitle, const BIGNUM *bn, const char *szTrailer=_NL)
BIGNUM * m_bnCoinID
Definition: bank.h:119
int CoinLength() const
Definition: bank.h:67
void HexDump(BIO *out, const char *szTitle, const unsigned char *acBuf, int nLength)
#define DIGEST_LENGTH
Definition: bank.h:15
int PrimeLength() const
Definition: bank.h:71
BIGNUM* UnsignedCoin::ID ( )
inline

Definition at line 148 of file bank.h.

149  { return m_bnCoinID; }
BIGNUM * m_bnCoinID
Definition: bank.h:119
void UnsignedCoin::Random ( int  nCoinLength)
inline

Definition at line 137 of file bank.h.

138  {
139  if(!m_bnCoinID)
140  m_bnCoinID=BN_new();
141  // choose x
142  BN_rand(m_bnCoinID,nCoinLength*8,0,1);
143  DumpNumber("x= ",m_bnCoinID);
144 
145  assert(BN_num_bytes(m_bnCoinID) == nCoinLength);
146  }
void DumpNumber(BIO *out, const char *szTitle, const BIGNUM *bn, const char *szTrailer=_NL)
BIGNUM * m_bnCoinID
Definition: bank.h:119
void UnsignedCoin::ReadBIO ( BIO *  bio)
void UnsignedCoin::Set ( const BIGNUM *  bnCoinID)
inline

Definition at line 132 of file bank.h.

133  {
134  Clear();
135  m_bnCoinID=BN_dup(bnCoinID);
136  }
BIGNUM * m_bnCoinID
Definition: bank.h:119
void Clear()
Definition: bank.h:127
void UnsignedCoin::WriteBIO ( BIO *  bio)

Member Data Documentation

BIGNUM* UnsignedCoin::m_bnCoinID
protected

Definition at line 119 of file bank.h.


The documentation for this class was generated from the following file: