SourceForge Logo
Main Page   Compound List   File List   Compound Members   File Members  

Blowfish.h

Go to the documentation of this file.
00001 /*!
00002  * \file Blowfish.h
00003  * \brief C++ implementation of the Blowfish encryption taken from the 
00004  *   FPM's modified version of GNUPG code
00005  *
00006  * \author Frederic RUAUDEL <grumz@users.sf.net>
00007  *
00008  * $Revision: 1.1 $
00009  * $Date: 2003/03/07 10:55:16 $
00010  *
00011  * \b FPMBlowfishPlugin
00012  * Copyleft (c) 2003 Frederic RUAUDEL, all rights reversed
00013  *
00014  * Copyleft (C) 1998 Free Software Foundation, Inc.
00015  *
00016  * This program is free software which I release under the GNU General Public
00017  * License. You may redistribute and/or modify this program under the terms
00018  * of that license as published by the Free Software Foundation; either
00019  * version 2 of the License, or (at your option) any later version.
00020  *
00021  * This program is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU General Public License for more details.  Version 2 is in the
00025  * COPYING file in the top level directory of this distribution.
00026  *
00027  * To get a copy of the GNU General Public License, write to the Free Software
00028  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  **/
00030 
00031 #ifndef BLOWFISH_H
00032 #define BLOWFISH_H
00033 
00034 /* Test values:
00035  * key    "abcdefghijklmnopqrstuvwxyz";
00036  * plain  "BLOWFISH"
00037  * cipher 32 4E D0 FE F4 13 A2 03
00038  *
00039  */
00040 
00041 #include <iostream>
00042 #include <stdlib.h>
00043 #include <string.h>
00044 #include <assert.h>
00045 
00046 typedef unsigned int u32;
00047 typedef unsigned char byte;
00048 
00049 #define G10ERR_SELFTEST_FAILED 50
00050 #define G10ERR_WEAK_KEY       43
00051 
00052 #define CIPHER_ALGO_BLOWFISH     4  /* blowfish 128 bit key */
00053 
00054 #define FNCCAST_SETKEY(f)  (int(*)(void*, byte*, unsigned))(f)
00055 #define FNCCAST_CRYPT(f)   (void(*)(void*, byte*, byte*))(f)
00056 
00057 #define BLOWFISH_BLOCKSIZE 8
00058 #define BLOWFISH_ROUNDS 16
00059 
00060 using namespace std;
00061 
00062 class Blowfish
00063 {
00064         public:
00065                 static const u32 ks0[];
00066                 static const u32 ks1[];
00067                 static const u32 ks2[];
00068                 static const u32 ks3[];
00069                 static const u32 ps[];
00070 
00071                 Blowfish ();
00072                 ~Blowfish ();
00073                 int  setkey (byte *key, unsigned keylen);
00074                 void encrypt_block (byte *outbuf, byte *inbuf);
00075                 void decrypt_block (byte *outbuf, byte *inbuf);
00076                 int get_blocksize (void);
00077 
00078         private:
00079                 void encrypt (u32 *ret_xl, u32 *ret_xr);
00080                 void decrypt (u32 *ret_xl, u32 *ret_xr);
00081                 const char* selftest (void);
00082 
00083                 const char *selftest_failed;
00084                 u32 s0[256];
00085                 u32 s1[256];
00086                 u32 s2[256];
00087                 u32 s3[256];
00088                 u32 p[BLOWFISH_ROUNDS+2];
00089                 int blocksize;
00090 };
00091 
00092 
00093 
00094 #endif /* BLOWFISH_H */
00095 

Generated on Sun Mar 9 11:13:59 2003 for FPMBlowfishPlugin by doxygen1.2.15