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

Function computeMIC

pkg/crypto/data_messages.go:118–138  ·  view source on GitHub ↗
(key types.AES128Key, dir uint8, confFCnt uint16, addr types.DevAddr, fCnt uint32, payload []byte)

Source from the content-addressed store, hash-verified

116}
117
118func computeMIC(key types.AES128Key, dir uint8, confFCnt uint16, addr types.DevAddr, fCnt uint32, payload []byte) ([4]byte, error) {
119 hash, _ := cmac.New(key[:])
120 var b0 [aes.BlockSize]byte
121 b0[0] = 0x49
122 binary.LittleEndian.PutUint16(b0[1:3], confFCnt)
123 b0[5] = dir
124 copy(b0[6:10], reverse(addr[:]))
125 binary.LittleEndian.PutUint32(b0[10:14], fCnt)
126 b0[15] = uint8(len(payload))
127 _, err := hash.Write(b0[:])
128 if err != nil {
129 return [4]byte{}, err
130 }
131 _, err = hash.Write(payload)
132 if err != nil {
133 return [4]byte{}, err
134 }
135 var mic [4]byte
136 copy(mic[:], hash.Sum([]byte{}))
137 return mic, nil
138}
139
140// ComputeLegacyUplinkMIC computes the Uplink Message Integrity Code.
141// - The payload contains MHDR | FHDR | FPort | FRMPayload

Callers 4

ComputeLegacyUplinkMICFunction · 0.85
ComputeUplinkMICFunction · 0.85
ComputeLegacyDownlinkMICFunction · 0.85
ComputeDownlinkMICFunction · 0.85

Calls 3

reverseFunction · 0.85
NewMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected