🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

libsodium-neon

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsodium-neon - npm Package Compare versions

Comparing version

to
2.0.1

.travis.yml

111

lib/index.js

@@ -22,30 +22,9 @@ /*

const os = require('os');
let sodiumneon;
var sodiumneon = require('../native');
switch(os.type()) {
case 'Darwin':
sodiumneon = require('../dist/macos/x64');
break;
case 'Linux':
sodiumneon = require('../dist/linux/x64');
break;
default:
throw new Error(`Your operating system (${os.type()}) is not supported.`);
}
const strToUint8Array = (obj) => {
if (obj instanceof Uint8Array) {
return obj;
} else if (typeof obj === 'string') {
if (typeof TextEncoder === 'function') {
return new TextEncoder('utf-8').encode(obj);
}
obj = unescape(encodeURIComponent(obj));
const arr = new Uint8Array(obj.length);
for (let i = 0; i < obj.length; i++) {
arr[i] = obj.charCodeAt(i);
}
return arr;
var objToBuffer = function(obj) {
if (typeof Buffer.from === 'function') {
return new Uint8Array(Buffer.from(obj));
} else {
return new Uint8Array(new Buffer(obj));
}

@@ -56,29 +35,17 @@ };

crypto_auth_BYTES: 32,
crypto_auth_hmacsha256 (message, key) {
message = strToUint8Array(message);
key = strToUint8Array(key);
crypto_auth_hmacsha256: function(message, key) {
message = objToBuffer(message);
key = objToBuffer(key);
return Uint8Array.from(sodiumneon.crypto_auth_hmacsha256(message, key));
return new Uint8Array(sodiumneon.crypto_auth_hmacsha256(message, key));
},
crypto_auth_hmacsha256_BYTES: 32,
crypto_auth_hmacsha256_KEYBYTES: 32,
crypto_auth_hmacsha256_verify (tag, message, key) {
tag = strToUint8Array(tag);
message = strToUint8Array(message);
key = strToUint8Array(key);
return sodiumneon.crypto_auth_hmacsha256_verify(tag, message, key);
},
crypto_auth_KEYBYTES: 32,
crypto_hash_BYTES: 64,
crypto_hash_sha256 (message) {
message = strToUint8Array(message);
return Uint8Array.from(sodiumneon.crypto_hash_sha256(message));
},
crypto_scalarmult (secretKey, publicKey) {
secretKey = strToUint8Array(secretKey);
publicKey = strToUint8Array(publicKey);
secretKey = objToBuffer(secretKey);
publicKey = objToBuffer(publicKey);
return Uint8Array.from(sodiumneon.crypto_scalarmult(secretKey, publicKey));
return new Uint8Array(sodiumneon.crypto_scalarmult(secretKey, publicKey));
},

@@ -88,25 +55,25 @@ crypto_scalarmult_BYTES: 32,

crypto_sign_BYTES: 64,
crypto_sign_detached (message, secretKey) {
message = strToUint8Array(message);
secretKey = strToUint8Array(secretKey);
crypto_sign_detached: function(message, secretKey) {
message = objToBuffer(message);
secretKey = objToBuffer(secretKey);
return Uint8Array.from(sodiumneon.crypto_sign_detached(message, secretKey));
return new Uint8Array(sodiumneon.crypto_sign_detached(message, secretKey));
},
crypto_sign_ed25519_pk_to_curve25519 (publicKey) {
publicKey = strToUint8Array(publicKey);
crypto_sign_ed25519_pk_to_curve25519: function(publicKey) {
publicKey = objToBuffer(publicKey);
return Uint8Array.from(sodiumneon.crypto_sign_ed25519_pk_to_curve25519(publicKey));
return new Uint8Array(sodiumneon.crypto_sign_ed25519_pk_to_curve25519(publicKey));
},
crypto_sign_ed25519_sk_to_curve25519 (secretKey) {
secretKey = strToUint8Array(secretKey);
crypto_sign_ed25519_sk_to_curve25519: function(secretKey) {
secretKey = objToBuffer(secretKey);
return Uint8Array.from(sodiumneon.crypto_sign_ed25519_sk_to_curve25519(secretKey));
return new Uint8Array(sodiumneon.crypto_sign_ed25519_sk_to_curve25519(secretKey));
},
crypto_sign_keypair () {
const { publicKeyBuffer, privateKeyBuffer, keyType } = sodiumneon.crypto_sign_keypair();
crypto_sign_keypair: function() {
var keyPair = sodiumneon.crypto_sign_keypair();
return {
publicKey: Uint8Array.from(publicKeyBuffer),
privateKey: Uint8Array.from(privateKeyBuffer),
keyType
publicKey: new Uint8Array(keyPair.publicKeyBuffer),
privateKey: new Uint8Array(keyPair.privateKeyBuffer),
keyType: keyPair.keyType
};

@@ -117,23 +84,9 @@ },

crypto_sign_SEEDBYTES: 32,
crypto_sign_verify_detached (signature, message, publicKey) {
signature = strToUint8Array(signature);
message = strToUint8Array(message);
publicKey = strToUint8Array(publicKey);
crypto_sign_verify_detached: function(signature, message, publicKey) {
signature = objToBuffer(signature);
message = objToBuffer(message);
publicKey = objToBuffer(publicKey);
return sodiumneon.crypto_sign_verify_detached(signature, message, publicKey);
},
crypto_stream_chacha20_KEYBYTES: 32,
crypto_stream_chacha20_NONCEBYTES: 8,
crypto_stream_chacha20_xor (message, nonce, key, outputFormat) {
message = strToUint8Array(message);
nonce = strToUint8Array(nonce);
key = strToUint8Array(key);
const stream = sodiumneon.crypto_stream_chacha20_xor(message, nonce, key);
if (outputFormat === 'uint8array') {
return Uint8Array.from(stream);
}
return stream;
}
};
{
"devDependencies": {
"jasmine": "2.5.3",
"libsodium-wrappers-sumo": "0.4.9",
"neon-cli": "0.1.13"

@@ -10,5 +12,7 @@ },

"scripts": {
"build": "neon build"
"build": "neon build",
"postinstall": "npm run build",
"test": "jasmine test"
},
"version": "1.0.1"
"version": "2.0.1"
}

@@ -32,3 +32,3 @@ -----

- [Node.js](https://nodejs.org/)
- [rustup](https://rustup.rs/)
- Rust (use [rustup](https://rustup.rs/))
- [Neon](https://github.com/neon-bindings/neon)

@@ -45,3 +45,3 @@

And build the project by running:
Afterwards the project will be built. For re-building run:

@@ -52,9 +52,6 @@ ```bash

Now move the build file from `native/` to the
corresponding `dist/` directory.
To test it with node, run:
```bash
node -e "console.log(require('./').crypto_sign_keypair());"
npm test
```

@@ -65,15 +62,14 @@

System specs: `macOS 10.12 @ 2.6 GHz Intel Core i7, 16 GB RAM`
|**Function** | **ops/sec** | **ops/sec** | **times faster** |
|:---------------------------------------|---------------:|-----------------:|-----------------:|
| | `libsodium.js` | `libsodium-neon` | |
| `crypto_auth_hmacsha256` |   65,364 | **72,274** |   1.11 |
| `crypto_auth_hmacsha256_verify` |   73,563 | **244,108** | 3.32 |
| `crypto_hash_sha256` | **152,876** | 81,748 |   -1.87 |
| `crypto_scalarmult` |   88 | **12,474** | 141.75 |
| `crypto_sign_detached` | 259 | **13,925** |   53.76 |
| `crypto_sign_ed25519_pk_to_curve25519` | 616 | **34,522** |   56.04 |
| `crypto_sign_ed25519_sk_to_curve25519` | 13,765 | **91,019** |   6.61 |
| `crypto_sign_keypair` |   286 | **11,804** |   41.27 |
| `crypto_stream_chacha20_xor` | **262,468** | 105,043 | -2.50 |
| `crypto_auth_hmacsha256` |   51,156 | **55,562** |   1.09 |
| `crypto_scalarmult` |   86 | **6,129** | 70.80 |
| `crypto_sign_detached` | 251 | **6,277** |   25.01 |
| `crypto_sign_ed25519_pk_to_curve25519` | 596 | **21,030** |   35.29 |
| `crypto_sign_ed25519_sk_to_curve25519` | 13,390 | **90,650** |   6.77 |
| `crypto_sign_keypair` |   276 | **6,602** |   23.92 |
| | | | |
| **Average** | **63,254** | **74,102** | **1.17** |
| **Average** | 10,959 | **31,042** | 2.83 |

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet