"Fossies" - the Fresh Open Source Software Archive

Member "libmcrypt-2.5.8/modules/algorithms/panama.h" (24 May 2002, 3276 Bytes) of package /linux/privat/old/libmcrypt-2.5.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "panama.h" see the Fossies "Dox" file reference documentation.

    1 /* panama.h */
    2 
    3 /**************************************************************************+
    4 *
    5 *  PANAMA high-performance reference C-code, based on the description in 
    6 *  the paper 'Fast Hashing and Stream Encryption with PANAMA', presented 
    7 *  at the Fast Software Encryption Workshop, Paris, 1998, see "Fast 
    8 *  Software Encryption - 5th International Workshop, FSE'98", edited by 
    9 *  Serge Vaudenay, LNCS-1372, Springer-Verlag, 1998, pp 60-74, also 
   10 *  available on-line at http://standard.pictel.com/ftp/research/security
   11 *
   12 *  Algorithm design by Joan Daemen and Craig Clapp
   13 *
   14 *  panama.h  -  Header file for Panama C-code implementation.
   15 *
   16 *
   17 *  History:
   18 *
   19 *  29-Oct-98  Craig Clapp  Implemention for Dr. Dobbs, Dec. 1998 issue, 
   20 *                          based on earlier performance-benchmark code.
   21 *
   22 *
   23 *  Notes:  This code is supplied for the purposes of evaluating the 
   24 *          performance of the Panama stream/hash module and as a 
   25 *          reference implementation for generating test vectors for 
   26 *          compatibility / interoperability verification.
   27 *
   28 *
   29 +**************************************************************************/
   30 
   31 #ifndef NULL
   32 #define NULL 0
   33 #endif
   34 
   35 #define WORDLENGTH   32
   36 #define ONES         0xffffffffL
   37 
   38 
   39 /* standard C idioms for Microsoft and TriMedia compiler features */
   40 #define restrict        /* 'restrict' keyword is not part of ANSI C, null it out */
   41 #define ROTL32(a,shift)  (((a) << (shift)) | ((a) >> (WORDLENGTH - (shift))))
   42 
   43 
   44 
   45 /****** structure definitions ******/
   46 
   47 #define PAN_STAGE_SIZE   8
   48 #define PAN_STAGES       32
   49 #define PAN_STATE_SIZE   17
   50 
   51 
   52 typedef struct {
   53     word32 word[PAN_STAGE_SIZE];
   54 } PAN_STAGE;
   55 
   56 typedef struct {
   57     PAN_STAGE stage[PAN_STAGES];
   58     int tap_0;
   59 } PAN_BUFFER;
   60 
   61 typedef struct {
   62     word32 word[PAN_STATE_SIZE];
   63 } PAN_STATE;
   64 
   65 typedef struct {
   66     PAN_BUFFER buffer;
   67     PAN_STATE state;
   68     word32 wkeymat[8];
   69     byte *keymat;
   70     int keymat_pointer;
   71 } PANAMA_KEY;
   72 
   73 
   74 /****** function prototypes ******/
   75 
   76 static void pan_pull(word32 * restrict In,  /* input array                    */
   77           word32 * restrict Out,    /* output array                   */
   78           word32 pan_blocks,    /* number of blocks to be Pulled  */
   79           PAN_BUFFER * restrict buffer, /* LFSR buffer                    */
   80           PAN_STATE * restrict state);  /* 17-word finite-state machine   */
   81 
   82 static void pan_push(word32 * restrict In,  /* input array                    */
   83           word32 pan_blocks,    /* number of blocks to be Pushed  */
   84           PAN_BUFFER * restrict buffer, /* LFSR buffer                    */
   85           PAN_STATE * restrict state);  /* 17-word finite-state machine   */
   86 
   87 static void pan_reset(PAN_BUFFER * buffer, PAN_STATE * state);
   88 
   89 #ifndef USE_MODULES
   90 void _mcrypt_panama_set_key(PANAMA_KEY * pan_key, char *in_key, int keysize,
   91              char *init_vec, int vecsize);
   92 void _mcrypt_panama_encrypt(PANAMA_KEY * pan_key, byte * buf, int length);
   93 void _mcrypt_panama_decrypt(PANAMA_KEY * pan_key, byte * buf, int length);
   94 int _mcrypt_panama_get_size ();
   95 int _mcrypt_panama_get_block_size();
   96 int _panama_is_block_algorithm();
   97 int _mcrypt_panama_get_key_size();
   98 int _mcrypt_panama_get_supported_key_sizes(int *size);
   99 char * _mcrypt_panama_get_algorithms_name();
  100 int _mcrypt_panama_self_test();
  101 word32 _mcrypt_panama_algorithm_version();
  102 #endif