ctc_aes.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* ctc_aes.h
  2. *
  3. * Copyright (C) 2006-2011 Sawtooth Consulting Ltd.
  4. *
  5. * This file is part of CyaSSL.
  6. *
  7. * CyaSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * CyaSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  20. */
  21. #ifndef NO_AES
  22. #ifndef CTAO_CRYPT_AES_H
  23. #define CTAO_CRYPT_AES_H
  24. #include "ctc_types.h"
  25. #ifdef CYASSL_AESNI
  26. #include <wmmintrin.h>
  27. #if !defined (ALIGN16)
  28. #if defined (__GNUC__)
  29. #define ALIGN16 __attribute__ ( (aligned (16)))
  30. #elif defined(_MSC_VER)
  31. #define ALIGN16 __declspec (align (16))
  32. #else
  33. #define ALIGN16
  34. #endif
  35. #endif
  36. #endif /* CYASSL_AESNI */
  37. #if !defined (ALIGN16)
  38. #define ALIGN16
  39. #endif
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. enum {
  44. AES_ENCRYPTION = 0,
  45. AES_DECRYPTION = 1,
  46. AES_BLOCK_SIZE = 16
  47. };
  48. typedef struct Aes {
  49. /* AESNI needs key first, rounds 2nd, not sure why yet */
  50. ALIGN16 word32 key[60];
  51. word32 rounds;
  52. ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
  53. ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */
  54. } Aes;
  55. CYASSL_API int AesSetKey(Aes* aes, const byte* key, word32 len, const byte* iv,
  56. int dir);
  57. CYASSL_API void AesCbcEncrypt(Aes* aes, byte* out, const byte* in, word32 sz);
  58. CYASSL_API void AesCbcDecrypt(Aes* aes, byte* out, const byte* in, word32 sz);
  59. #ifdef __cplusplus
  60. } /* extern "C" */
  61. #endif
  62. #endif /* CTAO_CRYPT_AES_H */
  63. #endif /* NO_AES */