Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013
00014
00015 #include <stdio.h>
00016
00017 #ifndef __RIJNDAEL_ALG_H
00018 #define __RIJNDAEL_ALG_H
00019
00020 #define MAXKC (256/32)
00021 #define MAXROUNDS 14
00022
00023 typedef unsigned char word8;
00024 typedef unsigned short word16;
00025 typedef unsigned int word32;
00026
00027 int rijndaelKeySched (word8 k[MAXKC][4], int keyBits,
00028 word8 rk[MAXROUNDS+1][4][4]);
00029 int rijndaelKeyEnctoDec (int keyBits, word8 W[MAXROUNDS+1][4][4]);
00030 int rijndaelEncrypt (word8 a[16], word8 b[16],
00031 word8 rk[MAXROUNDS+1][4][4]);
00032 int rijndaelEncryptRound (word8 a[4][4],
00033 word8 rk[MAXROUNDS+1][4][4], int rounds);
00034 int rijndaelDecrypt (word8 a[16], word8 b[16],
00035 word8 rk[MAXROUNDS+1][4][4]);
00036 int rijndaelDecryptRound (word8 a[4][4],
00037 word8 rk[MAXROUNDS+1][4][4], int rounds);
00038
00039 #endif
00040
00041
00042
00043
00044 #ifndef __RIJNDAEL_API_H
00045 #define __RIJNDAEL_API_H
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 #define DIR_ENCRYPT 0 // Are we encrpyting?
00056 #define DIR_DECRYPT 1 // Are we decrpyting?
00057 #define MODE_ECB 1 // Are we ciphering in ECB mode?
00058 #define MODE_CBC 2 // Are we ciphering in CBC mode?
00059 #define MODE_CFB1 3 // Are we ciphering in 1-bit CFB mode?
00060 #ifndef TRUE
00061 #define TRUE 1
00062 #endif
00063 #ifndef FALSE
00064 #define FALSE 0
00065 #endif
00066 #define BITSPERBLOCK 128 // Default number of bits in a cipher block
00067
00068
00069 #define BAD_KEY_DIR -1 // Key direction is invalid, e.g., unknown value
00070 #define BAD_KEY_MAT -2 // Key material not of correct length
00071 #define BAD_KEY_INSTANCE -3 // Key passed is not valid
00072 #define BAD_CIPHER_MODE -4 // Params struct passed to cipherInit invalid
00073 #define BAD_CIPHER_STATE -5 // Cipher in wrong state (e.g., not initialized)
00074 #define BAD_BLOCK_LENGTH -6
00075 #define BAD_CIPHER_INSTANCE -7
00076
00077
00078
00079
00080 #define MAX_KEY_SIZE 32 // # of unsigned char's needed to represent a key
00081 #define MAX_IV_SIZE 16 // # bytes needed to represent an IV
00082
00083
00084
00085
00086 typedef unsigned char BYTE;
00087
00088
00089 typedef struct {
00090 BYTE direction;
00091 int keyLen;
00092 char keyMaterial[MAX_KEY_SIZE+1];
00093
00094 int blockLen;
00095 word8 keySched[MAXROUNDS+1][4][4];
00096 } keyInstance;
00097
00098
00099 typedef struct {
00100 BYTE mode;
00101 BYTE IV[MAX_IV_SIZE];
00102
00103 int blockLen;
00104 } cipherInstance;
00105
00106
00107
00108
00109
00110
00111
00112 int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial);
00113
00114 int cipherInit(cipherInstance *cipher, BYTE mode, char *IV);
00115
00116 int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input,
00117 int inputLen, BYTE *outBuffer);
00118
00119 int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input,
00120 int inputLen, BYTE *outBuffer);
00121 int cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, BYTE *input,
00122 int inputLen, BYTE *outBuffer, int Rounds);
00123
00124
00125 #endif // __RIJNDAEL_API_H