xref: /onnv-gate/usr/src/common/openssl/doc/crypto/BIO_f_cipher.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948=pod
2*2175Sjp161948
3*2175Sjp161948=head1 NAME
4*2175Sjp161948
5*2175Sjp161948BIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx - cipher BIO filter
6*2175Sjp161948
7*2175Sjp161948=head1 SYNOPSIS
8*2175Sjp161948
9*2175Sjp161948 #include <openssl/bio.h>
10*2175Sjp161948 #include <openssl/evp.h>
11*2175Sjp161948
12*2175Sjp161948 BIO_METHOD *	BIO_f_cipher(void);
13*2175Sjp161948 void BIO_set_cipher(BIO *b,const EVP_CIPHER *cipher,
14*2175Sjp161948		unsigned char *key, unsigned char *iv, int enc);
15*2175Sjp161948 int BIO_get_cipher_status(BIO *b)
16*2175Sjp161948 int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx)
17*2175Sjp161948
18*2175Sjp161948=head1 DESCRIPTION
19*2175Sjp161948
20*2175Sjp161948BIO_f_cipher() returns the cipher BIO method. This is a filter
21*2175Sjp161948BIO that encrypts any data written through it, and decrypts any data
22*2175Sjp161948read from it. It is a BIO wrapper for the cipher routines
23*2175Sjp161948EVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal().
24*2175Sjp161948
25*2175Sjp161948Cipher BIOs do not support BIO_gets() or BIO_puts().
26*2175Sjp161948
27*2175Sjp161948BIO_flush() on an encryption BIO that is being written through is
28*2175Sjp161948used to signal that no more data is to be encrypted: this is used
29*2175Sjp161948to flush and possibly pad the final block through the BIO.
30*2175Sjp161948
31*2175Sjp161948BIO_set_cipher() sets the cipher of BIO B<b> to B<cipher> using key B<key>
32*2175Sjp161948and IV B<iv>. B<enc> should be set to 1 for encryption and zero for
33*2175Sjp161948decryption.
34*2175Sjp161948
35*2175Sjp161948When reading from an encryption BIO the final block is automatically
36*2175Sjp161948decrypted and checked when EOF is detected. BIO_get_cipher_status()
37*2175Sjp161948is a BIO_ctrl() macro which can be called to determine whether the
38*2175Sjp161948decryption operation was successful.
39*2175Sjp161948
40*2175Sjp161948BIO_get_cipher_ctx() is a BIO_ctrl() macro which retrieves the internal
41*2175Sjp161948BIO cipher context. The retrieved context can be used in conjunction
42*2175Sjp161948with the standard cipher routines to set it up. This is useful when
43*2175Sjp161948BIO_set_cipher() is not flexible enough for the applications needs.
44*2175Sjp161948
45*2175Sjp161948=head1 NOTES
46*2175Sjp161948
47*2175Sjp161948When encrypting BIO_flush() B<must> be called to flush the final block
48*2175Sjp161948through the BIO. If it is not then the final block will fail a subsequent
49*2175Sjp161948decrypt.
50*2175Sjp161948
51*2175Sjp161948When decrypting an error on the final block is signalled by a zero
52*2175Sjp161948return value from the read operation. A successful decrypt followed
53*2175Sjp161948by EOF will also return zero for the final read. BIO_get_cipher_status()
54*2175Sjp161948should be called to determine if the decrypt was successful.
55*2175Sjp161948
56*2175Sjp161948As always, if BIO_gets() or BIO_puts() support is needed then it can
57*2175Sjp161948be achieved by preceding the cipher BIO with a buffering BIO.
58*2175Sjp161948
59*2175Sjp161948=head1 RETURN VALUES
60*2175Sjp161948
61*2175Sjp161948BIO_f_cipher() returns the cipher BIO method.
62*2175Sjp161948
63*2175Sjp161948BIO_set_cipher() does not return a value.
64*2175Sjp161948
65*2175Sjp161948BIO_get_cipher_status() returns 1 for a successful decrypt and 0
66*2175Sjp161948for failure.
67*2175Sjp161948
68*2175Sjp161948BIO_get_cipher_ctx() currently always returns 1.
69*2175Sjp161948
70*2175Sjp161948=head1 EXAMPLES
71*2175Sjp161948
72*2175Sjp161948TBA
73*2175Sjp161948
74*2175Sjp161948=head1 SEE ALSO
75*2175Sjp161948
76*2175Sjp161948TBA
77