Exemple #1
0
/*
    Calculation of the Account ID

    The AccountID is a 160-bit identifier that uniquely
    distinguishes an account. The account may or may not
    exist in the ledger. Even for accounts that are not in
    the ledger, cryptographic operations may be performed
    which affect the ledger. For example, designating an
    account not in the ledger as a regular key for an
    account that is in the ledger.

    Why did we use half of SHA512 for most things but then
    SHA256 followed by RIPEMD160 for account IDs? Why didn't
    we do SHA512 half then RIPEMD160? Or even SHA512 then RIPEMD160?
    For that matter why RIPEMD160 at all why not just SHA512 and keep
    only 160 bits?

    Answer (David Schwartz):

        The short answer is that we kept Bitcoin's behavior.
        The longer answer was that:
            1) Using a single hash could leave ripple
               vulnerable to length extension attacks.
            2) Only RIPEMD160 is generally considered safe at 160 bits.

        Any of those schemes would have been acceptable. However,
        the one chosen avoids any need to defend the scheme chosen.
        (Against any criticism other than unnecessary complexity.)

        "The historical reason was that in the very early days,
        we wanted to give people as few ways to argue that we were
        less secure than Bitcoin. So where there was no good reason
        to change something, it was not changed."
*/
AccountID
calcAccountID (PublicKey const& pk)
{
    ripesha_hasher rsh;
    rsh(pk.data(), pk.size());
    auto const d = static_cast<
        ripesha_hasher::result_type>(rsh);
    AccountID id;
    static_assert(sizeof(d) == sizeof(id), "");
    std::memcpy(id.data(), d.data(), d.size());
    return id;
}
void sphericalHarmonics::bDiffuseTransfer(SHSample* samp, const int num_samp, const float unitarea, XYZ* inCoeff, XYZ* outCoeff, const XYZ& normal) const
{
	bReconstructSH rsh(inCoeff);
	for (int j = 0; j < SH_N_BASES; j++) outCoeff[j] = XYZ(0);
	
	for(int j=0; j<num_samp; j++)
	{
		SHSample& s = samp[j];
		float H = normal.dot(s.vector);
		if(H>0)
		{
			XYZ col = rsh.getColor(s) * H * unitarea;
			projectASample(outCoeff, s, col);
		}
	}
}
void sphericalHarmonics::reconstructAndDraw(float* coeffs)
{
	
	
	//cout<<" "<<m_exampleCoeffs[0]<<endl;
	//cout<<" "<<m_exampleCoeffs[1]<<" "<<m_exampleCoeffs[2]<<" "<<m_exampleCoeffs[3]<<endl;
	//cout<<" "<<m_exampleCoeffs[4]<<" "<<m_exampleCoeffs[5]<<" "<<m_exampleCoeffs[6]<<" "<<m_exampleCoeffs[7]<<" "<<m_exampleCoeffs[8]<<endl;
	//cout<<" "<<m_exampleCoeffs[9]<<" "<<m_exampleCoeffs[10]<<" "<<m_exampleCoeffs[11]<<" "<<m_exampleCoeffs[12]<<" "<<m_exampleCoeffs[13]<<" "<<m_exampleCoeffs[14]<<" "<<m_exampleCoeffs[15]<<endl;
	
	reconstructSH rsh(coeffs);
	
	
	
	//glPushMatrix();
	//glTranslatef(1, 0, 0);
	drawSHFunction(rsh);
	//glPopMatrix();

}
void sphericalHarmonics::diffuseTransfer(SHSample* samp, const int num_samp, const float unitarea, XYZ* inCoeff, XYZ* outCoeff, float* tmpCoeff, const XYZ& normal) const
{
	reconstructSH rsh(inCoeff);
	
	for (int j = 0; j < SH_N_BASES; j++)
		tmpCoeff[j] = 0;
	
	for(int j=0; j<num_samp; j++)
	{
		SHSample& s = samp[j];
		float H = normal.dot(s.vector);
		if(H>0)
		{
			float shd = rsh.getFloat(s) * H * unitarea;
			projectASample(tmpCoeff, s, shd);
		}
	}
	
	for (int j = 0; j < SH_N_BASES; j++)
		outCoeff[j].x = outCoeff[j].y = outCoeff[j].z = tmpCoeff[j];
}
Exemple #5
0
Z H1(tra){A z;ND1{XA;if((m=ar-2)<0)R ic(a);DO(ar,d[i]=ad[ar-1-i])
 if(u= *ad,v=tr(ar-1,ad+1),v<2)R rsh(a,ar,d);W(ga(t=at,ar,an,d))C1(((PFI)t1))}}
Exemple #6
0
Z H2(rho){A z;ND2 I1{I wt=w->t,wn=w->n;I *d=a->p,r=a->n,n=tr1(r,d);Q(n<0,9)
 Q(r>MAXR,13)if(n==wn)R rsh(w,r,d);W(ga(t=wt,r,n,d))u=wn;C2(m0)}}
Exemple #7
0
Z H1(rav){ND1 R rsh(a,1,&a->n);}
Exemple #8
0
Z H1(rdc){I r,d[9];ND1 r=a->r-1;Q(r<1,7);R mv(d,a->d+1,r),*d*=*a->d,rsh(a,r,d);}
Exemple #9
0
I rk(I f,A r,A a,A w)
{
  A z=0,*p=0;
  if(w)ND2 else ND1;
  {
    XA;
    C *pp=0,*ap,*wp;
    I wt=0,wr=0,wn=0,*wd=0;
    I n=0,t=0,i,j,k,d[9],rw,ra,ri,ir,iw=0,ia=0,ii=0,
    e=!w&&f==MP(9),h=QP(f)&&f!=MP(71)&&!e;
    Q(!QA(r),9);
    Q(r->t,6);
    Q(r->n<1||r->n>3,8);
    ar-=ra=raw(ar,*r->p);
    if(!w) mv(d,ad,ra),ir=tr(ra,ad),ad+=ra;
    else 
    {
      wt=w->t,wr=w->r,wd=w->d;
      wr-=rw=raw(wr,r->p[r->n>1]),ri=r->n>2?r->p[2]:9;
      Q(ri<0,9);
      if(ri>ra)ri=ra;
      if(ri>rw)ri=rw;
      mv(d,ad,ra-=ri);
      ia=tr(ra,ad),mv(d+ra,wd,rw),iw=tr(rw-=ri,wd);
      Q(cm(ad+=ra,wd+=rw,ri),11);
      ii=tr(ri,ad),ra+=rw+ri,ir=ia*iw*ii,wn=tr(wr,wd+=ri),ad+=ri;
      if(h&&ir>iw&&(f==MP(21)||f==MP(25)||f==MP(26)||f==MP(32)||f==MP(33)))
	h=0;
    } 
    an=tr(ar,ad);
    if(h)
    {
      g=0;
      aw_c[0]=a->c;
      aw_c[1]=w&&w->c;
      r=(A)fa(f,gC(at,ar,an,ad,a->n?a->p:0),w?gC(wt,wr,wn,wd,w->n?w->p:0):0);
      aw_c[0]=aw_c[1]=1;
      if(!r)R 0;
      r=un(&r);
      mv(d+ra,r->d,j=r->r);
      if((j+=ra)>MAXR)R q=13,(I)r;
      n=r->n;t=r->t;
      if(ir<2) R mv(r->d,d,r->r=j),r->n*=ir,(I)r;
      dc(r);
      if(g==(I (*)())rsh) R rsh(w?w:a,j,d);
      if(!g){h=0;}
      else
      {
	if(at=atOnExit,w) wt=wtOnExit;
	if(at!=a->t&&!(a=at?ep_cf(1):ci(1))) R 0;
	if(w&&wt!=w->t&&!(w=wt?ep_cf(2):ci(2))) R 0;
	OF(i,ir,n);
	W(ga(t,j,i,d));
	pp=(C*)z->p;
      }
    }
    if(!h) 
    {
      W(ga(Et,ra,ir,d));
      *--Y=zr(z),p=(A*)z->p;
    }
    if(!w)
    {
      for(ap=(C*)a->p;ir--;ap+=Tt(at,an))
	if(h) (*(I(*)(C*,C*,I))g)(pp,ap,an),pp+=Tt(t,n);
	else a=gc(at,ar,an,ad,(I*)ap),*p++=e?a:(A)fa(f,(I)a,0);
    } 
    else
    {
      for(i=0;i<ia;++i)for(j=0;j<iw;++j)
	for(k=0;k<ii;++k){
	  ap=(C*)a->p+Tt(at,(i*ii+k)*an);
	  wp=(C*)w->p+Tt(wt,(j*ii+k)*wn);
	  if(h)
	  {
	    (*(I(*)(C*,C*,C*,I))g)(pp,ap,wp,n),pp+=Tt(t,n);
	    if(q==1)*--Y=(I)z,aplus_err(q,(A)Y[1]),++Y;
	  } 
	  else
	  { 
	    *p++=(A)fa(f,(I)gc(at,ar,an,ad,(I*)ap),(I)gc(wt,wr,wn,wd,(I*)wp));
	  }
	}
    }
    if(h)R(I)z;
    if(!e)z=(A)dis(r=z),dc(r);
    R ++Y,(I)z;
  }
}
void sphericalHarmonics::reconstructAndDraw(XYZ* coeffs)
{
	rgbReconstructSH rsh(coeffs);
	
	drawSHFunction(rsh);
}