1 /** $MirOS: src/sys/crypto/rijndael.h,v 1.4 2013/10/31 20:06:49 tg Exp $ */ 2 /* $OpenBSD: rijndael.h,v 1.11 2005/05/25 05:47:53 markus Exp $ */ 3 4 /*- 5 * Adaptions for VIA C3 hardware cryptography and integration is 6 * Copyright © 2008, 2013 7 * Thorsten “mirabilos” Glaser <tg@mirbsd.org> 8 */ 9 10 /** 11 * rijndael-alg-fst.h 12 * 13 * @version 3.0 (December 2000) 14 * 15 * Optimised ANSI C code for the Rijndael cipher (now AES) 16 * 17 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be> 18 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be> 19 * @author Paulo Barreto <paulo.barreto@terra.com.br> 20 * 21 * This code is hereby placed in the public domain. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS 24 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 32 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 33 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef __RIJNDAEL_H 37 #define __RIJNDAEL_H 38 39 #if !defined(SMALL_KERNEL) || (defined(i386) && defined(CRYPTO)) 40 #define __RIJNDAEL_ALIGNED __attribute__((__aligned__(16))) 41 #else 42 #define __RIJNDAEL_ALIGNED __attribute__((__aligned__(4))) 43 #endif 44 45 #define MAXKC (256/32) 46 #define MAXKB (256/8) 47 #define MAXNR 14 48 49 typedef unsigned char u8; 50 typedef unsigned short u16; 51 typedef unsigned int u32; 52 53 /* VIA C3 additional information */ 54 struct viac3_rijndael_ctx { 55 uint32_t cw0; /* control word */ 56 }; 57 58 /* The structure for key information */ 59 typedef struct { 60 u32 ek[4*(MAXNR + 1) + 4] /* encrypt key schedule */ 61 __RIJNDAEL_ALIGNED; 62 u32 dk[4*(MAXNR + 1) + 4] /* decrypt key schedule */ 63 __RIJNDAEL_ALIGNED; 64 union { 65 struct viac3_rijndael_ctx via; 66 } hwcr_info; 67 u8 enc_only; /* context contains only encrypt schedule */ 68 u8 Nr; /* key-length-dependent number of rounds */ 69 #define RIJNDAEL_HWCR_SOFTWARE 0 70 #define RIJNDAEL_HWCR_VIA 1 71 u8 hwcr_id; /* which crypto processor is used */ 72 } rijndael_ctx __RIJNDAEL_ALIGNED; 73 74 typedef int (*rijndael_setkey_t)(rijndael_ctx *, u_char *, int); 75 typedef void (*rijndael_do_cbc_t)(rijndael_ctx *, u_char *, u_char *, u_char *, 76 int); 77 78 int rijndael_set_key(rijndael_ctx *, u_char *, int); 79 int rijndael_set_key_enc_only(rijndael_ctx *, u_char *, int); 80 void rijndael_decrypt(rijndael_ctx *, u_char *, u_char *); 81 void rijndael_encrypt(rijndael_ctx *, u_char *, u_char *); 82 void rijndael_cbc_decrypt(rijndael_ctx *, u_char *, u_char *, u_char *, 83 int); 84 void rijndael_cbc_encrypt(rijndael_ctx *, u_char *, u_char *, u_char *, 85 int); 86 87 extern rijndael_setkey_t rijndael_set_key_fast; 88 extern rijndael_setkey_t rijndael_set_key_enc_only_fast; 89 extern rijndael_do_cbc_t rijndael_cbc_decrypt_fast; 90 extern rijndael_do_cbc_t rijndael_cbc_encrypt_fast; 91 92 int rijndaelKeySetupEnc(unsigned int [], const unsigned char [], int); 93 int rijndaelKeySetupDec(unsigned int [], const unsigned char [], int); 94 void rijndaelEncrypt(const unsigned int [], int, const unsigned char [], 95 unsigned char []); 96 97 #endif /* __RIJNDAEL_H */ 98