static void offset_init(const ocb_aes_t *ctx, char *offset) {
  const int stretch_size = AES_BLOCK_SIZE + (AES_BLOCK_SIZE/2);
  uchar nonce[AES_BLOCK_SIZE];
  int bottom;
  uchar ktop[AES_BLOCK_SIZE];
  uchar stretch[stretch_size];
  uchar shifted_block[stretch_size];

  memset(offset, 0, AES_BLOCK_SIZE);
  nonce_init(ctx, nonce);
  bottom = 0;
  bottom = (nonce[AES_BLOCK_SIZE - 1] & 0x1F);
  ktop_init(ctx, nonce, ktop);
  stretch_init(ktop, stretch);
  left_shift(stretch, stretch_size, shifted_block, bottom);
  cpy_block(offset, shifted_block);
}
Beispiel #2
0
void ditime3d_init (float dipo,   float dipd,   int dipn,   // x-dip angle axis 
					float sdipo,  float sdipd,  int sdipn,  // y-dip angle axis 
				    float xio,    float xid,    int xin,    // xi axis in x-direction
				    float sxio,   float sxid,   int sxin,   // xi axis in y-direction
				    float dip0o,  float dip0d,  int dip0n,  // x-refl dip axis
				    float sdip0o, float sdip0d, int sdip0n, // y-refl dip axis
				    float to,     float td,     int tn,     // time axis 
				    bool isAA,                              // antialiasing
				    int invMod) 						 
/*< initialize >*/
{
    int reflSize, diffSize;
    float CONVPARAM;
    float *pTableR, *pTableD;
    int id, ixi, id0, it, sid, sixi, sid0;
    float curDip, a, tan_a, tan_sa, curXi, scurXi, aux_diff, curTime, a0, sa0, tan_a0, tan_sa0, aux_refl, sa;
	float curDip0, scurDip, scurDip0;

	float k2, ke, k0, k1, kM;

    to_   = to;   td_   = td;   tn_   = tn;  

    dipo_ = dipo; dipd_ = dipd; dipn_ = dipn;  
    sdipo_ = sdipo; sdipd_ = sdipd; sdipn_ = sdipn;  

    dip0o_ = dip0o; dip0d_ = dip0d; dip0n_ = dip0n;  
    sdip0o_ = sdip0o; sdip0d_ = sdip0d; sdip0n_ = sdip0n;  
    xio_  = xio; xid_  = xid;  xin_  = xin;  
    sxio_ = sxio; sxid_ = sxid; sxin_ = sxin;  

    tLim_ = to_ + td_ * (tn_ - 1);

    invMod_ = invMod;
    isAA_   = isAA;

    if (isAA_) {
		sf_aastretch_init  (false, tn_, to_, td_, tn_);
		sf_halfint_init (true, 2 * tn_, 1.f - 1.f / tn_);
    } else {
		stretch_init  (tn_, to_, td_, tn_);
	}

	amp = sf_floatalloc (tn_);
    str = sf_floatalloc (tn_);
    tx  = sf_floatalloc (tn_);
    tmp = sf_floatalloc (tn_);

    // shift tables
    reflSize = tn_ * dip0n_ * sdip0n_ * dipn_ * sdipn_;
    diffSize = tn_ * xin_ * dipn_ * sxin_ * sdipn_;

    tableRefl_ = sf_floatalloc (reflSize);
    tableDiff_ = sf_floatalloc (diffSize);
	
    CONVPARAM = SF_PI / 180.f;

    pTableR = tableRefl_;
    pTableD = tableDiff_;

    for (sid = 0; sid < sdipn_; ++sid) { 
		scurDip = sdipo_ + sid * sdipd_;
		sa      = scurDip * CONVPARAM;
		tan_sa  = tan (sa);
	    for (id = 0; id < dipn_; ++id) { 
			curDip = dipo_ + id * dipd_;
			a      = curDip * CONVPARAM;
			tan_a  = tan (a);
	
			// diffraction part
			for (sixi = 0; sixi < sxin_; ++sixi) { 
			    scurXi = sxio_ + sixi * sxid_;
				for (ixi = 0; ixi < xin_; ++ixi) { 
				    curXi = xio_ + ixi * xid_;

					k2 = scurXi * tan_sa + curXi * tan_a;
					ke = scurXi*scurXi + curXi*curXi + 1.f;
	
				    aux_diff = k2 + sqrt (k2 * k2 + ke);
	
				    for (it = 0; it < tn_; ++it, ++pTableD) { 
						curTime = to_ + it * td_;
						*pTableD = curTime * aux_diff;			    
				    }
				}
			}		
				
			// reflection part
			for (sid0 = 0; sid0 < sdip0n_; ++sid0) { 
			    scurDip0 = sdip0o_ + sid0 * sdip0d_;
			    sa0 = scurDip0 * CONVPARAM;
			    tan_sa0 = tan (sa0);	

				k0 = sqrt (1.f + tan_a0*tan_a0 + tan_sa0*tan_sa0);

				for (id0 = 0; id0 < dip0n_; ++id0) { 
				    curDip0 = dip0o_ + id0 * dip0d_;
				    a0 = curDip0 * CONVPARAM;
				    tan_a0 = tan (a0);	
	
					kM = sqrt (1.f + tan_a*tan_a + tan_sa*tan_sa);
					k1 = tan_sa0*tan_sa + tan_a0*tan_a;
			
				    aux_refl = 1.f / (k0 * kM - k1);
		
				    for (it = 0; it < tn_; ++it, ++pTableR) {		
						curTime = to_ + it * td_;
						*pTableR = curTime * aux_refl;		
				    }
				}	
	    	}	

		}
	}

    return;
}