Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LoRaMacLib by
mac/crypto/LoRaMacCrypto.h@0:9be122c18509, 2015-08-12 (annotated)
- Committer:
- GregCr
- Date:
- Wed Aug 12 14:08:29 2015 +0000
- Revision:
- 0:9be122c18509
First Implementation
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| GregCr | 0:9be122c18509 | 1 | /* |
| GregCr | 0:9be122c18509 | 2 | / _____) _ | | |
| GregCr | 0:9be122c18509 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
| GregCr | 0:9be122c18509 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
| GregCr | 0:9be122c18509 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
| GregCr | 0:9be122c18509 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
| GregCr | 0:9be122c18509 | 7 | (C)2013 Semtech |
| GregCr | 0:9be122c18509 | 8 | |
| GregCr | 0:9be122c18509 | 9 | Description: LoRa MAC layer implementation |
| GregCr | 0:9be122c18509 | 10 | |
| GregCr | 0:9be122c18509 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
| GregCr | 0:9be122c18509 | 12 | |
| GregCr | 0:9be122c18509 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
| GregCr | 0:9be122c18509 | 14 | */ |
| GregCr | 0:9be122c18509 | 15 | #ifndef __LORAMAC_CRYPTO_H__ |
| GregCr | 0:9be122c18509 | 16 | #define __LORAMAC_CRYPTO_H__ |
| GregCr | 0:9be122c18509 | 17 | |
| GregCr | 0:9be122c18509 | 18 | /*! |
| GregCr | 0:9be122c18509 | 19 | * Copies size elements of src array to dst array |
| GregCr | 0:9be122c18509 | 20 | * |
| GregCr | 0:9be122c18509 | 21 | * \remark STM32 Standard memcpy function only works on pointers that are aligned |
| GregCr | 0:9be122c18509 | 22 | * |
| GregCr | 0:9be122c18509 | 23 | * \param [IN] src Source array |
| GregCr | 0:9be122c18509 | 24 | * \param [OUT] dst Destination array |
| GregCr | 0:9be122c18509 | 25 | * \param [IN] size Number of bytes to be copied |
| GregCr | 0:9be122c18509 | 26 | */ |
| GregCr | 0:9be122c18509 | 27 | #define LoRaMacMemCpy( src, dst, size ) memcpy1( dst, src, size ) |
| GregCr | 0:9be122c18509 | 28 | |
| GregCr | 0:9be122c18509 | 29 | /*! |
| GregCr | 0:9be122c18509 | 30 | * Computes the LoRaMAC frame MIC field |
| GregCr | 0:9be122c18509 | 31 | * |
| GregCr | 0:9be122c18509 | 32 | * \param [IN] buffer Data buffer |
| GregCr | 0:9be122c18509 | 33 | * \param [IN] size Data buffer size |
| GregCr | 0:9be122c18509 | 34 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 35 | * \param [IN] address Frame address |
| GregCr | 0:9be122c18509 | 36 | * \param [IN] dir Frame direction [0: uplink, 1: downlink] |
| GregCr | 0:9be122c18509 | 37 | * \param [IN] sequenceCounter Frame sequence counter |
| GregCr | 0:9be122c18509 | 38 | * \param [OUT] mic Computed MIC field |
| GregCr | 0:9be122c18509 | 39 | */ |
| GregCr | 0:9be122c18509 | 40 | void LoRaMacComputeMic( uint8_t *buffer, uint16_t size, uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint32_t *mic ); |
| GregCr | 0:9be122c18509 | 41 | |
| GregCr | 0:9be122c18509 | 42 | /*! |
| GregCr | 0:9be122c18509 | 43 | * Computes the LoRaMAC payload encryption |
| GregCr | 0:9be122c18509 | 44 | * |
| GregCr | 0:9be122c18509 | 45 | * \param [IN] buffer Data buffer |
| GregCr | 0:9be122c18509 | 46 | * \param [IN] size Data buffer size |
| GregCr | 0:9be122c18509 | 47 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 48 | * \param [IN] address Frame address |
| GregCr | 0:9be122c18509 | 49 | * \param [IN] dir Frame direction [0: uplink, 1: downlink] |
| GregCr | 0:9be122c18509 | 50 | * \param [IN] sequenceCounter Frame sequence counter |
| GregCr | 0:9be122c18509 | 51 | * \param [OUT] encBuffer Encrypted buffer |
| GregCr | 0:9be122c18509 | 52 | */ |
| GregCr | 0:9be122c18509 | 53 | void LoRaMacPayloadEncrypt( uint8_t *buffer, uint16_t size, uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *encBuffer ); |
| GregCr | 0:9be122c18509 | 54 | |
| GregCr | 0:9be122c18509 | 55 | /*! |
| GregCr | 0:9be122c18509 | 56 | * Computes the LoRaMAC payload decryption |
| GregCr | 0:9be122c18509 | 57 | * |
| GregCr | 0:9be122c18509 | 58 | * \param [IN] buffer Data buffer |
| GregCr | 0:9be122c18509 | 59 | * \param [IN] size Data buffer size |
| GregCr | 0:9be122c18509 | 60 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 61 | * \param [IN] address Frame address |
| GregCr | 0:9be122c18509 | 62 | * \param [IN] dir Frame direction [0: uplink, 1: downlink] |
| GregCr | 0:9be122c18509 | 63 | * \param [IN] sequenceCounter Frame sequence counter |
| GregCr | 0:9be122c18509 | 64 | * \param [OUT] decBuffer Decrypted buffer |
| GregCr | 0:9be122c18509 | 65 | */ |
| GregCr | 0:9be122c18509 | 66 | void LoRaMacPayloadDecrypt( uint8_t *buffer, uint16_t size, uint8_t *key, uint32_t address, uint8_t dir, uint32_t sequenceCounter, uint8_t *decBuffer ); |
| GregCr | 0:9be122c18509 | 67 | |
| GregCr | 0:9be122c18509 | 68 | /*! |
| GregCr | 0:9be122c18509 | 69 | * Computes the LoRaMAC Join Request frame MIC field |
| GregCr | 0:9be122c18509 | 70 | * |
| GregCr | 0:9be122c18509 | 71 | * \param [IN] buffer Data buffer |
| GregCr | 0:9be122c18509 | 72 | * \param [IN] size Data buffer size |
| GregCr | 0:9be122c18509 | 73 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 74 | * \param [OUT] mic Computed MIC field |
| GregCr | 0:9be122c18509 | 75 | */ |
| GregCr | 0:9be122c18509 | 76 | void LoRaMacJoinComputeMic( uint8_t *buffer, uint16_t size, const uint8_t *key, uint32_t *mic ); |
| GregCr | 0:9be122c18509 | 77 | |
| GregCr | 0:9be122c18509 | 78 | /*! |
| GregCr | 0:9be122c18509 | 79 | * Computes the LoRaMAC join frame decryption |
| GregCr | 0:9be122c18509 | 80 | * |
| GregCr | 0:9be122c18509 | 81 | * \param [IN] buffer Data buffer |
| GregCr | 0:9be122c18509 | 82 | * \param [IN] size Data buffer size |
| GregCr | 0:9be122c18509 | 83 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 84 | * \param [OUT] decBuffer Decrypted buffer |
| GregCr | 0:9be122c18509 | 85 | */ |
| GregCr | 0:9be122c18509 | 86 | void LoRaMacJoinDecrypt( uint8_t *buffer, uint16_t size, const uint8_t *key, uint8_t *decBuffer ); |
| GregCr | 0:9be122c18509 | 87 | |
| GregCr | 0:9be122c18509 | 88 | /*! |
| GregCr | 0:9be122c18509 | 89 | * Computes the LoRaMAC join frame decryption |
| GregCr | 0:9be122c18509 | 90 | * |
| GregCr | 0:9be122c18509 | 91 | * \param [IN] key AES key to be used |
| GregCr | 0:9be122c18509 | 92 | * \param [IN] appNonce Application nonce |
| GregCr | 0:9be122c18509 | 93 | * \param [IN] devNonce Device nonce |
| GregCr | 0:9be122c18509 | 94 | * \param [OUT] nwkSKey Network session key |
| GregCr | 0:9be122c18509 | 95 | * \param [OUT] appSKey Application session key |
| GregCr | 0:9be122c18509 | 96 | */ |
| GregCr | 0:9be122c18509 | 97 | void LoRaMacJoinComputeSKeys( const uint8_t *key, uint8_t *appNonce, uint16_t devNonce, uint8_t *nwkSKey, uint8_t *appSKey ); |
| GregCr | 0:9be122c18509 | 98 | |
| GregCr | 0:9be122c18509 | 99 | #endif // __LORAMAC_CRYPTO_H__ |
