The culprit: sometimes DH_calculate_key returns less than DH_KEY_LEN bytes; we needed to check the return value. svn:r322