MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / ComputeJoinRequestMIC

Function ComputeJoinRequestMIC

pkg/crypto/join_messages.go:71–86  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

69// - In LoRaWAN 1.0, the AppKey is used
70// - In LoRaWAN 1.1, the NwkKey is used
71func 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
88var (
89 errrInvalidRejoinRequestSize = errInvalidSize("rejoin_request", "rejoin-request", "15 or 20")

Callers 4

JoinRequestMICMethod · 0.92
randomJoinRequestPayloadFunction · 0.92
simulate.goFile · 0.92

Calls 3

NewMethod · 0.65
WithAttributesMethod · 0.45
WriteMethod · 0.45

Tested by 1