Package gnu.javax.crypto.assembly

Examples of gnu.javax.crypto.assembly.Cascade


    IBlockCipher desEDE = new TripleDES();

    HashMap map1 = new HashMap();
    HashMap map2 = new HashMap();
    HashMap map3 = new HashMap();
    Cascade new3DES = new Cascade();
    Object des1 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.FORWARD));
    Object des2 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.REVERSED));
    Object des3 = new3DES.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.ECB_MODE, new DES(), 8),
            Direction.FORWARD));

    map.put(des1, map1);
    map.put(des2, map2);
    map.put(des3, map3);

    for (int i = 0; i < E_TV.length; i++)
      {
        map1.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][0]));
        map2.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][1]));
        map3.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(E_TV[i][2]));
        map.put(IBlockCipher.KEY_MATERIAL,
                Util.toBytesFromString(E_TV[i][0] + E_TV[i][1] + E_TV[i][2]));
        map.put(Cascade.DIRECTION, Direction.FORWARD);
        pt = Util.toBytesFromString(E_TV[i][3]);
        ct = Util.toBytesFromString(E_TV[i][4]);

        try
          {
            desEDE.reset();
            new3DES.reset();

            desEDE.init(map);
            new3DES.init(map);

            desEDE.encryptBlock(pt, 0, ct1, 0);
            new3DES.update(pt, 0, ct2, 0);
            harness.check(Arrays.equals(ct1, ct2));

            for (int j = 0; j < 9999; j++)
              {
                desEDE.encryptBlock(ct1, 0, ct1, 0);
                new3DES.update(ct2, 0, ct2, 0);
              }
            harness.check(Arrays.equals(ct, ct1));
            harness.check(Arrays.equals(ct, ct2));
          }
        catch (InvalidKeyException x)
          {
            harness.fail("init (encryption)");
            harness.debug(x);
          }
      }

    for (int i = 0; i < D_TV.length; i++)
      {
        map1.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][0]));
        map2.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][1]));
        map3.put(IBlockCipher.KEY_MATERIAL, Util.toBytesFromString(D_TV[i][2]));
        map.put(IBlockCipher.KEY_MATERIAL,
                Util.toBytesFromString(D_TV[i][0] + D_TV[i][1] + D_TV[i][2]));
        map.put(Cascade.DIRECTION, Direction.REVERSED);
        pt = Util.toBytesFromString(D_TV[i][3]);
        ct = Util.toBytesFromString(D_TV[i][4]);

        try
          {
            desEDE.reset();
            new3DES.reset();

            desEDE.init(map);
            new3DES.init(map);

            desEDE.decryptBlock(pt, 0, ct1, 0);
            new3DES.update(pt, 0, ct2, 0);
            harness.check(Arrays.equals(ct1, ct2));

            for (int j = 0; j < 9999; j++)
              {
                desEDE.decryptBlock(ct1, 0, ct1, 0);
                new3DES.update(ct2, 0, ct2, 0);
              }
            harness.check(Arrays.equals(ct, ct1));
            harness.check(Arrays.equals(ct, ct2));
          }
        catch (InvalidKeyException x)
View Full Code Here


  public void test(TestHarness harness)
  {
    TestOfAssembly testcase = new TestOfAssembly();

    // build an OFB-Blowfish cascade
    Cascade ofbBlowfish = new Cascade();
    Object modeNdx = ofbBlowfish.append(Stage.getInstance(
        ModeFactory.getInstance(
            Registry.OFB_MODE, new Blowfish(), 8),
            Direction.FORWARD));

    testcase.attributes.put(modeNdx, testcase.modeAttributes);
View Full Code Here

TOP

Related Classes of gnu.javax.crypto.assembly.Cascade

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.