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

cubehash-wasm

v1.0.1

Published

A port of CubeHash to WASM.

Downloads

6

Readme

cubehash-wasm

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

this library is a port of my js cubehash library to assemblyscript. i believed that it would provide for higher optimization (which i was wrong about). this took hours of work, and frankly, i regret it deeply. it runs 3 times slower than the pure JS version on 1MB arrays, and cannot run at all on 500MB arrays. if you understand this and are still curious, feel free to read the below.

installation

browser:

  • there is NO support for the browser. you will have to hack your own wrapper around the .wasm file. if you want to build the WASM file, here are some things you should know:
    • you should 100% read the assemblyscript docs before you go into this
    • the exports are as follows:
export function hash(m: Uint8Array, i: u32, r: u32, b: u32, f: u32, h: u32): Uint8Array // this is the hash function's signature.
export const Uint8Array_ID = idof<Uint8Array>(); // you need this if you want to hash anything!
  • the wasm file is available in the git repo for your convenience.

node:

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

usage

the module.exports of this library is an async function aptly called load. when load is called, it will load in the wasm library and then return 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. NOTE THAT NO INPUT CHECKING IS DONE ON THE PARAMETERS AND YOU SHOULD VERIFY THAT THEY ARE CORRECT YOURSELF. ALSO, UNLIKE THE JS IMPLEMENTATION, THE INITIALIZATION VECTOR IS NOT PRECOMPUTED. 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.

in other words, the class provides the exact same interface as the pure-JS CubeHash implementation.

reference usage:

async function main() {
    // require cubehash
    const CubeHash = await (require("cubehash-wasm"))();
    // 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"));
}
main();

testing

first, make sure any dependencies are installed with npm i. then, run npm test to run the test suite (this will also compile the WASM). the test suite includes a speedtest and verifies the output based on certain test vectors (found here).

code

you honestly shouldn't be implementing cubehash in assemblyscript (the performance gets worse), but if you want to, there are some comments around in the code. i recommend using my js implementation (linked in the introduction) for reference instead.