Document

LoRaWAN® Specification v1.0.1

Issue link: https://read.uberflip.com/i/1428386

Contents of this Issue

Navigation

Page 20 of 90

LoRaWAN Specification ©2016 LoRa™ Alliance Page 21 of 91 The authors reserve the right to change specifications without notice. 4.3.3 MAC Frame Payload Encryption (FRMPayload) 1 If a data frame carries a payload, FRMPayload must be encrypted before the message 2 integrity code (MIC) is calculated. 3 The encryption scheme used is based on the generic algorithm described in IEEE 4 802.15.4/2006 Annex B [IEEE802154] using AES with a key length of 128 bits. 5 The key K used depends on the FPort of the data message: 6 7 FPort K 0 NwkSKey 1..255 AppSKey Table 3: FPort list 8 The fields encrypted are: 9 pld = FRMPayload 10 For each data message, the algorithm defines a sequence of Blocks A i for i = 1..k with k = 11 ceil(len(pld) / 16): 12 Size (bytes) 1 4 1 4 4 1 1 A i 0x01 4 x 0x00 Dir DevAddr FCntUp or FCntDown 0x00 i The direction field (Dir) is 0 for uplink frames and 1 for downlink frames. 13 The blocks A i are encrypted to get a sequence S of blocks S i : 14 15 S i = aes128_encrypt(K, A i ) for i = 1..k 16 S = S 1 | S 2 | .. | S k 17 Encryption and decryption of the payload is done by truncating 18 19 (pld | pad 16 ) xor S 20 to the first len(pld) octets. 21 4.4 Message Integrity Code (MIC) 22 The message integrity code (MIC) is calculated over all the fields in the message. 23 24 msg = MHDR | FHDR | FPort | FRMPayload 25 whereby len(msg) denotes the length of the message in octets. 26 The MIC is calculated as follows [RFC4493]: 27 28 cmac = aes128_cmac(NwkSKey, B 0 | msg) 29 MIC = cmac[0..3] 30 31 whereby the block B 0 is defined as follows: 32 Size (bytes) 1 4 1 4 4 1 1 B 0 0x49 4 x 0x00 Dir DevAddr FCntUp or FCntDown 0x00 len(msg) 33 The direction field (Dir) is 0 for uplink frames and 1 for downlink frames. 34

Articles in this issue

view archives of Document - LoRaWAN® Specification v1.0.1