/** * Generates a new signature key pair. Runs in a single thread. * @return a key pair */ public SignatureKeyPair generateKeyPairSingleThread() { SignaturePrivateKey priv = new SignaturePrivateKey(param); SignaturePublicKey pub = null; Basis pubBasis = generateBoundedBasis(); pub = new SignaturePublicKey(pubBasis.h, param.q); pubBasis.h = null; // remove the public polynomial h from the private key priv.add(pubBasis); for (int k = param.B; k > 0; k--) { Basis basis = generateBoundedBasis(); priv.add(basis); } SignatureKeyPair kp = new SignatureKeyPair(priv, pub); return(kp); }
/** * Generates a new signature key pair. Uses up to <code>B+1</code> threads * if multiple processors are available. * @return a key pair */ public SignatureKeyPair generateKeyPair() { int processors = Environment.ProcessorCount; SignaturePrivateKey priv = new SignaturePrivateKey(param); int B = param.B; //if (processors == 1) // generate all B+1 bases in the current thread for (int k = B; k >= 0; k--) { priv.add(generateBoundedBasis()); } /*else { * List<Future<Basis>> bases = new ArrayList<Future<Basis>>(); * * // start up to processors-1 new threads and generate B bases * int numThreads = Math.min(B, processors-1); * if (numThreads > 0) { * ExecutorService executor = Executors.newFixedThreadPool(numThreads); * for (int k=B-1; k>=0; k--) * bases.add(executor.submit(new BasisGenerationTask())); * executor.shutdown(); * } * * // generate the remaining basis in the current thread * Basis basis0 = generateBoundedBasis(); * * // build the private key * for (Future<Basis> basis: bases) * try { * priv.add(basis.get()); * } catch (Exception e) { * throw new NtruException(e); * } * priv.add(basis0); * }*/ int q = param.q; SignaturePublicKey pub = new SignaturePublicKey(priv.getBasis(0).h, q); priv.getBasis(0).h = null; // remove the public polynomial h from the private key SignatureKeyPair kp = new SignatureKeyPair(priv, pub); return(kp); }
/** * Generates a new signature key pair. Uses up to <code>B+1</code> threads * if multiple processors are available. * @return a key pair */ public SignatureKeyPair generateKeyPair() { int processors = Environment.ProcessorCount; SignaturePrivateKey priv = new SignaturePrivateKey(param); int B = param.B; //if (processors == 1) // generate all B+1 bases in the current thread for (int k = B; k >= 0; k--) priv.add(generateBoundedBasis()); /*else { List<Future<Basis>> bases = new ArrayList<Future<Basis>>(); // start up to processors-1 new threads and generate B bases int numThreads = Math.min(B, processors-1); if (numThreads > 0) { ExecutorService executor = Executors.newFixedThreadPool(numThreads); for (int k=B-1; k>=0; k--) bases.add(executor.submit(new BasisGenerationTask())); executor.shutdown(); } // generate the remaining basis in the current thread Basis basis0 = generateBoundedBasis(); // build the private key for (Future<Basis> basis: bases) try { priv.add(basis.get()); } catch (Exception e) { throw new NtruException(e); } priv.add(basis0); }*/ int q = param.q; SignaturePublicKey pub = new SignaturePublicKey(priv.getBasis(0).h, q); priv.getBasis(0).h = null; // remove the public polynomial h from the private key SignatureKeyPair kp = new SignatureKeyPair(priv, pub); return kp; }
/** * Generates a new signature key pair. Runs in a single thread. * @return a key pair */ public SignatureKeyPair generateKeyPairSingleThread() { SignaturePrivateKey priv = new SignaturePrivateKey(param); SignaturePublicKey pub = null; Basis pubBasis = generateBoundedBasis(); pub = new SignaturePublicKey(pubBasis.h, param.q); pubBasis.h = null; // remove the public polynomial h from the private key priv.add(pubBasis); for (int k = param.B; k > 0; k--) { Basis basis = generateBoundedBasis(); priv.add(basis); } SignatureKeyPair kp = new SignatureKeyPair(priv, pub); return kp; }