Package gnu.javax.crypto.mac

Examples of gnu.javax.crypto.mac.IMac


{
  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfMacFactory");
    String mac;
    IMac algorithm;
    for (Iterator it = MacFactory.getNames().iterator(); it.hasNext();)
      {
        mac = (String) it.next();
        try
          {
View Full Code Here


    harness.checkPoint("TestOfHMacCloneability.clone1");

    setUp(harness);
    try
      {
        IMac clone = (IMac) hmac.clone();

        hmac.init(hmacAttributes);

        hmac.update((byte) 'a');
        hmac.update((byte) 'b');
        hmac.update((byte) 'c');

        clone.init(hmacAttributes);

        clone.update((byte) 'a');
        clone.update((byte) 'b');
        clone.update((byte) 'c');

        byte[] md1 = hmac.digest();
        byte[] md2 = clone.digest();

        harness.check(Arrays.equals(md1, md2), "clone1");
      }
    catch (Exception x)
      {
View Full Code Here

        hmac.update((byte) 'a');
        hmac.update((byte) 'b');
        hmac.update((byte) 'c');

        IMac clone = (IMac) hmac.clone();

        hmac.update((byte) 'd');
        hmac.update((byte) 'e');
        hmac.update((byte) 'f');

        clone.update((byte) 'd');
        clone.update((byte) 'e');
        clone.update((byte) 'f');

        byte[] md1 = hmac.digest();
        byte[] md2 = clone.digest();

        harness.check(Arrays.equals(md1, md2), "clone2");
      }
    catch (Exception x)
      {
View Full Code Here

{
  public void test(TestHarness harness)
  {
    harness.checkPoint("TestOfHMacFactory");
    String mac;
    IMac algorithm;
    for (Iterator it = HMacFactory.getNames().iterator(); it.hasNext();)
      {
        mac = (String) it.next();
        try
          {
View Full Code Here

                                           + "f69f2445df4f9b17ad2b417be66c3710"),
                    Util.toBytesFromString("e1992190549f6ed5696a2c056c315410") } };

  public void test(TestHarness harness)
  {
    IMac mac = MacFactory.getInstance(Registry.OMAC_PREFIX
                                      + Registry.AES_CIPHER);
    harness.checkPoint("OMAC/AES-128");
    HashMap attr = new HashMap();
    for (int i = 0; i < TESTS1.length; i++)
      {
        attr.put(IMac.MAC_KEY_MATERIAL, TESTS1[i][0]);
        try
          {
            mac.init(attr);
            mac.update(TESTS1[i][1], 0, TESTS1[i][1].length);
            byte[] tag = mac.digest();
            harness.check(Arrays.equals(TESTS1[i][2], tag));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }
      }

    harness.checkPoint("OMAC/AES-192");
    for (int i = 0; i < TESTS2.length; i++)
      {
        attr.put(IMac.MAC_KEY_MATERIAL, TESTS2[i][0]);
        try
          {
            mac.init(attr);
            mac.update(TESTS2[i][1], 0, TESTS2[i][1].length);
            byte[] tag = mac.digest();
            harness.check(Arrays.equals(TESTS2[i][2], tag));
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail(x.toString());
          }
      }

    harness.checkPoint("OMAC/AES-256");
    for (int i = 0; i < TESTS3.length; i++)
      {
        attr.put(IMac.MAC_KEY_MATERIAL, TESTS3[i][0]);
        try
          {
            mac.init(attr);
            mac.update(TESTS3[i][1], 0, TESTS3[i][1].length);
            byte[] tag = mac.digest();
            harness.check(Arrays.equals(TESTS3[i][2], tag));
          }
        catch (Exception x)
          {
            harness.debug(x);
View Full Code Here

   */
  public void testEquality(TestHarness harness)
  {
    harness.checkPoint("testEquality");
    String macName;
    IMac gnu = null;
    Mac jce = null;
    byte[] in = this.getClass().getName().getBytes();
    byte[] ba1, ba2;
    HashMap attrib = new HashMap();
    for (Iterator it = MacFactory.getNames().iterator(); it.hasNext();)
      {
        macName = (String) it.next();
        // we dont provide OMAC based on NullCipher through the JCE. skip
        if (macName.equals("omac-null"))
          continue;

        AlgorithmParameterSpec params = null;
        if (macName.equalsIgnoreCase("UMAC32"))
          {
            byte[] nonce = new byte[16];
            for (int i = 0; i < nonce.length; i++)
              nonce[i] = (byte) i;

            params = new UMac32ParameterSpec(nonce);
            attrib.put(UMac32.NONCE_MATERIAL, nonce);
          }
        else if (macName.equalsIgnoreCase("TMMH16"))
          {
            IRandom rand1 = new MDGenerator();
            rand1.init(new HashMap());
            Integer tagLen = new Integer(4);
            params = new TMMHParameterSpec(rand1, tagLen);

            IRandom rand2 = new MDGenerator();
            rand2.init(new HashMap());
            attrib.put(TMMH16.KEYSTREAM, rand2);
            attrib.put(TMMH16.TAG_LENGTH, tagLen);
          }

        try
          {
            gnu = MacFactory.getInstance(macName);
            harness.check(gnu != null, "MacFactory.getInstance(" + macName
                                       + ")");
          }
        catch (InternalError x)
          {
            harness.fail("MacFactory.getInstance(" + macName + "): "
                         + String.valueOf(x));
          }

        try
          {
            jce = Mac.getInstance(macName, Registry.GNU_CRYPTO);
            harness.check(jce != null, "Mac.getInstance()");
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail("Mac.getInstance(" + macName + "): "
                         + String.valueOf(x));
          }

        byte[] kb = null;
        if (macName.equalsIgnoreCase("UMAC32")
            || macName.equalsIgnoreCase("UHASH32"))
          kb = new byte[16];
        else if (macName.toLowerCase().startsWith(Registry.OMAC_PREFIX))
          {
            IBlockCipher cipher = CipherFactory.getInstance(
                macName.substring(Registry.OMAC_PREFIX.length()));
            if (cipher != null)
              kb = new byte[cipher.defaultKeySize()];
            else
              kb = new byte[gnu.macSize()];
          }
        else
          kb = new byte[gnu.macSize()];

        for (int i = 0; i < kb.length; i++)
          kb[i] = (byte) i;

        attrib.put(IMac.MAC_KEY_MATERIAL, kb);
        try
          {
            gnu.init(attrib);
            if (macName.equalsIgnoreCase("TMMH16"))
              jce.init(null, params);
            else
              jce.init(new SecretKeySpec(kb, macName), params);
          }
        catch (Exception x)
          {
            harness.debug(x);
            harness.fail("Mac.getInstance(" + macName + "): "
                         + String.valueOf(x));
          }

        gnu.update(in, 0, in.length);
        ba1 = gnu.digest();
        ba2 = jce.doFinal(in);

        harness.check(Arrays.equals(ba1, ba2), "testEquality(" + macName + ")");
      }
  }
View Full Code Here

TOP

Related Classes of gnu.javax.crypto.mac.IMac

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.