source: tools/traceanon/rijndael.h @ 361d283

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 361d283 was 0e66585, checked in by Shane Alcock <salcock@…>, 13 years ago
  • Fixed function prototypes that were accidentally commented out a while back
  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[49f147b]1#ifndef _RIJNDAEL_H_
2#define _RIJNDAEL_H_
3
[853603a]4/* $Id$
[49f147b]5//
6// File : rijndael.h
7// Creation date : Sun Nov 5 2000 03:21:05 CEST
8// Author : Szymon Stefanek (stefanek@tin.it)
9//
10// Another implementation of the Rijndael cipher.
11// This is intended to be an easily usable library file.
12// This code is public domain.
13// Based on the Vincent Rijmen and K.U.Leuven implementation 2.4.
[853603a]14*/
[49f147b]15
[853603a]16/*
[49f147b]17// Original Copyright notice:
18//
19//    rijndael-alg-fst.c   v2.4   April '2000
20//    rijndael-alg-fst.h
21//    rijndael-api-fst.c
22//    rijndael-api-fst.h
23//
24//    Optimised ANSI C code
25//
26//    authors: v1.0: Antoon Bosselaers
27//             v2.0: Vincent Rijmen, K.U.Leuven
28//             v2.3: Paulo Barreto
29//             v2.4: Vincent Rijmen, K.U.Leuven
30//
31//    This code is placed in the public domain.
[853603a]32*/
[49f147b]33
[853603a]34/*
[49f147b]35// This implementation works on 128 , 192 , 256 bit keys
36// and on 128 bit blocks
[853603a]37*/
[49f147b]38
[853603a]39/*
[49f147b]40// Example of usage:
41//
42//  // Input data
43//  unsigned char key[32];                       // The key
44//  initializeYour256BitKey();                   // Obviously initialized with sth
45//  const unsigned char * plainText = getYourPlainText(); // Your plain text
46//  int plainTextLen = strlen(plainText);        // Plain text length
47//
48//  // Encrypting
49//  Rijndael rin;
50//  unsigned char output[plainTextLen + 16];
51//
52//  rin.init(Rijndael::CBC,Rijndael::Encrypt,key,Rijndael::Key32Bytes);
53//  // It is a good idea to check the error code
54//  int len = rin.padEncrypt(plainText,len,output);
55//  if(len >= 0)useYourEncryptedText();
56//  else encryptError(len);
57//
58//  // Decrypting: we can reuse the same object
59//  unsigned char output2[len];
60//  rin.init(Rijndael::CBC,Rijndael::Decrypt,key,Rijndael::Key32Bytes));
61//  len = rin.padDecrypt(output,len,output2);
62//  if(len >= 0)useYourDecryptedText();
63//  else decryptError(len);
[853603a]64*/
[49f147b]65
66#define _MAX_KEY_COLUMNS (256/32)
67#define _MAX_ROUNDS      14
68#define MAX_IV_SIZE      16
69
[853603a]70/* We assume that unsigned int is 32 bits long....  */
[49f147b]71typedef unsigned char  UINT8;
72typedef unsigned int   UINT32;
73typedef unsigned short UINT16;
74
[853603a]75/* Error codes */
[49f147b]76#define RIJNDAEL_SUCCESS 0
77#define RIJNDAEL_UNSUPPORTED_MODE -1
78#define RIJNDAEL_UNSUPPORTED_DIRECTION -2
79#define RIJNDAEL_UNSUPPORTED_KEY_LENGTH -3
80#define RIJNDAEL_BAD_KEY -4
81#define RIJNDAEL_NOT_INITIALIZED -5
82#define RIJNDAEL_BAD_DIRECTION -6
83#define RIJNDAEL_CORRUPTED_DATA -7
84
[853603a]85/*class Rijndael
[49f147b]86//{     
87//public:
[853603a]88*/
[49f147b]89
90enum Direction_e { Encrypt , Decrypt };
91enum Mode_e { ECB , CBC , CFB1 };
92enum KeyLength_e { Key16Bytes , Key24Bytes , Key32Bytes };
93enum State_e { Valid , Invalid };
94
95typedef enum Mode_e Mode;
96typedef enum Direction_e Direction;
97typedef enum KeyLength_e KeyLength;
98typedef enum State_e State;
[853603a]99/*
[49f147b]100// Creates a Rijndael cipher object
101// You have to call init() before you can encrypt or decrypt stuff
102//
103//      Rijndael();
104//      ~Rijndael();
105//protected:
106//      // Internal stuff
107
108//public:
109        //////////////////////////////////////////////////////////////////////////////////////////
110        // API
111        //////////////////////////////////////////////////////////////////////////////////////////
112
113        // init(): Initializes the crypt session
114        // Returns RIJNDAEL_SUCCESS or an error code
115        // mode      : Rijndael::ECB, Rijndael::CBC or Rijndael::CFB1
116        //             You have to use the same mode for encrypting and decrypting
117        // dir       : Rijndael::Encrypt or Rijndael::Decrypt
118        //             A cipher instance works only in one direction
119        //             (Well , it could be easily modified to work in both
120        //             directions with a single init() call, but it looks
121        //             useless to me...anyway , it is a matter of generating
122        //             two expanded keys)
123        // key       : array of unsigned octets , it can be 16 , 24 or 32 bytes long
124        //             this CAN be binary data (it is not expected to be null terminated)
125        // keyLen    : Rijndael::Key16Bytes , Rijndael::Key24Bytes or Rijndael::Key32Bytes
126        // initVector: initialization vector, you will usually use 0 here
[0e66585]127*/
[49f147b]128int rijndael_init(Mode mode, Direction dir, const UINT8 *key, KeyLength keyLen, UINT8 * initVector);
129
[0e66585]130/*
[49f147b]131  // Encrypts the input array (can be binary data)
132        // The input array length must be a multiple of 16 bytes, the remaining part
133        // is DISCARDED.
134        // so it actually encrypts inputLen / 128 blocks of input and puts it in outBuffer
135        // Input len is in BITS!
136        // outBuffer must be at least inputLen / 8 bytes long.
137        // Returns the encrypted buffer length in BITS or an error code < 0 in case of error
[0e66585]138*/
[49f147b]139int blockEncrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer);
[0e66585]140
141/*
142        // Encrypts the input array (can be binary data)
[49f147b]143        // The input array can be any length , it is automatically padded on a 16 byte boundary.
144        // Input len is in BYTES!
145        // outBuffer must be at least (inputLen + 16) bytes long
146        // Returns the encrypted buffer length in BYTES or an error code < 0 in case of error
[0e66585]147*/
[49f147b]148int padEncrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer);
[0e66585]149
150/*
151        // Decrypts the input vector
[49f147b]152        // Input len is in BITS!
153        // outBuffer must be at least inputLen / 8 bytes long
154        // Returns the decrypted buffer length in BITS and an error code < 0 in case of error
[0e66585]155*/
[49f147b]156int blockDecrypt(const UINT8 *input, int inputLen, UINT8 *outBuffer);
[0e66585]157
158/*
[49f147b]159        // Decrypts the input vector
160        // Input len is in BYTES!
161        // outBuffer must be at least inputLen bytes long
162        // Returns the decrypted buffer length in BYTES and an error code < 0 in case of error
[0e66585]163*/
[49f147b]164int padDecrypt(const UINT8 *input, int inputOctets, UINT8 *outBuffer);
[0e66585]165/*protected:*/
166/*
[49f147b]167void keySched(UINT8 key[_MAX_KEY_COLUMNS][4]);
168void keyEncToDec();
[41b53c2]169void r_encrypt(const UINT8 a[16], UINT8 b[16]);
170void r_decrypt(const UINT8 a[16], UINT8 b[16]);
[853603a]171*/
[0e66585]172/*};*/
[49f147b]173       
[853603a]174#endif /* _RIJNDAEL_H_ */
Note: See TracBrowser for help on using the repository browser.