xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man3/BIO_f_cipher.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosBIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx - cipher BIO filter
6*4724848cSchristos
7*4724848cSchristos=head1 SYNOPSIS
8*4724848cSchristos
9*4724848cSchristos=for comment multiple includes
10*4724848cSchristos
11*4724848cSchristos #include <openssl/bio.h>
12*4724848cSchristos #include <openssl/evp.h>
13*4724848cSchristos
14*4724848cSchristos const BIO_METHOD *BIO_f_cipher(void);
15*4724848cSchristos void BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher,
16*4724848cSchristos                     unsigned char *key, unsigned char *iv, int enc);
17*4724848cSchristos int BIO_get_cipher_status(BIO *b)
18*4724848cSchristos int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx)
19*4724848cSchristos
20*4724848cSchristos=head1 DESCRIPTION
21*4724848cSchristos
22*4724848cSchristosBIO_f_cipher() returns the cipher BIO method. This is a filter
23*4724848cSchristosBIO that encrypts any data written through it, and decrypts any data
24*4724848cSchristosread from it. It is a BIO wrapper for the cipher routines
25*4724848cSchristosEVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal().
26*4724848cSchristos
27*4724848cSchristosCipher BIOs do not support BIO_gets() or BIO_puts().
28*4724848cSchristos
29*4724848cSchristosBIO_flush() on an encryption BIO that is being written through is
30*4724848cSchristosused to signal that no more data is to be encrypted: this is used
31*4724848cSchristosto flush and possibly pad the final block through the BIO.
32*4724848cSchristos
33*4724848cSchristosBIO_set_cipher() sets the cipher of BIO B<b> to B<cipher> using key B<key>
34*4724848cSchristosand IV B<iv>. B<enc> should be set to 1 for encryption and zero for
35*4724848cSchristosdecryption.
36*4724848cSchristos
37*4724848cSchristosWhen reading from an encryption BIO the final block is automatically
38*4724848cSchristosdecrypted and checked when EOF is detected. BIO_get_cipher_status()
39*4724848cSchristosis a BIO_ctrl() macro which can be called to determine whether the
40*4724848cSchristosdecryption operation was successful.
41*4724848cSchristos
42*4724848cSchristosBIO_get_cipher_ctx() is a BIO_ctrl() macro which retrieves the internal
43*4724848cSchristosBIO cipher context. The retrieved context can be used in conjunction
44*4724848cSchristoswith the standard cipher routines to set it up. This is useful when
45*4724848cSchristosBIO_set_cipher() is not flexible enough for the applications needs.
46*4724848cSchristos
47*4724848cSchristos=head1 NOTES
48*4724848cSchristos
49*4724848cSchristosWhen encrypting BIO_flush() B<must> be called to flush the final block
50*4724848cSchristosthrough the BIO. If it is not then the final block will fail a subsequent
51*4724848cSchristosdecrypt.
52*4724848cSchristos
53*4724848cSchristosWhen decrypting an error on the final block is signaled by a zero
54*4724848cSchristosreturn value from the read operation. A successful decrypt followed
55*4724848cSchristosby EOF will also return zero for the final read. BIO_get_cipher_status()
56*4724848cSchristosshould be called to determine if the decrypt was successful.
57*4724848cSchristos
58*4724848cSchristosAs always, if BIO_gets() or BIO_puts() support is needed then it can
59*4724848cSchristosbe achieved by preceding the cipher BIO with a buffering BIO.
60*4724848cSchristos
61*4724848cSchristos=head1 RETURN VALUES
62*4724848cSchristos
63*4724848cSchristosBIO_f_cipher() returns the cipher BIO method.
64*4724848cSchristos
65*4724848cSchristosBIO_set_cipher() does not return a value.
66*4724848cSchristos
67*4724848cSchristosBIO_get_cipher_status() returns 1 for a successful decrypt and 0
68*4724848cSchristosfor failure.
69*4724848cSchristos
70*4724848cSchristosBIO_get_cipher_ctx() currently always returns 1.
71*4724848cSchristos
72*4724848cSchristos=head1 COPYRIGHT
73*4724848cSchristos
74*4724848cSchristosCopyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
75*4724848cSchristos
76*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
77*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
78*4724848cSchristosin the file LICENSE in the source distribution or at
79*4724848cSchristosL<https://www.openssl.org/source/license.html>.
80*4724848cSchristos
81*4724848cSchristos=cut
82