1ae1f160dSDag-Erling Smørgrav /* $OpenBSD: rijndael.h,v 1.15 2021/09/28 11:14:50 dtucker Exp $ */ 21e8db6e2SBrian Feldman 3ae1f160dSDag-Erling Smørgrav /** 4ae1f160dSDag-Erling Smørgrav * rijndael-alg-fst.h 5ae1f160dSDag-Erling Smørgrav * 6ae1f160dSDag-Erling Smørgrav * @version 3.0 (December 2000) 7ae1f160dSDag-Erling Smørgrav * 8ae1f160dSDag-Erling Smørgrav * Optimised ANSI C code for the Rijndael cipher (now AES) 9ae1f160dSDag-Erling Smørgrav * 10ae1f160dSDag-Erling Smørgrav * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> 11ae1f160dSDag-Erling Smørgrav * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> 12ae1f160dSDag-Erling Smørgrav * @author Paulo Barreto <paulo.barreto@terra.com.br> 13ae1f160dSDag-Erling Smørgrav * 14ae1f160dSDag-Erling Smørgrav * This code is hereby placed in the public domain. 15ae1f160dSDag-Erling Smørgrav * 16ae1f160dSDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 17ae1f160dSDag-Erling Smørgrav * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18ae1f160dSDag-Erling Smørgrav * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19ae1f160dSDag-Erling Smørgrav * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 20ae1f160dSDag-Erling Smørgrav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21ae1f160dSDag-Erling Smørgrav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22ae1f160dSDag-Erling Smørgrav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23ae1f160dSDag-Erling Smørgrav * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24ae1f160dSDag-Erling Smørgrav * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25ae1f160dSDag-Erling Smørgrav * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26ae1f160dSDag-Erling Smørgrav * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27ae1f160dSDag-Erling Smørgrav */ 28ae1f160dSDag-Erling Smørgrav #ifndef _PRIVATE_RIJNDAEL_H 29ae1f160dSDag-Erling Smørgrav #define _PRIVATE_RIJNDAEL_H 301e8db6e2SBrian Feldman 31ae1f160dSDag-Erling Smørgrav #define AES_MAXKEYBITS (256) 32ae1f160dSDag-Erling Smørgrav #define AES_MAXKEYBYTES (AES_MAXKEYBITS/8) 33ae1f160dSDag-Erling Smørgrav /* for 256-bit keys, fewer for less */ 345b9b2fafSBrian Feldman #define AES_MAXROUNDS 14 35ae1f160dSDag-Erling Smørgrav 36ae1f160dSDag-Erling Smørgrav typedef unsigned char u8; 37ae1f160dSDag-Erling Smørgrav typedef unsigned short u16; 385b9b2fafSBrian Feldman typedef unsigned int u32; 39ae1f160dSDag-Erling Smørgrav 40ae1f160dSDag-Erling Smørgrav int rijndaelKeySetupEnc(unsigned int [], const unsigned char [], int); 415b9b2fafSBrian Feldman void rijndaelEncrypt(const unsigned int [], int, const u8 [16], u8 [16]); 42ae1f160dSDag-Erling Smørgrav 43ae1f160dSDag-Erling Smørgrav /* The structure for key information */ 44ae1f160dSDag-Erling Smørgrav typedef struct { 455b9b2fafSBrian Feldman int decrypt; 465b9b2fafSBrian Feldman int Nr; /* key-length-dependent number of rounds */ 47ae1f160dSDag-Erling Smørgrav u32 ek[4*(AES_MAXROUNDS + 1)]; /* encrypt key schedule */ 48ae1f160dSDag-Erling Smørgrav u32 dk[4*(AES_MAXROUNDS + 1)]; /* decrypt key schedule */ 49ae1f160dSDag-Erling Smørgrav } rijndael_ctx; 505b9b2fafSBrian Feldman 51ae1f160dSDag-Erling Smørgrav void rijndael_set_key(rijndael_ctx *, u_char *, int, int); 52 void rijndael_decrypt(rijndael_ctx *, u_char *, u_char *); 53 void rijndael_encrypt(rijndael_ctx *, u_char *, u_char *); 54 55 #endif /* _PRIVATE_RIJNDAEL_H */ 56