Path: blob/main/sys/crypto/rijndael/rijndael-api-fst.h
39482 views
/* $KAME: rijndael-api-fst.h,v 1.6 2001/05/27 00:23:23 itojun Exp $ */12/*3* rijndael-api-fst.h v2.3 April '20004*5* Optimised ANSI C code6*7*/89#ifndef __RIJNDAEL_API_FST_H10#define __RIJNDAEL_API_FST_H1112#include <crypto/rijndael/rijndael.h>1314/* Generic Defines */15#define DIR_ENCRYPT 0 /* Are we encrpyting? */16#define DIR_DECRYPT 1 /* Are we decrpyting? */17#define MODE_ECB 1 /* Are we ciphering in ECB mode? */18#define MODE_CBC 2 /* Are we ciphering in CBC mode? */19#define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */20#define BITSPERBLOCK 128 /* Default number of bits in a cipher block */2122/* Error Codes */23#define BAD_KEY_DIR -1 /* Key direction is invalid, e.g., unknown value */24#define BAD_KEY_MAT -2 /* Key material not of correct length */25#define BAD_KEY_INSTANCE -3 /* Key passed is not valid */26#define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */27#define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */28#define BAD_BLOCK_LENGTH -629#define BAD_CIPHER_INSTANCE -730#define BAD_DATA -8 /* Data contents are invalid, e.g., invalid padding */31#define BAD_OTHER -9 /* Unknown error */3233/* Algorithm-specific Defines */34#define RIJNDAEL_MAX_KEY_SIZE 64 /* # of ASCII char's needed to represent a key */35#define RIJNDAEL_MAX_IV_SIZE 16 /* # bytes needed to represent an IV */3637/* Typedefs */3839/* The structure for key information */40typedef struct {41uint8_t direction; /* Key used for encrypting or decrypting? */42int keyLen; /* Length of the key */43char keyMaterial[RIJNDAEL_MAX_KEY_SIZE+1]; /* Raw key data in ASCII, e.g., user input or KAT values */44int Nr; /* key-length-dependent number of rounds */45uint32_t rk[4*(RIJNDAEL_MAXNR + 1)]; /* key schedule */46uint32_t ek[4*(RIJNDAEL_MAXNR + 1)]; /* CFB1 key schedule (encryption only) */47} keyInstance;4849/* The structure for cipher information */50typedef struct { /* changed order of the components */51uint8_t mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */52uint8_t IV[RIJNDAEL_MAX_IV_SIZE]; /* A possible Initialization Vector for ciphering */53} cipherInstance;5455/* Function prototypes */5657int rijndael_makeKey(keyInstance *, uint8_t, int, const char *);5859int rijndael_cipherInit(cipherInstance *, uint8_t, char *);6061int rijndael_blockEncrypt(cipherInstance *, keyInstance *, const uint8_t *,62int, uint8_t *);63int rijndael_padEncrypt(cipherInstance *, keyInstance *, const uint8_t *,64int, uint8_t *);6566int rijndael_blockDecrypt(cipherInstance *, keyInstance *, const uint8_t *,67int, uint8_t *);68int rijndael_padDecrypt(cipherInstance *, keyInstance *, const uint8_t *,69int, uint8_t *);7071#endif /* __RIJNDAEL_API_FST_H */727374