This is a little trickier than I expected. A cipher in a vacuum has a few uncomfortable places like above. A cipher with a mode is where the pain lies:
// 128-bit key, 256-bit blocksize
AlgorithmParameters params = MakeParameters
(Name::BlockSize(), 32)
(Name::IV(), ConstByteArrayParameter(iv, 32));
CBC_Mode<Kalyna>::Encryption enc; // Line 1
enc.SetKey(key, 16, params); // Line 2
On mode construction (line 1), CBC_Mode (and other modes) size some buffers based on the block cipher's blocksize. The problem is, the key (and other parameters) have not been set (line 2), so the blocksize is mostly unknown. You can see it by tracing calls to ResizeBuffers() in modes.h (
https://github.com/weidai11/cryptopp/blob/master/modes.h).
I think we can work around it by using a lazy resize strategy in the mode, but I'm concerned about how deep it could cut.
Does anyone have any thought or opinions on it?
Jeff