mac_security.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /**************************************************************************************************
  2. Filename: mac_security.h
  3. Revised: $Date: 2011-03-25 15:25:58 -0700 (Fri, 25 Mar 2011) $
  4. Revision: $Revision: 25522 $
  5. Description: Internal interface file for MAC security module.
  6. Copyright 2010-2011 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 MAC_SECURITY_H
  34. #define MAC_SECURITY_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Includes
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. #include "mac_api.h"
  40. #include "mac_high_level.h"
  41. /* ------------------------------------------------------------------------------------------------
  42. * Typedefs
  43. * ------------------------------------------------------------------------------------------------
  44. */
  45. /* Max frame counter */
  46. #define MAC_MAX_FRAME_COUNTER 0xFFFFFFFF
  47. /* Nonce length */
  48. #define MAC_NONCE_LEN 13
  49. /* MIC length */
  50. #define MAC_MIC_LEN 16
  51. /* This MAC status is only locally used in MAC security */
  52. #define MAC_CONDITIONALLY_PASSED (MAC_IMPROPER_SECURITY_LEVEL-1)
  53. /* Device lookup size short */
  54. #define MAC_DEVICE_LOOKUP_SHORT_LEN 4
  55. /* Device lookup size lonh */
  56. #define MAC_DEVICE_LOOKUP_LONG_LEN 8
  57. /* ------------------------------------------------------------------------------------------------
  58. * Global Variables
  59. * ------------------------------------------------------------------------------------------------
  60. */
  61. /* Length M of authentication tag indexed by security level */
  62. extern CODE const uint8 macAuthTagLen[];
  63. /* Length of key source indexed by key identifier mode */
  64. extern CODE const uint8 macKeySourceLen[];
  65. /* Incoming frame counter in the auxiliary security header */
  66. extern uint32 macFrameCounter;
  67. /* ------------------------------------------------------------------------------------------------
  68. * Function Prototypes
  69. * ------------------------------------------------------------------------------------------------
  70. */
  71. /**************************************************************************************************
  72. * @fn macOutgoingFrameSecurity
  73. *
  74. * @brief The inputs to this procedure are the frame to be secured and the security
  75. * parameters from the originating primitive or automatic request PIB attributes.
  76. * The outputs from this procedure are the status of the procedure and, if this status
  77. * is MAC_SUCCESS, pointer to the key to be used to secure the outgoing frame.
  78. *
  79. * input parameters
  80. *
  81. * @param pBuf - Pointer to buffer containing tx struct.
  82. * @param pDstAddr - Destination address.
  83. * @param dstPanId - Destination PAN ID.
  84. *
  85. * output parameters
  86. *
  87. * @param ppKey - Pointer to pointer to key to be used to secure the outgoing frame
  88. *
  89. * @return MAC_SUCCESS if successful, otherwise failure status.
  90. **************************************************************************************************
  91. */
  92. MAC_INTERNAL_API uint8 macOutgoingFrameSecurity( macTx_t *pBuf,
  93. sAddr_t *pDstAddr,
  94. uint16 dstPanId,
  95. uint8 **ppKey );
  96. /**************************************************************************************************
  97. * @fn macIncomingFrameSecurity
  98. *
  99. * @brief The input to this procedure is the frame to be unsecured. The outputs from this
  100. * procedure are the unsecured frame, the security level, the key identifier mode, the
  101. * key source, the key index, and the status of the procedure. All outputs of this
  102. * procedure are assumed to be invalid unless and until explicitly set in this
  103. * procedure. It is assumed that the PIB attributes associating KeyDescriptors in
  104. * macKeyTable with a single, unique device or a number of devices will have been
  105. * established by the next higher layer.
  106. *
  107. * input parameters
  108. *
  109. * @param pMsg - pointer to the frame to be unsecured.
  110. *
  111. * output parameters
  112. *
  113. * @param pMsg - pointer to the unsecured frame
  114. *
  115. * @return MAC_SUCCESS if successful, otherwise failure status.
  116. **************************************************************************************************
  117. */
  118. MAC_INTERNAL_API uint8 macIncomingFrameSecurity( macRx_t *pMsg );
  119. /**************************************************************************************************
  120. * @fn macCcmStarTransform
  121. *
  122. * @brief This function is used to do CCM* transformation. The inputs to this procedure are
  123. * the key, nonce, a data, m data. The output from this procedure is c data.
  124. *
  125. * input parameters
  126. *
  127. * @param pKey - pointer to key
  128. * @param securityLevel - security level
  129. * @param pAData - pointer to a data
  130. * @param aDataLen - a data length
  131. * @param pMData - pointer to m data
  132. * @param mDataLen - m data length
  133. *
  134. * output parameters
  135. *
  136. * @return MAC_SUCCESS if successful, otherwise failure status.
  137. **************************************************************************************************
  138. */
  139. MAC_INTERNAL_API uint8 macCcmStarTransform( uint8 *pKey,
  140. uint8 securityLevel,
  141. uint8 *pAData,
  142. uint8 aDataLen,
  143. uint8 *pMData,
  144. uint8 mDataLen );
  145. /**************************************************************************************************
  146. */
  147. #endif /* MAC_SECURITY_H */