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