Log how long it takes to generate and verify signatures.

This commit is contained in:
akwizgran
2015-01-14 19:09:17 +00:00
parent 920c81199e
commit 03247aedd6

View File

@@ -1,7 +1,10 @@
package org.briarproject.crypto;
import static java.util.logging.Level.INFO;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.util.logging.Logger;
import org.briarproject.api.crypto.PrivateKey;
import org.briarproject.api.crypto.PublicKey;
@@ -18,6 +21,9 @@ import org.spongycastle.crypto.signers.HMacDSAKCalculator;
class SignatureImpl implements Signature {
private static final Logger LOG =
Logger.getLogger(SignatureImpl.class.getName());
private final SecureRandom secureRandom;
private final DSADigestSigner signer;
@@ -53,10 +59,20 @@ class SignatureImpl implements Signature {
}
public byte[] sign() {
return signer.generateSignature();
long now = System.currentTimeMillis();
byte[] signature = signer.generateSignature();
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
LOG.info("Generating signature took " + duration + " ms");
return signature;
}
public boolean verify(byte[] signature) {
return signer.verifySignature(signature);
long now = System.currentTimeMillis();
boolean valid = signer.verifySignature(signature);
long duration = System.currentTimeMillis() - now;
if(LOG.isLoggable(INFO))
LOG.info("Verifying signature took " + duration + " ms");
return valid;
}
}