Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

CombinatoricThresholdVarRSA.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: CombinatoricThresholdVarRSA.h,v 1.3 2004/05/19 15:57:00 mmarsh Exp $
00008 //
00009 // $Log: CombinatoricThresholdVarRSA.h,v $
00010 // Revision 1.3  2004/05/19 15:57:00  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:51  mmarsh
00014 // *** empty log message ***
00015 //
00016 //
00017 
00018 #ifndef __CODEX_THRESHOLDCRYPTO_COMBINATORICTHRESHOLDVARRSA_H__
00019 #define __CODEX_THRESHOLDCRYPTO_COMBINATORICTHRESHOLDVARRSA_H__
00020 
00021 #include <fstream>
00022 
00023 #include "ThresholdVarRSA.h"
00024 #include "CODEX_VSS/Combinatoric.h"
00025 
00026 #include "timing.h"
00027 
00028 namespace CODEX_ThresholdCrypto
00029 {
00031    template< unsigned int NumT , unsigned int ThreshT >
00032    class ThresholdVarRSACrypto< CODEX_VSS::Combinatoric< NumT , ThreshT > >
00033    {
00034       public :
00036          typedef CODEX_VSS::Combinatoric< NumT , ThreshT >  ShareType;
00037 
00039          typedef CODEX_VSS::ShareSet< ShareType >           SetType;
00040 
00042          ThresholdVarRSACrypto( const CODEX_ASN1::BigNumber& modulus ) :
00043             m_modulus( modulus )
00044          {
00045          }
00046 
00050          void sign( const ShareType& shares,
00051                     const BIGNUM * message,
00052                     ShareType& partials ) const
00053          {
00054 #ifdef TIMING
00055             PartialSigTimer.start();
00056 #endif
00057             CODEX_VSS::ModExpFunctional f( BN_dup(message), m_modulus );
00058             shares.apply( f, partials );
00059 #ifdef TIMING
00060             PartialSigTimer.stop();
00061 #endif
00062          }
00063 
00067          void decrypt( const ShareType& shares,
00068                        const CODEX_Ciphers::VarRSACipherText& ciphertext,
00069                        ShareType& partials ) const
00070          {
00071 #ifdef TIMING
00072             //PartialDecTimer.start();
00073             PartialRSADecTimer.start();
00074 #endif
00075             CODEX_VSS::ModExpFunctional f( ciphertext.c1(), m_modulus );
00076             shares.apply( f, partials );
00077 #ifdef TIMING
00078             //PartialDecTimer.stop();
00079             PartialRSADecTimer.stop();
00080 #endif
00081          }
00082 
00086          void decrypt( const ShareType& shares,
00087                        const CODEX_Ciphers::VarRSABlindCipherText& ciphertext,
00088                        ShareType& partials ) const
00089          {
00090 #ifdef TIMING
00091             //PartialDecTimer.start();
00092             PartialRSADecTimer.start();
00093 #endif
00094             CODEX_VSS::ModExpFunctional f( ciphertext.c1(), m_modulus );
00095             shares.apply( f, partials );
00096 #ifdef TIMING
00097             //PartialDecTimer.stop();
00098             PartialRSADecTimer.stop();
00099 #endif
00100          }
00101 
00112          BIGNUM* threshold( const SetType& partials ) const
00113          {
00114 #ifdef TIMING
00115             ThresholdSigTimer.start();
00116 #endif
00117             for ( unsigned int i = 0 ; i < ShareType::NumShares ; ++i )
00118             {
00119                if ( ! partials(i).initialized() )
00120                {
00121 #ifdef TIMING
00122                   ThresholdSigTimer.stop();
00123 #endif
00124                   return 0;
00125                }
00126             }
00127             const BIGNUM * n = m_modulus.value();
00128             BIGNUM * s = 0;
00129             BN_CTX * ctx = 0;
00130             try
00131             {
00132                ctx = BN_CTX_new();
00133                if ( 0 == ctx )
00134                {
00135                   throw CODEX_Exceptions::BignumContextException( __FILE__ ,
00136                                                                   __LINE__ );
00137                }
00138                s = BN_new();
00139                if ( 0 == s )
00140                {
00141                   throw CODEX_Exceptions::BignumNullException( __FILE__ ,
00142                                                                __LINE__ );
00143                }
00144                BN_one(s); // This should never fail.
00145                for ( unsigned int i = 0 ; i < ShareType::NumShares ; ++i )
00146                {
00147                   const BIGNUM * share = partials(i).value();
00148                   if ( ! BN_mod_mul( s, s, share, n, ctx ) )
00149                   {
00150                      throw CODEX_Exceptions::BignumModMulException( __FILE__ ,
00151                                                                     __LINE__ );
00152                   }
00153                }
00154             }
00155             catch ( ... )
00156             {
00157                if ( 0 != s ) BN_free(s);
00158                if ( 0 != ctx ) BN_CTX_free(ctx);
00159 #ifdef TIMING
00160                ThresholdSigTimer.stop();
00161 #endif
00162                throw;
00163             }
00164             BN_CTX_free(ctx);
00165 #ifdef TIMING
00166             ThresholdSigTimer.stop();
00167 #endif
00168             return s;
00169          }
00170 
00171       private :
00172          CODEX_ASN1::BigNumber  m_modulus;
00173    };
00174 
00175 }
00176 
00177 #endif /* __CODEX_THRESHOLDCRYPTO_COMBINATORICTHRESHOLDVARRSA_H__ */

Generated on Fri May 6 17:38:55 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1