BIO_f_cipher.3ossl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "BIO_F_CIPHER 3ossl"
  58. .TH BIO_F_CIPHER 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx \- cipher BIO filter
  65. .SH SYNOPSIS
  66. .IX Header "SYNOPSIS"
  67. .Vb 2
  68. \& #include <openssl/bio.h>
  69. \& #include <openssl/evp.h>
  70. \&
  71. \& const BIO_METHOD *BIO_f_cipher(void);
  72. \& int BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
  73. \& const unsigned char *key, const unsigned char *iv, int enc);
  74. \& int BIO_get_cipher_status(BIO *b);
  75. \& int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx);
  76. .Ve
  77. .SH DESCRIPTION
  78. .IX Header "DESCRIPTION"
  79. \&\fBBIO_f_cipher()\fR returns the cipher BIO method. This is a filter
  80. BIO that encrypts any data written through it, and decrypts any data
  81. read from it. It is a BIO wrapper for the cipher routines
  82. \&\fBEVP_CipherInit()\fR, \fBEVP_CipherUpdate()\fR and \fBEVP_CipherFinal()\fR.
  83. .PP
  84. Cipher BIOs do not support \fBBIO_gets()\fR or \fBBIO_puts()\fR.
  85. .PP
  86. \&\fBBIO_flush()\fR on an encryption BIO that is being written through is
  87. used to signal that no more data is to be encrypted: this is used
  88. to flush and possibly pad the final block through the BIO.
  89. .PP
  90. \&\fBBIO_set_cipher()\fR sets the cipher of BIO \fBb\fR to \fBcipher\fR using key \fBkey\fR
  91. and IV \fBiv\fR. \fBenc\fR should be set to 1 for encryption and zero for
  92. decryption.
  93. .PP
  94. When reading from an encryption BIO the final block is automatically
  95. decrypted and checked when EOF is detected. \fBBIO_get_cipher_status()\fR
  96. is a \fBBIO_ctrl()\fR macro which can be called to determine whether the
  97. decryption operation was successful.
  98. .PP
  99. \&\fBBIO_get_cipher_ctx()\fR is a \fBBIO_ctrl()\fR macro which retrieves the internal
  100. BIO cipher context. The retrieved context can be used in conjunction
  101. with the standard cipher routines to set it up. This is useful when
  102. \&\fBBIO_set_cipher()\fR is not flexible enough for the applications needs.
  103. .SH NOTES
  104. .IX Header "NOTES"
  105. When encrypting \fBBIO_flush()\fR \fBmust\fR be called to flush the final block
  106. through the BIO. If it is not then the final block will fail a subsequent
  107. decrypt.
  108. .PP
  109. When decrypting an error on the final block is signaled by a zero
  110. return value from the read operation. A successful decrypt followed
  111. by EOF will also return zero for the final read. \fBBIO_get_cipher_status()\fR
  112. should be called to determine if the decrypt was successful.
  113. .PP
  114. As always, if \fBBIO_gets()\fR or \fBBIO_puts()\fR support is needed then it can
  115. be achieved by preceding the cipher BIO with a buffering BIO.
  116. .SH "RETURN VALUES"
  117. .IX Header "RETURN VALUES"
  118. \&\fBBIO_f_cipher()\fR returns the cipher BIO method.
  119. .PP
  120. \&\fBBIO_set_cipher()\fR returns 1 for success and 0 for failure.
  121. .PP
  122. \&\fBBIO_get_cipher_status()\fR returns 1 for a successful decrypt and <=0
  123. for failure.
  124. .PP
  125. \&\fBBIO_get_cipher_ctx()\fR returns 1 for success and <=0 for failure.
  126. .SH COPYRIGHT
  127. .IX Header "COPYRIGHT"
  128. Copyright 2000\-2020 The OpenSSL Project Authors. All Rights Reserved.
  129. .PP
  130. Licensed under the Apache License 2.0 (the "License"). You may not use
  131. this file except in compliance with the License. You can obtain a copy
  132. in the file LICENSE in the source distribution or at
  133. <https://www.openssl.org/source/license.html>.