void SpindleTorus::Compute_BBox() { DBL r1, r2; if (mSpindleMode & NonSpindleVisible) { r1 = MinorRadius; r2 = MajorRadius + MinorRadius; Make_BBox(BBox, -r2, -r1, -r2, 2.0 * r2, 2.0 * r1, 2.0 * r2); Recompute_BBox(&BBox, Trans); } else { Precompute(); // make sure mSpindleTipYSqr is properly set if (mSpindleTipYSqr >= 0) { r1 = sqrt(mSpindleTipYSqr); r2 = MinorRadius - MajorRadius; Make_BBox(BBox, -r2, -r1, -r2, 2.0 * r2, 2.0 * r1, 2.0 * r2); Recompute_BBox(&BBox, Trans); } else { Make_BBox(BBox, -BOUND_HUGE/2.0, -BOUND_HUGE/2.0, -BOUND_HUGE/2.0, BOUND_HUGE, BOUND_HUGE, BOUND_HUGE); } } }
Camera::Camera(const Matrix<double>& K, const Matrix<double>& R, const Vector<double>& t, const Vector<double>& GP) { this->K_ = K; this->R_ = R; this->t_ = t; this->GP_ = GP; Precompute(); }
Camera::Camera(const char *filename, int central_flag) { int CamIntStart = 0; int CamIntEnd = 9; int CamRotStart = 12; int CamRotEnd = 21; int CamPosStart = 21; int CamPosEnd = 24; int GPStart = 24; int GPEnd = 28; Vector<double> completeData; if (central_flag == 1) { completeData.readTXT(filename, 28); //********************************************************* // Read in Camera inter parameter //********************************************************* K_.set_size(3, 3); for (int i = CamIntStart; i < CamIntEnd; i++) { K_.data()[i - CamIntStart] = completeData(i); } //********************************************************* // Read in Camera Rotation parameter //********************************************************* R_.set_size(3, 3); for (int i = CamRotStart; i < CamRotEnd; i++) { R_.data()[i - CamRotStart] = completeData(i); } //********************************************************* // Read in Camera Position parameter //********************************************************* t_.setSize(3); for (int i = CamPosStart; i < CamPosEnd; i++) { t_(i - CamPosStart) = completeData(i); } //********************************************************* // Read in Ground Plane Parameter //********************************************************* GP_.setSize(4); for (int i = GPStart; i < GPEnd; i++){ GP_(i - GPStart) = completeData(i); } GP_(3) = GP_(3) * (-1.0); } Precompute(); }
void InvertibleRWFunction::SavePrecomputation(BufferedTransformation &bt) const { if(!m_precompute) Precompute(); DERSequenceEncoder seq(bt); m_pre_2_9p.DEREncode(seq); m_pre_2_3q.DEREncode(seq); m_pre_q_p.DEREncode(seq); seq.MessageEnd(); }
// generate a random private key void InvertibleRWFunction::GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &alg) { int modulusSize = 2048; alg.GetIntValue("ModulusSize", modulusSize) || alg.GetIntValue("KeySize", modulusSize); if (modulusSize < 16) throw InvalidArgument("InvertibleRWFunction: specified modulus length is too small"); AlgorithmParameters primeParam = MakeParametersForTwoPrimesOfEqualSize(modulusSize); m_p.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 3)("Mod", 8))); m_q.GenerateRandom(rng, CombinedNameValuePairs(primeParam, MakeParameters("EquivalentTo", 7)("Mod", 8))); m_n = m_p * m_q; m_u = m_q.InverseMod(m_p); Precompute(); }
EcPrecomputation<EC2N>::EcPrecomputation(const EC2N &ecIn, const EC2N::Point &base, unsigned int maxExpBits, unsigned int storage) : ec(new EC2N(ecIn)), ep(NULL) { Precompute(base, maxExpBits, storage); }
// DJB's "RSA signatures and Rabin-Williams signatures..." (http://cr.yp.to/sigs/rwsota-20080131.pdf). Integer InvertibleRWFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &x) const { DoQuickSanityCheck(); if(!m_precompute) Precompute(); ModularArithmetic modn(m_n), modp(m_p), modq(m_q); Integer r, rInv; do { // Do this in a loop for people using small numbers for testing r.Randomize(rng, Integer::One(), m_n - Integer::One()); // Fix for CVE-2015-2141. Thanks to Evgeny Sidorov for reporting. // Squaring to satisfy Jacobi requirements suggested by Jean-Pierre Muench. r = modn.Square(r); rInv = modn.MultiplicativeInverse(r); } while (rInv.IsZero()); Integer re = modn.Square(r); re = modn.Multiply(re, x); // blind const Integer &h = re, &p = m_p, &q = m_q; Integer e, f; const Integer U = modq.Exponentiate(h, (q+1)/8); if(((modq.Exponentiate(U, 4) - h) % q).IsZero()) e = Integer::One(); else e = -1; const Integer eh = e*h, V = modp.Exponentiate(eh, (p-3)/8); if(((modp.Multiply(modp.Exponentiate(V, 4), modp.Exponentiate(eh, 2)) - eh) % p).IsZero()) f = Integer::One(); else f = 2; Integer W, X; #pragma omp parallel sections if(CRYPTOPP_RW_USE_OMP) { #pragma omp section { W = (f.IsUnit() ? U : modq.Multiply(m_pre_2_3q, U)); } #pragma omp section { const Integer t = modp.Multiply(modp.Exponentiate(V, 3), eh); X = (f.IsUnit() ? t : modp.Multiply(m_pre_2_9p, t)); } } const Integer Y = W + q * modp.Multiply(m_pre_q_p, (X - W)); // Signature Integer s = modn.Multiply(modn.Square(Y), rInv); CRYPTOPP_ASSERT((e * f * s.Squared()) % m_n == x); // IEEE P1363, Section 8.2.8 IFSP-RW, p.44 s = STDMIN(s, m_n - s); if (ApplyFunction(s) != x) // check throw Exception(Exception::OTHER_ERROR, "InvertibleRWFunction: computational error during private key operation"); return s; }
void InvertibleRWFunction::Initialize(const Integer &n, const Integer &p, const Integer &q, const Integer &u) { m_n = n; m_p = p; m_q = q; m_u = u; Precompute(); }