5353 * [2] [Zin96] V.A. Zinoviev. On the solution of equations of degree 10 over
5454 * finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996.
5555 */
56-
56+ /* mbed Microcontroller Library
57+ * Copyright (c) 2022 ARM Limited
58+ * SPDX-License-Identifier: Apache-2.0
59+ *
60+ * Licensed under the Apache License, Version 2.0 (the "License");
61+ * you may not use this file except in compliance with the License.
62+ * You may obtain a copy of the License at
63+ *
64+ * http://www.apache.org/licenses/LICENSE-2.0
65+ *
66+ * Unless required by applicable law or agreed to in writing, software
67+ * distributed under the License is distributed on an "AS IS" BASIS,
68+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69+ * See the License for the specific language governing permissions and
70+ * limitations under the License.
71+ */
5772#include <stdint.h>
5873#include <stdlib.h>
5974#include <string.h>
@@ -132,10 +147,10 @@ static void encode_bch_unaligned(struct bch_control *bch,
132147 const int l = BCH_ECC_WORDS (bch ) - 1 ;
133148
134149 while (len -- ) {
135- p = bch -> mod8_tab + (l + 1 )* (((ecc [0 ] >> 24 ) ^ (* data ++ )) & 0xff );
150+ p = bch -> mod8_tab + (l + 1 ) * (((ecc [0 ] >> 24 ) ^ (* data ++ )) & 0xff );
136151
137152 for (i = 0 ; i < l ; i ++ ) {
138- ecc [i ] = ((ecc [i ] << 8 )| (ecc [i + 1 ] >> 24 ))^ (* p ++ );
153+ ecc [i ] = ((ecc [i ] << 8 ) | (ecc [i + 1 ] >> 24 )) ^ (* p ++ );
139154 }
140155
141156 ecc [l ] = (ecc [l ] << 8 ) ^ (* p );
@@ -250,8 +265,8 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
250265 p2 = tab2 + (l + 1 ) * ((w >> 16 ) & 0xff );
251266 p3 = tab3 + (l + 1 ) * ((w >> 24 ) & 0xff );
252267
253- for (i = 0 ; i < l ; i ++ )
254- r [i ] = r [i + 1 ]^ p0 [i ]^ p1 [i ]^ p2 [i ]^ p3 [i ];
268+ for (i = 0 ; i < l ; i ++ ) {
269+ r [i ] = r [i + 1 ] ^ p0 [i ] ^ p1 [i ] ^ p2 [i ] ^ p3 [i ];
255270
256271 r [l ] = p0 [l ] ^ p1 [l ] ^ p2 [l ] ^ p3 [l ];
257272 }
@@ -323,7 +338,7 @@ static inline unsigned int gf_div(struct bch_control *bch, unsigned int a,
323338 unsigned int b )
324339{
325340 return a ? bch -> a_pow_tab [mod_s (bch , bch -> a_log_tab [a ] +
326- GF_N (bch )- bch -> a_log_tab [b ])] : 0 ;
341+ GF_N (bch ) - bch -> a_log_tab [b ])] : 0 ;
327342}
328343
329344static inline unsigned int gf_inv (struct bch_control * bch , unsigned int a )
@@ -343,7 +358,7 @@ static inline int a_log(struct bch_control *bch, unsigned int x)
343358
344359static inline int a_ilog (struct bch_control * bch , unsigned int x )
345360{
346- return mod_s (bch , GF_N (bch )- bch -> a_log_tab [x ]);
361+ return mod_s (bch , GF_N (bch ) - bch -> a_log_tab [x ]);
347362}
348363
349364/*
@@ -542,8 +557,8 @@ static int find_affine4_roots(struct bch_control *bch, unsigned int a,
542557
543558 /* buid linear system to solve X^4+aX^2+bX+c = 0 */
544559 for (i = 0 ; i < m ; i ++ ) {
545- rows [i + 1 ] = bch -> a_pow_tab [4 * i ]^
546- (a ? bch -> a_pow_tab [mod_s (bch , k )] : 0 )^
560+ rows [i + 1 ] = bch -> a_pow_tab [4 * i ] ^
561+ (a ? bch -> a_pow_tab [mod_s (bch , k )] : 0 ) ^
547562 (b ? bch -> a_pow_tab [mod_s (bch , j )] : 0 );
548563 j ++ ;
549564 k += 2 ;
@@ -581,7 +596,7 @@ static int find_poly_deg1_roots(struct bch_control *bch, struct gf_poly *poly,
581596 * compute roots of a degree 2 polynomial over GF(2^m)
582597 */
583598static int find_poly_deg2_roots (struct bch_control * bch , struct gf_poly * poly ,
584- unsigned int * roots )
599+ unsigned int * roots )
585600{
586601 int n = 0 , i , l0 , l1 , l2 ;
587602 unsigned int u , v , r ;
@@ -611,9 +626,9 @@ static int find_poly_deg2_roots(struct bch_control *bch, struct gf_poly *poly,
611626 if ((gf_sqr (bch , r )^r ) == u ) {
612627 /* reverse z=a/bX transformation and compute log(1/r) */
613628 roots [n ++ ] = modulo (bch , 2 * GF_N (bch ) - l1 -
614- bch -> a_log_tab [r ] + l2 );
629+ bch -> a_log_tab [r ] + l2 );
615630 roots [n ++ ] = modulo (bch , 2 * GF_N (bch ) - l1 -
616- bch -> a_log_tab [r ^ 1 ] + l2 );
631+ bch -> a_log_tab [r ^ 1 ] + l2 );
617632 }
618633 }
619634 return n ;
@@ -689,8 +704,8 @@ static int find_poly_deg4_roots(struct bch_control *bch, struct gf_poly *poly,
689704 * z^4 + az^3 + (ae+b)z^2 + e^4+be^2+d
690705 * z^4 + az^3 + b'z^2 + d'
691706 */
692- d = a_pow (bch , 2 * l )^ gf_mul (bch , b , f )^ d ;
693- b = gf_mul (bch , a , e )^ b ;
707+ d = a_pow (bch , 2 * l ) ^ gf_mul (bch , b , f ) ^ d ;
708+ b = gf_mul (bch , a , e ) ^ b ;
694709 }
695710 /* now, use Y=1/X to get Y^4 + b/dY^2 + a/dY + 1/d */
696711 if (d == 0 ) {
@@ -927,10 +942,12 @@ static int find_poly_roots(struct bch_control *bch, unsigned int k,
927942 cnt = 0 ;
928943 if (poly -> deg && (k <= GF_M (bch ))) {
929944 factor_polynomial (bch , k , poly , & f1 , & f2 );
930- if (f1 )
945+ if (f1 ) {
931946 cnt += find_poly_roots (bch , k + 1 , f1 , roots );
932- if (f2 )
947+ }
948+ if (f2 ) {
933949 cnt += find_poly_roots (bch , k + 1 , f2 , roots + cnt );
950+ }
934951 }
935952 break ;
936953 }
@@ -1026,7 +1043,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
10261043 uint32_t sum ;
10271044
10281045 /* sanity check: make sure data length can be handled */
1029- if (8 * len > (bch -> n - bch -> ecc_bits )) {
1046+ if (8 * len > (bch -> n - bch -> ecc_bits )) {
10301047 return - EINVAL ;
10311048 }
10321049
@@ -1138,7 +1155,7 @@ static void build_mod8_tables(struct bch_control *bch, const uint32_t *g)
11381155 for (j = 0 ; j < ecclen ; j ++ ) {
11391156 hi = (d < 31 ) ? g [j ] << (d + 1 ) : 0 ;
11401157 lo = (j + 1 < plen ) ?
1141- g [j + 1 ] >> (31 - d ) : 0 ;
1158+ g [j + 1 ] >> (31 - d ) : 0 ;
11421159 tab [j ] ^= hi | lo ;
11431160 }
11441161 }
@@ -1213,7 +1230,7 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
12131230
12141231 g = bch_alloc (GF_POLY_SZ (m * t ), & err );
12151232 roots = bch_alloc ((bch -> n + 1 ) * sizeof (* roots ), & err );
1216- genpoly = bch_alloc (DIV_ROUND_UP (m * t + 1 , 32 )* sizeof (* genpoly ), & err );
1233+ genpoly = bch_alloc (DIV_ROUND_UP (m * t + 1 , 32 ) * sizeof (* genpoly ), & err );
12171234
12181235 if (err ) {
12191236 free (genpoly );
@@ -1222,7 +1239,7 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
12221239 }
12231240
12241241 /* enumerate all roots of g(X) */
1225- memset (roots , 0 , (bch -> n + 1 ) * sizeof (* roots ));
1242+ memset (roots , 0 , (bch -> n + 1 ) * sizeof (* roots ));
12261243 for (i = 0 ; i < t ; i ++ ) {
12271244 for (j = 0 , r = 2 * i + 1 ; j < m ; j ++ ) {
12281245 roots [r ] = 1 ;
@@ -1323,7 +1340,7 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
13231340 }
13241341
13251342 /* sanity checks */
1326- if ((t < 1 ) || (m * t >= ((1 << m ) - 1 ))) {
1343+ if ((t < 1 ) || (m * t >= ((1 << m ) - 1 ))) {
13271344 /* invalid t value */
13281345 goto fail ;
13291346 }
0 commit comments