GithubHelp home page GithubHelp logo

hash-test-vectors's Introduction

hash-test-vectors

The nist test vectors expanded to cover every hash function supported by node.js, output is saved in a json file, so that it is possible to run tests in the browser.

NIST provides test vectors for sha and md5, and this module takes that set and outputs a json file containing the input (in base 64) plus all output of every hash function that node.js supports.

This makes it easy to test javascript hash functions, with fairly roboust coverage.

I took the original test vectors at http://www.nsrl.nist.gov/testdata/

example

var vectors = require('hash-test-vectors')
var tape = require('tape')
var MySha1 = require('./my-sha1-implementation')

vectors.forEach(function (v, i) {

  tape('my-sha1 against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    t.equal(new MySha1().update(v.input, 'base64').digest('hex'), v.sha1)
    t.equal(new MySha1().update(new Buffer(v.input, 'base64')).digest('hex'), v.sha1)
    t.end()
  })
})

hmac example

hmac vectors taken from rfc4231 (included in this repo)

each test vector has {key: hex, data: hex} and the outputs of hmac with every hash algorithm in node, also in hex encoding.

var vectors = require('hash-test-vectors')
var tape = require('tape')
var MySha1Hmac = require('./my-sha1-hmac-implementation')

vectors.forEach(function (v, i) {
  tape('my-sha1-hmac against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    t.equal(new MySha1Hmac(new Buffer(v.key, 'hex')).update(v.data, 'hex').digest('hex'), v.sha1)
    t.end()
  })
})

pbkdf2 example

pbkdf2 vectors taken from rfc6070 (also included in this repo)

var vectors = require('hash-test-vectors')
var tape = require('tape')
var MyPbkdf2 = require('./my-pbkdf2-implementation')

vectors.forEach(function (v, i) {
  tape('my-pbkdf2 against test vector ' + i, function (t) {
    //test in bash64 encoding + as a buffer
    var key = new MyPbkdf2(v.password, v.salt, v.iterations, v.length)
    t.equal(key.toString('hex')), v.sha1)
    t.end()
  })
})

License

MIT

hash-test-vectors's People

Contributors

dominictarr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.