Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

VarRSA.h

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: VarRSA.h,v 1.3 2004/05/19 15:56:48 mmarsh Exp $
00008 //
00009 // $Log: VarRSA.h,v $
00010 // Revision 1.3  2004/05/19 15:56:48  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:08:54  mmarsh
00014 // General code cleanup.
00015 //
00016 //
00017 
00018 #ifndef __CODEX_CIPHERS_VARRSA_H__
00019 #define __CODEX_CIPHERS_VARRSA_H__
00020 
00021 #include <openssl/bn.h>
00022 #include "RSA.h"
00023 #include "HashFunction.h"
00024 
00025 // NOTES: The ciphertext must be changed to a pair of BIGNUMs.
00026 //        It also needs (un)serialization implemented.
00027 //        The blind ciphertext and plaintext need to be implemented.
00028 
00029 namespace CODEX_Ciphers
00030 {
00031    // Forward declaration
00032    class VarRSABlindCipherText;
00033 
00037    class VarRSACipherText : public CODEX_ASN1::Base
00038    {
00039       public:
00041          VarRSACipherText() :
00042             CODEX_ASN1::Base( false )
00043          {}
00045          VarRSACipherText( BIGNUM * c1, BIGNUM * c2 ) :
00046             CODEX_ASN1::Base( true ),
00047             m_c1( c1 ),
00048             m_c2( c2 )
00049          {}
00051          VarRSACipherText( const CODEX_ASN1::BigNumber& c1,
00052                            const CODEX_ASN1::BigNumber& c2 ) :
00053             CODEX_ASN1::Base( true ),
00054             m_c1( c1 ),
00055             m_c2( c2 )
00056          {}
00058          VarRSACipherText( const VarRSACipherText& aOther ) :
00059             CODEX_ASN1::Base( aOther.m_initialized ),
00060             m_c1( aOther.m_c1 ),
00061             m_c2( aOther.m_c2 )
00062          {
00063          }
00065          virtual ~VarRSACipherText() {}
00066 
00068          void operator=( const VarRSACipherText& aOther );
00069 
00071          bool operator==( const VarRSACipherText& aBN ) const;
00072 
00074          bool operator!=( const VarRSACipherText& aBN ) const;
00075 
00080          const CODEX_ASN1::BigNumber& c1() const { return m_c1; }
00085          const CODEX_ASN1::BigNumber& c2() const { return m_c2; }
00086 
00094          VarRSABlindCipherText* blind(
00095             const RSACipherText& aOther,
00096             const CODEX_ASN1::BigNumber& modulus ) const;
00097 
00099          int marshal( unsigned char ** pp ) const;
00101          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00102 
00103       private :
00104          CODEX_ASN1::BigNumber  m_c1;
00105          CODEX_ASN1::BigNumber  m_c2;
00106    };
00107 
00114    class VarRSABlindCipherText : public CODEX_ASN1::Base
00115    {
00116       public:
00118          VarRSABlindCipherText() :
00119             CODEX_ASN1::Base( false )
00120          {}
00122          VarRSABlindCipherText( BIGNUM * c1, BIGNUM * c2 ) :
00123             CODEX_ASN1::Base( true ),
00124             m_c1( c1 ),
00125             m_c2( c2 )
00126          {}
00128          VarRSABlindCipherText( const CODEX_ASN1::BigNumber& c1,
00129                                 const CODEX_ASN1::BigNumber& c2 ) :
00130             CODEX_ASN1::Base( true ),
00131             m_c1( c1 ),
00132             m_c2( c2 )
00133          {}
00135          VarRSABlindCipherText( const VarRSABlindCipherText& aOther ) :
00136             CODEX_ASN1::Base( aOther.m_initialized ),
00137             m_c1( aOther.m_c1 ),
00138             m_c2( aOther.m_c2 )
00139          {
00140          }
00142          virtual ~VarRSABlindCipherText() {}
00143 
00145          void operator=( const VarRSABlindCipherText& aOther );
00146 
00148          bool operator<( const VarRSABlindCipherText& aOther ) const;
00149 
00154          const CODEX_ASN1::BigNumber& c1() const { return m_c1; }
00159          const CODEX_ASN1::BigNumber& c2() const { return m_c2; }
00160 
00162          int marshal( unsigned char ** pp ) const;
00164          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00165 
00166       private :
00167          CODEX_ASN1::BigNumber  m_c1;
00168          CODEX_ASN1::BigNumber  m_c2;
00169    };
00170 
00178    class VarRSABlindPlainText : public CODEX_ASN1::Base
00179    {
00180       public:
00182          VarRSABlindPlainText() :
00183             CODEX_ASN1::Base( false )
00184          {}
00186          VarRSABlindPlainText( BIGNUM * b1, BIGNUM * b2 ) :
00187             CODEX_ASN1::Base( true ),
00188             m_b1( b1 ),
00189             m_b2( b2 )
00190          {}
00192          VarRSABlindPlainText( const CODEX_ASN1::BigNumber& b1,
00193                                const CODEX_ASN1::BigNumber& b2 ) :
00194             CODEX_ASN1::Base( true ),
00195             m_b1( b1 ),
00196             m_b2( b2 )
00197          {}
00199          VarRSABlindPlainText( const VarRSABlindPlainText& aOther ) :
00200             CODEX_ASN1::Base( aOther.m_initialized ),
00201             m_b1( aOther.m_b1 ),
00202             m_b2( aOther.m_b2 )
00203          {
00204          }
00206          virtual ~VarRSABlindPlainText() {}
00207 
00209          void operator=( const VarRSABlindPlainText& aOther );
00210 
00215          const CODEX_ASN1::BigNumber& b1() const { return m_b1; }
00220          const CODEX_ASN1::BigNumber& b2() const { return m_b2; }
00221 
00230          BIGNUM * unblind( const BIGNUM * b,
00231                            const CODEX_ASN1::BigNumber& modulus,
00232                            const HashFunction& hashFunc ) const;
00233 
00235          int marshal( unsigned char ** pp ) const;
00237          void* unmarshal( void* bogus, unsigned char ** pp, long length );
00238 
00239       private :
00240          CODEX_ASN1::BigNumber  m_b1;
00241          CODEX_ASN1::BigNumber  m_b2;
00242    };
00243 
00244    typedef RSASignature VarRSASignature;
00245 
00249    class VarRSAPublicKey : public RSAPublicKey
00250    {
00251       public:
00253          VarRSAPublicKey( const RSAPublicKey& aKey );
00254 
00256          virtual ~VarRSAPublicKey() {}
00257 
00259          const CODEX_ASN1::BigNumber& n() const { return m_key.n(); }
00261          const CODEX_ASN1::BigNumber& e() const { return m_key.e(); }
00262 
00280          VarRSACipherText* encrypt( const BIGNUM * message,
00281                                     const HashFunction& hashFunc,
00282                                     BIGNUM * r=0 ) const;
00283 
00300          bool verifySignature( const VarRSASignature& signature,
00301                                const BIGNUM * message ) const
00302          {
00303             return m_key.verifySignature( signature, message );
00304          }
00305 
00306       private:
00307          const RSAPublicKey&  m_key;
00308    };
00309 
00313    class VarRSAPrivateKey : public RSAPrivateKey
00314    {
00315       public:
00317          VarRSAPrivateKey( const RSAPrivateKey& aKey );
00318 
00320          virtual ~VarRSAPrivateKey();
00321 
00323          const CODEX_ASN1::SecureBigNumber& p()   const { return m_key.p(); }
00325          const CODEX_ASN1::SecureBigNumber& q()   const { return m_key.q(); }
00327          const CODEX_ASN1::SecureBigNumber& d()   const { return m_key.d(); }
00329          const CODEX_ASN1::SecureBigNumber& n()   const { return m_key.n(); }
00331          const CODEX_ASN1::SecureBigNumber& phi() const { return m_key.phi(); }
00332 
00346          BIGNUM * decrypt( const VarRSACipherText& cipherText,
00347                            const HashFunction& hashFunc ) const;
00361          VarRSABlindPlainText* decryptBlind(
00362             const VarRSABlindCipherText& cipherText ) const;
00377          VarRSASignature* sign( const BIGNUM * message ) const
00378          {
00379             return m_key.sign( message );
00380          }
00381 
00382       private:
00383          const RSAPrivateKey&  m_key;
00384    };
00385 
00386 }
00387 
00388 #endif /* __CODEX_CIPHERS_VARRSA_H__ */

Generated on Wed Jun 2 16:32:57 2004 for COrnell Data EXchange (CODEX) by doxygen1.2.18