Classic protocol and crypto cleanups.

Each of these blocks you've created for the sole purpose of localising some variables is a candidate for breaking out into a little static function, that would help break up this big long function and possibly make it a little more readable.