- /* convert pub_point to a octet string according to the SECG standard */
- if ((pub_key_len = EC_POINT_point2buf(ecg, pub_point,
- POINT_CONVERSION_COMPRESSED,
- pub_key, bnctx)) == 0
- || !ossl_param_build_set_octet_string(tmpl, params,
- OSSL_PKEY_PARAM_PUB_KEY,
- *pub_key, pub_key_len))
- goto err;
+
+ /* If we are doing a get then check first before decoding the point */
+ if (tmpl == NULL) {
+ p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_PUB_KEY);
+ px = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_PUB_X);
+ py = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_PUB_Y);
+ }
+
+ if (p != NULL || tmpl != NULL) {
+ /* convert pub_point to a octet string according to the SECG standard */
+ if ((pub_key_len = EC_POINT_point2buf(ecg, pub_point,
+ POINT_CONVERSION_COMPRESSED,
+ pub_key, bnctx)) == 0
+ || !ossl_param_build_set_octet_string(tmpl, p,
+ OSSL_PKEY_PARAM_PUB_KEY,
+ *pub_key, pub_key_len))
+ goto err;
+ }
+ if (px != NULL || py != NULL) {
+ if (px != NULL)
+ x = BN_CTX_get(bnctx);
+ if (py != NULL)
+ y = BN_CTX_get(bnctx);
+
+ if (!EC_POINT_get_affine_coordinates(ecg, pub_point, x, y, bnctx))
+ goto err;
+ if (px != NULL
+ && !ossl_param_build_set_bn(tmpl, px,
+ OSSL_PKEY_PARAM_EC_PUB_X, x))
+ goto err;
+ if (py != NULL
+ && !ossl_param_build_set_bn(tmpl, py,
+ OSSL_PKEY_PARAM_EC_PUB_Y, y))
+ goto err;
+ }