Package nl.warper.threefish

Examples of nl.warper.threefish.ThreefishImpl


  static {
    Logger threefishLogger = Logger.getLogger(ThreefishImpl.class.getName());
  }

  public static void testThreefish(final int blockSize, final int rounds) {
    final ThreefishImpl impl;
    if(rounds <= 0) {
      impl = new ThreefishImpl(blockSize);
    } else {
      impl = new ThreefishImpl(blockSize, rounds);
    }

    byte[] keyData = new byte[blockSize / Byte.SIZE]; // initialized to 00h values, used later on
    final long[] tweak;
    try {
      SecureRandom rnd = SecureRandom.getInstance("SHA1PRNG");
      rnd.nextBytes(keyData);
      tweak = new long[] { rnd.nextLong(), rnd.nextLong() };
    } catch (GeneralSecurityException e) {
      throw new RuntimeException(e);
    }

    ThreefishSecretKey sk = new ThreefishSecretKey(keyData);

    impl.init(sk, tweak);
    final byte[] plain = "Maarten".getBytes();
    final byte[] plainPadded = zeroPad(plain, impl.getBlockSize());

    final long[] encryptedBlock = new long[impl.getBlockSize() / Long.SIZE];

    final long[] plainBlock = lsbBytesToArrayOfLong(plainPadded);
    System.out.printf("Threefish plainbl: %s%n", tohex(lsbArrayOfLongToBytes(plainBlock)));

    // not needed: impl.init(sk, tweak);
    impl.blockEncrypt(plainBlock, encryptedBlock);

    System.out.printf("Threefish encrypt: %s%n", tohex(lsbArrayOfLongToBytes(encryptedBlock)));


    long[] decryptedBlock= new long[encryptedBlock.length];
    impl.blockDecrypt(encryptedBlock, decryptedBlock);

    System.out.printf("Threefish decrypt: %s%n", tohex(lsbArrayOfLongToBytes(decryptedBlock)));
  }
View Full Code Here


    // create buffer
    byte[] blockBuffer = new byte[blockSizeBytes];

    // create cipher
    ThreefishImpl threefish = new ThreefishImpl(blockSize);

    // create and init UBI
    UBI64 ubi = new UBI64(threefish);
    ubi.init();
View Full Code Here

    // create buffer
    byte[] blockBuffer = new byte[blockSizeBytes];

    // create cipher
    ThreefishImpl threefish = new ThreefishImpl(blockSize);

    // create and init UBI
    UBI64 ubi = new UBI64(threefish);
    ubi.init();
View Full Code Here

    // create buffer
    byte[] blockBuffer = new byte[blockSizeBytes];

    // create cipher
    ThreefishImpl threefish = new ThreefishImpl(blockSize);

    // create and init UBI
    UBI64 ubi = new UBI64(threefish);
    ubi.init();
View Full Code Here

TOP

Related Classes of nl.warper.threefish.ThreefishImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.