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

Function ComputeLegacyJoinAcceptMIC

pkg/crypto/join_messages.go:133–148  ·  view source on GitHub ↗

ComputeLegacyJoinAcceptMIC computes the Message Integrity Code for a join-accept message - The payload contains MHDR | JoinNonce/AppNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) - In LoRaWAN 1.0, the AppKey is used - In LoRaWAN 1.1 with OptNeg=0, the NwkKey is used

(key types.AES128Key, payload []byte)

Source from the content-addressed store, hash-verified

131// - In LoRaWAN 1.0, the AppKey is used
132// - In LoRaWAN 1.1 with OptNeg=0, the NwkKey is used
133func ComputeLegacyJoinAcceptMIC(key types.AES128Key, payload []byte) ([4]byte, error) {
134 if n := len(payload); n != 13 && n != 29 {
135 return [4]byte{}, errInvalidJoinAcceptPayloadSize.WithAttributes("size", len(payload))
136 }
137 hash, err := cmac.New(key[:])
138 if err != nil {
139 return [4]byte{}, err
140 }
141 _, err = hash.Write(payload)
142 if err != nil {
143 return [4]byte{}, err
144 }
145 var mic [4]byte
146 copy(mic[:], hash.Sum([]byte{}))
147 return mic, nil
148}
149
150// ComputeJoinAcceptMIC computes the Message Integrity Code for a join-accept message
151// - The payload contains MHDR | JoinNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType)

Callers 3

JoinAcceptMICMethod · 0.92
processDownlinkFunction · 0.92

Calls 3

NewMethod · 0.65
WithAttributesMethod · 0.45
WriteMethod · 0.45

Tested by 1