Skip to content

Instantly share code, notes, and snippets.

@justmoon
Created May 21, 2016 17:55
Show Gist options
  • Save justmoon/3566a1108685706f3e1a8e5e6028eb9d to your computer and use it in GitHub Desktop.
Save justmoon/3566a1108685706f3e1a8e5e6028eb9d to your computer and use it in GitHub Desktop.
Quick and dirty tool to convert RSA-PSS test cases using OpenSSL
// Used to create test vectors for five-bells-condition
// https://github.com/interledger/five-bells-condition
'use strict'
const fs = require('fs')
const execSync = require('child_process').execSync
const Rsa = require('./src/crypto/rsa')
const pem = require('./src/util/pem')
const sha1Data = require('./test/data/rsa/sha1.json')
const HASH_ALGORITHM = 'sha256'
const rsa = new Rsa({
hashAlgorithm: HASH_ALGORITHM
})
const outputData = sha1Data.map((group) => {
fs.writeFileSync('priv.pem', group.privateKey)
group.cases = group.cases.map((caseSpec) => {
const message = new Buffer(caseSpec.message, 'hex')
fs.writeFileSync('tmp.data', message)
execSync('sh -c "openssl dgst -' + HASH_ALGORITHM + ' -sigopt rsa_padding_mode:pss -sigopt rsa_pss_saltlen:-1 -sign priv.pem -out tmp.data.sig tmp.data"')
const signature = fs.readFileSync('tmp.data.sig')
caseSpec.signature = signature.toString('hex')
rsa.verify(pem.modulusFromPrivateKey(group.privateKey), message, signature)
caseSpec.salt = rsa.pss.lastSalt.toString('hex')
return caseSpec
})
return group
})
console.log(JSON.stringify(outputData, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment