How to use the sodium-native.crypto_sign_SECRETKEYBYTES function in sodium-native

To help you get started, we’ve selected a few sodium-native examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chm-diederichs / minisign / test / extract-secret-key.js View on Github external
fs.readFile('./test/fixtures/no-string.pub', function (err, PK) {
      t.error(err)
      var publicKeyID = minisign.parsePubKey(PK).keyID

      t.equal(SKdetails.secretKey.byteLength, sodium.crypto_sign_SECRETKEYBYTES)
      t.deepEqual(SKdetails.keyID, publicKeyID)
      t.equal(SKdetails.signatureAlgorithm, 'Ed')
      t.end()
    })
  })
github chm-diederichs / minisign / test / extract-secret-key.js View on Github external
fs.readFile('./test/fixtures/emoji-string.pub', function (err, PK) {
      t.error(err)
      var publicKeyID = minisign.parsePubKey(PK).keyID

      t.equal(SKdetails.secretKey.byteLength, sodium.crypto_sign_SECRETKEYBYTES)
      t.deepEqual(SKdetails.keyID, publicKeyID)
      t.equal(SKdetails.signatureAlgorithm, 'Ed')
      t.end()
    })
  })
github emilbayes / rendezvous-point / index.js View on Github external
assert(remoteKey.byteLength === sodium.crypto_kx_PUBLICKEYBYTES)
  assert(message.byteLength <= 1000)

  var self = this
  var rendevousPoint = Buffer.allocUnsafe(sodium.crypto_kx_SESSIONKEYBYTES)

  sodium.crypto_kx_server_session_keys(
    rendevousPoint,
    null,
    self.keypair.publicKey,
    self.keypair.secretKey,
    remoteKey
  )

  var discoveryPk = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES)
  var discoverySk = sodium.sodium_malloc(sodium.crypto_sign_SECRETKEYBYTES)
  sodium.crypto_sign_seed_keypair(discoveryPk, discoverySk, rendevousPoint)

  self.dht.put({
    v: message,
    k: discoveryPk,
    seq: 0,
    sign: function (buf) {
      var sig = Buffer.alloc(sodium.crypto_sign_BYTES)
      sodium.crypto_sign_detached(sig, buf, discoverySk)
      return sig
    }
  }, cb)
}
github chm-diederichs / minisign / minisign.js View on Github external
function extractSecretKey (pwd, parsedSK) {
  var kdfOutput = Buffer.alloc(104)
  var keynumInfo
  var sumCheck = Buffer.alloc(sodium.crypto_generichash_BYTES)
  var opsLimit = parsedSK.kdfOpsLimit
  var memLimit = parsedSK.kdfMemLimit
  var salt = parsedSK.kdfSalt

  sodium.sodium_mprotect_readwrite(pwd)
  sodium.crypto_pwhash_scryptsalsa208sha256(kdfOutput, pwd, salt, opsLimit, memLimit)
  sodium.sodium_memzero(pwd)
  sodium.sodium_mprotect_noaccess(pwd)

  const secretKey = sodium.sodium_malloc(sodium.crypto_sign_SECRETKEYBYTES)
  keynumInfo = xor(kdfOutput, parsedSK.keynumSK)
  const keyID = keynumInfo.subarray(0, 8)
  secretKey.fill(keynumInfo.subarray(8, 72))
  const checkSum = keynumInfo.subarray(72)
  const signatureAlgorithm = parsedSK.signatureAlgorithm.toString()

  var sumCheckData = Buffer.concat([parsedSK.signatureAlgorithm, keyID, secretKey])
  sodium.sodium_mprotect_noaccess(secretKey)

  sodium.crypto_generichash(sumCheck, sumCheckData)
  assert(sumCheck.equals(checkSum), 'invalid check sum')

  return {
    keyID,
    secretKey,
    sumCheck,
github mafintosh / sodium-signatures / sodium.js View on Github external
exports.keyPair = function (seed) {
  var publicKey = new Buffer(sodium.crypto_sign_PUBLICKEYBYTES)
  var secretKey = new Buffer(sodium.crypto_sign_SECRETKEYBYTES)

  if (seed) sodium.crypto_sign_seed_keypair(publicKey, secretKey, seed)
  else sodium.crypto_sign_keypair(publicKey, secretKey)

  return {
    publicKey: publicKey,
    secretKey: secretKey
  }
}
github AraiEzzra / DDKCORE / shared / util / ed.ts View on Github external
public makeKeyPair(hash: Buffer): IKeyPair {
        const keyPair: IKeyPair = {
            publicKey: Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES),
            privateKey: Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES)
        };

        sodium.crypto_sign_seed_keypair(keyPair.publicKey, keyPair.privateKey, hash);
        return keyPair;
    }
github chm-diederichs / minisign / minisignTool.js View on Github external
function keypairGen (comment, pwd, sigAlgorithm = 'Ed', kdfAlgorithm = 'Sc', cksumAlgorithm = 'B2') {
  var keyID = Buffer.alloc(8)
  var kdfSalt = Buffer.alloc(32)
  var kdfOutput = Buffer.alloc(104)

  var publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES)
  var secretKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES)
  var checkSum = Buffer.alloc(sodium.crypto_generichash_BYTES)

  var fullComment = Buffer.from('untrusted comment: ' + comment + '\n')

  const kdfOpsLimit = sodium.crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE
  const kdfMemLimit = sodium.crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE

  sodium.randombytes_buf(keyID)
  sodium.randombytes_buf(kdfSalt)
  sodium.crypto_sign_keypair(publicKey, secretKey)

  var checksumData = Buffer.concat([Buffer.from(sigAlgorithm), keyID, secretKey])
  sodium.crypto_generichash(checkSum, checksumData)

  var keynumData = Buffer.concat([keyID, secretKey, checkSum])
  sodium.crypto_pwhash_scryptsalsa208sha256(kdfOutput, Buffer.from(pwd), kdfSalt, kdfOpsLimit, kdfMemLimit)
github automerge / hypermerge / src / Crypto.ts View on Github external
export function signingKeyPair(): sodium.SigningKeyPair {
  const publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES) as sodium.PublicSigningKey
  const secretKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES) as sodium.SecretSigningKey
  sodium.crypto_sign_keypair(publicKey, secretKey)
  return { publicKey, secretKey }
}
github LiskHQ / lisk-sdk / framework / src / modules / chain / helpers / ed.js View on Github external
ed.makeKeypair = function(hash) {
	const publicKey = Buffer.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
	const privateKey = Buffer.alloc(sodium.crypto_sign_SECRETKEYBYTES);
	sodium.crypto_sign_seed_keypair(publicKey, privateKey, hash);

	return {
		publicKey,
		privateKey,
	};
};