provider-mac.pod 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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_dispatch.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 *OSSL_FUNC_mac_newctx(void *provctx);
  15. void OSSL_FUNC_mac_freectx(void *mctx);
  16. void *OSSL_FUNC_mac_dupctx(void *src);
  17. /* Encryption/decryption */
  18. int OSSL_FUNC_mac_init(void *mctx, unsigned char *key, size_t keylen,
  19. const OSSL_PARAM params[]);
  20. int OSSL_FUNC_mac_update(void *mctx, const unsigned char *in, size_t inl);
  21. int OSSL_FUNC_mac_final(void *mctx, unsigned char *out, size_t *outl, size_t outsize);
  22. /* MAC parameter descriptors */
  23. const OSSL_PARAM *OSSL_FUNC_mac_gettable_params(void *provctx);
  24. const OSSL_PARAM *OSSL_FUNC_mac_gettable_ctx_params(void *mctx, void *provctx);
  25. const OSSL_PARAM *OSSL_FUNC_mac_settable_ctx_params(void *mctx, void *provctx);
  26. /* MAC parameters */
  27. int OSSL_FUNC_mac_get_params(OSSL_PARAM params[]);
  28. int OSSL_FUNC_mac_get_ctx_params(void *mctx, OSSL_PARAM params[]);
  29. int OSSL_FUNC_mac_set_ctx_params(void *mctx, const OSSL_PARAM params[]);
  30. =head1 DESCRIPTION
  31. This documentation is primarily aimed at provider authors. See L<provider(7)>
  32. for further information.
  33. The MAC operation enables providers to implement mac algorithms and make
  34. them available to applications via the API functions L<EVP_MAC_init(3)>,
  35. L<EVP_MAC_update(3)> and L<EVP_MAC_final(3)>.
  36. All "functions" mentioned here are passed as function pointers between
  37. F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
  38. B<OSSL_ALGORITHM> arrays that are returned by the provider's
  39. provider_query_operation() function
  40. (see L<provider-base(7)/Provider Functions>).
  41. All these "functions" have a corresponding function type definition
  42. named B<OSSL_FUNC_{name}_fn>, and a helper function to retrieve the
  43. function pointer from an B<OSSL_DISPATCH> element named
  44. B<OSSL_FUNC_{name}>.
  45. For example, the "function" OSSL_FUNC_mac_newctx() has these:
  46. typedef void *(OSSL_OSSL_FUNC_mac_newctx_fn)(void *provctx);
  47. static ossl_inline OSSL_OSSL_FUNC_mac_newctx_fn
  48. OSSL_FUNC_mac_newctx(const OSSL_DISPATCH *opf);
  49. B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
  50. macros in L<openssl-core_dispatch.h(7)>, as follows:
  51. OSSL_FUNC_mac_newctx OSSL_FUNC_MAC_NEWCTX
  52. OSSL_FUNC_mac_freectx OSSL_FUNC_MAC_FREECTX
  53. OSSL_FUNC_mac_dupctx OSSL_FUNC_MAC_DUPCTX
  54. OSSL_FUNC_mac_init OSSL_FUNC_MAC_INIT
  55. OSSL_FUNC_mac_update OSSL_FUNC_MAC_UPDATE
  56. OSSL_FUNC_mac_final OSSL_FUNC_MAC_FINAL
  57. OSSL_FUNC_mac_get_params OSSL_FUNC_MAC_GET_PARAMS
  58. OSSL_FUNC_mac_get_ctx_params OSSL_FUNC_MAC_GET_CTX_PARAMS
  59. OSSL_FUNC_mac_set_ctx_params OSSL_FUNC_MAC_SET_CTX_PARAMS
  60. OSSL_FUNC_mac_gettable_params OSSL_FUNC_MAC_GETTABLE_PARAMS
  61. OSSL_FUNC_mac_gettable_ctx_params OSSL_FUNC_MAC_GETTABLE_CTX_PARAMS
  62. OSSL_FUNC_mac_settable_ctx_params OSSL_FUNC_MAC_SETTABLE_CTX_PARAMS
  63. A mac algorithm implementation may not implement all of these functions.
  64. In order to be a consistent set of functions, at least the following functions
  65. must be implemented: OSSL_FUNC_mac_newctx(), OSSL_FUNC_mac_freectx(), OSSL_FUNC_mac_init(),
  66. OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final().
  67. All other functions are optional.
  68. =head2 Context Management Functions
  69. OSSL_FUNC_mac_newctx() should create and return a pointer to a provider side
  70. structure for holding context information during a mac operation.
  71. A pointer to this context will be passed back in a number of the other mac
  72. operation function calls.
  73. The parameter I<provctx> is the provider context generated during provider
  74. initialisation (see L<provider(7)>).
  75. OSSL_FUNC_mac_freectx() is passed a pointer to the provider side mac context in
  76. the I<mctx> parameter.
  77. If it receives NULL as I<mctx> value, it should not do anything other than
  78. return.
  79. This function should free any resources associated with that context.
  80. OSSL_FUNC_mac_dupctx() should duplicate the provider side mac context in the
  81. I<mctx> parameter and return the duplicate copy.
  82. =head2 Encryption/Decryption Functions
  83. OSSL_FUNC_mac_init() initialises a mac operation given a newly created provider
  84. side mac context in the I<mctx> parameter. The I<params> are set before setting
  85. the MAC I<key> of I<keylen> bytes.
  86. OSSL_FUNC_mac_update() is called to supply data for MAC computation of a previously
  87. initialised mac operation.
  88. The I<mctx> parameter contains a pointer to a previously initialised provider
  89. side context.
  90. OSSL_FUNC_mac_update() may be called multiple times for a single mac operation.
  91. OSSL_FUNC_mac_final() completes the MAC computation started through previous
  92. OSSL_FUNC_mac_init() and OSSL_FUNC_mac_update() calls.
  93. The I<mctx> parameter contains a pointer to the provider side context.
  94. The resulting MAC should be written to I<out> and the amount of data written
  95. to I<*outl>, which should not exceed I<outsize> bytes.
  96. The same expectations apply to I<outsize> as documented for
  97. L<EVP_MAC_final(3)>.
  98. =head2 Mac Parameters
  99. See L<OSSL_PARAM(3)> for further details on the parameters structure used by
  100. these functions.
  101. OSSL_FUNC_mac_get_params() gets details of parameter values associated with the
  102. provider algorithm and stores them in I<params>.
  103. OSSL_FUNC_mac_set_ctx_params() sets mac parameters associated with the given
  104. provider side mac context I<mctx> to I<params>.
  105. Any parameter settings are additional to any that were previously set.
  106. Passing NULL for I<params> should return true.
  107. OSSL_FUNC_mac_get_ctx_params() gets details of currently set parameter values
  108. associated with the given provider side mac context I<mctx> and stores them
  109. in I<params>.
  110. Passing NULL for I<params> should return true.
  111. OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params(),
  112. and OSSL_FUNC_mac_settable_ctx_params() all return constant B<OSSL_PARAM>
  113. arrays as descriptors of the parameters that OSSL_FUNC_mac_get_params(),
  114. OSSL_FUNC_mac_get_ctx_params(), and OSSL_FUNC_mac_set_ctx_params()
  115. can handle, respectively. OSSL_FUNC_mac_gettable_ctx_params() and
  116. OSSL_FUNC_mac_settable_ctx_params() will return the parameters associated
  117. with the provider side context I<mctx> in its current state if it is
  118. not NULL. Otherwise, they return the parameters associated with the
  119. provider side algorithm I<provctx>.
  120. All MAC implementations are expected to handle the following parameters:
  121. =over 4
  122. =item with OSSL_FUNC_set_ctx_params():
  123. =over 4
  124. =item "key" (B<OSSL_MAC_PARAM_KEY>) <octet string>
  125. Sets the key in the associated MAC ctx. This is identical to passing a I<key>
  126. argument to the OSSL_FUNC_mac_init() function.
  127. =back
  128. =item with OSSL_FUNC_get_params():
  129. =over 4
  130. =item "size" (B<OSSL_MAC_PARAM_SIZE>) <integer>
  131. Can be used to get the default MAC size (which might be the only allowable
  132. MAC size for the implementation).
  133. Note that some implementations allow setting the size that the resulting MAC
  134. should have as well, see the documentation of the implementation.
  135. =back
  136. =over 4
  137. =item "size" (B<OSSL_MAC_PARAM_BLOCK_SIZE>) <integer>
  138. Can be used to get the MAC block size (if supported by the algorithm).
  139. =back
  140. =back
  141. =head1 NOTES
  142. The MAC life-cycle is described in L<life_cycle-rand(7)>. Providers should
  143. ensure that the various transitions listed there are supported. At some point
  144. the EVP layer will begin enforcing the listed transitions.
  145. =head1 RETURN VALUES
  146. OSSL_FUNC_mac_newctx() and OSSL_FUNC_mac_dupctx() should return the newly created
  147. provider side mac context, or NULL on failure.
  148. OSSL_FUNC_mac_init(), OSSL_FUNC_mac_update(), OSSL_FUNC_mac_final(), OSSL_FUNC_mac_get_params(),
  149. OSSL_FUNC_mac_get_ctx_params() and OSSL_FUNC_mac_set_ctx_params() should return 1 for
  150. success or 0 on error.
  151. OSSL_FUNC_mac_gettable_params(), OSSL_FUNC_mac_gettable_ctx_params() and
  152. OSSL_FUNC_mac_settable_ctx_params() should return a constant B<OSSL_PARAM>
  153. array, or NULL if none is offered.
  154. =head1 SEE ALSO
  155. L<provider(7)>,
  156. L<EVP_MAC-BLAKE2(7)>, L<EVP_MAC-CMAC(7)>, L<EVP_MAC-GMAC(7)>,
  157. L<EVP_MAC-HMAC(7)>, L<EVP_MAC-KMAC(7)>, L<EVP_MAC-Poly1305(7)>,
  158. L<EVP_MAC-Siphash(7)>,
  159. L<life_cycle-mac(7)>, L<EVP_MAC(3)>
  160. =head1 HISTORY
  161. The provider MAC interface was introduced in OpenSSL 3.0.
  162. =head1 COPYRIGHT
  163. Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
  164. Licensed under the Apache License 2.0 (the "License"). You may not use
  165. this file except in compliance with the License. You can obtain a copy
  166. in the file LICENSE in the source distribution or at
  167. L<https://www.openssl.org/source/license.html>.
  168. =cut