gf2m: save some log lookups with combined ops
This commit is contained in:
		
							parent
							
								
									b566beaa38
								
							
						
					
					
						commit
						6fd26d4c79
					
				
							
								
								
									
										12
									
								
								src/gf2m.h
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/gf2m.h
									
									
									
									
									
								
							|  | @ -61,6 +61,18 @@ public: | ||||||
| 		return antilog[ (n - 1 - log[a]) % (n - 1)]; | 		return antilog[ (n - 1 - log[a]) % (n - 1)]; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	inline uint inv_square (uint a) { | ||||||
|  | 		if (!a) return 0; | ||||||
|  | 		return antilog[ (2 * (n - 1 - log[a]) ) | ||||||
|  | 		                % (n - 1)]; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	inline uint div (uint a, uint b) { | ||||||
|  | 		if (! (a && b) ) return 0; | ||||||
|  | 		return antilog[ (n - 1 - log[b] + log[a]) | ||||||
|  | 		                % (n - 1)]; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	inline uint sq_root (uint a) { | 	inline uint sq_root (uint a) { | ||||||
| 		if (!a) return 0; | 		if (!a) return 0; | ||||||
| 		uint t = log[a]; | 		uint t = log[a]; | ||||||
|  |  | ||||||
|  | @ -411,8 +411,8 @@ int privkey::decrypt (const bvector & in, bvector & out, bvector & errors) | ||||||
| 	synd.clear(); | 	synd.clear(); | ||||||
| 	synd.resize (h_size, 0); | 	synd.resize (h_size, 0); | ||||||
| 	for (i = 0; i < cipher_size(); ++i) if (in[i]) { | 	for (i = 0; i < cipher_size(); ++i) if (in[i]) { | ||||||
| 			tmp = fld.inv (g.eval (permuted_support[i], fld) ); | 			tmp = fld.inv_square //g(Li)^{-2}
 | ||||||
| 			tmp = fld.mult (tmp, tmp); //g(Li)^{-2}
 | 			      (g.eval (permuted_support[i], fld) ); | ||||||
| 			synd[0] = fld.add (synd[0], tmp); | 			synd[0] = fld.add (synd[0], tmp); | ||||||
| 			for (j = 1; j < h_size; ++j) { | 			for (j = 1; j < h_size; ++j) { | ||||||
| 				tmp = fld.mult (tmp, permuted_support[i]); | 				tmp = fld.mult (tmp, permuted_support[i]); | ||||||
|  |  | ||||||
|  | @ -378,7 +378,7 @@ void polynomial::ext_euclid (polynomial&a_out, polynomial&b_out, | ||||||
| 		A.swap (a); | 		A.swap (a); | ||||||
| 		B.swap (b); | 		B.swap (b); | ||||||
| 		while ( (j = A.degree() - a.degree() ) >= 0) { | 		while ( (j = A.degree() - a.degree() ) >= 0) { | ||||||
| 			h = fld.mult (A.head(), fld.inv (a.head() ) ); | 			h = fld.div (A.head(), a.head() ); | ||||||
| 			tmp = a; | 			tmp = a; | ||||||
| 			tmp.shift (j); | 			tmp.shift (j); | ||||||
| 			A.add_mult (tmp, h, fld); | 			A.add_mult (tmp, h, fld); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue