private static void initBlockCipherEngines() { blockCipherEngines.put("MARS", MarsEngine.class); blockCipherEngines.put("AES", AESEngine.class); blockCipherEngines.put("Blowfish", BlowfishEngine.class); blockCipherEngines.put("Camellia", CamelliaEngine.class); blockCipherEngines.put("CAST5", CAST5Engine.class); blockCipherEngines.put("CAST6", CAST6Engine.class); blockCipherEngines.put("DESede", DESedeEngine.class); blockCipherEngines.put("DES", DESEngine.class); blockCipherEngines.put("GOST28147", GOST28147Engine.class); blockCipherEngines.put("IDEA", IDEAEngine.class); blockCipherEngines.put("Noekeon", NoekeonEngine.class); blockCipherEngines.put("RC2", RC2Engine.class); blockCipherEngines.put("RC5", RC532Engine.class); blockCipherEngines.put("RC6", RC6Engine.class); blockCipherEngines.put("SEED", SEEDEngine.class); blockCipherEngines.put("Serpent", SerpentEngine.class); blockCipherEngines.put("Shacal2", Shacal2Engine.class); blockCipherEngines.put("Skipjack", SkipjackEngine.class); blockCipherEngines.put("SM4", SM4Engine.class); blockCipherEngines.put("TEA", TEAEngine.class); blockCipherEngines.put("Twofish", TwofishEngine.class); blockCipherEngines.put("XTEA", XTEAEngine.class); blockCipherEngines.put("Threefish", ThreefishEngine.class); }
public static void main(String[] args) throws InterruptedException, IOException { // testTF_1024_1(); // testTF_1024_2(); testTF_512_1(); testTF_512_2(); // testTF_256_1(); // testTF_256_2(); System.out.println("Initialising test data."); byte[] input = new byte[DATA_SIZE]; rand.nextBytes(input); System.out.println("Init complete."); // speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256), input); speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), input); // speedTestCipher(new Skein3FishEngine(), input); // speedTestCipher(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024), input); // speedTestCipher(new ThreefishReferenceEngine(), input); speedTestCipher(new AESFastEngine(), input); // speedTestCipher(new TwofishEngine(), input); // speedTestCipher(new BlowfishEngine(), input); }
public void setParameters(int KeySize, int alg) throws NoSuchAlgorithmException, InvalidKeySpecException { switch (alg) { case 7: case 1: this.blockSize = KeySize; break; case 8: this.blockSize = 256; break; default: this.blockSize = 128; break; } switch (KeySize) { case 128: case 192: Algs[1] = new RijndaelEngine(KeySize); break; case 256: Algs[1] = new RijndaelEngine(KeySize); Algs[7] = new ThreefishEngine(KeySize); break; default: Algs[7] = new ThreefishEngine(KeySize); break; } padding = new PKCS7Padding(); }
public Configuration(long outputSizeBits) { // 0..3 = ASCII SHA3 bytes[0] = (byte)'S'; bytes[1] = (byte)'H'; bytes[2] = (byte)'A'; bytes[3] = (byte)'3'; // 4..5 = version number in LSB order bytes[4] = 1; bytes[5] = 0; // 8..15 = output length ThreefishEngine.wordToBytes(outputSizeBits, bytes, 8); }
private void processBlock(long[] output) { threefish.init(true, chain, tweak.getWords()); for (int i = 0; i < message.length; i++) { message[i] = ThreefishEngine.bytesToWord(currentBlock, i * 8); } threefish.processBlock(message, output); for (int i = 0; i < output.length; i++) { output[i] ^= message[i]; } }
/** * Constructs a Skein engine. * * @param blockSizeBits the internal state size in bits - one of {@link #SKEIN_256}, {@link #SKEIN_512} or * {@link #SKEIN_1024}. * @param outputSizeBits the output/digest size to produce in bits, which must be an integral number of * bytes. */ public SkeinEngine(int blockSizeBits, int outputSizeBits) { if (outputSizeBits % 8 != 0) { throw new IllegalArgumentException("Output size must be a multiple of 8 bits. :" + outputSizeBits); } // TODO: Prevent digest sizes > block size? this.outputSizeBytes = outputSizeBits / 8; this.threefish = new ThreefishEngine(blockSizeBits); this.ubi = new UBI(threefish.getBlockSize()); }
private void output(long outputSequence, byte[] out, int outOff, int outputBytes) { byte[] currentBytes = new byte[8]; ThreefishEngine.wordToBytes(outputSequence, currentBytes, 0); // Output is a sequence of UBI invocations all of which use and preserve the pre-output // state long[] outputWords = new long[chain.length]; ubiInit(PARAM_TYPE_OUTPUT); this.ubi.update(currentBytes, 0, currentBytes.length, outputWords); ubi.doFinal(outputWords); final int wordsRequired = ((outputBytes + 8 - 1) / 8); for (int i = 0; i < wordsRequired; i++) { int toWrite = Math.min(8, outputBytes - (i * 8)); if (toWrite == 8) { ThreefishEngine.wordToBytes(outputWords[i], out, outOff + (i * 8)); } else { ThreefishEngine.wordToBytes(outputWords[i], currentBytes, 0); System.arraycopy(currentBytes, 0, out, outOff + (i * 8), toWrite); } } }
private void performTests() throws Exception { testModes(new BlowfishEngine(), new BlowfishEngine(), 16); testModes(new DESEngine(), new DESEngine(), 8); testModes(new DESedeEngine(), new DESedeEngine(), 24); testModes(new TEAEngine(), new TEAEngine(), 16); testModes(new CAST5Engine(), new CAST5Engine(), 16); testModes(new RC2Engine(), new RC2Engine(), 16); testModes(new XTEAEngine(), new XTEAEngine(), 16); testModes(new AESEngine(), new AESEngine(), 16); testModes(new NoekeonEngine(), new NoekeonEngine(), 16); testModes(new TwofishEngine(), new TwofishEngine(), 16); testModes(new CAST6Engine(), new CAST6Engine(), 16); testModes(new SEEDEngine(), new SEEDEngine(), 16); testModes(new SerpentEngine(), new SerpentEngine(), 16); testModes(new RC6Engine(), new RC6Engine(), 16); testModes(new CamelliaEngine(), new CamelliaEngine(), 16); testModes(new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512), 64); testMode(new RC4Engine(), new KeyParameter(new byte[16])); testMode(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new XSalsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[32]), new byte[24])); testMode(new ChaChaEngine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grainv1Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testMode(new Grain128Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[12])); testMode(new HC128Engine(), new KeyParameter(new byte[16])); testMode(new HC256Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); testSkipping(new Salsa20Engine(), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[8])); testSkipping(new SICBlockCipher(new AESEngine()), new ParametersWithIV(new KeyParameter(new byte[16]), new byte[16])); }
public Configuration(long outputSizeBits) { // 0..3 = ASCII SHA3 bytes[0] = 'S'; bytes[1] = 'H'; bytes[2] = 'A'; bytes[3] = '3'; // 4..5 = version number in LSB order bytes[4] = 1; bytes[5] = 0; // 8..15 = output length ThreefishEngine.wordToBytes(outputSizeBits, bytes, 8); }
private static void testTF_512_1() throws IOException { byte[] key = new byte[64]; byte[] tweak = new byte[16]; byte[] plaintext = new byte[64]; byte[] expected = Hex.decode("b1a2bbc6ef6025bc40eb3822161f36e375d1bb0aee3186fbd19e47c5d479947b7bc2f8586e35f0cff7e7f03084b0b7b1f1ab3961a580a3e97eb41ea14a6d7bbe"); runTestVector("Threefish-512-1: Fast", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512)); runTestVector("Threefish-512-1: Reference", key, tweak, plaintext, expected, new ThreefishReferenceEngine()); }
private static void testTF_256_1() throws IOException { byte[] key = new byte[32]; byte[] tweak = new byte[16]; byte[] plaintext = new byte[32]; byte[] expected = Hex.decode("84da2a1f8beaee947066ae3e3103f1ad536db1f4a1192495116b9f3ce6133fd8"); runTestVector("Threefish-256-1: ", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256)); }
private static void testTF_1024_1() throws IOException { byte[] key = new byte[128]; byte[] tweak = new byte[16]; byte[] plaintext = new byte[128]; byte[] expected = Hex.decode("f05c3d0a3d05b304f785ddc7d1e036015c8aa76e2f217b06c6e1544c0bc1a90df0accb9473c24e0fd54fea68057f43329cb454761d6df5cf7b2e9b3614fbd5a20b2e4760b40603540d82eabc5482c171c832afbe68406bc39500367a592943fa9a5b4a43286ca3c4cf46104b443143d560a4b230488311df4feef7e1dfe8391e"); runTestVector("Threefish-1024-1: ", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024)); }
private static void testTF_512_2() throws IOException { byte[] key = Hex.decode("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f"); byte[] tweak = Hex.decode("000102030405060708090a0b0c0d0e0f"); byte[] plaintext = Hex.decode("fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0"); byte[] expected = Hex.decode("e304439626d45a2cb401cad8d636249a6338330eb06d45dd8b36b90e97254779272a0a8d99463504784420ea18c9a725af11dffea10162348927673d5c1caf3d"); runTestVector("Threefish-512-2: Fast", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_512)); runTestVector("Threefish-512-2: Reference", key, tweak, plaintext, expected, new ThreefishReferenceEngine()); }
private static void testTF_256_2() throws IOException { byte[] key = Hex.decode("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f"); byte[] tweak = Hex.decode("000102030405060708090a0b0c0d0e0f"); byte[] plaintext = Hex.decode("FFFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0EFEEEDECEBEAE9E8E7E6E5E4E3E2E1E0"); byte[] expected = Hex.decode("e0d091ff0eea8fdfc98192e62ed80ad59d865d08588df476657056b5955e97df"); runTestVector("Threefish-256-2: ", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_256)); }
private static void testTF_1024_2() throws IOException { byte[] key = Hex.decode("101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f"); byte[] tweak = Hex.decode("000102030405060708090a0b0c0d0e0f"); byte[] plaintext = Hex.decode("fffefdfcfbfaf9f8f7f6f5f4f3f2f1f0efeeedecebeae9e8e7e6e5e4e3e2e1e0dfdedddcdbdad9d8d7d6d5d4d3d2d1d0cfcecdcccbcac9c8c7c6c5c4c3c2c1c0bfbebdbcbbbab9b8b7b6b5b4b3b2b1b0afaeadacabaaa9a8a7a6a5a4a3a2a1a09f9e9d9c9b9a999897969594939291908f8e8d8c8b8a89888786858483828180"); byte[] expected = Hex.decode("a6654ddbd73cc3b05dd777105aa849bce49372eaaffc5568d254771bab85531c94f780e7ffaae430d5d8af8c70eebbe1760f3b42b737a89cb363490d670314bd8aa41ee63c2e1f45fbd477922f8360b388d6125ea6c7af0ad7056d01796e90c83313f4150a5716b30ed5f569288ae974ce2b4347926fce57de44512177dd7cde"); runTestVector("Threefish-1024-2: ", key, tweak, plaintext, expected, new ThreefishEngine(ThreefishEngine.BLOCKSIZE_1024)); }