hal_aes.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**************************************************************************************************
  2. Filename: hal_aes.h
  3. Revised: $Date: 2010-01-08 13:24:55 -0800 (Fri, 08 Jan 2010) $
  4. Revision: $Revision: 21463 $
  5. Description: Support for HW/SW AES encryption.
  6. Copyright 2007-2010 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef HAL_AES_H_
  34. #define HAL_AES_H_
  35. #include "ZComDef.h"
  36. #define STATE_BLENGTH 16 // Number of bytes in State
  37. #define KEY_BLENGTH 16 // Number of bytes in Key
  38. #define KEY_EXP_LENGTH 176 // Nb * (Nr+1) * 4
  39. /* AES Engine is default to hardware AES. To turn on software AES, #define one of the followings:
  40. * #define SOFTWARE_AES TRUE, uses software aes ( slowest setting )
  41. * #define SW_AES_AND_KEY_EXP TRUE, enables software aes with key expansion ( improves speed at the cost of 176 bytes of data (RAM) )
  42. */
  43. #if ((defined SOFTWARE_AES) && (SOFTWARE_AES == TRUE)) && ((defined SW_AES_AND_KEY_EXP) && (SW_AES_AND_KEY_EXP == TRUE))
  44. #error "SOFTWARE_AES and SW_AES_AND_KEY_EXP cannot be both defined."
  45. #endif
  46. extern void HalAesInit( void );
  47. extern void AesLoadBlock( uint8 * );
  48. extern void AesStartBlock( uint8 *, uint8 * );
  49. extern void AesStartShortBlock( uint8 *, uint8 * );
  50. extern void AesLoadIV(uint8 *);
  51. extern void AesDmaSetup( uint8 *, uint16, uint8 *, uint16 );
  52. extern void AesLoadKey( uint8 * );
  53. extern void (*pSspAesEncrypt)( uint8 *, uint8 * );
  54. extern void ssp_HW_KeyInit (uint8 *);
  55. extern void sspKeyExpansion (uint8 *, uint8 *);
  56. extern void sspAesEncryptHW (uint8 *, uint8 *);
  57. extern void sspAesEncryptKeyExp (uint8 *, uint8 *);
  58. extern void sspAesEncryptBasic (uint8 *, uint8 *);
  59. extern void sspAesEncrypt( uint8 *key, uint8 *buf );
  60. #define AES_BUSY 0x08
  61. #define ENCRYPT 0x00
  62. #define DECRYPT 0x01
  63. // Macro for setting the mode of the AES operation
  64. #define AES_SETMODE(mode) do { ENCCS &= ~0x70; ENCCS |= mode; } while (0)
  65. // _mode_ is one of
  66. #define CBC 0x00
  67. #define CFB 0x10
  68. #define OFB 0x20
  69. #define CTR 0x30
  70. #define ECB 0x40
  71. #define CBC_MAC 0x50
  72. // Macro for starting or stopping encryption or decryption
  73. #define AES_SET_ENCR_DECR_KEY_IV(mode) \
  74. do { \
  75. ENCCS = (ENCCS & ~0x07) | mode \
  76. } while(0)
  77. // Where _mode_ is one of
  78. #define AES_ENCRYPT 0x00;
  79. #define AES_DECRYPT 0x02;
  80. #define AES_LOAD_KEY 0x04;
  81. #define AES_LOAD_IV 0x06;
  82. // Macro for starting the AES module for either encryption, decryption,
  83. // key or initialisation vector loading.
  84. #define AES_START() ENCCS |= 0x01
  85. /* Used by DMA macros to shift 1 to create a mask for DMA registers. */
  86. #define HAL_DMA_AES_IN 1
  87. #define HAL_DMA_AES_OUT 2
  88. /* AES registers */
  89. #define HAL_AES_IN_ADDR 0x70B1
  90. #define HAL_AES_OUT_ADDR 0x70B2
  91. #if !defined (HAL_AES_DMA) || (HAL_AES_DMA == FALSE)
  92. #define HAL_AES_DELAY() \
  93. do { \
  94. uint8 delay = 15; \
  95. while(delay--); \
  96. } while(0)
  97. #endif
  98. // End of CC2530 hardware AES engine definitions
  99. #endif // HAL_AES_H_