/** * \todo make this general for all mesh treatments. For now, since this is only * used for MoC, we wil just hard-code it to use PLANE treatment. */ ArrayB3 TransportSweeper::pin_powers() const { assert(n_reg_ == (int)core_mesh_->n_reg(MeshTreatment::PLANE)); ArrayB3 powers(core_mesh_->subplane().size(), core_mesh_->ny(), core_mesh_->nx()); powers = 0.0; // This isnt the most efficient way to do this, memory-wise, but its // quick and simple. Calculate volume x flux x kappa-fission for all // flat source regions, then reduce to the pin mesh. ArrayB1 fsr_pow(n_reg_); fsr_pow = 0.0; int ixsr = 0; for (const auto &xsr : *xs_mesh_) { for (int ig = 0; ig < n_group_; ig++) { for (auto ireg : xsr.reg()) { fsr_pow(ireg) += flux_(ireg, ig) * xsr.xsmacf(ig) * vol_[ireg]; } } ixsr++; } int ireg = 0; real_t tot_pow = 0.0; int iz = 0; for (int iplane = 0; iplane < (int)core_mesh_->subplane().size(); ++iplane) { auto stt = core_mesh_->begin(iz); auto stp = core_mesh_->end(iz); int ipin = 0; for (auto it = stt; it != stp; ++it) { const PinMesh &pm = (*it)->mesh(); Position pos = core_mesh_->pin_position(ipin); pos.z = iplane; for (int ir = 0; ir < pm.n_reg(); ir++) { tot_pow += fsr_pow(ireg); powers(iplane, pos.y, pos.x) += fsr_pow(ireg); ireg++; } ipin++; } iz += core_mesh_->subplane()[iplane]; } // Normalize! tot_pow = core_mesh_->n_fuel_2d() / tot_pow; for (auto &v : powers) { v *= tot_pow; } return powers; }
//--------------------------------------------------------------------- Vector3 SimpleSpline::interpolate(unsigned int fromIndex, Real t) { // Bounds check assert (fromIndex >= 0 && fromIndex < mPoints.size() && "fromIndex out of bounds"); if ((fromIndex + 1) == mPoints.size()) { // Duff request, cannot blend to nothing // Just return source return mPoints[fromIndex]; } // Fast special cases if (t == 0.0f) { return mPoints[fromIndex]; } else if(t == 1.0f) { return mPoints[fromIndex + 1]; } // Real interpolation // Form a vector of powers of t Real t2, t3; t2 = t * t; t3 = t2 * t; Vector4 powers(t3, t2, t, 1); // Algorithm is ret = powers * mCoeffs * Matrix4(point1, point2, tangent1, tangent2) Vector3& point1 = mPoints[fromIndex]; Vector3& point2 = mPoints[fromIndex+1]; Vector3& tan1 = mTangents[fromIndex]; Vector3& tan2 = mTangents[fromIndex+1]; Matrix4 pt; pt[0][0] = point1.x; pt[0][1] = point1.y; pt[0][2] = point1.z; pt[0][3] = 1.0f; pt[1][0] = point2.x; pt[1][1] = point2.y; pt[1][2] = point2.z; pt[1][3] = 1.0f; pt[2][0] = tan1.x; pt[2][1] = tan1.y; pt[2][2] = tan1.z; pt[2][3] = 1.0f; pt[3][0] = tan2.x; pt[3][1] = tan2.y; pt[3][2] = tan2.z; pt[3][3] = 1.0f; Vector4 ret = powers * mCoeffs * pt; return Vector3(ret.x, ret.y, ret.z); }
shared_ptr<Distribution1Df> ComputeLightPowerDistribution( const vector<shared_ptr<Light> >& lights, float sceneRadius ) { vector<float> powers(lights.size()); for(uint32_t i = 0; i < lights.size(); i++) powers[i] = lights[i]->Power(sceneRadius).Average(); shared_ptr<Distribution1Df> dist = shared_ptr<Distribution1Df>(new Distribution1Df(&powers[0], (uint32_t)powers.size())); return dist; }
Polynomial Polynomial::CoordinateMonomial(const Index numVars, const Index i, const Power p) { if (!(numVars > 0)) throw PolynomialIndexError(); if (!isNonnegativePower(p)) throw PolynomialValueError(); MapPowers powers(numVars); powers.setPower(i, p); return Polynomial(powers); }
Chroma::spd Chroma::blackbody(float temp, std::vector<float> wavelengths) { const float h = 6.62606957e-34; /* Planck's constant */ const float c = 299792458; /* speed of light */ const float k = 1.3806488e-23; /* Boltzmann's constant */ auto I = [&h, &c, &k, &temp](float wavelength) { float nm = wavelength * 1e-9; return ((2*M_PI*h*(c*c))/(powf(nm,5)))*(1.0/(expf((h*c/nm)/(k*temp))-1.0)); }; std::vector<float> powers(wavelengths.size()); std::transform(wavelengths.begin(), wavelengths.end(), powers.begin(), I); return {wavelengths, powers}; }
CVector3 CSplineInterpolatorVector3::intepolate(S32 index, F32 t){ if ((index + 1) == nodes.size()){ return nodes[index]; } if (t == 0.0f){ return nodes[index]; }else if(t == 1.0f){ return nodes[index + 1]; } F32 t2, t3; t2 = t * t; t3 = t2 * t; CVector4 powers(t3, t2, t, 1); // ret = powers * mCoeffs * (point1, point2, tangent1, tangent2) CVector3& point1 = nodes[index]; CVector3& point2 = nodes[index+1]; CVector3& tan1 = mTangents[index]; CVector3& tan2 = mTangents[index+1]; CMatrix4 mpt; FMatrix4 &pt = mpt.m; pt[0][0] = point1.x; pt[0][1] = point1.y; pt[0][2] = point1.z; pt[0][3] = 1.0f; pt[1][0] = point2.x; pt[1][1] = point2.y; pt[1][2] = point2.z; pt[1][3] = 1.0f; pt[2][0] = tan1.x; pt[2][1] = tan1.y; pt[2][2] = tan1.z; pt[2][3] = 1.0f; pt[3][0] = tan2.x; pt[3][1] = tan2.y; pt[3][2] = tan2.z; pt[3][3] = 1.0f; CVector4 ret = mCoeffs * mpt * powers; return CVector3(ret.x, ret.y, ret.z); }
template<int m> static void perturbed_sign_test() { for (const int power : vec(1,2,3)) for (const int index : range(20)) { if (verbose) cout << endl; // Evaluate perturbed sign using our fancy routine nasty_power = power; nasty_index = index; Array<exact::Perturbed<m>> fX(1); fX[0].seed_ = index; const bool fast = perturbed_sign<exact::Perturbed<m>>(nasty_predicate,m*power,fX); GEODE_ASSERT((power&1) || fast); // Evaluate the series out to several terms using brute force Array<int> powers(m+1); // Choose powers of 2 to approximate nested infinitesimals for (int i=0;i<m;i++) powers[i+1] = (power+1)*powers[i]+128; mpz_t yp; mpz_init(yp); const int enough = 5120/(8*sizeof(ExactInt)); Vector<Exact<enough>,m> sX[1]; for (int i=0;i<=m+1;i++) { if (i) { const Vector<Exact<1>,m> y(perturbation<m>(i,index)); for (int j=0;j<m;j++) { auto& x = sX[0][j]; Exact<enough> yp; const int skip = (powers.back()-powers[i-1])/(8*sizeof(mp_limb_t)); mpz_set(asarray(yp.n).slice(skip,yp.limbs),y[j]); // yp = y[j]<<(powers[-1]-powers[i-1]) x += yp; } } // We should be initially zero, and then match the correct sign once nonzero Array<mp_limb_t> result(enough*m*power,uninit); nasty_predicate(result,asconstarray(sX)); const int slow = mpz_sign(result); if (0) { cout << "m "<<m<<", power "<<power<<", index "<<index<<", i "<<i<<", fast "<<2*fast-1<<", slow "<<slow<<endl; cout << " fX = "<<fX[0]<<", sX = "<<sX[0]<<" (x = "<<mpz_str(asarray(sX[0].x.n),true)<<')'<<endl; cout << " sX result = "<<mpz_str(result,true)<<endl; } GEODE_ASSERT(slow==(i<m?0:2*fast-1)); } mpz_clear(yp); } }
Vector3 ActionBySpline::Interpolate(uint fromIndex, float t) const { if((fromIndex + 1) == m_vPoints.size()) return m_vPoints[fromIndex]; if(t <= 0.0f) return m_vPoints[fromIndex]; if(t >= 1.0f) return m_vPoints[fromIndex + 1]; float t2 = t * t; float t3 = t2 * t; Vector4 powers(t3, t2, t, 1); // Algorithm is ret = powers * mCoeffs * Matrix4(point1, point2, tangent1, tangent2) // const Vector3& point1 = m_vPoints[fromIndex]; const Vector3& point2 = m_vPoints[fromIndex + 1]; const Vector3& tan1 = m_vTangents[fromIndex]; const Vector3& tan2 = m_vTangents[fromIndex + 1]; Matrix4x4 pt; pt.e[Matrix4x4::E11] = point1.x; pt.e[Matrix4x4::E12] = point1.y; pt.e[Matrix4x4::E13] = point1.z; pt.e[Matrix4x4::E14] = 1.0f; pt.e[Matrix4x4::E21] = point2.x; pt.e[Matrix4x4::E22] = point2.y; pt.e[Matrix4x4::E23] = point2.z; pt.e[Matrix4x4::E24] = 1.0f; pt.e[Matrix4x4::E31] = tan1.x; pt.e[Matrix4x4::E32] = tan1.y; pt.e[Matrix4x4::E33] = tan1.z; pt.e[Matrix4x4::E34] = 1.0f; pt.e[Matrix4x4::E41] = tan2.x; pt.e[Matrix4x4::E42] = tan2.y; pt.e[Matrix4x4::E43] = tan2.z; pt.e[Matrix4x4::E44] = 1.0f; Vector4 ret = powers * m_matCoeffs * pt; return Vector3(ret.x, ret.y, ret.z); }
void *sending_thread(){ int i; PacketDescriptor pd; int r; int sleep; while (1){ pd = blockingReadBB(outgoing); for (i=0;i<10;i++){ if ((send_packet(netdev, pd)) == 1){ break; } r=random(); sleep = (unsigned int) r; //casting to unsigned removes any negative numbers sleep = sleep % powers(2,i); // limits it to the desired range// usleep(sleep); //I believe this code is waiting a random time in the range 0-(2 to the power i) microseconds } blocking_put_pd(fpds, pd); } return NULL; }
// Main entry point: Evaluate an encrypted polynomial on an encrypted input // return in ret = sum_i poly[i] * x^i void polyEval(Ctxt& ret, const Vec<Ctxt>& poly, const Ctxt& x) { if (poly.length()<=1) { // Some special cases if (poly.length()==0) ret.clear(); // empty polynomial else ret = poly[0]; // constant polynomial return; } long deg = poly.length()-1; long logD = NextPowerOfTwo(divc(poly.length(),3)); long d = 1L << logD; // We have d <= deg(poly) < 3d assert(d <= deg && deg < 3*d); Vec<Ctxt> powers(INIT_SIZE, logD+1, x); if (logD>0) { powers[1].square(); for (long i=2; i<=logD; i++) { // powers[i] = x^{2^i} powers[i] = powers[i-1]; powers[i].square(); } } // Compute in three parts p0(X) + ( p1(X) + p2(X)*X^d )*X^d Ctxt tmp(ZeroCtxtLike, ret); recursivePolyEval(ret, &poly[d], min(d,poly.length()-d), powers); // p1(X) if (poly.length() > 2*d) { // p2 is not empty recursivePolyEval(tmp, &poly[2*d], poly.length()-2*d, powers); // p2(X) tmp.multiplyBy(powers[logD]); ret += tmp; } ret.multiplyBy(powers[logD]); // ( p1(X) + p2(X)*X^d )*X^d recursivePolyEval(tmp, &poly[0], d, powers); // p0(X) ret += tmp; }
//--------------------------------------------------------------------- Vec3 PUSimpleSpline::interpolate(unsigned int fromIndex, float t) const { // Bounds check CCASSERT (fromIndex < _points.size(), "fromIndex out of bounds"); if ((fromIndex + 1) == _points.size()) { // Duff request, cannot blend to nothing // Just return source return _points[fromIndex]; } // Fast special cases if (t == 0.0f) { return _points[fromIndex]; } else if(t == 1.0f) { return _points[fromIndex + 1]; } // Real interpolation // Form a vector of powers of t float t2, t3; t2 = t * t; t3 = t2 * t; Vec4 powers(t3, t2, t, 1); // Algorithm is ret = powers * mCoeffs * Matrix4(point1, point2, tangent1, tangent2) const Vec3& point1 = _points[fromIndex]; const Vec3& point2 = _points[fromIndex+1]; const Vec3& tan1 = _tangents[fromIndex]; const Vec3& tan2 = _tangents[fromIndex+1]; Mat4 pt; pt.m[0] = point1.x; pt.m[1] = point1.y; pt.m[2] = point1.z; pt.m[3] = 1.0f; pt.m[4] = point2.x; pt.m[5] = point2.y; pt.m[6] = point2.z; pt.m[7] = 1.0f; pt.m[8] = tan1.x; pt.m[9] = tan1.y; pt.m[10] = tan1.z; pt.m[11] = 1.0f; pt.m[12] = tan2.x; pt.m[13] = tan2.y; pt.m[14] = tan2.z; pt.m[15] = 1.0f; Vec4 ret = pt * _coeffs * powers; return Vec3(ret.x, ret.y, ret.z); }
int main() { int j,k; big a,b,x,y,p,A2; time_t seed; epoint *g; double tr1,tr2,ts,tv1,tv2,tp,td; #ifndef MR_NOFULLWIDTH miracl *mip=mirsys(300,0); #else miracl *mip=mirsys(300,MAXBASE); #endif p=mirvar(0); a=mirvar(-3); b=mirvar(0); x=mirvar(1); y=mirvar(0); A2=mirvar(0); mip->IOBASE=60; time(&seed); irand((long)seed); printf("MIRACL - %d bit version\n",MIRACL); #ifdef MR_LITTLE_ENDIAN printf("Little Endian processor\n"); #endif #ifdef MR_BIG_ENDIAN printf("Big Endian processor\n"); #endif #ifdef MR_NOASM printf("C-Only Version of MIRACL\n"); #else printf("Using some assembly language\n"); #endif #ifdef MR_STRIPPED_DOWN printf("Stripped down version of MIRACL - no error messages\n"); #endif #ifdef MR_KCM k=MR_KCM*MIRACL; printf("Using KCM method \n"); printf("Optimized for %d, %d, %d, %d...etc. bit moduli\n",k,k*2,k*4,k*8); #endif #ifdef MR_COMBA k=MR_COMBA*MIRACL; printf("Using COMBA method \n"); printf("Optimized for %d bit moduli\n",k); #endif #ifdef MR_PENTIUM printf("Floating-point co-processor arithmetic used for Pentium\n"); #endif #ifndef MR_KCM #ifndef MR_COMBA #ifndef MR_PENTIUM printf("No special optimizations\n"); #endif #endif #endif printf("Precomputation uses fixed Window size = %d\n",WINDOW); printf("So %d values are precomputed and stored\n",(1<<WINDOW)); #ifdef MR_NOFULLWIDTH printf("No Fullwidth base possible\n"); #else printf("NOTE: No optimizations/assembly language apply to GF(2^m) Elliptic Curves\n"); #endif printf("NOTE: times are elapsed real-times - so make sure nothing else is running!\n\n"); printf("Modular exponentiation benchmarks - calculating g^e mod p\n"); printf("From these figures it should be possible to roughly estimate the time\n"); printf("required for your favourite PK algorithm, RSA, DSA, DH, etc.\n"); printf("Key R - random base bits/random exponent bits \n"); printf(" V - random base bits/(small exponent e) \n"); printf(" S - (small base g) /random exponent bits \n"); printf(" P - exponentiation with precomputation (fixed base g)\n"); printf(" D - double exponentiation g^e.a^b mod p\n"); printf("F3 = 257, F4 = 65537\n"); printf("RSA - Rivest-Shamir-Adleman\n"); printf("DH - Diffie Hellman Key exchange\n"); printf("DSA - Digital Signature Algorithm\n"); printf("\n512 bit prime....\n"); cinstr(p,p512); k=512; j=160; tr1=powers(k,j,p); td=powers_double(k,j,p); tr2=powers(k,k,p); ts=powers_small_base(3,j,p); tp=powers_precomp(k,j,p); printf("\n"); printf("%4d bit RSA decryption %8.2lf ms \n",2*k,2*tr2); printf("%4d bit DH %d bit exponent:-\n",k,j); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, small base %8.2lf ms \n",ts); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit DSA %d bit exponent:-\n",k,j); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n1024 bit prime....\n"); cinstr(p,p1024); k=1024; j=160; tr1=powers(k,j,p); td=powers_double(k,j,p); tr2=powers(k,k,p); tv1=powers_small_exp(k,3,p); tv2=powers_small_exp(k,65537L,p); ts=powers_small_base(3,j,p); tp=powers_precomp(k,j,p); printf("\n"); printf("%4d bit RSA decryption %8.2lf ms \n",2*k,2*tr2); printf("%4d bit RSA encryption e=3 %8.2lf ms \n",k,tv1); printf("%4d bit RSA encryption e=65537 %8.2lf ms \n",k,tv2); printf("%4d bit DH %d bit exponent:-\n",k,j); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, small base %8.2lf ms \n",ts); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit DSA %d bit exponent:-\n",k,j); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n2048 bit prime....\n"); cinstr(p,p2048); k=2048; j=256; tr1=powers(k,j,p); td=powers_double(k,j,p); powers(k,k,p); tv1=powers_small_exp(k,3,p); tv2=powers_small_exp(k,65537L,p); ts=powers_small_base(3,j,p); tp=powers_precomp(k,j,p); printf("\n"); printf("%4d bit RSA encryption e=3 %8.2lf ms \n",k,tv1); printf("%4d bit RSA encryption e=65537 %8.2lf ms \n",k,tv2); printf("%4d bit DH %d bit exponent:-\n",k,j); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, small base %8.2lf ms \n",ts); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit DSA %d bit exponent:-\n",k,j); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n"); printf("Elliptic Curve point multiplication benchmarks - calculating r.P\n"); printf("From these figures it should be possible to roughly estimate the time\n"); printf("required for your favourite EC PK algorithm, ECDSA, ECDH, etc.\n"); printf("Key - ER - Elliptic Curve point multiplication r.P\n"); printf(" ED - Elliptic Curve double multiplication r.P + s.Q\n"); printf(" EP - Elliptic Curve multiplication with precomputation\n"); printf("EC - Elliptic curve GF(p) - p of no special form \n"); printf("ECDH - Diffie Hellman Key exchange\n"); printf("ECDSA - Digital Signature Algorithm\n"); mip->IOBASE=10; printf("\n160 bit GF(p) Elliptic Curve....\n"); k=160; cinstr(p,p160); cinstr(b,b160); cinstr(y,y160); ecurve_init(a,b,p,MR_PROJECTIVE); g=epoint_init(); if (!epoint_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults(k,g); td=mult_double(k,g); tp=mult_precomp(k,x,y,a,b,p); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n192 bit GF(p) Elliptic Curve....\n"); k=192; cinstr(p,p192); cinstr(b,b192); cinstr(y,y192); ecurve_init(a,b,p,MR_PROJECTIVE); g=epoint_init(); if (!epoint_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults(k,g); td=mult_double(k,g); tp=mult_precomp(k,x,y,a,b,p); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n224 bit GF(p) Elliptic Curve....\n"); k=224; cinstr(p,p224); cinstr(b,b224); cinstr(y,y224); ecurve_init(a,b,p,MR_PROJECTIVE); g=epoint_init(); if (!epoint_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults(k,g); td=mult_double(k,g); tp=mult_precomp(k,x,y,a,b,p); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n256 bit GF(p) Elliptic Curve....\n"); k=256; cinstr(p,p256); cinstr(b,b256); cinstr(y,y256); ecurve_init(a,b,p,MR_PROJECTIVE); g=epoint_init(); if (!epoint_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults(k,g); td=mult_double(k,g); tp=mult_precomp(k,x,y,a,b,p); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); #ifndef MR_FP printf("\n163 bit GF(2^m) Elliptic Curve....\n"); k=163; mip->IOBASE=16; cinstr(b,B163); cinstr(x,x163); cinstr(y,y163); mip->IOBASE=10; convert(A163,A2); ecurve2_init(m163,a163,b163,c163,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m163,a163,b163,c163); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n163 bit GF(2^m) Koblitz Elliptic Curve....\n"); k=163; mip->IOBASE=16; cinstr(b,KB163); cinstr(x,Kx163); cinstr(y,Ky163); mip->IOBASE=10; convert(KA163,A2); ecurve2_init(m163,a163,b163,c163,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m163,a163,b163,c163); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n233 bit GF(2^m) Elliptic Curve....\n"); k=233; mip->IOBASE=16; cinstr(b,B233); cinstr(x,x233); cinstr(y,y233); mip->IOBASE=10; convert(A233,A2); ecurve2_init(m233,a233,b233,c233,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m233,a233,b233,c233); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n233 bit GF(2^m) Koblitz Elliptic Curve....\n"); k=233; mip->IOBASE=16; cinstr(b,KB233); cinstr(x,Kx233); cinstr(y,Ky233); mip->IOBASE=10; convert(KA233,A2); ecurve2_init(m233,a233,b233,c233,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m233,a233,b233,c233); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n283 bit GF(2^m) Elliptic Curve....\n"); k=283; mip->IOBASE=16; cinstr(b,B283); cinstr(x,x283); cinstr(y,y283); mip->IOBASE=10; convert(A283,A2); ecurve2_init(m283,a283,b283,c283,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m283,a283,b283,c283); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n283 bit GF(2^m) Koblitz Elliptic Curve....\n"); k=283; mip->IOBASE=16; cinstr(b,KB283); cinstr(x,Kx283); cinstr(y,Ky283); mip->IOBASE=10; convert(KA283,A2); ecurve2_init(m283,a283,b283,c283,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m283,a283,b283,c283); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n571 bit GF(2^m) Elliptic Curve....\n"); k=571; mip->IOBASE=16; cinstr(b,B571); cinstr(x,x571); cinstr(y,y571); mip->IOBASE=10; convert(A571,A2); ecurve2_init(m571,a571,b571,c571,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m571,a571,b571,c571); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); printf("\n571 bit GF(2^m) Koblitz Elliptic Curve....\n"); k=571; mip->IOBASE=16; cinstr(b,KB571); cinstr(x,Kx571); cinstr(y,Ky571); mip->IOBASE=10; convert(KA571,A2); ecurve2_init(m571,a571,b571,c571,A2,b,FALSE,MR_PROJECTIVE); g=epoint_init(); if (!epoint2_set(x,y,0,g)) { printf("This is not a point on the curve!\n"); exit(0); } tr1=mults2(k,g); td=mult2_double(k,g); tp=mult2_precomp(k,x,y,A2,b,m571,a571,b571,c571); printf("\n"); printf("%4d bit ECDH :-\n",k); printf(" offline, no precomputation %8.2lf ms \n",tr1); printf(" offline, w. precomputation %8.2lf ms \n",tp); printf(" online %8.2lf ms \n",tr1); printf("%4d bit ECDSA :-\n",k); printf(" signature no precomputation %8.2lf ms \n",tr1); printf(" signature w. precomputation %8.2lf ms \n",tp); printf(" verification %8.2lf ms \n",td); #endif return 0; }
static T_Status Crawl_Data(bool use_cache, T_Glyph_Ptr email, T_Glyph_Ptr password, T_Filename output_folder, bool is_clear) { T_Status status; T_WWW internet = NULL; bool is_exists; T_Glyph_Ptr path_ptr; T_Filename folder; T_XML_Document doc_languages = NULL; T_XML_Document doc_wepprops = NULL; T_XML_Document doc_sources = NULL; C_Pool pool(10000000,10000000); C_DDI_Deities deities(&pool); C_DDI_Skills skills(&pool); C_DDI_Rituals rituals(&pool); C_DDI_Items items(&pool); C_DDI_Classes classes(&pool); C_DDI_Races races(&pool); C_DDI_Paragons paragons(&pool); C_DDI_Epics epics(&pool); C_DDI_Feats feats(&pool); C_DDI_Powers powers(&pool); C_DDI_Monsters monsters(&pool); C_DDI_Backgrounds backgrounds(&pool); vector<C_DDI_Common *> list; vector<C_DDI_Single_Common *> singles; /* Add all of our downloader classes to the list */ list.push_back(&deities); list.push_back(&skills); list.push_back(&rituals); list.push_back(&items); list.push_back(&classes); list.push_back(&races); list.push_back(¶gons); list.push_back(&epics); list.push_back(&feats); list.push_back(&powers); //Monsters aren't supported yet... #ifdef NOTYET list.push_back(&monsters); #endif list.push_back(&backgrounds); /* Find a temporary folder to use */ Get_Temporary_Folder(folder); path_ptr = folder + strlen(folder); /* Search for the folder and create it if it doesn't exist */ is_exists = FileSys_Does_Folder_Exist(folder); if (!is_exists) { status = FileSys_Create_Directory(folder); if (x_Trap_Opt(!x_Is_Success(status))) { Log_Message("Couldn't create temporary folder."); x_Status_Return(LWD_ERROR); } } /* If we're not using cached copies, log in to D&D insider (if we don't have a username and password, this just establishes the connection) */ if (!use_cache) { Log_Message("Connecting to server...\n", true); /* Open a connection to the server first */ status = WWW_HTTP_Open(&internet,LOGIN_URL,NULL,NULL,NULL); if (x_Trap_Opt(!x_Is_Success(status))) { Log_Message("Couldn't open connection to login server!\n", true); goto cleanup_exit; } status = Login(internet, email, password, true); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* If we're not using the cache, we want to make sure we have fresh copies of everything, so delete the files in our temporary folder */ if (!use_cache) { strcpy(path_ptr,"*.*"); FileSys_Delete_Files(folder); *path_ptr = '\0'; } /* Create XML documents for deities languages - the crawlers can add their own entries for these during processing */ status = Create_Document(&doc_languages, &l_language_root, "language", DTD_Get_Data()); if (!x_Is_Success(status)) goto cleanup_exit; status = Create_Document(&doc_wepprops, &l_wepprop_root, "weapon property", DTD_Get_Augmentation()); if (!x_Is_Success(status)) goto cleanup_exit; status = Create_Document(&doc_sources, &l_source_root, "source", DTD_Get_Augmentation()); if (!x_Is_Success(status)) goto cleanup_exit; /* First, download all the index pages if we need to */ if (!use_cache) { for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Download_Index(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Download(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } } /* Read them in */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Read_Index(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Read(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Now download the rest of the content all at once NOTE: As of March 2011, there's no further content for download unless you have a password. */ if (!use_cache && l_is_password) { for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Download_Content(folder, internet); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* It's possible that some downloads were screwed up due to the servers acting weirdly. If so, they were added to a failed list, so try them again */ Retry_Failed_Downloads(internet); } /* Read it in and process it */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Read_Content(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Process all our stuff */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Process(); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Process(); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Post-process all our stuff - this requires it to have been output first, and puts finishing touches on everything */ for (ddi_iter it = list.begin(); it != list.end(); ++it) { status = (*it)->Post_Process(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } for (single_iter it = singles.begin(); it != singles.end(); ++it) { status = (*it)->Post_Process(folder); if (x_Trap_Opt(!x_Is_Success(status))) goto cleanup_exit; } /* Output our languages to the temporary folder, so we can append extensions to them later */ status = Finish_Document(doc_languages, folder, LANGUAGE_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; /* Now append any fixup extensions that are needed to compensate for the data being terrible */ Append_Extensions(folder, output_folder); /* Load the old "powers" XML document and try and copy any wizard powers out of it */ //We don't need to do this any more, but keep the code around just in case... // Fixup_Wizard_Powers(output_folder); /* Sources and weapon properties don't need any extensions, so they can go directly into the output folder - plus they're augmentation files, which aren't messed with anyway */ status = Finish_Document(doc_sources, output_folder, SOURCE_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; status = Finish_Document(doc_wepprops, output_folder, WEPPROP_FILENAME); if (!x_Is_Success(status)) goto cleanup_exit; /* wrapup everything */ cleanup_exit: l_language_root = NULL; if (doc_languages != NULL) XML_Destroy_Document(doc_languages); l_wepprop_root = NULL; if (doc_wepprops != NULL) XML_Destroy_Document(doc_wepprops); l_source_root = NULL; if (doc_sources != NULL) XML_Destroy_Document(doc_sources); if (internet != NULL) WWW_Close_Server(internet); /* Delete everything in our folder if required */ if (is_clear) { strcpy(path_ptr,"*.*"); FileSys_Delete_Files(folder); *path_ptr = '\0'; } x_Status_Return(status); }