core/psd/imx6ull/bch.c
static int build_deg2_base(struct bch_control *bch)
{
	const int m = GF_M(bch);
	int i, j, r;
	unsigned int sum, x, y, remaining, ak = 0, xi[m];

	/* find k s.t. Tr(a^k) = 1 and 0 <= k < m */
	for (i = 0; i < m; i++) {
		for (j = 0, sum = 0; j < m; j++)
			sum ^= a_pow(bch, i*(1 << j));

		if (sum) {
			ak = bch->a_pow_tab[i];
			break;
		}
	}
	/* find xi, i=0..m-1 such that xi^2+xi = a^i+Tr(a^i).a^k */
	remaining = m;
	memset(xi, 0, sizeof(xi));

	for (x = 0; (x <= GF_N(bch)) && remaining; x++) {
		y = gf_sqr(bch, x)^x;
		for (i = 0; i < 2; i++) {
			r = a_log(bch, y);
			if (y && (r < m) && !xi[r]) {
				bch->xi_tab[r] = x;
				xi[r] = 1;
				remaining--;
				break;
			}
			y ^= ak;
		}
	}
	/* should not happen but check anyway */
	return remaining ? -1 : 0;
}
/*
 * build a base for factoring degree 2 polynomials
 */
build a base for factoring degree 2 polynomials
build a base for factoring degree 2 polynomials
static int build_deg2_base(struct bch_control *bch)
{
	const int m = GF_M(bch);
	int i, j, r;
	unsigned int sum, x, y, remaining, ak = 0, xi[m];
	for (i = 0; i < m; i++) {
		for (j = 0, sum = 0; j < m; j++)
			sum ^= a_pow(bch, i*(1 << j));
		if (sum) {
			ak = bch->a_pow_tab[i];
			break;
		}
	}
	remaining = m;
	memset(xi, 0, sizeof(xi));
	for (x = 0; (x <= GF_N(bch)) && remaining; x++) {
		y = gf_sqr(bch, x)^x;
		for (i = 0; i < 2; i++) {
			r = a_log(bch, y);
			if (y && (r < m) && !xi[r]) {
				bch->xi_tab[r] = x;
				xi[r] = 1;
				remaining--;
				break;
			}
			y ^= ak;
		}
	}
	return remaining ? -1 : 0;
}
static int build_deg2_base ( struct bch_control * bch ) { const int m = GF_M ( bch ) ; int i , j , r ; unsigned int sum , x , y , remaining , ak = 0 , xi [ m ] ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 , sum = 0 ; j < m ; j ++ ) sum ^= a_pow ( bch , i * ( 1 << j ) ) ; if ( sum ) { ak = bch -> a_pow_tab [ i ] ; break ; } } remaining = m ; memset ( xi , 0 , sizeof ( xi ) ) ; for ( x = 0 ; ( x <= GF_N ( bch ) ) && remaining ; x ++ ) { y = gf_sqr ( bch , x ) ^ x ; for ( i = 0 ; i < 2 ; i ++ ) { r = a_log ( bch , y ) ; if ( y && ( r < m ) && ! xi [ r ] ) { bch -> xi_tab [ r ] = x ; xi [ r ] = 1 ; remaining -- ; break ; } y ^= ak ; } } return remaining ? -1 : 0 ; }
build a base for factoring degree 2 polynomials
build a base for factoring degree 2 polynomials
/* find k s.t. Tr(a^k) = 1 and 0 <= k < m */ /* find xi, i=0..m-1 such that xi^2+xi = a^i+Tr(a^i).a^k */ /* should not happen but check anyway */