summaryrefslogtreecommitdiffstats
path: root/core/hmac.js
diff options
context:
space:
mode:
authorSteve Thomas <Sc00bz@users.noreply.github.com>2015-11-01 14:36:28 -0600
committerSteve Thomas <Sc00bz@users.noreply.github.com>2015-11-01 14:36:28 -0600
commitdb7e40d449ab4ae65bacf267b38d1bf836b4fe54 (patch)
treef6f815673f56490c8ae3bfdc8ed9a5f4d9996f76 /core/hmac.js
parent025908ef2b091faab75f60188654f789b691ff0d (diff)
parentf9a2494fae0dcddef493de453aa6ab69caa987cf (diff)
downloadsjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.zip
sjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.tar.gz
sjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.tar.bz2
Merge pull request #1 from bitwiseshiftleft/master
Update
Diffstat (limited to 'core/hmac.js')
-rw-r--r--core/hmac.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/core/hmac.js b/core/hmac.js
index 87237b2..84f9a15 100644
--- a/core/hmac.js
+++ b/core/hmac.js
@@ -27,14 +27,35 @@ sjcl.misc.hmac = function (key, Hash) {
this._baseHash[0].update(exKey[0]);
this._baseHash[1].update(exKey[1]);
+ this._resultHash = new Hash(this._baseHash[0]);
};
/** HMAC with the specified hash function. Also called encrypt since it's a prf.
* @param {bitArray|String} data The data to mac.
- * @param {Codec} [encoding] the encoding function to use.
*/
-sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (data, encoding) {
- var w = new (this._hash)(this._baseHash[0]).update(data, encoding).finalize();
- return new (this._hash)(this._baseHash[1]).update(w).finalize();
+sjcl.misc.hmac.prototype.encrypt = sjcl.misc.hmac.prototype.mac = function (data) {
+ if (!this._updated) {
+ this.update(data);
+ return this.digest(data);
+ } else {
+ throw new sjcl.exception.invalid("encrypt on already updated hmac called!");
+ }
+};
+
+sjcl.misc.hmac.prototype.reset = function () {
+ this._resultHash = new this._hash(this._baseHash[0]);
+ this._updated = false;
};
+sjcl.misc.hmac.prototype.update = function (data) {
+ this._updated = true;
+ this._resultHash.update(data);
+};
+
+sjcl.misc.hmac.prototype.digest = function () {
+ var w = this._resultHash.finalize(), result = new (this._hash)(this._baseHash[1]).update(w).finalize();
+
+ this.reset();
+
+ return result;
+}; \ No newline at end of file