go.crypto/openpgp: Allow configuration of s2k hash during encryption.

This patch/CL allows the user to configure the hash function
used in the s2k key-stretching transformation during
encryption. It fixes the current limitation in which SHA1 is
hard-coded for that task.

With this change, packet.Config.DefaultHash is used by default
for the mode 3 s2k key-stretching that is currently used for
encryption, but the user may choose any other valid openpgp
hash by passing a new (possibly nil) pointer argument to
s2k.Serialize().

Note that this change introduces an API change to
s2k.Serialize() in the form of an additional
argument. However, the s2k package is a low-level facility
that (as far as I could tell) is used directly by
go.crypto/openpgp only.

The CL comes with an modified test to check the use and
decoding of all the valid hash functions with regard to
s2k.Serialize().

This patch should be followed by one that allows the user to
configure the iteration count in mode 3 s2k, and it is a
prerequisite for that forthcoming change.

R=golang-codereviews, agl
CC=agl, golang-codereviews
https://golang.org/cl/160110045
3 files changed