aes.h 3.4 KB

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