aes.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef _AES_REF_H_
  24. #define _AES_REF_H_
  25. /*
  26. * AES encryption library, with small code size, supporting only 128-bit AES
  27. *
  28. * AES is a stream cipher which works a block at a time, with each block
  29. * in this case being AES_KEY_LENGTH bytes.
  30. */
  31. enum {
  32. AES_STATECOLS = 4, /* columns in the state & expanded key */
  33. AES_KEYCOLS = 4, /* columns in a key */
  34. AES_ROUNDS = 10, /* rounds in encryption */
  35. AES_KEY_LENGTH = 128 / 8,
  36. AES_EXPAND_KEY_LENGTH = 4 * AES_STATECOLS * (AES_ROUNDS + 1),
  37. };
  38. /**
  39. * Expand a key into a key schedule, which is then used for the other
  40. * operations.
  41. *
  42. * \param key Key, of length AES_KEY_LENGTH bytes
  43. * \param expkey Buffer to place expanded key, AES_EXPAND_KEY_LENGTH
  44. */
  45. void aes_expand_key(u8 *key, u8 *expkey);
  46. /**
  47. * Encrypt a single block of data
  48. *
  49. * in Input data
  50. * expkey Expanded key to use for encryption (from aes_expand_key())
  51. * out Output data
  52. */
  53. void aes_encrypt(u8 *in, u8 *expkey, u8 *out);
  54. /**
  55. * Decrypt a single block of data
  56. *
  57. * in Input data
  58. * expkey Expanded key to use for decryption (from aes_expand_key())
  59. * out Output data
  60. */
  61. void aes_decrypt(u8 *in, u8 *expkey, u8 *out);
  62. #endif /* _AES_REF_H_ */