HMAC Module

This hmac (About Modules) module implements a HMAC for Espruino. It depends on the inclusion of hashlib to compute the checksums.

How to use the module:

  var hmac = require("hmac");
  var hashlib = require("hashlib");
  var foo = hmac.create("secret", "message", hashlib.sha256);
  var bar = hmac.create("secret", "another message", hashlib.sha256);

  foo.digest() // raw digest
  foo.hexdigest() // hex encoded digest

  foo.update('more message') // used to iterate parts of a message

  // This function uses an approach designed to prevent timing analysis,
  // making it appropriate for cryptography.
  hmac.compare_digest(foo.digest(), bar.digest())

Reference

hmac.prototype.update = function (m) { ... }

hmac.prototype.digest = function () { ... }

hmac.prototype.hexdigest = function () { ... }

exports.create = function (key, message, digestmod) { ... }

/* compare_digest(a, b) -> bool

  Return 'a == b'.  This function uses an approach designed to prevent
  timing analysis, making it appropriate for cryptography.
  a and b must both be of the same type.

  Note: If a and b are of different lengths, or if an error occurs,
  a timing attack could theoretically reveal information about the
  types and lengths of a and b--but not their values.
*/
exports.compare_digest = function (a, b) { ... }

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.