00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "BIGNUM_xor.h"
00019 #include "CODEX_Exceptions/BignumExceptions.h"
00020
00021 using namespace CODEX_Ciphers;
00022
00023 BIGNUM *
00024 CODEX_Ciphers::BIGNUM_xor( BIGNUM * r , const BIGNUM * a , const BIGNUM * b )
00025 {
00026 if ( 0 == a )
00027 {
00028 throw CODEX_Exceptions::BignumNullException( __FILE__ , __LINE__ );
00029 }
00030 if ( 0 == b )
00031 {
00032 throw CODEX_Exceptions::BignumNullException( __FILE__ , __LINE__ );
00033 }
00034
00035 BIGNUM * retVal = 0;
00036 if ( 0 != r )
00037 {
00038 retVal = r;
00039 }
00040 else
00041 {
00042 retVal = BN_new();
00043 if ( 0 == retVal )
00044 {
00045 throw CODEX_Exceptions::BignumNullException( __FILE__ , __LINE__ );
00046 }
00047 }
00048 BN_clear( retVal );
00049
00050 const BIGNUM *at, *bt;
00051
00052 if ( a->top < b->top )
00053 {
00054 at = b;
00055 bt = a;
00056 }
00057 else
00058 {
00059 at = a;
00060 bt = b;
00061 }
00062
00063 bn_expand2( retVal, at->top );
00064
00065 int i;
00066 for ( i = 0 ; i < bt->top ; i++ )
00067 {
00068 retVal->d[i] = at->d[i] ^ bt->d[i];
00069 }
00070 for ( ; i < at->top ; i++ )
00071 {
00072 retVal->d[i] = at->d[i];
00073 }
00074
00075 retVal->top = at->top;
00076 bn_fix_top(retVal);
00077 return retVal;
00078 }