(key types.AES128Key, dir uint8, confFCnt uint16, addr types.DevAddr, fCnt uint32, payload []byte)
| 116 | } |
| 117 | |
| 118 | func 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 |
no test coverage detected