public int getMacLength() { return hmac.getMacSize(); }
/** * Base constructor. * * @param digest digest to build the HMAC on. */ public HMacDSAKCalculator(Digest digest) { this.hMac = new HMac(digest); this.V = new byte[hMac.getMacSize()]; this.K = new byte[hMac.getMacSize()]; }
public byte[] getMac() { byte[] res = new byte[hMac.getMacSize()]; hMac.doFinal(res, 0); return res; }
public byte[] calculateMAC() { byte[] rv = new byte[hmac.getMacSize()]; hmac.doFinal(rv, 0); return rv; }
public byte[] getMac() { byte[] res = new byte[hMac.getMacSize()]; hMac.doFinal(res, 0); return res; }
static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out) { HMac mac = new HMac(digest); mac.init(new KeyParameter(secret)); byte[] a = seed; int size = digest.getDigestSize(); int iterations = (out.length + size - 1) / size; byte[] buf = new byte[mac.getMacSize()]; byte[] buf2 = new byte[mac.getMacSize()]; for (int i = 0; i < iterations; i++) { mac.update(a, 0, a.length); mac.doFinal(buf, 0); a = buf; mac.update(a, 0, a.length); mac.update(seed, 0, seed.length); mac.doFinal(buf2, 0); System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i))); } }
public void engineStore(OutputStream stream, char[] password) throws IOException { DataOutputStream dOut = new DataOutputStream(stream); byte[] salt = new byte[STORE_SALT_SIZE]; int iterationCount = MIN_ITERATIONS + (random.nextInt() & 0x3ff); random.nextBytes(salt); dOut.writeInt(STORE_VERSION); dOut.writeInt(salt.length); dOut.write(salt); dOut.writeInt(iterationCount); HMac hMac = new HMac(new SHA1Digest()); MacOutputStream mOut = new MacOutputStream(hMac); PBEParametersGenerator pbeGen = new PKCS12ParametersGenerator(new SHA1Digest()); byte[] passKey = PBEParametersGenerator.PKCS12PasswordToBytes(password); pbeGen.init(passKey, salt, iterationCount); hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8)); for (int i = 0; i != passKey.length; i++) { passKey[i] = 0; } saveStore(new TeeOutputStream(dOut, mOut)); byte[] mac = new byte[hMac.getMacSize()]; hMac.doFinal(mac, 0); dOut.write(mac); dOut.close(); }
macParams = pbeGen.generateDerivedMacParameters(hMac.getMacSize()); macParams = pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8); byte[] mac = new byte[hMac.getMacSize()]; hMac.doFinal(mac, 0); byte[] oldMac = new byte[hMac.getMacSize()]; dIn.readFully(oldMac); byte[] oldMac = new byte[hMac.getMacSize()]; dIn.readFully(oldMac);
hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize())); hMac.init(pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8)); byte[] mac = new byte[hMac.getMacSize()];
macParams = pbeGen.generateDerivedMacParameters(hMac.getMacSize()); macParams = pbeGen.generateDerivedMacParameters(hMac.getMacSize() * 8); byte[] mac = new byte[hMac.getMacSize()]; hMac.doFinal(mac, 0); byte[] oldMac = new byte[hMac.getMacSize()]; dIn.readFully(oldMac); byte[] oldMac = new byte[hMac.getMacSize()]; dIn.readFully(oldMac);
private static void hmac_hash(Digest digest, byte[] secret, byte[] seed, byte[] out) { HMac mac = new HMac(digest); KeyParameter param = new KeyParameter(secret); byte[] a = seed; int size = digest.getDigestSize(); int iterations = (out.length + size - 1) / size; byte[] buf = new byte[mac.getMacSize()]; byte[] buf2 = new byte[mac.getMacSize()]; for (int i = 0; i < iterations; i++) { mac.init(param); mac.update(a, 0, a.length); mac.doFinal(buf, 0); a = buf; mac.init(param); mac.update(a, 0, a.length); mac.update(seed, 0, seed.length); mac.doFinal(buf2, 0); System.arraycopy(buf2, 0, out, (size * i), Math.min(size, out.length - (size * i))); } }
protected void hmacHash(Digest digest, byte[] secret, int secretOff, int secretLen, byte[] seed, byte[] output) { HMac mac = new HMac(digest); mac.init(new KeyParameter(secret, secretOff, secretLen)); byte[] a = seed; int macSize = mac.getMacSize(); byte[] b1 = new byte[macSize]; byte[] b2 = new byte[macSize]; int pos = 0; while (pos < output.length) { mac.update(a, 0, a.length); mac.doFinal(b1, 0); a = b1; mac.update(a, 0, a.length); mac.update(seed, 0, seed.length); mac.doFinal(b2, 0); System.arraycopy(b2, 0, output, pos, Math.min(macSize, output.length - pos)); pos += macSize; } }
byte[] computedSignature = new byte[hmac.getMacSize()]; hmac.update(dataToVerify, inputOffset, verifyLen); hmac.doFinal(computedSignature, 0);
byte[] macOutput = new byte[mac.getMacSize()]; mac.init(new KeyParameter(macKey));