internal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef OPENSSL_HEADER_AES_INTERNAL_H
  15. #define OPENSSL_HEADER_AES_INTERNAL_H
  16. #include <stdlib.h>
  17. #include <openssl/cpu.h>
  18. #if defined(__cplusplus)
  19. extern "C" {
  20. #endif
  21. #if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
  22. #define HWAES
  23. static int hwaes_capable(void) {
  24. return CRYPTO_is_ARMv8_AES_capable();
  25. }
  26. #endif // !NO_ASM && (AES || AARCH64)
  27. #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_PPC64LE)
  28. #define HWAES
  29. static int hwaes_capable(void) {
  30. return CRYPTO_is_PPC64LE_vcrypto_capable();
  31. }
  32. #endif // !NO_ASM && PPC64LE
  33. #if defined(HWAES)
  34. int aes_hw_set_encrypt_key(const uint8_t *user_key, const int bits,
  35. AES_KEY *key);
  36. int aes_hw_set_decrypt_key(const uint8_t *user_key, const int bits,
  37. AES_KEY *key);
  38. void aes_hw_encrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
  39. void aes_hw_decrypt(const uint8_t *in, uint8_t *out, const AES_KEY *key);
  40. void aes_hw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
  41. const AES_KEY *key, uint8_t *ivec, const int enc);
  42. void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out, size_t len,
  43. const AES_KEY *key, const uint8_t ivec[16]);
  44. #else
  45. // If HWAES isn't defined then we provide dummy functions for each of the hwaes
  46. // functions.
  47. static int hwaes_capable(void) { return 0; }
  48. static int aes_hw_set_encrypt_key(const uint8_t *user_key, int bits,
  49. AES_KEY *key) {
  50. abort();
  51. }
  52. static int aes_hw_set_decrypt_key(const uint8_t *user_key, int bits,
  53. AES_KEY *key) {
  54. abort();
  55. }
  56. static void aes_hw_encrypt(const uint8_t *in, uint8_t *out,
  57. const AES_KEY *key) {
  58. abort();
  59. }
  60. static void aes_hw_decrypt(const uint8_t *in, uint8_t *out,
  61. const AES_KEY *key) {
  62. abort();
  63. }
  64. static void aes_hw_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t length,
  65. const AES_KEY *key, uint8_t *ivec, int enc) {
  66. abort();
  67. }
  68. static void aes_hw_ctr32_encrypt_blocks(const uint8_t *in, uint8_t *out,
  69. size_t len, const AES_KEY *key,
  70. const uint8_t ivec[16]) {
  71. abort();
  72. }
  73. #endif // !HWAES
  74. #if defined(__cplusplus)
  75. } // extern C
  76. #endif
  77. #endif // OPENSSL_HEADER_AES_INTERNAL_H