Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import com.google.crypto.tink.mac.ChunkedMac;
import com.google.crypto.tink.mac.ChunkedMacComputation;
import com.google.crypto.tink.mac.ChunkedMacVerification;
import com.google.crypto.tink.util.Bytes;
import com.google.errorprone.annotations.Immutable;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.security.Provider;
import java.util.Arrays;

/** AES-CMAC implementation of the ChunkedMac interface. */
@Immutable
Expand All @@ -52,7 +53,9 @@ public ChunkedMacVerification createVerification(final byte[] tag)
if (tag.length < key.getOutputPrefix().size()) {
throw new GeneralSecurityException("Tag too short");
}
if (!key.getOutputPrefix().equals(Bytes.copyFrom(tag, 0, key.getOutputPrefix().size()))) {
if (!MessageDigest.isEqual(
key.getOutputPrefix().toByteArray(),
Arrays.copyOf(tag, key.getOutputPrefix().size()))) {
throw new GeneralSecurityException("Wrong tag prefix");
}
return ChunkedMacVerificationFromComputation.create(new ChunkedAesCmacComputation(key), tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import com.google.crypto.tink.mac.ChunkedMacComputation;
import com.google.crypto.tink.mac.ChunkedMacVerification;
import com.google.crypto.tink.mac.HmacKey;
import com.google.crypto.tink.util.Bytes;
import com.google.errorprone.annotations.Immutable;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.util.Arrays;

/** Class that provides the functionality expressed by the ChunkedMac interface with HMAC. */
@Immutable
Expand Down Expand Up @@ -53,7 +54,9 @@ public ChunkedMacVerification createVerification(final byte[] tag)
if (tag.length < key.getOutputPrefix().size()) {
throw new GeneralSecurityException("Tag too short");
}
if (!key.getOutputPrefix().equals(Bytes.copyFrom(tag, 0, key.getOutputPrefix().size()))) {
if (!MessageDigest.isEqual(
key.getOutputPrefix().toByteArray(),
Arrays.copyOf(tag, key.getOutputPrefix().size()))) {
throw new GeneralSecurityException("Wrong tag prefix");
}
return ChunkedMacVerificationFromComputation.create(new ChunkedHmacComputation(key), tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.crypto.tink.proto.OutputPrefixType;
import com.google.crypto.tink.subtle.Bytes;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.util.Arrays;

/**
Expand Down Expand Up @@ -97,7 +98,7 @@ public void verifyMac(byte[] mac, byte[] data) throws GeneralSecurityException {
macNoPrefix = Arrays.copyOfRange(mac, CryptoFormat.NON_RAW_PREFIX_SIZE, mac.length);
}

if (!Arrays.equals(identifier, prefix)) {
if (!MessageDigest.isEqual(identifier, prefix)) {
throw new GeneralSecurityException("wrong prefix");
}

Expand Down