Home | History | Annotate | Line # | Download | only in designs
      1  1.1  christos Fetching composite algorithms and using them - adding the bits still missing
      2  1.1  christos ============================================================================
      3  1.1  christos 
      4  1.1  christos Quick background
      5  1.1  christos ----------------
      6  1.1  christos 
      7  1.1  christos We currently support - at least in the public libcrypto API - explicitly
      8  1.1  christos fetching composite algorithms (such as AES-128-CBC or HMAC-SHA256), and
      9  1.1  christos using them in most cases.  In some cases (symmetric ciphers), our providers
     10  1.1  christos also provide them.
     11  1.1  christos 
     12  1.1  christos However, there is one class of algorithms where the support for *using*
     13  1.1  christos explicitly fetched algorithms is lacking: asymmetric algorithms.
     14  1.1  christos 
     15  1.1  christos For a longer background and explanation, see
     16  1.1  christos [Background / tl;dr](#background-tldr) at the end of this design.
     17  1.1  christos 
     18  1.1  christos Public API - Add variants of `EVP_PKEY_CTX` initializers
     19  1.1  christos --------------------------------------------------------
     20  1.1  christos 
     21  1.1  christos As far as this design is concerned, these API sets are affected:
     22  1.1  christos 
     23  1.1  christos - SIGNATURE
     24  1.1  christos - ASYM_CIPHER
     25  1.1  christos - KEYEXCH
     26  1.1  christos 
     27  1.1  christos The proposal is to add these initializer functions:
     28  1.1  christos 
     29  1.1  christos ``` C
     30  1.1  christos int EVP_PKEY_sign_init_ex2(EVP_PKEY_CTX *pctx,
     31  1.1  christos                            EVP_SIGNATURE *algo, const OSSL_PARAM params[]);
     32  1.1  christos int EVP_PKEY_verify_init_ex2(EVP_PKEY_CTX *pctx,
     33  1.1  christos                              EVP_SIGNATURE *algo, const OSSL_PARAM params[]);
     34  1.1  christos int EVP_PKEY_verify_recover_init_ex2(EVP_PKEY_CTX *pctx,
     35  1.1  christos                                      EVP_SIGNATURE *algo, const OSSL_PARAM params[]);
     36  1.1  christos 
     37  1.1  christos int EVP_PKEY_encrypt_init_ex2(EVP_PKEY_CTX *ctx, EVP_ASYM_CIPHER *asymciph,
     38  1.1  christos                               const OSSL_PARAM params[]);
     39  1.1  christos int EVP_PKEY_decrypt_init_ex2(EVP_PKEY_CTX *ctx, EVP_ASYM_CIPHER *asymciph,
     40  1.1  christos                               const OSSL_PARAM params[]);
     41  1.1  christos 
     42  1.1  christos int EVP_PKEY_derive_init_ex2(EVP_PKEY_CTX *ctx, EVP_KEYEXCH *exchange,
     43  1.1  christos                              const OSSL_PARAM params[]);
     44  1.1  christos ```
     45  1.1  christos 
     46  1.1  christos Detailed proposal for these APIs will be or are prepared in other design
     47  1.1  christos documents:
     48  1.1  christos 
     49  1.1  christos - [Functions for explicitly fetched signature algorithms]
     50  1.1  christos - [Functions for explicitly fetched asym-cipher algorithms] (not yet designed)
     51  1.1  christos - [Functions for explicitly fetched keyexch algorithms] (not yet designed)
     52  1.1  christos 
     53  1.1  christos -----
     54  1.1  christos 
     55  1.1  christos -----
     56  1.1  christos 
     57  1.1  christos Background / tl;dr
     58  1.1  christos ------------------
     59  1.1  christos 
     60  1.1  christos ### What is a composite algorithm?
     61  1.1  christos 
     62  1.1  christos A composite algorithm is an algorithm that's composed of more than one other
     63  1.1  christos algorithm.  In OpenSSL parlance with a focus on signatures, they have been
     64  1.1  christos known as "sigalgs", but this is really broader than just signature algorithms.
     65  1.1  christos Examples are:
     66  1.1  christos 
     67  1.1  christos -   AES-128-CBC
     68  1.1  christos -   hmacWithSHA256
     69  1.1  christos -   sha256WithRSAEncryption
     70  1.1  christos 
     71  1.1  christos ### The connection with AlgorithmIdentifiers
     72  1.1  christos 
     73  1.1  christos AlgorithmIdentifier is an ASN.1 structure that defines an algorithm as an
     74  1.1  christos OID, along with parameters that should be passed to that algorithm.
     75  1.1  christos 
     76  1.1  christos It is expected that an application should be able to take that OID and
     77  1.1  christos fetch it directly, after conversion to string form (either a name if the
     78  1.1  christos application or libcrypto happens to know it, or the OID itself in canonical
     79  1.1  christos numerical form).  To enable this, explicit fetching is necessary.
     80  1.1  christos 
     81  1.1  christos ### What we have today
     82  1.1  christos 
     83  1.1  christos As a matter of fact, we already have built-in support for fetching
     84  1.1  christos composite algorithms, although our providers do not fully participate in
     85  1.1  christos that support, and *most of the time*, we also have public APIs to use the
     86  1.1  christos fetched result, commonly known as support for explicit fetching.
     87  1.1  christos 
     88  1.1  christos The idea is that providers can declare the different compositions of a base
     89  1.1  christos algorithm in the `OSSL_ALGORITHM` array, each pointing to different
     90  1.1  christos `OSSL_DISPATCH` tables, which would in turn refer to pretty much the same
     91  1.1  christos functions, apart from the constructor function.
     92  1.1  christos 
     93  1.1  christos For example, we already do this with symmetric ciphers.
     94  1.1  christos 
     95  1.1  christos Another example, which we could implement in our providers today, would be
     96  1.1  christos compositions of HMAC:
     97  1.1  christos 
     98  1.1  christos ``` C
     99  1.1  christos static const OSSL_ALGORITHM deflt_macs[] = {
    100  1.1  christos     /* ... */
    101  1.1  christos     { "HMAC-SHA1:hmacWithSHA1:1.2.840.113549.2.7",
    102  1.1  christos       "provider=default", ossl_hmac_sha1_functions },
    103  1.1  christos     { "HMAC-SHA224:hmacWithSHA224:1.2.840.113549.2.8",
    104  1.1  christos       "provider=default", ossl_hmac_sha224_functions },
    105  1.1  christos     { "HMAC-SHA256:hmacWithSHA256:1.2.840.113549.2.9",
    106  1.1  christos       "provider=default", ossl_hmac_sha256_functions },
    107  1.1  christos     { "HMAC-SHA384:hmacWithSHA384:1.2.840.113549.2.10",
    108  1.1  christos       "provider=default", ossl_hmac_sha384_functions },
    109  1.1  christos     { "HMAC-SHA512:hmacWithSHA512:1.2.840.113549.2.11",
    110  1.1  christos       "provider=default", ossl_hmac_sha512_functions },
    111  1.1  christos     /* ... */
    112  1.1  christos ```
    113  1.1  christos 
    114  1.1  christos ### What we don't have today
    115  1.1  christos 
    116  1.1  christos There are some classes of algorithms for which we have no support for using
    117  1.1  christos the result of explicit fetching.  So for example, while it's possible for a
    118  1.1  christos provider to declare composite algorithms through the `OSSL_ALGORITHM` array,
    119  1.1  christos there's currently no way for an application to use them.
    120  1.1  christos 
    121  1.1  christos This all revolves around asymmetric algorithms, where we currently only
    122  1.1  christos support implicit fetching.
    123  1.1  christos 
    124  1.1  christos This is hurtful in multiple ways:
    125  1.1  christos 
    126  1.1  christos -   It fails the provider authors in terms being able to consistently
    127  1.1  christos     declare all algorithms through `OSSL_ALGORITHM` arrays.
    128  1.1  christos -   It fails the applications in terms of being able to fetch algorithms and
    129  1.1  christos     use the result.
    130  1.1  christos -   It fails discoverability, for example through the `openssl list`
    131  1.1  christos     command.
    132  1.1  christos 
    133  1.1  christos <!-- links -->
    134  1.1  christos [Functions for explicitly fetched signature algorithms]:
    135  1.1  christos     functions-for-explicitly-fetched-signature-algorithms.md
    136