public IMac CreateEngine(EngineUsage usage) { IMac mac = new GMac(new GcmBlockCipher(baseProvider.CreateEngine(EngineUsage.ENCRYPTION)), parameters.MacSizeInBits); mac.Init(new Internal.Parameters.ParametersWithIV(null, parameters.GetIV())); return(mac); }
private void testInvalidMacSize(int size) { try { GMac mac = new GMac(new GcmBlockCipher(new AesFastEngine()), size); mac.Init(new ParametersWithIV(null, new byte[16])); Fail("Expected failure for illegal mac size " + size); } catch (ArgumentException) { } }
private void testInvalidMacSize(int size) { try { GMac mac = new GMac(new GcmBlockCipher(new AesEngine()), size); mac.Init(new ParametersWithIV(null, new byte[16])); Fail("Expected failure for illegal mac size " + size); } catch (ArgumentException e) { if (!e.Message.StartsWith("Invalid value for MAC size")) { Fail("Illegal mac size failed with unexpected message"); } } }
public override void PerformTest() { for (int i = 0; i < TEST_VECTORS.Length; i++) { TestCase testCase = TEST_VECTORS[i]; IMac mac = new GMac(new GcmBlockCipher(new AesEngine()), testCase.getTag().Length * 8); ICipherParameters key = new KeyParameter(testCase.getKey()); mac.Init(new ParametersWithIV(key, testCase.getIv())); testSingleByte(mac, testCase); testMultibyte(mac, testCase); } // Invalid mac size testInvalidMacSize(97); testInvalidMacSize(136); testInvalidMacSize(24); }
public static byte[] AddGmacToBuffer(GmacInfo gmacInfo, uint keyPos, byte[] buffer, int gmacPositionInBuffer) { //keyPos = (uint) System.Net.IPAddress.HostToNetworkOrder((int)keyPos); byte[] iv = new byte[16]; SetGmacCounter(iv, gmacInfo.Iv, keyPos / 0x10); byte[] gmacKey = gmacInfo.KeyGmacCurrent; long keyIndex = (keyPos > 0 ? keyPos - 1 : 0) / GmacKeyRefreshKeyPosition; if (keyIndex > gmacInfo.GmacCurrentIndex) { gmacKey = GenerateNewGmacKey(gmacInfo, keyIndex); gmacInfo.KeyGmacCurrent = gmacKey; gmacInfo.GmacCurrentIndex = keyIndex; gmacKey = gmacInfo.KeyGmacCurrent; } else if (keyIndex < gmacInfo.GmacCurrentIndex) { gmacKey = GenerateTmpGmacKey(gmacInfo, keyIndex); } IMac mac = new GMac(new GcmBlockCipher(new AesEngine()), 32); ICipherParameters key = new KeyParameter(gmacKey); mac.Init(new ParametersWithIV(key, iv)); mac.BlockUpdate(buffer, 0, buffer.Length); int macSize = mac.GetMacSize(); byte[] gmac = new byte[macSize]; mac.DoFinal(gmac, 0); for (int i = 0; i < gmac.Length; i++) { buffer[gmacPositionInBuffer + i] = gmac[i]; } return(gmac); }