aes.h 3.3 KB

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