Blame doc/man3/RSA_set_method.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
RSA_set_default_method, RSA_get_default_method, RSA_set_method,
Packit c4476c
RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags,
Packit c4476c
RSA_new_method - select RSA method
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/rsa.h>
Packit c4476c
Packit c4476c
 void RSA_set_default_method(const RSA_METHOD *meth);
Packit c4476c
Packit c4476c
 RSA_METHOD *RSA_get_default_method(void);
Packit c4476c
Packit c4476c
 int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
Packit c4476c
Packit c4476c
 RSA_METHOD *RSA_get_method(const RSA *rsa);
Packit c4476c
Packit c4476c
 RSA_METHOD *RSA_PKCS1_OpenSSL(void);
Packit c4476c
Packit c4476c
 int RSA_flags(const RSA *rsa);
Packit c4476c
Packit c4476c
 RSA *RSA_new_method(ENGINE *engine);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
Packit c4476c
operations. By modifying the method, alternative implementations such as
Packit c4476c
hardware accelerators may be used. IMPORTANT: See the NOTES section for
Packit c4476c
important information about how these RSA API functions are affected by the
Packit c4476c
use of B<ENGINE> API calls.
Packit c4476c
Packit c4476c
Initially, the default RSA_METHOD is the OpenSSL internal implementation,
Packit c4476c
as returned by RSA_PKCS1_OpenSSL().
Packit c4476c
Packit c4476c
RSA_set_default_method() makes B<meth> the default method for all RSA
Packit c4476c
structures created later.
Packit c4476c
B<NB>: This is true only whilst no ENGINE has
Packit c4476c
been set as a default for RSA, so this function is no longer recommended.
Packit c4476c
This function is not thread-safe and should not be called at the same time
Packit c4476c
as other OpenSSL functions.
Packit c4476c
Packit c4476c
RSA_get_default_method() returns a pointer to the current default
Packit c4476c
RSA_METHOD. However, the meaningfulness of this result is dependent on
Packit c4476c
whether the ENGINE API is being used, so this function is no longer
Packit c4476c
recommended.
Packit c4476c
Packit c4476c
RSA_set_method() selects B<meth> to perform all operations using the key
Packit c4476c
B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
Packit c4476c
previous method was supplied by an ENGINE, the handle to that ENGINE will
Packit c4476c
be released during the change. It is possible to have RSA keys that only
Packit c4476c
work with certain RSA_METHOD implementations (eg. from an ENGINE module
Packit c4476c
that supports embedded hardware-protected keys), and in such cases
Packit c4476c
attempting to change the RSA_METHOD for the key can have unexpected
Packit c4476c
results.
Packit c4476c
Packit c4476c
RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
Packit c4476c
This method may or may not be supplied by an ENGINE implementation, but if
Packit c4476c
it is, the return value can only be guaranteed to be valid as long as the
Packit c4476c
RSA key itself is valid and does not have its implementation changed by
Packit c4476c
RSA_set_method().
Packit c4476c
Packit c4476c
RSA_flags() returns the B<flags> that are set for B<rsa>'s current
Packit c4476c
RSA_METHOD. See the BUGS section.
Packit c4476c
Packit c4476c
RSA_new_method() allocates and initializes an RSA structure so that
Packit c4476c
B<engine> will be used for the RSA operations. If B<engine> is NULL, the
Packit c4476c
default ENGINE for RSA operations is used, and if no default ENGINE is set,
Packit c4476c
the RSA_METHOD controlled by RSA_set_default_method() is used.
Packit c4476c
Packit c4476c
RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
Packit c4476c
Packit c4476c
RSA_new_method() allocates and initializes an B<RSA> structure so that
Packit c4476c
B<method> will be used for the RSA operations. If B<method> is B<NULL>,
Packit c4476c
the default method is used.
Packit c4476c
Packit c4476c
=head1 THE RSA_METHOD STRUCTURE
Packit c4476c
Packit c4476c
 typedef struct rsa_meth_st
Packit c4476c
 {
Packit c4476c
     /* name of the implementation */
Packit c4476c
     const char *name;
Packit c4476c
Packit c4476c
     /* encrypt */
Packit c4476c
     int (*rsa_pub_enc)(int flen, unsigned char *from,
Packit c4476c
                        unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
     /* verify arbitrary data */
Packit c4476c
     int (*rsa_pub_dec)(int flen, unsigned char *from,
Packit c4476c
                        unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
     /* sign arbitrary data */
Packit c4476c
     int (*rsa_priv_enc)(int flen, unsigned char *from,
Packit c4476c
                         unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
     /* decrypt */
Packit c4476c
     int (*rsa_priv_dec)(int flen, unsigned char *from,
Packit c4476c
                         unsigned char *to, RSA *rsa, int padding);
Packit c4476c
Packit c4476c
     /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
Packit c4476c
     int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
Packit c4476c
Packit c4476c
     /* compute r = a ^ p mod m (May be NULL for some implementations) */
Packit c4476c
     int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
Packit c4476c
                       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
Packit c4476c
Packit c4476c
     /* called at RSA_new */
Packit c4476c
     int (*init)(RSA *rsa);
Packit c4476c
Packit c4476c
     /* called at RSA_free */
Packit c4476c
     int (*finish)(RSA *rsa);
Packit c4476c
Packit c4476c
     /*
Packit c4476c
      * RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
Packit c4476c
      *                            operations, even if p,q,dmp1,dmq1,iqmp
Packit c4476c
      *                            are NULL
Packit c4476c
      * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
Packit c4476c
      */
Packit c4476c
     int flags;
Packit c4476c
Packit c4476c
     char *app_data; /* ?? */
Packit c4476c
Packit c4476c
     int (*rsa_sign)(int type,
Packit c4476c
                     const unsigned char *m, unsigned int m_length,
Packit c4476c
                     unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
Packit c4476c
     int (*rsa_verify)(int dtype,
Packit c4476c
                       const unsigned char *m, unsigned int m_length,
Packit c4476c
                       const unsigned char *sigbuf, unsigned int siglen,
Packit c4476c
                       const RSA *rsa);
Packit c4476c
     /* keygen. If NULL builtin RSA key generation will be used */
Packit c4476c
     int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
Packit c4476c
Packit c4476c
 } RSA_METHOD;
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
RSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method()
Packit c4476c
and RSA_get_method() return pointers to the respective RSA_METHODs.
Packit c4476c
Packit c4476c
RSA_set_default_method() returns no value.
Packit c4476c
Packit c4476c
RSA_set_method() returns a pointer to the old RSA_METHOD implementation
Packit c4476c
that was replaced. However, this return value should probably be ignored
Packit c4476c
because if it was supplied by an ENGINE, the pointer could be invalidated
Packit c4476c
at any time if the ENGINE is unloaded (in fact it could be unloaded as a
Packit c4476c
result of the RSA_set_method() function releasing its handle to the
Packit c4476c
ENGINE). For this reason, the return type may be replaced with a B<void>
Packit c4476c
declaration in a future release.
Packit c4476c
Packit c4476c
RSA_new_method() returns NULL and sets an error code that can be obtained
Packit c4476c
by L<ERR_get_error(3)> if the allocation fails. Otherwise
Packit c4476c
it returns a pointer to the newly allocated structure.
Packit c4476c
Packit c4476c
=head1 BUGS
Packit c4476c
Packit c4476c
The behaviour of RSA_flags() is a mis-feature that is left as-is for now
Packit c4476c
to avoid creating compatibility problems. RSA functionality, such as the
Packit c4476c
encryption functions, are controlled by the B<flags> value in the RSA key
Packit c4476c
itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
Packit c4476c
(which is what this function returns). If the flags element of an RSA key
Packit c4476c
is changed, the changes will be honoured by RSA functionality but will not
Packit c4476c
be reflected in the return value of the RSA_flags() function - in effect
Packit c4476c
RSA_flags() behaves more like an RSA_default_flags() function (which does
Packit c4476c
not currently exist).
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<RSA_new(3)>
Packit c4476c
Packit c4476c
=head1 HISTORY
Packit c4476c
Packit c4476c
The RSA_null_method(), which was a partial attempt to avoid patent issues,
Packit c4476c
was replaced to always return NULL in OpenSSL 1.1.1.
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2000-2016 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