1*433d6423SLionel Sambuc /* rijndael-api.h - Rijndael encryption programming interface. 2*433d6423SLionel Sambuc * Author: Kees J. Bot 3*433d6423SLionel Sambuc * 3 Nov 2000 4*433d6423SLionel Sambuc * Heavily based on the original API code by Antoon Bosselaers, 5*433d6423SLionel Sambuc * Vincent Rijmen, and Paulo Barreto, but with a different interface. 6*433d6423SLionel Sambuc * 7*433d6423SLionel Sambuc * This code (.h and .c) is in the public domain. 8*433d6423SLionel Sambuc */ 9*433d6423SLionel Sambuc 10*433d6423SLionel Sambuc #ifndef _CRYPTO__RIJNDAEL_H 11*433d6423SLionel Sambuc #define _CRYPTO__RIJNDAEL_H 12*433d6423SLionel Sambuc 13*433d6423SLionel Sambuc /* Error codes. */ 14*433d6423SLionel Sambuc #define RD_BAD_KEY_MAT -1 /* Key material not of correct length */ 15*433d6423SLionel Sambuc #define RD_BAD_BLOCK_LENGTH -2 /* Data is not a block multiple */ 16*433d6423SLionel Sambuc #define RD_BAD_DATA -3 /* Data contents are invalid (bad padding?) */ 17*433d6423SLionel Sambuc 18*433d6423SLionel Sambuc /* Key information. */ 19*433d6423SLionel Sambuc #define RD_KEY_HEX -1 /* Key is in hex (otherwise octet length) */ 20*433d6423SLionel Sambuc #define RD_MAXROUNDS 14 /* Max number of encryption rounds. */ 21*433d6423SLionel Sambuc 22*433d6423SLionel Sambuc typedef struct { 23*433d6423SLionel Sambuc int rounds; /* Key-length-dependent number of rounds */ 24*433d6423SLionel Sambuc unsigned char encsched[RD_MAXROUNDS+1][4][4]; /* Encr key schedule */ 25*433d6423SLionel Sambuc unsigned char decsched[RD_MAXROUNDS+1][4][4]; /* Decr key schedule */ 26*433d6423SLionel Sambuc } rd_keyinstance; 27*433d6423SLionel Sambuc 28*433d6423SLionel Sambuc #define AES_BLOCKSIZE 16 29*433d6423SLionel Sambuc 30*433d6423SLionel Sambuc /* Function prototypes. */ 31*433d6423SLionel Sambuc 32*433d6423SLionel Sambuc int rijndael_makekey(rd_keyinstance *_key, 33*433d6423SLionel Sambuc size_t _keylen, const void *_keymaterial); 34*433d6423SLionel Sambuc 35*433d6423SLionel Sambuc ssize_t rijndael_ecb_encrypt(rd_keyinstance *_key, 36*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_dummyIV); 37*433d6423SLionel Sambuc 38*433d6423SLionel Sambuc ssize_t rijndael_ecb_decrypt(rd_keyinstance *_key, 39*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_dummyIV); 40*433d6423SLionel Sambuc 41*433d6423SLionel Sambuc ssize_t rijndael_cbc_encrypt(rd_keyinstance *_key, 42*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 43*433d6423SLionel Sambuc 44*433d6423SLionel Sambuc ssize_t rijndael_cbc_decrypt(rd_keyinstance *_key, 45*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 46*433d6423SLionel Sambuc 47*433d6423SLionel Sambuc ssize_t rijndael_cfb1_encrypt(rd_keyinstance *_key, 48*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 49*433d6423SLionel Sambuc 50*433d6423SLionel Sambuc ssize_t rijndael_cfb1_decrypt(rd_keyinstance *_key, 51*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 52*433d6423SLionel Sambuc 53*433d6423SLionel Sambuc ssize_t rijndael_cfb8_encrypt(rd_keyinstance *_key, 54*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 55*433d6423SLionel Sambuc 56*433d6423SLionel Sambuc ssize_t rijndael_cfb8_decrypt(rd_keyinstance *_key, 57*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 58*433d6423SLionel Sambuc 59*433d6423SLionel Sambuc ssize_t rijndael_pad(void *_input, size_t _length); 60*433d6423SLionel Sambuc 61*433d6423SLionel Sambuc ssize_t rijndael_unpad(const void *_input, size_t _length); 62*433d6423SLionel Sambuc 63*433d6423SLionel Sambuc typedef ssize_t (*rd_function)(rd_keyinstance *_key, 64*433d6423SLionel Sambuc const void *_input, void *_output, size_t _length, void *_IV); 65*433d6423SLionel Sambuc 66*433d6423SLionel Sambuc #ifdef INTERMEDIATE_VALUE_KAT 67*433d6423SLionel Sambuc 68*433d6423SLionel Sambuc void cipherEncryptUpdateRounds(rd_keyinstance *key, 69*433d6423SLionel Sambuc const void *input, void *output, int rounds); 70*433d6423SLionel Sambuc 71*433d6423SLionel Sambuc void cipherDecryptUpdateRounds(rd_keyinstance *key, 72*433d6423SLionel Sambuc const void *input, void *output, int rounds); 73*433d6423SLionel Sambuc 74*433d6423SLionel Sambuc #endif /* INTERMEDIATE_VALUE_KAT */ 75*433d6423SLionel Sambuc 76*433d6423SLionel Sambuc #endif /* _CRYPTO__RIJNDAEL_H */ 77*433d6423SLionel Sambuc 78*433d6423SLionel Sambuc /* 79*433d6423SLionel Sambuc * $PchId: rijndael.h,v 1.1 2005/06/01 10:13:45 philip Exp $ 80*433d6423SLionel Sambuc */ 81