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