Bunny2.0

- Main Page
- Classes
- Files

- File List

Headers/Bunny.h

    00001
    00002 #ifndef BUNNY_H
    00003 #define BUNNY_H
    00004
    00005 #include <iostream>
    00006 #include <stdio.h>
    00007 #include <stdlib.h>
    00008 #include <time.h>
    00009 #include <iomanip> // to use the function setw()
    00010 #include <bitset> // to use the bitset class
    00011 #include <vector>
    00012
    00013 #include <math.h>
    00014
    00015 #include <sstream>
    00016
    00017 #include "myFunctions.h"
    00018
    00019
    00020 #ifndef ASSERT1
    00021   #include <sstream>
    00022   #define ASSERT1(COND,MSG)                                     \
    00023     if ( !(COND) ) {                                            \
    00024       std::ostringstream ost ;                                  \
    00025       ost << "\n--------------------------------------------"   \
    00026           << "\nfile: " << __FILE__                             \
    00027           << "\nline: " << __LINE__                             \
    00028           << '\n' << MSG << '\n'                                \
    00029           << "\n--------------------------------------------" ; \
    00030       throw std::runtime_error(ost.str()) ;                     \
    00031     }
    00032 #endif
    00033
    00034 #ifndef ASSERT
    00035   #define ASSERT(COND,MSG)                                       \
    00036     if ( !(COND) ) {                                             \
    00037       cerr << "\n--------------------------------------------"   \
    00038            << "\nfile: " << __FILE__                             \
    00039            << "\nline: " << __LINE__                             \
    00040            << '\n' << MSG << '\n'                                \
    00041            << "\n--------------------------------------------" ; \
    00042       exit(1) ;                                                  \
    00043     }
    00044 #endif
    00045
    00046
    00047 using namespace std;
    00048
    00049
    00051
    00054 template <unsigned nb_msg, unsigned nb_key, unsigned nb_sbox, unsigned nround>
    00055 class Bunny {
    00056   public:
    00058     typedef bitset<nb_msg>       msgType ;
    00059
    00061     typedef bitset<nb_key>       keyType ;
    00062
    00064     typedef bitset<nb_sbox>     sboxType ;
    00065
    00067     typedef bitset<nb_sbox*4>     wordType ;
    00068
    00070
    00071     typedef vector<keyType> roundkeyType ;
    00072
    00074         roundkeyType rk;
    00075
    00076     // CONSTRUCTORS
    00077         Bunny() ;
    00078
    00079     // Print functions
    00080     void printParameter() ;
    00081
    00082     // CODING FUNCTIONS
    00083         virtual msgType encode( msgType m, keyType k ) ;
    00084         virtual msgType decode( msgType m, keyType k ) ;
    00085
    00086
    00087   //protected:
    00088   //se le metto protected non posso testarle????????????
    00089
    00090     // ROUND FUNCTIONS
    00091
    00092     // Sbox
    00093     virtual sboxType sbox( unsigned nbox, sboxType x ) = 0 ; //" = 0 " means declared as pure virtual, i.e. it will always be declared in class inheriting from this class
    00094     virtual sboxType sboxInverse( unsigned nbox, sboxType x ) = 0 ;
    00095
    00096     virtual msgType sBox (msgType m) ; // sBox based on sbox
    00097     virtual msgType sBoxInverse (msgType m)  ; // sBox based on sbox
    00098
    00099
    00100     // Mixing layer
    00101     virtual msgType mixingLayer (msgType m ) = 0;
    00102     virtual msgType mixingLayerInverse (msgType m ) = 0;
    00103
    00104     //Add round key
    00105     virtual msgType addRoundKey (msgType m, msgType k) ;
    00106
    00107
    00108         // KEY SCHEDULE
    00109     virtual void keySchedule(keyType k) ;
    00110
    00111     // MISC FUNCTIONS
    00112         sboxType extractBlock              ( unsigned nblk, msgType x ) ;
    00113     sboxType extractFromWordToSboxType ( unsigned pos, wordType x ) ;
    00114         msgType  insertBlock               ( msgType m, unsigned nblk, sboxType x ) ;
    00115     keyType  copyIntoKey               (keyType m, unsigned pos, wordType x) ;
    00116     wordType copyIntoWord              (wordType m, unsigned pos, sboxType x) ;
    00117     wordType extractWord               ( unsigned pos, keyType x ) ;
    00118
    00119 } ;
    00120
    00121 #include "Bunny.hxx"
    00122
    00123 #endif
    00124

All Classes Functions Variables Typedefs