Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
| 5 | RSA_set0_key, RSA_set0_factors, RSA_set0_crt_params, RSA_get0_key, |
| 6 | RSA_get0_factors, RSA_get0_crt_params, RSA_clear_flags, |
| 7 | RSA_test_flags, RSA_set_flags, RSA_get0_engine - Routines for getting |
| 8 | and setting data in an RSA object |
| 9 | |
| 10 | =head1 SYNOPSIS |
| 11 | |
| 12 | #include <openssl/rsa.h> |
| 13 | |
| 14 | int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d); |
| 15 | int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q); |
| 16 | int RSA_set0_crt_params(RSA *r,BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp); |
Richard Levitte | fd809cf | 2016-06-14 15:48:16 +0200 | [diff] [blame^] | 17 | void RSA_get0_key(const RSA *r, |
| 18 | const BIGNUM **n, const BIGNUM **e, const BIGNUM **d); |
| 19 | void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q); |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 20 | void RSA_get0_crt_params(const RSA *r, |
Richard Levitte | fd809cf | 2016-06-14 15:48:16 +0200 | [diff] [blame^] | 21 | const BIGNUM **dmp1, const BIGNUM **dmq1, |
| 22 | const BIGNUM **iqmp); |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 23 | void RSA_clear_flags(RSA *r, int flags); |
| 24 | int RSA_test_flags(const RSA *r, int flags); |
| 25 | void RSA_set_flags(RSA *r, int flags); |
| 26 | ENGINE *RSA_get0_engine(RSA *r); |
| 27 | |
| 28 | =head1 DESCRIPTION |
| 29 | |
| 30 | An RSA object contains the components for the public and private key, |
| 31 | B<n>, B<e>, B<d>, B<p>, B<q>, B<dmp1>, B<dmq1> and B<iqmp>. B<n> is |
| 32 | the modulus common to both public and private key, B<e> is the public |
| 33 | exponent and B<d> is the private exponent. B<p>, B<q>, B<dmp1>, |
| 34 | B<dmq1> and B<iqmp> are the factors for the second representation of a |
| 35 | private key (see PKCS#1 section 3 Key Types), where B<p> and B<q> are |
| 36 | the first and second factor of B<n> and B<dmp1>, B<dmq1> and B<iqmp> |
| 37 | are the exponents and coefficient for CRT calculations. |
| 38 | |
| 39 | The B<n>, B<e> and B<d> parameters can be obtained by calling |
| 40 | RSA_get0_key(). If they have not been set yet, then B<*n>, B<*e> and |
| 41 | B<*d> will be set to NULL. Otherwise, they are set to pointers to |
| 42 | their respective values. These point directly to the internal |
| 43 | representations of the values and therefore should not be freed |
| 44 | by the caller. |
| 45 | |
| 46 | The B<n>, B<e> and B<d> parameter values can be set by calling |
| 47 | RSA_set0_key() and passing the new values for B<n>, B<e> and B<d> as |
Richard Levitte | 4c5e6b2 | 2016-04-26 13:40:53 +0200 | [diff] [blame] | 48 | parameters to the function. The values B<n> and B<e> must be non-NULL |
| 49 | the first time this function is called on a given RSA object. The |
| 50 | value B<d> may be NULL. On subsequent calls any of these values may be |
| 51 | NULL which means the corresponding RSA field is left untouched. |
| 52 | Calling this function transfers the memory management of the values to |
| 53 | the RSA object, and therefore the values that have been passed in |
| 54 | should not be freed by the caller after this function has been called. |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 55 | |
| 56 | In a similar fashion, the B<p> and B<q> parameters can be obtained and |
| 57 | set with RSA_get0_factors() and RSA_set0_factors(), and the B<dmp1>, |
| 58 | B<dmq1> and B<iqmp> parameters can be obtained and set with |
| 59 | RSA_get0_crt_params() and RSA_set0_crt_params(). |
| 60 | |
| 61 | RSA_set_flags() sets the flags in the B<flags> parameter on the RSA |
| 62 | object. Multiple flags can be passed in one go (bitwise ORed together). |
| 63 | Any flags that are already set are left set. RSA_test_flags() tests to |
| 64 | see whether the flags passed in the B<flags> parameter are currently |
| 65 | set in the RSA object. Multiple flags can be tested in one go. All |
| 66 | flags that are currently set are returned, or zero if none of the |
| 67 | flags are set. RSA_clear_flags() clears the specified flags within the |
| 68 | RSA object. |
| 69 | |
| 70 | RSA_get0_engine() returns a handle to the ENGINE that has been set for |
| 71 | this RSA object, or NULL if no such ENGINE has been set. |
| 72 | |
Richard Levitte | 4c5e6b2 | 2016-04-26 13:40:53 +0200 | [diff] [blame] | 73 | =head1 NOTES |
| 74 | |
| 75 | Values retrieved with RSA_get0_key() are owned by the RSA object used |
| 76 | in the call and may therefore I<not> be passed to RSA_set0_key(). If |
| 77 | needed, duplicate the received value using BN_dup() and pass the |
| 78 | duplicate. The same applies to RSA_get0_factors() and RSA_set0_factors() |
| 79 | as well as RSA_get0_crt_params() and RSA_set0_crt_params(). |
| 80 | |
Richard Levitte | b879882 | 2016-04-02 16:43:21 +0200 | [diff] [blame] | 81 | =head1 RETURN VALUES |
| 82 | |
| 83 | RSA_set0_key(), RSA_set0_factors and RSA_set0_crt_params() return 1 on |
| 84 | success or 0 on failure. |
| 85 | |
| 86 | RSA_test_flags() returns the current state of the flags in the RSA object. |
| 87 | |
| 88 | RSA_get0_engine() returns the ENGINE set for the RSA object or NULL if no |
| 89 | ENGINE has been set. |
| 90 | |
| 91 | =head1 SEE ALSO |
| 92 | |
| 93 | L<rsa(3)>, L<RSA_new(3)>, L<RSA_size(3)> |
| 94 | |
| 95 | =head1 HISTORY |
| 96 | |
| 97 | The functions described here were added in OpenSSL version 1.1.0. |
| 98 | |
Rich Salz | e2f9261 | 2016-05-18 11:44:05 -0400 | [diff] [blame] | 99 | =head1 COPYRIGHT |
| 100 | |
| 101 | Copyright 2016 The OpenSSL Project Authors. All Rights Reserved. |
| 102 | |
| 103 | Licensed under the OpenSSL license (the "License"). You may not use |
| 104 | this file except in compliance with the License. You can obtain a copy |
| 105 | in the file LICENSE in the source distribution or at |
| 106 | L<https://www.openssl.org/source/license.html>. |
| 107 | |
| 108 | =cut |