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

BIGNUM_xor.cc

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: BIGNUM_xor.cc,v 1.3 2004/05/19 15:56:46 mmarsh Exp $
00008 //
00009 // $Log: BIGNUM_xor.cc,v $
00010 // Revision 1.3  2004/05/19 15:56:46  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:31:47  mmarsh
00014 // *** empty log message ***
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 }

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