Hi,

I had reported this privately to Niels Möller, but I'm re-sending it
here so it's publicly available and archived. (Niels didn't think it's
neccesary to keep this private.)

The attached example will show a bug in the nistp256 point
multiplication of nettle. It compiles a certain curve point with 1
which should not change the coordinates, however it does.

Was fixed here:
https://git.lysator.liu.se/nettle/nettle/commit/c71d2c9d20eeebb985e3872e4550137209e3ce4d


-- 
Hanno Böck
http://hboeck.de/

mail/jabber: [email protected]
GPG: BBB51E42
#include <stdio.h>
#include <gmp.h>
#include <nettle/ecc.h>
#include <nettle/ecc-curve.h>

#define XCOORD "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFF001C2C00"
#define YCOORD "9731275B8E973CEAFD8ABF5A6E16A177F05A345114FBC7527B3A60BC65FE606A"


int main(int argc, char *argv[]) {
	mpz_t x, y, rx, ry, gmul;
	struct ecc_point point, result;
	struct ecc_scalar gs1;
	char* outx;

	mpz_init_set_str(x, XCOORD, 16);
	mpz_init_set_str(y, YCOORD, 16);
	mpz_init_set_str(gmul, "1", 16);

	gmp_printf("input x:  %ZX\n", x);
	gmp_printf("input y:  %ZX\n", y);
	gmp_printf("scalar:   %ZX\n\n", gmul);

	ecc_point_init(&point, &nettle_secp_256r1);
	if (ecc_point_set(&point, x, y) == 0) { printf("point not on curve\n"); return -1; }

	ecc_scalar_init(&gs1, &nettle_secp_256r1);
	if (ecc_scalar_set(&gs1, gmul) ==0) { printf ("scalar out of range\n"); return -1; }

	ecc_point_init(&result, &nettle_secp_256r1);
	ecc_point_mul(&result, &gs1, &point);

	mpz_init(rx);
	mpz_init(ry);
	ecc_point_get(&result, rx, ry);
	gmp_asprintf(&outx, "%ZX", rx);

	printf("output x: %s\n", outx);

	if (strcmp(outx, XCOORD)!=0) printf("Output and input don't match!\n");

	return 0;
}

Attachment: pgpzudwC15UB5.pgp
Description: OpenPGP digital signature

_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs

Reply via email to