bio.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2016-2022 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. #ifndef OSSL_INTERNAL_BIO_H
  10. # define OSSL_INTERNAL_BIO_H
  11. # pragma once
  12. # include <openssl/core.h>
  13. # include <openssl/bio.h>
  14. struct bio_method_st {
  15. int type;
  16. char *name;
  17. int (*bwrite) (BIO *, const char *, size_t, size_t *);
  18. int (*bwrite_old) (BIO *, const char *, int);
  19. int (*bread) (BIO *, char *, size_t, size_t *);
  20. int (*bread_old) (BIO *, char *, int);
  21. int (*bputs) (BIO *, const char *);
  22. int (*bgets) (BIO *, char *, int);
  23. long (*ctrl) (BIO *, int, long, void *);
  24. int (*create) (BIO *);
  25. int (*destroy) (BIO *);
  26. long (*callback_ctrl) (BIO *, int, BIO_info_cb *);
  27. int (*bsendmmsg) (BIO *, BIO_MSG *, size_t, size_t, uint64_t, size_t *);
  28. int (*brecvmmsg) (BIO *, BIO_MSG *, size_t, size_t, uint64_t, size_t *);
  29. };
  30. void bio_free_ex_data(BIO *bio);
  31. void bio_cleanup(void);
  32. /* Old style to new style BIO_METHOD conversion functions */
  33. int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written);
  34. int bread_conv(BIO *bio, char *data, size_t datal, size_t *read);
  35. /* Changes to these internal BIOs must also update include/openssl/bio.h */
  36. # define BIO_CTRL_SET_KTLS 72
  37. # define BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG 74
  38. # define BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG 75
  39. # define BIO_CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE 90
  40. /*
  41. * This is used with socket BIOs:
  42. * BIO_FLAGS_KTLS_TX means we are using ktls with this BIO for sending.
  43. * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next.
  44. * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving.
  45. * BIO_FLAGS_KTLS_TX_ZEROCOPY_SENDFILE means we are using the zerocopy mode with
  46. * this BIO for sending using sendfile.
  47. */
  48. # define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000
  49. # define BIO_FLAGS_KTLS_RX 0x2000
  50. # define BIO_FLAGS_KTLS_TX 0x4000
  51. # define BIO_FLAGS_KTLS_TX_ZEROCOPY_SENDFILE 0x8000
  52. /* KTLS related controls and flags */
  53. # define BIO_set_ktls_flag(b, is_tx) \
  54. BIO_set_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX)
  55. # define BIO_should_ktls_flag(b, is_tx) \
  56. BIO_test_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX)
  57. # define BIO_set_ktls_ctrl_msg_flag(b) \
  58. BIO_set_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  59. # define BIO_should_ktls_ctrl_msg_flag(b) \
  60. BIO_test_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  61. # define BIO_clear_ktls_ctrl_msg_flag(b) \
  62. BIO_clear_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  63. # define BIO_set_ktls_zerocopy_sendfile_flag(b) \
  64. BIO_set_flags(b, BIO_FLAGS_KTLS_TX_ZEROCOPY_SENDFILE)
  65. # define BIO_set_ktls(b, keyblob, is_tx) \
  66. BIO_ctrl(b, BIO_CTRL_SET_KTLS, is_tx, keyblob)
  67. # define BIO_set_ktls_ctrl_msg(b, record_type) \
  68. BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG, record_type, NULL)
  69. # define BIO_clear_ktls_ctrl_msg(b) \
  70. BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG, 0, NULL)
  71. # define BIO_set_ktls_tx_zerocopy_sendfile(b) \
  72. BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_ZEROCOPY_SENDFILE, 0, NULL)
  73. /* Functions to allow the core to offer the CORE_BIO type to providers */
  74. OSSL_CORE_BIO *ossl_core_bio_new_from_bio(BIO *bio);
  75. OSSL_CORE_BIO *ossl_core_bio_new_file(const char *filename, const char *mode);
  76. OSSL_CORE_BIO *ossl_core_bio_new_mem_buf(const void *buf, int len);
  77. int ossl_core_bio_read_ex(OSSL_CORE_BIO *cb, void *data, size_t dlen,
  78. size_t *readbytes);
  79. int ossl_core_bio_write_ex(OSSL_CORE_BIO *cb, const void *data, size_t dlen,
  80. size_t *written);
  81. int ossl_core_bio_gets(OSSL_CORE_BIO *cb, char *buf, int size);
  82. int ossl_core_bio_puts(OSSL_CORE_BIO *cb, const char *buf);
  83. long ossl_core_bio_ctrl(OSSL_CORE_BIO *cb, int cmd, long larg, void *parg);
  84. int ossl_core_bio_up_ref(OSSL_CORE_BIO *cb);
  85. int ossl_core_bio_free(OSSL_CORE_BIO *cb);
  86. int ossl_core_bio_vprintf(OSSL_CORE_BIO *cb, const char *format, va_list args);
  87. int ossl_bio_init_core(OSSL_LIB_CTX *libctx, const OSSL_DISPATCH *fns);
  88. #endif