Fix alignment errors in hashtable fuzzer
[openssl.git] / doc / man7 / provider-encoder.pod
index 99787e704074638a9ca34a3a29327cb2a4481005..f3e9ce5b1632765702107485b7fb7e176ede1699 100644 (file)
@@ -2,7 +2,7 @@
 
 =head1 NAME
 
-provider-encoder - The ENCODER library E<lt>-E<gt> provider functions
+provider-encoder - The OSSL_ENCODER library E<lt>-E<gt> provider functions
 
 =head1 SYNOPSIS
 
@@ -14,36 +14,65 @@ provider-encoder - The ENCODER library E<lt>-E<gt> provider functions
   * pointers in OSSL_DISPATCH arrays.
   */
 
+ /* Encoder parameter accessor and descriptor */
+ const OSSL_PARAM *OSSL_FUNC_encoder_gettable_params(void *provctx);
+ int OSSL_FUNC_encoder_get_params(OSSL_PARAM params[]);
+
  /* Functions to construct / destruct / manipulate the encoder context */
  void *OSSL_FUNC_encoder_newctx(void *provctx);
  void OSSL_FUNC_encoder_freectx(void *ctx);
  int OSSL_FUNC_encoder_set_ctx_params(void *ctx, const OSSL_PARAM params[]);
- const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx)
+ const OSSL_PARAM *OSSL_FUNC_encoder_settable_ctx_params(void *provctx);
+
+ /* Functions to check selection support */
+ int OSSL_FUNC_encoder_does_selection(void *provctx, int selection);
 
  /* Functions to encode object data */
- int OSSL_FUNC_encoder_encode_data(void *ctx, const OSSL_PARAM *data,
-                                         OSSL_CORE_BIO *out,
-                                         OSSL_PASSPHRASE_CALLBACK *cb,
-                                         void *cbarg);
- int OSSL_FUNC_encoder_encode_object(void *ctx, void *obj, OSSL_CORE_BIO *out,
-                                           OSSL_PASSPHRASE_CALLBACK *cb,
-                                           void *cbarg);
+ int OSSL_FUNC_encoder_encode(void *ctx, OSSL_CORE_BIO *out,
+                              const void *obj_raw,
+                              const OSSL_PARAM obj_abstract[],
+                              int selection,
+                              OSSL_PASSPHRASE_CALLBACK *cb,
+                              void *cbarg);
+
+ /* Functions to import and free a temporary object to be encoded */
+ void *OSSL_FUNC_encoder_import_object(void *ctx, int selection,
+                                       const OSSL_PARAM params[]);
+ void OSSL_FUNC_encoder_free_object(void *obj);
+
 
 =head1 DESCRIPTION
 
 I<We use the wide term "encode" in this manual.  This includes but is
 not limited to serialization.>
 
-The ENCODER is a generic method to encode any set of object data
-in L<OSSL_PARAM(3)> array form, or any provider side object into
-encoded form, and write it to the given OSSL_CORE_BIO.  If the caller wants
-to get the encoded stream to memory, it should provide a
-L<BIO_s_membuf(3)>.
+The ENCODER operation is a generic method to encode a provider-native
+object (I<obj_raw>) or an object abstraction (I<object_abstract>, see
+L<provider-object(7)>) into an encoded form, and write the result to
+the given OSSL_CORE_BIO.  If the caller wants to get the encoded
+stream to memory, it should provide a L<BIO_s_mem(3)> B<BIO>.
 
-The encoder doesn't need to know more about the B<OSSL_CORE_BIO> pointer than
-being able to pass it to the appropriate BIO upcalls (see
+The encoder doesn't need to know more about the B<OSSL_CORE_BIO>
+pointer than being able to pass it to the appropriate BIO upcalls (see
 L<provider-base(7)/Core functions>).
 
+The ENCODER implementation may be part of a chain, where data is
+passed from one to the next.  For example, there may be an
+implementation to encode an object to DER (that object is assumed to
+be provider-native and thereby passed via I<obj_raw>), and another one
+that encodes DER to PEM (that one would receive the DER encoding via
+I<obj_abstract>).
+
+=begin comment
+
+Having the DER encoding passed via I<obj_abstract> may seem
+complicated.  However, there may be associated meta-data, such as the
+original data type, that need to be passed alongside it, and since
+L<provider-object(7)> already defines a way to pass such data,
+inventing another way to do it makes things even more complicated.
+
+=end comment
+
 The encoding using the L<OSSL_PARAM(3)> array form allows a
 encoder to be used for data that's been exported from another
 provider, and thereby allow them to exist independently of each
@@ -54,102 +83,122 @@ with provider data coming from the same provider, for example keys
 with the L<KEYMGMT|provider-keymgmt(7)> provider.
 
 All "functions" mentioned here are passed as function pointers between
-F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
-B<OSSL_ALGORITHM> arrays that are returned by the provider's
+F<libcrypto> and the provider in L<OSSL_DISPATCH(3)> arrays via
+L<OSSL_ALGORITHM(3)> arrays that are returned by the provider's
 provider_query_operation() function
 (see L<provider-base(7)/Provider Functions>).
 
 All these "functions" have a corresponding function type definition
-named B<OSSL_{name}_fn>, and a helper function to retrieve the
-function pointer from a B<OSSL_DISPATCH> element named
+named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
+function pointer from an L<OSSL_DISPATCH(3)> element named
 B<OSSL_FUNC_{name}>.
-For example, the "function" OSSL_FUNC_encoder_encode_data() has these:
+For example, the "function" OSSL_FUNC_encoder_encode() has these:
 
  typedef int
-     (OSSL_FUNC_encoder_encode_data_fn)(void *provctx,
-                                            const OSSL_PARAM params[],
-                                            OSSL_CORE_BIO *out);
- static ossl_inline OSSL_FUNC_encoder_encode_data_fn
-     OSSL_FUNC_encoder_encode_data(const OSSL_DISPATCH *opf);
-
-B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
+     (OSSL_FUNC_encoder_encode_fn)(void *ctx, OSSL_CORE_BIO *out,
+                                   const void *obj_raw,
+                                   const OSSL_PARAM obj_abstract[],
+                                   int selection,
+                                   OSSL_PASSPHRASE_CALLBACK *cb, void *cbarg);
+ static ossl_inline OSSL_FUNC_encoder_encode_fn
+     OSSL_FUNC_encoder_encode(const OSSL_DISPATCH *opf);
+
+L<OSSL_DISPATCH(3)> arrays are indexed by numbers that are provided as
 macros in L<openssl-core_dispatch.h(7)>, as follows:
 
+ OSSL_FUNC_encoder_get_params          OSSL_FUNC_ENCODER_GET_PARAMS
+ OSSL_FUNC_encoder_gettable_params     OSSL_FUNC_ENCODER_GETTABLE_PARAMS
+
  OSSL_FUNC_encoder_newctx              OSSL_FUNC_ENCODER_NEWCTX
  OSSL_FUNC_encoder_freectx             OSSL_FUNC_ENCODER_FREECTX
  OSSL_FUNC_encoder_set_ctx_params      OSSL_FUNC_ENCODER_SET_CTX_PARAMS
  OSSL_FUNC_encoder_settable_ctx_params OSSL_FUNC_ENCODER_SETTABLE_CTX_PARAMS
 
- OSSL_FUNC_encoder_encode_data      OSSL_FUNC_ENCODER_ENCODE_DATA
- OSSL_FUNC_encoder_encode_object    OSSL_FUNC_ENCODER_ENCODE_OBJECT
+ OSSL_FUNC_encoder_does_selection      OSSL_FUNC_ENCODER_DOES_SELECTION
+
+ OSSL_FUNC_encoder_encode              OSSL_FUNC_ENCODER_ENCODE
+
+ OSSL_FUNC_encoder_import_object       OSSL_FUNC_ENCODER_IMPORT_OBJECT
+ OSSL_FUNC_encoder_free_object         OSSL_FUNC_ENCODER_FREE_OBJECT
 
 =head2 Names and properties
 
-The name of an implementation should match the type of object it
-handles.  For example, an implementation that encodes an RSA key
-should be named accordingly.
+The name of an implementation should match the type of object it handles.
+For example, an implementation that encodes an RSA key should be named "RSA".
+Likewise, an implementation that further encodes DER should be named "DER".
 
-To be able to specify exactly what encoding format and what type
-of data a encoder implementation is expected to handle, two
-additional properties may be given:
+Properties can be used to further specify details about an implementation:
 
 =over 4
 
-=item format
+=item output
+
+This property is used to specify what type of output the implementation
+produces.
+
+This property is I<mandatory>.
 
-This property is used to specify what kind of output format the
-implementation produces.  Currently known formats are:
+OpenSSL providers recognize the following output types:
 
 =over 4
 
 =item text
 
-An implementation with that format property value outputs human
-readable text, making that implementation suitable for C<-text> output
-in diverse L<openssl(1)> commands.
+An implementation with that output type outputs human readable text, making
+that implementation suitable for C<-text> output in diverse L<openssl(1)>
+commands.
 
 =item pem
 
-An implementation with that format property value outputs PEM
-formatted data.
+An implementation with that output type outputs PEM formatted data.
 
 =item der
 
-An implementation with that format property value outputs DER
-formatted data.
+An implementation with that output type outputs DER formatted data.
 
-=back
+=item msblob
 
-=item type
+An implementation with that output type outputs MSBLOB formatted data.
 
-With objects that have multiple purposes, this can be used to specify
-the purpose type.  The currently known use cases are asymmetric keys
-and key parameters, where the type can be one of:
+=item pvk
 
-=over 4
+An implementation with that output type outputs PVK formatted data.
 
-=item private
+=back
 
-An implementation with that format property value outputs a private
-key.
+=item structure
 
-=item public
+This property is used to specify the structure that is used for the encoded
+object.  An example could be C<pkcs8>, to specify explicitly that an object
+(presumably an asymmetric key pair, in this case) will be wrapped in a
+PKCS#8 structure as part of the encoding.
 
-An implementation with that format property value outputs a public
-key.
+This property is I<optional>.
 
-=item parameters
+=back
 
-An implementation with that format property value outputs key
-parameters.
+The possible values of both these properties is open ended.  A provider may
+very well specify output types and structures that libcrypto doesn't know
+anything about.
 
-=back
+=head2 Subset selections
 
-=back
+Sometimes, an object has more than one subset of data that is interesting to
+treat separately or together.  It's possible to specify what subsets are to
+be encoded, with a set of bits I<selection> that are passed in an B<int>.
+
+This set of bits depend entirely on what kind of provider-side object is
+passed.  For example, those bits are assumed to be the same as those used
+with L<provider-keymgmt(7)> (see L<provider-keymgmt(7)/Key Objects>) when
+the object is an asymmetric keypair.
 
-The possible values of both these properties is open ended.  A
-provider may very well specify other formats that libcrypto doesn't
-know anything about.
+ENCODER implementations are free to regard the I<selection> as a set of
+hints, but must do so with care.  In the end, the output must make sense,
+and if there's a corresponding decoder, the resulting decoded object must
+match the original object that was encoded.
+
+OSSL_FUNC_encoder_does_selection() should tell if a particular implementation
+supports any of the combinations given by I<selection>.
 
 =head2 Context functions
 
@@ -159,40 +208,47 @@ the functions.
 OSSL_FUNC_encoder_freectx() frees the given I<ctx>, if it was created by
 OSSL_FUNC_encoder_newctx().
 
-OSSL_FUNC_encoder_set_ctx_params() sets context data according to
-parameters from I<params> that it recognises.  Unrecognised parameters
-should be ignored.
+OSSL_FUNC_encoder_set_ctx_params() sets context data according to parameters
+from I<params> that it recognises.  Unrecognised parameters should be
+ignored.
+Passing NULL for I<params> should return true.
 
-OSSL_FUNC_encoder_settable_ctx_params() returns a constant B<OSSL_PARAM>
+OSSL_FUNC_encoder_settable_ctx_params() returns a constant L<OSSL_PARAM(3)>
 array describing the parameters that OSSL_FUNC_encoder_set_ctx_params()
 can handle.
 
-See L<OSSL_PARAM(3)> for further details on the parameters structure used
-by OSSL_FUNC_encoder_set_ctx_params() and OSSL_FUNC_encoder_settable_ctx_params().
+See L<OSSL_PARAM(3)> for further details on the parameters structure used by
+OSSL_FUNC_encoder_set_ctx_params() and OSSL_FUNC_encoder_settable_ctx_params().
 
-=head2 Encoding functions
+=head2 Import functions
+
+A provider-native object may be associated with a foreign provider, and may
+therefore be unsuitable for direct use with a given ENCODER implementation.
+Provided that the foreign provider's implementation to handle the object has
+a function to export that object in L<OSSL_PARAM(3)> array form, the ENCODER
+implementation should be able to import that array and create a suitable
+object to be passed to OSSL_FUNC_encoder_encode()'s I<obj_raw>.
 
-=for comment There will be a "Decoding functions" title as well
+OSSL_FUNC_encoder_import_object() should import the subset of I<params>
+given with I<selection> to create a provider-native object that can be
+passed as I<obj_raw> to OSSL_FUNC_encoder_encode().
 
-OSSL_FUNC_encoder_encode_data() should take an array of B<OSSL_PARAM>,
-I<data>, and if it contains the data necessary for the object type
-that the implementation handles, it should output the object in
-encoded form to the B<OSSL_CORE_BIO>.
+OSSL_FUNC_encoder_free_object() should free the object that was created with
+OSSL_FUNC_encoder_import_object().
 
-OSSL_FUNC_encoder_encode_object() should take a pointer to an object
-that it knows intimately, and output that object in encoded form to
-the B<OSSL_CORE_BIO>.  The caller I<must> ensure that this function is called
-with a pointer that the provider of this function is familiar with.
-It is not suitable to use with object pointers coming from other
-providers.
+=head2 Encoding functions
 
-Both encoding functions also take an B<OSSL_PASSPHRASE_CALLBACK>
-function pointer along with a pointer to application data I<cbarg>,
-which should be used when a pass phrase prompt is needed.
+OSSL_FUNC_encoder_encode() should take a provider-native object (in
+I<obj_raw>) or an object abstraction (in I<obj_abstract>), and should output
+the object in encoded form to the B<OSSL_CORE_BIO>.  The I<selection> bits,
+if relevant, should determine in greater detail what will be output.
+The encoding functions also take an L<OSSL_PASSPHRASE_CALLBACK(3)> function
+pointer along with a pointer to application data I<cbarg>, which should be
+used when a pass phrase prompt is needed.
 
-=head2 Encoder parameters
+=head2 Encoder operation parameters
 
-Parameters currently recognised by built-in encoders are as
+Operation parameters currently recognised by built-in encoders are as
 follows:
 
 =over 4
@@ -220,10 +276,10 @@ However, it is recommended that implementations that do not handle
 property strings return an error on receiving this parameter unless
 its value NULL or the empty string.
 
-=item "passphrase" (B<OSSL_ENCODER_PARAM_PASS>) <octet string>
+=item "save-parameters" (B<OSSL_ENCODER_PARAM_SAVE_PARAMETERS>) <integer>
 
-A pass phrase provided by the application.  When this is given, the
-built-in encoders will not attempt to use the passphrase callback.
+If set to 0 disables saving of key domain parameters. Default is 1.
+It currently has an effect only on DSA keys.
 
 =back
 
@@ -245,13 +301,15 @@ OSSL_FUNC_encoder_newctx() returns a pointer to a context, or NULL on
 failure.
 
 OSSL_FUNC_encoder_set_ctx_params() returns 1, unless a recognised
-parameters was invalid or caused an error, for which 0 is returned.
+parameter was invalid or caused an error, for which 0 is returned.
 
 OSSL_FUNC_encoder_settable_ctx_params() returns a pointer to an array of
-constant B<OSSL_PARAM> elements.
+constant L<OSSL_PARAM(3)> elements.
 
-OSSL_FUNC_encoder_encode_data() and OSSL_FUNC_encoder_encode_object()
-return 1 on success, or 0 on failure.
+OSSL_FUNC_encoder_does_selection() returns 1 if the encoder implementation
+supports any of the I<selection> bits, otherwise 0.
+
+OSSL_FUNC_encoder_encode() returns 1 on success, or 0 on failure.
 
 =head1 SEE ALSO
 
@@ -263,7 +321,7 @@ The ENCODER interface was introduced in OpenSSL 3.0.
 
 =head1 COPYRIGHT
 
-Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
+Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
 
 Licensed under the Apache License 2.0 (the "License").  You may not use
 this file except in compliance with the License.  You can obtain a copy