Examples of IBlockCipher


Examples of gnu.javax.crypto.cipher.IBlockCipher

  public void testDoFinal(TestHarness harness)
  {
    harness.checkPoint("testDoFinal");
    String cipherName = null;
    Cipher jce;
    IBlockCipher gnu;
    byte[] pt;
    byte[] kb;
    Iterator it;
    for (it = CipherFactory.getNames().iterator(); it.hasNext();)
      {
        try
          {
            cipherName = (String) it.next();
            gnu = CipherFactory.getInstance(cipherName);
            jce = Cipher.getInstance(cipherName, Registry.GNU_CRYPTO);
            pt = new byte[gnu.defaultBlockSize() - 1];
            for (int i = 0; i < pt.length; i++)
              {
                pt[i] = (byte) i;
              }
            kb = new byte[gnu.defaultKeySize()];
            for (int i = 0; i < kb.length; i++)
              {
                kb[i] = (byte) i;
              }
            jce.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kb, cipherName));
View Full Code Here

Examples of gnu.javax.crypto.cipher.IBlockCipher

    byte[] pt, ct;
    byte[] ct1 = new byte[8];
    byte[] ct2 = new byte[8];

    HashMap map = new HashMap();
    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));
          }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.