Blame doc/man3/RSA_get0_key.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key,
Packit c4476c
RSA_get0_factors, RSA_get0_crt_params,
Packit c4476c
RSA_get0_n, RSA_get0_e, RSA_get0_d, RSA_get0_p, RSA_get0_q,
Packit c4476c
RSA_get0_dmp1, RSA_get0_dmq1, RSA_get0_iqmp, RSA_get0_pss_params,
Packit c4476c
RSA_clear_flags,
Packit c4476c
RSA_test_flags, RSA_set_flags, RSA_get0_engine, RSA_get_multi_prime_extra_count,
Packit c4476c
RSA_get0_multi_prime_factors, RSA_get0_multi_prime_crt_params,
Packit c4476c
RSA_set0_multi_prime_params, RSA_get_version
Packit c4476c
- Routines for getting and setting data in an RSA object
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/rsa.h>
Packit c4476c
Packit c4476c
 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
Packit c4476c
 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
Packit c4476c
 int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
Packit c4476c
 void RSA_get0_key(const RSA *r,
Packit c4476c
                   const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
Packit c4476c
 void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
Packit c4476c
 void RSA_get0_crt_params(const RSA *r,
Packit c4476c
                          const BIGNUM **dmp1, const BIGNUM **dmq1,
Packit c4476c
                          const BIGNUM **iqmp);
Packit c4476c
 const BIGNUM *RSA_get0_n(const RSA *d);
Packit c4476c
 const BIGNUM *RSA_get0_e(const RSA *d);
Packit c4476c
 const BIGNUM *RSA_get0_d(const RSA *d);
Packit c4476c
 const BIGNUM *RSA_get0_p(const RSA *d);
Packit c4476c
 const BIGNUM *RSA_get0_q(const RSA *d);
Packit c4476c
 const BIGNUM *RSA_get0_dmp1(const RSA *r);
Packit c4476c
 const BIGNUM *RSA_get0_dmq1(const RSA *r);
Packit c4476c
 const BIGNUM *RSA_get0_iqmp(const RSA *r);
Packit c4476c
 const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *r);
Packit c4476c
 void RSA_clear_flags(RSA *r, int flags);
Packit c4476c
 int RSA_test_flags(const RSA *r, int flags);
Packit c4476c
 void RSA_set_flags(RSA *r, int flags);
Packit c4476c
 ENGINE *RSA_get0_engine(RSA *r);
Packit c4476c
 int RSA_get_multi_prime_extra_count(const RSA *r);
Packit c4476c
 int RSA_get0_multi_prime_factors(const RSA *r, const BIGNUM *primes[]);
Packit c4476c
 int RSA_get0_multi_prime_crt_params(const RSA *r, const BIGNUM *exps[],
Packit c4476c
                                     const BIGNUM *coeffs[]);
Packit c4476c
 int RSA_set0_multi_prime_params(RSA *r, BIGNUM *primes[], BIGNUM *exps[],
Packit c4476c
                                BIGNUM *coeffs[], int pnum);
Packit c4476c
 int RSA_get_version(RSA *r);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
An RSA object contains the components for the public and private key,
Packit c4476c
B<n>, B<e>, B<d>, B

, B<q>, B<dmp1>, B<dmq1> and B<iqmp>. B<n> is

Packit c4476c
the modulus common to both public and private key, B<e> is the public
Packit c4476c
exponent and B<d> is the private exponent.  B

, B<q>, B<dmp1>,

Packit c4476c
B<dmq1> and B<iqmp> are the factors for the second representation of a
Packit c4476c
private key (see PKCS#1 section 3 Key Types), where B

and B<q> are

Packit c4476c
the first and second factor of B<n> and B<dmp1>, B<dmq1> and B<iqmp>
Packit c4476c
are the exponents and coefficient for CRT calculations.
Packit c4476c
Packit c4476c
For multi-prime RSA (defined in RFC 8017), there are also one or more
Packit c4476c
'triplet' in an RSA object. A triplet contains three members, B<r>, B<d>
Packit c4476c
and B<t>. B<r> is the additional prime besides B

and B<q>. B<d> and

Packit c4476c
B<t> are the exponent and coefficient for CRT calculations.
Packit c4476c
Packit c4476c
The B<n>, B<e> and B<d> parameters can be obtained by calling
Packit c4476c
RSA_get0_key().  If they have not been set yet, then B<*n>, B<*e> and
Packit c4476c
B<*d> will be set to NULL.  Otherwise, they are set to pointers to
Packit c4476c
their respective values. These point directly to the internal
Packit c4476c
representations of the values and therefore should not be freed
Packit c4476c
by the caller.
Packit c4476c
Packit c4476c
The B<n>, B<e> and B<d> parameter values can be set by calling
Packit c4476c
RSA_set0_key() and passing the new values for B<n>, B<e> and B<d> as
Packit c4476c
parameters to the function.  The values B<n> and B<e> must be non-NULL
Packit c4476c
the first time this function is called on a given RSA object. The
Packit c4476c
value B<d> may be NULL. On subsequent calls any of these values may be
Packit c4476c
NULL which means the corresponding RSA field is left untouched.
Packit c4476c
Calling this function transfers the memory management of the values to
Packit c4476c
the RSA object, and therefore the values that have been passed in
Packit c4476c
should not be freed by the caller after this function has been called.
Packit c4476c
Packit c4476c
In a similar fashion, the B

and B<q> parameters can be obtained and

Packit c4476c
set with RSA_get0_factors() and RSA_set0_factors(), and the B<dmp1>,
Packit c4476c
B<dmq1> and B<iqmp> parameters can be obtained and set with
Packit c4476c
RSA_get0_crt_params() and RSA_set0_crt_params().
Packit c4476c
Packit c4476c
For RSA_get0_key(), RSA_get0_factors(), and RSA_get0_crt_params(),
Packit c4476c
NULL value BIGNUM ** output parameters are permitted. The functions
Packit c4476c
ignore NULL parameters but return values for other, non-NULL, parameters.
Packit c4476c
Packit c4476c
For multi-prime RSA, RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params()
Packit c4476c
can be used to obtain other primes and related CRT parameters. The
Packit c4476c
return values are stored in an array of B<BIGNUM *>. RSA_set0_multi_prime_params()
Packit c4476c
sets a collect of multi-prime 'triplet' members (prime, exponent and coefficient)
Packit c4476c
into an RSA object.
Packit c4476c
Packit c4476c
Any of the values B<n>, B<e>, B<d>, B

, B<q>, B<dmp1>, B<dmq1>, and B<iqmp> can also be

Packit c4476c
retrieved separately by the corresponding function
Packit c4476c
RSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(),
Packit c4476c
RSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp(), respectively.
Packit c4476c
Packit c4476c
RSA_get0_pss_params() is used to retrieve the RSA-PSS parameters.
Packit c4476c
Packit c4476c
RSA_set_flags() sets the flags in the B<flags> parameter on the RSA
Packit c4476c
object. Multiple flags can be passed in one go (bitwise ORed together).
Packit c4476c
Any flags that are already set are left set. RSA_test_flags() tests to
Packit c4476c
see whether the flags passed in the B<flags> parameter are currently
Packit c4476c
set in the RSA object. Multiple flags can be tested in one go. All
Packit c4476c
flags that are currently set are returned, or zero if none of the
Packit c4476c
flags are set. RSA_clear_flags() clears the specified flags within the
Packit c4476c
RSA object.
Packit c4476c
Packit c4476c
RSA_get0_engine() returns a handle to the ENGINE that has been set for
Packit c4476c
this RSA object, or NULL if no such ENGINE has been set.
Packit c4476c
Packit c4476c
RSA_get_version() returns the version of an RSA object B<r>.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
Values retrieved with RSA_get0_key() are owned by the RSA object used
Packit c4476c
in the call and may therefore I<not> be passed to RSA_set0_key().  If
Packit c4476c
needed, duplicate the received value using BN_dup() and pass the
Packit c4476c
duplicate.  The same applies to RSA_get0_factors() and RSA_set0_factors()
Packit c4476c
as well as RSA_get0_crt_params() and RSA_set0_crt_params().
Packit c4476c
Packit c4476c
The caller should obtain the size by calling RSA_get_multi_prime_extra_count()
Packit c4476c
in advance and allocate sufficient buffer to store the return values before
Packit c4476c
calling RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_params().
Packit c4476c
Packit c4476c
RSA_set0_multi_prime_params() always clears the original multi-prime
Packit c4476c
triplets in RSA object B<r> and assign the new set of triplets into it.
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
RSA_set0_key(), RSA_set0_factors(), RSA_set0_crt_params() and
Packit c4476c
RSA_set0_multi_prime_params() return 1 on success or 0 on failure.
Packit c4476c
Packit c4476c
RSA_get0_n(), RSA_get0_e(), RSA_get0_d(), RSA_get0_p(), RSA_get0_q(),
Packit c4476c
RSA_get0_dmp1(), RSA_get0_dmq1(), and RSA_get0_iqmp()
Packit c4476c
return the respective value.
Packit c4476c
Packit c4476c
RSA_get0_multi_prime_factors() and RSA_get0_multi_prime_crt_params() return
Packit c4476c
1 on success or 0 on failure.
Packit c4476c
Packit c4476c
RSA_get_multi_prime_extra_count() returns two less than the number of primes
Packit c4476c
in use, which is 0 for traditional RSA and the number of extra primes for
Packit c4476c
multi-prime RSA.
Packit c4476c
Packit c4476c
RSA_get_version() returns B<RSA_ASN1_VERSION_MULTI> for multi-prime RSA and
Packit c4476c
B<RSA_ASN1_VERSION_DEFAULT> for normal two-prime RSA, as defined in RFC 8017.
Packit c4476c
Packit c4476c
RSA_test_flags() returns the current state of the flags in the RSA object.
Packit c4476c
Packit c4476c
RSA_get0_engine() returns the ENGINE set for the RSA object or NULL if no
Packit c4476c
ENGINE has been set.
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<RSA_new(3)>, L<RSA_size(3)>
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
The RSA_get0_pss_params() function was added in OpenSSL 1.1.1e.
Packit c4476c
Packit c4476c
The
Packit c4476c
RSA_get_multi_prime_extra_count(), RSA_get0_multi_prime_factors(),
Packit c4476c
RSA_get0_multi_prime_crt_params(), RSA_set0_multi_prime_params(),
Packit c4476c
and RSA_get_version() functions were added in OpenSSL 1.1.1.
Packit c4476c
Packit c4476c
Other functions described here were added in OpenSSL 1.1.0.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut