53
53
* [2] [Zin96] V.A. Zinoviev. On the solution of equations of degree 10 over
54
54
* finite fields GF(2^q). In Rapport de recherche INRIA no 2829, 1996.
55
55
*/
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
+ */
57
72
#include <stdint.h>
58
73
#include <stdlib.h>
59
74
#include <string.h>
@@ -132,10 +147,10 @@ static void encode_bch_unaligned(struct bch_control *bch,
132
147
const int l = BCH_ECC_WORDS (bch ) - 1 ;
133
148
134
149
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 );
136
151
137
152
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 ++ );
139
154
}
140
155
141
156
ecc [l ] = (ecc [l ] << 8 ) ^ (* p );
@@ -250,8 +265,8 @@ void encode_bch(struct bch_control *bch, const uint8_t *data,
250
265
p2 = tab2 + (l + 1 ) * ((w >> 16 ) & 0xff );
251
266
p3 = tab3 + (l + 1 ) * ((w >> 24 ) & 0xff );
252
267
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 ];
255
270
256
271
r [l ] = p0 [l ] ^ p1 [l ] ^ p2 [l ] ^ p3 [l ];
257
272
}
@@ -323,7 +338,7 @@ static inline unsigned int gf_div(struct bch_control *bch, unsigned int a,
323
338
unsigned int b )
324
339
{
325
340
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 ;
327
342
}
328
343
329
344
static 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)
343
358
344
359
static inline int a_ilog (struct bch_control * bch , unsigned int x )
345
360
{
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 ]);
347
362
}
348
363
349
364
/*
@@ -542,8 +557,8 @@ static int find_affine4_roots(struct bch_control *bch, unsigned int a,
542
557
543
558
/* buid linear system to solve X^4+aX^2+bX+c = 0 */
544
559
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 ) ^
547
562
(b ? bch -> a_pow_tab [mod_s (bch , j )] : 0 );
548
563
j ++ ;
549
564
k += 2 ;
@@ -581,7 +596,7 @@ static int find_poly_deg1_roots(struct bch_control *bch, struct gf_poly *poly,
581
596
* compute roots of a degree 2 polynomial over GF(2^m)
582
597
*/
583
598
static int find_poly_deg2_roots (struct bch_control * bch , struct gf_poly * poly ,
584
- unsigned int * roots )
599
+ unsigned int * roots )
585
600
{
586
601
int n = 0 , i , l0 , l1 , l2 ;
587
602
unsigned int u , v , r ;
@@ -611,9 +626,9 @@ static int find_poly_deg2_roots(struct bch_control *bch, struct gf_poly *poly,
611
626
if ((gf_sqr (bch , r )^r ) == u ) {
612
627
/* reverse z=a/bX transformation and compute log(1/r) */
613
628
roots [n ++ ] = modulo (bch , 2 * GF_N (bch ) - l1 -
614
- bch -> a_log_tab [r ] + l2 );
629
+ bch -> a_log_tab [r ] + l2 );
615
630
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 );
617
632
}
618
633
}
619
634
return n ;
@@ -689,8 +704,8 @@ static int find_poly_deg4_roots(struct bch_control *bch, struct gf_poly *poly,
689
704
* z^4 + az^3 + (ae+b)z^2 + e^4+be^2+d
690
705
* z^4 + az^3 + b'z^2 + d'
691
706
*/
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 ;
694
709
}
695
710
/* now, use Y=1/X to get Y^4 + b/dY^2 + a/dY + 1/d */
696
711
if (d == 0 ) {
@@ -927,10 +942,12 @@ static int find_poly_roots(struct bch_control *bch, unsigned int k,
927
942
cnt = 0 ;
928
943
if (poly -> deg && (k <= GF_M (bch ))) {
929
944
factor_polynomial (bch , k , poly , & f1 , & f2 );
930
- if (f1 )
945
+ if (f1 ) {
931
946
cnt += find_poly_roots (bch , k + 1 , f1 , roots );
932
- if (f2 )
947
+ }
948
+ if (f2 ) {
933
949
cnt += find_poly_roots (bch , k + 1 , f2 , roots + cnt );
950
+ }
934
951
}
935
952
break ;
936
953
}
@@ -1026,7 +1043,7 @@ int decode_bch(struct bch_control *bch, const uint8_t *data, unsigned int len,
1026
1043
uint32_t sum ;
1027
1044
1028
1045
/* 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 )) {
1030
1047
return - EINVAL ;
1031
1048
}
1032
1049
@@ -1138,7 +1155,7 @@ static void build_mod8_tables(struct bch_control *bch, const uint32_t *g)
1138
1155
for (j = 0 ; j < ecclen ; j ++ ) {
1139
1156
hi = (d < 31 ) ? g [j ] << (d + 1 ) : 0 ;
1140
1157
lo = (j + 1 < plen ) ?
1141
- g [j + 1 ] >> (31 - d ) : 0 ;
1158
+ g [j + 1 ] >> (31 - d ) : 0 ;
1142
1159
tab [j ] ^= hi | lo ;
1143
1160
}
1144
1161
}
@@ -1213,7 +1230,7 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
1213
1230
1214
1231
g = bch_alloc (GF_POLY_SZ (m * t ), & err );
1215
1232
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 );
1217
1234
1218
1235
if (err ) {
1219
1236
free (genpoly );
@@ -1222,7 +1239,7 @@ static uint32_t *compute_generator_polynomial(struct bch_control *bch)
1222
1239
}
1223
1240
1224
1241
/* enumerate all roots of g(X) */
1225
- memset (roots , 0 , (bch -> n + 1 ) * sizeof (* roots ));
1242
+ memset (roots , 0 , (bch -> n + 1 ) * sizeof (* roots ));
1226
1243
for (i = 0 ; i < t ; i ++ ) {
1227
1244
for (j = 0 , r = 2 * i + 1 ; j < m ; j ++ ) {
1228
1245
roots [r ] = 1 ;
@@ -1323,7 +1340,7 @@ struct bch_control *init_bch(int m, int t, unsigned int prim_poly)
1323
1340
}
1324
1341
1325
1342
/* sanity checks */
1326
- if ((t < 1 ) || (m * t >= ((1 << m ) - 1 ))) {
1343
+ if ((t < 1 ) || (m * t >= ((1 << m ) - 1 ))) {
1327
1344
/* invalid t value */
1328
1345
goto fail ;
1329
1346
}
0 commit comments