Hi there!
I checked the code you provided and its possibly added by a malware indeed.
The code by itself doesn’t seem to have the capability to do more than list all the posts you have and inject some content into them.
You can search the database for <div id=”wp_cd_code”> to check if there was in fact any injection. If any record is found then i recommend you start cleaning up the database or try restore a good backup.
If the code continues to be added to the functions.php file then you may have some backdoor present on the site that needs to be removed.
As a precaution just in case be sure to change all credentials, FTP, wp-admin and database.