private void testFF3_1w() { byte[] key = Hex.Decode("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6"); byte[] plainText = Hex.Decode("0327035100210215"); byte[] cipherText = Hex.Decode("02fb024900310220"); byte[] tweak = Hex.Decode("39383736353433"); FpeEngine fpeEngine = new FpeFf3_1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), 1024, tweak)); byte[] enc = new byte[plainText.Length]; fpeEngine.ProcessBlock(plainText, 0, plainText.Length, enc, 0); IsTrue("enc failed: " + Hex.ToHexString(enc), AreEqual(cipherText, enc)); fpeEngine.Init(false, new FpeParameters(new KeyParameter(key), 1024, tweak)); fpeEngine.ProcessBlock(cipherText, 0, cipherText.Length, enc, 0); IsTrue(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 testFF3_1_255() { byte[] key = Hex.Decode("339BB5B1F2D44BAABF87CA1B7380CDC8"); byte[] tweak = Hex.Decode("3F096DE35BFA31"); int radix = 256; FpeEngine fpeEngine = new FpeFf3_1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(key), radix, tweak)); ulong valueToEncrypt = 0x31009155FFL; byte[] bytes = Hex.Decode("00000031009155FF"); byte[] enc = new byte[bytes.Length]; //Encrypt fpeEngine.ProcessBlock(bytes, 0, bytes.Length, enc, 0); IsTrue(Arrays.AreEqual(Hex.Decode("18fa139dc978a681"), enc)); //Decrypt fpeEngine.Init(false, new FpeParameters(new KeyParameter(key), radix, tweak)); fpeEngine.ProcessBlock(enc, 0, enc.Length, enc, 0); IsTrue(Arrays.AreEqual(bytes, enc)); }
private void testFF3_1Sample(FFSample ff3_1) { FpeEngine fpeEngine = new FpeFf3_1Engine(); fpeEngine.Init(true, new FpeParameters(new KeyParameter(ff3_1.getKey()), ff3_1.getRadix(), ff3_1.getTweak())); byte[] plain = ff3_1.getPlaintext(); byte[] enc = new byte[plain.Length]; fpeEngine.ProcessBlock(plain, 0, plain.Length, enc, 0); IsTrue(AreEqual(ff3_1.getCiphertext(), enc)); fpeEngine.Init(false, new FpeParameters(new KeyParameter(ff3_1.getKey()), ff3_1.getRadix(), ff3_1.getTweak())); fpeEngine.ProcessBlock(ff3_1.getCiphertext(), 0, plain.Length, enc, 0); IsTrue(AreEqual(ff3_1.getPlaintext(), enc)); }
public void testFF3_1() { for (int i = 0; i < ff3_1Samples.Length; ++i) { testFF3_1Sample(ff3_1Samples[i]); } byte[] key = Hex.Decode("EF4359D8D580AA4F7F036D6F04FC6A942B7E151628AED2A6"); byte[] plainText = Hex.Decode("0327035100210215"); byte[] tweak = Hex.Decode("39383736353433"); FpeEngine fpeEngine = new FpeFf3_1Engine(); 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.Init(true, new FpeParameters(new KeyParameter(key), 24, Hex.Decode("beef"))); Fail("no exception"); } catch (ArgumentException e) { IsEquals("tweak should be 56 bits", e.Message); } }
private void ff3_1Test(IAlphabetMapper alphabetMapper, String skey, String stweak, String input, String output) { FpeEngine fpeEncEngine = new FpeFf3_1Engine(); FpeEngine fpeDecEngine = new FpeFf3_1Engine(); byte[] key = Hex.Decode(skey); byte[] tweak = Hex.Decode(stweak); int radix = alphabetMapper.Radix; fpeEncEngine.Init(true, new FpeParameters(new KeyParameter(key), radix, tweak)); fpeDecEngine.Init(false, new FpeParameters(new KeyParameter(key), radix, tweak)); byte[] bytes = alphabetMapper.ConvertToIndexes(input.ToCharArray()); byte[] encryptedBytes = process(fpeEncEngine, bytes); IsEquals(output, new String(alphabetMapper.ConvertToChars(encryptedBytes))); byte[] decryptedBytes = process(fpeDecEngine, encryptedBytes); IsTrue(Arrays.AreEqual(bytes, decryptedBytes)); char[] chars = alphabetMapper.ConvertToChars(decryptedBytes); IsEquals(input, new String(chars)); }