00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "RSA.h"
00019 #include "CODEX_Exceptions/BignumExceptions.h"
00020
00021 using namespace CODEX_Ciphers;
00022
00023 RSACipherText*
00024 RSACipherText::blind( const RSACipherText& aOther,
00025 const CODEX_ASN1::BigNumber& modulus ) const
00026 {
00027 RSACipherText* retVal = 0;
00028
00029 const BIGNUM * kbn = value();
00030 const BIGNUM * b = aOther.value();
00031 const BIGNUM * n = modulus.value();
00032 BIGNUM * bk = 0;
00033 BN_CTX * ctx = 0;
00034 try
00035 {
00036 ctx = BN_CTX_new();
00037 if ( 0 == ctx )
00038 {
00039 throw CODEX_Exceptions::BignumContextException( __FILE__ , __LINE__ );
00040 }
00041 bk = BN_new();
00042 if ( 0 == bk )
00043 {
00044 throw CODEX_Exceptions::BignumNullException( __FILE__ , __LINE__ );
00045 }
00046 if ( ! BN_mod_mul( bk, b, kbn, n, ctx ) )
00047 {
00048 throw CODEX_Exceptions::BignumModMulException( __FILE__ , __LINE__ );
00049 }
00050 retVal = new RSACipherText( bk );
00051 bk = 0;
00052 BN_CTX_free( ctx );
00053 ctx = 0;
00054 return retVal;
00055 }
00056 catch ( ... )
00057 {
00058 if ( 0 != ctx ) BN_CTX_free( ctx );
00059 if ( 0 != bk ) BN_free( bk );
00060 throw;
00061 }
00062 }