cipher_aead.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright 2019 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. /* TODO(3.0) Figure out what flags are really needed */
  11. #define AEAD_FLAGS (EVP_CIPH_FLAG_AEAD_CIPHER \
  12. | EVP_CIPH_CUSTOM_IV \
  13. | EVP_CIPH_FLAG_CUSTOM_CIPHER \
  14. | EVP_CIPH_ALWAYS_CALL_INIT \
  15. | EVP_CIPH_CTRL_INIT \
  16. | EVP_CIPH_CUSTOM_COPY)
  17. #define IMPLEMENT_aead_cipher(alg, lc, UCMODE, flags, kbits, blkbits, ivbits) \
  18. static OSSL_OP_cipher_get_params_fn alg##_##kbits##_##lc##_get_params; \
  19. static int alg##_##kbits##_##lc##_get_params(OSSL_PARAM params[]) \
  20. { \
  21. return cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
  22. flags, kbits, blkbits, ivbits); \
  23. } \
  24. static OSSL_OP_cipher_newctx_fn alg##kbits##lc##_newctx; \
  25. static void * alg##kbits##lc##_newctx(void *provctx) \
  26. { \
  27. return alg##_##lc##_newctx(provctx, kbits); \
  28. } \
  29. const OSSL_DISPATCH alg##kbits##lc##_functions[] = { \
  30. { OSSL_FUNC_CIPHER_NEWCTX, (void (*)(void))alg##kbits##lc##_newctx }, \
  31. { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))alg##_##lc##_freectx }, \
  32. { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void)) lc##_einit }, \
  33. { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void)) lc##_dinit }, \
  34. { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void)) lc##_stream_update }, \
  35. { OSSL_FUNC_CIPHER_FINAL, (void (*)(void)) lc##_stream_final }, \
  36. { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void)) lc##_cipher }, \
  37. { OSSL_FUNC_CIPHER_GET_PARAMS, \
  38. (void (*)(void)) alg##_##kbits##_##lc##_get_params }, \
  39. { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
  40. (void (*)(void)) lc##_get_ctx_params }, \
  41. { OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
  42. (void (*)(void)) lc##_set_ctx_params }, \
  43. { OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
  44. (void (*)(void))cipher_generic_gettable_params }, \
  45. { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
  46. (void (*)(void))cipher_aead_gettable_ctx_params }, \
  47. { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
  48. (void (*)(void))cipher_aead_settable_ctx_params }, \
  49. { 0, NULL } \
  50. }