1 /* Copyright (c) 2017, Google Inc. 2 * 3 * Permission to use, copy, modify, and/or distribute this software for any 4 * purpose with or without fee is hereby granted, provided that the above 5 * copyright notice and this permission notice appear in all copies. 6 * 7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 15 #ifndef OPENSSL_HEADER_AES_INTERNAL_H 16 #define OPENSSL_HEADER_AES_INTERNAL_H 17 18 #include <stdlib.h> 19 20 #include <openssl/cpu.h> 21 22 #if defined(__cplusplus) 23 extern "C" { 24 #endif 25 26 27 #if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) 28 #define HWAES 29 30 static int hwaes_capable(void) { 31 return CRYPTO_is_ARMv8_AES_capable(); 32 } 33 #endif /* !NO_ASM && (AES || AARCH64) */ 34 35 #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_PPC64LE) 36 #define HWAES 37 38 static int hwaes_capable(void) { 39 return CRYPTO_is_PPC64LE_vcrypto_capable(); 40 } 41 #endif /* !NO_ASM && PPC64LE */ 42 43 44 #if defined(HWAES) 45 46 int aes_hw_set_encrypt_key(const uint8_t *user_key, const int bits, 47 AES_KEY *key); 48 int aes_hw_set_decrypt_key(const uint8_t *user_key, const int bits, 49 AES_KEY *key); 50 void aes_hw_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key); 51 void aes_hw_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key); 52 void aes_hw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length, 53 const AES_KEY *key, uint8_t *ivec, const int enc); 54 void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len, 55 const AES_KEY *key, const uint8_t ivec[16]); 56 57 #else 58 59 /* If HWAES isn't defined then we provide dummy functions for each of the hwaes 60 * functions. */ 61 static int hwaes_capable(void) { return 0; } 62 63 static int aes_hw_set_encrypt_key(const uint8_t *user_key, int bits, 64 AES_KEY *key) { 65 abort(); 66 } 67 68 static int aes_hw_set_decrypt_key(const uint8_t *user_key, int bits, 69 AES_KEY *key) { 70 abort(); 71 } 72 73 static void aes_hw_encrypt(const uint8_t *in, uint8_t *out, 74 const AES_KEY *key) { 75 abort(); 76 } 77 78 static void aes_hw_decrypt(const uint8_t *in, uint8_t *out, 79 const AES_KEY *key) { 80 abort(); 81 } 82 83 static void aes_hw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length, 84 const AES_KEY *key, uint8_t *ivec, int enc) { 85 abort(); 86 } 87 88 static void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, 89 size_t len, const AES_KEY *key, 90 const uint8_t ivec[16]) { 91 abort(); 92 } 93 94 #endif /* !HWAES */ 95 96 #if defined(__cplusplus) 97 } /* extern C */ 98 #endif 99 100 #endif /* OPENSSL_HEADER_AES_INTERNAL_H */ 101