npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-cubehash

v1.0.4

Published

A pure JavaScript implementation of CubeHash.

Downloads

14

Readme

cubehash

DISCLAIMER

THIS LIBRARY IS MEANT AS A REFERENCE IMPLEMENTATION. A REFERENCE IMPLEMENTATION. I AM NOT AN EXPERIENCED CRYPTOGRAPHER AND I CANNOT GUARANTEE THAT THIS LIBRARY IS SECURE. DO NOT USE THIS FOR ANYTHING IMPORTANT! YOU HAVE BEEN WARNED.

introduction

cubehash is an ARX cryptographic hash function by DJB, which was submitted to the SHA-3 competition but did not make it to the finalists. i found it rather interesting and wanted to write an implementation of it. currently, the cryptanalysis seems rather promising (although there hasn't been much since the early 2010s). cubehash is simple to implement and has some nice features, like being able to change the number of rounds, size of input blocks, digest length, etc. however, there seems to be no good implementation of cubehash in JS. this library is meant as a reference for future JS implementations of cubehash. this implementation has no dependencies and is well commented for future reference.

installation

browser:

  • put something along the lines of <script src="https://cdn.jsdelivr.net/npm/node-cubehash/index.js"> in your code. window.CubeHash will be set to the CubeHash class.

node:

  • npm i --save node-cubehash will install cubehash for you.

usage

the module.exports of this library (or window.CubeHash if you include index.js in the browser) is a class called CubeHash. its methods are provided below for reference.

  • constructor() - sets the parameters for CubeHash512, or CubeHash16+16/32+32-512, and precomputes the initialization vector. this is a sane default and no further configuration is required after creating the object.
  • constructor(Number i, Number r, Number b, Number f, Number h) - sets the parameters for CubeHashi+r/b+f-h and precomputes the initialization vector (to know what this means, click here). NOTE THAT NO INPUT CHECKING IS DONE ON THE PARAMETERS AND YOU SHOULD VERIFY THAT THEY ARE CORRECT YOURSELF. i should be a member of the set {1,2,3,...}, r should be a member of the set {1,2,3,...}, b should be a member of the set {1,2,3,...,128}, f should be a member of the set {1,2,3,...}, and h should be a member of the set {8,16,24,...,512}.
  • Uint8Array hash(Uint8Array m) - returns the hash for m with the parameters specified in the constructor.
  • Uint8Array mac(Uint8Array message, Uint8Array key) - returns the CubeMAC with key key and message message with the parameters specified in the constructor. the key must be 512 bits (64 bytes). for more information, click here.

reference usage:

// require cubehash
const CubeHash = require("node-cubehash");
// create a new cubehash object. cubehash512 by default.
const cubehash512 = new CubeHash();

// create a message uint8array
let message = new Uint8Array(Buffer.from("cubehash"));
// compute our hash
let rawHash = cubehash512.hash(message);
// log our hash as base64
console.log(Buffer.from(rawHash).toString("base64"));

testing

run npm test or node test to run the test suite. the test suite includes a speedtest and verifies the output based on certain test vectors (found here).

code

most implementations of cubehash seem to be rather scarcely commented. this implementation is well commented. for further reference, read the specification.