@@ -98,7 +98,7 @@ public unsafe Scalar8x32(uint* hPt, out bool overflow)
98
98
/// <summary>
99
99
/// Initializes a new instance of <see cref="Scalar8x32"/> using the given pointer.
100
100
/// </summary>
101
- /// <param name="hPt"><see cref="Hashing.Sha512. hashState"/> pointer</param>
101
+ /// <param name="hPt">SHA512 hashState pointer</param>
102
102
/// <param name="overflow">Returns true if value is bigger than or equal to curve order; otherwise false</param>
103
103
public unsafe Scalar8x32 ( ulong * hPt , out bool overflow )
104
104
{
@@ -1148,7 +1148,13 @@ public int NegateConditional(int flag, out Scalar8x32 result)
1148
1148
}
1149
1149
1150
1150
1151
-
1151
+ /// <summary>
1152
+ /// Conditional move. Sets <paramref name="r"/> equal to <paramref name="a"/> if flag is true (=1).
1153
+ /// </summary>
1154
+ /// <param name="r"></param>
1155
+ /// <param name="a"></param>
1156
+ /// <param name="flag">Zero or one. Sets <paramref name="r"/> equal to <paramref name="a"/> if flag is one.</param>
1157
+ /// <returns></returns>
1152
1158
public static Scalar8x32 CMov ( in Scalar8x32 r , in Scalar8x32 a , uint flag )
1153
1159
{
1154
1160
Debug . Assert ( GetOverflow ( r ) == 0 ) ;
@@ -1183,9 +1189,18 @@ internal static void Split128(in Scalar8x32 k, out Scalar8x32 r1, out Scalar8x32
1183
1189
r2 = new Scalar8x32 ( k . b4 , k . b5 , k . b6 , k . b7 , 0 , 0 , 0 , 0 ) ;
1184
1190
}
1185
1191
1192
+ /// <summary>
1193
+ /// Find r1 and r2 such that r1+r2*lambda = k, where r1 and r2 or their negations are
1194
+ /// maximum 128 bits long (see <see cref="Point.MulLambda"/>).
1195
+ /// </summary>
1196
+ /// <param name="r1"></param>
1197
+ /// <param name="r2"></param>
1198
+ /// <param name="k"></param>
1186
1199
internal static void SplitLambda ( out Scalar8x32 r1 , out Scalar8x32 r2 , in Scalar8x32 k )
1187
1200
{
1188
- // these _var calls are constant time since the shift amount is constant
1201
+ Debug . Assert ( GetOverflow ( k ) == 0 ) ;
1202
+
1203
+ // these *Var calls are constant time since the shift amount is constant
1189
1204
Scalar8x32 c1 = MulShiftVar ( k , G1 , 384 ) ;
1190
1205
Scalar8x32 c2 = MulShiftVar ( k , G2 , 384 ) ;
1191
1206
c1 = c1 . Multiply ( Minus_b1 ) ;
@@ -1195,6 +1210,8 @@ internal static void SplitLambda(out Scalar8x32 r1, out Scalar8x32 r2, in Scalar
1195
1210
r1 = r1 . Negate ( ) ;
1196
1211
r1 = r1 . Add ( k , out _ ) ;
1197
1212
1213
+ Debug . Assert ( GetOverflow ( r1 ) == 0 ) ;
1214
+ Debug . Assert ( GetOverflow ( r2 ) == 0 ) ;
1198
1215
#if DEBUG
1199
1216
SplitLambdaVerify ( r1 , r2 , k ) ;
1200
1217
#endif
@@ -1235,7 +1252,8 @@ private static void SplitLambdaVerify(in Scalar8x32 r1, in Scalar8x32 r2, in Sca
1235
1252
Debug . Assert ( MemCmpVar ( buf1 , k2_bound , 32 ) < 0 || MemCmpVar ( buf2 , k2_bound , 32 ) < 0 ) ;
1236
1253
}
1237
1254
1238
- private static int MemCmpVar ( Span < byte > s1 , Span < byte > s2 , int n )
1255
+ // https://github.com/bitcoin-core/secp256k1/blob/b314cf28334a91db2fe144d04f86077e2bfd7a25/src/util.h#L212-L228
1256
+ private static int MemCmpVar ( ReadOnlySpan < byte > s1 , ReadOnlySpan < byte > s2 , int n )
1239
1257
{
1240
1258
for ( int i = 0 ; i < n ; i ++ )
1241
1259
{
@@ -1247,7 +1265,8 @@ private static int MemCmpVar(Span<byte> s1, Span<byte> s2, int n)
1247
1265
}
1248
1266
return 0 ;
1249
1267
}
1250
- #endif
1268
+ #endif // DEBUG
1269
+
1251
1270
1252
1271
/// <summary>
1253
1272
/// Returns byte array representation of this instance
0 commit comments