Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing functionality for setting the initial value when using instance methods #9

Open
Blenderpics opened this issue Aug 10, 2018 · 3 comments
Assignees

Comments

@Blenderpics
Copy link

Blenderpics commented Aug 10, 2018

I need to calculate a crc32 checksum with LSB bit-ordering and a start value of 0xFFFFFFFF.
This seems to be impossible with this library.

By using the public static uint Append(uint initial, byte[] input, int offset, int length) function, you can specify a start value (by using the uint initial argument to do so). However it is not possible to specify the bit-ordering when using the static functions.

It is possible to specify the bit-ordering by instantiating the public class Crc32Algorithm : HashAlgorithm via the constructor argument bool isBigEndian. However, using an instance it is not possible to set a start value since public abstract class HashAlgorithm : IDisposable, ICryptoTransform has no functionality for it.

@force-net
Copy link
Owner

Main usage of instance methods is to use as specific implementation of HashAlgorithm class. Ordering is only used in HashFinal method, when byte array is needed.
If you use crc32 as 'integer' value, there is no difference in bit ordering.
To convert to byte array manually, you can use BitConverter.GetBytes or use such code:

public static byte[] ToBigEndian(int v)
{
	return new[] { (byte)(v >> 24), (byte)(v >> 16), (byte)(v >> 8), (byte)v };
}

Anyway, I'll think about adding initial value for instance methods.

@Blenderpics
Copy link
Author

Blenderpics commented Aug 10, 2018

Whoops, i thought the bool isBigEndian argument was used to indicate the bit-order of the input data (the old Endian vs. LSB/MSB confusion).
that certainly explains why i could not reproduce any checksums i generated with this lib with other tools.

I will swap the bit-order of my input data manually then.
Adding support for an initial value for the instance methods would be quite nice, since there are quite a few usecases where a start value of 0xFFFFFFFF is used.

should i close this issue or do you want to use it to keep track of the potential improvement regarding the initial value for instance methods?

@force-net
Copy link
Owner

Let task will be opened until ability to set initial value will be implemented.

@force-net force-net self-assigned this Aug 10, 2018
@Blenderpics Blenderpics changed the title LSB + Initial value can't be calculated with the current implementation Missing functionality for setting the initial value when using instance methods Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants