/* Computes p*Delta. * * This will only be run once! */ struct polynomial compute_delta(void) { int i; struct polynomial A, B, C; A.leading = NULL; B.leading = NULL; C.leading = NULL; A = copy_pol(myf); B = copy_pol(myf); for (i = 2; i <= p; i++) { C = pol_mult(A, B); free_tail(B.leading); B = C; C.leading = NULL; C.degree = 0; } free_tail(A.leading); A.leading = NULL; A.degree = 0; A = frobenius(myf); /* Replace A by negative. */ times_int(-1, &A); /* Add -F(f) + f^p */ C = pol_add(A, B); free_tail(A.leading); free_tail(B.leading); return(C); }
/* Warning: destroys aa! */ void test_split(struct polynomial **aa, struct polynomial orig) { int i, j, aalen; struct polynomial tmp; tmp.leading = NULL; if (orig.degree != aa[0]->degree) { printf("Wrong degrees! Stop."); exit(1); } aalen = 1 + aa[0]->degree/d; for (i = 1; i + 1 <= aalen; i++) { printf(" %d \n", i); tmp = pol_mult(myf, *aa[i]); free_tail(aa[i]->leading); merge_add(aa[0], tmp); for (j = i + 1; j + 1 <= aalen; j++) { tmp = pol_mult(myf, *aa[j]); free_tail(aa[j]->leading); *aa[j] = tmp; } } times_int(-1, aa[0]); printf("Here is the test result: \n"); print_pol(pol_add(*aa[0], orig)); return; }
static dev_t choose_spare(struct state *from, struct state *to, struct domainlist *domlist, unsigned long long min_size) { int d; dev_t dev = 0; for (d = from->raid; !dev && d < MAX_DISKS; d++) { if (from->devid[d] > 0 && from->devstate[d] == 0) { struct dev_policy *pol; unsigned long long dev_size; if (to->metadata->ss->external && test_partition_from_id(from->devid[d])) continue; if (min_size && dev_size_from_id(from->devid[d], &dev_size) && dev_size < min_size) continue; pol = devid_policy(from->devid[d]); if (from->spare_group) pol_add(&pol, pol_domain, from->spare_group, NULL); if (domain_test(domlist, pol, to->metadata->ss->name) == 1) dev = from->devid[d]; dev_policy_free(pol); } } return dev; }
static void op_add() { int i; struct polynom pol,pol1,pol2; // extern struct polynom *pol_add(); *q++=EOS; i=muste_pol_load(p,&pol1); if (i<0) return; i=muste_pol_load(q,&pol2); if (i<0) return; pol_add(&pol,&pol1,&pol2); muste_pol_save(xx,&pol); }
/*! * Poly GCD * * \param f - polynomial in GF2^8[x] * \param g - polynomial in GF2^8[x] * \param gcd [out] - gcd(f,g) * \param a [out] - polynomial f quotient * \param b [put] - polynomial f quotient * * s.t. gdc(f,g) = a*f + b*g */ void polynomial_gcd(byte * f, byte * g, byte * gcd, byte * a, byte * b) { byte s[256]={0},t[256]={0},r[256]={0}; byte os[256]={0},ot[256]={0},or[256]={0}; // s = 0; pol_assign(os,one_pol); // old_s = 1 pol_assign(t,one_pol); // t = 1 // old_t = 0 pol_assign(r,f); // r = b pol_assign(or,g); // old_r = a while ( pol_cmp( r, zero_pol) != 0 ) { // r != 0 byte tmp[256] = {0}; // (old_r, r) := (r, old_r - r) pol_assign(tmp,r); pol_add(or,r,r); // r = old_r - r pol_assign(or,tmp); // ord_r = r // (old_s, s) := (s, old_s - s) pol_assign(tmp,s); pol_add(os,s,s); pol_assign(os,tmp); // (old_t, t) := (t, old_t - t) pol_assign(tmp,t); pol_add(ot,t,t); pol_assign(os,tmp); } pol_assign(gcd,or); pol_assign(a,t); pol_assign(b,s); }
int main() { mscalar ma, mb, mc, md, me; struct polynomial A, B, C, D, E, F, G, H; make_scalar(ma); make_scalar(mb); make_scalar(mc); make_scalar(md); make_scalar(me); A.leading = NULL; B.leading = NULL; C.leading = NULL; D.leading = NULL; E.leading = NULL; F.leading = NULL; G.leading = NULL; H.leading = NULL; printf("The prime is: %d.\n", p); printf("The power is: %d.\n", r); setup_scalars(); set_seed(0); sc_zero(ma); printf("The number 0 is: "); printmscalar(ma); printf(".\n"); sc_one(mb); printf("The number 1 is: "); printmscalar(mb); printf(".\n"); ito_sc(541, mc); printf("The number 541 is: "); printmscalar(mc); printf(".\n"); sc_inv(mc, md); printf("The inverse of 541 is: "); printmscalar(md); printf(".\n"); sc_mult(md, mc, me); printf("The number 1 is: "); printmscalar(me); printf(".\n"); A = make_random(10); F = copy_pol(A); /* print_pol(A); printf("\n"); */ B = make_random(11); H = copy_pol(B); /* print_pol(B); printf("\n"); */ C = pol_mult(A, B); /* print_pol(C); printf("\n"); */ D = pol_mult(B, A); /* print_pol(D); printf("\n"); */ times_int(-1, &D); E = pol_add(C, D); print_pol(E); printf("\n"); times_int(-1, &F); G = pol_add(A, F); print_pol(G); printf("\n"); times_int(-1, &H); G = pol_add(B, H); print_pol(G); exit(0); }