ciphercommon_aead.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2019-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #define UNINITIALISED_SIZET ((size_t)-1)
  10. #define AEAD_FLAGS (PROV_CIPHER_FLAG_AEAD | PROV_CIPHER_FLAG_CUSTOM_IV)
  11. #define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits) \
  12. static OSSL_FUNC_cipher_get_params_fn alg##_##kbits##_##lc##_get_params; \
  13. static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[]) \
  14. { \
  15. return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
  16. flags, kbits, blkbits, ivbits); \
  17. } \
  18. static OSSL_FUNC_cipher_newctx_fn alg##kbits##lc##_newctx; \
  19. static void * alg##kbits##lc##_newctx(void *provctx) \
  20. { \
  21. return alg##_##lc##_newctx(provctx, kbits); \
  22. } \
  23. static void * alg##kbits##lc##_dupctx(void *src) \
  24. { \
  25. return alg##_##lc##_dupctx(src); \
  26. } \
  27. const OSSL_DISPATCH ossl_##alg##kbits##lc##_functions[] = { \
  28. { OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))alg##kbits##lc##_newctx }, \
  29. { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_##lc##_freectx }, \
  30. { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))alg##kbits##lc##_dupctx }, \
  31. { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_##lc##_einit }, \
  32. { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_##lc##_dinit }, \
  33. { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))ossl_##lc##_stream_update }, \
  34. { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))ossl_##lc##_stream_final }, \
  35. { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_##lc##_cipher }, \
  36. { OSSL_FUNC_CIPHER_GET_PARAMS, \
  37. (void (*)(void)) alg##_##kbits##_##lc##_get_params }, \
  38. { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
  39. (void (*)(void)) ossl_##lc##_get_ctx_params }, \
  40. { OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
  41. (void (*)(void)) ossl_##lc##_set_ctx_params }, \
  42. { OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
  43. (void (*)(void))ossl_cipher_generic_gettable_params }, \
  44. { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
  45. (void (*)(void))ossl_cipher_aead_gettable_ctx_params }, \
  46. { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
  47. (void (*)(void))ossl_cipher_aead_settable_ctx_params }, \
  48. { 0, NULL } \
  49. }