<commit_before>var bignum = require('bignum'),
    crypto = require('crypto');

var config = require('../config');

var UserError = require('./error').UserError;

var Signer = function ()
{
  if ("object" !== typeof config.rsa)
    throw UserError('Config error: config.rsa is not an object');

  if ("string" !== typeof config.rsa.d)
    throw UserError('Config.error: config.rsa.d is not a string');

  if ("string" !== typeof config.rsa.e)
    throw UserError('Config error: config.rsa.e is not a string');

  this.e = bignum(config.rsa.e, 16);
  this.d = bignum(config.rsa.d, 16);
  this.phi = bignum(config.rsa.phi, 16);
  this.n = bignum(config.rsa.n, 16);
};

// Full domain hash based on SHA512
function fdh(data, bytelen)
{
  if (typeof data === "string") {
    data = new Buffer(data, "utf8");
  }

  // Add hashing rounds until we exceed desired length in bits
  var counter = 0, output = new Buffer(0);
  while (output.length < bytelen) {
    var buf = Buffer.concat([new Buffer([
      counter >>> 24,
      counter >>> 16,
      counter >>>  8,
      counter >>>  0
    ]), data]);
    var hash = crypto.createHash('sha512').update(buf).digest();
    output = Buffer.concat([output, hash]);
    counter++;
  }

  // Truncate to desired length
  output = output.slice(0, bytelen);

  return output;
}

Signer.prototype.sign = function (infoData, signreq)
{
  var info = this.verifyPublicInfo(infoData);

  // XXX Do something with the username - check if we know it, rate-limit etc.

  // Transform the unblinded portion of the message to the correct length using
  // a full domain hash.
  var publen = Math.ceil(Math.min((7+this.n.bitLength()) >>> 3, 256)/8);
  var vbuf = fdh(infoData, publen);
  // Last bit must be set
  vbuf[vbuf.length-1] |= 1;<commit_msg>log user info on sign<commit_after>var bignum = require('bignum'),
    crypto = require('crypto'),
    log    = require('./lib/log').winston;

var config = require('../config');

var UserError = require('./error').UserError;

var Signer = function ()
{
  if ("object" !== typeof config.rsa)
    throw UserError('Config error: config.rsa is not an object');

  if ("string" !== typeof config.rsa.d)
    throw UserError('Config.error: config.rsa.d is not a string');

  if ("string" !== typeof config.rsa.e)
    throw UserError('Config error: config.rsa.e is not a string');

  this.e = bignum(config.rsa.e, 16);
  this.d = bignum(config.rsa.d, 16);
  this.phi = bignum(config.rsa.phi, 16);
  this.n = bignum(config.rsa.n, 16);
};

// Full domain hash based on SHA512
function fdh(data, bytelen)
{
  if (typeof data === "string") {
    data = new Buffer(data, "utf8");
  }

  // Add hashing rounds until we exceed desired length in bits
  var counter = 0, output = new Buffer(0);
  while (output.length < bytelen) {
    var buf = Buffer.concat([new Buffer([
      counter >>> 24,
      counter >>> 16,
      counter >>>  8,
      counter >>>  0
    ]), data]);
    var hash = crypto.createHash('sha512').update(buf).digest();
    output = Buffer.concat([output, hash]);
    counter++;
  }

  // Truncate to desired length
  output = output.slice(0, bytelen);

  return output;
}

Signer.prototype.sign = function (infoData, signreq)
{
  var info = this.verifyPublicInfo(infoData);

  log.info("Signer.sign", info);

  // Transform the unblinded portion of the message to the correct length using
  // a full domain hash.
  var publen = Math.ceil(Math.min((7+this.n.bitLength()) >>> 3, 256)/8);
  var vbuf = fdh(infoData, publen);
  // Last bit must be set
  vbuf[vbuf.length-1] |= 1;
{'fraction_non_alphanumeric': 0.1579983131852685, 'fraction_numerical': 0.017992690469496767, 'mean_word_length': 3.2407628128724673, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5579970', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1185, 'n_words': 350}