How to use the sodium-native.crypto_sign_keypair 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 / minisign.js View on Github external
if (opts == null) opts = {}
  var PKcomment = opts.PKcomment || PKdComment
  var SKcomment = opts.SKcomment || SKdComment
  var sigAlgorithm = Buffer.from(opts.sigAlgorithm || 'Ed')
  var kdfAlgorithm = Buffer.from(opts.kdfAlgorithm || 'Sc')
  var cksumAlgorithm = Buffer.from(opts.cksumAlgorithm || 'B2')

  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)

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

  const kdfOpsLimit = sodium.crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE
  const kdfMemLimit = sodium.crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE
  var kdfLimits = Buffer.alloc(16)
  kdfLimits.writeUInt32LE(kdfOpsLimit, 0)
  kdfLimits.writeUInt32LE(kdfMemLimit, 8)

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

  var keynumData = Buffer.concat([keyID, secretKey, checkSum])
  sodium.sodium_mprotect_readwrite(pwd)
  sodium.crypto_pwhash_scryptsalsa208sha256(kdfOutput, pwd, kdfSalt, kdfOpsLimit, kdfMemLimit)
  sodium.sodium_memzero(pwd)
  sodium.sodium_mprotect_noaccess(pwd)
  var keynumSK = xor(kdfOutput, keynumData)
github chm-diederichs / minisign / minisignTool.js View on Github external
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)

  var keynumSK = xor(kdfOutput, keynumData)
  var algorithmInfo = Buffer.from(sigAlgorithm + kdfAlgorithm + cksumAlgorithm)
  var kdfLimits = Buffer.from(kdfOpsLimit.toString() + kdfMemLimit.toString())
  var SKinfo = Buffer.from(Buffer.concat([algorithmInfo, kdfSalt, kdfLimits, keynumSK]).toString('base64'))

  return {
    publicKey,
    keyID,
    fullComment,
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 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
  }
}