Skip to content

Commit

Permalink
Add shr method
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Aug 11, 2023
1 parent dbd841a commit d6aa9f2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Src/Autarkysoft.Bitcoin/Cryptography/EllipticCurve/Scalar8x32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,31 @@ private static Scalar8x32 Reduce(in Scalar8x32 r, uint overflow)
}


/// <summary>
/// Shift this scalar right by the given amount strictly between 0 and 16.
/// </summary>
/// <param name="shift">Shift must be between 0 and 16</param>
/// <param name="ret">Low bits that were shifted off</param>
/// <returns>Shifted scalar</returns>
public unsafe Scalar8x32 Shr16(int shift, out uint ret)
{
Debug.Assert(shift > 0);
Debug.Assert(shift < 16);

ret = b0 & ((1U << shift) - 1);
uint r0 = (b0 >> shift) + (b1 << (32 - shift));
uint r1 = (b1 >> shift) + (b2 << (32 - shift));
uint r2 = (b2 >> shift) + (b3 << (32 - shift));
uint r3 = (b3 >> shift) + (b4 << (32 - shift));
uint r4 = (b4 >> shift) + (b5 << (32 - shift));
uint r5 = (b5 >> shift) + (b6 << (32 - shift));
uint r6 = (b6 >> shift) + (b7 << (32 - shift));
uint r7 = (b7 >> shift);

return new Scalar8x32(r0, r1, r2, r3, r4, r5, r6, r7);
}


public static unsafe Scalar8x32 MulShiftVar(in Scalar8x32 a, in Scalar8x32 b, int shift)
{
Debug.Assert(shift >= 256);
Expand Down

0 comments on commit d6aa9f2

Please sign in to comment.