1/* $FreeBSD: head/sys/crypto/rijndael/rijndael-api-fst.h 121050 2003-10-12 21:05:05Z ume $ */ 2/* $NetBSD: rijndael-api-fst.h,v 1.5 2003/07/16 05:08:09 itojun Exp $ */ 3/* $KAME: rijndael-api-fst.h,v 1.9 2003/07/16 05:09:38 itojun Exp $ */
| 1/* $FreeBSD: head/sys/crypto/rijndael/rijndael-api-fst.h 121257 2003-10-19 21:28:34Z ume $ */ 2/* $KAME: rijndael-api-fst.h,v 1.6 2001/05/27 00:23:23 itojun Exp $ */
|
4
| 3
|
5/** 6 * rijndael-api-fst.h
| 4/* 5 * rijndael-api-fst.h v2.3 April '2000
|
7 *
| 6 *
|
8 * @version 2.9 (December 2000)
| 7 * Optimised ANSI C code
|
9 *
| 8 *
|
10 * Optimised ANSI C code for the Rijndael cipher (now AES) 11 * 12 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> 13 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> 14 * @author Paulo Barreto <paulo.barreto@terra.com.br> 15 * 16 * This code is hereby placed in the public domain. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * 30 * Acknowledgements: 31 * 32 * We are deeply indebted to the following people for their bug reports, 33 * fixes, and improvement suggestions to this implementation. Though we 34 * tried to list all contributions, we apologise in advance for any 35 * missing reference. 36 * 37 * Andrew Bales <Andrew.Bales@Honeywell.com> 38 * Markus Friedl <markus.friedl@informatik.uni-erlangen.de> 39 * John Skodon <skodonj@webquill.com>
| 9 * #define INTERMEDIATE_VALUE_KAT to generate the Intermediate Value Known Answer Test.
|
40 */ 41 42#ifndef __RIJNDAEL_API_FST_H 43#define __RIJNDAEL_API_FST_H 44 45#include <crypto/rijndael/rijndael-alg-fst.h> 46
| 10 */ 11 12#ifndef __RIJNDAEL_API_FST_H 13#define __RIJNDAEL_API_FST_H 14 15#include <crypto/rijndael/rijndael-alg-fst.h> 16
|
47/* Generic Defines */
| 17/* Defines: 18 Add any additional defines you need 19*/ 20
|
48#define DIR_ENCRYPT 0 /* Are we encrpyting? */ 49#define DIR_DECRYPT 1 /* Are we decrpyting? */ 50#define MODE_ECB 1 /* Are we ciphering in ECB mode? */ 51#define MODE_CBC 2 /* Are we ciphering in CBC mode? */ 52#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
| 21#define DIR_ENCRYPT 0 /* Are we encrpyting? */ 22#define DIR_DECRYPT 1 /* Are we decrpyting? */ 23#define MODE_ECB 1 /* Are we ciphering in ECB mode? */ 24#define MODE_CBC 2 /* Are we ciphering in CBC mode? */ 25#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */
|
53#define TRUE 1 54#define FALSE 0
| |
55#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */ 56
| 26#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */ 27
|
57/* Error Codes */
| 28/* Error Codes - CHANGE POSSIBLE: inclusion of additional error codes */
|
58#define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */ 59#define BAD_KEY_MAT -2 /* Key material not of correct length */ 60#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */ 61#define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */ 62#define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */ 63#define BAD_BLOCK_LENGTH -6 64#define BAD_CIPHER_INSTANCE -7 65#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */ 66#define BAD_OTHER -9 /* Unknown error */ 67
| 29#define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */ 30#define BAD_KEY_MAT -2 /* Key material not of correct length */ 31#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */ 32#define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */ 33#define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */ 34#define BAD_BLOCK_LENGTH -6 35#define BAD_CIPHER_INSTANCE -7 36#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */ 37#define BAD_OTHER -9 /* Unknown error */ 38
|
68/* Algorithm-specific Defines */ 69#define RIJNDAEL_MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */ 70#define RIJNDAEL_MAX_IV_SIZE 16 /* # bytes needed to represent an IV */
| 39/* CHANGE POSSIBLE: inclusion of algorithm specific defines */ 40#define MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */ 41#define MAX_IV_SIZE 16 /* # bytes needed to represent an IV */
|
71
| 42
|
72/* Typedefs */
| 43/* Typedefs:
|
73
| 44
|
74typedef unsigned char BYTE;
| 45 Typedef'ed data storage elements. Add any algorithm specific 46parameters at the bottom of the structs as appropriate. 47*/
|
75 76/* The structure for key information */ 77typedef struct {
| 48 49/* The structure for key information */ 50typedef struct {
|
78 BYTE direction; /* Key used for encrypting or decrypting? */
| 51 u_int8_t direction; /* Key used for encrypting or decrypting? */
|
79 int keyLen; /* Length of the key */
| 52 int keyLen; /* Length of the key */
|
80 char keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */ 81 int Nr; /* key-length-dependent number of rounds */ 82 u_int32_t rk[4*(RIJNDAEL_MAXNR + 1)]; /* key schedule */ 83 u_int32_t ek[4*(RIJNDAEL_MAXNR + 1)]; /* CFB1 key schedule (encryption only) */
| 53 char keyMaterial[MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */ 54 /* The following parameters are algorithm dependent, replace or add as necessary */ 55 int ROUNDS; /* key-length-dependent number of rounds */ 56 int blockLen; /* block length */ 57 union { 58 u_int8_t xkS8[RIJNDAEL_MAXROUNDS+1][4][4]; /* key schedule */ 59 u_int32_t xkS32[RIJNDAEL_MAXROUNDS+1][4]; /* key schedule */ 60 } xKeySched; 61#define keySched xKeySched.xkS8
|
84} keyInstance; 85 86/* The structure for cipher information */ 87typedef struct { /* changed order of the components */
| 62} keyInstance; 63 64/* The structure for cipher information */ 65typedef struct { /* changed order of the components */
|
88 BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 89 BYTE IV[RIJNDAEL_MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */
| 66 u_int8_t mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 67 u_int8_t IV[MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */ 68 /* Add any algorithm specific parameters needed here */ 69 int blockLen; /* Sample: Handles non-128 bit block sizes (if available) */
|
90} cipherInstance; 91 92/* Function prototypes */
| 70} cipherInstance; 71 72/* Function prototypes */
|
| 73/* CHANGED: nothing 74 TODO: implement the following extensions to setup 192-bit and 256-bit block lengths: 75 makeKeyEx(): parameter blockLen added 76 -- this parameter is absolutely necessary if you want to 77 setup the round keys in a variable block length setting 78 cipherInitEx(): parameter blockLen added (for obvious reasons) 79 */
|
93
| 80
|
94int rijndael_makeKey(keyInstance *, BYTE, int, char *);
| 81int rijndael_makeKey(keyInstance *key, u_int8_t direction, int keyLen, char *keyMaterial);
|
95
| 82
|
96int rijndael_cipherInit(cipherInstance *, BYTE, char *);
| 83int rijndael_cipherInit(cipherInstance *cipher, u_int8_t mode, char *IV);
|
97
| 84
|
98int rijndael_blockEncrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
| 85int rijndael_blockEncrypt(cipherInstance *cipher, keyInstance *key, 86 u_int8_t *input, int inputLen, u_int8_t *outBuffer);
|
99
| 87
|
100int rijndael_padEncrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
| 88int rijndael_padEncrypt(cipherInstance *cipher, keyInstance *key, 89 u_int8_t *input, int inputOctets, u_int8_t *outBuffer);
|
101
| 90
|
102int rijndael_blockDecrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
| 91int rijndael_blockDecrypt(cipherInstance *cipher, keyInstance *key, 92 u_int8_t *input, int inputLen, u_int8_t *outBuffer);
|
103
| 93
|
104int rijndael_padDecrypt(cipherInstance *, keyInstance *, BYTE *, int, BYTE *);
| 94int rijndael_padDecrypt(cipherInstance *cipher, keyInstance *key, 95 u_int8_t *input, int inputOctets, u_int8_t *outBuffer);
|
105
| 96
|
106#endif /* __RIJNDAEL_API_FST_H */
| 97#ifdef INTERMEDIATE_VALUE_KAT 98int rijndael_cipherUpdateRounds(cipherInstance *cipher, keyInstance *key, 99 u_int8_t *input, int inputLen, u_int8_t *outBuffer, int Rounds); 100#endif /* INTERMEDIATE_VALUE_KAT */ 101 102#endif /* __RIJNDAEL_API_FST_H */
|
| |