int sc_main(int ac, char *av[]) { sc_signal<double> in1; sc_signal<double> in2; sc_signal<double> sum; sc_signal<double> diff; sc_signal<double> prod; sc_signal<double> quot; sc_signal<double> powr; powr = 0.0; sc_clock clk("CLOCK", 20.0, SC_NS, 0.5, 0.0, SC_NS); numgen N("STIMULUS", clk, in1, in2); stage1 S1("Stage1", clk, in1, in2, sum, diff); stage2 S2("Stage2", clk, sum, diff, prod, quot); stage3 S3("Stage3", clk, prod, quot, powr); display D("Display", clk, powr); sc_start(1000, SC_NS); return 0; }
void CParam::iterate(int iter, CData &Data, CFeasibilityMap &FM, CHyperParam &hyper, Uniform &randUnif, int n_simul) { if (hyper.f_Sigma < 0) { //if we use default hyper parameters hyper.f_Sigma = Data.n_var-Data.n_balance_edit+1; } if (K == -1) { Rprintf( "The number of components has not been set\n"); return; } if (K < 0) { //the K has been changed and delayed re-initilization is needed //cout << "Initilizing parameters" << endl; initizalize(Data,-K,FM,randUnif,n_simul); } //clock_t start = clock(), diff; // S1. // vector_r S1(iter, randUnif, Data, FM, n_simul); /* diff = clock() - start; int msec = diff * 1000 / CLOCKS_PER_SEC; << "s1:" << msec << endl; start = clock(); */ // S2-add. // Y_in | S_i for sum(s_i) >= 2 S2_add(randUnif,Data); S3_Z_in(Data); S4_Z_out(Data); S5_MuSigma(Data, hyper.f_Sigma,hyper.h_Mu); S6_pi(); S7_alpha(hyper.a_alpha, hyper.b_alpha); S8_Phi(hyper.f_Sigma, hyper.a_Phi, hyper.b_Phi); }
TEST(InputTest, CppUnitLite) { std::stringstream Out, Out1, Out2; std::string Line, Message; // Default sample file where everything is expected to be OK. Sudoku S("Sample.txt", Out, false); while(std::getline(Out, Line)) { if (Line.find("Count") != std::string::npos) Message = Line; } CHECK_EQUAL(Message, "Count = 14890"); // Sample file with incomplete lines or delimeters between characters. Sudoku S1("SampleBad1.txt", Out1, true); S1.IOFile(Out1); while(std::getline(Out1, Line)) { if (Line.find("Line") != std::string::npos) Message = Line; } CHECK_EQUAL(Message, "Line 8 incomplete or mal-formatted."); // Sample file with excess data or otherwise no valid solution. Sudoku S2("SampleBad2.txt", Out2, true); S2.IOFile(Out2); Out2.str(""); S2.IOStats(Out2); CHECK_EQUAL(Out2.str(), "\nNo solution found.\n\n"); }
/// Calculate the number of primes below x using the /// Deleglise-Rivat algorithm. /// Run time: O(x^(2/3) / (log x)^2) operations, O(x^(1/3) * (log x)^3) space. /// int64_t pi_deleglise_rivat1(int64_t x) { if (x < 2) return 0; double alpha = get_alpha_deleglise_rivat(x); int64_t x13 = iroot<3>(x); int64_t y = (int64_t) (x13 * alpha); int64_t z = x / y; int64_t c = PhiTiny::get_c(y); int64_t p2 = P2(x, y, 1); vector<int32_t> mu = generate_moebius(y); vector<int32_t> lpf = generate_least_prime_factors(y); int64_t pi_y = pi_legendre(y, 1); int64_t s1 = S1(x, y, c, 1); int64_t s2 = S2(x, y, z, c, lpf, mu); int64_t phi = s1 + s2; int64_t sum = phi + pi_y - 1 - p2; return sum; }
/// Calculate the number of primes below x using the /// Lagarias-Miller-Odlyzko algorithm. /// Run time: O(x^(2/3)) operations, O(x^(1/3) * (log x)^2) space. /// int64_t pi_lmo3(int64_t x) { if (x < 2) return 0; double alpha = get_alpha_lmo(x); int64_t x13 = iroot<3>(x); int64_t y = (int64_t) (x13 * alpha); int64_t c = PhiTiny::get_c(y); int64_t p2 = P2(x, y, 1); vector<int32_t> mu = generate_moebius(y); vector<int32_t> lpf = generate_least_prime_factors(y); vector<int32_t> primes = generate_primes(y); int64_t pi_y = primes.size() - 1; int64_t s1 = S1(x, y, c, 1); int64_t s2 = S2(x, y, c, primes, lpf, mu); int64_t phi = s1 + s2; int64_t sum = phi + pi_y - 1 - p2; return sum; }
static void _BRSHA512Compress(uint64_t *r, uint64_t *x) { static const uint64_t k[] = { 0x428a2f98d728ae22, 0x7137449123ef65cd, 0xb5c0fbcfec4d3b2f, 0xe9b5dba58189dbbc, 0x3956c25bf348b538, 0x59f111f1b605d019, 0x923f82a4af194f9b, 0xab1c5ed5da6d8118, 0xd807aa98a3030242, 0x12835b0145706fbe, 0x243185be4ee4b28c, 0x550c7dc3d5ffb4e2, 0x72be5d74f27b896f, 0x80deb1fe3b1696b1, 0x9bdc06a725c71235, 0xc19bf174cf692694, 0xe49b69c19ef14ad2, 0xefbe4786384f25e3, 0x0fc19dc68b8cd5b5, 0x240ca1cc77ac9c65, 0x2de92c6f592b0275, 0x4a7484aa6ea6e483, 0x5cb0a9dcbd41fbd4, 0x76f988da831153b5, 0x983e5152ee66dfab, 0xa831c66d2db43210, 0xb00327c898fb213f, 0xbf597fc7beef0ee4, 0xc6e00bf33da88fc2, 0xd5a79147930aa725, 0x06ca6351e003826f, 0x142929670a0e6e70, 0x27b70a8546d22ffc, 0x2e1b21385c26c926, 0x4d2c6dfc5ac42aed, 0x53380d139d95b3df, 0x650a73548baf63de, 0x766a0abb3c77b2a8, 0x81c2c92e47edaee6, 0x92722c851482353b, 0xa2bfe8a14cf10364, 0xa81a664bbc423001, 0xc24b8b70d0f89791, 0xc76c51a30654be30, 0xd192e819d6ef5218, 0xd69906245565a910, 0xf40e35855771202a, 0x106aa07032bbd1b8, 0x19a4c116b8d2d0c8, 0x1e376c085141ab53, 0x2748774cdf8eeb99, 0x34b0bcb5e19b48a8, 0x391c0cb3c5c95a63, 0x4ed8aa4ae3418acb, 0x5b9cca4f7763e373, 0x682e6ff3d6b2b8a3, 0x748f82ee5defb2fc, 0x78a5636f43172f60, 0x84c87814a1f0ab72, 0x8cc702081a6439ec, 0x90befffa23631e28, 0xa4506cebde82bde9, 0xbef9a3f7b2c67915, 0xc67178f2e372532b, 0xca273eceea26619c, 0xd186b8c721c0c207, 0xeada7dd6cde0eb1e, 0xf57d4f7fee6ed178, 0x06f067aa72176fba, 0x0a637dc5a2c898a6, 0x113f9804bef90dae, 0x1b710b35131c471b, 0x28db77f523047d84, 0x32caab7b40c72493, 0x3c9ebe0a15c9bebc, 0x431d67c49c100d4c, 0x4cc5d4becb3e42b6, 0x597f299cfc657e2a, 0x5fcb6fab3ad6faec, 0x6c44198c4a475817 }; int i; uint64_t a = r[0], b = r[1], c = r[2], d = r[3], e = r[4], f = r[5], g = r[6], h = r[7], t1, t2, w[80]; for (i = 0; i < 16; i++) w[i] = be64(x[i]); for (; i < 80; i++) w[i] = S3(w[i - 2]) + w[i - 7] + S2(w[i - 15]) + w[i - 16]; for (i = 0; i < 80; i++) { t1 = h + S1(e) + ch(e, f, g) + k[i] + w[i]; t2 = S0(a) + maj(a, b, c); h = g, g = f, f = e, e = d + t1, d = c, c = b, b = a, a = t1 + t2; } r[0] += a, r[1] += b, r[2] += c, r[3] += d, r[4] += e, r[5] += f, r[6] += g, r[7] += h; var_clean(&a, &b, &c, &d, &e, &f, &g, &h, &t1, &t2); mem_clean(w, sizeof(w)); }
void test(int M) { /* Scattering iterators. */ int c1, c2; /* Original iterators. */ int i, j, k; if (M >= 2) { for (c2=2;c2<=M;c2++) { for (j=2;j<=M;j++) { S2(1,j,c2) ; } } } for (c1=2;c1<=M-1;c1++) { for (c2=c1+1;c2<=M;c2++) { for (j=1;j<=c1-1;j++) { S1(c1,j,c2) ; } for (j=c1+1;j<=M;j++) { S2(c1,j,c2) ; } } } }
/// Calculate the number of primes below x using the /// Deleglise-Rivat algorithm. /// Run time: O(x^(2/3) / (log x)^2) operations, O(x^(1/3) * (log x)^3) space. /// int64_t pi_deleglise_rivat_parallel1(int64_t x, int threads) { if (x < 2) return 0; double alpha = get_alpha(x, 0.0017154, -0.0508992, 0.483613, 0.0672202); int64_t x13 = iroot<3>(x); int64_t y = (int64_t) (x13 * alpha); int64_t z = x / y; int64_t p2 = P2(x, y, threads); vector<int32_t> mu = generate_moebius(y); vector<int32_t> lpf = generate_least_prime_factors(y); vector<int32_t> primes = generate_primes(y); int64_t pi_y = pi_bsearch(primes, y); int64_t c = PhiTiny::get_c(y); int64_t s1 = S1(x, y, c, threads); int64_t s2 = S2(x, y, z, c, primes, lpf, mu, threads); int64_t phi = s1 + s2; int64_t sum = phi + pi_y - 1 - p2; return sum; }
int main() { init_arrays(); double annot_t_start=0, annot_t_end=0, annot_t_total=0; int annot_i; for (annot_i=0; annot_i<REPS; annot_i++) { annot_t_start = rtclock(); int t, i, j, k, l, m, n,ii,jj; #define S1(zT0,zT1,t,j) {ey[0][j]=t;} #define S2(zT0,zT1,zT2,t,i,j) {ey[i][j]=ey[i][j]-((double)(1))/2*(hz[i][j]-hz[i-1][j]);} #define S3(zT0,zT1,zT2,t,i,j) {ex[i][j]=ex[i][j]-((double)(1))/2*(hz[i][j]-hz[i][j-1]);} #define S4(zT0,zT1,zT2,t,i,j) {hz[i][j]=hz[i][j]-((double)(7))/10*(ey[1+i][j]+ex[i][1+j]-ex[i][j]-ey[i][j]);} int c1, c2, c3, c4, c5, c6, c7; register int lbv, ubv; for (c1=0;c1<=floord(tmax-1,32);c1++) { for (c2=max(ceild(32*c1-31,32),0);c2<=min(floord(tmax+ny-1,32),floord(32*c1+ny+31,32));c2++) { for (c3=max(max(max(max(ceild(32*c2-ny-30,32),0),ceild(64*c1-32*c2-61,32)),ceild(32*c1-31,32)),ceild(32*c1-992*c2-1891,992));c3<=min(min(floord(32*c2+nx+30,32),floord(tmax+nx-1,32)),floord(32*c1+nx+31,32));c3++) { if ((c1 <= floord(32*c3-nx,32)) && (c2 <= floord(32*c3-nx+ny,32)) && (c3 >= ceild(nx,32))) { for (c5=max(32*c3-nx+1,32*c2);c5<=min(32*c2+31,32*c3-nx+ny);c5++) { S4(c1,-c1+c3,-c1+c2,32*c3-nx,nx-1,-32*c3+c5+nx-1) ; } } if ((c1 <= floord(32*c2-ny,32)) && (c2 >= max(ceild(32*c3-nx+ny+1,32),ceild(ny,32)))) { for (c6=max(32*c3,32*c2-ny+1);c6<=min(32*c2+nx-ny,32*c3+31);c6++) { S4(c1,-c1+c3,-c1+c2,32*c2-ny,-32*c2+c6+ny-1,ny-1) ; } } if (c1 == c3) { for (c4=max(max(32*c2-ny+1,0),32*c3);c4<=min(min(32*c3+30,32*c2-ny+31),tmax-1);c4++) { for (c5=32*c2;c5<=c4+ny-1;c5++) { S1(c1,-c1+c2,c4,-c4+c5) ; S3(c1,0,-c1+c2,c4,0,-c4+c5) ; for (c6=c4+1;c6<=32*c3+31;c6++) { S2(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,0,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } } for (c6=c4+1;c6<=32*c3+31;c6++) { S4(c1,0,-c1+c2,c4,-c4+c6-1,ny-1) ; } } } if (c1 == c3) { for (c4=max(max(0,32*c3),32*c2-ny+32);c4<=min(min(tmax-1,32*c3+30),32*c2-1);c4++) { for (c5=32*c2;c5<=32*c2+31;c5++) { S1(c1,-c1+c2,c4,-c4+c5) ; S3(c1,0,-c1+c2,c4,0,-c4+c5) ; for (c6=c4+1;c6<=32*c3+31;c6++) { S2(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,0,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } } } } if (c1 == c3) { for (c4=max(max(32*c2,0),32*c3);c4<=min(min(tmax-1,32*c3+30),32*c2+30);c4++) { S1(c1,-c1+c2,c4,0) ; for (c6=c4+1;c6<=32*c3+31;c6++) { S2(c1,0,-c1+c2,c4,-c4+c6,0) ; } for (c5=c4+1;c5<=32*c2+31;c5++) { S1(c1,-c1+c2,c4,-c4+c5) ; S3(c1,0,-c1+c2,c4,0,-c4+c5) ; for (c6=c4+1;c6<=32*c3+31;c6++) { S2(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,0,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,0,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } } } } for (c4=max(max(max(32*c1,0),32*c2-ny+1),32*c3-nx+1);c4<=min(min(min(32*c3-nx+31,32*c2-ny+31),32*c1+31),tmax-1);c4++) { for (c5=32*c2;c5<=c4+ny-1;c5++) { for (c6=32*c3;c6<=c4+nx-1;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } S4(c1,-c1+c3,-c1+c2,c4,nx-1,-c4+c5-1) ; } for (c6=32*c3;c6<=c4+nx;c6++) { S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,ny-1) ; } } for (c4=max(max(max(32*c1,0),32*c3-nx+1),32*c2-ny+32);c4<=min(min(min(tmax-1,32*c1+31),32*c2-1),32*c3-nx+31);c4++) { for (c5=32*c2;c5<=32*c2+31;c5++) { for (c6=32*c3;c6<=c4+nx-1;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } S4(c1,-c1+c3,-c1+c2,c4,nx-1,-c4+c5-1) ; } } for (c4=max(max(max(32*c3-nx+32,32*c1),0),32*c2-ny+1);c4<=min(min(min(32*c2-ny+31,32*c1+31),tmax-1),32*c3-1);c4++) { for (c5=32*c2;c5<=c4+ny-1;c5++) { for (c6=32*c3;c6<=32*c3+31;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } } for (c6=32*c3;c6<=32*c3+31;c6++) { S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,ny-1) ; } } for (c4=max(max(max(32*c2,32*c1),0),32*c3-nx+1);c4<=min(min(min(32*c2+30,tmax-1),32*c1+31),32*c3-nx+31);c4++) { for (c6=32*c3;c6<=c4+nx-1;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,0) ; } for (c5=c4+1;c5<=32*c2+31;c5++) { for (c6=32*c3;c6<=c4+nx-1;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } S4(c1,-c1+c3,-c1+c2,c4,nx-1,-c4+c5-1) ; } } for (c4=max(max(max(32*c1,0),32*c3-nx+32),32*c2-ny+32);c4<=min(min(min(32*c3-1,tmax-1),32*c1+31),32*c2-1);c4++) { /*@ begin Loop( transform Composite( tile = [('c5',T1,'ii'),('c6',T2,'jj')], permut = [PERMUTS], unrolljam = [('c5',U1),('c6',U2)], vector = (VEC, ['ivdep','vector always']) ) for (c5=32*c2;c5<=32*c2+31;c5++) for (c6=32*c3;c6<=32*c3+31;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } ) @*/{ for (c6=32*c3; c6<=32*c3+28; c6=c6+4) { register int cbv_1, cbv_2; cbv_1=32*c2; cbv_2=32*c2+31; #pragma ivdep #pragma vector always for (c5=cbv_1; c5<=cbv_2; c5=c5+1) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5); S2(c1,-c1+c3,-c1+c2,c4,-c4+c6+1,-c4+c5); S2(c1,-c1+c3,-c1+c2,c4,-c4+c6+2,-c4+c5); S2(c1,-c1+c3,-c1+c2,c4,-c4+c6+3,-c4+c5); S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5); S3(c1,-c1+c3,-c1+c2,c4,-c4+c6+1,-c4+c5); S3(c1,-c1+c3,-c1+c2,c4,-c4+c6+2,-c4+c5); S3(c1,-c1+c3,-c1+c2,c4,-c4+c6+3,-c4+c5); S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1); S4(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5-1); S4(c1,-c1+c3,-c1+c2,c4,-c4+c6+1,-c4+c5-1); S4(c1,-c1+c3,-c1+c2,c4,-c4+c6+2,-c4+c5-1); } } for (; c6<=32*c3+31; c6=c6+1) { register int cbv_3, cbv_4; cbv_3=32*c2; cbv_4=32*c2+31; #pragma ivdep #pragma vector always for (c5=cbv_3; c5<=cbv_4; c5=c5+1) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5); S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5); S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1); } } } /*@ end @*/ } for (c4=max(max(max(32*c2,32*c3-nx+32),32*c1),0);c4<=min(min(min(32*c3-1,32*c2+30),tmax-1),32*c1+31);c4++) { for (c6=32*c3;c6<=32*c3+31;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,0) ; } for (c5=c4+1;c5<=32*c2+31;c5++) { for (c6=32*c3;c6<=32*c3+31;c6++) { S2(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S3(c1,-c1+c3,-c1+c2,c4,-c4+c6,-c4+c5) ; S4(c1,-c1+c3,-c1+c2,c4,-c4+c6-1,-c4+c5-1) ; } } } if ((c1 == c3) && (c2 <= min(floord(32*c3-1,32),floord(tmax-32,32)))) { S1(c1,-c1+c2,32*c2+31,0) ; for (c6=32*c2+32;c6<=32*c3+31;c6++) { S2(c1,0,-c1+c2,32*c2+31,-32*c2+c6-31,0) ; } } if ((-c1 == -c3) && (c1 >= ceild(32*c2-31,32)) && (c1 <= min(floord(tmax-32,32),floord(32*c2-1,32)))) { S1(c1,-c1+c2,32*c1+31,0) ; for (c5=32*c1+32;c5<=32*c2+31;c5++) { S1(c1,-c1+c2,32*c1+31,-32*c1+c5-31) ; S3(c1,0,-c1+c2,32*c1+31,0,-32*c1+c5-31) ; } } if ((-c1 == -c3) && (c1 <= min(floord(tmax-32,32),c2-1))) { for (c5=32*c2;c5<=min(32*c2+31,32*c1+ny+30);c5++) { S1(c1,-c1+c2,32*c1+31,-32*c1+c5-31) ; S3(c1,0,-c1+c2,32*c1+31,0,-32*c1+c5-31) ; } } if ((-c1 == -c2) && (-c1 == -c3) && (c1 <= floord(tmax-32,32))) { S1(c1,0,32*c1+31,0) ; } if ((c1 >= c2) && (c2 <= min(c3-1,floord(tmax-32,32)))) { for (c6=32*c3;c6<=min(32*c2+nx+30,32*c3+31);c6++) { S2(c1,-c1+c3,-c1+c2,32*c2+31,-32*c2+c6-31,0) ; } } } } } annot_t_end = rtclock(); annot_t_total += annot_t_end - annot_t_start; } annot_t_total = annot_t_total / REPS; printf("%f\n", annot_t_total); return 1; }
static inline void sha256d_ms(uint32_t *hash, uint32_t *W, const uint32_t *midstate, const uint32_t *prehash) { uint32_t S[64]; uint32_t t0, t1; int i; S[18] = W[18]; S[19] = W[19]; S[20] = W[20]; S[22] = W[22]; S[23] = W[23]; S[24] = W[24]; S[30] = W[30]; S[31] = W[31]; W[18] += s0(W[3]); W[19] += W[3]; W[20] += s1(W[18]); W[21] = s1(W[19]); W[22] += s1(W[20]); W[23] += s1(W[21]); W[24] += s1(W[22]); W[25] = s1(W[23]) + W[18]; W[26] = s1(W[24]) + W[19]; W[27] = s1(W[25]) + W[20]; W[28] = s1(W[26]) + W[21]; W[29] = s1(W[27]) + W[22]; W[30] += s1(W[28]) + W[23]; W[31] += s1(W[29]) + W[24]; for (i = 32; i < 64; i += 2) { W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; W[i+1] = s1(W[i - 1]) + W[i - 6] + s0(W[i - 14]) + W[i - 15]; } memcpy(S, prehash, 32); RNDr(S, W, 3); RNDr(S, W, 4); RNDr(S, W, 5); RNDr(S, W, 6); RNDr(S, W, 7); RNDr(S, W, 8); RNDr(S, W, 9); RNDr(S, W, 10); RNDr(S, W, 11); RNDr(S, W, 12); RNDr(S, W, 13); RNDr(S, W, 14); RNDr(S, W, 15); RNDr(S, W, 16); RNDr(S, W, 17); RNDr(S, W, 18); RNDr(S, W, 19); RNDr(S, W, 20); RNDr(S, W, 21); RNDr(S, W, 22); RNDr(S, W, 23); RNDr(S, W, 24); RNDr(S, W, 25); RNDr(S, W, 26); RNDr(S, W, 27); RNDr(S, W, 28); RNDr(S, W, 29); RNDr(S, W, 30); RNDr(S, W, 31); RNDr(S, W, 32); RNDr(S, W, 33); RNDr(S, W, 34); RNDr(S, W, 35); RNDr(S, W, 36); RNDr(S, W, 37); RNDr(S, W, 38); RNDr(S, W, 39); RNDr(S, W, 40); RNDr(S, W, 41); RNDr(S, W, 42); RNDr(S, W, 43); RNDr(S, W, 44); RNDr(S, W, 45); RNDr(S, W, 46); RNDr(S, W, 47); RNDr(S, W, 48); RNDr(S, W, 49); RNDr(S, W, 50); RNDr(S, W, 51); RNDr(S, W, 52); RNDr(S, W, 53); RNDr(S, W, 54); RNDr(S, W, 55); RNDr(S, W, 56); RNDr(S, W, 57); RNDr(S, W, 58); RNDr(S, W, 59); RNDr(S, W, 60); RNDr(S, W, 61); RNDr(S, W, 62); RNDr(S, W, 63); for (i = 0; i < 8; i++) S[i] += midstate[i]; W[18] = S[18]; W[19] = S[19]; W[20] = S[20]; W[22] = S[22]; W[23] = S[23]; W[24] = S[24]; W[30] = S[30]; W[31] = S[31]; memcpy(S + 8, sha256d_hash1 + 8, 32); S[16] = s1(sha256d_hash1[14]) + sha256d_hash1[ 9] + s0(S[ 1]) + S[ 0]; S[17] = s1(sha256d_hash1[15]) + sha256d_hash1[10] + s0(S[ 2]) + S[ 1]; S[18] = s1(S[16]) + sha256d_hash1[11] + s0(S[ 3]) + S[ 2]; S[19] = s1(S[17]) + sha256d_hash1[12] + s0(S[ 4]) + S[ 3]; S[20] = s1(S[18]) + sha256d_hash1[13] + s0(S[ 5]) + S[ 4]; S[21] = s1(S[19]) + sha256d_hash1[14] + s0(S[ 6]) + S[ 5]; S[22] = s1(S[20]) + sha256d_hash1[15] + s0(S[ 7]) + S[ 6]; S[23] = s1(S[21]) + S[16] + s0(sha256d_hash1[ 8]) + S[ 7]; S[24] = s1(S[22]) + S[17] + s0(sha256d_hash1[ 9]) + sha256d_hash1[ 8]; S[25] = s1(S[23]) + S[18] + s0(sha256d_hash1[10]) + sha256d_hash1[ 9]; S[26] = s1(S[24]) + S[19] + s0(sha256d_hash1[11]) + sha256d_hash1[10]; S[27] = s1(S[25]) + S[20] + s0(sha256d_hash1[12]) + sha256d_hash1[11]; S[28] = s1(S[26]) + S[21] + s0(sha256d_hash1[13]) + sha256d_hash1[12]; S[29] = s1(S[27]) + S[22] + s0(sha256d_hash1[14]) + sha256d_hash1[13]; S[30] = s1(S[28]) + S[23] + s0(sha256d_hash1[15]) + sha256d_hash1[14]; S[31] = s1(S[29]) + S[24] + s0(S[16]) + sha256d_hash1[15]; for (i = 32; i < 60; i += 2) { S[i] = s1(S[i - 2]) + S[i - 7] + s0(S[i - 15]) + S[i - 16]; S[i+1] = s1(S[i - 1]) + S[i - 6] + s0(S[i - 14]) + S[i - 15]; } S[60] = s1(S[58]) + S[53] + s0(S[45]) + S[44]; sha256_init(hash); RNDr(hash, S, 0); RNDr(hash, S, 1); RNDr(hash, S, 2); RNDr(hash, S, 3); RNDr(hash, S, 4); RNDr(hash, S, 5); RNDr(hash, S, 6); RNDr(hash, S, 7); RNDr(hash, S, 8); RNDr(hash, S, 9); RNDr(hash, S, 10); RNDr(hash, S, 11); RNDr(hash, S, 12); RNDr(hash, S, 13); RNDr(hash, S, 14); RNDr(hash, S, 15); RNDr(hash, S, 16); RNDr(hash, S, 17); RNDr(hash, S, 18); RNDr(hash, S, 19); RNDr(hash, S, 20); RNDr(hash, S, 21); RNDr(hash, S, 22); RNDr(hash, S, 23); RNDr(hash, S, 24); RNDr(hash, S, 25); RNDr(hash, S, 26); RNDr(hash, S, 27); RNDr(hash, S, 28); RNDr(hash, S, 29); RNDr(hash, S, 30); RNDr(hash, S, 31); RNDr(hash, S, 32); RNDr(hash, S, 33); RNDr(hash, S, 34); RNDr(hash, S, 35); RNDr(hash, S, 36); RNDr(hash, S, 37); RNDr(hash, S, 38); RNDr(hash, S, 39); RNDr(hash, S, 40); RNDr(hash, S, 41); RNDr(hash, S, 42); RNDr(hash, S, 43); RNDr(hash, S, 44); RNDr(hash, S, 45); RNDr(hash, S, 46); RNDr(hash, S, 47); RNDr(hash, S, 48); RNDr(hash, S, 49); RNDr(hash, S, 50); RNDr(hash, S, 51); RNDr(hash, S, 52); RNDr(hash, S, 53); RNDr(hash, S, 54); RNDr(hash, S, 55); RNDr(hash, S, 56); hash[2] += hash[6] + S1(hash[3]) + Ch(hash[3], hash[4], hash[5]) + S[57] + sha256_k[57]; hash[1] += hash[5] + S1(hash[2]) + Ch(hash[2], hash[3], hash[4]) + S[58] + sha256_k[58]; hash[0] += hash[4] + S1(hash[1]) + Ch(hash[1], hash[2], hash[3]) + S[59] + sha256_k[59]; hash[7] += hash[3] + S1(hash[0]) + Ch(hash[0], hash[1], hash[2]) + S[60] + sha256_k[60] + sha256_h[7]; }
void sha1_core(const uint32_t M[16], uint32_t hash_value[5]) { uint32_t H0; uint32_t H1; uint32_t H2; uint32_t H3; uint32_t H4; uint32_t W[80]; uint32_t A, B, C, D, E, TEMP; int t; /* copy hash_value into H0, H1, H2, H3, H4 */ H0 = hash_value[0]; H1 = hash_value[1]; H2 = hash_value[2]; H3 = hash_value[3]; H4 = hash_value[4]; /* copy/xor message into array */ W[0] = bswap_32(M[0]); W[1] = bswap_32(M[1]); W[2] = bswap_32(M[2]); W[3] = bswap_32(M[3]); W[4] = bswap_32(M[4]); W[5] = bswap_32(M[5]); W[6] = bswap_32(M[6]); W[7] = bswap_32(M[7]); W[8] = bswap_32(M[8]); W[9] = bswap_32(M[9]); W[10] = bswap_32(M[10]); W[11] = bswap_32(M[11]); W[12] = bswap_32(M[12]); W[13] = bswap_32(M[13]); W[14] = bswap_32(M[14]); W[15] = bswap_32(M[15]); TEMP = W[13] ^ W[8] ^ W[2] ^ W[0]; W[16] = S1(TEMP); TEMP = W[14] ^ W[9] ^ W[3] ^ W[1]; W[17] = S1(TEMP); TEMP = W[15] ^ W[10] ^ W[4] ^ W[2]; W[18] = S1(TEMP); TEMP = W[16] ^ W[11] ^ W[5] ^ W[3]; W[19] = S1(TEMP); TEMP = W[17] ^ W[12] ^ W[6] ^ W[4]; W[20] = S1(TEMP); TEMP = W[18] ^ W[13] ^ W[7] ^ W[5]; W[21] = S1(TEMP); TEMP = W[19] ^ W[14] ^ W[8] ^ W[6]; W[22] = S1(TEMP); TEMP = W[20] ^ W[15] ^ W[9] ^ W[7]; W[23] = S1(TEMP); TEMP = W[21] ^ W[16] ^ W[10] ^ W[8]; W[24] = S1(TEMP); TEMP = W[22] ^ W[17] ^ W[11] ^ W[9]; W[25] = S1(TEMP); TEMP = W[23] ^ W[18] ^ W[12] ^ W[10]; W[26] = S1(TEMP); TEMP = W[24] ^ W[19] ^ W[13] ^ W[11]; W[27] = S1(TEMP); TEMP = W[25] ^ W[20] ^ W[14] ^ W[12]; W[28] = S1(TEMP); TEMP = W[26] ^ W[21] ^ W[15] ^ W[13]; W[29] = S1(TEMP); TEMP = W[27] ^ W[22] ^ W[16] ^ W[14]; W[30] = S1(TEMP); TEMP = W[28] ^ W[23] ^ W[17] ^ W[15]; W[31] = S1(TEMP); /* process the remainder of the array */ for (t=32; t < 80; t++) { TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]; W[t] = S1(TEMP); } A = H0; B = H1; C = H2; D = H3; E = H4; for (t=0; t < 20; t++) { TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 40; t++) { TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 60; t++) { TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 80; t++) { TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3; E = D; D = C; C = S30(B); B = A; A = TEMP; } hash_value[0] = H0 + A; hash_value[1] = H1 + B; hash_value[2] = H2 + C; hash_value[3] = H3 + D; hash_value[4] = H4 + E; return; }
static void mixer_test_controlA(HMIXER mix, LPMIXERCONTROLA control) { MMRESULT rc; if ((control->dwControlType == MIXERCONTROL_CONTROLTYPE_VOLUME) || (control->dwControlType == MIXERCONTROL_CONTROLTYPE_UNSIGNED)) { MIXERCONTROLDETAILS details; MIXERCONTROLDETAILS_UNSIGNED value; details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.dwControlID = control->dwControlID; details.cChannels = 1; U(details).cMultipleItems = 0; details.paDetails = &value; details.cbDetails = sizeof(value); /* read the current control value */ rc=mixerGetControlDetails((HMIXEROBJ)mix,&details,MIXER_GETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerGetControlDetails(MIXER_GETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR && winetest_interactive) { MIXERCONTROLDETAILS new_details; MIXERCONTROLDETAILS_UNSIGNED new_value; trace(" Value=%d\n",value.dwValue); if (value.dwValue + control->Metrics.cSteps < S1(control->Bounds).dwMaximum) new_value.dwValue = value.dwValue + control->Metrics.cSteps; else new_value.dwValue = value.dwValue - control->Metrics.cSteps; new_details.cbStruct = sizeof(MIXERCONTROLDETAILS); new_details.dwControlID = control->dwControlID; new_details.cChannels = 1; U(new_details).cMultipleItems = 0; new_details.paDetails = &new_value; new_details.cbDetails = sizeof(new_value); /* change the control value by one step */ rc=mixerSetControlDetails((HMIXEROBJ)mix,&new_details,MIXER_SETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerSetControlDetails(MIXER_SETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR) { MIXERCONTROLDETAILS ret_details; MIXERCONTROLDETAILS_UNSIGNED ret_value; ret_details.cbStruct = sizeof(MIXERCONTROLDETAILS); ret_details.dwControlID = control->dwControlID; ret_details.cChannels = 1; U(ret_details).cMultipleItems = 0; ret_details.paDetails = &ret_value; ret_details.cbDetails = sizeof(ret_value); /* read back the new control value */ rc=mixerGetControlDetails((HMIXEROBJ)mix,&ret_details,MIXER_GETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerGetControlDetails(MIXER_GETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR) { /* result may not match exactly because of rounding */ ok(abs(ret_value.dwValue-new_value.dwValue)<=1, "Couldn't change value from %d to %d, returned %d\n", value.dwValue,new_value.dwValue,ret_value.dwValue); if (abs(ret_value.dwValue-new_value.dwValue)<=1) { details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.dwControlID = control->dwControlID; details.cChannels = 1; U(details).cMultipleItems = 0; details.paDetails = &value; details.cbDetails = sizeof(value); /* restore original value */ rc=mixerSetControlDetails((HMIXEROBJ)mix,&details,MIXER_SETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerSetControlDetails(MIXER_SETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); } } } } } else if ((control->dwControlType == MIXERCONTROL_CONTROLTYPE_MUTE) || (control->dwControlType == MIXERCONTROL_CONTROLTYPE_BOOLEAN) || (control->dwControlType == MIXERCONTROL_CONTROLTYPE_BUTTON)) { MIXERCONTROLDETAILS details; MIXERCONTROLDETAILS_BOOLEAN value; details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.dwControlID = control->dwControlID; details.cChannels = 1; U(details).cMultipleItems = 0; details.paDetails = &value; details.cbDetails = sizeof(value); rc=mixerGetControlDetails((HMIXEROBJ)mix,&details,MIXER_GETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerGetControlDetails(MIXER_GETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR && winetest_interactive) { MIXERCONTROLDETAILS new_details; MIXERCONTROLDETAILS_BOOLEAN new_value; trace(" Value=%d\n",value.fValue); if (value.fValue == FALSE) new_value.fValue = TRUE; else new_value.fValue = FALSE; new_details.cbStruct = sizeof(MIXERCONTROLDETAILS); new_details.dwControlID = control->dwControlID; new_details.cChannels = 1; U(new_details).cMultipleItems = 0; new_details.paDetails = &new_value; new_details.cbDetails = sizeof(new_value); /* change the control value by one step */ rc=mixerSetControlDetails((HMIXEROBJ)mix,&new_details,MIXER_SETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerSetControlDetails(MIXER_SETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR) { MIXERCONTROLDETAILS ret_details; MIXERCONTROLDETAILS_BOOLEAN ret_value; ret_details.cbStruct = sizeof(MIXERCONTROLDETAILS); ret_details.dwControlID = control->dwControlID; ret_details.cChannels = 1; U(ret_details).cMultipleItems = 0; ret_details.paDetails = &ret_value; ret_details.cbDetails = sizeof(ret_value); /* read back the new control value */ rc=mixerGetControlDetails((HMIXEROBJ)mix,&ret_details,MIXER_GETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerGetControlDetails(MIXER_GETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); if (rc==MMSYSERR_NOERROR) { /* result may not match exactly because of rounding */ ok(ret_value.fValue==new_value.fValue, "Couldn't change value from %d to %d, returned %d\n", value.fValue,new_value.fValue,ret_value.fValue); if (ret_value.fValue==new_value.fValue) { details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.dwControlID = control->dwControlID; details.cChannels = 1; U(details).cMultipleItems = 0; details.paDetails = &value; details.cbDetails = sizeof(value); /* restore original value */ rc=mixerSetControlDetails((HMIXEROBJ)mix,&details,MIXER_SETCONTROLDETAILSF_VALUE); ok(rc==MMSYSERR_NOERROR,"mixerSetControlDetails(MIXER_SETCONTROLDETAILSF_VALUE): " "MMSYSERR_NOERROR expected, got %s\n", mmsys_error(rc)); } } } } } else { /* FIXME */ } }
TEST( Commission , EquivalenceClass ) { srand(time(NULL)); for( int times = 0 ; times < 100000 ; ++times ) { vector<tuple<int,int,int>> dataSets; int sets = rand()%10+5; bool VALID_FLAG = true; bool TERM_FLAG = false; bool LOCK_ERR_FLAG = false ,STOCK_ERR_FLAG = false ,BARREL_ERR_FLAG = false; for( int i = 0 ; i < sets ; ++i ) { int l = num() , s = num() , b = num(); if( !L1(l) || !S1(s) || !B1(b) ) VALID_FLAG = false; if( L2(l) ) TERM_FLAG = true; if( L3(l) || L4(l) ) LOCK_ERR_FLAG = true; if( S2(s) || S3(s) ) STOCK_ERR_FLAG = true; if( B2(b) || B3(b) ) BARREL_ERR_FLAG = true; dataSets.emplace_back(make_tuple(l,s,b)); if( TERM_FLAG ) break; } //add terminator if( !TERM_FLAG ) if( num() % 4 != 3 ) // 75% chance { dataSets.emplace_back(make_tuple(-1,0,0)); TERM_FLAG = true; } else VALID_FLAG = false; // for any error, result will be invalid if( LOCK_ERR_FLAG || STOCK_ERR_FLAG || BARREL_ERR_FLAG || !TERM_FLAG ) VALID_FLAG = false; double result = retrieve(dataSets); if( VALID_FLAG == true ) { ASSERT_TRUE( 0 <= result ) << "Result is Valid but return error"; } else { // error code must match the flag switch(cms_error_code) { case TERM_ERROR: ASSERT_TRUE(!TERM_FLAG); break; case LOCK_ERROR: ASSERT_TRUE(LOCK_ERR_FLAG); break; case STOCK_ERROR: ASSERT_TRUE(STOCK_ERR_FLAG); break; case BARREL_ERROR: ASSERT_TRUE(BARREL_ERR_FLAG); break; case OK: break; default: ASSERT_TRUE(false) << "Fatel Error ,Code = " << cms_error_code << endl; } } } }
/**************** * Transform the message W which consists of 16 64-bit-words */ static void transform (SHA512_CONTEXT *hd, byte *data) { u64 a, b, c, d, e, f, g, h; u64 w[80]; int t; static const u64 k[] = { U64_C(0x428a2f98d728ae22), U64_C(0x7137449123ef65cd), U64_C(0xb5c0fbcfec4d3b2f), U64_C(0xe9b5dba58189dbbc), U64_C(0x3956c25bf348b538), U64_C(0x59f111f1b605d019), U64_C(0x923f82a4af194f9b), U64_C(0xab1c5ed5da6d8118), U64_C(0xd807aa98a3030242), U64_C(0x12835b0145706fbe), U64_C(0x243185be4ee4b28c), U64_C(0x550c7dc3d5ffb4e2), U64_C(0x72be5d74f27b896f), U64_C(0x80deb1fe3b1696b1), U64_C(0x9bdc06a725c71235), U64_C(0xc19bf174cf692694), U64_C(0xe49b69c19ef14ad2), U64_C(0xefbe4786384f25e3), U64_C(0x0fc19dc68b8cd5b5), U64_C(0x240ca1cc77ac9c65), U64_C(0x2de92c6f592b0275), U64_C(0x4a7484aa6ea6e483), U64_C(0x5cb0a9dcbd41fbd4), U64_C(0x76f988da831153b5), U64_C(0x983e5152ee66dfab), U64_C(0xa831c66d2db43210), U64_C(0xb00327c898fb213f), U64_C(0xbf597fc7beef0ee4), U64_C(0xc6e00bf33da88fc2), U64_C(0xd5a79147930aa725), U64_C(0x06ca6351e003826f), U64_C(0x142929670a0e6e70), U64_C(0x27b70a8546d22ffc), U64_C(0x2e1b21385c26c926), U64_C(0x4d2c6dfc5ac42aed), U64_C(0x53380d139d95b3df), U64_C(0x650a73548baf63de), U64_C(0x766a0abb3c77b2a8), U64_C(0x81c2c92e47edaee6), U64_C(0x92722c851482353b), U64_C(0xa2bfe8a14cf10364), U64_C(0xa81a664bbc423001), U64_C(0xc24b8b70d0f89791), U64_C(0xc76c51a30654be30), U64_C(0xd192e819d6ef5218), U64_C(0xd69906245565a910), U64_C(0xf40e35855771202a), U64_C(0x106aa07032bbd1b8), U64_C(0x19a4c116b8d2d0c8), U64_C(0x1e376c085141ab53), U64_C(0x2748774cdf8eeb99), U64_C(0x34b0bcb5e19b48a8), U64_C(0x391c0cb3c5c95a63), U64_C(0x4ed8aa4ae3418acb), U64_C(0x5b9cca4f7763e373), U64_C(0x682e6ff3d6b2b8a3), U64_C(0x748f82ee5defb2fc), U64_C(0x78a5636f43172f60), U64_C(0x84c87814a1f0ab72), U64_C(0x8cc702081a6439ec), U64_C(0x90befffa23631e28), U64_C(0xa4506cebde82bde9), U64_C(0xbef9a3f7b2c67915), U64_C(0xc67178f2e372532b), U64_C(0xca273eceea26619c), U64_C(0xd186b8c721c0c207), U64_C(0xeada7dd6cde0eb1e), U64_C(0xf57d4f7fee6ed178), U64_C(0x06f067aa72176fba), U64_C(0x0a637dc5a2c898a6), U64_C(0x113f9804bef90dae), U64_C(0x1b710b35131c471b), U64_C(0x28db77f523047d84), U64_C(0x32caab7b40c72493), U64_C(0x3c9ebe0a15c9bebc), U64_C(0x431d67c49c100d4c), U64_C(0x4cc5d4becb3e42b6), U64_C(0x597f299cfc657e2a), U64_C(0x5fcb6fab3ad6faec), U64_C(0x6c44198c4a475817) }; /* get values from the chaining vars */ a = hd->h0; b = hd->h1; c = hd->h2; d = hd->h3; e = hd->h4; f = hd->h5; g = hd->h6; h = hd->h7; #ifdef WORDS_BIGENDIAN memcpy (w, data, 128); #else { int i; byte *p2; for (i = 0, p2 = (byte *) w; i < 16; i++, p2 += 8) { p2[7] = *data++; p2[6] = *data++; p2[5] = *data++; p2[4] = *data++; p2[3] = *data++; p2[2] = *data++; p2[1] = *data++; p2[0] = *data++; } } #endif #define ROTR(x,n) (((x)>>(n)) | ((x)<<(64-(n)))) #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) #define Sum0(x) (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39)) #define Sum1(x) (ROTR((x),14) ^ ROTR((x),18) ^ ROTR((x),41)) #define S0(x) (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7)) #define S1(x) (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6)) for (t = 16; t < 80; t++) w[t] = S1 (w[t - 2]) + w[t - 7] + S0 (w[t - 15]) + w[t - 16]; for (t = 0; t < 80; t++) { u64 t1, t2; t1 = h + Sum1 (e) + Ch (e, f, g) + k[t] + w[t]; t2 = Sum0 (a) + Maj (a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; /* printf("t=%d a=%016llX b=%016llX c=%016llX d=%016llX " "e=%016llX f=%016llX g=%016llX h=%016llX\n",t,a,b,c,d,e,f,g,h); */ } /* update chaining vars */ hd->h0 += a; hd->h1 += b; hd->h2 += c; hd->h3 += d; hd->h4 += e; hd->h5 += f; hd->h6 += g; hd->h7 += h; }
static void test_register_filter_with_null_clsMinorType(void) { IFilterMapper2 *pMapper = NULL; HRESULT hr; REGFILTER2 rgf2; REGFILTERPINS rgPins; REGFILTERPINS2 rgPins2; REGPINTYPES rgPinType; static WCHAR wszPinName[] = {'P', 'i', 'n', 0 }; static const WCHAR wszFilterName1[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '1', 0 }; static const WCHAR wszFilterName2[] = {'T', 'e', 's', 't', 'f', 'i', 'l', 't', 'e', 'r', '2', 0 }; CLSID clsidFilter1; CLSID clsidFilter2; hr = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC_SERVER, &IID_IFilterMapper2, (LPVOID*)&pMapper); ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr); if (FAILED(hr)) goto out; hr = CoCreateGuid(&clsidFilter1); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); hr = CoCreateGuid(&clsidFilter2); ok(hr == S_OK, "CoCreateGuid failed with %x\n", hr); rgPinType.clsMajorType = &GUID_NULL; /* Make sure quartz accepts it without crashing */ rgPinType.clsMinorType = NULL; /* Test with pin descript version 1 */ ZeroMemory(&rgf2, sizeof(rgf2)); rgf2.dwVersion = 1; rgf2.dwMerit = MERIT_UNLIKELY; S1(U(rgf2)).cPins = 1; S1(U(rgf2)).rgPins = &rgPins; rgPins.strName = wszPinName; rgPins.bRendered = 1; rgPins.bOutput = 0; rgPins.bZero = 0; rgPins.bMany = 0; rgPins.clsConnectsToFilter = NULL; rgPins.strConnectsToPin = NULL; rgPins.nMediaTypes = 1; rgPins.lpMediaType = &rgPinType; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter1, wszFilterName1, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); if (hr == E_ACCESSDENIED) { skip("Not authorized to register filters\n"); goto out; } ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter1); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); /* Test with pin descript version 2 */ ZeroMemory(&rgf2, sizeof(rgf2)); rgf2.dwVersion = 2; rgf2.dwMerit = MERIT_UNLIKELY; S2(U(rgf2)).cPins2 = 1; S2(U(rgf2)).rgPins2 = &rgPins2; rgPins2.dwFlags = REG_PINFLAG_B_RENDERER; rgPins2.cInstances = 1; rgPins2.nMediaTypes = 1; rgPins2.lpMediaType = &rgPinType; rgPins2.nMediums = 0; rgPins2.lpMedium = NULL; rgPins2.clsPinCategory = NULL; hr = IFilterMapper2_RegisterFilter(pMapper, &clsidFilter2, wszFilterName2, NULL, &CLSID_LegacyAmFilterCategory, NULL, &rgf2); ok(hr == S_OK, "IFilterMapper2_RegisterFilter failed with %x\n", hr); hr = IFilterMapper2_UnregisterFilter(pMapper, &CLSID_LegacyAmFilterCategory, NULL, &clsidFilter2); ok(hr == S_OK, "FilterMapper_UnregisterFilter failed with %x\n", hr); out: if (pMapper) IFilterMapper2_Release(pMapper); }
void sha1_final(sha1_ctx_t *ctx, uint32_t *output) { uint32_t A, B, C, D, E, TEMP; uint32_t W[80]; int i, t; /* * process the remaining octets_in_buffer, padding and terminating as * necessary */ { int tail = ctx->octets_in_buffer % 4; /* copy/xor message into array */ for (i=0; i < (ctx->octets_in_buffer+3)/4; i++) W[i] = bswap_32(ctx->M[i]); /* why no bswap_32() here? - DAM */ /* set the high bit of the octet immediately following the message */ switch (tail) { case (3): W[i-1] = (bswap_32(ctx->M[i-1]) & 0xffffff00) | 0x80; W[i] = 0x0; break; case (2): W[i-1] = (bswap_32(ctx->M[i-1]) & 0xffff0000) | 0x8000; W[i] = 0x0; break; case (1): W[i-1] = (bswap_32(ctx->M[i-1]) & 0xff000000) | 0x800000; W[i] = 0x0; break; case (0): W[i] = 0x80000000; break; } /* zeroize remaining words */ for (i++ ; i < 15; i++) W[i] = 0x0; /* * if there is room at the end of the word array, then set the * last word to the bit-length of the message; otherwise, set that * word to zero and then we need to do one more run of the * compression algo. */ if (ctx->octets_in_buffer < 56) W[15] = ctx->num_bits_in_msg; else W[15] = 0x0; /* process the word array */ for (t=16; t < 80; t++) { TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]; W[t] = S1(TEMP); } A = ctx->H[0]; B = ctx->H[1]; C = ctx->H[2]; D = ctx->H[3]; E = ctx->H[4]; for (t=0; t < 20; t++) { TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 40; t++) { TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 60; t++) { TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 80; t++) { TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3; E = D; D = C; C = S30(B); B = A; A = TEMP; } ctx->H[0] += A; ctx->H[1] += B; ctx->H[2] += C; ctx->H[3] += D; ctx->H[4] += E; } debug_print(mod_sha1, "(final) running sha1_core()", NULL); if (ctx->octets_in_buffer >= 56) { debug_print(mod_sha1, "(final) running sha1_core() again", NULL); /* we need to do one final run of the compression algo */ /* * set initial part of word array to zeros, and set the * final part to the number of bits in the message */ for (i=0; i < 15; i++) W[i] = 0x0; W[15] = ctx->num_bits_in_msg; /* process the word array */ for (t=16; t < 80; t++) { TEMP = W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]; W[t] = S1(TEMP); } A = ctx->H[0]; B = ctx->H[1]; C = ctx->H[2]; D = ctx->H[3]; E = ctx->H[4]; for (t=0; t < 20; t++) { TEMP = S5(A) + f0(B,C,D) + E + W[t] + SHA_K0; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 40; t++) { TEMP = S5(A) + f1(B,C,D) + E + W[t] + SHA_K1; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 60; t++) { TEMP = S5(A) + f2(B,C,D) + E + W[t] + SHA_K2; E = D; D = C; C = S30(B); B = A; A = TEMP; } for ( ; t < 80; t++) { TEMP = S5(A) + f3(B,C,D) + E + W[t] + SHA_K3; E = D; D = C; C = S30(B); B = A; A = TEMP; } ctx->H[0] += A; ctx->H[1] += B; ctx->H[2] += C; ctx->H[3] += D; ctx->H[4] += E; } /* copy result into output buffer */ output[0] = bswap_32(ctx->H[0]); output[1] = bswap_32(ctx->H[1]); output[2] = bswap_32(ctx->H[2]); output[3] = bswap_32(ctx->H[3]); output[4] = bswap_32(ctx->H[4]); /* indicate that message buffer in context is empty */ ctx->octets_in_buffer = 0; return; }
void test(int M) { if (M >= 0) { S1() ; } }
int __serpent_setkey(struct serpent_ctx *ctx, const u8 *key, unsigned int keylen) { u32 *k = ctx->expkey; u8 *k8 = (u8 *)k; u32 r0, r1, r2, r3, r4; int i; /* Copy key, add padding */ for (i = 0; i < keylen; ++i) k8[i] = key[i]; if (i < SERPENT_MAX_KEY_SIZE) k8[i++] = 1; while (i < SERPENT_MAX_KEY_SIZE) k8[i++] = 0; /* Expand key using polynomial */ r0 = le32_to_cpu(k[3]); r1 = le32_to_cpu(k[4]); r2 = le32_to_cpu(k[5]); r3 = le32_to_cpu(k[6]); r4 = le32_to_cpu(k[7]); keyiter(le32_to_cpu(k[0]), r0, r4, r2, 0, 0); keyiter(le32_to_cpu(k[1]), r1, r0, r3, 1, 1); keyiter(le32_to_cpu(k[2]), r2, r1, r4, 2, 2); keyiter(le32_to_cpu(k[3]), r3, r2, r0, 3, 3); keyiter(le32_to_cpu(k[4]), r4, r3, r1, 4, 4); keyiter(le32_to_cpu(k[5]), r0, r4, r2, 5, 5); keyiter(le32_to_cpu(k[6]), r1, r0, r3, 6, 6); keyiter(le32_to_cpu(k[7]), r2, r1, r4, 7, 7); keyiter(k[0], r3, r2, r0, 8, 8); keyiter(k[1], r4, r3, r1, 9, 9); keyiter(k[2], r0, r4, r2, 10, 10); keyiter(k[3], r1, r0, r3, 11, 11); keyiter(k[4], r2, r1, r4, 12, 12); keyiter(k[5], r3, r2, r0, 13, 13); keyiter(k[6], r4, r3, r1, 14, 14); keyiter(k[7], r0, r4, r2, 15, 15); keyiter(k[8], r1, r0, r3, 16, 16); keyiter(k[9], r2, r1, r4, 17, 17); keyiter(k[10], r3, r2, r0, 18, 18); keyiter(k[11], r4, r3, r1, 19, 19); keyiter(k[12], r0, r4, r2, 20, 20); keyiter(k[13], r1, r0, r3, 21, 21); keyiter(k[14], r2, r1, r4, 22, 22); keyiter(k[15], r3, r2, r0, 23, 23); keyiter(k[16], r4, r3, r1, 24, 24); keyiter(k[17], r0, r4, r2, 25, 25); keyiter(k[18], r1, r0, r3, 26, 26); keyiter(k[19], r2, r1, r4, 27, 27); keyiter(k[20], r3, r2, r0, 28, 28); keyiter(k[21], r4, r3, r1, 29, 29); keyiter(k[22], r0, r4, r2, 30, 30); keyiter(k[23], r1, r0, r3, 31, 31); k += 50; keyiter(k[-26], r2, r1, r4, 32, -18); keyiter(k[-25], r3, r2, r0, 33, -17); keyiter(k[-24], r4, r3, r1, 34, -16); keyiter(k[-23], r0, r4, r2, 35, -15); keyiter(k[-22], r1, r0, r3, 36, -14); keyiter(k[-21], r2, r1, r4, 37, -13); keyiter(k[-20], r3, r2, r0, 38, -12); keyiter(k[-19], r4, r3, r1, 39, -11); keyiter(k[-18], r0, r4, r2, 40, -10); keyiter(k[-17], r1, r0, r3, 41, -9); keyiter(k[-16], r2, r1, r4, 42, -8); keyiter(k[-15], r3, r2, r0, 43, -7); keyiter(k[-14], r4, r3, r1, 44, -6); keyiter(k[-13], r0, r4, r2, 45, -5); keyiter(k[-12], r1, r0, r3, 46, -4); keyiter(k[-11], r2, r1, r4, 47, -3); keyiter(k[-10], r3, r2, r0, 48, -2); keyiter(k[-9], r4, r3, r1, 49, -1); keyiter(k[-8], r0, r4, r2, 50, 0); keyiter(k[-7], r1, r0, r3, 51, 1); keyiter(k[-6], r2, r1, r4, 52, 2); keyiter(k[-5], r3, r2, r0, 53, 3); keyiter(k[-4], r4, r3, r1, 54, 4); keyiter(k[-3], r0, r4, r2, 55, 5); keyiter(k[-2], r1, r0, r3, 56, 6); keyiter(k[-1], r2, r1, r4, 57, 7); keyiter(k[0], r3, r2, r0, 58, 8); keyiter(k[1], r4, r3, r1, 59, 9); keyiter(k[2], r0, r4, r2, 60, 10); keyiter(k[3], r1, r0, r3, 61, 11); keyiter(k[4], r2, r1, r4, 62, 12); keyiter(k[5], r3, r2, r0, 63, 13); keyiter(k[6], r4, r3, r1, 64, 14); keyiter(k[7], r0, r4, r2, 65, 15); keyiter(k[8], r1, r0, r3, 66, 16); keyiter(k[9], r2, r1, r4, 67, 17); keyiter(k[10], r3, r2, r0, 68, 18); keyiter(k[11], r4, r3, r1, 69, 19); keyiter(k[12], r0, r4, r2, 70, 20); keyiter(k[13], r1, r0, r3, 71, 21); keyiter(k[14], r2, r1, r4, 72, 22); keyiter(k[15], r3, r2, r0, 73, 23); keyiter(k[16], r4, r3, r1, 74, 24); keyiter(k[17], r0, r4, r2, 75, 25); keyiter(k[18], r1, r0, r3, 76, 26); keyiter(k[19], r2, r1, r4, 77, 27); keyiter(k[20], r3, r2, r0, 78, 28); keyiter(k[21], r4, r3, r1, 79, 29); keyiter(k[22], r0, r4, r2, 80, 30); keyiter(k[23], r1, r0, r3, 81, 31); k += 50; keyiter(k[-26], r2, r1, r4, 82, -18); keyiter(k[-25], r3, r2, r0, 83, -17); keyiter(k[-24], r4, r3, r1, 84, -16); keyiter(k[-23], r0, r4, r2, 85, -15); keyiter(k[-22], r1, r0, r3, 86, -14); keyiter(k[-21], r2, r1, r4, 87, -13); keyiter(k[-20], r3, r2, r0, 88, -12); keyiter(k[-19], r4, r3, r1, 89, -11); keyiter(k[-18], r0, r4, r2, 90, -10); keyiter(k[-17], r1, r0, r3, 91, -9); keyiter(k[-16], r2, r1, r4, 92, -8); keyiter(k[-15], r3, r2, r0, 93, -7); keyiter(k[-14], r4, r3, r1, 94, -6); keyiter(k[-13], r0, r4, r2, 95, -5); keyiter(k[-12], r1, r0, r3, 96, -4); keyiter(k[-11], r2, r1, r4, 97, -3); keyiter(k[-10], r3, r2, r0, 98, -2); keyiter(k[-9], r4, r3, r1, 99, -1); keyiter(k[-8], r0, r4, r2, 100, 0); keyiter(k[-7], r1, r0, r3, 101, 1); keyiter(k[-6], r2, r1, r4, 102, 2); keyiter(k[-5], r3, r2, r0, 103, 3); keyiter(k[-4], r4, r3, r1, 104, 4); keyiter(k[-3], r0, r4, r2, 105, 5); keyiter(k[-2], r1, r0, r3, 106, 6); keyiter(k[-1], r2, r1, r4, 107, 7); keyiter(k[0], r3, r2, r0, 108, 8); keyiter(k[1], r4, r3, r1, 109, 9); keyiter(k[2], r0, r4, r2, 110, 10); keyiter(k[3], r1, r0, r3, 111, 11); keyiter(k[4], r2, r1, r4, 112, 12); keyiter(k[5], r3, r2, r0, 113, 13); keyiter(k[6], r4, r3, r1, 114, 14); keyiter(k[7], r0, r4, r2, 115, 15); keyiter(k[8], r1, r0, r3, 116, 16); keyiter(k[9], r2, r1, r4, 117, 17); keyiter(k[10], r3, r2, r0, 118, 18); keyiter(k[11], r4, r3, r1, 119, 19); keyiter(k[12], r0, r4, r2, 120, 20); keyiter(k[13], r1, r0, r3, 121, 21); keyiter(k[14], r2, r1, r4, 122, 22); keyiter(k[15], r3, r2, r0, 123, 23); keyiter(k[16], r4, r3, r1, 124, 24); keyiter(k[17], r0, r4, r2, 125, 25); keyiter(k[18], r1, r0, r3, 126, 26); keyiter(k[19], r2, r1, r4, 127, 27); keyiter(k[20], r3, r2, r0, 128, 28); keyiter(k[21], r4, r3, r1, 129, 29); keyiter(k[22], r0, r4, r2, 130, 30); keyiter(k[23], r1, r0, r3, 131, 31); /* Apply S-boxes */ S3(r3, r4, r0, r1, r2); store_and_load_keys(r1, r2, r4, r3, 28, 24); S4(r1, r2, r4, r3, r0); store_and_load_keys(r2, r4, r3, r0, 24, 20); S5(r2, r4, r3, r0, r1); store_and_load_keys(r1, r2, r4, r0, 20, 16); S6(r1, r2, r4, r0, r3); store_and_load_keys(r4, r3, r2, r0, 16, 12); S7(r4, r3, r2, r0, r1); store_and_load_keys(r1, r2, r0, r4, 12, 8); S0(r1, r2, r0, r4, r3); store_and_load_keys(r0, r2, r4, r1, 8, 4); S1(r0, r2, r4, r1, r3); store_and_load_keys(r3, r4, r1, r0, 4, 0); S2(r3, r4, r1, r0, r2); store_and_load_keys(r2, r4, r3, r0, 0, -4); S3(r2, r4, r3, r0, r1); store_and_load_keys(r0, r1, r4, r2, -4, -8); S4(r0, r1, r4, r2, r3); store_and_load_keys(r1, r4, r2, r3, -8, -12); S5(r1, r4, r2, r3, r0); store_and_load_keys(r0, r1, r4, r3, -12, -16); S6(r0, r1, r4, r3, r2); store_and_load_keys(r4, r2, r1, r3, -16, -20); S7(r4, r2, r1, r3, r0); store_and_load_keys(r0, r1, r3, r4, -20, -24); S0(r0, r1, r3, r4, r2); store_and_load_keys(r3, r1, r4, r0, -24, -28); k -= 50; S1(r3, r1, r4, r0, r2); store_and_load_keys(r2, r4, r0, r3, 22, 18); S2(r2, r4, r0, r3, r1); store_and_load_keys(r1, r4, r2, r3, 18, 14); S3(r1, r4, r2, r3, r0); store_and_load_keys(r3, r0, r4, r1, 14, 10); S4(r3, r0, r4, r1, r2); store_and_load_keys(r0, r4, r1, r2, 10, 6); S5(r0, r4, r1, r2, r3); store_and_load_keys(r3, r0, r4, r2, 6, 2); S6(r3, r0, r4, r2, r1); store_and_load_keys(r4, r1, r0, r2, 2, -2); S7(r4, r1, r0, r2, r3); store_and_load_keys(r3, r0, r2, r4, -2, -6); S0(r3, r0, r2, r4, r1); store_and_load_keys(r2, r0, r4, r3, -6, -10); S1(r2, r0, r4, r3, r1); store_and_load_keys(r1, r4, r3, r2, -10, -14); S2(r1, r4, r3, r2, r0); store_and_load_keys(r0, r4, r1, r2, -14, -18); S3(r0, r4, r1, r2, r3); store_and_load_keys(r2, r3, r4, r0, -18, -22); k -= 50; S4(r2, r3, r4, r0, r1); store_and_load_keys(r3, r4, r0, r1, 28, 24); S5(r3, r4, r0, r1, r2); store_and_load_keys(r2, r3, r4, r1, 24, 20); S6(r2, r3, r4, r1, r0); store_and_load_keys(r4, r0, r3, r1, 20, 16); S7(r4, r0, r3, r1, r2); store_and_load_keys(r2, r3, r1, r4, 16, 12); S0(r2, r3, r1, r4, r0); store_and_load_keys(r1, r3, r4, r2, 12, 8); S1(r1, r3, r4, r2, r0); store_and_load_keys(r0, r4, r2, r1, 8, 4); S2(r0, r4, r2, r1, r3); store_and_load_keys(r3, r4, r0, r1, 4, 0); S3(r3, r4, r0, r1, r2); storekeys(r1, r2, r4, r3, 0); return 0; }
void _stdcall serpent256_set_key(const unsigned char *key, serpent256_key *skey) { u32 *k = skey->expkey; u32 r0,r1,r2,r3,r4; /* Copy key, add padding */ memcpy(k, key, SERPENT_KEY_SIZE); /* Expand key using polynomial */ r0 = k[3]; r1 = k[4]; r2 = k[5]; r3 = k[6]; r4 = k[7]; keyiter(k[0],r0,r4,r2,0,0); keyiter(k[1],r1,r0,r3,1,1); keyiter(k[2],r2,r1,r4,2,2); keyiter(k[3],r3,r2,r0,3,3); keyiter(k[4],r4,r3,r1,4,4); keyiter(k[5],r0,r4,r2,5,5); keyiter(k[6],r1,r0,r3,6,6); keyiter(k[7],r2,r1,r4,7,7); keyiter(k[ 0],r3,r2,r0, 8, 8); keyiter(k[ 1],r4,r3,r1, 9, 9); keyiter(k[ 2],r0,r4,r2, 10, 10); keyiter(k[ 3],r1,r0,r3, 11, 11); keyiter(k[ 4],r2,r1,r4, 12, 12); keyiter(k[ 5],r3,r2,r0, 13, 13); keyiter(k[ 6],r4,r3,r1, 14, 14); keyiter(k[ 7],r0,r4,r2, 15, 15); keyiter(k[ 8],r1,r0,r3, 16, 16); keyiter(k[ 9],r2,r1,r4, 17, 17); keyiter(k[ 10],r3,r2,r0, 18, 18); keyiter(k[ 11],r4,r3,r1, 19, 19); keyiter(k[ 12],r0,r4,r2, 20, 20); keyiter(k[ 13],r1,r0,r3, 21, 21); keyiter(k[ 14],r2,r1,r4, 22, 22); keyiter(k[ 15],r3,r2,r0, 23, 23); keyiter(k[ 16],r4,r3,r1, 24, 24); keyiter(k[ 17],r0,r4,r2, 25, 25); keyiter(k[ 18],r1,r0,r3, 26, 26); keyiter(k[ 19],r2,r1,r4, 27, 27); keyiter(k[ 20],r3,r2,r0, 28, 28); keyiter(k[ 21],r4,r3,r1, 29, 29); keyiter(k[ 22],r0,r4,r2, 30, 30); keyiter(k[ 23],r1,r0,r3, 31, 31); k += 50; keyiter(k[-26],r2,r1,r4, 32,-18); keyiter(k[-25],r3,r2,r0, 33,-17); keyiter(k[-24],r4,r3,r1, 34,-16); keyiter(k[-23],r0,r4,r2, 35,-15); keyiter(k[-22],r1,r0,r3, 36,-14); keyiter(k[-21],r2,r1,r4, 37,-13); keyiter(k[-20],r3,r2,r0, 38,-12); keyiter(k[-19],r4,r3,r1, 39,-11); keyiter(k[-18],r0,r4,r2, 40,-10); keyiter(k[-17],r1,r0,r3, 41, -9); keyiter(k[-16],r2,r1,r4, 42, -8); keyiter(k[-15],r3,r2,r0, 43, -7); keyiter(k[-14],r4,r3,r1, 44, -6); keyiter(k[-13],r0,r4,r2, 45, -5); keyiter(k[-12],r1,r0,r3, 46, -4); keyiter(k[-11],r2,r1,r4, 47, -3); keyiter(k[-10],r3,r2,r0, 48, -2); keyiter(k[ -9],r4,r3,r1, 49, -1); keyiter(k[ -8],r0,r4,r2, 50, 0); keyiter(k[ -7],r1,r0,r3, 51, 1); keyiter(k[ -6],r2,r1,r4, 52, 2); keyiter(k[ -5],r3,r2,r0, 53, 3); keyiter(k[ -4],r4,r3,r1, 54, 4); keyiter(k[ -3],r0,r4,r2, 55, 5); keyiter(k[ -2],r1,r0,r3, 56, 6); keyiter(k[ -1],r2,r1,r4, 57, 7); keyiter(k[ 0],r3,r2,r0, 58, 8); keyiter(k[ 1],r4,r3,r1, 59, 9); keyiter(k[ 2],r0,r4,r2, 60, 10); keyiter(k[ 3],r1,r0,r3, 61, 11); keyiter(k[ 4],r2,r1,r4, 62, 12); keyiter(k[ 5],r3,r2,r0, 63, 13); keyiter(k[ 6],r4,r3,r1, 64, 14); keyiter(k[ 7],r0,r4,r2, 65, 15); keyiter(k[ 8],r1,r0,r3, 66, 16); keyiter(k[ 9],r2,r1,r4, 67, 17); keyiter(k[ 10],r3,r2,r0, 68, 18); keyiter(k[ 11],r4,r3,r1, 69, 19); keyiter(k[ 12],r0,r4,r2, 70, 20); keyiter(k[ 13],r1,r0,r3, 71, 21); keyiter(k[ 14],r2,r1,r4, 72, 22); keyiter(k[ 15],r3,r2,r0, 73, 23); keyiter(k[ 16],r4,r3,r1, 74, 24); keyiter(k[ 17],r0,r4,r2, 75, 25); keyiter(k[ 18],r1,r0,r3, 76, 26); keyiter(k[ 19],r2,r1,r4, 77, 27); keyiter(k[ 20],r3,r2,r0, 78, 28); keyiter(k[ 21],r4,r3,r1, 79, 29); keyiter(k[ 22],r0,r4,r2, 80, 30); keyiter(k[ 23],r1,r0,r3, 81, 31); k += 50; keyiter(k[-26],r2,r1,r4, 82,-18); keyiter(k[-25],r3,r2,r0, 83,-17); keyiter(k[-24],r4,r3,r1, 84,-16); keyiter(k[-23],r0,r4,r2, 85,-15); keyiter(k[-22],r1,r0,r3, 86,-14); keyiter(k[-21],r2,r1,r4, 87,-13); keyiter(k[-20],r3,r2,r0, 88,-12); keyiter(k[-19],r4,r3,r1, 89,-11); keyiter(k[-18],r0,r4,r2, 90,-10); keyiter(k[-17],r1,r0,r3, 91, -9); keyiter(k[-16],r2,r1,r4, 92, -8); keyiter(k[-15],r3,r2,r0, 93, -7); keyiter(k[-14],r4,r3,r1, 94, -6); keyiter(k[-13],r0,r4,r2, 95, -5); keyiter(k[-12],r1,r0,r3, 96, -4); keyiter(k[-11],r2,r1,r4, 97, -3); keyiter(k[-10],r3,r2,r0, 98, -2); keyiter(k[ -9],r4,r3,r1, 99, -1); keyiter(k[ -8],r0,r4,r2,100, 0); keyiter(k[ -7],r1,r0,r3,101, 1); keyiter(k[ -6],r2,r1,r4,102, 2); keyiter(k[ -5],r3,r2,r0,103, 3); keyiter(k[ -4],r4,r3,r1,104, 4); keyiter(k[ -3],r0,r4,r2,105, 5); keyiter(k[ -2],r1,r0,r3,106, 6); keyiter(k[ -1],r2,r1,r4,107, 7); keyiter(k[ 0],r3,r2,r0,108, 8); keyiter(k[ 1],r4,r3,r1,109, 9); keyiter(k[ 2],r0,r4,r2,110, 10); keyiter(k[ 3],r1,r0,r3,111, 11); keyiter(k[ 4],r2,r1,r4,112, 12); keyiter(k[ 5],r3,r2,r0,113, 13); keyiter(k[ 6],r4,r3,r1,114, 14); keyiter(k[ 7],r0,r4,r2,115, 15); keyiter(k[ 8],r1,r0,r3,116, 16); keyiter(k[ 9],r2,r1,r4,117, 17); keyiter(k[ 10],r3,r2,r0,118, 18); keyiter(k[ 11],r4,r3,r1,119, 19); keyiter(k[ 12],r0,r4,r2,120, 20); keyiter(k[ 13],r1,r0,r3,121, 21); keyiter(k[ 14],r2,r1,r4,122, 22); keyiter(k[ 15],r3,r2,r0,123, 23); keyiter(k[ 16],r4,r3,r1,124, 24); keyiter(k[ 17],r0,r4,r2,125, 25); keyiter(k[ 18],r1,r0,r3,126, 26); keyiter(k[ 19],r2,r1,r4,127, 27); keyiter(k[ 20],r3,r2,r0,128, 28); keyiter(k[ 21],r4,r3,r1,129, 29); keyiter(k[ 22],r0,r4,r2,130, 30); keyiter(k[ 23],r1,r0,r3,131, 31); /* Apply S-boxes */ S3(r3,r4,r0,r1,r2); storekeys(r1,r2,r4,r3, 28); loadkeys(r1,r2,r4,r3, 24); S4(r1,r2,r4,r3,r0); storekeys(r2,r4,r3,r0, 24); loadkeys(r2,r4,r3,r0, 20); S5(r2,r4,r3,r0,r1); storekeys(r1,r2,r4,r0, 20); loadkeys(r1,r2,r4,r0, 16); S6(r1,r2,r4,r0,r3); storekeys(r4,r3,r2,r0, 16); loadkeys(r4,r3,r2,r0, 12); S7(r4,r3,r2,r0,r1); storekeys(r1,r2,r0,r4, 12); loadkeys(r1,r2,r0,r4, 8); S0(r1,r2,r0,r4,r3); storekeys(r0,r2,r4,r1, 8); loadkeys(r0,r2,r4,r1, 4); S1(r0,r2,r4,r1,r3); storekeys(r3,r4,r1,r0, 4); loadkeys(r3,r4,r1,r0, 0); S2(r3,r4,r1,r0,r2); storekeys(r2,r4,r3,r0, 0); loadkeys(r2,r4,r3,r0, -4); S3(r2,r4,r3,r0,r1); storekeys(r0,r1,r4,r2, -4); loadkeys(r0,r1,r4,r2, -8); S4(r0,r1,r4,r2,r3); storekeys(r1,r4,r2,r3, -8); loadkeys(r1,r4,r2,r3,-12); S5(r1,r4,r2,r3,r0); storekeys(r0,r1,r4,r3,-12); loadkeys(r0,r1,r4,r3,-16); S6(r0,r1,r4,r3,r2); storekeys(r4,r2,r1,r3,-16); loadkeys(r4,r2,r1,r3,-20); S7(r4,r2,r1,r3,r0); storekeys(r0,r1,r3,r4,-20); loadkeys(r0,r1,r3,r4,-24); S0(r0,r1,r3,r4,r2); storekeys(r3,r1,r4,r0,-24); loadkeys(r3,r1,r4,r0,-28); k -= 50; S1(r3,r1,r4,r0,r2); storekeys(r2,r4,r0,r3, 22); loadkeys(r2,r4,r0,r3, 18); S2(r2,r4,r0,r3,r1); storekeys(r1,r4,r2,r3, 18); loadkeys(r1,r4,r2,r3, 14); S3(r1,r4,r2,r3,r0); storekeys(r3,r0,r4,r1, 14); loadkeys(r3,r0,r4,r1, 10); S4(r3,r0,r4,r1,r2); storekeys(r0,r4,r1,r2, 10); loadkeys(r0,r4,r1,r2, 6); S5(r0,r4,r1,r2,r3); storekeys(r3,r0,r4,r2, 6); loadkeys(r3,r0,r4,r2, 2); S6(r3,r0,r4,r2,r1); storekeys(r4,r1,r0,r2, 2); loadkeys(r4,r1,r0,r2, -2); S7(r4,r1,r0,r2,r3); storekeys(r3,r0,r2,r4, -2); loadkeys(r3,r0,r2,r4, -6); S0(r3,r0,r2,r4,r1); storekeys(r2,r0,r4,r3, -6); loadkeys(r2,r0,r4,r3,-10); S1(r2,r0,r4,r3,r1); storekeys(r1,r4,r3,r2,-10); loadkeys(r1,r4,r3,r2,-14); S2(r1,r4,r3,r2,r0); storekeys(r0,r4,r1,r2,-14); loadkeys(r0,r4,r1,r2,-18); S3(r0,r4,r1,r2,r3); storekeys(r2,r3,r4,r0,-18); loadkeys(r2,r3,r4,r0,-22); k -= 50; S4(r2,r3,r4,r0,r1); storekeys(r3,r4,r0,r1, 28); loadkeys(r3,r4,r0,r1, 24); S5(r3,r4,r0,r1,r2); storekeys(r2,r3,r4,r1, 24); loadkeys(r2,r3,r4,r1, 20); S6(r2,r3,r4,r1,r0); storekeys(r4,r0,r3,r1, 20); loadkeys(r4,r0,r3,r1, 16); S7(r4,r0,r3,r1,r2); storekeys(r2,r3,r1,r4, 16); loadkeys(r2,r3,r1,r4, 12); S0(r2,r3,r1,r4,r0); storekeys(r1,r3,r4,r2, 12); loadkeys(r1,r3,r4,r2, 8); S1(r1,r3,r4,r2,r0); storekeys(r0,r4,r2,r1, 8); loadkeys(r0,r4,r2,r1, 4); S2(r0,r4,r2,r1,r3); storekeys(r3,r4,r0,r1, 4); loadkeys(r3,r4,r0,r1, 0); S3(r3,r4,r0,r1,r2); storekeys(r1,r2,r4,r3, 0); }
void executor_cpack_align(int n_inter,int n_moles,int n_tstep,double data[][9],int * inter1,int * inter2,ExplicitRelation **sigma) { ExplicitRelation * cpack_input_ER; ExplicitRelation * sigma_ER; ExplicitRelation * inter1_ER; ExplicitRelation * inter2_ER; int i,ii,ii_out0,tstep; inter1_ER=ER_ctor(inter1,n_inter+-1-0); inter2_ER=ER_ctor(inter2,n_inter+-1-0); sigma_ER=*sigma; /* Define the executor main loop body statments */ /* data[ %(a1)s ][ 3 ] += data[ %(a1)s ][ 0 ] + data[ %(a1)s ][ 6 ]; data[ %(a1)s ][ 4 ] += data[ %(a1)s ][ 1 ] + data[ %(a1)s ][ 7 ]; data[ %(a1)s ][ 5 ] += data[ %(a1)s ][ 2 ] + data[ %(a1)s ][ 8 ]; if (data[ %(a1)s ][ 3 ] < 0.0) data[ %(a1)s ][ 3 ] += side; if (data[ %(a1)s ][ 3 ] > side) data[ %(a1)s ][ 3 ] -= side; if (data[ %(a1)s ][ 4 ] < 0.0) data[ %(a1)s ][ 4 ] += side; if (data[ %(a1)s ][ 4 ] > side) data[ %(a1)s ][ 4 ] -= side; if (data[ %(a1)s ][ 5 ] < 0.0) data[ %(a1)s ][ 5 ] += side; if (data[ %(a1)s ][ 5 ] > side) data[ %(a1)s ][ 5 ] -= side; data[ %(a1)s ][ 0 ] += data[ %(a1)s ][ 6 ]; data[ %(a1)s ][ 1 ] += data[ %(a1)s ][ 7 ]; data[ %(a1)s ][ 2 ] += data[ %(a1)s ][ 8 ]; data[ %(a1)s ][ 6 ] = 0.0; data[ %(a1)s ][ 7 ] = 0.0; data[ %(a1)s ][ 8 ] = 0.0; */ /* a1: {[tstep,i]->[sigma_out1]: -1sigma_out1+i=0} */ #define S0(tstep,i) data[ i ][ 3 ] += data[ i ][ 0 ] + data[ i ][ 6 ];\ data[ i ][ 4 ] += data[ i ][ 1 ] + data[ i ][ 7 ];\ data[ i ][ 5 ] += data[ i ][ 2 ] + data[ i ][ 8 ];\ if (data[ i ][ 3 ] < 0.0) data[ i ][ 3 ] += side;\ if (data[ i ][ 3 ] > side) data[ i ][ 3 ] -= side;\ if (data[ i ][ 4 ] < 0.0) data[ i ][ 4 ] += side;\ if (data[ i ][ 4 ] > side) data[ i ][ 4 ] -= side;\ if (data[ i ][ 5 ] < 0.0) data[ i ][ 5 ] += side;\ if (data[ i ][ 5 ] > side) data[ i ][ 5 ] -= side;\ data[ i ][ 0 ] += data[ i ][ 6 ];\ data[ i ][ 1 ] += data[ i ][ 7 ];\ data[ i ][ 2 ] += data[ i ][ 8 ];\ data[ i ][ 6 ] = 0.0;\ data[ i ][ 7 ] = 0.0;\ data[ i ][ 8 ] = 0.0; /* cutoffSquare = cutoffRadius * cutoffRadius; n_inter = ninter; vir = 0.0; epot = 0.0; */ #define S1(tstep) cutoffSquare = cutoffRadius * cutoffRadius;\ n_inter = ninter;\ vir = 0.0;\ epot = 0.0; /* xx = data[ %(a31)s ][ 3 ] - data[ %(a32)s ][ 3 ]; yy = data[ %(a31)s ][ 4 ] - data[ %(a32)s ][ 4 ]; zz = data[ %(a31)s ][ 5 ] - data[ %(a32)s ][ 5 ]; if (xx < -sideHalf) xx += side; if (yy < -sideHalf) yy += side; if (zz < -sideHalf) zz += side; if (xx > sideHalf) xx -= side; if (yy > sideHalf) yy -= side; if (zz > sideHalf) zz -= side; rd = (xx * xx + yy * yy + zz * zz); if (rd < cutoffSquare) { rrd = 1.0 / rd; rrd2 = rrd * rrd; rrd3 = rrd2 * rrd; rrd4 = rrd2 * rrd2; rrd6 = rrd2 * rrd4; rrd7 = rrd6 * rrd; r148 = rrd7 - 0.5 * rrd4; forcex = xx * r148; forcey = yy * r148; forcez = zz * r148; data[ %(a31)s ][ 6 ] += forcex; data[ %(a31)s ][ 7 ] += forcey; data[ %(a31)s ][ 8 ] += forcez; data[ %(a32)s ][ 6 ] -= forcex; data[ %(a32)s ][ 7 ] -= forcey; data[ %(a32)s ][ 8 ] -= forcez; vir -= rd * r148; epot += (rrd6 - rrd3); } */ /* a32: {[tstep,ii]->[sigma_out1]: sigma_out1+-1sigma(inter2(ii))=0} */ /* a31: {[tstep,ii]->[sigma_out1]: sigma_out1+-1sigma(inter1(ii))=0} */ #define S2(tstep,ii) xx = data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 3 ] - data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 3 ];\ yy = data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 4 ] - data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 4 ];\ zz = data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 5 ] - data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 5 ];\ if (xx < -sideHalf) xx += side;\ if (yy < -sideHalf) yy += side;\ if (zz < -sideHalf) zz += side;\ if (xx > sideHalf) xx -= side;\ if (yy > sideHalf) yy -= side;\ if (zz > sideHalf) zz -= side;\ rd = (xx * xx + yy * yy + zz * zz);\ if (rd < cutoffSquare) \ {\ rrd = 1.0 / rd;\ rrd2 = rrd * rrd;\ rrd3 = rrd2 * rrd;\ rrd4 = rrd2 * rrd2;\ rrd6 = rrd2 * rrd4;\ rrd7 = rrd6 * rrd;\ r148 = rrd7 - 0.5 * rrd4;\ forcex = xx * r148;\ forcey = yy * r148;\ forcez = zz * r148;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 6 ] += forcex;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 7 ] += forcey;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter1_ER,ii)) ][ 8 ] += forcez;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 6 ] -= forcex;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 7 ] -= forcey;\ data[ ER_out_given_in(sigma_ER,ER_out_given_in(inter2_ER,ii)) ][ 8 ] -= forcez;\ vir -= rd * r148;\ epot += (rrd6 - rrd3);\ } /* data[ %(a43)s ][ 6 ] *= timeStepSqHalf; data[ %(a43)s ][ 7 ] *= timeStepSqHalf; data[ %(a43)s ][ 8 ] *= timeStepSqHalf; data[ %(a43)s ][ 0 ] += data[ %(a43)s ][ 6 ]; data[ %(a43)s ][ 1 ] += data[ %(a43)s ][ 7 ]; data[ %(a43)s ][ 2 ] += data[ %(a43)s ][ 8 ]; */ /* a43: {[tstep,i]->[sigma_out1]: -1sigma_out1+i=0} */ #define S3(tstep,i) data[ i ][ 6 ] *= timeStepSqHalf;\ data[ i ][ 7 ] *= timeStepSqHalf;\ data[ i ][ 8 ] *= timeStepSqHalf;\ data[ i ][ 0 ] += data[ i ][ 6 ];\ data[ i ][ 1 ] += data[ i ][ 7 ];\ data[ i ][ 2 ] += data[ i ][ 8 ]; /* The executor main loop */ if (n_tstep >= 1) { if ((n_inter >= 1) && (n_moles >= 1)) { for (tstep=0;tstep<=n_tstep-1;tstep++) { for (i=0;i<=n_moles-1;i++) { S0(tstep,i); } S1(tstep); for (i=0;i<=n_inter-1;i++) { S2(tstep,i); } for (i=0;i<=n_moles-1;i++) { S3(tstep,i); } } } if ((n_inter <= 0) && (n_moles >= 1)) { for (tstep=0;tstep<=n_tstep-1;tstep++) { for (i=0;i<=n_moles-1;i++) { S0(tstep,i); } S1(tstep); for (i=0;i<=n_moles-1;i++) { S3(tstep,i); } } } if ((n_inter >= 1) && (n_moles <= 0)) { for (tstep=0;tstep<=n_tstep-1;tstep++) { S1(tstep); for (i=0;i<=n_inter-1;i++) { S2(tstep,i); } } } if ((n_inter <= 0) && (n_moles <= 0)) { for (tstep=0;tstep<=n_tstep-1;tstep++) { S1(tstep); } } } /* Undefine the executor main loop body statments */ #undef S0 #undef S1 #undef S2 #undef S3 }
void test(int M, int N) { /* Scattering iterators. */ int c2, c4, c6; /* Original iterators. */ int i, j, k; if ((M <= -1) && (N >= 1)) { S1(0) ; } if ((M >= 0) && (N >= 1)) { S1(0) ; } if ((M >= 1) && (N >= 2)) { for (c4=0;c4<=M-1;c4++) { S2(0,c4) ; } S3(0) ; for (c4=0;c4<=M-1;c4++) { S4(0,c4) ; } S10(0) ; S1(1) ; S5(0) ; } if ((M <= 0) && (N >= 2)) { S3(0) ; S10(0) ; S1(1) ; S5(0) ; } if ((M >= 1) && (N == 1)) { for (c4=0;c4<=M-1;c4++) { S2(0,c4) ; } S3(0) ; for (c4=0;c4<=M-1;c4++) { S4(0,c4) ; } S10(0) ; S5(0) ; } if ((M <= 0) && (N == 1)) { S3(0) ; S10(0) ; S5(0) ; } for (c2=2;c2<=min(N-1,M);c2++) { for (c4=c2-1;c4<=N-1;c4++) { i = c2-2 ; S6(c2-2,c4) ; for (c6=c2-2;c6<=M-1;c6++) { i = c2-2 ; S7(c2-2,c4,c6) ; } i = c2-2 ; S8(c2-2,c4) ; for (c6=c2-2;c6<=M-1;c6++) { i = c2-2 ; S9(c2-2,c4,c6) ; } } for (c4=c2-1;c4<=M-1;c4++) { i = c2-1 ; S2(c2-1,c4) ; } i = c2-1 ; S3(c2-1) ; for (c4=c2-1;c4<=M-1;c4++) { i = c2-1 ; S4(c2-1,c4) ; } i = c2-1 ; S10(c2-1) ; S1(c2) ; i = c2-1 ; S5(c2-1) ; } if ((M >= 1) && (M <= N-2)) { c2 = M+1 ; for (c4=M;c4<=N-1;c4++) { i = M-1 ; S6(M-1,c4) ; c6 = M-1 ; i = M-1 ; k = M-1 ; S7(M-1,c4,M-1) ; i = M-1 ; S8(M-1,c4) ; c6 = M-1 ; i = M-1 ; k = M-1 ; S9(M-1,c4,M-1) ; } S3(M) ; S10(M) ; i = M+1 ; S1(M+1) ; S5(M) ; } if ((M >= N) && (N >= 2)) { c4 = N-1 ; i = N-2 ; j = N-1 ; S6(N-2,N-1) ; for (c6=N-2;c6<=M-1;c6++) { i = N-2 ; j = N-1 ; S7(N-2,N-1,c6) ; } i = N-2 ; j = N-1 ; S8(N-2,N-1) ; for (c6=N-2;c6<=M-1;c6++) { i = N-2 ; j = N-1 ; S9(N-2,N-1,c6) ; } for (c4=N-1;c4<=M-1;c4++) { i = N-1 ; S2(N-1,c4) ; } i = N-1 ; S3(N-1) ; for (c4=N-1;c4<=M-1;c4++) { i = N-1 ; S4(N-1,c4) ; } i = N-1 ; S10(N-1) ; i = N-1 ; S5(N-1) ; } if ((M == N-1) && (N >= 2)) { c4 = N-1 ; i = N-2 ; j = N-1 ; S6(N-2,N-1) ; c6 = N-2 ; i = N-2 ; j = N-1 ; k = N-2 ; S7(N-2,N-1,N-2) ; i = N-2 ; j = N-1 ; S8(N-2,N-1) ; c6 = N-2 ; i = N-2 ; j = N-1 ; k = N-2 ; S9(N-2,N-1,N-2) ; i = N-1 ; S3(N-1) ; i = N-1 ; S10(N-1) ; i = N-1 ; S5(N-1) ; } for (c2=max(M+2,2);c2<=N-1;c2++) { for (c4=c2-1;c4<=N-1;c4++) { i = c2-2 ; S6(c2-2,c4) ; i = c2-2 ; S8(c2-2,c4) ; } i = c2-1 ; S3(c2-1) ; i = c2-1 ; S10(c2-1) ; S1(c2) ; i = c2-1 ; S5(c2-1) ; } if ((M <= N-2) && (N >= 2)) { c4 = N-1 ; i = N-2 ; j = N-1 ; S6(N-2,N-1) ; i = N-2 ; j = N-1 ; S8(N-2,N-1) ; i = N-1 ; S3(N-1) ; i = N-1 ; S10(N-1) ; i = N-1 ; S5(N-1) ; } }
/**************** * Transform the message W which consists of 16 64-bit-words */ static void transform (SHA512_CONTEXT *hd, const unsigned char *data) { u64 a, b, c, d, e, f, g, h; u64 w[80]; int t; static const u64 k[] = { U64_C(0x428a2f98d728ae22), U64_C(0x7137449123ef65cd), U64_C(0xb5c0fbcfec4d3b2f), U64_C(0xe9b5dba58189dbbc), U64_C(0x3956c25bf348b538), U64_C(0x59f111f1b605d019), U64_C(0x923f82a4af194f9b), U64_C(0xab1c5ed5da6d8118), U64_C(0xd807aa98a3030242), U64_C(0x12835b0145706fbe), U64_C(0x243185be4ee4b28c), U64_C(0x550c7dc3d5ffb4e2), U64_C(0x72be5d74f27b896f), U64_C(0x80deb1fe3b1696b1), U64_C(0x9bdc06a725c71235), U64_C(0xc19bf174cf692694), U64_C(0xe49b69c19ef14ad2), U64_C(0xefbe4786384f25e3), U64_C(0x0fc19dc68b8cd5b5), U64_C(0x240ca1cc77ac9c65), U64_C(0x2de92c6f592b0275), U64_C(0x4a7484aa6ea6e483), U64_C(0x5cb0a9dcbd41fbd4), U64_C(0x76f988da831153b5), U64_C(0x983e5152ee66dfab), U64_C(0xa831c66d2db43210), U64_C(0xb00327c898fb213f), U64_C(0xbf597fc7beef0ee4), U64_C(0xc6e00bf33da88fc2), U64_C(0xd5a79147930aa725), U64_C(0x06ca6351e003826f), U64_C(0x142929670a0e6e70), U64_C(0x27b70a8546d22ffc), U64_C(0x2e1b21385c26c926), U64_C(0x4d2c6dfc5ac42aed), U64_C(0x53380d139d95b3df), U64_C(0x650a73548baf63de), U64_C(0x766a0abb3c77b2a8), U64_C(0x81c2c92e47edaee6), U64_C(0x92722c851482353b), U64_C(0xa2bfe8a14cf10364), U64_C(0xa81a664bbc423001), U64_C(0xc24b8b70d0f89791), U64_C(0xc76c51a30654be30), U64_C(0xd192e819d6ef5218), U64_C(0xd69906245565a910), U64_C(0xf40e35855771202a), U64_C(0x106aa07032bbd1b8), U64_C(0x19a4c116b8d2d0c8), U64_C(0x1e376c085141ab53), U64_C(0x2748774cdf8eeb99), U64_C(0x34b0bcb5e19b48a8), U64_C(0x391c0cb3c5c95a63), U64_C(0x4ed8aa4ae3418acb), U64_C(0x5b9cca4f7763e373), U64_C(0x682e6ff3d6b2b8a3), U64_C(0x748f82ee5defb2fc), U64_C(0x78a5636f43172f60), U64_C(0x84c87814a1f0ab72), U64_C(0x8cc702081a6439ec), U64_C(0x90befffa23631e28), U64_C(0xa4506cebde82bde9), U64_C(0xbef9a3f7b2c67915), U64_C(0xc67178f2e372532b), U64_C(0xca273eceea26619c), U64_C(0xd186b8c721c0c207), U64_C(0xeada7dd6cde0eb1e), U64_C(0xf57d4f7fee6ed178), U64_C(0x06f067aa72176fba), U64_C(0x0a637dc5a2c898a6), U64_C(0x113f9804bef90dae), U64_C(0x1b710b35131c471b), U64_C(0x28db77f523047d84), U64_C(0x32caab7b40c72493), U64_C(0x3c9ebe0a15c9bebc), U64_C(0x431d67c49c100d4c), U64_C(0x4cc5d4becb3e42b6), U64_C(0x597f299cfc657e2a), U64_C(0x5fcb6fab3ad6faec), U64_C(0x6c44198c4a475817) }; /* get values from the chaining vars */ a = hd->h0; b = hd->h1; c = hd->h2; d = hd->h3; e = hd->h4; f = hd->h5; g = hd->h6; h = hd->h7; #ifdef WORDS_BIGENDIAN memcpy (w, data, 128); #else { int i; byte *p2; for (i = 0, p2 = (byte *) w; i < 16; i++, p2 += 8) { p2[7] = *data++; p2[6] = *data++; p2[5] = *data++; p2[4] = *data++; p2[3] = *data++; p2[2] = *data++; p2[1] = *data++; p2[0] = *data++; } } #endif #define S0(x) (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7)) #define S1(x) (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6)) for (t = 16; t < 80; t++) w[t] = S1 (w[t - 2]) + w[t - 7] + S0 (w[t - 15]) + w[t - 16]; for (t = 0; t < 80; ) { u64 t1, t2; /* Performance on a AMD Athlon(tm) Dual Core Processor 4050e with gcc 4.3.3 using gcry_md_hash_buffer of each 10000 bytes initialized to 0,1,2,3...255,0,... and 1000 iterations: Not unrolled with macros: 440ms Unrolled with macros: 350ms Unrolled with inline: 330ms */ #if 1 /* Not unrolled. */ t1 = h + Sum1 (e) + Ch (e, f, g) + k[t] + w[t]; t2 = Sum0 (a) + Maj (a, b, c); h = g; g = f; f = e; e = d + t1; d = c; c = b; b = a; a = t1 + t2; t++; #else /* Unrolled to interweave the chain variables. */ t1 = h + Sum1 (e) + Ch (e, f, g) + k[t] + w[t]; t2 = Sum0 (a) + Maj (a, b, c); d += t1; h = t1 + t2; t1 = g + Sum1 (d) + Ch (d, e, f) + k[t+1] + w[t+1]; t2 = Sum0 (h) + Maj (h, a, b); c += t1; g = t1 + t2; t1 = f + Sum1 (c) + Ch (c, d, e) + k[t+2] + w[t+2]; t2 = Sum0 (g) + Maj (g, h, a); b += t1; f = t1 + t2; t1 = e + Sum1 (b) + Ch (b, c, d) + k[t+3] + w[t+3]; t2 = Sum0 (f) + Maj (f, g, h); a += t1; e = t1 + t2; t1 = d + Sum1 (a) + Ch (a, b, c) + k[t+4] + w[t+4]; t2 = Sum0 (e) + Maj (e, f, g); h += t1; d = t1 + t2; t1 = c + Sum1 (h) + Ch (h, a, b) + k[t+5] + w[t+5]; t2 = Sum0 (d) + Maj (d, e, f); g += t1; c = t1 + t2; t1 = b + Sum1 (g) + Ch (g, h, a) + k[t+6] + w[t+6]; t2 = Sum0 (c) + Maj (c, d, e); f += t1; b = t1 + t2; t1 = a + Sum1 (f) + Ch (f, g, h) + k[t+7] + w[t+7]; t2 = Sum0 (b) + Maj (b, c, d); e += t1; a = t1 + t2; t += 8; #endif } /* Update chaining vars. */ hd->h0 += a; hd->h1 += b; hd->h2 += c; hd->h3 += d; hd->h4 += e; hd->h5 += f; hd->h6 += g; hd->h7 += h; }
static void transform (SHA256_CONTEXT *hd, byte *data) { static const u32 K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; u32 a,b,c,d,e,f,g,h,t1,t2; u32 x[16]; u32 w[64]; int i; a = hd->h0; b = hd->h1; c = hd->h2; d = hd->h3; e = hd->h4; f = hd->h5; g = hd->h6; h = hd->h7; #ifdef WORDS_BIGENDIAN memcpy (x, data, 64); #else { byte *p2; for (i=0, p2=(byte*)x; i < 16; i++, p2 += 4 ) { p2[3] = *data++; p2[2] = *data++; p2[1] = *data++; p2[0] = *data++; } } #endif for (i=0; i < 16; i++) w[i] = x[i]; for (; i < 64; i++) w[i] = S1(w[i-2]) + w[i-7] + S0(w[i-15]) + w[i-16]; for (i=0; i < 64; i++) R(a,b,c,d,e,f,g,h,K[i],w[i]); hd->h0 += a; hd->h1 += b; hd->h2 += c; hd->h3 += d; hd->h4 += e; hd->h5 += f; hd->h6 += g; hd->h7 += h; }
int main() { init_arrays(); double annot_t_start=0, annot_t_end=0, annot_t_total=0; int annot_i; for (annot_i=0; annot_i<REPS; annot_i++) { annot_t_start = rtclock(); #include <math.h> #include <assert.h> #define ceild(n,d) ceil(((double)(n))/((double)(d))) #define floord(n,d) floor(((double)(n))/((double)(d))) #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) #define S1(zT0,zT1,zT2,zT3,zT4,zT5,t,i,j) {A[i][j]=(A[1+i][1+j]+A[1+i][j]+A[1+i][j-1]+A[i][1+j]+A[i][j]+A[i][j-1]+A[i-1][1+j]+A[i-1][j]+A[i-1][j-1])/9;} int c1, c2, c3, c4, c5, c6, c7, c8, c9; register int lb, ub, lb1, ub1, lb2, ub2; register int lbv, ubv; omp_set_nested(1); omp_set_num_threads(2); /* Generated from PLuTo-produced CLooG file by CLooG v0.14.1 64 bits in 5.45s. */ for (c1=-2;c1<=floord(4*T+3*N-10,256);c1++) { lb1=max(max(max(0,ceild(256*c1-2*T-N-251,512)),ceild(256*c1-3*T-2*N+7,256)),ceild(256*c1-N-761,1024)); ub1=min(min(min(floord(256*c1+2*N+505,1024),floord(256*c1+509,512)),floord(64*c1+127,64)),floord(T+N-3,256)); #pragma omp parallel for shared(c1,lb1,ub1) private(lb2,ub2,c2,c3,c4,c5,c6,c7,c8,c9) for (c2=lb1; c2<=ub1; c2++) { lb2=max(max(max(max(max(max(ceild(256*c1-256*c2-T+1,256),ceild(512*c1-512*c2-253,768)),0),ceild(512*c2-N-252,256)),ceild(128*c1-256*c2-127,128)),ceild(128*c2-127,128)),ceild(128*c1-127,256)); ub2=min(min(min(min(min(min(floord(256*c1-256*c2+255,256),floord(256*c1-512*c2+N+253,256)),floord(256*c2+T+N+252,256)),floord(T+N-3,128)),floord(256*c1+N+508,512)),floord(256*c1-256*c2+N+253,384)),floord(512*c2+N+507,256)); #pragma omp parallel for shared(c1,c2,lb1,ub1,lb2,ub2) private(c3,c4,c5,c6,c7,c8,c9) for (c3=lb2; c3<=ub2; c3++) { for (c4=max(max(max(max(0,ceild(-256*c2+256*c3-N-284,32)),8*c1-8*c2-8*c3),ceild(256*c2-N-29,32)),ceild(128*c3-N-29,32));c4<=min(min(min(min(8*c1-8*c2-8*c3+7,floord(256*c3+253,64)),floord(T-1,32)),floord(128*c2+127,16)),floord(-128*c2+128*c3+127,16));c4++) { for (c5=max(max(max(max(max(8*c2,ceild(16*c4-15,16)),ceild(256*c3-T-N-28,32)),0),ceild(256*c3-32*c4-N-60,32)),ceild(256*c3-N-59,64));c5<=min(min(min(min(min(floord(32*c4+N+29,32),floord(128*c3+127,16)),8*c2+7),floord(128*c3-16*c4+127,16)),floord(T+N-3,32)),floord(256*c3+N+252,64));c5++) { for (c6=max(max(max(max(max(ceild(64*c4-29,32),8*c3),ceild(16*c5-15,16)),ceild(16*c4+16*c5-15,16)),0),ceild(64*c5-N-28,32));c6<=min(min(min(min(min(8*c3+7,floord(T+N-3,16)),floord(32*c4+32*c5+N+60,32)),floord(32*c4+N+29,16)),floord(64*c5+N+59,32)),floord(32*c5+T+N+28,32));c6++) { for (c7=max(max(max(max(0,32*c4),32*c5-N+2),16*c6-N+2),-32*c5+32*c6-N-29);c7<=min(min(min(min(-32*c5+32*c6+30,floord(32*c6+29,2)),T-1),32*c5+30),32*c4+31);c7++) { /*@ begin Loop( transform UnrollJam(ufactor=8) for (c8=max(max(32*c5,c7+1),32*c6-c7-N+2);c8<=min(min(32*c6-c7+30,32*c5+31),c7+N-2);c8++) transform Unroll(ufactor=8) for (c9=max(c7+c8+1,32*c6);c9<=min(32*c6+31,c7+c8+N-2);c9++) { S1(c1-c2-c3,-c1+2*c2+c3,-c1+2*c3,c4,-c4+c5,-c4-c5+c6,c7,-c7+c8,-c7-c8+c9) ; } ) @*/ for (c8=max(max(32*c5,c7+1),32*c6-c7-N+2);c8<=min(min(32*c6-c7+30,32*c5+31),c7+N-2);c8++) { for (c9=max(c7+c8+1,32*c6);c9<=min(32*c6+31,c7+c8+N-2);c9++) { S1(c1-c2-c3,-c1+2*c2+c3,-c1+2*c3,c4,-c4+c5,-c4-c5+c6,c7,-c7+c8,-c7-c8+c9) ; } } /*@ end @*/ } } } } } } } /* End of CLooG code */ annot_t_end = rtclock(); annot_t_total += annot_t_end - annot_t_start; } annot_t_total = annot_t_total / REPS; printf("%f\n", annot_t_total); return ((int) A[0][0]); }
/* The SHA-256 core: Transform the message X which consists of 16 32-bit-words. See FIPS 180-2 for details. */ static void transform (hmac256_context_t hd, const void *data_arg) { const unsigned char *data = data_arg; #define Cho(x,y,z) (z ^ (x & (y ^ z))) /* (4.2) same as SHA-1's F1 */ #define Maj(x,y,z) ((x & y) | (z & (x|y))) /* (4.3) same as SHA-1's F3 */ #define Sum0(x) (ror ((x), 2) ^ ror ((x), 13) ^ ror ((x), 22)) /* (4.4) */ #define Sum1(x) (ror ((x), 6) ^ ror ((x), 11) ^ ror ((x), 25)) /* (4.5) */ #define S0(x) (ror ((x), 7) ^ ror ((x), 18) ^ ((x) >> 3)) /* (4.6) */ #define S1(x) (ror ((x), 17) ^ ror ((x), 19) ^ ((x) >> 10)) /* (4.7) */ #define R(a,b,c,d,e,f,g,h,k,w) do \ { \ t1 = (h) + Sum1((e)) + Cho((e),(f),(g)) + (k) + (w); \ t2 = Sum0((a)) + Maj((a),(b),(c)); \ h = g; \ g = f; \ f = e; \ e = d + t1; \ d = c; \ c = b; \ b = a; \ a = t1 + t2; \ } while (0) static const u32 K[64] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 }; u32 a, b, c, d, e, f, g, h, t1, t2; u32 x[16]; u32 w[64]; int i; a = hd->h0; b = hd->h1; c = hd->h2; d = hd->h3; e = hd->h4; f = hd->h5; g = hd->h6; h = hd->h7; #ifdef WORDS_BIGENDIAN memcpy (x, data, 64); #else /*!WORDS_BIGENDIAN*/ { unsigned char *p2; for (i=0, p2=(unsigned char*)x; i < 16; i++, p2 += 4 ) { p2[3] = *data++; p2[2] = *data++; p2[1] = *data++; p2[0] = *data++; } } #endif /*!WORDS_BIGENDIAN*/ for (i=0; i < 16; i++) w[i] = x[i]; for (; i < 64; i++) w[i] = S1(w[i-2]) + w[i-7] + S0(w[i-15]) + w[i-16]; for (i=0; i < 64; i++) R(a,b,c,d,e,f,g,h,K[i],w[i]); hd->h0 += a; hd->h1 += b; hd->h2 += c; hd->h3 += d; hd->h4 += e; hd->h5 += f; hd->h6 += g; hd->h7 += h; }
template < typename T > S2 s (S3 < T > s3) { S1 (s3, 0); }
void test(int n) { /* Scattering iterators. */ int t1, t2, t3; /* Original iterators. */ int i, j, k; if (n >= 1) { t1 = -n+1 ; t2 = n+1 ; for (t3=n+3;t3<=3*n+1;t3++) { if ((t3+n+1)%2 == 0) { k = (t3-n-1)/2 ; S1(1,n,(t3-n-1)/2) ; } } } if ((n >= 2) && (n <= 2)) { t1 = -n+2 ; for (t2=-n+4;t2<=3*n-2;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t2+n)%2 == 0) { i = (t2-n+2)/2 ; j = (t2+n-2)/2 ; if ((t3+n)%2 == 0) { k = (-t2+t3)/2 ; S1((t2-n+2)/2,(t2+n-2)/2,(-t2+t3)/2) ; } } } } t2 = n+3 ; for (t3=1;t3<=n;t3++) { S2(1,n,t3) ; } } if (n >= 3) { t1 = -n+2 ; for (t2=n;t2<=n+2;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t2+n)%2 == 0) { i = (t2-n+2)/2 ; j = (t2+n-2)/2 ; if ((t3+n)%2 == 0) { k = (-t2+t3)/2 ; S1((t2-n+2)/2,(t2+n-2)/2,(-t2+t3)/2) ; } } } } t2 = n+3 ; for (t3=1;t3<=n;t3++) { S2(1,n,t3) ; } } for (t1=ceild(-2*n+5,2);t1<=min(-n+6,-1);t1++) { for (t2=-t1+2;t2<=-t1+4;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+5;t2<=t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } t2 = t1+2*n+1 ; for (t3=1;t3<=n;t3++) { i = t1+n-1 ; S2(t1+n-1,n,t3) ; } } if (n == 2) { for (t3=5;t3<=7;t3++) { if ((t3+1)%2 == 0) { k = (t3-3)/2 ; S1(2,1,(t3-3)/2) ; } } for (t2=4;t2<=6;t2++) { for (t3=1;t3<=2;t3++) { if (t2%2 == 0) { i = (t2-2)/2 ; j = (t2-2)/2 ; S2((t2-2)/2,(t2-2)/2,t3) ; } } } } for (t1=-n+7;t1<=-1;t1++) { for (t2=-t1+2;t2<=-t1+4;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+5;t2<=n-2;t2++) { for (t3=1;t3<=t2+1;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } for (t3=n+1;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=n-1;t2<=t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } t2 = t1+2*n+1 ; for (t3=1;t3<=n;t3++) { i = t1+n-1 ; S2(t1+n-1,n,t3) ; } } if (n >= 3) { for (t1=0;t1<=min(1,-n+6);t1++) { for (t2=t1+2;t2<=-t1+4;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+5;t2<=-t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+2*n+1;t2<=t1+2*n+1;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } } } } for (t1=max(-n+7,0);t1<=1;t1++) { for (t2=t1+2;t2<=-t1+4;t2++) { for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+5;t2<=n-2;t2++) { for (t3=1;t3<=t2+1;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } for (t3=n+1;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=n-1;t2<=-t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+2*n+1;t2<=t1+2*n+1;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } } } for (t1=2;t1<=n-5;t1++) { t2 = t1+2 ; for (t3=t1+4;t3<=t1+2*n+2;t3++) { i = t1+1 ; if ((t1+t3)%2 == 0) { k = (-t1+t3-2)/2 ; S1(t1+1,1,(-t1+t3-2)/2) ; } } for (t2=t1+3;t2<=n-2;t2++) { for (t3=1;t3<=t2+1;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } for (t3=n+1;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=n-1;t2<=-t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+2*n+1;t2<=-t1+2*n+3;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } } } for (t1=max(2,n-4);t1<=floord(2*n-3,2);t1++) { t2 = t1+2 ; for (t3=t1+4;t3<=t1+2*n+2;t3++) { i = t1+1 ; if ((t1+t3)%2 == 0) { k = (-t1+t3-2)/2 ; S1(t1+1,1,(-t1+t3-2)/2) ; } } for (t2=t1+3;t2<=-t1+2*n;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } for (t3=t2+2;t3<=t2+2*n;t3++) { if ((t1+t2)%2 == 0) { i = (t1+t2)/2 ; j = (-t1+t2)/2 ; if ((t1+t3)%2 == 0) { k = (-t2+t3)/2 ; S1((t1+t2)/2,(-t1+t2)/2,(-t2+t3)/2) ; } } } } for (t2=-t1+2*n+1;t2<=-t1+2*n+3;t2++) { for (t3=1;t3<=n;t3++) { if ((t1+t2+1)%2 == 0) { i = (t1+t2-3)/2 ; j = (-t1+t2-1)/2 ; S2((t1+t2-3)/2,(-t1+t2-1)/2,t3) ; } } } } if (n >= 3) { t1 = n-1 ; t2 = n+1 ; for (t3=n+3;t3<=3*n+1;t3++) { if ((t3+n+1)%2 == 0) { k = (t3-n-1)/2 ; S1(n,1,(t3-n-1)/2) ; } } for (t2=n+2;t2<=n+4;t2++) { for (t3=1;t3<=n;t3++) { if ((t2+n)%2 == 0) { i = (t2+n-4)/2 ; j = (t2-n)/2 ; S2((t2+n-4)/2,(t2-n)/2,t3) ; } } } } if (n >= 1) { t2 = n+3 ; for (t3=1;t3<=n;t3++) { S2(n,1,t3) ; } } }
mlib_status mlib_ImagePolynomialWarp_0_BC( mlib_image *dst, const mlib_image *src, mlib_d64 wx, mlib_d64 wy) { mlib_d64 a0, a1, a2, a3; mlib_d64 r0, r1, r2, r3, res; mlib_d64 fx0, fx1, fx2, fx3; mlib_d64 fy0, fy1, fy2, fy3; mlib_d64 dx, dy; mlib_s32 i, srcYStride, srcChannels, color[4]; mlib_type srcType; mlib_d64 limit_lo, limit_hi; srcType = mlib_ImageGetType(src); srcYStride = mlib_ImageGetStride(src); srcChannels = mlib_ImageGetChannels(src); dx = wx - (mlib_s32)wx; dy = wy - (mlib_s32)wy; fx0 = S0(dx); fx1 = S1(dx); fx2 = S2(dx); fx3 = S3(dx); fy0 = S0(dy); fy1 = S1(dy); fy2 = S2(dy); fy3 = S3(dy); switch (srcType) { case MLIB_BYTE: { mlib_u8 *srcData0, *srcData = mlib_ImageGetData(src); limit_lo = MLIB_U8_MIN; limit_hi = MLIB_U8_MAX; srcData = srcData + ((mlib_s32)wy - 1) * srcYStride; srcData += ((mlib_s32)wx - 1) * srcChannels; CALC_BICUBIC; } break; case MLIB_SHORT: { mlib_s16 *srcData0, *srcData = mlib_ImageGetData(src); limit_lo = MLIB_S16_MIN; limit_hi = MLIB_S16_MAX; srcData = (void *)((mlib_u8 *)srcData + ((mlib_s32)wy - 1) * srcYStride); srcData += ((mlib_s32)wx - 1) * srcChannels; CALC_BICUBIC; } break; case MLIB_USHORT: { mlib_u16 *srcData0, *srcData = mlib_ImageGetData(src); limit_lo = MLIB_U16_MIN; limit_hi = MLIB_U16_MAX; srcData = (void *)((mlib_u8 *)srcData + ((mlib_s32)wy - 1) * srcYStride); srcData += ((mlib_s32)wx - 1) * srcChannels; CALC_BICUBIC; } break; case MLIB_INT: { mlib_s32 *srcData0, *srcData = mlib_ImageGetData(src); limit_lo = MLIB_S32_MIN; limit_hi = MLIB_S32_MAX; srcData = (void *)((mlib_u8 *)srcData + ((mlib_s32)wy - 1) * srcYStride); srcData += ((mlib_s32)wx - 1) * srcChannels; CALC_BICUBIC; } break; default: return (MLIB_FAILURE); } return (__mlib_ImageClear(dst, color)); }
void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) { if (object == &Obj && Prop.getTypeId() == Part::PropertyGeometryList::getClassTypeId()) { const Part::PropertyGeometryList& geom = static_cast<const Part::PropertyGeometryList&>(Prop); const std::vector<Part::Geometry*>& items = geom.getValues(); if (items.size() != 2) return; Part::Geometry* g1 = items[0]; Part::Geometry* g2 = items[1]; if (!g1 || g1->getTypeId() != Part::GeomArcOfCircle::getClassTypeId()) return; if (!g2 || g2->getTypeId() != Part::GeomLineSegment::getClassTypeId()) return; Part::GeomArcOfCircle* arc = static_cast<Part::GeomArcOfCircle*>(g1); Part::GeomLineSegment* seg = static_cast<Part::GeomLineSegment*>(g2); try { Base::Vector3d m1 = arc->getCenter(); //Base::Vector3d a3 = arc->getStartPoint(); Base::Vector3d a3 = arc->getEndPoint(true); //Base::Vector3d l1 = seg->getStartPoint(); Base::Vector3d l2 = seg->getEndPoint(); #if 0 Py::Module pd("FilletArc"); Py::Callable method(pd.getAttr(std::string("makeFilletArc"))); Py::Callable vector(pd.getAttr(std::string("Vector"))); Py::Tuple xyz(3); Py::Tuple args(6); xyz.setItem(0, Py::Float(m1.x)); xyz.setItem(1, Py::Float(m1.y)); xyz.setItem(2, Py::Float(m1.z)); args.setItem(0,vector.apply(xyz)); xyz.setItem(0, Py::Float(a3.x)); xyz.setItem(1, Py::Float(a3.y)); xyz.setItem(2, Py::Float(a3.z)); args.setItem(1,vector.apply(xyz)); xyz.setItem(0, Py::Float(l2.x)); xyz.setItem(1, Py::Float(l2.y)); xyz.setItem(2, Py::Float(l2.z)); args.setItem(2,vector.apply(xyz)); xyz.setItem(0, Py::Float((float)0)); xyz.setItem(1, Py::Float((float)0)); xyz.setItem(2, Py::Float((float)1)); args.setItem(3,vector.apply(xyz)); args.setItem(4,Py::Float(radius)); args.setItem(5,Py::Int((int)0)); Py::Tuple ret(method.apply(args)); Py::Object S1(ret.getItem(0)); Py::Object S2(ret.getItem(1)); Py::Object M2(ret.getItem(2)); Base::Vector3d s1, s2, m2; s1.x = (double)Py::Float(S1.getAttr("x")); s1.y = (double)Py::Float(S1.getAttr("y")); s1.z = (double)Py::Float(S1.getAttr("z")); s2.x = (double)Py::Float(S2.getAttr("x")); s2.y = (double)Py::Float(S2.getAttr("y")); s2.z = (double)Py::Float(S2.getAttr("z")); m2.x = (double)Py::Float(M2.getAttr("x")); m2.y = (double)Py::Float(M2.getAttr("y")); m2.z = (double)Py::Float(M2.getAttr("z")); coords->point.set1Value(0, (float)s1.x,(float)s1.y,(float)s1.z); coords->point.set1Value(1, (float)m2.x,(float)m2.y,(float)m2.z); coords->point.set1Value(2, (float)s2.x,(float)s2.y,(float)s2.z); Base::Console().Message("M1=<%.4f,%.4f>\n", m1.x,m1.y); Base::Console().Message("M2=<%.4f,%.4f>\n", m2.x,m2.y); Base::Console().Message("S1=<%.4f,%.4f>\n", s1.x,s1.y); Base::Console().Message("S2=<%.4f,%.4f>\n", s2.x,s2.y); Base::Console().Message("P=<%.4f,%.4f>\n", a3.x,a3.y); Base::Console().Message("Q=<%.4f,%.4f>\n", l2.x,l2.y); Base::Console().Message("\n"); #else Py::Module pd("PartDesign"); Py::Callable method(pd.getAttr(std::string("makeFilletArc"))); Py::Tuple args(6); args.setItem(0,Py::Vector(m1)); args.setItem(1,Py::Vector(a3)); args.setItem(2,Py::Vector(l2)); args.setItem(3,Py::Vector(Base::Vector3d(0,0,1))); args.setItem(4,Py::Float(radius)); //args.setItem(5,Py::Int((int)0)); args.setItem(5,Py::Int((int)1)); Py::Tuple ret(method.apply(args)); Py::Vector S1(ret.getItem(0)); Py::Vector S2(ret.getItem(1)); Py::Vector M2(ret.getItem(2)); Base::Vector3d s1 = S1.toVector(); Base::Vector3d s2 = S2.toVector(); Base::Vector3d m2 = M2.toVector(); coords->point.set1Value(0, (float)s1.x,(float)s1.y,(float)s1.z); coords->point.set1Value(1, (float)m2.x,(float)m2.y,(float)m2.z); coords->point.set1Value(2, (float)s2.x,(float)s2.y,(float)s2.z); Base::Console().Message("M1=<%.4f,%.4f>\n", m1.x,m1.y); Base::Console().Message("M2=<%.4f,%.4f>\n", m2.x,m2.y); Base::Console().Message("S1=<%.4f,%.4f>\n", s1.x,s1.y); Base::Console().Message("S2=<%.4f,%.4f>\n", s2.x,s2.y); Base::Console().Message("P=<%.4f,%.4f>\n", a3.x,a3.y); Base::Console().Message("Q=<%.4f,%.4f>\n", l2.x,l2.y); Base::Console().Message("\n"); #endif } catch (Py::Exception&) { Base::PyException e; // extract the Python error text Base::Console().Error("%s\n", e.what()); } } }
/* Process LEN bytes of BUFFER, accumulating context into CTX. It is assumed that LEN % 128 == 0. */ void sha512_process_block (const void *buffer, size_t len, struct sha512_ctx *ctx) { const uint64_t *words = buffer; size_t nwords = len / sizeof (uint64_t); uint64_t a = ctx->H[0]; uint64_t b = ctx->H[1]; uint64_t c = ctx->H[2]; uint64_t d = ctx->H[3]; uint64_t e = ctx->H[4]; uint64_t f = ctx->H[5]; uint64_t g = ctx->H[6]; uint64_t h = ctx->H[7]; /* First increment the byte count. FIPS 180-2 specifies the possible length of the file up to 2^128 bits. Here we only compute the number of bytes. Do a double word increment. */ #ifdef USE_TOTAL128 ctx->total128 += len; #else uint64_t lolen = len; ctx->total[TOTAL128_low] += lolen; ctx->total[TOTAL128_high] += ((len >> 31 >> 31 >> 2) + (ctx->total[TOTAL128_low] < lolen)); #endif /* Process all bytes in the buffer with 128 bytes in each round of the loop. */ while (nwords > 0) { uint64_t W[80]; uint64_t a_save = a; uint64_t b_save = b; uint64_t c_save = c; uint64_t d_save = d; uint64_t e_save = e; uint64_t f_save = f; uint64_t g_save = g; uint64_t h_save = h; /* Operators defined in FIPS 180-2:4.1.2. */ #define Ch(x, y, z) ((x & y) ^ (~x & z)) #define Maj(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) #define S0(x) (CYCLIC (x, 28) ^ CYCLIC (x, 34) ^ CYCLIC (x, 39)) #define S1(x) (CYCLIC (x, 14) ^ CYCLIC (x, 18) ^ CYCLIC (x, 41)) #define R0(x) (CYCLIC (x, 1) ^ CYCLIC (x, 8) ^ (x >> 7)) #define R1(x) (CYCLIC (x, 19) ^ CYCLIC (x, 61) ^ (x >> 6)) /* It is unfortunate that C does not provide an operator for cyclic rotation. Hope the C compiler is smart enough. */ #define CYCLIC(w, s) ((w >> s) | (w << (64 - s))) /* Compute the message schedule according to FIPS 180-2:6.3.2 step 2. */ for (unsigned int t = 0; t < 16; ++t) { W[t] = SWAP (*words); ++words; } for (unsigned int t = 16; t < 80; ++t) W[t] = R1 (W[t - 2]) + W[t - 7] + R0 (W[t - 15]) + W[t - 16]; /* The actual computation according to FIPS 180-2:6.3.2 step 3. */ for (unsigned int t = 0; t < 80; ++t) { uint64_t T1 = h + S1 (e) + Ch (e, f, g) + K[t] + W[t]; uint64_t T2 = S0 (a) + Maj (a, b, c); h = g; g = f; f = e; e = d + T1; d = c; c = b; b = a; a = T1 + T2; } /* Add the starting values of the context according to FIPS 180-2:6.3.2 step 4. */ a += a_save; b += b_save; c += c_save; d += d_save; e += e_save; f += f_save; g += g_save; h += h_save; /* Prepare for the next round. */ nwords -= 16; } /* Put checksum in context given as argument. */ ctx->H[0] = a; ctx->H[1] = b; ctx->H[2] = c; ctx->H[3] = d; ctx->H[4] = e; ctx->H[5] = f; ctx->H[6] = g; ctx->H[7] = h; }