Package gnu.javax.crypto.pad

Examples of gnu.javax.crypto.pad.IPad


{
  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfPadFactory");
    String pad;
    IPad algorithm;
    for (Iterator it = PadFactory.getNames().iterator(); it.hasNext();)
      {
        pad = (String) it.next();
        try
          {
View Full Code Here


  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfTBC");
    try
      {
        IPad algorithm = PadFactory.getInstance("tbc");
        harness.check(algorithm.selfTest(), "selfTest");
      }
    catch (Exception x)
      {
        harness.debug(x);
        harness.fail("TestOfTBC.selfTest");
View Full Code Here

  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfISO10126");
    try
      {
        IPad algorithm = PadFactory.getInstance("iso10126");
        byte[] in = new byte[1024];
        for (int bs = 2; bs < 256; bs++)
          if (! padderTest1BlockSize(algorithm, bs, in))
            harness.fail("ISO10126 padder failed for block-size = " + bs);
        harness.check(true, "ISO10126 padder OK");
View Full Code Here

  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfPKCS7");
    try
      {
        IPad algorithm = PadFactory.getInstance("pkcs7");
        harness.check(algorithm.selfTest(), "selfTest");
      }
    catch (Exception x)
      {
        harness.debug(x);
        harness.fail("TestOfPKCS7.selfTest");
View Full Code Here

  public void testPadding(TestHarness harness)
  {
    harness.checkPoint("testPadding");
    String padName = null;
    IMode gnu = ModeFactory.getInstance("ECB", "AES", 16);
    IPad pad;
    Cipher jce;
    byte[] kb = new byte[32];
    for (int i = 0; i < kb.length; i++)
      kb[i] = (byte) i;
    byte[] pt = new byte[42];
    for (int i = 0; i < pt.length; i++)
      pt[i] = (byte) i;
    byte[] ppt = new byte[48]; // padded plaintext.
    System.arraycopy(pt, 0, ppt, 0, 42);
    byte[] ct1 = new byte[48], ct2 = new byte[48];
    byte[] cpt1 = new byte[42], cpt2 = new byte[42];
    HashMap attrib = new HashMap();
    attrib.put(IBlockCipher.KEY_MATERIAL, kb);
    try
      {
        for (Iterator it = PadFactory.getNames().iterator(); it.hasNext();)
          {
            padName = (String) it.next();
            // skip EME-PKCS1-V1.5 padding since it's not a true block cipher
            // padding algorithm
            if (padName.equalsIgnoreCase(Registry.EME_PKCS1_V1_5_PAD))
              continue;

            pad = PadFactory.getInstance(padName);
            pad.reset();
            pad.init(16);

            byte[] padding = pad.pad(pt, 0, pt.length);
            System.arraycopy(padding, 0, ppt, 42, padding.length);
            attrib.put(IMode.STATE, new Integer(IMode.ENCRYPTION));
            gnu.reset();
            gnu.init(attrib);
            for (int i = 0; i < ppt.length; i += 16)
              gnu.update(ppt, i, ct1, i);

            jce = Cipher.getInstance("AES/ECB/" + padName, Registry.GNU_CRYPTO);
            jce.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kb, "AES"));
            jce.doFinal(ct1, 0, ct1.length, cpt1, 0);
            harness.check(Arrays.equals(pt, cpt1),
                          "testPadding(" + padName + ")");

            jce.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kb, "AES"));
            jce.doFinal(pt, 0, pt.length, ct2, 0);

            attrib.put(IMode.STATE, new Integer(IMode.DECRYPTION));
            gnu.reset();
            gnu.init(attrib);
            byte[] pcpt = new byte[48];
            for (int i = 0; i < ct2.length; i += 16)
              gnu.update(ct2, i, pcpt, i);

            int trim = pad.unpad(pcpt, 0, pcpt.length);
            System.arraycopy(pcpt, 0, cpt2, 0, pcpt.length - trim);

            harness.check(Arrays.equals(pt, cpt2),
                          "testPadding(" + padName + ")");
          }
View Full Code Here

            Registry.OFB_MODE, new Blowfish(), 8),
            Direction.FORWARD));

    testcase.attributes.put(modeNdx, testcase.modeAttributes);

    IPad pkcs7 = PadFactory.getInstance(Registry.PKCS7_PAD);

    testcase.asm = new Assembly();
    testcase.asm.addPreTransformer(Transformer.getCascadeTransformer(ofbBlowfish));
    testcase.asm.addPreTransformer(Transformer.getPaddingTransformer(pkcs7));
View Full Code Here

TOP

Related Classes of gnu.javax.crypto.pad.IPad

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.