ComputeJoinRequestMIC computes the Message Integrity Code for a join-request message - The payload contains MHDR | JoinEUI/AppEUI | DevEUI | DevNonce - In LoRaWAN 1.0, the AppKey is used - In LoRaWAN 1.1, the NwkKey is used
(key types.AES128Key, payload []byte)
| 69 | // - In LoRaWAN 1.0, the AppKey is used |
| 70 | // - In LoRaWAN 1.1, the NwkKey is used |
| 71 | func ComputeJoinRequestMIC(key types.AES128Key, payload []byte) ([4]byte, error) { |
| 72 | if len(payload) != 19 { |
| 73 | return [4]byte{}, errInvalidJoinRequestPayloadSize.WithAttributes("size", len(payload)) |
| 74 | } |
| 75 | hash, err := cmac.New(key[:]) |
| 76 | if err != nil { |
| 77 | return [4]byte{}, err |
| 78 | } |
| 79 | _, err = hash.Write(payload) |
| 80 | if err != nil { |
| 81 | return [4]byte{}, err |
| 82 | } |
| 83 | var mic [4]byte |
| 84 | copy(mic[:], hash.Sum([]byte{})) |
| 85 | return mic, nil |
| 86 | } |
| 87 | |
| 88 | var ( |
| 89 | errrInvalidRejoinRequestSize = errInvalidSize("rejoin_request", "rejoin-request", "15 or 20") |