Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How might one use the output parameters of `HashAlgorithm.TransformBlock`?

Tags:

.net

api

The method HashAlgorithm.TransformBlock takes the arguments outputBuffer and outputOffset.

I can't think of a reason for this method to have those. Is it so common to copy the hashed data somewhere that the copy was made an integral part of this method?

I'm rather curious to see a good use case involving these output parameters.

like image 692
Roman Starkov Avatar asked Jan 28 '11 19:01

Roman Starkov


1 Answers

It's pretty clearly an oversight. I couldn't find a source to back this up, but as it stands any use case we could imagine (I can't imagine any practical use cases) saves developers at most one line of code. Worse, any developer who (for whatever reason) did want a copy of his own buffer made would probably find it so unlikely that TransformBlock would do this for her that she'd probably write that line of code herself anyway!

outputBuffer is used by other ICryptoTransforms in sensible ways (eg. as an output buffer), so it really should contain - when not null and not overwriting the input buffer - the intermediate digest, especially since it's not otherwise available from the class. (Making the intermediate digest available is a nice idea whenever the input to the algorithm appears in multiple contexts.)

My guess is:

  1. Someone got it backwards in 1.1 regarding when the IOException should be thrown.
  2. In 2.0, someone "fixed" that problem, but misread the spec and copied from inputBuffer instead of this.HashValue.
  3. Intermediate digests are used so rarely that no one has complained before 4.0.
like image 84
ladenedge Avatar answered Sep 30 '22 08:09

ladenedge