provider-mac.pod 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. =pod
  2. =head1 NAME
  3. provider-mac - The mac library E<lt>-E<gt> provider functions
  4. =head1 SYNOPSIS
  5. =for openssl multiple includes
  6. #include <openssl/core_numbers.h>
  7. #include <openssl/core_names.h>
  8. /*
  9. * None of these are actual functions, but are displayed like this for
  10. * the function signatures for functions that are offered as function
  11. * pointers in OSSL_DISPATCH arrays.
  12. */
  13. /* Context management */
  14. void *OP_mac_newctx(void *provctx);
  15. void OP_mac_freectx(void *mctx);
  16. void *OP_mac_dupctx(void *src);
  17. /* Encryption/decryption */
  18. int OP_mac_init(void *mctx);
  19. int OP_mac_update(void *mctx, const unsigned char *in, size_t inl);
  20. int OP_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
  21. /* MAC parameter descriptors */
  22. const OSSL_PARAM *OP_mac_get_params(void);
  23. const OSSL_PARAM *OP_mac_get_ctx_params(void);
  24. const OSSL_PARAM *OP_mac_set_ctx_params(void);
  25. /* MAC parameters */
  26. int OP_mac_get_params(OSSL_PARAM params[]);
  27. int OP_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
  28. int OP_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
  29. =head1 DESCRIPTION
  30. This documentation is primarily aimed at provider authors. See L<provider(7)>
  31. for further information.
  32. The MAC operation enables providers to implement mac algorithms and make
  33. them available to applications via the API functions L<EVP_MAC_init(3)>,
  34. L<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>.
  35. All "functions" mentioned here are passed as function pointers between
  36. F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
  37. B<OSSL_ALGORITHM> arrays that are returned by the provider's
  38. provider_query_operation() function
  39. (see L<provider-base(7)/Provider Functions>).
  40. All these "functions" have a corresponding function type definition
  41. named B<OSSL_{name}_fn>, and a helper function to retrieve the
  42. function pointer from an B<OSSL_DISPATCH> element named
  43. B<OSSL_get_{name}>.
  44. For example, the "function" OP_mac_newctx() has these:
  45. typedef void *(OSSL_OP_mac_newctx_fn)(void *provctx);
  46. static ossl_inline OSSL_OP_mac_newctx_fn
  47. OSSL_get_OP_mac_newctx(const OSSL_DISPATCH *opf);
  48. B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
  49. macros in L<openssl-core_numbers.h(7)>, as follows:
  50. OP_mac_newctx OSSL_FUNC_MAC_NEWCTX
  51. OP_mac_freectx OSSL_FUNC_MAC_FREECTX
  52. OP_mac_dupctx OSSL_FUNC_MAC_DUPCTX
  53. OP_mac_init OSSL_FUNC_MAC_INIT
  54. OP_mac_update OSSL_FUNC_MAC_UPDATE
  55. OP_mac_final OSSL_FUNC_MAC_FINAL
  56. OP_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
  57. OP_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
  58. OP_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
  59. OP_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
  60. OP_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
  61. OP_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
  62. A mac algorithm implementation may not implement all of these functions.
  63. In order to be a consistent set of functions, at least the following functions
  64. must be implemented: OP_mac_newctx(), OP_mac_freectx(), OP_mac_init(),
  65. OP_mac_update(), OP_mac_final().
  66. All other functions are optional.
  67. =head2 Context Management Functions
  68. OP_mac_newctx() should create and return a pointer to a provider side
  69. structure for holding context information during a mac operation.
  70. A pointer to this context will be passed back in a number of the other mac
  71. operation function calls.
  72. The parameter I<provctx> is the provider context generated during provider
  73. initialisation (see L<provider(7)>).
  74. OP_mac_freectx() is passed a pointer to the provider side mac context in
  75. the I<mctx> parameter.
  76. If it receives NULL as I<mctx> value, it should not do anything other than
  77. return.
  78. This function should free any resources associated with that context.
  79. OP_mac_dupctx() should duplicate the provider side mac context in the
  80. I<mctx> parameter and return the duplicate copy.
  81. =head2 Encryption/Decryption Functions
  82. OP_mac_init() initialises a mac operation given a newly created provider
  83. side mac context in the I<mctx> parameter.
  84. OP_mac_update() is called to supply data for MAC computation of a previously
  85. initialised mac operation.
  86. The I<mctx> parameter contains a pointer to a previously initialised provider
  87. side context.
  88. OP_mac_update() may be called multiple times for a single mac operation.
  89. OP_mac_final() completes the MAC computation started through previous
  90. OP_mac_init() and OP_mac_update() calls.
  91. The I<mctx> parameter contains a pointer to the provider side context.
  92. The resulting MAC should be written to I<out> and the amount of data written
  93. to I<*outl>, which should not exceed I<outsize> bytes.
  94. The same expectations apply to I<outsize> as documented for
  95. L<EVP_MAC_final(3)>.
  96. =head2 Mac Parameters
  97. See L<OSSL_PARAM(3)> for further details on the parameters structure used by
  98. these functions.
  99. OP_mac_get_params() gets details of parameter values associated with the
  100. provider algorithm and stores them in I<params>.
  101. OP_mac_set_ctx_params() sets mac parameters associated with the given
  102. provider side mac context I<mctx> to I<params>.
  103. Any parameter settings are additional to any that were previously set.
  104. OP_mac_get_ctx_params() gets details of currently set parameter values
  105. associated with the given provider side mac context I<mctx> and stores them
  106. in I<params>.
  107. OP_mac_gettable_params(), OP_mac_gettable_ctx_params(), and
  108. OP_mac_settable_ctx_params() all return constant B<OSSL_PARAM> arrays
  109. as descriptors of the parameters that OP_mac_get_params(),
  110. OP_mac_get_ctx_params(), and OP_mac_set_ctx_params() can handle,
  111. respectively.
  112. Parameters currently recognised by built-in macs are as follows. Not all
  113. parameters are relevant to, or are understood by all macs:
  114. =over 4
  115. =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
  116. Sets the key in the associated MAC ctx.
  117. =item "iv" (B<OSSL_MAC_PARAM_IV>) <octet string>
  118. Sets the IV of the underlying cipher, when applicable.
  119. =item "custom" (B<OSSL_MAC_PARAM_CUSTOM>) <UTF8 string>
  120. Sets the custom string in the associated MAC ctx.
  121. =item "salt" (B<OSSL_MAC_PARAM_SALT>) <octet string>
  122. Sets the salt of the underlying cipher, when applicable.
  123. =item "xof" (B<OSSL_MAC_PARAM_BLOCK_XOF>) <integer>
  124. Sets XOF mode in the associated MAC ctx.
  125. 0 means no XOF mode, 1 means XOF mode.
  126. =item "flags" (B<OSSL_MAC_PARAM_FLAGS>) <integer>
  127. Gets flags associated with the MAC.
  128. =for comment We need to investigate if this is the right approach
  129. =item "cipher" (B<OSSL_MAC_PARAM_CIPHER>) <UTF8 string>
  130. =item "digest" (B<OSSL_MAC_PARAM_DIGEST>) <UTF8 string>
  131. Sets the name of the underlying cipher or digest to be used.
  132. It must name a suitable algorithm for the MAC that's being used.
  133. =item "properties" (B<OSSL_MAC_PARAM_PROPERTIES>) <UTF8 string>
  134. Sets the properties to be queried when trying to fetch the underlying algorithm.
  135. This must be given together with the algorithm naming parameter to be
  136. considered valid.
  137. =item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
  138. Can be used to get the resulting MAC size.
  139. With some MAC algorithms, it can also be used to set the size that the
  140. resulting MAC should have.
  141. Allowable sizes are decided within each implementation.
  142. =back
  143. =head1 RETURN VALUES
  144. OP_mac_newctx() and OP_mac_dupctx() should return the newly created
  145. provider side mac context, or NULL on failure.
  146. OP_mac_init(), OP_mac_update(), OP_mac_final(), OP_mac_get_params(),
  147. OP_mac_get_ctx_params() and OP_mac_set_ctx_params() should return 1 for
  148. success or 0 on error.
  149. OP_mac_gettable_params(), OP_mac_gettable_ctx_params() and
  150. OP_mac_settable_ctx_params() should return a constant B<OSSL_PARAM>
  151. array, or NULL if none is offered.
  152. =head1 SEE ALSO
  153. L<provider(7)>
  154. =head1 HISTORY
  155. The provider MAC interface was introduced in OpenSSL 3.0.
  156. =head1 COPYRIGHT
  157. Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
  158. Licensed under the Apache License 2.0 (the "License"). You may not use
  159. this file except in compliance with the License. You can obtain a copy
  160. in the file LICENSE in the source distribution or at
  161. L<https://www.openssl.org/source/license.html>.
  162. =cut