Blame doc/man3/RSA_set_method.pod

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