NanoStack lib for Cortex-M4
Dependents: mbedEndpointNetwork mbedEndpointNetworkMJK
Fork of Nanostack_lib by
inc/ccm/ccmLIB.h@11:1b7aaf37a131, 2014-06-25 (annotated)
- Committer:
- jusu_81
- Date:
- Wed Jun 25 21:05:58 2014 +0000
- Revision:
- 11:1b7aaf37a131
- Parent:
- 4:c449bead5cf3
Added C++ & C Extern C sectors to hedaer files.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mika Karjalainen |
4:c449bead5cf3 | 1 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 2 | * |
Mika Karjalainen |
4:c449bead5cf3 | 3 | * \file ccmLIB.h |
Mika Karjalainen |
4:c449bead5cf3 | 4 | * \brief CCM Library API. |
Mika Karjalainen |
4:c449bead5cf3 | 5 | * Copyright Sensinode Ltd 2013 |
Mika Karjalainen |
4:c449bead5cf3 | 6 | * |
Mika Karjalainen |
4:c449bead5cf3 | 7 | * \section ccm-api CCM Library API: |
Mika Karjalainen |
4:c449bead5cf3 | 8 | * - ccm_sec_init(), A function to init CCM library. |
Mika Karjalainen |
4:c449bead5cf3 | 9 | * - ccm_process_run(), A function to run configured CCM process |
Mika Karjalainen |
4:c449bead5cf3 | 10 | * |
Mika Karjalainen |
4:c449bead5cf3 | 11 | * \section ccm-inctuction CCM process sequency: |
Mika Karjalainen |
4:c449bead5cf3 | 12 | * 1. Init CCM library by , ccm key, ccm_sec_init() |
Mika Karjalainen |
4:c449bead5cf3 | 13 | * - security level |
Mika Karjalainen |
4:c449bead5cf3 | 14 | * - 128-bit ccm key |
Mika Karjalainen |
4:c449bead5cf3 | 15 | * - mode: AES_CCM_ENCRYPT or AES_CCM_DECRYPT |
Mika Karjalainen |
4:c449bead5cf3 | 16 | * - CCM L parameter: 2 or 3 depends nonce legth (802.15.4 use 2 and TLS security use 3) |
Mika Karjalainen |
4:c449bead5cf3 | 17 | * 2. Define ADATA pointer and length, if returned global structure mic_len field is > 0 |
Mika Karjalainen |
4:c449bead5cf3 | 18 | * 3. Set Data pointer and length |
Mika Karjalainen |
4:c449bead5cf3 | 19 | * 4. Do configured CCM process ccm_process_run() |
Mika Karjalainen |
4:c449bead5cf3 | 20 | * 5. Check Return value: |
Mika Karjalainen |
4:c449bead5cf3 | 21 | * -If 0 Process ok |
Mika Karjalainen |
4:c449bead5cf3 | 22 | * -< 0 MIC fail or parameter fail |
Mika Karjalainen |
4:c449bead5cf3 | 23 | */ |
jusu_81 | 11:1b7aaf37a131 | 24 | #ifdef __cplusplus |
jusu_81 | 11:1b7aaf37a131 | 25 | extern "C" { |
jusu_81 | 11:1b7aaf37a131 | 26 | #endif |
Mika Karjalainen |
4:c449bead5cf3 | 27 | #ifndef CCMLIB_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 28 | #define CCMLIB_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 29 | #define AES_NO_SECURITY 0x00 |
Mika Karjalainen |
4:c449bead5cf3 | 30 | #define AES_SECURITY_LEVEL_MIC32 0x01 |
Mika Karjalainen |
4:c449bead5cf3 | 31 | #define AES_SECURITY_LEVEL_MIC64 0x02 |
Mika Karjalainen |
4:c449bead5cf3 | 32 | #define AES_SECURITY_LEVEL_MIC128 0x03 |
Mika Karjalainen |
4:c449bead5cf3 | 33 | #define AES_SECURITY_LEVEL_ENC 0x04 |
Mika Karjalainen |
4:c449bead5cf3 | 34 | #define AES_SECURITY_LEVEL_ENC_MIC32 0x05 |
Mika Karjalainen |
4:c449bead5cf3 | 35 | #define AES_SECURITY_LEVEL_ENC_MIC64 0x06 |
Mika Karjalainen |
4:c449bead5cf3 | 36 | #define AES_SECURITY_LEVEL_ENC_MIC128 0x07 |
Mika Karjalainen |
4:c449bead5cf3 | 37 | |
Mika Karjalainen |
4:c449bead5cf3 | 38 | #define AES_CCM_ENCRYPT 0x00 |
Mika Karjalainen |
4:c449bead5cf3 | 39 | #define AES_CCM_DECRYPT 0x01 |
Mika Karjalainen |
4:c449bead5cf3 | 40 | |
Mika Karjalainen |
4:c449bead5cf3 | 41 | /*! |
Mika Karjalainen |
4:c449bead5cf3 | 42 | * \struct ccm_globals_t |
Mika Karjalainen |
4:c449bead5cf3 | 43 | * \brief CCM global structure. |
Mika Karjalainen |
4:c449bead5cf3 | 44 | * Structure is used to configure NONCE, adata and data before call ccm_process_run(). |
Mika Karjalainen |
4:c449bead5cf3 | 45 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 46 | typedef struct |
Mika Karjalainen |
4:c449bead5cf3 | 47 | { |
Mika Karjalainen |
4:c449bead5cf3 | 48 | uint8_t exp_nonce[15]; /**< CCM NONCE buffer Nonce */ |
Mika Karjalainen |
4:c449bead5cf3 | 49 | uint8_t *data_ptr; /**< Pointer to Data IN */ |
Mika Karjalainen |
4:c449bead5cf3 | 50 | uint16_t data_len; /**< Length of Data IN */ |
Mika Karjalainen |
4:c449bead5cf3 | 51 | uint8_t *adata_ptr; /**< Pointer to Auhentication data */ |
Mika Karjalainen |
4:c449bead5cf3 | 52 | uint16_t adata_len; /**< Length of Auhentication data */ |
Mika Karjalainen |
4:c449bead5cf3 | 53 | uint8_t mic_len; /**< ccm_sec_init() will set here length of MIC */ |
Mika Karjalainen |
4:c449bead5cf3 | 54 | uint8_t *mic; /**< Encrypt process will write MIC and decode compare given MIC */ |
Mika Karjalainen |
4:c449bead5cf3 | 55 | }ccm_globals_t; |
Mika Karjalainen |
4:c449bead5cf3 | 56 | |
Mika Karjalainen |
4:c449bead5cf3 | 57 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 58 | * \brief A function to init CCM library. |
Mika Karjalainen |
4:c449bead5cf3 | 59 | * \param sec_level Used CCM security level (0-7). |
Mika Karjalainen |
4:c449bead5cf3 | 60 | * \param ccm_key pointer to 128-key. |
Mika Karjalainen |
4:c449bead5cf3 | 61 | * \param mode AES_CCM_ENCRYPT or AES_CCM_DECRYPT |
Mika Karjalainen |
4:c449bead5cf3 | 62 | * \param ccm_l cuold be 2 or 3. 2 when NONCE length is 13 and 3 when length is 12. (NONCE Len= (15-ccm_l)) |
Mika Karjalainen |
4:c449bead5cf3 | 63 | * |
Mika Karjalainen |
4:c449bead5cf3 | 64 | * \return Pointer to Global CCM paramameter buffer. |
Mika Karjalainen |
4:c449bead5cf3 | 65 | * \return 0 When parameter fail or CCM is Busy. |
Mika Karjalainen |
4:c449bead5cf3 | 66 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 67 | extern ccm_globals_t * ccm_sec_init(uint8_t sec_level, uint8_t *ccm_key, uint8_t mode, uint8_t ccm_l); |
Mika Karjalainen |
4:c449bead5cf3 | 68 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 69 | * \brief A function to run configured CCM process. |
Mika Karjalainen |
4:c449bead5cf3 | 70 | * When AES_CCM_ENCRYPT mode is selected and MIC is needed library will save MIC direct after when data ends. |
Mika Karjalainen |
4:c449bead5cf3 | 71 | * \param sec_level Used CCM security level (0-7). |
Mika Karjalainen |
4:c449bead5cf3 | 72 | * \param ccm_key pointer to 128-key. |
Mika Karjalainen |
4:c449bead5cf3 | 73 | * \param mode AES_CCM_ENCRYPT or AES_CCM_DECRYPT |
Mika Karjalainen |
4:c449bead5cf3 | 74 | * \param ccm_l cuold be 2 or 3. 2 when NONCE length is 13 and 3 when length is 12. (NONCE Len= (15-ccm_l)) |
Mika Karjalainen |
4:c449bead5cf3 | 75 | * |
Mika Karjalainen |
4:c449bead5cf3 | 76 | * \return 0 CCM process OK and when AES_CCM_DECRYPT mode was selectected also MIC was correct. |
Mika Karjalainen |
4:c449bead5cf3 | 77 | * \return -1 Init have not called or data or adata pointers or lengths are zero. |
Mika Karjalainen |
4:c449bead5cf3 | 78 | * \return -2 Null pointer given to function |
Mika Karjalainen |
4:c449bead5cf3 | 79 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 80 | extern int8_t ccm_process_run(ccm_globals_t *ccm_params); |
jusu_81 | 11:1b7aaf37a131 | 81 | #ifdef __cplusplus |
jusu_81 | 11:1b7aaf37a131 | 82 | } |
jusu_81 | 11:1b7aaf37a131 | 83 | #endif |
Mika Karjalainen |
4:c449bead5cf3 | 84 | #endif /* CCMLIB_H_ */ |