curve25519 icon indicating copy to clipboard operation
curve25519 copied to clipboard

Bugfix for GetNumSize

Open Petr-Kovalev opened this issue 2 years ago • 2 comments

GetNumSize method contains a bug (file https://github.com/hanswolff/curve25519/blob/master/Curve25519/Curve25519.cs)

Original Java method (http://code.google.com/p/curve25519-java/):

	private static final int numsize(byte[] x,int n) {
		while (n--!=0 && x[n]==0)
			;
		return n+1;
	}

The current implementation (note the counter increment):

       static int GetNumSize(byte[] num, int maxSize)
        {
            for (int i = maxSize; i >= 0; i++)
            {
                if (num[i] == 0) return i + 1;
            }
            return 0;
        }

Petr-Kovalev avatar May 11 '22 10:05 Petr-Kovalev

It must be for (int i = maxSize - 1; i >= 0; i--), starting from maxSize -1

andresgutierrez avatar May 30 '22 13:05 andresgutierrez