xref: /freebsd/sys/crypto/rijndael/rijndael-api-fst.h (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*	$FreeBSD$	*/
2 /*	$KAME: rijndael-api-fst.h,v 1.6 2001/05/27 00:23:23 itojun Exp $	*/
3 
4 /*
5  * rijndael-api-fst.h   v2.3   April '2000
6  *
7  * Optimised ANSI C code
8  *
9  */
10 
11 #ifndef __RIJNDAEL_API_FST_H
12 #define __RIJNDAEL_API_FST_H
13 
14 #include <crypto/rijndael/rijndael.h>
15 
16 /*  Generic Defines  */
17 #define     DIR_ENCRYPT           0 /*  Are we encrpyting?  */
18 #define     DIR_DECRYPT           1 /*  Are we decrpyting?  */
19 #define     MODE_ECB              1 /*  Are we ciphering in ECB mode?   */
20 #define     MODE_CBC              2 /*  Are we ciphering in CBC mode?   */
21 #define     MODE_CFB1             3 /*  Are we ciphering in 1-bit CFB mode? */
22 #define     BITSPERBLOCK        128 /* Default number of bits in a cipher block */
23 
24 /*  Error Codes  */
25 #define     BAD_KEY_DIR          -1 /*  Key direction is invalid, e.g., unknown value */
26 #define     BAD_KEY_MAT          -2 /*  Key material not of correct length */
27 #define     BAD_KEY_INSTANCE     -3 /*  Key passed is not valid */
28 #define     BAD_CIPHER_MODE      -4 /*  Params struct passed to cipherInit invalid */
29 #define     BAD_CIPHER_STATE     -5 /*  Cipher in wrong state (e.g., not initialized) */
30 #define     BAD_BLOCK_LENGTH     -6
31 #define     BAD_CIPHER_INSTANCE  -7
32 #define     BAD_DATA             -8 /*  Data contents are invalid, e.g., invalid padding */
33 #define     BAD_OTHER            -9 /*  Unknown error */
34 
35 /*  Algorithm-specific Defines  */
36 #define     RIJNDAEL_MAX_KEY_SIZE         64 /* # of ASCII char's needed to represent a key */
37 #define     RIJNDAEL_MAX_IV_SIZE          16 /* # bytes needed to represent an IV  */
38 
39 /*  Typedefs  */
40 
41 /*  The structure for key information */
42 typedef struct {
43     u_int8_t  direction;            /* Key used for encrypting or decrypting? */
44     int   keyLen;                   /* Length of the key  */
45     char  keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1];  /* Raw key data in ASCII, e.g., user input or KAT values */
46 	int   Nr;                       /* key-length-dependent number of rounds */
47 	u_int32_t   rk[4*(RIJNDAEL_MAXNR + 1)];        /* key schedule */
48 	u_int32_t   ek[4*(RIJNDAEL_MAXNR + 1)];        /* CFB1 key schedule (encryption only) */
49 } keyInstance;
50 
51 /*  The structure for cipher information */
52 typedef struct {                    /* changed order of the components */
53     u_int8_t mode;                  /* MODE_ECB, MODE_CBC, or MODE_CFB1 */
54     u_int8_t IV[RIJNDAEL_MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */
55 } cipherInstance;
56 
57 /*  Function prototypes  */
58 
59 int rijndael_makeKey(keyInstance *, u_int8_t, int, const char *);
60 
61 int rijndael_cipherInit(cipherInstance *, u_int8_t, char *);
62 
63 int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const u_int8_t *,
64 	int, u_int8_t *);
65 int rijndael_padEncrypt(cipherInstance *, keyInstance *, const u_int8_t *,
66 	int, u_int8_t *);
67 
68 int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const u_int8_t *,
69 	int, u_int8_t *);
70 int rijndael_padDecrypt(cipherInstance *, keyInstance *, const u_int8_t *,
71 	int, u_int8_t *);
72 
73 #endif /*  __RIJNDAEL_API_FST_H */
74