Home | History | Annotate | Line # | Download | only in man3
      1      1.1  christos =pod
      2      1.1  christos 
      3      1.1  christos =head1 NAME
      4      1.1  christos 
      5      1.1  christos RSA_set_default_method, RSA_get_default_method, RSA_set_method,
      6      1.1  christos RSA_get_method, RSA_PKCS1_OpenSSL, RSA_flags,
      7      1.1  christos RSA_new_method - select RSA method
      8      1.1  christos 
      9      1.1  christos =head1 SYNOPSIS
     10      1.1  christos 
     11      1.1  christos  #include <openssl/rsa.h>
     12      1.1  christos 
     13  1.1.1.3  christos The following functions have been deprecated since OpenSSL 3.0, and can be
     14  1.1.1.3  christos hidden entirely by defining B<OPENSSL_API_COMPAT> with a suitable version value,
     15  1.1.1.3  christos see L<openssl_user_macros(7)>:
     16  1.1.1.3  christos 
     17      1.1  christos  void RSA_set_default_method(const RSA_METHOD *meth);
     18      1.1  christos 
     19  1.1.1.3  christos  const RSA_METHOD *RSA_get_default_method(void);
     20      1.1  christos 
     21      1.1  christos  int RSA_set_method(RSA *rsa, const RSA_METHOD *meth);
     22      1.1  christos 
     23  1.1.1.3  christos  const RSA_METHOD *RSA_get_method(const RSA *rsa);
     24      1.1  christos 
     25  1.1.1.3  christos  const RSA_METHOD *RSA_PKCS1_OpenSSL(void);
     26      1.1  christos 
     27      1.1  christos  int RSA_flags(const RSA *rsa);
     28      1.1  christos 
     29      1.1  christos  RSA *RSA_new_method(ENGINE *engine);
     30      1.1  christos 
     31      1.1  christos =head1 DESCRIPTION
     32      1.1  christos 
     33  1.1.1.3  christos All of the functions described on this page are deprecated.
     34  1.1.1.3  christos Applications should instead use the OSSL_PROVIDER APIs.
     35  1.1.1.3  christos 
     36      1.1  christos An B<RSA_METHOD> specifies the functions that OpenSSL uses for RSA
     37      1.1  christos operations. By modifying the method, alternative implementations such as
     38      1.1  christos hardware accelerators may be used. IMPORTANT: See the NOTES section for
     39      1.1  christos important information about how these RSA API functions are affected by the
     40      1.1  christos use of B<ENGINE> API calls.
     41      1.1  christos 
     42      1.1  christos Initially, the default RSA_METHOD is the OpenSSL internal implementation,
     43      1.1  christos as returned by RSA_PKCS1_OpenSSL().
     44      1.1  christos 
     45      1.1  christos RSA_set_default_method() makes B<meth> the default method for all RSA
     46      1.1  christos structures created later.
     47      1.1  christos B<NB>: This is true only whilst no ENGINE has
     48      1.1  christos been set as a default for RSA, so this function is no longer recommended.
     49      1.1  christos This function is not thread-safe and should not be called at the same time
     50      1.1  christos as other OpenSSL functions.
     51      1.1  christos 
     52      1.1  christos RSA_get_default_method() returns a pointer to the current default
     53      1.1  christos RSA_METHOD. However, the meaningfulness of this result is dependent on
     54      1.1  christos whether the ENGINE API is being used, so this function is no longer
     55      1.1  christos recommended.
     56      1.1  christos 
     57      1.1  christos RSA_set_method() selects B<meth> to perform all operations using the key
     58      1.1  christos B<rsa>. This will replace the RSA_METHOD used by the RSA key and if the
     59      1.1  christos previous method was supplied by an ENGINE, the handle to that ENGINE will
     60      1.1  christos be released during the change. It is possible to have RSA keys that only
     61  1.1.1.2  christos work with certain RSA_METHOD implementations (e.g. from an ENGINE module
     62      1.1  christos that supports embedded hardware-protected keys), and in such cases
     63      1.1  christos attempting to change the RSA_METHOD for the key can have unexpected
     64      1.1  christos results.
     65      1.1  christos 
     66      1.1  christos RSA_get_method() returns a pointer to the RSA_METHOD being used by B<rsa>.
     67      1.1  christos This method may or may not be supplied by an ENGINE implementation, but if
     68      1.1  christos it is, the return value can only be guaranteed to be valid as long as the
     69      1.1  christos RSA key itself is valid and does not have its implementation changed by
     70      1.1  christos RSA_set_method().
     71      1.1  christos 
     72      1.1  christos RSA_flags() returns the B<flags> that are set for B<rsa>'s current
     73      1.1  christos RSA_METHOD. See the BUGS section.
     74      1.1  christos 
     75      1.1  christos RSA_new_method() allocates and initializes an RSA structure so that
     76      1.1  christos B<engine> will be used for the RSA operations. If B<engine> is NULL, the
     77      1.1  christos default ENGINE for RSA operations is used, and if no default ENGINE is set,
     78      1.1  christos the RSA_METHOD controlled by RSA_set_default_method() is used.
     79      1.1  christos 
     80      1.1  christos RSA_flags() returns the B<flags> that are set for B<rsa>'s current method.
     81      1.1  christos 
     82      1.1  christos RSA_new_method() allocates and initializes an B<RSA> structure so that
     83      1.1  christos B<method> will be used for the RSA operations. If B<method> is B<NULL>,
     84      1.1  christos the default method is used.
     85      1.1  christos 
     86      1.1  christos =head1 THE RSA_METHOD STRUCTURE
     87      1.1  christos 
     88      1.1  christos  typedef struct rsa_meth_st
     89      1.1  christos  {
     90      1.1  christos      /* name of the implementation */
     91      1.1  christos      const char *name;
     92      1.1  christos 
     93      1.1  christos      /* encrypt */
     94      1.1  christos      int (*rsa_pub_enc)(int flen, unsigned char *from,
     95      1.1  christos                         unsigned char *to, RSA *rsa, int padding);
     96      1.1  christos 
     97      1.1  christos      /* verify arbitrary data */
     98      1.1  christos      int (*rsa_pub_dec)(int flen, unsigned char *from,
     99      1.1  christos                         unsigned char *to, RSA *rsa, int padding);
    100      1.1  christos 
    101      1.1  christos      /* sign arbitrary data */
    102      1.1  christos      int (*rsa_priv_enc)(int flen, unsigned char *from,
    103      1.1  christos                          unsigned char *to, RSA *rsa, int padding);
    104      1.1  christos 
    105      1.1  christos      /* decrypt */
    106      1.1  christos      int (*rsa_priv_dec)(int flen, unsigned char *from,
    107      1.1  christos                          unsigned char *to, RSA *rsa, int padding);
    108      1.1  christos 
    109      1.1  christos      /* compute r0 = r0 ^ I mod rsa->n (May be NULL for some implementations) */
    110      1.1  christos      int (*rsa_mod_exp)(BIGNUM *r0, BIGNUM *I, RSA *rsa);
    111      1.1  christos 
    112      1.1  christos      /* compute r = a ^ p mod m (May be NULL for some implementations) */
    113      1.1  christos      int (*bn_mod_exp)(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
    114      1.1  christos                        const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
    115      1.1  christos 
    116      1.1  christos      /* called at RSA_new */
    117      1.1  christos      int (*init)(RSA *rsa);
    118      1.1  christos 
    119      1.1  christos      /* called at RSA_free */
    120      1.1  christos      int (*finish)(RSA *rsa);
    121      1.1  christos 
    122      1.1  christos      /*
    123      1.1  christos       * RSA_FLAG_EXT_PKEY        - rsa_mod_exp is called for private key
    124      1.1  christos       *                            operations, even if p,q,dmp1,dmq1,iqmp
    125      1.1  christos       *                            are NULL
    126      1.1  christos       * RSA_METHOD_FLAG_NO_CHECK - don't check pub/private match
    127      1.1  christos       */
    128      1.1  christos      int flags;
    129      1.1  christos 
    130      1.1  christos      char *app_data; /* ?? */
    131      1.1  christos 
    132      1.1  christos      int (*rsa_sign)(int type,
    133      1.1  christos                      const unsigned char *m, unsigned int m_length,
    134      1.1  christos                      unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
    135      1.1  christos      int (*rsa_verify)(int dtype,
    136      1.1  christos                        const unsigned char *m, unsigned int m_length,
    137      1.1  christos                        const unsigned char *sigbuf, unsigned int siglen,
    138      1.1  christos                        const RSA *rsa);
    139  1.1.1.3  christos      /* keygen. If NULL built-in RSA key generation will be used */
    140      1.1  christos      int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
    141      1.1  christos 
    142      1.1  christos  } RSA_METHOD;
    143      1.1  christos 
    144      1.1  christos =head1 RETURN VALUES
    145      1.1  christos 
    146      1.1  christos RSA_PKCS1_OpenSSL(), RSA_PKCS1_null_method(), RSA_get_default_method()
    147      1.1  christos and RSA_get_method() return pointers to the respective RSA_METHODs.
    148      1.1  christos 
    149      1.1  christos RSA_set_default_method() returns no value.
    150      1.1  christos 
    151      1.1  christos RSA_set_method() returns a pointer to the old RSA_METHOD implementation
    152      1.1  christos that was replaced. However, this return value should probably be ignored
    153      1.1  christos because if it was supplied by an ENGINE, the pointer could be invalidated
    154      1.1  christos at any time if the ENGINE is unloaded (in fact it could be unloaded as a
    155      1.1  christos result of the RSA_set_method() function releasing its handle to the
    156      1.1  christos ENGINE). For this reason, the return type may be replaced with a B<void>
    157      1.1  christos declaration in a future release.
    158      1.1  christos 
    159      1.1  christos RSA_new_method() returns NULL and sets an error code that can be obtained
    160      1.1  christos by L<ERR_get_error(3)> if the allocation fails. Otherwise
    161      1.1  christos it returns a pointer to the newly allocated structure.
    162      1.1  christos 
    163      1.1  christos =head1 BUGS
    164      1.1  christos 
    165      1.1  christos The behaviour of RSA_flags() is a mis-feature that is left as-is for now
    166      1.1  christos to avoid creating compatibility problems. RSA functionality, such as the
    167      1.1  christos encryption functions, are controlled by the B<flags> value in the RSA key
    168      1.1  christos itself, not by the B<flags> value in the RSA_METHOD attached to the RSA key
    169      1.1  christos (which is what this function returns). If the flags element of an RSA key
    170      1.1  christos is changed, the changes will be honoured by RSA functionality but will not
    171      1.1  christos be reflected in the return value of the RSA_flags() function - in effect
    172      1.1  christos RSA_flags() behaves more like an RSA_default_flags() function (which does
    173      1.1  christos not currently exist).
    174      1.1  christos 
    175      1.1  christos =head1 SEE ALSO
    176      1.1  christos 
    177      1.1  christos L<RSA_new(3)>
    178      1.1  christos 
    179      1.1  christos =head1 HISTORY
    180      1.1  christos 
    181  1.1.1.3  christos All of these functions were deprecated in OpenSSL 3.0.
    182  1.1.1.3  christos 
    183      1.1  christos The RSA_null_method(), which was a partial attempt to avoid patent issues,
    184      1.1  christos was replaced to always return NULL in OpenSSL 1.1.1.
    185      1.1  christos 
    186      1.1  christos =head1 COPYRIGHT
    187      1.1  christos 
    188  1.1.1.3  christos Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
    189      1.1  christos 
    190  1.1.1.3  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    191      1.1  christos this file except in compliance with the License.  You can obtain a copy
    192      1.1  christos in the file LICENSE in the source distribution or at
    193      1.1  christos L<https://www.openssl.org/source/license.html>.
    194      1.1  christos 
    195      1.1  christos =cut
    196