ll_enc.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /*******************************************************************************
  29. Filename: ll_enc.h
  30. Revised:
  31. Revision:
  32. Description: This file contains the Link Layer (LL) types, contants,
  33. API's etc. for the Bluetooth Low Energy (BLE) Controller
  34. CCM encryption and decryption.
  35. This API is based on ULP BT LE D09R23.
  36. *******************************************************************************/
  37. #ifndef LL_ENC_H
  38. #define LL_ENC_H
  39. #ifdef __cplusplus
  40. extern "C"
  41. {
  42. #endif
  43. /*******************************************************************************
  44. * INCLUDES
  45. */
  46. #include "bcomdef.h"
  47. #include "ll_def.h"
  48. /*******************************************************************************
  49. * MACROS
  50. */
  51. /*******************************************************************************
  52. * CONSTANTS
  53. */
  54. #define LL_ENC_TX_DIRECTION_MASTER 1
  55. #define LL_ENC_TX_DIRECTION_SLAVE 0
  56. #define LL_ENC_RX_DIRECTION_MASTER 0
  57. #define LL_ENC_RX_DIRECTION_SLAVE 1
  58. #define LL_ENC_DATA_BANK_MASK 0xFF7F
  59. #define LL_ENC_TRUE_RAND_BUF_SIZE ((LL_ENC_IV_LEN/2) + (LL_ENC_SKD_LEN/2))
  60. // Generate Session Key using LTK for key and SKD for plaintext.
  61. #define LL_ENC_GenerateSK LL_ENC_AES128_Encrypt
  62. /*******************************************************************************
  63. * TYPEDEFS
  64. */
  65. /*******************************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. /*******************************************************************************
  69. * GLOBAL VARIABLES
  70. */
  71. extern uint8 dataPkt[2*LL_ENC_BLOCK_LEN];
  72. extern uint8 cachedTRNGdata[ LL_ENC_TRUE_RAND_BUF_SIZE ];
  73. /*******************************************************************************
  74. * Functions
  75. */
  76. // Random Number Generation
  77. extern uint8 LL_ENC_GeneratePseudoRandNum( void );
  78. extern uint8 LL_ENC_GenerateTrueRandNum( uint8 *buf, uint8 len );
  79. // CCM Encryption
  80. extern void LL_ENC_AES128_Encrypt( uint8 *key, uint8 *plaintext, uint8 *ciphertext );
  81. extern void LL_ENC_AES128_Decrypt( uint8 *key, uint8 *ciphertext, uint8 *plaintext );
  82. extern void LL_ENC_LoadEmptyIV( void );
  83. extern void LL_ENC_ReverseBytes( uint8 *buf, uint8 len );
  84. extern void LL_ENC_GenDeviceSKD( uint8 *SKD );
  85. extern void LL_ENC_GenDeviceIV( uint8 *IV );
  86. extern void LL_ENC_GenerateNonce( uint32 pktCnt, uint8 direction, uint8 *nonce );
  87. extern void LL_ENC_EncryptMsg( uint8 *nonce, uint8 pktLen, uint8 *pbuf, uint8 *mic );
  88. extern void LL_ENC_DecryptMsg( uint8 *nonce, uint8 pktLen, uint8 *pBuf, uint8 *mic );
  89. extern void LL_ENC_Encrypt( llConnState_t *connPtr, uint8 pktHdr, uint8 pktLen, uint8 *pBuf );
  90. extern uint8 LL_ENC_Decrypt( llConnState_t *connPtr, uint8 pktHdr, uint8 pktLen, uint8 *pBuf );
  91. extern void LL_ENC_sm_ah( uint8 *pK, uint8 *pR, uint8 *pAh );
  92. //
  93. extern void LL_ENC_MoveData( uint8 *pDst, uint8 *pSrc, uint16 len );
  94. #ifdef __cplusplus
  95. }
  96. #endif
  97. #endif /* LL_ENC_H */