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