Return an error if no recipient type matches.

If the key type does not match any CMS recipient type return
an error instead of using a random key (MMA mitigation). This
does not leak any useful information to an attacker.

PR#3348
(cherry picked from commit bd43b4cf778a53ffa5d77510ecd408a009dc00d2)
safety check to ensure we dont send out beyond the users buffer
Move length check earlier to ensure we don't go beyond the end of the user's buffer. PR#3320
Unit/regression test for TLS heartbeats.

Regression test against CVE-2014-0160 (Heartbleed).

More info: http://mike-bland.com/tags/heartbleed.html

(based on commit 35cb55988b75573105eefd00d27d0138eebe40b1)