aes_cmac.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * \file aes_cmac.h
  3. *
  4. *
  5. */
  6. /*
  7. * Copyright (C) 2013. Mindtree Ltd.
  8. * All rights reserved.
  9. */
  10. #ifndef _H_AES_CMAC_
  11. #define _H_AES_CMAC_
  12. /* --------------------------------------------- Header File Inclusion */
  13. #include "EM_os.h"
  14. /* --------------------------------------------- Global Definitions */
  15. /* TODO: Make it proper error id */
  16. #define AES_CMAC_PROC_PENDING 0x1100
  17. /* Operations */
  18. #define AES_CMAC_MAC_GENERATE 0x00
  19. #define AES_CMAC_MAC_VERIFY 0x01
  20. /* AES-CMAC key and data block size */
  21. #define AES_CMAC_KEY_SIZE 16
  22. #define AES_CMAC_BLOCK_SIZE 16
  23. #define AES_128_ENC_KEY_SIZE 16
  24. #define AES_128_ENC_DATA_SIZE 16
  25. #define AES_128_ENC_OUT_SIZE 16
  26. /* AES-CMAC Block size exponent (2^4 = 16) */
  27. #define AES_CMAC_BLOCK_EXPONENT 4
  28. /* AES-CMAC state masks */
  29. #define AES_CMAC_STATE_INIT 0x01
  30. #define AES_CMAC_STATE_OPERATING 0x02
  31. #define AES_CMAC_STATE_IN_ENCRYPT 0x04
  32. #define AES_CMAC_STATE_SUBKEY_GEN 0x10
  33. #define AES_CMAC_STATE_MAC_GENERATE 0x20
  34. #define AES_CMAC_STATE_MAC_VERIFY 0x40
  35. /* --------------------------------------------- Structures/Data Types */
  36. /* AES-CMAC context callback type */
  37. typedef void (* AES_CMAC_CB) (void);
  38. /* AES-CMAC Context */
  39. typedef struct _AES_CMAC_CONTEXT
  40. {
  41. /** Application Use */
  42. /* 128-Bit Key to be used for the CMAC algorithm */
  43. UCHAR * key;
  44. /* Message to be used */
  45. UCHAR * data;
  46. /* Message Length */
  47. UINT16 datalen;
  48. /* MAC */
  49. UCHAR * mac;
  50. /* MAC length, in bytes */
  51. UCHAR maclen;
  52. /* Action - Generate MAC or Verify MAC */
  53. UCHAR action;
  54. /* Context callback */
  55. AES_CMAC_CB cb;
  56. /** Internal Use */
  57. /* Context state */
  58. UCHAR state;
  59. /* Number of data blocks */
  60. UINT16 num_blocks;
  61. /* Number of processed data blocks */
  62. UINT16 processed;
  63. /* Subkey references */
  64. UCHAR subkey1[AES_CMAC_KEY_SIZE];
  65. UCHAR subkey2[AES_CMAC_KEY_SIZE];
  66. } AES_CMAC_CONTEXT;
  67. /* --------------------------------------------- Macros */
  68. /* --------------------------------------------- API Declarations */
  69. /* Initialize module */
  70. EM_RESULT aes_cmac_init (void);
  71. /* Initialize Context */
  72. EM_RESULT aes_cmac_context_init (AES_CMAC_CONTEXT * context);
  73. /* Generate/Verify MAC for Context */
  74. EM_RESULT aes_cmac (AES_CMAC_CONTEXT * context);
  75. /* Interface to indicate encrypt complete */
  76. void aes_cmac_aes_128_encryption_complete (UCHAR status, UCHAR * data, UINT16 datalen);
  77. #endif /* _H_AES_CMAC_ */