bio.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2016-2021 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. };
  28. void bio_free_ex_data(BIO *bio);
  29. void bio_cleanup(void);
  30. /* Old style to new style BIO_METHOD conversion functions */
  31. int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written);
  32. int bread_conv(BIO *bio, char *data, size_t datal, size_t *read);
  33. /* Changes to these internal BIOs must also update include/openssl/bio.h */
  34. # define BIO_CTRL_SET_KTLS 72
  35. # define BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG 74
  36. # define BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG 75
  37. /*
  38. * This is used with socket BIOs:
  39. * BIO_FLAGS_KTLS_TX means we are using ktls with this BIO for sending.
  40. * BIO_FLAGS_KTLS_TX_CTRL_MSG means we are about to send a ctrl message next.
  41. * BIO_FLAGS_KTLS_RX means we are using ktls with this BIO for receiving.
  42. */
  43. # define BIO_FLAGS_KTLS_TX 0x800
  44. # define BIO_FLAGS_KTLS_TX_CTRL_MSG 0x1000
  45. # define BIO_FLAGS_KTLS_RX 0x2000
  46. /* KTLS related controls and flags */
  47. # define BIO_set_ktls_flag(b, is_tx) \
  48. BIO_set_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX)
  49. # define BIO_should_ktls_flag(b, is_tx) \
  50. BIO_test_flags(b, (is_tx) ? BIO_FLAGS_KTLS_TX : BIO_FLAGS_KTLS_RX)
  51. # define BIO_set_ktls_ctrl_msg_flag(b) \
  52. BIO_set_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  53. # define BIO_should_ktls_ctrl_msg_flag(b) \
  54. BIO_test_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  55. # define BIO_clear_ktls_ctrl_msg_flag(b) \
  56. BIO_clear_flags(b, BIO_FLAGS_KTLS_TX_CTRL_MSG)
  57. # define BIO_set_ktls(b, keyblob, is_tx) \
  58. BIO_ctrl(b, BIO_CTRL_SET_KTLS, is_tx, keyblob)
  59. # define BIO_set_ktls_ctrl_msg(b, record_type) \
  60. BIO_ctrl(b, BIO_CTRL_SET_KTLS_TX_SEND_CTRL_MSG, record_type, NULL)
  61. # define BIO_clear_ktls_ctrl_msg(b) \
  62. BIO_ctrl(b, BIO_CTRL_CLEAR_KTLS_TX_CTRL_MSG, 0, NULL)
  63. /* Functions to allow the core to offer the CORE_BIO type to providers */
  64. OSSL_CORE_BIO *ossl_core_bio_new_from_bio(BIO *bio);
  65. OSSL_CORE_BIO *ossl_core_bio_new_file(const char *filename, const char *mode);
  66. OSSL_CORE_BIO *ossl_core_bio_new_mem_buf(const void *buf, int len);
  67. int ossl_core_bio_read_ex(OSSL_CORE_BIO *cb, void *data, size_t dlen,
  68. size_t *readbytes);
  69. int ossl_core_bio_write_ex(OSSL_CORE_BIO *cb, const void *data, size_t dlen,
  70. size_t *written);
  71. int ossl_core_bio_gets(OSSL_CORE_BIO *cb, char *buf, int size);
  72. int ossl_core_bio_puts(OSSL_CORE_BIO *cb, const char *buf);
  73. long ossl_core_bio_ctrl(OSSL_CORE_BIO *cb, int cmd, long larg, void *parg);
  74. int ossl_core_bio_up_ref(OSSL_CORE_BIO *cb);
  75. int ossl_core_bio_free(OSSL_CORE_BIO *cb);
  76. int ossl_core_bio_vprintf(OSSL_CORE_BIO *cb, const char *format, va_list args);
  77. int ossl_bio_init_core(OSSL_LIB_CTX *libctx, const OSSL_DISPATCH *fns);
  78. #endif