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

Function ComputeRejoinRequestMIC

pkg/crypto/join_messages.go:99–125  ·  view source on GitHub ↗

ComputeRejoinRequestMIC computes the Message Integrity Code for a RejoinRequest message - For a type 0 or 2 RejoinRequest, the payload contains MHDR | RejoinType | NetID | DevEUI | RJcount0 - For a type 0 or 2 RejoinRequest, the SNwkSIntKey is used - For a type 1 RejoinRequest, the payload contains

(key types.AES128Key, payload []byte)

Source from the content-addressed store, hash-verified

97// - For a type 1 RejoinRequest, the payload contains MHDR | RejoinType | JoinEUI | DevEUI | RJcount1
98// - For a type 1 RejoinRequest, the JSIntKey is used
99func ComputeRejoinRequestMIC(key types.AES128Key, payload []byte) ([4]byte, error) {
100 if len(payload) != 15 && len(payload) != 20 {
101 return [4]byte{}, errrInvalidRejoinRequestSize.WithAttributes("size", len(payload))
102 }
103 rejoinType := payload[1]
104 switch rejoinType {
105 case 0, 2:
106 if len(payload) != 15 {
107 return [4]byte{}, errrInvalidRejoinRequestType0_2.WithAttributes("size", len(payload))
108 }
109 case 1:
110 if len(payload) != 20 {
111 return [4]byte{}, errrInvalidRejoinRequestType1.WithAttributes("size", len(payload))
112 }
113 }
114 hash, err := cmac.New(key[:])
115 if err != nil {
116 return [4]byte{}, err
117 }
118 _, err = hash.Write(payload)
119 if err != nil {
120 return [4]byte{}, err
121 }
122 var mic [4]byte
123 copy(mic[:], hash.Sum([]byte{}))
124 return mic, nil
125}
126
127var errInvalidJoinAcceptPayloadSize = errInvalidSize("join_accept_payload", "JoinAccept payload", "13 or 29")
128

Callers 1

Calls 3

NewMethod · 0.65
WithAttributesMethod · 0.45
WriteMethod · 0.45

Tested by 1