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

/ray/src/lib/crypto/bcipherbase.cc

Go to the documentation of this file.
00001 /*
00002  * lib/crypto/bcipherbase.cc
00003  * 
00004  * Implementation of "cryptographic" null - block cipher (doing nothing). 
00005  * 
00006  * Copyright (c) 2001--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "bcipherbase.h"
00018 
00019 
00020 const size_t BLOCKSIZE=8;  // we may change that 
00021 
00022 static const size_t null_par_kl[9]={8,16,24,32,48,64,96,128,256};
00023 
00024 const BlockCipherBase::Parameters BlockCipherBase::par = 
00025 {
00026     INIT_FIELD(block_size) BLOCKSIZE,
00027     INIT_FIELD(n_key_lengths) 9,
00028     INIT_FIELD(key_length) null_par_kl,
00029     INIT_FIELD(cipher_ID) 0x0000,
00030     INIT_FIELD(name) "null"
00031 };
00032 
00033 
00034 int BlockCipherBase::SetKey(char * /*key*/,size_t len)
00035 {
00036     for(int i=0; i<par.n_key_lengths; i++)
00037     {  if(par.key_length[i]==len)  return(0);  }
00038     return(-2);
00039 }
00040 
00041 
00042 // The "null" cipher never has a weak key, has it? ;)
00043 int BlockCipherBase::CheckWeakKey()
00044 {
00045     return(0);
00046 }
00047 
00048 
00049 void BlockCipherBase::EncryptBlock(char *ibuf,char *obuf)
00050 {
00051     // Simply copy. 
00052     if(ibuf==obuf)  return;
00053     for(char *iend=ibuf+BLOCKSIZE; ibuf<iend; ibuf++,obuf++)
00054     {  *obuf=*ibuf;  }
00055 }
00056 
00057 
00058 void BlockCipherBase::DecryptBlock(char *ibuf,char *obuf)
00059 {
00060     // Simply copy. 
00061     if(ibuf==obuf)  return;
00062     for(char *iend=ibuf+BLOCKSIZE; ibuf<iend; ibuf++,obuf++)
00063     {  *obuf=*ibuf;  }
00064 }
00065 
00066 
00067 int BlockCipherBase::CopyFrom(BlockCipherBase *bcb)
00068 {
00069     if(!bcb || bcb->GetPar()->cipher_ID!=par.cipher_ID)  return(-2);
00070     // Nothing to do...
00071     return(0);
00072 }

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5