2
0

aes.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef _ANODE_AES_H
  17. #define _ANODE_AES_H
  18. #include <openssl/aes.h>
  19. #include "types.h"
  20. /* This just glues us to OpenSSL's built-in AES-256 implementation */
  21. #define ANODE_AES_BLOCK_SIZE 16
  22. #define ANODE_AES_KEY_SIZE 32
  23. typedef AES_KEY AnodeAesExpandedKey;
  24. #define Anode_aes256_expand_key(k,ek) AES_set_encrypt_key((const unsigned char *)(k),256,(AES_KEY *)(ek))
  25. /* Note: in and out can be the same thing */
  26. #define Anode_aes256_encrypt(ek,in,out) AES_encrypt((const unsigned char *)(in),(unsigned char *)(out),(const AES_KEY *)(ek))
  27. /* Note: iv is modified */
  28. static inline void Anode_aes256_cfb_encrypt(
  29. const AnodeAesExpandedKey *expkey,
  30. const unsigned char *in,
  31. unsigned char *out,
  32. unsigned char *iv,
  33. unsigned long len)
  34. {
  35. int tmp = 0;
  36. AES_cfb128_encrypt(in,out,len,(const AES_KEY *)expkey,iv,&tmp,AES_ENCRYPT);
  37. }
  38. static inline void Anode_aes256_cfb_decrypt(
  39. const AnodeAesExpandedKey *expkey,
  40. const unsigned char *in,
  41. unsigned char *out,
  42. unsigned char *iv,
  43. unsigned long len)
  44. {
  45. int tmp = 0;
  46. AES_cfb128_encrypt(in,out,len,(const AES_KEY *)expkey,iv,&tmp,AES_DECRYPT);
  47. }
  48. /* CMAC message authentication code */
  49. void Anode_cmac_aes256(
  50. const AnodeAesExpandedKey *expkey,
  51. const unsigned char *restrict data,
  52. unsigned long data_len,
  53. unsigned char *restrict mac);
  54. #endif