Package makwa

Examples of makwa.Makwa


  }

  private void checkSimple(boolean preHash,
    int postHashLength, int workFactor)
  {
    Makwa mpub = new Makwa(modulus, Makwa.SHA256,
      preHash, postHashLength, workFactor);
    Makwa mpriv = new Makwa(privKey, Makwa.SHA256,
      preHash, postHashLength, workFactor);

    String h1 = mpub.hashNewPassword("test1");
    check(mpub.verifyPassword("test1", h1));
    check(mpriv.verifyPassword("test1", h1));
    check(!mpub.verifyPassword("test2", h1));
    check(!mpriv.verifyPassword("test2", h1));
    String h2 = mpriv.hashNewPassword("test1");
    check(mpub.verifyPassword("test1", h2));
    check(mpriv.verifyPassword("test1", h2));
    check(!mpub.verifyPassword("test2", h2));
    check(!mpriv.verifyPassword("test2", h2));

    // Since each hash value uses its own salt, the strings
    // ought to be different.
    check(!h1.equals(h2));
  }
View Full Code Here


    check(!h1.equals(h2));
  }

  private void checkWFChange()
  {
    Makwa mpubSmall = new Makwa(modulus, Makwa.SHA256,
      false, 0, 384);
    Makwa mprivSmall = new Makwa(privKey, Makwa.SHA256,
      false, 0, 384);
    Makwa mpubLarge = new Makwa(modulus, Makwa.SHA256,
      false, 0, 4096);
    Makwa mprivLarge = new Makwa(privKey, Makwa.SHA256,
      false, 0, 4096);

    String hsmall = mpubSmall.hashNewPassword("test1");
    String hlarge = mpubSmall.setNewWorkFactor(hsmall, 4096);
    check(mprivLarge.verifyPassword("test1", hlarge));
    hlarge = mprivSmall.setNewWorkFactor(hsmall, 4096);
    check(mpubLarge.verifyPassword("test1", hlarge));
    hsmall = mprivLarge.setNewWorkFactor(hlarge, 384);
    check(mpubSmall.verifyPassword("test1", hsmall));
  }
View Full Code Here

  }

  private void checkUnescrow()
    throws Exception
  {
    Makwa mpub = new Makwa(modulus, Makwa.SHA256,
      false, 0, 3072);
    Makwa mpriv = new Makwa(privKey, Makwa.SHA256,
      false, 0, 3072);

    String h = mpub.hashNewPassword("test1");
    check(equals("test1".getBytes("UTF-8"),
      mpriv.unescrow(h)));
  }
View Full Code Here

  {
    MakwaDelegation md = MakwaDelegation.generate(
      PRIV2048, 4096);
    byte[] mdEnc = md.export();
    md = new MakwaDelegation(mdEnc);
    Makwa mpub = new Makwa(modulus, Makwa.SHA256,
      false, 0, 4096);
    Makwa mpriv = new Makwa(privKey, Makwa.SHA256,
      false, 0, 4096);

    Makwa.DelegationContext dc =
      mpub.hashNewPasswordDelegate("test1", md);
    byte[] req = dc.getRequest();
    byte[] ans = Makwa.processDelegationRequest(req);
    String h = dc.doFinalToString(ans);
    check(mpriv.verifyPassword("test1", h));

    dc = mpub.verifyPasswordDelegate("test1", h, md);
    req = dc.getRequest();
    ans = Makwa.processDelegationRequest(req);
    check(dc.doFinalVerify(ans));
View Full Code Here

     * is no "PHC-compliant API" in Java. However, we can still
     * check a test vector.
     */
    byte[] salt = new byte[] { 1, 2, 3, 4 };
    byte[] input = "sample for PHC".getBytes("UTF-8");
    Makwa m = new Makwa(PHC_PUB2048, 0, false, 0, 4096);
    byte[] out = m.doHash(input, salt, true, 16, 8192);
    byte[] ref = new byte[] {
      (byte)0x1d, (byte)0x4f, (byte)0x1b, (byte)0x05,
      (byte)0x58, (byte)0xe9, (byte)0x60, (byte)0xce,
      (byte)0x11, (byte)0xad, (byte)0xd5, (byte)0x20,
      (byte)0xca, (byte)0x9e, (byte)0x28, (byte)0xf3
View Full Code Here

    check(equals(out, ref));
  }

  private void speedTest()
  {
    Makwa mpub = new Makwa(modulus, Makwa.SHA256,
      false, 0, 4096);
    int wprev = 1;
    int w = 2;
    long ttprev = 0;
    byte[] input = new byte[9];
    for (;;) {
      long begin = System.currentTimeMillis();
      byte[] salt = Makwa.createSalt();
      mpub.doHash(input, salt, true, 16, w);
      long end = System.currentTimeMillis();
      long tt = end - begin;
      if (tt > 4000) {
        System.out.printf("wf/s = %.2f",
          (1000.0 * (w - wprev)) / (tt - ttprev));
        System.out.println();
        break;
      }
      ttprev = tt;
      wprev = w;
      w <<= 1;
    }

    Makwa mpriv = new Makwa(PRIV2048, 0, true, 16, 65536);
    String ref = mpriv.hashNewPassword("speedtest");
    int cc = 2;
    for (;;) {
      long begin = System.currentTimeMillis();
      for (int m = 0; m < cc; m ++) {
        mpriv.verifyPassword("speedtest", ref);
      }
      long end = System.currentTimeMillis();
      long tt = end - begin;
      if (tt > 4000) {
        System.out.printf("priv/s = %.2f",
View Full Code Here

    }

    BigInteger mod = MakwaPrivateKey.decodePublic(PUB2048);
    MakwaPrivateKey pkey = new MakwaPrivateKey(PRIV2048);
    check(mod.equals(pkey.getModulus()));
    Makwa mpub = new Makwa(mod, Makwa.SHA256, false, 0, 1024);
    Makwa mpriv = new Makwa(pkey, Makwa.SHA256, false, 0, 1024);

    /*
     * Some KDF test vectors.
     */
    for (int i = 0; i < 200; i ++) {
      byte[] input = new byte[i];
      for (int j = 0; j < i; j ++) {
        input[j] = (byte)(7 * i + 83 * j);
      }
      printKDF("KDF/SHA-256", Makwa.SHA256, input, 100);
      printKDF("KDF/SHA-512", Makwa.SHA512, input, 100);
    }

    /*
     * The detailed test vector from the specification.
     */
    byte[] pi;
    try {
      String pwd = "Gego beshwaji'aaken awe makwa;"
        + " onzaam naniizaanizi.";
      pi = pwd.getBytes("UTF-8");
    } catch (Exception e) {
      throw new Error(e);
    }
    byte[] salt = new byte[] {
      (byte)0xC7, (byte)0x27, (byte)0x03, (byte)0xC2,
      (byte)0x2A, (byte)0x96, (byte)0xD9, (byte)0x99,
      (byte)0x2F, (byte)0x3D, (byte)0xEA, (byte)0x87,
      (byte)0x64, (byte)0x97, (byte)0xE3, (byte)0x92
    };
    byte[] ref = new byte[] {
      (byte)0xC9, (byte)0xCE, (byte)0xA0, (byte)0xE6,
      (byte)0xEF, (byte)0x09, (byte)0x39, (byte)0x3A,
      (byte)0xB1, (byte)0x71, (byte)0x0A, (byte)0x08
    };
    check(equals(ref, mpub.doHash(pi, salt, false, 12, 4096)));
    String detailed = mpub.encodeOutput(salt, false, 12, 4096, ref);
    System.out.println("2048-bit modulus, SHA-256");
    println("input", pi);
    println("salt", salt);
    System.out.println("pre-hashing: false");
    System.out.println("post-hashing: 12");
    println("bin4096", ref);
    System.out.println("str4096: " + detailed);
    System.out.println();

    sha256.update(ref);
    sha256.update(detailed.getBytes("UTF-8"));

    /*
     * A lot of test vectors of various sizes and parameters.
     */
    printKAT("2048-bit modulus, SHA-256", mpub, mpriv);

    mpub = new Makwa(mod, Makwa.SHA512, false, 0, 1024);
    mpriv = new Makwa(pkey, Makwa.SHA512, false, 0, 1024);
    printKAT("2048-bit modulus, SHA-512", mpub, mpriv);

    println("KAT digest", sha256.digest());
  }
View Full Code Here

TOP

Related Classes of makwa.Makwa

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.