1*4724848cSchristos /* 2*4724848cSchristos * Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved. 3*4724848cSchristos * 4*4724848cSchristos * Licensed under the OpenSSL license (the "License"). You may not use 5*4724848cSchristos * this file except in compliance with the License. You can obtain a copy 6*4724848cSchristos * in the file LICENSE in the source distribution or at 7*4724848cSchristos * https://www.openssl.org/source/license.html 8*4724848cSchristos */ 9*4724848cSchristos 10*4724848cSchristos #ifndef HEADER_AES_H 11*4724848cSchristos # define HEADER_AES_H 12*4724848cSchristos 13*4724848cSchristos # include <openssl/opensslconf.h> 14*4724848cSchristos 15*4724848cSchristos # include <stddef.h> 16*4724848cSchristos # ifdef __cplusplus 17*4724848cSchristos extern "C" { 18*4724848cSchristos # endif 19*4724848cSchristos 20*4724848cSchristos # define AES_ENCRYPT 1 21*4724848cSchristos # define AES_DECRYPT 0 22*4724848cSchristos 23*4724848cSchristos /* 24*4724848cSchristos * Because array size can't be a const in C, the following two are macros. 25*4724848cSchristos * Both sizes are in bytes. 26*4724848cSchristos */ 27*4724848cSchristos # define AES_MAXNR 14 28*4724848cSchristos # define AES_BLOCK_SIZE 16 29*4724848cSchristos 30*4724848cSchristos /* This should be a hidden type, but EVP requires that the size be known */ 31*4724848cSchristos struct aes_key_st { 32*4724848cSchristos # ifdef AES_LONG 33*4724848cSchristos unsigned long rd_key[4 * (AES_MAXNR + 1)]; 34*4724848cSchristos # else 35*4724848cSchristos unsigned int rd_key[4 * (AES_MAXNR + 1)]; 36*4724848cSchristos # endif 37*4724848cSchristos int rounds; 38*4724848cSchristos }; 39*4724848cSchristos typedef struct aes_key_st AES_KEY; 40*4724848cSchristos 41*4724848cSchristos const char *AES_options(void); 42*4724848cSchristos 43*4724848cSchristos int AES_set_encrypt_key(const unsigned char *userKey, const int bits, 44*4724848cSchristos AES_KEY *key); 45*4724848cSchristos int AES_set_decrypt_key(const unsigned char *userKey, const int bits, 46*4724848cSchristos AES_KEY *key); 47*4724848cSchristos 48*4724848cSchristos void AES_encrypt(const unsigned char *in, unsigned char *out, 49*4724848cSchristos const AES_KEY *key); 50*4724848cSchristos void AES_decrypt(const unsigned char *in, unsigned char *out, 51*4724848cSchristos const AES_KEY *key); 52*4724848cSchristos 53*4724848cSchristos void AES_ecb_encrypt(const unsigned char *in, unsigned char *out, 54*4724848cSchristos const AES_KEY *key, const int enc); 55*4724848cSchristos void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 56*4724848cSchristos size_t length, const AES_KEY *key, 57*4724848cSchristos unsigned char *ivec, const int enc); 58*4724848cSchristos void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out, 59*4724848cSchristos size_t length, const AES_KEY *key, 60*4724848cSchristos unsigned char *ivec, int *num, const int enc); 61*4724848cSchristos void AES_cfb1_encrypt(const unsigned char *in, unsigned char *out, 62*4724848cSchristos size_t length, const AES_KEY *key, 63*4724848cSchristos unsigned char *ivec, int *num, const int enc); 64*4724848cSchristos void AES_cfb8_encrypt(const unsigned char *in, unsigned char *out, 65*4724848cSchristos size_t length, const AES_KEY *key, 66*4724848cSchristos unsigned char *ivec, int *num, const int enc); 67*4724848cSchristos void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, 68*4724848cSchristos size_t length, const AES_KEY *key, 69*4724848cSchristos unsigned char *ivec, int *num); 70*4724848cSchristos /* NB: the IV is _two_ blocks long */ 71*4724848cSchristos void AES_ige_encrypt(const unsigned char *in, unsigned char *out, 72*4724848cSchristos size_t length, const AES_KEY *key, 73*4724848cSchristos unsigned char *ivec, const int enc); 74*4724848cSchristos /* NB: the IV is _four_ blocks long */ 75*4724848cSchristos void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out, 76*4724848cSchristos size_t length, const AES_KEY *key, 77*4724848cSchristos const AES_KEY *key2, const unsigned char *ivec, 78*4724848cSchristos const int enc); 79*4724848cSchristos 80*4724848cSchristos int AES_wrap_key(AES_KEY *key, const unsigned char *iv, 81*4724848cSchristos unsigned char *out, 82*4724848cSchristos const unsigned char *in, unsigned int inlen); 83*4724848cSchristos int AES_unwrap_key(AES_KEY *key, const unsigned char *iv, 84*4724848cSchristos unsigned char *out, 85*4724848cSchristos const unsigned char *in, unsigned int inlen); 86*4724848cSchristos 87*4724848cSchristos 88*4724848cSchristos # ifdef __cplusplus 89*4724848cSchristos } 90*4724848cSchristos # endif 91*4724848cSchristos 92*4724848cSchristos #endif 93