{"size": 704, "ext": "js", "max_stars_repo_path": "js-mutual-auth-ecies/crypto/kmac.js", "max_stars_repo_name": "PrivateSky/pskcrypto", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js-mutual-auth-ecies/crypto/kmac.js", "max_issues_repo_name": "PrivateSky/pskcrypto", "max_issues_repo_issues_event_min_datetime": "2021-04-22T11:17:35.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-22T11:17:35.000Z", "max_forks_repo_path": "js-mutual-auth-ecies/crypto/kmac.js", "max_forks_repo_name": "PrivateSky/pskcrypto", "max_forks_repo_forks_event_min_datetime": "2021-01-25T21:14:53.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-25T21:14:53.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 27.0769230769, "max_line_length": 82, "alphanum_fraction": 0.6818181818}
'use strict';

const crypto = require('crypto');
const config = require('../config');

function computeKMAC(key, data, options) {
    if (key.length !== options.macKeySize) {
        throw new Error('Invalid length of input MAC key')
    }
    return crypto.createHmac(options.hashFunctionName, key).update(data).digest();
}

function verifyKMAC(tag, key, data, options) {
    if (key.length !== options.macKeySize) {
        throw new Error('Invalid length of input MAC key')
    }
    const timingSafeEqual = require('./index').timingSafeEqual;
    const computedTag = computeKMAC(key, data, options)
    return timingSafeEqual(computedTag, tag)
}

module.exports = {
    computeKMAC,
    verifyKMAC
}
