aes.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * (C) Copyright 2010 - 2011 NVIDIA Corporation <www.nvidia.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef _AES_REF_H_
  8. #define _AES_REF_H_
  9. /*
  10. * AES encryption library, with small code size, supporting only 128-bit AES
  11. *
  12. * AES is a stream cipher which works a block at a time, with each block
  13. * in this case being AES_KEY_LENGTH bytes.
  14. */
  15. enum {
  16. AES_STATECOLS = 4, /* columns in the state & expanded key */
  17. AES_KEYCOLS = 4, /* columns in a key */
  18. AES_ROUNDS = 10, /* rounds in encryption */
  19. AES_KEY_LENGTH = 128 / 8,
  20. AES_EXPAND_KEY_LENGTH = 4 * AES_STATECOLS * (AES_ROUNDS + 1),
  21. };
  22. /**
  23. * aes_expand_key() - Expand the AES key
  24. *
  25. * Expand a key into a key schedule, which is then used for the other
  26. * operations.
  27. *
  28. * @key Key, of length AES_KEY_LENGTH bytes
  29. * @expkey Buffer to place expanded key, AES_EXPAND_KEY_LENGTH
  30. */
  31. void aes_expand_key(u8 *key, u8 *expkey);
  32. /**
  33. * aes_encrypt() - Encrypt single block of data with AES 128
  34. *
  35. * @in Input data
  36. * @expkey Expanded key to use for encryption (from aes_expand_key())
  37. * @out Output data
  38. */
  39. void aes_encrypt(u8 *in, u8 *expkey, u8 *out);
  40. /**
  41. * aes_decrypt() - Decrypt single block of data with AES 128
  42. *
  43. * @in Input data
  44. * @expkey Expanded key to use for decryption (from aes_expand_key())
  45. * @out Output data
  46. */
  47. void aes_decrypt(u8 *in, u8 *expkey, u8 *out);
  48. /**
  49. * aes_cbc_encrypt_blocks() - Encrypt multiple blocks of data with AES CBC.
  50. *
  51. * @key_exp Expanded key to use
  52. * @src Source data to encrypt
  53. * @dst Destination buffer
  54. * @num_aes_blocks Number of AES blocks to encrypt
  55. */
  56. void aes_cbc_encrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks);
  57. /**
  58. * Decrypt multiple blocks of data with AES CBC.
  59. *
  60. * @key_exp Expanded key to use
  61. * @src Source data to decrypt
  62. * @dst Destination buffer
  63. * @num_aes_blocks Number of AES blocks to decrypt
  64. */
  65. void aes_cbc_decrypt_blocks(u8 *key_exp, u8 *src, u8 *dst, u32 num_aes_blocks);
  66. #endif /* _AES_REF_H_ */