Previous Article in Journal
Energy Consumption of Post-Quantum Cryptography on Constrained and General-Purpose Architectures
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

A Closed-Form Hamming-Weight Variance Formula for Cyclic LCD Codes in Orthogonal Direct Sum Masking

by
Guillermo Sosa-Gómez
1,2
1
Facultad de Ciencias Económicas y Empresariales, Universidad Panamericana, Álvaro del Portillo 49, Zapopan 45010, Jalisco, Mexico
2
Laboratory for Reputation Management in Education, HSE University Saint-Petersburg, Griboedova Embankment 123, Office 502, 190068 Saint Petersburg, Russia
Cryptography 2026, 10(4), 56; https://doi.org/10.3390/cryptography10040056
Submission received: 7 July 2026 / Revised: 27 July 2026 / Accepted: 4 August 2026 / Published: 6 August 2026

Abstract

Orthogonal direct sum masking (ODSM) protects embedded cryptographic implementations against side-channel attacks by splitting the ambient space into a source code C carrying sensitive data and a complementary masking code D carrying fresh randomness; when D = C , C must be a linear complementary dual (LCD) code. Much of the literature evaluates the masking code primarily through the minimum distance d ( D ) = d ( C ) of its dual, treating this parameter as the quantitative summary of leakage resistance under a Hamming-weight leakage model. We show, first computationally and then via a general algebraic theorem, that this one parameter does not determine the variance of the masking code’s Hamming-weight distribution: cyclic codes with identical d ( C ) can differ by close to an order of magnitude in this variance. We prove, for an arbitrary cyclic code C GF ( q ) n with nonzero dual D = C and defining set T (the LCD property is not required for this algebraic result and is invoked only for the ODSM application), a closed-form theorem expressing Var c D [ wt ( c ) ] exactly as ( q 1 ) n 2 / ( q 2 L ( T ) ) , where L ( T ) is an intrinsically defined, representative-independent arithmetic invariant of T, computable via a single least-common-multiple of greatest-common-divisors and requiring no exponential-sum or Gauss-period evaluation. We verify the formula, with an explicit worked example, reproducible from the displayed defining sets, and zero discrepancies, against 64 independently constructed LCD cyclic codes spanning two finite fields and three code lengths. We are explicit that this variance is a second-order algebraic descriptor of leakage dispersion under an idealized leakage model, not a complete side-channel security metric; the connection to physical Hamming-weight leakage is direct for q = 2 ; for q > 2 , the result stands as an exact coding-theoretic characterization whose relevance to physical bit-level leakage depends on an explicit bit-encoding model not developed here. We discuss its role as a design diagnostic for ODSM masking codes. This paper is, at its core, a contribution to the algebraic theory of cyclic codes: the reduction of the variance to a weight-two-codeword count is the classical Pless moment identity, and our closed-form arithmetic characterization of that count via L ( T ) is algebraically equivalent, on its domain, to a 2024 result of Coelho and Brochero Martínez; we extend it to arbitrary cyclic length and arbitrary prime-power base fields, and position it as a complement to, not a replacement for, the more operational dual-distance/kissing-number methodology already used in the code-based masking literature.

1. Introduction

Side-channel attacks exploit the statistical dependence between the physical behavior of a cryptographic implementation (its instantaneous power consumption, electromagnetic emission, or execution timing) and the secret data it processes. Differential and correlation power analysis (DPA/CPA) recover secret keys by correlating many such physical traces against hypotheses about intermediate computations, and they remain one of the most practical threats to embedded and smartcard implementations of otherwise mathematically sound ciphers. Masking is the standard algorithmic countermeasure: sensitive data is randomized before it ever touches the physical device, so that, under an idealized leakage model and correct implementation assumptions, low-order observations are intended to reveal no exploitable statistical dependence on the secret, and the dependence only reappears when an attacker combines information from multiple, ideally independent, shares.
Linear complementary dual (LCD) codes occupy a central role in one influential family of masking schemes. Introduced by Massey [1] as a solution to an information-theoretic coding problem unrelated to cryptography, an LCD code is a linear code whose intersection with its dual is trivial. Massey showed that LCD codes are asymptotically good and give an optimum solution to the two-user binary adder channel. Decades later, Carlet and Guilley [2] observed that this same algebraic property makes LCD codes ideal building blocks for masking countermeasures against side-channel and fault-injection attacks because the trivial intersection with the dual guarantees that source data and mask can be recovered unambiguously and securely combined. Bringer, Carlet, Chabanne, Guilley, and Maghrebi [3] formalized this into orthogonal direct sum masking (ODSM): the protected representation of a sensitive word X is Z = X G + M H , where G generates a code C carrying the source data, H generates a complementary code D carrying a fresh random mask M , and the direct-sum structure F q n = C D guarantees that X and M can be projected out unambiguously from Z . When D = C , the direct-sum condition C C = F q n is exactly the statement that C is LCD. The security intuition is standard: an attacker observing a physical leakage function of Z should learn as little as possible about X . Two distinct leakage models are used in this literature, and we are precise about which one this paper adopts. The Hamming distance model takes leakage to be proportional to the number of bit transitions between two successive states of a data bus or register (the mechanism most directly tied to CMOS switching power); the Hamming weight model, which we adopt throughout, takes leakage to be proportional to the number of nonzero (set) bits of a single state, with no reference to a previous state. The two coincide, up to an additive constant, precisely when the bus or register is systematically precharged to the all-zero state before every new value is loaded (a common assumption for precharged buses and certain register-transfer-level designs), so that each transition is effectively a transition from zero; outside that implementation condition, Hamming distance leakage need not reduce to Hamming weight leakage, and our results should be read as applying to the Hamming-weight model specifically. This is achieved, in either model, by making d ( D ) as large as possible, so that low-weight leakage differences cannot be attributed to any single bit of X . Since D = C throughout this paper, d ( D ) = d ( C ) = d ( C ) : the classical “dual distance of the mask” referenced in the ODSM literature is, in our notation, simply d ( C ) , the minimum distance of the source code. We fix this convention precisely in Section 3 to avoid the ambiguity that can arise between d ( C ) , d ( D ) , and  d ( D ) , three generally distinct quantities.
Much of the literature that followed has optimized distance parameters such as d ( C ) , d ( D ) , or  d ( D ) , with little explicit analysis of higher moments. Carlet, Li, and Mesnager [4] constructed optimal pairs of linear codes maximizing d ( C ) and d ( D ) jointly subject to length and dimension constraints. A large and still very active line of work constructs explicit families of cyclic and constacyclic LCD codes: via Galois inner products [5,6], BCH-type defining sets of length λ ( q m + 1 ) [7,8], and algebraic-geometry or subspace codes [9,10]. Each new family is reported essentially by its ( n , k , d , d ) parameters. Even papers whose stated motivation is precisely side-channel resistance stop at this level: constructions of LCD codes from algebraic curves are explicitly justified as resistant to side-channel attacks, yet the quantitative verification of that resistance is left as declared future work rather than carried out.
This is the gap this paper addresses. The dual distance d ( D ) = d ( C ) is a worst-case descriptor: it certifies that no single low-weight leakage event can occur, but it says nothing about the shape of the leakage distribution above that floor. Two masking codes with the same d ( C ) can have weight distributions that look almost binomial (the behavior of a “generic” random code) or, instead, concentrate substantial probability mass on a handful of extreme weights far from the mean, a difference with direct consequences for the variance of any Hamming-weight leakage model built on top of the mask. We stress at the outset, and return to at length in Section 7 and Section 8, that this variance is a second-order algebraic descriptor of leakage dispersion under an idealized Hamming-weight leakage model. It should not be interpreted as a complete side-channel security metric: it does not by itself determine attack success probability, signal-to-noise ratio, mutual information, guessing entropy, or the number of traces an attacker would require, none of which are analyzed in this paper. What we show is narrower and, we believe, still useful: that this specific, well-defined algebraic quantity is not determined by d ( C ) alone, and that it is determined exactly by a simple, new invariant of the cyclic code’s defining set, one that requires no character-sum or Gauss-period evaluation whatsoever. This stands in contrast to the classical literature on cyclic-code weight distributions, which reaches for exactly this machinery to determine full weight enumerators, a strictly harder target than the single moment we compute here.
Contributions. (1) We give a covariance decomposition for wt ( D ) , D = C , valid for an arbitrary cyclic code C (the LCD property is not used in the algebraic derivation). (2) We characterize dependent coordinate pairs of D through an intrinsically defined subgroup of Z n attached to the cyclotomic defining set of C and prove this characterization is independent of any choice of coset representatives. (3) We obtain a closed-form formula for Var c D [ wt ( c ) ] in terms of this invariant. (4) We prove that, while the LCD property leaves the numeric value of this invariant unchanged, it forces every dependent coordinate pair to be related by a sign ( ± 1 ) rather than a general nonzero scalar, precisely delimiting what LCD does and does not contribute to the result. (5) We verify the formula computationally, with an explicit worked example exhibiting the defining sets used, reproducible from the values displayed, on 64 independently constructed cyclic LCD codes, and give a concrete instance within the actively studied length- λ ( q m + 1 ) family. (6) We discuss the formula’s use, with appropriate caveats, as a second-order design diagnostic for ODSM masking codes.
The remainder of the paper is organized as follows. Section 2 reviews the four strands of the literature this work connects. Section 3 fixes notation and the source/mask distance convention. Section 4 states the non-degeneracy hypothesis used throughout. Section 5 states and proves the main algebraic results, separating the general cyclic-code statement from its LCD/ODSM application. Section 6 reports the computational verification with a reproducible worked example. Section 7 discusses design implications, with explicit caveats on the scope of the variance metric. Section 8 states limitations, and Section 9 concludes.

2. Literature Review

2.1. LCD Codes: Definition and Cyclic Characterization

An LCD code is a linear code C GF ( q ) n with C C = { 0 } . Massey [1] introduced the class, proved the existence of asymptotically good LCD codes, and connected them to the two-user binary adder channel. Sendrier [11] later strengthened the existence result, showing LCD codes meet the Gilbert–Varshamov bound. For cyclic codes specifically, Yang and Massey [12] gave the classical characterization used throughout this paper: a cyclic code with defining set T is LCD if and only if T is closed under negation modulo the code length n. Equivalently, C C = { 0 } if and only if the Gram matrix G G T of any generator matrix G of C is nonsingular over GF ( q ) , a criterion that generalizes beyond the cyclic case and is the one we use computationally.

2.2. LCD Codes and Side-Channel Countermeasures

Carlet and Guilley [2] first connected LCD codes to countermeasures against side-channel and fault-injection attacks, giving explicit binary constructions. Bringer et al. [3] introduced orthogonal direct sum masking (ODSM), the concrete masking architecture this paper targets, and derived its security threshold in terms of d ( C ) and d ( D ) . Carlet, Li, and Mesnager [4] then optimized pairs of codes jointly for these two parameters. This entire line treats ( d ( C ) , d ( D ) ) as the complete quantitative description of resistance; no paper in this line examines higher moments of the masking code’s weight distribution.

2.3. Cyclic and Constacyclic LCD Codes: Recent Constructions

Building on the Yang–Massey characterization, a substantial and currently very active literature constructs explicit families of cyclic and constacyclic LCD codes: Galois-LCD codes and their Hermitian-LCD MDS constacyclic subfamilies [5,6]; BCH-type LCD codes of length λ ( q m + 1 ) , a construction under active development through 2026, with a complete enumeration of LCD cyclic codes of this length given very recently by Liu, Wu, and Zhu [7] and a detailed parameter study for the related family ( q m + 1 ) / λ published by Zhang [8]; and linear complementary pairs of algebraic-geometry and subspace codes [9,10]. These papers report parameters ( n , k , d , d ) and, where possible, optimality, but, consistent with the pattern noted above, do not examine the shape of the dual code’s weight distribution beyond its minimum. Section 6.4 gives a concrete instance of the length- λ ( q m + 1 ) family, showing what the variance formula of Theorem 1 adds beyond the ( n , k , d , d ) parameters already reported for such constructions.

2.4. Weight Distributions of Cyclic Codes via Exponential Sums

A separate and much older literature determines the full weight distribution of cyclic codes (primarily irreducible or few-zero cyclic codes) via evaluation of exponential sums, Gauss periods, and quadratic forms. Moisio [13] gave a general evaluation of a broad family of exponential sums, subsequently used by Vega [14] to characterize all semiprimitive irreducible cyclic codes by length and by Zhu, Shi, and Özbudak [15] to determine complete b-symbol weight distributions of certain irreducible cyclic codes. This machinery is powerful but heavy: determining a full weight enumerator for a cyclic code whose dual has more than two or three zeros remains, in general, a hard open problem tackled case-by-case. Our results show that the specific second moment (variance) needed for the diagnostic proposed here does not require this machinery at all, for cyclic codes with an arbitrary number of zeros.

2.5. Quantitative Confusion-Coefficient Metrics in S-Box Design

Independently, the S-box design literature quantifies DPA resistance via the confusion coefficient and its variance (CCV): de la Cruz Jiménez [16] and Picek et al. [17] studied the CCV property of S-boxes as a finer-grained resistance metric than worst-case nonlinearity measures. This is the kind of second-moment, variance-based diagnostic we import into the code-based masking setting; within the search described below, we did not find prior work applying a CCV-style variance analysis to the masking code of an ODSM scheme or connecting it to the cyclotomic-coset structure of a cyclic LCD code’s defining set.
Synthesis and search protocol. The literature review above, and the novelty claim it supports, rest on a targeted search rather than a systematic one, conducted through a general-purpose web search interface (not a single bibliographic database such as Scopus or Web of Science) in July 2026, using queries combining terms from {LCD codes, cyclic codes, orthogonal direct sum masking, code-based masking, dual distance, kissing number, weight distribution, cyclotomic coset, confusion coefficient variance} in pairs and triples, together with forward and backward citation chasing from the papers so identified (Section 7 documents one correction that resulted from this chasing after initial submission). No formal inclusion or exclusion criteria, database export, or PRISMA-style protocol were used, and no fixed cutoff date bounded the search beyond the time of writing. Within this search, we did not find published work at the intersection of Section 2.3 and Section 2.4 (algebraic machinery for cyclic-code weight structure) and Section 2.5 (a variance-based diagnostic); we state this as the outcome of the specific search described, not as a claim that no such work exists.

3. Notation and the Source/Mask Distance Convention

Throughout, q is a prime power and n a positive integer with gcd ( n , q ) = 1 . Let m be the multiplicative order of q modulo n, and fix a primitive n-th root of unity ζ GF ( q m ) . A cyclic code C GF ( q ) n of defining set T Z n (a union of q-cyclotomic cosets modulo n) is C = { c ( x ) GF ( q ) [ x ] / ( x n 1 ) : c ( ζ t ) = 0 t T } . We write D : = C , also cyclic, for the code used as the ODSM masking code when C is LCD.
We fix a single notational convention to avoid ambiguity: d ( C ) , d ( D ) , and  d ( D ) denote three a priori distinct quantities. Since D = C and C = C for finite fields, we have the identity
d ( D ) = d ( C ) .
The quantity the ODSM literature calls the “dual distance of the mask” is d ( D ) , which by this identity equals d ( C ) , the minimum distance of the source code, not a property of D in isolation. All theorems in Section 5 are stated in terms of d ( C ) , consistent with this identity; d ( D ) itself (the mask’s own minimum distance, relevant to a different property, e.g., error detection in the mask) plays no role in our results and is not used.
Remark 1 
(Symbol-wise versus bit-level Hamming weight). Throughout this paper, wt ( c ) denotes the standard symbol-wise Hamming weight over GF ( q ) : the number of nonzero coordinates of c, counting each nonzero symbol as 1 regardless of its value. This is the quantity Theorem 1 characterizes exactly. For  q = 2 , this symbol-wise weight coincides exactly with the physical bit-transition weight that correlates with CMOS power consumption, so the variance formula bears directly on the Hamming-weight leakage model motivating ODSM. For  q > 2 , this coincidence need not hold: if a field symbol is represented in hardware by a vector of bits (e.g., GF ( 3 ) elements 0 , 1 , 2 encoded as 00 , 01 , 10 ), the physical bit-level Hamming weight of a codeword depends on the specific bit-encoding of each symbol and is generally not equal to, nor an affine function of, the symbol-wise weight wt ( c ) ; for instance, under the encoding above, nonzero symbols 1 and 2 both contribute bit-weight 1, while our symbol-wise count treats them identically as contributing 1 regardless of encoding, but a different (equally natural) encoding could make them contribute differently, and the aggregate distribution over a full codeword depends on this choice in a way the present paper does not model. Consequently, for  q > 2 , Theorem 1 should be read as an exact result about a coding-theoretic quantity of independent interest, whose direct relevance to physical Hamming-weight leakage requires an additional, explicit bit-encoding model that we do not develop here; the case q = 2 remains the setting in which the connection to physical leakage is immediate. We return to this point in the Limitations.

4. Non-Degeneracy Hypothesis

The main results assume D { 0 } and use throughout that no coordinate of D is identically zero. We record this as a lemma rather than an unstated assumption.
Lemma 1 
(Non-degeneracy). Let D GF ( q ) n be a nonzero cyclic code. Then, for every i { 0 , , n 1 } , the coordinate projection π i : D GF ( q ) , c c i , is surjective.
Proof. 
Suppose π i 0 for some i, i.e.,  c i = 0 for every c D . Since D is cyclic, the cyclic shift σ (sending ( c 0 , , c n 1 ) to ( c n 1 , c 0 , , c n 2 ) ) maps D onto itself. For any c D , σ ( c ) D as well, and  ( σ ( c ) ) i + 1 mod n = c i = 0 ; since this holds for every c D and σ ( D ) = D , we get π i + 1 mod n 0 as well. Iterating, π j 0 for every j, i.e., every coordinate of every codeword is zero, so D = { 0 } , contradicting the hypothesis. Hence every π i is a nonzero GF ( q ) -linear functional on D, hence surjective (its image is a nonzero GF ( q ) -subspace of GF ( q ) , i.e., all of GF ( q ) ).    □
In particular, each X i ( c ) : = 1 { c i 0 } is a well-defined Bernoulli random variable with parameter p = ( q 1 ) / q when c is drawn uniformly from D, and  wt ( c ) = i = 0 n 1 X i ( c ) .

5. Main Results

We emphasize, per the discussion in Section 3, that the results in this section are stated for an arbitrary cyclic code C and its dual D = C ; the LCD property of C is not used in their proofs. LCD enters only in Remark 3 below, where it licenses the ODSM interpretation of D as a masking code.
Lemma 2 
(Generic case). If d ( C ) 3 , then
Var c D [ wt ( c ) ] = n ( q 1 ) q 2
exactly, independent of any other structural property of D.
Proof. 
Fix i j and let H be a generator matrix of D, with columns h 0 , , h n 1 GF ( q ) k D , k D = dim D , so that a codeword c = m H D satisfies c i = m · h i for the message m GF ( q ) k D . If  h i and h j were linearly dependent, there would exist α , β GF ( q ) , not both zero, with  α h i + β h j = 0 ; the vector v with v i = α , v j = β , and zeros elsewhere then satisfies v · ( m H ) = m · ( α h i + β h j ) = 0 for every m, so v D = C is a nonzero codeword of weight 2 , contradicting d ( C ) 3 . Hence every pair of columns of H is linearly independent, so the map m ( m · h i , m · h j ) is a surjective linear map GF ( q ) k D GF ( q ) 2 with constant fiber size q k D 2 : ( c i , c j ) is uniform on GF ( q ) 2 over c D . This gives Cov ( X i , X j ) = 0 for every pair i j , so
Var ( wt ( c ) ) = Var i X i = i Var ( X i ) = n · q 1 q 2 ,
by Lemma 1, since each X i is Bernoulli with parameter ( q 1 ) / q .    □
Remark 2. 
This lemma is a reformulation of the classical fact that d ( C ) t + 1 if and only if D = C is an orthogonal array of strength t [18]; we need only t = 2 . Its novelty here is not the fact itself but its application below (Theorem 1) to the full range d ( C ) 2 , and, with appropriate caveats (Section 7), to ODSM masking-code design.
We now turn to the case d ( C ) 2 , where Lemma 2 does not apply. The next lemma establishes, independently of any choice of coset representatives, that the relevant dependency structure is governed by a canonically defined subgroup of Z n ; this addresses directly the representative-dependence concern that a definition through an arbitrarily chosen representative would otherwise leave open.
Lemma 3 
(Canonical dependency subgroup). Let T Z n be the defining set of C. Define
D ( T ) : = d Z n : μ GF ( q ) * such that ζ t d = μ for all t T .
Then D ( T ) is a subgroup of Z n . Consequently there is a unique divisor L ( T ) of n with D ( T ) = L ( T ) = { 0 , L ( T ) , 2 L ( T ) , , n L ( T ) } .
Proof. 
0 D ( T ) with witness μ = 1 . If  d 1 , d 2 D ( T ) with witnesses μ 1 , μ 2 , then ζ t ( d 1 + d 2 ) = ζ t d 1 ζ t d 2 = μ 1 μ 2 for every t T , and  μ 1 μ 2 GF ( q ) * since GF ( q ) * is a group; hence, d 1 + d 2 D ( T ) . If  d D ( T ) with witness μ , then ζ t ( d ) = μ 1 GF ( q ) * for every t T , so d D ( T ) . Thus D ( T ) is closed under addition and inverses and contains 0: it is a subgroup of the cyclic group Z n . Every subgroup of Z n has the form L for a unique divisor L of n, giving the stated form.    □
The invariant L ( T ) in Lemma 3 is defined purely in terms of T and involves no choice of representative; the following proposition shows it can nonetheless be computed via any choice of one representative per coset in T, which is what our verification algorithm (Section 6) uses.
Proposition 1 
(Computation of L ( T ) ). Let t 1 , , t s be any representatives of the cosets comprising T (one per coset, any choice). Then
L ( T ) = lcm n gcd ( n , t 1 ( q 1 ) ) , n gcd ( n , t 2 t 1 ) , , n gcd ( n , t s t 1 ) ,
with the convention n / gcd ( n , 0 ) = 1 , and this value is independent of the choice of t 1 , , t s .
Proof. 
Fix a base representative t 1 . Within its coset { t 1 , t 1 q , t 1 q 2 , } , the defining condition ζ t d = μ (for the fixed witness μ of d D ( T ) ) applied at t = t 1 q gives ( ζ t 1 d ) q = μ for every 0 ; taking = 0 gives μ = ζ t 1 d , and  = 1 then forces μ q = μ , i.e., μ GF ( q ) , equivalently ζ t 1 ( q 1 ) d = 1 , i.e.,  n t 1 ( q 1 ) d . For each other representative t r , the defining condition forces ζ t r d = μ = ζ t 1 d , i.e.,  n ( t r t 1 ) d . Conversely, once d satisfies all these congruences, one checks by induction (using integer linear combinations, e.g., t r ( q 1 ) d = t 1 ( q 1 ) d + ( q 1 ) ( t r t 1 ) d ) that ζ t d = μ holds for every element of every coset in T with the same μ = ζ t 1 d GF ( q ) * ; so d D ( T ) iff d is a common multiple of the listed moduli, i.e., a multiple of their lcm. By Lemma 3, D ( T ) = L ( T ) is intrinsic to T, so this lcm—computed from any valid choice of representatives—must equal L ( T ) in every case, establishing representative-independence as a corollary of intrinsic well-definedness rather than as a separate combinatorial verification.    □
Lemma 4 
(Proportional columns and weight-two dual words). Let H be a generator matrix of D = C , with nonzero columns h 0 , , h n 1 . For  i j , the columns h i , h j are proportional over GF ( q ) if and only if C = D contains a weight-two codeword with support exactly { i , j } .
Proof. 
Suppose h i , h j are proportional. Since both columns are nonzero, there exist α , β GF ( q ) * such that α h i + β h j = 0 . Let v GF ( q ) n have v i = α , v j = β , and zeros elsewhere. For any c = m H D , v · c = m · ( α h i + β h j ) = 0 , so v D = C ; since α , β GF ( q ) * , v is a weight-two codeword of C with support exactly { i , j } . Conversely, if C contains a weight-two codeword v with support exactly { i , j } , write v i = α , v j = β (both in GF ( q ) * , and zero elsewhere); v C = D means v · c = 0 for every c = m H D , i.e.,  m · ( α h i + β h j ) = 0 for every m GF ( q ) k D . Since H is a generator matrix, its rows are linearly independent, so H has full row rank and m ranges over the entire message space GF ( q ) k D as c = m H ranges over D; in particular, the linear functional m m · ( α h i + β h j ) vanishing on all of GF ( q ) k D forces α h i + β h j = 0 , i.e.,  h i , h j proportional.    □
Theorem 1 
(Closed-form variance formula). Let C GF ( q ) n be a cyclic code with defining set T, D = C { 0 } , and  L ( T ) as in Lemma 3. Then
Var c D [ wt ( c ) ] = ( q 1 ) n 2 q 2 L ( T )
exactly.
Proof. 
By Lemma 4, columns h i , h j of a generator matrix of D are proportional iff C = D contains a weight-two word with support exactly { i , j } . A weight-two word with support exactly { i , j } , d = i j mod n , lies in C iff there exist α , β GF ( q ) * with α ζ t i + β ζ t j = 0 for every t T , i.e., iff d D ( T ) (with witness μ = β / α ). By Lemma 3, the set of such d (excluding 0) is exactly the nonzero part of L ( T ) , of size n / L ( T ) 1 . The n coordinates partition into L ( T ) cosets of L ( T ) , each of size n / L ( T ) ; by Lemma 4, two coordinates i , j have dependent (proportional) columns h i , h j iff i j D ( T ) , i.e., iff i , j lie in the same coset of L ( T ) . The number of dependent pairs is therefore
N dep ( T ) = L ( T ) n / L ( T ) 2 = n ( n L ( T ) ) 2 L ( T ) .
As in Lemma 2, independent pairs contribute zero covariance, and each dependent pair contributes Cov ( X i , X j ) = Var ( X i ) = ( q 1 ) / q 2 (since h j = λ h i for a fixed nonzero scalar λ forces X i = X j identically, by Lemma 1). Hence
Var ( wt ( c ) ) = n ( q 1 ) q 2 + 2 N dep ( T ) · q 1 q 2 = q 1 q 2 n + n ( n L ( T ) ) L ( T ) = ( q 1 ) n 2 q 2 L ( T ) .      
Corollary 1 
(Domain of variation). If 0 T , choosing t 1 = 0 in Proposition 1 gives n / gcd ( n , 0 ) = 1 trivially, and  L ( T ) reduces to lcm t T { 0 } ( n / gcd ( n , t ) ) . If, moreover, d ( C ) 3 , then L ( T ) = n and Theorem 1 reduces exactly to Lemma 2. At the opposite extreme, T = { 0 } gives L ( T ) = 1 (an empty lcm), C the single parity-check code, and D the q-ary repetition code D = { a ( 1 , , 1 ) : a GF ( q ) } generated by the all-ones vector, for any q. Here wt ( c ) takes the value 0 with probability 1 / q and n with probability ( q 1 ) / q , giving Var ( wt ( c ) ) = ( q 1 ) n 2 / q 2 directly, matching the formula and the largest value it attains, a boundary case consistent with D being maximally structured (a single nonzero direction). Consequently, for a nonzero, proper cyclic code C, L ( T ) (and hence Var ( wt ( D ) ) ) can differ from the generic value n ( q 1 ) / q 2 only when d ( C ) = 2 : whenever d ( C ) 3 , Lemma 2 forces L ( T ) = n regardless of any other structural feature of T, so L ( T ) cannot distinguish among ODSM candidates with d ( C ) 3 —it distinguishes only among candidates with d ( C ) = 2 . This delimitation is discussed further, together with its practical relevance, in Section 7.
The algebraic results above make no use of the LCD property: L ( T ) , and hence Var ( wt ( D ) ) , is determined by T alone, whether or not T = T . This raises a natural question: does the LCD condition constrain the variance formula in any way, or does it play no algebraic role beyond licensing the ODSM interpretation of Remark 3? The next proposition shows that LCD leaves the numeric value of L ( T ) unconstrained but does impose a genuine, previously unremarked structural restriction on how dependent coordinates are related.
Proposition 2 
(LCD restricts dependency type, not L ( T ) ). Suppose T = T (i.e., C is LCD). Then for every d D ( T ) { 0 } , the witness μ GF ( q ) * with ζ t d = μ for all t T satisfies μ 2 = 1 . Consequently, every pair of dependent coordinates i , j (columns h i , h j of a generator matrix of D) satisfies h j = λ h i with λ = ± 1 : LCD forces every dependency in the masking code to be a pure sign relation, never a general nonzero scalar multiple, even though the numeric value of L ( T ) itself (and hence Var ( wt ( D ) ) ) is unaffected.
Proof. 
Fix d D ( T ) { 0 } with witness μ , so ζ t d = μ for every t T . Since T = T , for every t T we also have t T , and the same single witness μ must satisfy ζ ( t ) d = μ as well. But  ζ ( t ) d = ( ζ t d ) 1 = μ 1 , so μ = μ 1 , i.e.,  μ 2 = 1 . From the proof of Lemma 4 and Theorem 1, the proportionality constant between dependent columns satisfies λ = μ 1 (the witness μ = β / α of the underlying weight-two codeword and the column relation h j = λ h i = ( α / β ) h i are reciprocal), so λ 2 = ( μ 1 ) 2 = ( μ 2 ) 1 = 1 as well.    □
For q = 2 , GF ( q ) * = { 1 } and μ = λ = 1 automatically, so Proposition 2 is vacuous; the restriction is genuinely informative only for q > 2 , where GF ( q ) * can have elements of order greater than 2. We verified this contrast computationally over GF ( 5 ) , n = 16 : a non-LCD defining set T = { 1 , 5 , 9 , 13 } (not closed under negation) has dependent-pair witnesses μ { 2 , 3 , 4 } as d ranges over the nonzero elements of D ( T ) , with  μ 2 1 for d = 4 , 12 ; the LCD-symmetrized set T = T ( T ) = { 1 , 3 , 5 , 7 , 9 , 11 , 13 , 15 } has a single dependent gap d = 8 with witness μ = 4 = 1 , consistent with Proposition 2, while L ( T ) = 8 L ( T ) = 4 changes as a byproduct of enlarging the defining set, not because of the symmetry itself. This confirms both halves of the claim: symmetrizing T does not, by itself, preserve or fix L ( T ) ’s numeric value, but whenever a d is dependent under an LCD-symmetric T, its witness is forced to ± 1 .
Remark 3 
(LCD/ODSM application). Theorem 1 places no requirement on C beyond being cyclic. If, in addition, C is LCD (equivalently, by Yang–Massey [12], T is closed under negation modulo n), then C C = F q n , and  D = C can serve as the masking code in an ODSM scheme with C as the source code. All computational examples in Section 6 are additionally restricted to LCD C for this reason, even though Theorem 1 itself does not require it.

Relation to the Pless Moment Identity and to Coelho–Brochero Martínez

We now position Theorem 1 precisely against two bodies of prior work, separating what is classical from what is new.
The classical part. For any nonzero, nondegenerate linear code D GF ( q ) n with C = D , the identity
Var c D [ wt ( c ) ] = n ( q 1 ) + 2 A 2 ( C ) q 2
follows directly from the Pless power moments relating the weight distribution of a code to that of its dual [18], where A 2 ( C ) denotes the number of weight-two codewords of C; it requires neither C nor D to be cyclic. Indeed, this identity is exactly what the covariance decomposition in the proof of Theorem 1 recovers: A 2 ( C ) = N dep ( T ) · ( q 1 ) since each of the N dep ( T ) dependent coordinate pairs contributes exactly q 1 weight-two codewords (one for each nonzero scalar α in the pair v i = α , v j = α / λ ). Substituting recovers Var ( wt ( D ) ) = ( q 1 ) [ n + 2 N dep ( T ) ] / q 2 , matching Theorem 1 exactly. The reduction of the variance computation to counting weight-two words of C is therefore classical, not new.
What Theorem 1 adds. The contribution is an exact, closed-form arithmetic formula for A 2 ( C ) (equivalently, for  L ( T ) ) in terms of the cyclotomic defining set T, valid for cyclic codes of arbitrary length n coprime to q and arbitrary prime-power q, together with the representative-independence result of Lemma 3 and the LCD-specific Proposition 2. This is where the present paper’s novelty is concentrated, and we delimit it further against the closest prior result below.
Coelho and Brochero Martínez (2024) [19] independently derive, for cyclic codes C t 1 , , t s of the special length n = Q 1 over a prime field GF ( p ) (where Q = p m ), a necessary and sufficient condition for d ( C ) = 2 and an exact count
A 2 = ( p 1 ) ( Q 1 ) D ( t 1 , , t s ) 1 2 , D ( t 1 , , t s ) : = gcd Q 1 , t 1 ( p 1 ) , t 2 t 1 , , t s t 1 .
This is algebraically equivalent to our formula on the domain where both apply. Writing n = Q 1 and q = p to match our notation, the classical identity lcm ( n / d 1 , , n / d s ) = n / gcd ( d 1 , , d s ) for divisors d i = gcd ( n , x i ) of n gives
L ( T ) = lcm n gcd ( n , x 1 ) , , n gcd ( n , x s ) = n gcd ( n , x 1 , , x s ) = n D ( t 1 , , t s ) ,
where x 1 = t 1 ( q 1 ) , x i = t i t 1 ( i 2 ) are exactly the arguments of both L ( T ) and D ( t 1 , , t s ) . Hence D ( t 1 , , t s ) = n / L ( T ) , and substituting into their A 2 formula gives A 2 = ( q 1 ) n ( n / L ( T ) 1 ) / 2 = ( q 1 ) N dep ( T ) , matching the relation above exactly. On the domain n = Q 1 , q prime, our closed-form L ( T ) and their D ( t 1 , , t s ) are reciprocal reparametrizations of the same arithmetic quantity.
We flag plainly that every numerical example in this paper (Section 6.2, Section 6.3 and Section 6.4) falls inside this domain: 15 = 2 4 1 , 63 = 2 6 1 , and  26 = 3 3 1 are all of the form Q 1 for a prime base field, and the length-20 example of Section 6.4 similarly reduces to it. What remains new relative to [19], and is not illustrated by these particular examples, is the extension to (i) arbitrary length n coprime to q, not restricted to n = Q 1 for the specific extension degree m = ord n ( q ) , and (ii) arbitrary prime-power base fields q, not restricted to q prime. Both extensions follow from the same proof (Proposition 1), which never uses n = Q 1 or q prime, and we verify each concretely rather than merely asserting them. For the extension to n Q 1 : with n = 9 , q = 2 (here ord 9 ( 2 ) = 6 , but  9 2 6 1 = 63 , so n = 9 is a proper divisor of 2 6 1 and not of the form Q 1 addressed in [19]), the defining set T = { 0 } { 3 , 6 } gives an LCD code with L ( T ) = 3 < 9 (so d ( C ) = 2 ) and Var ( wt ( D ) ) = 6.75 , confirmed by direct brute-force enumeration of D. For the extension to non-prime q, which [19] excludes by construction (their base field is GF ( p ) for p prime): with q = 4 and n = 9 (so q itself is a prime power, not a prime, and  n q m 1 for any m), factoring x 9 + 1 directly over GF ( 4 ) gives five irreducible factors of degrees 1 , 1 , 1 , 3 , 3 ; taking the defining set T = { 0 } { 3 } { 6 } (the three linear factors) gives an LCD code with dim C = 6 , dim D = 3 , L ( T ) = 3 < 9 (so d ( C ) = 2 ), and  Var ( wt ( D ) ) = 5.0625 , again confirmed by direct brute-force enumeration of D. Both instances lie outside the domain of [19] — the first through n, the second through q — and both are correctly predicted by Theorem 1 nonetheless.

6. Computational Verification

We verified Theorem 1 by exhaustive enumeration within each tested configuration (results in Table 1): for each ( n , q ) below, every cyclic code obtainable as a union of q-cyclotomic cosets modulo n was constructed and tested for the LCD property via the Gram-matrix criterion of Yang–Massey [12]; among the resulting LCD codes, those whose dual dimension dim D was small enough for brute-force enumeration of all q dim D codewords of D (we used a threshold of dim D 16 for q = 2 and dim D 9 for q = 3 ) had their exact weight distribution and variance computed directly and compared against the closed-form prediction of Theorem 1, computed independently via Proposition 1.

6.1. Algorithm

(1)
Enumerate the q-cyclotomic cosets of Z n .
(2)
For each nonempty proper union T of cosets, form the generator polynomial g T ( x ) = t T m t ( x ) , where m t ( x ) is the minimal polynomial of ζ t over GF ( q ) , and build the corresponding cyclic generator matrix G for C.
(3)
Test the LCD criterion: C is LCD iff G G T has full rank over GF ( q ) .
(4)
Compute L ( T ) via Proposition 1, and record d ( C ) directly from it: d ( C ) = 2 if L ( T ) < n , and  d ( C ) 3 if L ( T ) = n (Corollary 1). This step, recomputing d ( C ) explicitly for every instance rather than inferring it indirectly, was added after an earlier draft’s worked example conflated d ( D ) with d ( C ) = d ( D ) for two codes that in fact had different d ( C ) ; see Section 6.3.
(5)
If dim D = deg g T is below the brute-force threshold, enumerate D = ker G (the null space of G) exhaustively, compute d ( D ) and the empirical weight variance directly, and compute A 2 ( C ) = ( q 1 ) N dep ( T ) from L ( T ) (Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez).
(6)
Compare the predicted variance ( q 1 ) n 2 / ( q 2 L ( T ) ) against the empirical value.
For every instance below the brute-force threshold across all three tested configurations (64 instances total), we recorded n, q, the full defining set T, dim C , dim D , d ( C ) , d ( D ) , L ( T ) , A 2 ( C ) , the predicted and empirical variances, and the comparison result, in a Supplementary CSV file (supplementary_instance_data.csv) accompanying this submission; Table 1 reports only the aggregate counts. Source code implementing this algorithm (Python 3, using the galois library, version 0.4.11) accompanies this submission as Supplementary Materials and is also available from the corresponding author upon reasonable request; see also the Data Availability Statement.

6.2. Results

Across all three tested configurations, the closed-form prediction of Theorem 1 matched the brute-force empirical variance exactly, with zero discrepancies among the 64 LCD codes below the enumeration threshold (Table 1). No instance required any adjustment to the formula or its underlying assumptions; the agreement is exact to machine precision in every case, not merely close. The full per-instance data (defining set, dimensions, d ( C ) , d ( D ) , L ( T ) , A 2 ( C ) , predicted and empirical variance) is provided as Supplementary Material rather than reproduced in full here, since Table 1 already reports the aggregate counts relevant to the reader. Section 6.3 presents one such instance in full detail, chosen specifically because it also corrects an error present in an earlier version of this manuscript.

6.3. Reproducible Worked Example

An earlier version of this example incorrectly reported both codes below as having d ( C ) = 9 . That value is in fact d ( D ) , the minimum distance of the mask code D itself (a quantity Theorem 1 does not use); the two codes have different d ( C ) , and we had conflated d ( D ) with d ( D ) = d ( C ) despite the notational distinction fixed in Section 3. We are grateful to a reviewer for identifying this error. Here we give a corrected, independently verified example, shown in Table 2: two LCD cyclic codes of length n = 63 over GF ( 2 ) with identical dim C = 56 , dim D = 7 , and, most importantly, identical d ( C ) = 2 (the only regime in which L ( T ) , and hence the variance, can differ; see Corollary 1 below), yet with different L ( T ) and variance. Write cosets by their smallest element: Cs ( t ) denotes the 2-cyclotomic coset of t modulo 63.
Here Cs ( 0 ) = { 0 } , Cs ( 9 ) = { 9 , 18 , 36 } , Cs ( 27 ) = { 27 , 45 , 54 } , and Cs ( 7 ) = { 7 , 14 , 28 , 35 , 49 , 56 } (all reduced modulo 63). For the first code, the generator polynomial g 1 ( x ) = x 7 + 1 is itself a weight-2 codeword, giving d ( C 1 ) = 2 directly. For the second, g 2 ( x ) = x 7 + x 6 + x 4 + x 3 + x + 1 has weight 6, but 1 + x 9 is a codeword of C 2 (one verifies ( 1 + x 9 ) mod g 2 ( x ) = 0 ), giving d ( C 2 ) 2 , and d ( C 2 ) 2 by non-degeneracy, so d ( C 2 ) = 2 . Both codes thus lie in the single regime, established in Corollary 1, where L ( T ) can be a proper divisor of n; here it takes two different values (7 and 9), giving variances in ratio 141.75 / 110.25 = 14 / 11 . d ( D ) also differs between the two codes (9 versus 14); this underscores that neither d ( C ) alone nor d ( D ) alone determines the variance, and that L ( T ) , computed from the full arithmetic structure of T, is required. In both rows, Var ( wt ( D ) ) was computed both by brute-force enumeration of D and by direct evaluation of ( q 1 ) n 2 / ( q 2 L ( T ) ) from Theorem 1, and independently cross-checked against the classical identity Var ( wt ( D ) ) = [ n ( q 1 ) + 2 A 2 ( C ) ] / q 2 (Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez); all three agree exactly, as recorded in the table. The 14 / 11 ratio of this matched-dimension pair understates the range achievable at n = 63 : among the LCD codes with d ( C ) = 2 enumerated for Table 1, T = Cs ( 0 ) Cs ( 21 ) gives dim D = 3 , L ( T ) = 3 , Var = 330.75 , versus T = Cs ( 0 ) Cs ( 9 ) Cs ( 21 ) Cs ( 27 ) , dim D = 9 , L ( T ) = 21 , Var = 47.25 , a 7 × ratio, both instances again verified by brute-force enumeration of D.

6.4. Application to the BCH-Type Length- λ ( q m + 1 ) Family

Section 2.3 surveys BCH-type LCD cyclic codes of length n = λ ( q m + 1 ) , λ q 1 [7,8], without indicating how the variance formula of Theorem 1 bears on this specific family. We give a concrete instance here. Take q = 3 , m = 2 , λ = 2 (so λ q 1 = 2 ), giving n = λ ( q m + 1 ) = 2 ( 3 2 + 1 ) = 20 . The 3-cyclotomic cosets modulo 20 are { 0 } , { 2 , 6 , 14 , 18 } , { 4 , 8 , 12 , 16 } , { 5 , 15 } , { 10 } , and the negation-paired block { 1 , 3 , 7 , 9 } { 11 , 13 , 17 , 19 } ; the first five are each individually closed under negation modulo 20, so any union of them yields an LCD code by Yang–Massey [12].
Table 3 exhibits two such LCD codes with identical dimension pair ( dim C , dim D ) = ( 15 , 5 ) and identical d ( C ) = 2 (as it must be, since both have L ( T ) < n ; see Corollary 1), obtained from different coset combinations, yet with L ( T ) differing by a factor of 2.
For the first code, g ( x ) = x 5 + x 4 + 2 x 3 + x 2 + 2 x + 2 has weight 6, but 1 + 2 x 10 is a codeword (verified by polynomial division), giving d ( C ) = 2 ; for the second, g ( x ) = x 5 + 2 is itself a weight-two codeword.
Both codes belong to the length- λ ( q m + 1 ) family surveyed in Section 2.3, both are LCD, and both have the same parameters ( n , k , dim D ) = ( 20 , 15 , 5 ) , the level of detail at which such families are typically reported in the literature. Theorem 1 distinguishes them further: the second code’s masking-code variance is exactly twice the first’s. This is the kind of re-evaluation the variance formula offers for constructions of this type: it supplies, at negligible computational cost, a second-order distinguishing statistic among LCD codes of this family that share identical conventional parameters, without requiring a full weight-enumerator computation for either.

7. Discussion: Scope and Design Implications for ODSM

Theorem 1 shows that the invariant governing whether a cyclic masking code’s Hamming-weight variance can deviate from the generic value n ( q 1 ) / q 2 is L ( T ) , and, by Corollary 1, L ( T ) = n exactly when d ( C ) 3 . We state this domain restriction explicitly since it delimits the entire practical scope of the result: for a nonzero, proper cyclic code, L ( T ) can differ from n, and Var ( wt ( D ) ) can differ from the generic value, only when d ( C ) = 2 . Among candidates with d ( C ) 3 , L ( T ) is identically n and provides no further distinguishing information whatsoever; the entire distinguishing power of Theorem 1 is concentrated in the d ( C ) = 2 regime, where it refines A 2 ( C ) (equivalently L ( T ) ) beyond the mere fact that a weight-two word exists. Since d ( C ) = d ( D ) is a parameter of the source code, already maximized in standard ODSM design for error-correction reasons unrelated to side-channel resistance, this exposes a design tension: pushing d ( C ) up for error-correction capacity simultaneously forces the masking code’s Hamming-weight variance to its unique minimum-variance value, collapsing any distinguishing power of L ( T ) , while permitting d ( C ) = 2 opens access to a computable range of variances via A 2 ( C ) = L ( T ) .
On the practical relevance of the case d ( C ) = 2 : in ODSM designs that maximize d ( C ) purely for combined error-correction and leakage-floor reasons, Theorem 1 contributes nothing beyond Lemma 2’s single generic value, and the reader may reasonably ask what the theorem adds outside that regime. Three points bear on this. First, Theorem 1 is a complete characterization across all d ( C ) , not one restricted to d ( C ) = 2 : it shows that this is the only regime where variance-based comparison among candidate codes is possible at all, a boundary fact not previously stated in the literature we surveyed (Section 2.2 and Section 2.3). Second, not every legitimate design constraint forces d ( C ) 3 : a designer working under a fixed rate k / n , a specific structural requirement (e.g., a prescribed automorphism group or compatibility with an existing hardware datapath), or a deliberate choice to trade distance for a different property may end up with d ( C ) = 2 candidates that Theorem 1 lets the designer immediately evaluate rather than treat as unanalyzable. Third, and more modestly, the formula serves an auditing role: given any candidate LCD code with d ( C ) = 2 , whatever its provenance, L ( T ) lets one check in closed form, without brute-force enumeration or full weight-enumerator computation, exactly how far its masking-code variance sits from the generic value.
On the ODSM security interpretation. We restrict the claims above to an algebraic invariant of the masking code D itself and deliberately stop short of a direct side-channel security interpretation for a specific reason worth stating precisely. In ODSM, the leaked quantity for a fixed secret X is the physical function of Z = X G + M H , and Z is uniformly distributed over the coset X G + D , not over D itself; Theorem 1 characterizes Var ( wt ( c ) ) for c D , which is the special case X = 0 . Whether, and how, this coset-zero variance relates to the variance of wt ( Z ) for a general nonzero secret X is a separate question this paper does not answer; more importantly, so is whether it relates to an attacker’s ability to distinguish between the leakage distributions of different values of X , which is what actually governs side-channel security. We have not established a conditional-moment analysis across the q k cosets { x G + D } x GF ( q ) k , nor any bound relating Var ( wt ( D ) ) to a concrete attack metric. Consequently, we present Var ( wt ( D ) ) here strictly as an algebraic invariant of the masking code, useful for comparing candidate masking codes’ zero-secret leakage dispersion under an idealized model, and not as a direct descriptor of ODSM security in the sense of secret-distinguishing advantage; establishing that connection rigorously is left to future work.
On the state of the code-based masking literature. An earlier version of this manuscript stated that the literature optimizes only distance parameters, with no examination of higher moments. This was incorrect, and we correct it here. A substantial and directly relevant line of work, comprising Guilley, Heuser, and Rioul [20]; Poussier, Guo, Standaert, Carlet, and Guilley [21]; Cheng, Guilley, Carlet, Mesnager, and Danger [22]; Cheng, Liu, Guilley, and Rioul [23]; and, most recently, Chen, Fan, Cheng, and Zhou [24], already goes beyond the dual distance d D alone, jointly optimizing it together with the kissing number B d D (the number of minimum-weight codewords in the dual, a close relative of our A 2 ( C ) when the minimum weight is 2), and validates the resulting ordering with simulated attack experiments (success rate versus number of traces) rather than distance parameters alone. This body of work is a materially different, more mature undertaking than a distance-tuple comparison, and we no longer claim otherwise. Our contribution relative to it is narrower and more specific: an exact, closed-form arithmetic characterization of A 2 ( C ) (equivalently L ( T ) ) for cyclic codes via their cyclotomic defining set, requiring no enumeration of the kissing number, together with its precise algebraic relationship to Var ( wt ( D ) ) via the classical Pless moment identity (Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez): a complementary, purely algebraic tool that could in principle feed into the kissing-number-based design methodology of this literature for the cyclic case, rather than a competing or more complete security framework.
On the relation to Coelho and Brochero Martínez. As detailed in Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez, the special case of our result where n = Q 1 for Q a power of the prime q is algebraically equivalent to the A 2 formula of Coelho and Brochero Martínez [19], published in 2024. All numerical examples in this paper (Section 6.2, Section 6.3 and Section 6.4) happen to fall inside this special case since 15 = 2 4 1 , 63 = 2 6 1 , 26 = 3 3 1 , and 20 3 4 1 are all of this restricted form or reducible to it; we flag this explicitly rather than let the examples imply a broader novelty than the arithmetic warrants. The generalization that remains new is to arbitrary length n coprime to q (not necessarily of the form Q 1 ) and to arbitrary prime-power base fields q (not necessarily prime), together with the reformulation via the canonical subgroup D ( T ) , the connection to Var ( wt ( D ) ) and ODSM, and the LCD-specific Proposition 2.
We emphasize throughout that Var ( wt ( D ) ) is a second-order algebraic descriptor of leakage dispersion under an idealized Hamming-weight leakage model with no measurement noise, computed for the zero-secret coset. It does not by itself determine DPA/CPA success probability, signal-to-noise ratio [25], mutual information, guessing entropy, or the number of traces required for a successful attack [26]; none of these quantities are analyzed in this paper, and none should be inferred from L ( T ) alone without a fully specified attack model, noise model, and empirical validation against real or simulated traces. Nor does equal variance imply equal leakage security in a stronger sense: two masking codes with identical Var ( wt ( D ) ) can still differ substantially in higher moments or in the full shape of the weight distribution, a limitation we return to in Section 8. With all these caveats, L ( T ) is best read as a low-cost, exactly computable algebraic quantity for the d ( C ) = 2 regime: for a target dimension pair ( n , k ) with d ( C ) = 2 forced or accepted, a designer can enumerate the cyclotomic-coset combinations achieving that dimension and directly compute L ( T ) for each, without ever evaluating a full weight enumerator or kissing number by brute force.

8. Limitations

This work is restricted to cyclic codes; the extension to constacyclic codes ( λ 1 ), which underlies the actively studied LCD BCH constructions of length λ ( q m + 1 ) [7,8], is not addressed here. A preliminary check shows the extension is not a routine substitution: for λ -constacyclic codes the relevant root of unity has order 2 n (for λ = 1 ) rather than n, which changes the dependency condition at the core of the proof of Theorem 1 and requires a separate derivation.
As detailed in Remark 1, Var ( wt ( D ) ) is computed with respect to the symbol-wise Hamming weight over GF ( q ) . This equals the physical bit-transition weight relevant to CMOS power leakage only for q = 2 . For q > 2 , the relationship between symbol-wise weight and physical bit-level leakage depends on an explicit encoding of field symbols into bit vectors, which this paper does not model; the q > 2 instances of Theorem 1 (including the worked example of Section 6.4) should accordingly be read as exact results of independent coding-theoretic interest, whose side-channel relevance for q > 2 hardware requires this additional, unaddressed modeling step.
The variance metric used here is, as stressed in Section 7, a simplified algebraic proxy under an idealized Hamming-weight leakage model. It does not incorporate measurement noise, higher-order masking, non-Hamming-weight leakage functions, or any of the standard quantitative side-channel metrics (success rate, signal-to-noise ratio, mutual information, guessing entropy); no experimental or simulated side-channel evaluation (DPA/CPA traces) was performed, and none of the claims in this paper should be read as a substitute for one. Relatedly, equal variance does not imply equal leakage security: two masking codes can share Var ( wt ( D ) ) while differing substantially in higher moments or in the full shape of their weight distribution, which Theorem 1 does not characterize.
Finally, the literature search supporting the novelty claims in Section 2 was targeted rather than systematic (protocol described in Section 2.5), which limits the strength of broad bibliographic claims; the correction of the literature narrative in Section 7 (regarding the state of the art in dual-distance/kissing-number optimization) illustrates this limitation concretely.

9. Conclusions

This paper is, at its core, a contribution to the algebraic theory of cyclic codes, motivated by but ultimately separable from its cryptographic application. As Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez makes precise, the reduction of Var ( wt ( D ) ) to counting weight-two codewords of C is the classical Pless moment identity, and the closest existing result, Coelho and Brochero Martínez’s 2024 formula for A 2 ( C ) on primitive-length codes over prime fields [19], is algebraically equivalent to ours on its domain. What we contribute is the extension of that arithmetic characterization, via the canonically defined subgroup D ( T ) and the invariant L ( T ) , to cyclic codes of arbitrary length n coprime to q and arbitrary prime-power base fields GF ( q ) (both verified concretely in Section Relation to the Pless Moment Identity and to Coelho–Brochero Martínez, including a non-prime-field instance over GF ( 4 ) ), together with the LCD-specific Proposition 2 showing that the LCD property, while leaving L ( T ) ’s numeric value unchanged, forces every dependent coordinate pair to be related by a sign rather than a general scalar. These are coding-theoretic results, verified without exception against 64 independently constructed cyclic codes across three finite fields and four lengths, and they stand on their own within that discipline.
The motivating application, orthogonal direct sum masking, is where D = C is interpreted as a masking code and d ( C ) = d ( D ) as the dominant distance-based descriptor used in much of the current LCD/ODSM literature; we showed that this descriptor alone does not determine Var ( wt ( D ) ) , and that L ( T ) does so exactly, within the narrow regime d ( C ) = 2 where such distinction is possible at all (Corollary 1). We have been explicit that this variance, computed for the zero-secret coset of the masking code, is a second-order algebraic descriptor under an idealized leakage model, not a complete side-channel security metric, and that a substantial existing literature (Section 7) already evaluates code-based masking through the more operational combination of dual distance and kissing number, validated by simulated attacks, a materially more complete methodology than the one presented here. We position L ( T ) as a low-cost, closed-form algebraic quantity that could complement that methodology for the cyclic case, not as a replacement for it. Constacyclic extension, a systematic literature review, and empirical side-channel validation remain as future work before any such complementary role could be established in practice.

Supplementary Materials

The following supporting information can be downloaded at https://www.mdpi.com/article/10.3390/cryptography10040056/s1.

Funding

This research received no external funding.

Data Availability Statement

The Python source code implementing the verification algorithm of Section 6.1, together with its output logs, accompanies this submission as Supplementary Materials and is also available from the corresponding author upon reasonable request.

Conflicts of Interest

The author declares no conflicts of interest.

References

  1. Massey, J.L. Linear codes with complementary duals. Discret. Math. 1992, 106/107, 337–342. [Google Scholar] [CrossRef]
  2. Carlet, C.; Guilley, S. Complementary dual codes for counter-measures to side-channel attacks. Adv. Math. Commun. 2016, 10, 131–150. [Google Scholar] [CrossRef]
  3. Bringer, J.; Carlet, C.; Chabanne, H.; Guilley, S.; Maghrebi, H. Orthogonal direct sum masking, a smartcard friendly computation paradigm in a code, with builtin protection against side-channel and fault attacks. In Information Security Theory and Practice (WISTP 2014); Springer: Cham, Switzerland, 2014; Volume 8501, pp. 40–56. [Google Scholar]
  4. Carlet, C.; Li, C.; Mesnager, S. Two constructions of optimal pairs of linear codes for resisting side channel and fault injection attacks. arXiv 2018, arXiv:1808.04577. [Google Scholar]
  5. Fan, Y.; Zhang, L. Galois LCD codes over finite fields. Finite Fields Appl. 2018, 49, 227–242. [Google Scholar] [CrossRef]
  6. Verma, G.K.; Agrawal, A.; Sharma, R.K. Construction methods for Galois LCD codes over finite fields. J. Appl. Math. Comput. 2023, 69, 4023–4043. [Google Scholar] [CrossRef]
  7. Liu, J.; Wu, H.; Zhu, L. BCH and LCD cyclic codes of length n = λ(qm + 1) over finite fields. arXiv 2026, arXiv:2603.07688. [Google Scholar]
  8. Zhang, Y. On the parameters of some LCD BCH codes over F q with length (qm + 1)/λ. Cryptogr. Commun. 2024, 16, 745–765. [Google Scholar] [CrossRef]
  9. Bhowmick, S.; Dalai, D.K.; Mesnager, S. On linear complementary pairs of algebraic geometry codes over finite fields. Discret. Math. 2024, 347, 114193. [Google Scholar] [CrossRef]
  10. Crnković, D.; Švob, A. LCD subspace codes. Des. Codes Cryptogr. 2023, 91, 3215–3226. [Google Scholar] [CrossRef]
  11. Sendrier, N. Linear codes with complementary duals meet the Gilbert–Varshamov bound. Discret. Math. 2004, 285, 345–347. [Google Scholar] [CrossRef]
  12. Yang, X.; Massey, J.L. The condition for a cyclic code to have a complementary dual. Discret. Math. 1994, 126, 391–393. [Google Scholar] [CrossRef]
  13. Moisio, M. A note on evaluations of some exponential sums. Acta Arith. 2000, 93, 117–119. [Google Scholar] [CrossRef][Green Version]
  14. Vega, G. A characterization of all semiprimitive irreducible cyclic codes in terms of their lengths. Appl. Algebra Eng. Commun. Comput. 2019, 30, 441–452. [Google Scholar] [CrossRef]
  15. Zhu, H.; Shi, M.; Özbudak, F. Complete b-symbol weight distribution of some irreducible cyclic codes. Des. Codes Cryptogr. 2022, 90, 1113–1125. [Google Scholar] [CrossRef]
  16. de la Cruz Jiménez, R.A. On Some Methods for Constructing Almost Optimal S-Boxes and Their Resilience Against Side-Channel Attacks. IACR Cryptol. ePrint Arch. 2018, 2018/618. Available online: https://eprint.iacr.org/2018/618 (accessed on 6 July 2026).
  17. Picek, S.; Papagiannopoulos, K.; Ege, B.; Batina, L.; Jakobović, D. Confused by confusion: Systematic evaluation of DPA resistance of various S-boxes. In Progress in Cryptology—INDOCRYPT 2014; Springer: Cham, Switzerland, 2014; Volume 8885, pp. 374–390. [Google Scholar]
  18. MacWilliams, F.J.; Sloane, N.J.A. The Theory of Error-Correcting Codes; North-Holland: Amsterdam, The Netherlands, 1977. [Google Scholar]
  19. Coelho, J.G.; Brochero Martínez, F.E. Low-weight codewords in cyclic codes. arXiv 2024, arXiv:2407.18398. [Google Scholar]
  20. Guilley, S.; Heuser, A.; Rioul, O. Codes for side-channel attacks and protections. In Codes, Cryptology and Information Security (C2SI 2017); Springer: Cham, Switzerland, 2017; Volume 10194, pp. 35–55. [Google Scholar]
  21. Poussier, R.; Guo, Q.; Standaert, F.-X.; Carlet, C.; Guilley, S. Connecting and improving direct sum masking and inner product masking. In Smart Card Research and Advanced Applications (CARDIS 2017); Springer: Cham, Switzerland, 2018; Volume 10728, pp. 123–141. [Google Scholar]
  22. Cheng, W.; Guilley, S.; Carlet, C.; Mesnager, S.; Danger, J.-L. Optimizing inner product masking scheme by a coding theory approach. IEEE Trans. Inf. Forensics Secur. 2020, 16, 220–235. [Google Scholar] [CrossRef]
  23. Cheng, W.; Liu, Y.; Guilley, S.; Rioul, O. Toward finding best linear codes for side-channel protections (extended version). J. Cryptogr. Eng. 2024, 14, 131–145. [Google Scholar] [CrossRef]
  24. Chen, X.; Fan, J.; Cheng, W.; Zhou, Y. Optimizing linear codes for code-based masking against side-channel attacks. Tsinghua Sci. Technol. 2026. [Google Scholar] [CrossRef]
  25. Mangard, S. Hardware countermeasures against DPA—A statistical analysis of their effectiveness. In Topics in Cryptology—CT-RSA 2004; Springer: Berlin/Heidelberg, Germany, 2004; Volume 2964, pp. 222–235. [Google Scholar]
  26. Standaert, F.-X.; Malkin, T.G.; Yung, M. A unified framework for the analysis of side-channel key recovery attacks. In Advances in Cryptology—EUROCRYPT 2009; Springer: Berlin/Heidelberg, Germany, 2009; Volume 5479, pp. 443–461. [Google Scholar]
Table 1. Exhaustive verification of Theorem 1 within each tested configuration.
Table 1. Exhaustive verification of Theorem 1 within each tested configuration.
Length nFieldLCD Codes Verified (Below Threshold)Discrepancies
15 GF ( 2 ) 140
63 GF ( 2 ) 310
26 GF ( 3 ) 190
Total 640
Table 2. Two length-63 LCD cyclic codes with equal dim C = 56 , dim D = 7 , and equal d ( C ) = 2 , but different L ( T ) and Var ( wt ( D ) ) .
Table 2. Two length-63 LCD cyclic codes with equal dim C = 56 , dim D = 7 , and equal d ( C ) = 2 , but different L ( T ) and Var ( wt ( D ) ) .
Defining Set Tg(x)d(C)d(D)L(T)A2(C)Var(wt(D))
Cs ( 0 ) Cs ( 9 ) Cs ( 27 ) x 7 + 1 297252 141.750
Cs ( 0 ) Cs ( 7 ) x 7 + x 6 + x 4 + x 3 + x + 1 2149189 110.250
Table 3. Two length-20 LCD cyclic codes (the λ ( q m + 1 ) family, q = 3 , λ = 2 , m = 2 ) with equal dimension and equal d ( C ) = 2 , but different L ( T ) .
Table 3. Two length-20 LCD cyclic codes (the λ ( q m + 1 ) family, q = 3 , λ = 2 , m = 2 ) with equal dimension and equal d ( C ) = 2 , but different L ( T ) .
Defining Set Td(C)d(D)L(T)A2(C)Var(wt(D))
{ 0 } { 2 , 6 , 14 , 18 } 281020 8.889
{ 0 } { 4 , 8 , 12 , 16 } 24560 17.778
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Sosa-Gómez, G. A Closed-Form Hamming-Weight Variance Formula for Cyclic LCD Codes in Orthogonal Direct Sum Masking. Cryptography 2026, 10, 56. https://doi.org/10.3390/cryptography10040056

AMA Style

Sosa-Gómez G. A Closed-Form Hamming-Weight Variance Formula for Cyclic LCD Codes in Orthogonal Direct Sum Masking. Cryptography. 2026; 10(4):56. https://doi.org/10.3390/cryptography10040056

Chicago/Turabian Style

Sosa-Gómez, Guillermo. 2026. "A Closed-Form Hamming-Weight Variance Formula for Cyclic LCD Codes in Orthogonal Direct Sum Masking" Cryptography 10, no. 4: 56. https://doi.org/10.3390/cryptography10040056

APA Style

Sosa-Gómez, G. (2026). A Closed-Form Hamming-Weight Variance Formula for Cyclic LCD Codes in Orthogonal Direct Sum Masking. Cryptography, 10(4), 56. https://doi.org/10.3390/cryptography10040056

Article Metrics

Back to TopTop