00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __CODEX_VSS_COMBINATORICFELDMAN_H__
00019 #define __CODEX_VSS_COMBINATORICFELDMAN_H__
00020
00021 #include "Combinatoric.h"
00022 #include "ModExpFunctional.h"
00023 #include "ShareLabel.h"
00024 #include "VRecon.h"
00025
00026 namespace CODEX_VSS
00027 {
00032 template< unsigned int N , unsigned int T >
00033 class VRecon< Combinatoric< N , T > , ModExpFunctional >
00034 {
00035 public :
00037 typedef Combinatoric< N , T > ShareType;
00038
00040 typedef ModExpFunctional OneWay;
00041
00043 typedef CODEX_ASN1::BigNumber ValueType;
00044
00046 static const unsigned int NumShares = ShareType::NumShares;
00047
00049 VRecon( const OneWay& func ) : m_modulus( func.modulus() ) {}
00050
00057 void operator()( const ValueType vc[ NumShares ], ValueType& result )
00058 {
00059 const BIGNUM * n = m_modulus.value();
00060 BIGNUM * product = 0;
00061 BN_CTX * ctx = 0;
00062 try
00063 {
00064 product = BN_dup( BN_value_one() );
00065 if ( 0 == product )
00066 {
00067 throw CODEX_Exceptions::BignumNullException( __FILE__ ,
00068 __LINE__ );
00069 }
00070 ctx = BN_CTX_new();
00071 if ( 0 == ctx )
00072 {
00073 throw CODEX_Exceptions::BignumContextException( __FILE__ ,
00074 __LINE__ );
00075 }
00076 for ( unsigned int i = 0 ; i < NumShares ; ++i )
00077 {
00078 if ( ! vc[i].initialized() )
00079 {
00080 throw CODEX_Exceptions::BignumNullException( __FILE__ ,
00081 __LINE__ );
00082 }
00083 const BIGNUM * w = vc[i].value();
00084 if ( ! BN_mod_mul( product, product, w, n, ctx ) )
00085 {
00086 throw CODEX_Exceptions::BignumModMulException( __FILE__ ,
00087 __LINE__ );
00088 }
00089 }
00090 result = ValueType( product );
00091 BN_CTX_free(ctx);
00092 }
00093 catch ( ... )
00094 {
00095 if ( 0 != product ) BN_free(product);
00096 if ( 0 != ctx ) BN_CTX_free(ctx);
00097 throw;
00098 }
00099 }
00100
00104 bool checkShare( const ValueType checks[ NumShares ],
00105 const ShareType& share,
00106 const OneWay& func )
00107 {
00108 ValueType vc;
00109 for ( unsigned int i = 0 ; i < NumShares ; ++i )
00110 {
00111 if ( ! share.share(i).initialized() )
00112 {
00113 continue;
00114 }
00115
00116 func( share.share(i), vc );
00117 if ( checks[i] != vc ) return false;
00118 }
00119 return true;
00120 }
00121
00122 private :
00123 ValueType m_modulus;
00124 };
00125
00129 template< unsigned int N >
00130 struct factorial
00131 {
00133 static const unsigned int value = N*factorial<N-1>::value;
00134 };
00135
00139 template<>
00140 struct factorial<0>
00141 {
00143 static const unsigned int value = 1;
00144 };
00145
00149 template<>
00150 struct factorial<1>
00151 {
00153 static const unsigned int value = 1;
00154 };
00155
00156 }
00157
00158 #endif