Refine search
r = new BigInteger(bytes); s = new BigInteger(bytes); u1 = (new BigInteger(1, digest)).multiply(w).mod(q); u2 = r.multiply(w).mod(q); v = g.modPow(u1, p).multiply(y.modPow(u2, p)).mod(p).mod(q);
public AuthenticationHelper(String userPoolName) { do { a = new BigInteger(EPHEMERAL_KEY_LENGTH, SECURE_RANDOM).mod(N); A = GG.modPow(a, N); } while (A.mod(N).equals(BigInteger.ZERO)); if (userPoolName.contains("_")) { poolName = userPoolName.split("_", 2)[1]; } else { poolName = userPoolName; } }
/** * @param sigBytes ASN.1 R,S */ @Override protected boolean engineVerify(byte[] sigBytes) throws SignatureException { BigInteger elgp = key.getParams().getP(); BigInteger pm1 = elgp.subtract(BigInteger.ONE); BigInteger elgg = key.getParams().getG(); BigInteger y = ((ElGamalPublicKey) key).getY(); if (!(y instanceof NativeBigInteger)) y = new NativeBigInteger(y); byte[] data = digest.digest(); try { BigInteger[] rs = SigUtil.aSN1ToBigInteger(sigBytes, 256); BigInteger r = rs[0]; BigInteger s = rs[1]; if (r.signum() != 1 || s.signum() != 1 || r.compareTo(elgp) != -1 || s.compareTo(pm1) != -1) return false; NativeBigInteger h = new NativeBigInteger(1, data); BigInteger modvalr = r.modPow(s, elgp); BigInteger modvaly = y.modPow(r, elgp); BigInteger modmulval = modvalr.multiply(modvaly).mod(elgp); BigInteger v = elgg.modPow(h, elgp); boolean ok = v.compareTo(modmulval) == 0; return ok; } catch (RuntimeException e) { throw new SignatureException("verify", e); } }
/** * Generates the SRP verifier. * @param salt REQUIRED: The random salt created by the service. * @param userIdHash REQIURED: Username hash. * @return verifier as a BigInteger. */ private static BigInteger calcVerifier(BigInteger salt, byte[] userIdHash) { begin(); update(salt); update(userIdHash); final byte[] digest = end(); final BigInteger x = new BigInteger(1, digest); return GG.modPow(x, N); }
byte[] samplePrime = CryptoConstants.elgp.toByteArray(); BigInteger jg = new BigInteger(sampleGenerator); NativeBigInteger ng = CryptoConstants.elgg; BigInteger jp = new BigInteger(samplePrime); bi = new BigInteger(16, rand); } while (bi.signum() == 0); if (mode == 1) jg.modPow(bi, jp); else if (mode == 2) ng.modPowCT(bi, jp); jval = jg.modPow(bi, jp); else jval = bi.modInverse(jp);
private CramerShoupPublicKeyParameters calculatePublicKey(CramerShoupParameters csParams, CramerShoupPrivateKeyParameters sk) { BigInteger g1 = csParams.getG1(); BigInteger g2 = csParams.getG2(); BigInteger p = csParams.getP(); BigInteger c = g1.modPow(sk.getX1(), p).multiply(g2.modPow(sk.getX2(), p)); BigInteger d = g1.modPow(sk.getY1(), p).multiply(g2.modPow(sk.getY2(), p)); BigInteger h = g1.modPow(sk.getZ(), p); return new CramerShoupPublicKeyParameters(csParams, c, d, h); } }
BigInteger bi1; for (String sbigint : input.split(" ")) { BigInteger b1 = new BigInteger(sbigint); bi1 = b1.modPow(exp, mod); }
digestBI = new BigInteger(1, msgDigest.digest()); k = new BigInteger(1, randomBytes); if (k.compareTo(q) != -1) { continue; r = g.modPow(k, p).mod(q); if (r.signum() == 0) { continue; s = k.modInverse(q).multiply(digestBI.add(x.multiply(r)).mod(q)) .mod(q);
@Test public void pow22523ReturnsCorrectResult() { for (int i=0; i<1000; i++) { // Arrange: final FieldElement f1 = getRandomFieldElement(); final BigInteger b1 = toBigInteger(f1); // Act: final FieldElement f2 = f1.pow22523(); final BigInteger b2 = toBigInteger(f2).mod(getQ()); // Assert: Assert.assertThat(b2, IsEqual.equalTo(b1.modPow(BigInteger.ONE.shiftLeft(252).subtract(new BigInteger("3")), getQ()))); } }
private CramerShoupPublicKeyParameters calculatePublicKey(CramerShoupParameters csParams, CramerShoupPrivateKeyParameters sk) { BigInteger g1 = csParams.getG1(); BigInteger g2 = csParams.getG2(); BigInteger p = csParams.getP(); BigInteger c = g1.modPow(sk.getX1(), p).multiply(g2.modPow(sk.getX2(), p)); BigInteger d = g1.modPow(sk.getY1(), p).multiply(g2.modPow(sk.getY2(), p)); BigInteger h = g1.modPow(sk.getZ(), p); return new CramerShoupPublicKeyParameters(csParams, c, d, h); } }
public BigInteger[] step1() { x2 = getRandomExponent(); x3 = getRandomExponent(); g2 = new BigInteger(gen + "").modPow(x2, mod); g3 = new BigInteger(gen + "").modPow(x3, mod); BigInteger[] logProof1 = createLogProof("1", g2); BigInteger[] logProof2 = createLogProof("2", g3); BigInteger c1 = logProof1[0]; BigInteger d1 = logProof1[1]; BigInteger c2 = logProof2[0]; BigInteger d2 = logProof2[1]; return new BigInteger[] { g2, g3, c1, d1, c2, d2 }; }
messageDigest.reset(); messageDigest.update(A.toByteArray()); final BigInteger u = new BigInteger(1, messageDigest.digest(B.toByteArray())); if (u.equals(BigInteger.ZERO)) { throw new CognitoInternalErrorException("Hash of A and B cannot be zero"); final BigInteger x = new BigInteger(1, messageDigest.digest(userIdHash)); final BigInteger s = (B.subtract(KK.multiply(GG.modPow(x, N))) .modPow(a.add(u.multiply(x)), N)).mod(N);
public AuthenticationHelper(String userPoolName) { do { a = new BigInteger(EPHEMERAL_KEY_LENGTH, SECURE_RANDOM).mod(N); A = GG.modPow(a, N); } while (A.mod(N).equals(BigInteger.ZERO)); if (userPoolName.contains("_")) { poolName = userPoolName.split("_", 2)[1]; } else { poolName = userPoolName; } }
private CramerShoupPublicKeyParameters calculatePublicKey(CramerShoupParameters csParams, CramerShoupPrivateKeyParameters sk) { BigInteger g1 = csParams.getG1(); BigInteger g2 = csParams.getG2(); BigInteger p = csParams.getP(); BigInteger c = g1.modPow(sk.getX1(), p).multiply(g2.modPow(sk.getX2(), p)); BigInteger d = g1.modPow(sk.getY1(), p).multiply(g2.modPow(sk.getY2(), p)); BigInteger h = g1.modPow(sk.getZ(), p); return new CramerShoupPublicKeyParameters(csParams, c, d, h); } }
public void init(SecureRandom rnd) { k = null; x = new BigInteger(p.bitLength() - 1, rnd); e = g.modPow(x, p); }
private static ECPoint addPoint(ECPoint r, ECPoint s, EllipticCurve curve) { if (r.equals(s)) return doublePoint(r, curve); else if (r.equals(ECPoint.POINT_INFINITY)) return s; else if (s.equals(ECPoint.POINT_INFINITY)) return r; BigInteger prime = ((ECFieldFp) curve.getField()).getP(); // use NBI modInverse(); BigInteger tmp = r.getAffineX().subtract(s.getAffineX()); tmp = new NativeBigInteger(tmp); BigInteger slope = (r.getAffineY().subtract(s.getAffineY())).multiply(tmp.modInverse(prime)).mod(prime); slope = new NativeBigInteger(slope); BigInteger xOut = (slope.modPow(TWO, prime).subtract(r.getAffineX())).subtract(s.getAffineX()).mod(prime); BigInteger yOut = s.getAffineY().negate().mod(prime); yOut = yOut.add(slope.multiply(s.getAffineX().subtract(xOut))).mod(prime); ECPoint out = new ECPoint(xOut, yOut); return out; }
private static boolean isPrime(int n) { BigInteger N = new BigInteger(String.valueOf(n)); BigInteger N_MINUS_1 = N.subtract(BigInteger.ONE); BigInteger sum = BigInteger.ZERO; for (int k = 1; k < n; k++) sum = sum.add(new BigInteger(String.valueOf(k)).modPow(N_MINUS_1,N)).mod(N); return sum.equals(N_MINUS_1); }