NanoStack lib for Cortex-M4
Dependents: mbedEndpointNetwork mbedEndpointNetworkMJK
Fork of Nanostack_lib by
inc/ccm/ccmLIB.h@4:c449bead5cf3, 2014-06-24 (annotated)
- Committer:
- Mika Karjalainen
- Date:
- Tue Jun 24 16:48:01 2014 +0300
- Revision:
- 4:c449bead5cf3
- Child:
- 11:1b7aaf37a131
Creating initial nanostack release
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 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 24 | |
Mika Karjalainen |
4:c449bead5cf3 | 25 | #ifndef CCMLIB_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 26 | #define CCMLIB_H_ |
Mika Karjalainen |
4:c449bead5cf3 | 27 | #define AES_NO_SECURITY 0x00 |
Mika Karjalainen |
4:c449bead5cf3 | 28 | #define AES_SECURITY_LEVEL_MIC32 0x01 |
Mika Karjalainen |
4:c449bead5cf3 | 29 | #define AES_SECURITY_LEVEL_MIC64 0x02 |
Mika Karjalainen |
4:c449bead5cf3 | 30 | #define AES_SECURITY_LEVEL_MIC128 0x03 |
Mika Karjalainen |
4:c449bead5cf3 | 31 | #define AES_SECURITY_LEVEL_ENC 0x04 |
Mika Karjalainen |
4:c449bead5cf3 | 32 | #define AES_SECURITY_LEVEL_ENC_MIC32 0x05 |
Mika Karjalainen |
4:c449bead5cf3 | 33 | #define AES_SECURITY_LEVEL_ENC_MIC64 0x06 |
Mika Karjalainen |
4:c449bead5cf3 | 34 | #define AES_SECURITY_LEVEL_ENC_MIC128 0x07 |
Mika Karjalainen |
4:c449bead5cf3 | 35 | |
Mika Karjalainen |
4:c449bead5cf3 | 36 | #define AES_CCM_ENCRYPT 0x00 |
Mika Karjalainen |
4:c449bead5cf3 | 37 | #define AES_CCM_DECRYPT 0x01 |
Mika Karjalainen |
4:c449bead5cf3 | 38 | |
Mika Karjalainen |
4:c449bead5cf3 | 39 | /*! |
Mika Karjalainen |
4:c449bead5cf3 | 40 | * \struct ccm_globals_t |
Mika Karjalainen |
4:c449bead5cf3 | 41 | * \brief CCM global structure. |
Mika Karjalainen |
4:c449bead5cf3 | 42 | * Structure is used to configure NONCE, adata and data before call ccm_process_run(). |
Mika Karjalainen |
4:c449bead5cf3 | 43 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 44 | typedef struct |
Mika Karjalainen |
4:c449bead5cf3 | 45 | { |
Mika Karjalainen |
4:c449bead5cf3 | 46 | uint8_t exp_nonce[15]; /**< CCM NONCE buffer Nonce */ |
Mika Karjalainen |
4:c449bead5cf3 | 47 | uint8_t *data_ptr; /**< Pointer to Data IN */ |
Mika Karjalainen |
4:c449bead5cf3 | 48 | uint16_t data_len; /**< Length of Data IN */ |
Mika Karjalainen |
4:c449bead5cf3 | 49 | uint8_t *adata_ptr; /**< Pointer to Auhentication data */ |
Mika Karjalainen |
4:c449bead5cf3 | 50 | uint16_t adata_len; /**< Length of Auhentication data */ |
Mika Karjalainen |
4:c449bead5cf3 | 51 | uint8_t mic_len; /**< ccm_sec_init() will set here length of MIC */ |
Mika Karjalainen |
4:c449bead5cf3 | 52 | uint8_t *mic; /**< Encrypt process will write MIC and decode compare given MIC */ |
Mika Karjalainen |
4:c449bead5cf3 | 53 | }ccm_globals_t; |
Mika Karjalainen |
4:c449bead5cf3 | 54 | |
Mika Karjalainen |
4:c449bead5cf3 | 55 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 56 | * \brief A function to init CCM library. |
Mika Karjalainen |
4:c449bead5cf3 | 57 | * \param sec_level Used CCM security level (0-7). |
Mika Karjalainen |
4:c449bead5cf3 | 58 | * \param ccm_key pointer to 128-key. |
Mika Karjalainen |
4:c449bead5cf3 | 59 | * \param mode AES_CCM_ENCRYPT or AES_CCM_DECRYPT |
Mika Karjalainen |
4:c449bead5cf3 | 60 | * \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 | 61 | * |
Mika Karjalainen |
4:c449bead5cf3 | 62 | * \return Pointer to Global CCM paramameter buffer. |
Mika Karjalainen |
4:c449bead5cf3 | 63 | * \return 0 When parameter fail or CCM is Busy. |
Mika Karjalainen |
4:c449bead5cf3 | 64 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 65 | 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 | 66 | /** |
Mika Karjalainen |
4:c449bead5cf3 | 67 | * \brief A function to run configured CCM process. |
Mika Karjalainen |
4:c449bead5cf3 | 68 | * When AES_CCM_ENCRYPT mode is selected and MIC is needed library will save MIC direct after when data ends. |
Mika Karjalainen |
4:c449bead5cf3 | 69 | * \param sec_level Used CCM security level (0-7). |
Mika Karjalainen |
4:c449bead5cf3 | 70 | * \param ccm_key pointer to 128-key. |
Mika Karjalainen |
4:c449bead5cf3 | 71 | * \param mode AES_CCM_ENCRYPT or AES_CCM_DECRYPT |
Mika Karjalainen |
4:c449bead5cf3 | 72 | * \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 | 73 | * |
Mika Karjalainen |
4:c449bead5cf3 | 74 | * \return 0 CCM process OK and when AES_CCM_DECRYPT mode was selectected also MIC was correct. |
Mika Karjalainen |
4:c449bead5cf3 | 75 | * \return -1 Init have not called or data or adata pointers or lengths are zero. |
Mika Karjalainen |
4:c449bead5cf3 | 76 | * \return -2 Null pointer given to function |
Mika Karjalainen |
4:c449bead5cf3 | 77 | */ |
Mika Karjalainen |
4:c449bead5cf3 | 78 | extern int8_t ccm_process_run(ccm_globals_t *ccm_params); |
Mika Karjalainen |
4:c449bead5cf3 | 79 | |
Mika Karjalainen |
4:c449bead5cf3 | 80 | #endif /* CCMLIB_H_ */ |