Check whether a given HMAC value matches the HMAC for the timestamp in
this HawkWwwAuthenticateContext.

@param hmac
The HMAC value to test.
@return true if the HMAC matches the HMAC computed for this context,
false otherwise.
@throws HawkException
770738
public boolean isValidTimestampMac(String hmac) throws HawkException {
		String this_hmac = this.generateHmac();
		return Util.fixedTimeEqual(this_hmac, hmac);
	}
240384
private void validateMac(byte[] key, HashAlgorithm hmacAlgorithm) throws KSIException {
        try {
            HashAlgorithm receivedHmacAlgorithm = mac.getAlgorithm();
            if (receivedHmacAlgorithm != hmacAlgorithm) {
                throw new KSIException(
                        "HMAC algorithm mismatch. Expected " + hmacAlgorithm.getName() + ", received " + receivedHmacAlgorithm.getName());
            }
            // calculate and set the MAC value
            DataHash macValue = new DataHash(hmacAlgorithm, Util.calculateHMAC(getContent(), key, hmacAlgorithm.getName()));
            if (!mac.equals(macValue)) {
                throw new InvalidMessageAuthenticationCodeException("Invalid MAC code. Expected " + mac + ", calculated " + macValue);
            }
        } catch (IOException e) {
            throw new InvalidMessageAuthenticationCodeException("IO Exception occurred turning MAC calculation", e);
        } catch (InvalidKeyException e) {
            throw new InvalidMessageAuthenticationCodeException("Problem with HMAC key.", e);
        } catch (NoSuchAlgorithmException e) {
            throw new InvalidMessageAuthenticationCodeException("Unsupported HMAC algorithm.", e);
        } catch (HashException e) {
            throw new KSIProtocolException("Hashing exception occurred when calculating KSI service response HMAC", e);
        }
    }
998379
function compareHmac(hmac1, hmac2) {
    var left = hmac1;
    if (Buffer.isBuffer(hmac1)) {
        left = hmac1.toString('base64');
    }
    var right = hmac2;
    if (Buffer.isBuffer(hmac2)) {
        right = hmac2.toString('base64');
    }
    return (left == right);
}
1305497
final boolean match(JmsJcaUserDetails userDetails,
                        SICoreConnection coreConnection) {

        boolean usersMatch = (_userDetails == null) ? (userDetails == null)
                        : (_userDetails.equals(userDetails));
        boolean coreConnectionsMatch = (coreConnection == null)
                                       || coreConnection.isEquivalentTo(_coreConnection);

        return usersMatch && coreConnectionsMatch && isValid();
    }
1009714
def verify_hmac(self, data):
        
        hmac = HMAC(self.SK_ar, digestmod=sha256)
        hmac_theirs = data[-MACLEN:]
        hmac.update(data[:-MACLEN])
        hmac_ours = hmac.digest()[:MACLEN]
        logger.debug('HMAC verify (ours){} (theirs){}'.format(
            binascii.hexlify(hmac_ours), binascii.hexlify(hmac_theirs)))
        if hmac_ours != hmac_theirs:
            raise IkeError('HMAC verify failed')
793934
public static boolean verifyTimestampCertificates(TimeStampToken ts, KeyStore keystore, String provider) {
        if (provider == null)
            provider = "BC";
        try {
            for (Enumeration aliases = keystore.aliases(); aliases.hasMoreElements();) {
                try {
                    String alias = (String)aliases.nextElement();
                    if (!keystore.isCertificateEntry(alias))
                        continue;
                    X509Certificate certStoreX509 = (X509Certificate)keystore.getCertificate(alias);
                    SignerInformationVerifier siv = new JcaSimpleSignerInfoVerifierBuilder().setProvider(provider).build(certStoreX509);
                    ts.validate(siv);
                    return true;
                }
                catch (Exception ex) {
                }
            }
        }
        catch (Exception e) {
        }
        return false;
    }
573350
private boolean isSoilAnalysisExist(ArrayList<HashMap> icSubArr) {

        for (HashMap icSubData : icSubArr) {
            if (!getValueOr(icSubData, "slsc", "").equals("")) {
                return true;
            }
        }
        return false;
    }
1096450
public boolean matchesBeacon(Beacon beacon) {
        // All identifiers must match, or the corresponding region identifier must be null.
        for (int i = mIdentifiers.size(); --i >= 0; ) {
            final Identifier identifier = mIdentifiers.get(i);
            Identifier beaconIdentifier = null;
            if (i < beacon.mIdentifiers.size()) {
                beaconIdentifier = beacon.getIdentifier(i);
            }
            if ((beaconIdentifier == null && identifier != null) ||
                    (beaconIdentifier != null  && identifier != null && !identifier.equals(beaconIdentifier))) {
                return false;
            }
        }
        if (mBluetoothAddress != null && !mBluetoothAddress.equalsIgnoreCase(beacon.mBluetoothAddress)) {
            return false;
        }
        return true;
    }
644316
private static boolean matches(String matchHeader, String toMatch) {
        String[] matchValues = matchHeader.split("\\s*,\\s*");
        Arrays.sort(matchValues);
        return Arrays.binarySearch(matchValues, toMatch) > -1
                || Arrays.binarySearch(matchValues, "*") > -1;
    }
567409
public function validateHmac(string $hmac, string $key, string $algorithm = 'sha256', bool $raw = false): bool
	{
		return hash_equals($hmac, $this->getHmac($key, $algorithm, $raw));
	}
1340641
public boolean matchesAssignment(WorkerHeartbeat whb, Map<Integer, LocalAssignment> assignedTasks) {
        boolean isMatch = true;
        LocalAssignment localAssignment = assignedTasks.get(whb.getPort());
        if (localAssignment == null) {
            LOG.debug("Following worker has been removed, port=" + whb.getPort() + ", assignedTasks=" + assignedTasks);
            isMatch = false;
        } else if (!whb.getTopologyId().equals(localAssignment.getTopologyId())) {
            // topology id not equal
            LOG.info("topology id not equal whb=" + whb.getTopologyId() + ",localAssignment=" + localAssignment.getTopologyId());
            isMatch = false;
        }/*
          * else if (!(whb.getTaskIds().equals(localAssignment.getTaskIds()))) { // task-id isn't equal LOG.info("task-id isn't equal whb=" + whb.getTaskIds() +
          * ",localAssignment=" + localAssignment.getTaskIds()); isMatch = false; }
          */

        return isMatch;
    }
626003
private String generateHmac() throws HawkException {

		String baseString = getBaseString();

		Mac mac;
		try {
			mac = Mac.getInstance(getAlgorithm().getMacName());
		} catch (NoSuchAlgorithmException e) {
			throw new HawkException("Unknown algorithm "
					+ getAlgorithm().getMacName(), e);
		}

		SecretKeySpec secret_key = new SecretKeySpec(getKey().getBytes(
				Charsets.UTF_8), getAlgorithm().getMacName());
		try {
			mac.init(secret_key);
		} catch (InvalidKeyException e) {
			throw new HawkException("Key is invalid ", e);
		}

		return new String(Base64.encodeBase64(mac.doFinal(baseString
				.getBytes(Charsets.UTF_8))), Charsets.UTF_8);
	}
729908
protected void verifyTimestamp(WSHandlerResult result) throws WSSecurityException {
        List<WSSecurityEngineResult> insertTimestampResults = result.getActionResults().getOrDefault(WSConstants.TS, emptyList());
        if (insertTimestampResults.isEmpty()) {
            throw new Wss4jSecurityValidationException("No action results for 'Insert timestamp' found");
        } else if (insertTimestampResults.size() > 1) {
            throw new Wss4jSecurityValidationException("Multiple action results for 'Insert timestamp' found. Expected only 1.");
        }
        WSSecurityEngineResult actionResult = insertTimestampResults.get(0);

        if (actionResult != null) {
            Timestamp timestamp = (Timestamp) actionResult.get(WSSecurityEngineResult.TAG_TIMESTAMP);
            if (timestamp != null && timestampStrict) {
                Credential credential = new Credential();
                credential.setTimestamp(timestamp);

                RequestData requestData = new RequestData();
                requestData.setWssConfig(WSSConfig.getNewInstance());
                requestData.setTimeStampTTL(validationTimeToLive);
                requestData.setTimeStampStrict(timestampStrict);

                TimestampValidator validator = new TimestampValidator();
                validator.validate(credential, requestData);
            }
        }
    }
121472
private byte[] hmac(byte[] key, byte[] data) {
        try {
            final Mac mac = Mac.getInstance(hmacAlgorithm);
            mac.init(new SecretKeySpec(key, mac.getAlgorithm()));
            return mac.doFinal(data);
        } catch (InvalidKeyException e) {
            if (key.length == 0) {
                throw new UnsupportedOperationException("This JVM does not support empty HMAC keys (empty passwords). "
                        + "Please set a bucket password or upgrade your JVM.");
            } else {
                throw new RuntimeException("Failed to generate HMAC hash for password", e);
            }
        } catch (Throwable t) {
            throw new RuntimeException(t);
        }
    }
331942
public boolean matches(String digest) {
        String computed = sha1();
        LOGGER.trace("Signature: calculated={} provided={}", computed, digest);
        return StringUtils.equals(computed, digest);
    }
292370
@Override
    public boolean matchesIndexValue(int v) {
        /* The index value v, in the range [0,255], is contained in this set if
         * it is contained in any pair of this set.  Pairs either have the high
         * bytes equal, or unequal.  If the high bytes are equal, then we have
         * aaxx..aayy, where aa is the high byte.  Then v is contained if xx <=
         * v <= yy.  If the high bytes are unequal we have aaxx..bbyy, bb>aa.
         * Then v is contained if xx <= v || v <= yy.  (This is identical to the
         * time zone month containment logic.)
         */
        for (int i=0; i<getRangeCount(); ++i) {
            int low = getRangeStart(i);
            int high = getRangeEnd(i);
            if ((low & ~0xFF) == (high & ~0xFF)) {
                if ((low & 0xFF) <= v && v <= (high & 0xFF)) {
                    return true;
                }
            } else if ((low & 0xFF) <= v || v <= (high & 0xFF)) {
                return true;
            }
        }
        if (strings.size() != 0) {
            for (String s : strings) {
                //if (s.length() == 0) {
                //    // Empty strings match everything
                //    return true;
                //}
                // assert(s.length() != 0); // We enforce this elsewhere
                int c = UTF16.charAt(s, 0);
                if ((c & 0xFF) == v) {
                    return true;
                }
            }
        }
        return false;
    }
400719
public function verify(string $hmac, self $auth, int $driftAllowance = 90) : bool
    {
        $drift = $this->getTimeDrift($auth->getDate());
        if ($drift === null || $drift >= $driftAllowance) {
            return false;
        }

        try {
            if (\sodium_memcmp($hmac, $auth->getHMAC()) === 0) {
                return true;
            }
        } catch (\SodiumException $e) {
            return false;
        }

        return false;
    }