public void TestGmac() { byte[] gkcryptKey = { 0xb6, 0x4b, 0x1e, 0x65, 0x3f, 0xbb, 0xa7, 0xab, 0x80, 0xb3, 0x1e, 0x5a, 0x32, 0x4d, 0xec, 0xc0 }; byte[] gkcryptIv = { 0x7c, 0xc8, 0xd0, 0x19, 0x9e, 0xdf, 0xd8, 0xc3, 0xb5, 0x0f, 0x32, 0xee, 0x36, 0x33, 0x6a, 0x5a }; byte[] buf = { 0x03, 0x00, 0x18, 0x00, 0x19, 0x00, 0x02, 0x50, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69, 0xa0, 0x00, 0xf9, 0xf8, 0x98, 0x24, 0xda, 0x56, 0x0b, 0x74, 0xec, 0x68, 0x15, 0xd3, 0x1f, 0x85, 0x43, 0xaa, 0xd3, 0xcd, 0xb8, 0x50, 0x2e, 0x90, 0xa4, 0xb0, 0x85, 0xf3, 0xbe, 0x9a, 0x47, 0x97, 0xc1, 0xab, 0x5f, 0xa5, 0xfd, 0x62, 0x5c, 0x26, 0x1a, 0x54, 0x36, 0x72, 0x30, 0xc3, 0x2b, 0xe0, 0x2c, 0x5a, 0x86, 0x07, 0xf5, 0xdc, 0x12, 0x55, 0xb4, 0x8e, 0x17, 0x5b, 0xe4, 0x7f, 0x96, 0x55, 0x86, 0xf0, 0xfb, 0x45, 0xe2, 0xf8, 0xe8, 0x7d, 0x5f, 0x3a, 0x8b, 0xb0, 0x64, 0x6c, 0x54, 0xf6, 0x8c, 0x4e, 0xa4, 0x12, 0xa3, 0x26, 0x7f, 0x22, 0x5b, 0x19, 0x98, 0xba, 0xd4, 0xad, 0x9f, 0x5f, 0x63, 0xaf, 0x1f, 0x97, 0x8c, 0x17, 0x49, 0xa3, 0x30, 0x71, 0xd2, 0xb0, 0x49, 0x2c, 0x75, 0xa2, 0x89, 0xda, 0x50, 0xfd, 0x9b, 0x08, 0x41, 0x98, 0x2d, 0x8c, 0x0b, 0x92, 0x79, 0xae, 0x60, 0x23, 0x83, 0xef, 0x5c, 0xda, 0xce, 0x71, 0x08, 0x2d, 0x0b, 0x17, 0x62, 0x56, 0x48, 0xc5, 0xe2, 0x0f, 0x22, 0x1d, 0xdc, 0xcc, 0xc2, 0x82, 0xa6, 0x8e, 0xec, 0x1e, 0x04, 0x0c, 0x08, 0xaa, 0xa2, 0x80, 0x6c, 0x4f, 0xd3, 0x6f, 0xc1, 0x9b, 0x76, 0x9a, 0x58, 0xaa, 0x25, 0x56, 0xef, 0xf2, 0xfd, 0x77, 0xf0, 0x32, 0x4e, 0x83, 0xe2, 0x30, 0x25, 0xa5, 0x5a, 0xf1, 0xdf, 0xc8, 0x75, 0xa2, 0xb6, 0x2b, 0xfd, 0xac, 0xbc, 0x63, 0x09, 0xa1, 0xcc, 0x2b, 0xf5, 0x46, 0xef, 0x49, 0x83, 0x8f, 0x0b, 0xc1, 0x47, 0xac, 0x5a, 0x00, 0x2e, 0xec, 0x1c, 0xd0, 0x0a, 0x66, 0xb5, 0xee, 0x9e, 0xad, 0xc9, 0x64, 0x2d, 0xcb, 0x98, 0x0f, 0x43, 0xa6, 0xe1, 0x4c, 0xe7, 0x9f, 0x2d, 0xab, 0x94, 0x01, 0xd7, 0x52, 0x84, 0x19 }; const int keyPos = 0x69a0; byte[] gmacExpected = { 0x6f, 0x81, 0x10, 0x97 }; GmacInfo gmacInfo = new GmacInfo(new byte[16], gkcryptIv, gkcryptKey, 0); byte[] gmac = CryptoService.AddGmacToBuffer(gmacInfo, keyPos, buf, 10); Assert.Equal(gmacExpected, gmac); }
public void TestGmacMultipleOfKeyRefresh() { byte[] handshakeKey = { 0x70, 0x58, 0x37, 0x50, 0x91, 0xea, 0xd1, 0x37, 0x71, 0x58, 0xec, 0xb3, 0xb, 0xea, 0x23, 0x87 }; byte[] ecdhSecret = { 0x3c, 0x3a, 0xf0, 0xec, 0xd6, 0x33, 0x1b, 0xb1, 0x6d, 0x24, 0x4f, 0x48, 0x19, 0xde, 0x6, 0x3d, 0xc7, 0xe, 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 0xe2, 0x93, 0x74, 0xc6, 0xfb, 0xdd, 0x48, 0x57, 0xae, 0x53, 0xe2, 0xf4, 0x17, 0x80, 0x62, 0xf3, 0x9, 0xd8, 0xd4, 0x7a, 0x46, 0x6b, 0x8, 0x76, 0x9c, 0x29, 0x81, 0x91, 0x4e, 0x57, 0xaf, 0x70, 0xb6, 0x32, 0x78, 0x98, 0x9e, 0x85, 0xf2, 0xe3, 0x69, 0x15, 0xaf, 0xd4, 0x32, 0x54, 0xf, 0xd4, 0xa2, 0xfc, 0xf5, 0x36, 0xdc, 0x6, 0x45, 0xf4, 0x6, 0xa3, 0x38, 0x21, 0x2, 0xfd, 0xf0, 0x51, 0x75, 0xea, 0xb1, 0xf6, 0x8e, 0x39, 0x35, 0xfd, 0x75, 0x74, 0xad, 0xbc, 0x3e, 0xfb, 0xee, 0x7d, 0xf, 0x2d, 0x76, 0xbe, 0xfd, 0xee }; byte cryptIndex = 3; const int keyPos = 0x6b1de0; // % CHIAKI_GKCRYPT_GMAC_KEY_REFRESH_KEY_POS == 0 byte[] gmacExpected = { 0x20, 0xcc, 0xa5, 0xf1 }; GmacInfo gmacInfo = CryptoService.SetUpGmac(cryptIndex, handshakeKey, ecdhSecret); byte[] gmac = CryptoService.AddGmacToBuffer(gmacInfo, keyPos, data, 10); Assert.Equal(gmacExpected, gmac); }
private void SendCryptedFeedbackMessage(FeedbackMessage feedbackMessage, byte[] feebdackBuffer, RemotePlayContext remotePlayContext, Socket udpClient) { feedbackMessage.TagPos = (uint)remotePlayContext.LocalKeyPosition; byte[] feedbackMessageData = GetByteArrayForFeedbackMessage(feedbackMessage); int macOffset = GetMacOffset(6); // crypto position CryptoService.AddGmacToBuffer(remotePlayContext.LocalGmacInfo, feedbackMessage.TagPos, feedbackMessageData, macOffset); feebdackBuffer = CryptoService.EncryptGmacMessage(remotePlayContext.LocalGmacInfo, feedbackMessage.TagPos, feebdackBuffer); remotePlayContext.LocalKeyPosition += 16; //controlMessage.UnParsedPayload.Length < 16 ? 16 : controlMessage.UnParsedPayload.Length; SendData(udpClient, ByteUtil.ConcatenateArrays(feedbackMessageData, feebdackBuffer)); }
public void TestGmacSplit() { byte[] gkcryptKey = { 0x35, 0x95, 0x81, 0x87, 0xeb, 0xcb, 0x63, 0x54, 0x90, 0x00, 0xd7, 0xd5, 0xbd, 0xf4, 0xc5, 0xf4 }; byte[] gkcryptIv = { 0xb8, 0xde, 0xfc, 0xa4, 0x48, 0xf0, 0x4c, 0x3f, 0xd5, 0x94, 0x0e, 0x1c, 0x04, 0x64, 0x63, 0xb1 }; byte[] buf = { 0x2, 0x0, 0x1e, 0x0, 0x9, 0x0, 0x20, 0x8, 0x1, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xad, 0xf0, 0x2, 0x4e, 0x0, 0x2c, 0x6f, 0x3b, 0x6c, 0x2e, 0x4a, 0x27, 0x9c, 0x50, 0x34, 0x84, 0xea, 0x37, 0xc7, 0x76, 0xab, 0x92, 0x30, 0x43, 0x61, 0xc7, 0x1d, 0xcb, 0xc4, 0x35, 0x94, 0xcc, 0x44, 0xe2, 0xfa, 0x89, 0x86, 0x47, 0x5e, 0xc2, 0x1, 0x39, 0x4c, 0x9f, 0x67, 0xb3, 0x6e, 0x35, 0x44, 0x97, 0xf4, 0x28, 0xe2, 0x51, 0x12, 0xda, 0xf5, 0x2c, 0x43, 0x1c, 0x49, 0x46, 0x2c, 0x53, 0xe3, 0xe9, 0x76, 0x61, 0x87, 0x2b, 0x7a, 0xe3, 0x2f, 0xbb, 0x9f, 0x4d, 0x66, 0x8a, 0x31, 0xbc, 0x64, 0x9d, 0x6, 0xd, 0x4a, 0xdd, 0x42, 0x21, 0x73, 0x3c, 0x97, 0x21, 0x84, 0x53, 0x65, 0x53, 0x7a, 0xf4, 0x57, 0x77, 0x61, 0xae, 0xc, 0x7a, 0x42, 0x90, 0xfc, 0x6b, 0xbb, 0x38, 0x6e, 0x52, 0xb6, 0xe5, 0x26, 0xf, 0xd2, 0x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13, 0xab, 0x82, 0x52, 0x95, 0xb3, 0x62, 0xa6, 0x48, 0x48, 0xb8, 0xd8, 0x55, 0x26, 0x98, 0xa1, 0xc9, 0x57, 0x66, 0x1c, 0xac, 0xb1, 0xc7, 0x5f, 0xfa, 0x44, 0xc6, 0xd8, 0x19, 0x1, 0x8d, 0x41, 0x1f, 0xc7, 0xf, 0x89, 0x1d, 0xef, 0x34, 0x9a, 0x68, 0x77, 0x8c }; const int keyPos = 0xadf0; byte[] gmacExpected = { 0xd6, 0x6a, 0x07, 0xb7 }; GmacInfo gmacInfo = new GmacInfo(new byte[16], gkcryptIv, gkcryptKey, 0); byte[] gmac = CryptoService.AddGmacToBuffer(gmacInfo, keyPos, buf, 10); Assert.Equal(gmacExpected, gmac); }
public void SimpleGmacTest() { byte[] handshakeKey = HexUtil.Unhexlify("A96453B407050B006E9ADC0968392573"); byte[] ecdhSecret = HexUtil.Unhexlify("BE089ABCBE5C7F92A18D1CDFDDE330F0D8B61779A6AF89F9BC7A036E386DB9CA"); byte[] gmacExpected = { 0x90, 0x79, 0x5c, 0xbf }; const int keyPos = 0x20; byte[] buf = HexUtil.Unhexlify("0014cec66e00000000000000200300001014cec6700001900000000000"); GmacInfo gmacInfo = CryptoService.SetUpGmac(2, handshakeKey, ecdhSecret); byte[] gmac = CryptoService.AddGmacToBuffer(gmacInfo, keyPos, buf, 5); Assert.Equal(gmacExpected, gmac); }
private ControlResult SendCryptedControlMessageAndWaitForAnswer(ControlMessage controlMessage, RemotePlayContext remotePlayContext, Socket udpClient, int expectedPackets, string info) { controlMessage.TagPos = 0; byte[] controlMessageData = GetByteArrayForControlMessage(controlMessage); int macOffset = GetMacOffset(0); // crypto position CryptoService.AddGmacToBuffer(remotePlayContext.LocalGmacInfo, remotePlayContext.LocalKeyPosition, controlMessageData, macOffset); byte[] keyPosBuffer = ByteUtil.UIntToByteArray(remotePlayContext.LocalKeyPosition); int position = GetTagPosOffset(0); for (int i = 0; i < keyPosBuffer.Length; i++) { controlMessageData[position + i] = keyPosBuffer[i]; } remotePlayContext.LocalKeyPosition += 16; // controlMessage.UnParsedPayload.Length < 16 ? 16 : controlMessage.UnParsedPayload.Length; return(SendControlDataAndWaitForAnswer(udpClient, controlMessageData, expectedPackets, info)); }
private void SendCryptedControlMessage(ControlMessage controlMessage, RemotePlayContext remotePlayContext, Socket udpClient) { controlMessage.TagPos = 0; byte[] controlMessageData = GetByteArrayForControlMessage(controlMessage); int macOffset = GetMacOffset(0); // crypto position CryptoService.AddGmacToBuffer(remotePlayContext.LocalGmacInfo, remotePlayContext.LocalKeyPosition, controlMessageData, macOffset); byte[] keyPosBuffer = ByteUtil.UIntToByteArray(remotePlayContext.LocalKeyPosition); int position = GetTagPosOffset(0); for (int i = 0; i < keyPosBuffer.Length; i++) { controlMessageData[position + i] = keyPosBuffer[i]; } remotePlayContext.LocalKeyPosition += 16; //controlMessage.UnParsedPayload.Length < 16 ? 16 : controlMessage.UnParsedPayload.Length; SendData(udpClient, controlMessageData); }