1*e71b7053SJung-uk Kim=pod 2*e71b7053SJung-uk Kim 3*e71b7053SJung-uk Kim=head1 NAME 4*e71b7053SJung-uk Kim 5*e71b7053SJung-uk KimBIO_f_cipher, BIO_set_cipher, BIO_get_cipher_status, BIO_get_cipher_ctx - cipher BIO filter 6*e71b7053SJung-uk Kim 7*e71b7053SJung-uk Kim=head1 SYNOPSIS 8*e71b7053SJung-uk Kim 9*e71b7053SJung-uk Kim=for comment multiple includes 10*e71b7053SJung-uk Kim 11*e71b7053SJung-uk Kim #include <openssl/bio.h> 12*e71b7053SJung-uk Kim #include <openssl/evp.h> 13*e71b7053SJung-uk Kim 14*e71b7053SJung-uk Kim const BIO_METHOD *BIO_f_cipher(void); 15*e71b7053SJung-uk Kim void BIO_set_cipher(BIO *b, const EVP_CIPHER *cipher, 16*e71b7053SJung-uk Kim unsigned char *key, unsigned char *iv, int enc); 17*e71b7053SJung-uk Kim int BIO_get_cipher_status(BIO *b) 18*e71b7053SJung-uk Kim int BIO_get_cipher_ctx(BIO *b, EVP_CIPHER_CTX **pctx) 19*e71b7053SJung-uk Kim 20*e71b7053SJung-uk Kim=head1 DESCRIPTION 21*e71b7053SJung-uk Kim 22*e71b7053SJung-uk KimBIO_f_cipher() returns the cipher BIO method. This is a filter 23*e71b7053SJung-uk KimBIO that encrypts any data written through it, and decrypts any data 24*e71b7053SJung-uk Kimread from it. It is a BIO wrapper for the cipher routines 25*e71b7053SJung-uk KimEVP_CipherInit(), EVP_CipherUpdate() and EVP_CipherFinal(). 26*e71b7053SJung-uk Kim 27*e71b7053SJung-uk KimCipher BIOs do not support BIO_gets() or BIO_puts(). 28*e71b7053SJung-uk Kim 29*e71b7053SJung-uk KimBIO_flush() on an encryption BIO that is being written through is 30*e71b7053SJung-uk Kimused to signal that no more data is to be encrypted: this is used 31*e71b7053SJung-uk Kimto flush and possibly pad the final block through the BIO. 32*e71b7053SJung-uk Kim 33*e71b7053SJung-uk KimBIO_set_cipher() sets the cipher of BIO B<b> to B<cipher> using key B<key> 34*e71b7053SJung-uk Kimand IV B<iv>. B<enc> should be set to 1 for encryption and zero for 35*e71b7053SJung-uk Kimdecryption. 36*e71b7053SJung-uk Kim 37*e71b7053SJung-uk KimWhen reading from an encryption BIO the final block is automatically 38*e71b7053SJung-uk Kimdecrypted and checked when EOF is detected. BIO_get_cipher_status() 39*e71b7053SJung-uk Kimis a BIO_ctrl() macro which can be called to determine whether the 40*e71b7053SJung-uk Kimdecryption operation was successful. 41*e71b7053SJung-uk Kim 42*e71b7053SJung-uk KimBIO_get_cipher_ctx() is a BIO_ctrl() macro which retrieves the internal 43*e71b7053SJung-uk KimBIO cipher context. The retrieved context can be used in conjunction 44*e71b7053SJung-uk Kimwith the standard cipher routines to set it up. This is useful when 45*e71b7053SJung-uk KimBIO_set_cipher() is not flexible enough for the applications needs. 46*e71b7053SJung-uk Kim 47*e71b7053SJung-uk Kim=head1 NOTES 48*e71b7053SJung-uk Kim 49*e71b7053SJung-uk KimWhen encrypting BIO_flush() B<must> be called to flush the final block 50*e71b7053SJung-uk Kimthrough the BIO. If it is not then the final block will fail a subsequent 51*e71b7053SJung-uk Kimdecrypt. 52*e71b7053SJung-uk Kim 53*e71b7053SJung-uk KimWhen decrypting an error on the final block is signaled by a zero 54*e71b7053SJung-uk Kimreturn value from the read operation. A successful decrypt followed 55*e71b7053SJung-uk Kimby EOF will also return zero for the final read. BIO_get_cipher_status() 56*e71b7053SJung-uk Kimshould be called to determine if the decrypt was successful. 57*e71b7053SJung-uk Kim 58*e71b7053SJung-uk KimAs always, if BIO_gets() or BIO_puts() support is needed then it can 59*e71b7053SJung-uk Kimbe achieved by preceding the cipher BIO with a buffering BIO. 60*e71b7053SJung-uk Kim 61*e71b7053SJung-uk Kim=head1 RETURN VALUES 62*e71b7053SJung-uk Kim 63*e71b7053SJung-uk KimBIO_f_cipher() returns the cipher BIO method. 64*e71b7053SJung-uk Kim 65*e71b7053SJung-uk KimBIO_set_cipher() does not return a value. 66*e71b7053SJung-uk Kim 67*e71b7053SJung-uk KimBIO_get_cipher_status() returns 1 for a successful decrypt and 0 68*e71b7053SJung-uk Kimfor failure. 69*e71b7053SJung-uk Kim 70*e71b7053SJung-uk KimBIO_get_cipher_ctx() currently always returns 1. 71*e71b7053SJung-uk Kim 72*e71b7053SJung-uk Kim=head1 COPYRIGHT 73*e71b7053SJung-uk Kim 74*e71b7053SJung-uk KimCopyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved. 75*e71b7053SJung-uk Kim 76*e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License"). You may not use 77*e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 78*e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 79*e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 80*e71b7053SJung-uk Kim 81*e71b7053SJung-uk Kim=cut 82