crypto/cipher: BlockMode and HSMs #26787
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
I am a maintainer of a Go package which provides access to keys held in PKCS#11 HSMs to Go programs, using (as far as possible) native Go crypto APIs.
For asymmetric keys, this was a pleasant experience. It was straightforward to expose ECDSA keys via crypto.Signer. The interface was obviously designed with HSMs in mind (and we appreciate the thought l-)
Currently I am adding support for symmetric keys. This can be made to work but certain operations are very slow, due to a mismatch between the PKCS#11 API and the Go crypto/cipher APIs.
Specifically, to efficiently perform 'bulk' crypto operations, the PKCS#11 API requires a sequence of three calls:
C_EncryptInit
C_EncryptUpdate
(any number of times)C_EncryptFinal
Even if the mode in question does not produce any ciphertext in the call to
C_EncryptFinal
, it is necessary to call it in order to release resources.However,
cipher.Block
andcipher.BlockMode
provide no way for the caller to signal that they are finished. Essentially they lack aClose
method. So an implementation of either of these interfaces that uses an HSM is not possible.It is possible, of course, for a
cipher.Block
to encrypt a single block and clean up after itself (and this is what I've done). However using such an implementation from cipher.NewCBCEncrypter can be hundreds of times slower than an idiomatic PKCS#11-aware implementation.My questions/requests in this issue are:
Close()
methods to the existingcipher.Block
andcipher.BlockMode
interfaces?See ThalesGroup/crypto11#6 for additional information, although I believe I've captured everything relevant above.
What version of Go are you using (
go version
)?go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?The text was updated successfully, but these errors were encountered: