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