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 OSSL_PARAM_BLD, OSSL_PARAM_BLD_new, OSSL_PARAM_BLD_to_param,
      6      1.1  christos OSSL_PARAM_BLD_free, OSSL_PARAM_BLD_push_int,
      7      1.1  christos OSSL_PARAM_BLD_push_uint, OSSL_PARAM_BLD_push_long,
      8      1.1  christos OSSL_PARAM_BLD_push_ulong, OSSL_PARAM_BLD_push_int32,
      9      1.1  christos OSSL_PARAM_BLD_push_uint32, OSSL_PARAM_BLD_push_int64,
     10      1.1  christos OSSL_PARAM_BLD_push_uint64, OSSL_PARAM_BLD_push_size_t,
     11      1.1  christos OSSL_PARAM_BLD_push_time_t, OSSL_PARAM_BLD_push_double,
     12      1.1  christos OSSL_PARAM_BLD_push_BN, OSSL_PARAM_BLD_push_BN_pad,
     13      1.1  christos OSSL_PARAM_BLD_push_utf8_string, OSSL_PARAM_BLD_push_utf8_ptr,
     14      1.1  christos OSSL_PARAM_BLD_push_octet_string, OSSL_PARAM_BLD_push_octet_ptr
     15      1.1  christos - functions to assist in the creation of OSSL_PARAM arrays
     16      1.1  christos 
     17      1.1  christos =head1 SYNOPSIS
     18      1.1  christos 
     19      1.1  christos =for openssl generic
     20      1.1  christos 
     21      1.1  christos  #include <openssl/param_build.h>
     22      1.1  christos 
     23      1.1  christos  typedef struct OSSL_PARAM_BLD;
     24      1.1  christos 
     25      1.1  christos  OSSL_PARAM_BLD *OSSL_PARAM_BLD_new(void);
     26      1.1  christos  OSSL_PARAM *OSSL_PARAM_BLD_to_param(OSSL_PARAM_BLD *bld);
     27      1.1  christos  void OSSL_PARAM_BLD_free(OSSL_PARAM_BLD *bld);
     28      1.1  christos 
     29      1.1  christos  int OSSL_PARAM_BLD_push_TYPE(OSSL_PARAM_BLD *bld, const char *key, TYPE val);
     30      1.1  christos 
     31      1.1  christos  int OSSL_PARAM_BLD_push_BN(OSSL_PARAM_BLD *bld, const char *key,
     32      1.1  christos                             const BIGNUM *bn);
     33      1.1  christos  int OSSL_PARAM_BLD_push_BN_pad(OSSL_PARAM_BLD *bld, const char *key,
     34      1.1  christos                                 const BIGNUM *bn, size_t sz);
     35      1.1  christos 
     36      1.1  christos  int OSSL_PARAM_BLD_push_utf8_string(OSSL_PARAM_BLD *bld, const char *key,
     37      1.1  christos                                      const char *buf, size_t bsize);
     38      1.1  christos  int OSSL_PARAM_BLD_push_utf8_ptr(OSSL_PARAM_BLD *bld, const char *key,
     39      1.1  christos                                   char *buf, size_t bsize);
     40      1.1  christos  int OSSL_PARAM_BLD_push_octet_string(OSSL_PARAM_BLD *bld, const char *key,
     41      1.1  christos                                       const void *buf, size_t bsize);
     42      1.1  christos  int OSSL_PARAM_BLD_push_octet_ptr(OSSL_PARAM_BLD *bld, const char *key,
     43      1.1  christos                                    void *buf, size_t bsize);
     44      1.1  christos 
     45      1.1  christos 
     46      1.1  christos =head1 DESCRIPTION
     47      1.1  christos 
     48      1.1  christos A collection of utility functions that simplify the creation of OSSL_PARAM
     49      1.1  christos arrays.  The B<I<TYPE>> names are as per L<OSSL_PARAM_int(3)>.
     50      1.1  christos 
     51      1.1  christos OSSL_PARAM_BLD_new() allocates and initialises a new OSSL_PARAM_BLD structure
     52      1.1  christos so that values can be added.
     53      1.1  christos Any existing values are cleared.
     54      1.1  christos 
     55      1.1  christos OSSL_PARAM_BLD_free() deallocates the memory allocates by OSSL_PARAM_BLD_new().
     56  1.1.1.2  christos If the argument is NULL, nothing is done.
     57      1.1  christos 
     58      1.1  christos OSSL_PARAM_BLD_to_param() converts a built up OSSL_PARAM_BLD structure
     59      1.1  christos I<bld> into an allocated OSSL_PARAM array.
     60      1.1  christos The OSSL_PARAM array and all associated storage must be freed by calling
     61      1.1  christos OSSL_PARAM_free() with the functions return value.
     62      1.1  christos OSSL_PARAM_BLD_free() can safely be called any time after this function is.
     63      1.1  christos 
     64      1.1  christos =begin comment
     65      1.1  christos 
     66      1.1  christos POD is pretty good at recognising function names and making them appropriately
     67      1.1  christos bold...  however, when part of the function name is variable, we have to help
     68      1.1  christos the processor along
     69      1.1  christos 
     70      1.1  christos =end comment
     71      1.1  christos 
     72      1.1  christos B<OSSL_PARAM_BLD_push_I<TYPE>>() are a series of functions which will create
     73      1.1  christos OSSL_PARAM objects of the specified size and correct type for the I<val>
     74      1.1  christos argument.
     75      1.1  christos I<val> is stored by value and an expression or auto variable can be used.
     76      1.1  christos 
     77      1.1  christos OSSL_PARAM_BLD_push_BN() is a function that will create an OSSL_PARAM object
     78      1.1  christos that holds the specified BIGNUM I<bn>.
     79      1.1  christos If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
     80      1.1  christos will also be securely allocated.
     81      1.1  christos The I<bn> argument is stored by reference and the underlying BIGNUM object
     82      1.1  christos must exist until after OSSL_PARAM_BLD_to_param() has been called.
     83      1.1  christos 
     84      1.1  christos OSSL_PARAM_BLD_push_BN_pad() is a function that will create an OSSL_PARAM object
     85      1.1  christos that holds the specified BIGNUM I<bn>.
     86      1.1  christos The object will be padded to occupy exactly I<sz> bytes, if insufficient space
     87      1.1  christos is specified an error results.
     88      1.1  christos If I<bn> is marked as being securely allocated, its OSSL_PARAM representation
     89      1.1  christos will also be securely allocated.
     90      1.1  christos The I<bn> argument is stored by reference and the underlying BIGNUM object
     91      1.1  christos must exist until after OSSL_PARAM_BLD_to_param() has been called.
     92      1.1  christos 
     93      1.1  christos OSSL_PARAM_BLD_push_utf8_string() is a function that will create an OSSL_PARAM
     94      1.1  christos object that references the UTF8 string specified by I<buf>.
     95      1.1  christos The length of the string I<bsize> should not include the terminating NUL byte.
     96      1.1  christos If it is zero then it will be calculated.
     97      1.1  christos The string that I<buf> points to is stored by reference and must remain in
     98      1.1  christos scope until after OSSL_PARAM_BLD_to_param() has been called.
     99      1.1  christos 
    100      1.1  christos OSSL_PARAM_BLD_push_octet_string() is a function that will create an OSSL_PARAM
    101      1.1  christos object that references the octet string specified by I<buf> and <bsize>.
    102      1.1  christos The memory that I<buf> points to is stored by reference and must remain in
    103      1.1  christos scope until after OSSL_PARAM_BLD_to_param() has been called.
    104      1.1  christos 
    105      1.1  christos OSSL_PARAM_BLD_push_utf8_ptr() is a function that will create an OSSL_PARAM
    106      1.1  christos object that references the UTF8 string specified by I<buf>.
    107      1.1  christos The length of the string I<bsize> should not include the terminating NUL byte.
    108      1.1  christos If it is zero then it will be calculated.
    109      1.1  christos The string I<buf> points to is stored by reference and must remain in
    110      1.1  christos scope until the OSSL_PARAM array is freed.
    111      1.1  christos 
    112      1.1  christos OSSL_PARAM_BLD_push_octet_ptr() is a function that will create an OSSL_PARAM
    113      1.1  christos object that references the octet string specified by I<buf>.
    114      1.1  christos The memory I<buf> points to is stored by reference and must remain in
    115      1.1  christos scope until the OSSL_PARAM array is freed.
    116      1.1  christos 
    117      1.1  christos =head1 RETURN VALUES
    118      1.1  christos 
    119      1.1  christos OSSL_PARAM_BLD_new() returns the allocated OSSL_PARAM_BLD structure, or NULL
    120      1.1  christos on error.
    121      1.1  christos 
    122      1.1  christos OSSL_PARAM_BLD_to_param() returns the allocated OSSL_PARAM array, or NULL
    123      1.1  christos on error.
    124      1.1  christos 
    125      1.1  christos All of the OSSL_PARAM_BLD_push_TYPE functions return 1 on success and 0
    126      1.1  christos on error.
    127      1.1  christos 
    128      1.1  christos =head1 NOTES
    129      1.1  christos 
    130      1.1  christos OSSL_PARAM_BLD_push_BN() and OSSL_PARAM_BLD_push_BN_pad() currently only
    131      1.1  christos support nonnegative B<BIGNUM>s.  They return an error on negative B<BIGNUM>s.
    132      1.1  christos 
    133      1.1  christos =head1 EXAMPLES
    134      1.1  christos 
    135      1.1  christos Both examples creating an OSSL_PARAM array that contains an RSA key.
    136      1.1  christos For both, the predefined key variables are:
    137      1.1  christos 
    138      1.1  christos     BIGNUM *n;           /* modulus */
    139      1.1  christos     unsigned int e;      /* public exponent */
    140      1.1  christos     BIGNUM *d;           /* private exponent */
    141      1.1  christos     BIGNUM *p, *q;       /* first two prime factors */
    142      1.1  christos     BIGNUM *dmp1, *dmq1; /* first two CRT exponents */
    143      1.1  christos     BIGNUM *iqmp;        /* first CRT coefficient */
    144      1.1  christos 
    145      1.1  christos =head2 Example 1
    146      1.1  christos 
    147      1.1  christos This example shows how to create an OSSL_PARAM array that contains an RSA
    148      1.1  christos private key.
    149      1.1  christos 
    150      1.1  christos     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
    151      1.1  christos     OSSL_PARAM *params = NULL;
    152      1.1  christos 
    153      1.1  christos     if (bld == NULL
    154      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
    155      1.1  christos         || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
    156      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "d", d)
    157      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor1", p)
    158      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "rsa-factor2", q)
    159      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent1", dmp1)
    160      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "rsa-exponent2", dmq1)
    161      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "rsa-coefficient1", iqmp)
    162      1.1  christos         || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
    163      1.1  christos         goto err;
    164      1.1  christos     OSSL_PARAM_BLD_free(bld);
    165      1.1  christos     /* Use params */
    166      1.1  christos     ...
    167      1.1  christos     OSSL_PARAM_free(params);
    168      1.1  christos 
    169      1.1  christos =head2 Example 2
    170      1.1  christos 
    171      1.1  christos This example shows how to create an OSSL_PARAM array that contains an RSA
    172      1.1  christos public key.
    173      1.1  christos 
    174      1.1  christos     OSSL_PARAM_BLD *bld = OSSL_PARAM_BLD_new();
    175      1.1  christos     OSSL_PARAM *params = NULL;
    176      1.1  christos 
    177      1.1  christos     if (nld == NULL
    178      1.1  christos         || !OSSL_PARAM_BLD_push_BN(bld, "n", n)
    179      1.1  christos         || !OSSL_PARAM_BLD_push_uint(bld, "e", e)
    180      1.1  christos         || (params = OSSL_PARAM_BLD_to_param(bld)) == NULL)
    181      1.1  christos         goto err;
    182      1.1  christos     OSSL_PARAM_BLD_free(bld);
    183      1.1  christos     /* Use params */
    184      1.1  christos     ...
    185      1.1  christos     OSSL_PARAM_free(params);
    186      1.1  christos 
    187      1.1  christos =head1 SEE ALSO
    188      1.1  christos 
    189      1.1  christos L<OSSL_PARAM_int(3)>, L<OSSL_PARAM(3)>, L<OSSL_PARAM_free(3)>
    190      1.1  christos 
    191      1.1  christos =head1 HISTORY
    192      1.1  christos 
    193      1.1  christos The functions described here were all added in OpenSSL 3.0.
    194      1.1  christos 
    195      1.1  christos =head1 COPYRIGHT
    196      1.1  christos 
    197  1.1.1.2  christos Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
    198      1.1  christos 
    199      1.1  christos Licensed under the Apache License 2.0 (the "License").  You may not use
    200      1.1  christos this file except in compliance with the License.  You can obtain a copy
    201      1.1  christos in the file LICENSE in the source distribution or at
    202      1.1  christos L<https://www.openssl.org/source/license.html>.
    203      1.1  christos 
    204      1.1  christos =cut
    205