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