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

Function ComputeJoinAcceptMIC

pkg/crypto/join_messages.go:153–172  ·  view source on GitHub ↗

ComputeJoinAcceptMIC computes the Message Integrity Code for a join-accept message - The payload contains MHDR | JoinNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType) - the joinReqType is 0xFF in reply to a join-request or the rejoin type in reply to a RejoinRequest

(jsIntKey types.AES128Key, joinReqType byte, joinEUI types.EUI64, dn types.DevNonce, payload []byte)

Source from the content-addressed store, hash-verified

151// - The payload contains MHDR | JoinNonce | NetID | DevAddr | DLSettings | RxDelay | (CFList | CFListType)
152// - the joinReqType is 0xFF in reply to a join-request or the rejoin type in reply to a RejoinRequest
153func ComputeJoinAcceptMIC(jsIntKey types.AES128Key, joinReqType byte, joinEUI types.EUI64, dn types.DevNonce, payload []byte) ([4]byte, error) {
154 if n := len(payload); n != 13 && n != 29 {
155 return [4]byte{}, errInvalidJoinAcceptPayloadSize.WithAttributes("size", len(payload))
156 }
157 hash, err := cmac.New(jsIntKey[:])
158 if err != nil {
159 return [4]byte{}, err
160 }
161 _, err = hash.Write(append(append([]byte{joinReqType}, reverse(joinEUI[:])...), reverse(dn[:])...))
162 if err != nil {
163 return [4]byte{}, err
164 }
165 _, err = hash.Write(payload)
166 if err != nil {
167 return [4]byte{}, err
168 }
169 var mic [4]byte
170 copy(mic[:], hash.Sum([]byte{}))
171 return mic, nil
172}

Callers 3

JoinAcceptMICMethod · 0.92
processDownlinkFunction · 0.92
TestComputeJoinAcceptMICFunction · 0.85

Calls 4

reverseFunction · 0.85
NewMethod · 0.65
WithAttributesMethod · 0.45
WriteMethod · 0.45

Tested by 1

TestComputeJoinAcceptMICFunction · 0.68