Fix errors in EVP_PKEY_fromdata examples
The EVP_PKEY_fromdata man page has some code examples with various
errors in them. This fixes those errors.
@@ -138,6 +138,7 @@ TODO Write a set of cookbook documents and link to them.
#include <openssl/evp.h>
#include <openssl/param_build.h>
+ #include <openssl/ec.h>
/*
* Fixed data to represent the private and public key.
@@ -160,12 +161,6 @@ TODO Write a set of cookbook documents and link to them.
0x8f, 0xb9, 0x33, 0x6e, 0xcf, 0x12, 0x16, 0x2f,
0x5c, 0xcd, 0x86, 0x71, 0xa8, 0xbf, 0x1a, 0x47
};
- const OSSL_PARAM params[] = {
- OSSL_PARAM_utf8_string("group", "prime256v1", 10),
- OSSL_PARAM_BN("priv", priv, sizeof(priv)),
- OSSL_PARAM_BN("pub", pub, sizeof(pub)),
- OSSL_PARAM_END
- };
int main()
{
@@ -181,15 +176,15 @@ TODO Write a set of cookbook documents and link to them.
param_bld = OSSL_PARAM_BLD_new();
if (priv != NULL && param_bld != NULL
&& OSSL_PARAM_BLD_push_utf8_string(param_bld, "group",
- "prime256v1", 0);
- && OSSL_PARAM_BLD_push_BN(param_bld, "priv", priv);
+ "prime256v1", 0)
+ && OSSL_PARAM_BLD_push_BN(param_bld, "priv", priv)
&& OSSL_PARAM_BLD_push_octet_string(param_bld, "pub",
pub_data, sizeof(pub_data)))
params = OSSL_PARAM_BLD_to_param(param_bld);
ctx = EVP_PKEY_CTX_new_from_name(NULL, "EC", NULL);
if (ctx == NULL
- || params != NULL
+ || params == NULL
|| EVP_PKEY_fromdata_init(ctx) <= 0
|| EVP_PKEY_fromdata(ctx, &pkey, EVP_PKEY_KEYPAIR, params) <= 0) {
exitcode = 1;
@@ -209,12 +204,13 @@ TODO Write a set of cookbook documents and link to them.
=head2 Finding out params for an unknown key type
#include <openssl/evp.h>
+ #include <openssl/core.h>
/* Program expects a key type as first argument */
int main(int argc, char *argv[])
{
EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_from_name(NULL, argv[1], NULL);
- const *OSSL_PARAM *settable_params = NULL;
+ const OSSL_PARAM *settable_params = NULL;
if (ctx == NULL)
exit(1);
@@ -247,9 +243,9 @@ TODO Write a set of cookbook documents and link to them.
}
printf("%s : %s ", settable_params->key, datatype);
if (settable_params->data_size == 0)
- printf("(unlimited size)");
+ printf("(unlimited size)\n");
else
- printf("(maximum size %zu)", settable_params->data_size);
+ printf("(maximum size %zu)\n", settable_params->data_size);
}
}
