1*f5b1c8a1SJohn Marino /* $OpenBSD: aes.h,v 1.13 2014/06/12 15:49:27 deraadt Exp $ */ 2*f5b1c8a1SJohn Marino /* ==================================================================== 3*f5b1c8a1SJohn Marino * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 4*f5b1c8a1SJohn Marino * 5*f5b1c8a1SJohn Marino * Redistribution and use in source and binary forms, with or without 6*f5b1c8a1SJohn Marino * modification, are permitted provided that the following conditions 7*f5b1c8a1SJohn Marino * are met: 8*f5b1c8a1SJohn Marino * 9*f5b1c8a1SJohn Marino * 1. Redistributions of source code must retain the above copyright 10*f5b1c8a1SJohn Marino * notice, this list of conditions and the following disclaimer. 11*f5b1c8a1SJohn Marino * 12*f5b1c8a1SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 13*f5b1c8a1SJohn Marino * notice, this list of conditions and the following disclaimer in 14*f5b1c8a1SJohn Marino * the documentation and/or other materials provided with the 15*f5b1c8a1SJohn Marino * distribution. 16*f5b1c8a1SJohn Marino * 17*f5b1c8a1SJohn Marino * 3. All advertising materials mentioning features or use of this 18*f5b1c8a1SJohn Marino * software must display the following acknowledgment: 19*f5b1c8a1SJohn Marino * "This product includes software developed by the OpenSSL Project 20*f5b1c8a1SJohn Marino * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" 21*f5b1c8a1SJohn Marino * 22*f5b1c8a1SJohn Marino * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 23*f5b1c8a1SJohn Marino * endorse or promote products derived from this software without 24*f5b1c8a1SJohn Marino * prior written permission. For written permission, please contact 25*f5b1c8a1SJohn Marino * openssl-core@openssl.org. 26*f5b1c8a1SJohn Marino * 27*f5b1c8a1SJohn Marino * 5. Products derived from this software may not be called "OpenSSL" 28*f5b1c8a1SJohn Marino * nor may "OpenSSL" appear in their names without prior written 29*f5b1c8a1SJohn Marino * permission of the OpenSSL Project. 30*f5b1c8a1SJohn Marino * 31*f5b1c8a1SJohn Marino * 6. Redistributions of any form whatsoever must retain the following 32*f5b1c8a1SJohn Marino * acknowledgment: 33*f5b1c8a1SJohn Marino * "This product includes software developed by the OpenSSL Project 34*f5b1c8a1SJohn Marino * for use in the OpenSSL Toolkit (http://www.openssl.org/)" 35*f5b1c8a1SJohn Marino * 36*f5b1c8a1SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 37*f5b1c8a1SJohn Marino * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38*f5b1c8a1SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 39*f5b1c8a1SJohn Marino * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 40*f5b1c8a1SJohn Marino * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41*f5b1c8a1SJohn Marino * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 42*f5b1c8a1SJohn Marino * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 43*f5b1c8a1SJohn Marino * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44*f5b1c8a1SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 45*f5b1c8a1SJohn Marino * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 46*f5b1c8a1SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 47*f5b1c8a1SJohn Marino * OF THE POSSIBILITY OF SUCH DAMAGE. 48*f5b1c8a1SJohn Marino * ==================================================================== 49*f5b1c8a1SJohn Marino * 50*f5b1c8a1SJohn Marino */ 51*f5b1c8a1SJohn Marino 52*f5b1c8a1SJohn Marino #ifndef HEADER_AES_H 53*f5b1c8a1SJohn Marino #define HEADER_AES_H 54*f5b1c8a1SJohn Marino 55*f5b1c8a1SJohn Marino #include <openssl/opensslconf.h> 56*f5b1c8a1SJohn Marino 57*f5b1c8a1SJohn Marino #ifdef OPENSSL_NO_AES 58*f5b1c8a1SJohn Marino #error AES is disabled. 59*f5b1c8a1SJohn Marino #endif 60*f5b1c8a1SJohn Marino 61*f5b1c8a1SJohn Marino #include <stddef.h> 62*f5b1c8a1SJohn Marino 63*f5b1c8a1SJohn Marino #define AES_ENCRYPT 1 64*f5b1c8a1SJohn Marino #define AES_DECRYPT 0 65*f5b1c8a1SJohn Marino 66*f5b1c8a1SJohn Marino /* Because array size can't be a const in C, the following two are macros. 67*f5b1c8a1SJohn Marino Both sizes are in bytes. */ 68*f5b1c8a1SJohn Marino #define AES_MAXNR 14 69*f5b1c8a1SJohn Marino #define AES_BLOCK_SIZE 16 70*f5b1c8a1SJohn Marino 71*f5b1c8a1SJohn Marino #ifdef __cplusplus 72*f5b1c8a1SJohn Marino extern "C" { 73*f5b1c8a1SJohn Marino #endif 74*f5b1c8a1SJohn Marino 75*f5b1c8a1SJohn Marino /* This should be a hidden type, but EVP requires that the size be known */ 76*f5b1c8a1SJohn Marino struct aes_key_st { 77*f5b1c8a1SJohn Marino unsigned int rd_key[4 *(AES_MAXNR + 1)]; 78*f5b1c8a1SJohn Marino int rounds; 79*f5b1c8a1SJohn Marino }; 80*f5b1c8a1SJohn Marino typedef struct aes_key_st AES_KEY; 81*f5b1c8a1SJohn Marino 82*f5b1c8a1SJohn Marino const char *AES_options(void); 83*f5b1c8a1SJohn Marino 84*f5b1c8a1SJohn Marino int AES_set_encrypt_key(const unsigned char *userKey, const int bits, 85*f5b1c8a1SJohn Marino AES_KEY *key); 86*f5b1c8a1SJohn Marino int AES_set_decrypt_key(const unsigned char *userKey, const int bits, 87*f5b1c8a1SJohn Marino AES_KEY *key); 88*f5b1c8a1SJohn Marino 89*f5b1c8a1SJohn Marino void AES_encrypt(const unsigned char *in, unsigned char *out, 90*f5b1c8a1SJohn Marino const AES_KEY *key); 91*f5b1c8a1SJohn Marino void AES_decrypt(const unsigned char *in, unsigned char *out, 92*f5b1c8a1SJohn Marino const AES_KEY *key); 93*f5b1c8a1SJohn Marino 94*f5b1c8a1SJohn Marino void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, 95*f5b1c8a1SJohn Marino const AES_KEY *key, const int enc); 96*f5b1c8a1SJohn Marino void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 97*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); 98*f5b1c8a1SJohn Marino void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, 99*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, int *num, 100*f5b1c8a1SJohn Marino const int enc); 101*f5b1c8a1SJohn Marino void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, 102*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, int *num, 103*f5b1c8a1SJohn Marino const int enc); 104*f5b1c8a1SJohn Marino void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, 105*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, int *num, 106*f5b1c8a1SJohn Marino const int enc); 107*f5b1c8a1SJohn Marino void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, 108*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, int *num); 109*f5b1c8a1SJohn Marino void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, 110*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char ivec[AES_BLOCK_SIZE], 111*f5b1c8a1SJohn Marino unsigned char ecount_buf[AES_BLOCK_SIZE], unsigned int *num); 112*f5b1c8a1SJohn Marino /* NB: the IV is _two_ blocks long */ 113*f5b1c8a1SJohn Marino void AES_ige_encrypt(const unsigned char *in, unsigned char *out, 114*f5b1c8a1SJohn Marino size_t length, const AES_KEY *key, unsigned char *ivec, const int enc); 115*f5b1c8a1SJohn Marino 116*f5b1c8a1SJohn Marino int AES_wrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, 117*f5b1c8a1SJohn Marino const unsigned char *in, unsigned int inlen); 118*f5b1c8a1SJohn Marino int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, unsigned char *out, 119*f5b1c8a1SJohn Marino const unsigned char *in, unsigned int inlen); 120*f5b1c8a1SJohn Marino 121*f5b1c8a1SJohn Marino 122*f5b1c8a1SJohn Marino #ifdef __cplusplus 123*f5b1c8a1SJohn Marino } 124*f5b1c8a1SJohn Marino #endif 125*f5b1c8a1SJohn Marino 126*f5b1c8a1SJohn Marino #endif /* !HEADER_AES_H */ 127