[gnutls-devel] GnuTLS | Segfault in gnutls_x509_privkey_export2_pkcs8 if ECDSAP384SHA384 (#516)

Daniel Salzman gitlab at mg.gitlab.com
Mon Jul 16 15:39:38 CEST 2018


```
	gnutls_ecc_curve_t curve = GNUTLS_ECC_CURVE_SECP256R1;

	uint8_t x_data[] = {
		0xdd, 0x3b, 0xe9, 0x90, 0x9e, 0xb8, 0x2b, 0x36, 0x49, 0xa0, 0x0c, 0xc0, 0x30, 0x46, 0x97, 0x13,
		0xdc, 0x77, 0x7b, 0xd5, 0xdf, 0xe2, 0x6b, 0x3d, 0xbd, 0xc5, 0x37, 0x23, 0xde, 0x12, 0xac, 0x97
	};
	gnutls_datum_t x = { .size = sizeof(x_data), .data = x_data };

	uint8_t y_data[] = {
		0x54, 0xa2, 0x67, 0xe9, 0x59, 0xd0, 0xec, 0xa2, 0xcc, 0x34, 0x1b, 0xe6, 0x6b, 0x14, 0x6a, 0xdf,
		0xc3, 0xb4, 0x6c, 0x73, 0x0a, 0x1c, 0x1c, 0x5f, 0xde, 0x48, 0x6c, 0x47, 0x5e, 0x84, 0xf1, 0x75
	};
	gnutls_datum_t y = { .size = sizeof(y_data), .data = y_data };

	uint8_t priv_key[] = {
		0x28, 0xbd, 0xc1, 0xed, 0xed, 0xcd, 0x23, 0xdb, 0x6b, 0x69, 0x34, 0x94, 0xcb, 0xd9, 0xc6, 0xb5,
		0xb7, 0x9d, 0xb5, 0x37, 0x3b, 0xe2, 0x04, 0xea, 0x0a, 0x05, 0xfd, 0xd0, 0x8c, 0x20, 0xd8, 0x9c };
	gnutls_datum_t k = { .size = sizeof(priv_key), .data = priv_key };

	gnutls_x509_privkey_t key = NULL;
	int result = gnutls_x509_privkey_init(&key);
	assert(result == GNUTLS_E_SUCCESS);

	result = gnutls_x509_privkey_import_ecc_raw(key, curve, &x, &y, &k);
	assert(result == GNUTLS_E_SUCCESS);

	gnutls_x509_privkey_fix(key);
	assert(result == GNUTLS_E_SUCCESS);

	gnutls_x509_crt_fmt_t format = GNUTLS_X509_FMT_PEM;
	char *password = NULL;
	int flags = GNUTLS_PKCS_PLAIN;

	uint8_t out_data[4096];
	size_t out_size = 4096;
	result = gnutls_x509_privkey_export_pkcs8(key, format, password, flags,
						out_data, &out_size);
	assert(result == GNUTLS_E_SUCCESS);

	gnutls_x509_privkey_deinit(key);
```

-- 
Reply to this email directly or view it on GitLab: https://gitlab.com/gnutls/gnutls/issues/516#note_88235177
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnutls-devel/attachments/20180716/14d2b542/attachment.html>


More information about the Gnutls-devel mailing list