1 /* 2 * Copyright (c) 2001, Dr Brian Gladman <brg@gladman.uk.net>, Worcester, UK. 3 * All rights reserved. 4 * 5 * LICENSE TERMS 6 * 7 * The free distribution and use of this software in both source and binary 8 * form is allowed (with or without changes) provided that: 9 * 10 * 1. distributions of this source code include the above copyright 11 * notice, this list of conditions and the following disclaimer; 12 * 13 * 2. distributions in binary form include the above copyright 14 * notice, this list of conditions and the following disclaimer 15 * in the documentation and/or other associated materials; 16 * 17 * 3. the copyright holder's name is not used to endorse products 18 * built using this software without specific written permission. 19 * 20 * DISCLAIMER 21 * 22 * This software is provided 'as is' with no explcit or implied warranties 23 * in respect of any properties, including, but not limited to, correctness 24 * and fitness for purpose. 25 */ 26 27 /* 28 * Issue Date: 21/01/2002 29 * 30 * This file contains the definitions required to use AES (Rijndael) in C. 31 */ 32 33 #ifndef _AES_H 34 #define _AES_H 35 36 #include <stdint.h> 37 38 /* BLOCK_SIZE is in BYTES: 16, 24, 32 or undefined for aes.c and 16, 20, 39 24, 28, 32 or undefined for aespp.c. When left undefined a slower 40 version that provides variable block length is compiled. 41 */ 42 43 #define BLOCK_SIZE 16 44 45 /* key schedule length (in 32-bit words) */ 46 47 #if !defined(BLOCK_SIZE) 48 #define KS_LENGTH 128 49 #else 50 #define KS_LENGTH 4 * BLOCK_SIZE 51 #endif 52 53 #if defined(__cplusplus) 54 extern "C" 55 { 56 #endif 57 58 typedef uint16_t aes_fret; /* type for function return value */ 59 #define aes_bad 0 /* bad function return value */ 60 #define aes_good 1 /* good function return value */ 61 #ifndef AES_DLL /* implement normal or DLL functions */ 62 #define aes_rval aes_fret 63 #else 64 #define aes_rval aes_fret __declspec(dllexport) _stdcall 65 #endif 66 67 typedef struct /* the AES context for encryption */ 68 { uint32_t k_sch[KS_LENGTH]; /* the encryption key schedule */ 69 uint32_t n_rnd; /* the number of cipher rounds */ 70 uint32_t n_blk; /* the number of bytes in the state */ 71 } aes_ctx; 72 73 /* for Kerberos 5 tree -- hide names! */ 74 #define aes_blk_len krb5int_aes_blk_len 75 #define aes_enc_key krb5int_aes_enc_key 76 #define aes_enc_blk krb5int_aes_enc_blk 77 #define aes_dec_key krb5int_aes_dec_key 78 #define aes_dec_blk krb5int_aes_dec_blk 79 #define fl_tab krb5int_fl_tab 80 #define ft_tab krb5int_ft_tab 81 #define il_tab krb5int_il_tab 82 #define im_tab krb5int_im_tab 83 #define it_tab krb5int_it_tab 84 #define rcon_tab krb5int_rcon_tab 85 86 aes_rval aes_blk_len(unsigned int blen, aes_ctx cx[1]); 87 88 aes_rval aes_enc_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); 89 aes_rval aes_enc_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); 90 91 aes_rval aes_dec_key(const unsigned char in_key[], unsigned int klen, aes_ctx cx[1]); 92 aes_rval aes_dec_blk(const unsigned char in_blk[], unsigned char out_blk[], const aes_ctx cx[1]); 93 94 #if defined(__cplusplus) 95 } 96 #endif 97 98 #endif 99