I am trying to secure my RF communication in which one RF package consists of two separate segments. I need to make sure that one segment of one packet is not replaced with a valid segment of some previous packet, if you know what I mean.
My RF packet is 32 bytes long, and I need to secure it with CMAC (I found an implementation of AES-128 in CBC mode and CMAC - operating on 16 byte blocks). I am planning on doing it like this:
[B1][B2][B3]...[B30][B31][B32] = bytes in my RF packet [B1] [B2]... [B10] = first segment (10 bytes long) [B11][B12]...[B20] = second segment (also 10 bytes long) [B21][B22]...[B32] = remaining bytes of RF packet contain CMAC of first segment, and CMAC of second segment (both truncated to first 6 bytes in order to fit into 32 bytes that I have for one transmission).
Now for the problem: In order to make sure that nobody captures two of my RF packets, and creates third new packet that contain fist segment of packet 1 and second segment of packet 2 (with corresponding CMACs also copied) I am planning on calculating CMAC of first segment + 6 bytes of second segment, and calculating CMAC of second segment by borrowing last 6 bytes of first segment and remaining 10 bytes of second segment.
Should I do this? If not, how can I make sure someone doesn't transmit third custom packet containing two valid segments of my previous transmissions? It would be best if I could somehow calculate CMAC on the entire 20 bytes, but as I know I can only work with 16 byte blocks maximum.