aes_locl.h revision bdfb8ad83da0647e9b9a32792598e8ce7ba3ef4d
11ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot/* crypto/aes/aes.h -*- mode:C; c-file-style: "eay" -*- */
21ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot/* ====================================================================
31ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * Copyright (c) 1998-2002 The OpenSSL Project.  All rights reserved.
41ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
51ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * Redistribution and use in source and binary forms, with or without
61ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * modification, are permitted provided that the following conditions
71ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * are met:
81ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
91ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 1. Redistributions of source code must retain the above copyright
101ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    notice, this list of conditions and the following disclaimer.
111ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
121ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 2. Redistributions in binary form must reproduce the above copyright
131ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    notice, this list of conditions and the following disclaimer in
141ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    the documentation and/or other materials provided with the
151ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    distribution.
161ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
171ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 3. All advertising materials mentioning features or use of this
181ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    software must display the following acknowledgment:
191ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    "This product includes software developed by the OpenSSL Project
201ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
211ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
221ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
231ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    endorse or promote products derived from this software without
241ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    prior written permission. For written permission, please contact
251ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    openssl-core@openssl.org.
261ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
271ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 5. Products derived from this software may not be called "OpenSSL"
281ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    nor may "OpenSSL" appear in their names without prior written
291ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    permission of the OpenSSL Project.
301ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
311ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * 6. Redistributions of any form whatsoever must retain the following
321ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    acknowledgment:
331ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    "This product includes software developed by the OpenSSL Project
341ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
351ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
361ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
371ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
381ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
391ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
401ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
411ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
421ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
431ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
441ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
451ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
461ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
471ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * OF THE POSSIBILITY OF SUCH DAMAGE.
481ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot * ====================================================================
491ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot *
501ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot */
511ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
521ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#ifndef HEADER_AES_LOCL_H
531ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#define HEADER_AES_LOCL_H
541ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
551ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#include <openssl/e_os2.h>
561ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
571ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#ifdef OPENSSL_NO_AES
581ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#error AES is disabled.
591ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#endif
601ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
611ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#include <stdio.h>
621ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#include <stdlib.h>
631ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#include <string.h>
641ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot
651ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64))
661ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
671ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot# define GETU32(p) SWAP(*((u32 *)(p)))
681ecfda91236a8970119144e59e0ba6113dc22c0fBrett Chabot# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
69#else
70# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
71# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
72#endif
73
74#ifdef AES_LONG
75typedef unsigned long u32;
76#else
77typedef unsigned int u32;
78#endif
79typedef unsigned short u16;
80typedef unsigned char u8;
81
82#define MAXKC   (256/32)
83#define MAXKB   (256/8)
84#define MAXNR   14
85
86/* This controls loop-unrolling in aes_core.c */
87#undef FULL_UNROLL
88
89#endif /* !HEADER_AES_LOCL_H */
90