Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JCThePants committed Apr 13, 2020
0 parents commit 6f154cc
Show file tree
Hide file tree
Showing 31 changed files with 11,966 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Build & Test Package
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
linux-node10:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test

linux-node12:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test

windows-node10:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test

windows-node12:
runs-on: windows-2016
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm test
17 changes: 17 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Publish Package
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '10.x'
registry-url: 'https://npm.pkg.github.com'
- run: npm install
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.vscode/
.idea/
*.iml
node_modules/
build/
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
hasher-phi1
===========

This is a Node module for simple hashing of the phi1 (phi1612) algorithm.
Native code is adapted from [LUX](https://github.com/Lux-core/lux).

This module has been developed and tested on [Node v10.16.3](https://nodejs.org/) and [Ubuntu 16.04](http://releases.ubuntu.com/16.04/)

## Install ##
__Install as Dependency in NodeJS Project__
```bash
# Install from Github git package

sudo apt-get install build-essential
npm install mintpond/hasher-phi1 --save
```
-or-
```bash
# Install from Github NPM repository

sudo apt-get install build-essential
npm config set @mintpond:registry https://npm.pkg.github.com/mintpond
npm config set //npm.pkg.github.com/:_authToken <MY_GITHUB_AUTH_TOKEN>

npm install @mintpond/[email protected] --save
```

__Install & Test__
```bash
# Install nodejs v10
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install nodejs -y

# Download hasher-phi1
git clone https://github.com/MintPond/hasher-phi1

# build
cd hasher-phi1
sudo apt-get install build-essential
npm install
npm test
```

## Usage ##
__Hash__
```js
const phi1 = require('hasher-phi1');

/**
* Hash the data in a Buffer and return the result in a new Buffer.
*
* @param input {Buffer} The data to hash.
* @returns {Buffer}
*/
const result = phi1.phi1612(input);
```
26 changes: 26 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"targets": [
{
"target_name": "hasherphi1",
"sources": [
"hasherphi1.cc",
"phi1612.c",
"lyra2/lyra2.c",
"lyra2/sponge.c",
"sha3/aes_helper.c",
"sha3/gost_streebog.c",
"sha3/sph_cubehash.c",
"sha3/sph_echo.c",
"sha3/sph_fugue.c",
"sha3/sph_jh.c",
"sha3/sph_skein.c"
],
"include_dirs": [
"<!(node -e \"require('nan')\")"
],
"cflags_cc": [
"-std=c++0x"
]
}
]
}
42 changes: 42 additions & 0 deletions hasherphi1.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <node.h>
#include <node_buffer.h>
#include <v8.h>
#include <stdint.h>
#include "nan.h"

extern "C" {
#include "phi1612.h"
}

#define THROW_ERROR_EXCEPTION(x) Nan::ThrowError(x)
#define THROW_ERROR_EXCEPTION_WITH_STATUS_CODE(x, y) NanThrowError(x, y)

using namespace node;
using namespace v8;

NAN_METHOD(phi1612) {

if (info.Length() < 1)
return THROW_ERROR_EXCEPTION("You must provide one argument.");

Local<Object> target = Nan::To<Object>(info[0]).ToLocalChecked();

if(!Buffer::HasInstance(target))
return THROW_ERROR_EXCEPTION("Argument should be a buffer object.");

char* input = Buffer::Data(target);
char* output = (char*) malloc(sizeof(char) * 32);

uint32_t input_len = Buffer::Length(target);

phi1612_hash(input, output, input_len);

info.GetReturnValue().Set(Nan::NewBuffer(output, 32).ToLocalChecked());
}


NAN_MODULE_INIT(init) {
Nan::Set(target, Nan::New("phi1612").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(phi1612)).ToLocalChecked());
}

NODE_MODULE(hasherphi1, init)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('bindings')('hasherphi1.node');
Loading

0 comments on commit 6f154cc

Please sign in to comment.