public void testFF1w() { byte[] key = Hex.Decode("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6"); byte[] plainText = Hex.Decode("0327035100210215"); byte[] cipherText = Hex.Decode("022701f80217020a"); byte[] tweak = Hex.Decode("39383736353433323130"); FpeEngine fpeEngine = new FpeFf1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), 1024, tweak)); byte[] enc = new byte[plainText.Length]; fpeEngine.ProcessBlock(plainText, 0, plainText.Length, enc, 0); AreEqual(cipherText, enc); fpeEngine.Init(false, new FpeParameters(new KeyParameter(key), 1024, tweak)); fpeEngine.ProcessBlock(cipherText, 0, cipherText.Length, enc, 0); AreEqual(plainText, enc); byte[] outPt = Hex.Decode("03270F5100210215"); try { fpeEngine.ProcessBlock(outPt, 0, outPt.Length, enc, 0); } catch (ArgumentException e) { IsEquals("input data outside of radix", e.Message); } }
private void testFF1() { for (int i = 0; i < ff1Samples.Length; ++i) { testFF1Sample(ff1Samples[i]); } byte[] key = Hex.Decode("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6"); byte[] plainText = Hex.Decode("0327035100210215"); byte[] tweak = Hex.Decode("39383736353433323130"); FpeEngine fpeEngine = new FpeFf1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), 24, tweak)); try { fpeEngine.ProcessBlock(plainText, 0, plainText.Length, plainText, 0); Fail("no exception"); } catch (ArgumentException e) { IsEquals("input data outside of radix", e.Message); } try { fpeEngine.ProcessBlock(new byte[] { 1 }, 0, 1, plainText, 0); Fail("no exception"); } catch (ArgumentException e) { IsEquals("input too short", e.Message); } }
private void testFF1Sample(FFSample ff1) { FpeEngine fpeEngine = new FpeFf1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(ff1.getKey()), ff1.getRadix(), ff1.getTweak())); byte[] plain = ff1.getPlaintext(); byte[] enc = new byte[plain.Length]; fpeEngine.ProcessBlock(plain, 0, plain.Length, enc, 0); IsTrue(AreEqual(ff1.getCiphertext(), enc)); fpeEngine.Init(false, new FpeParameters(new KeyParameter(ff1.getKey()), ff1.getRadix(), ff1.getTweak())); fpeEngine.ProcessBlock(ff1.getCiphertext(), 0, ff1.getCiphertext().Length, enc, 0); IsTrue(AreEqual(ff1.getPlaintext(), enc)); }