you should use:
FillChar(buffer, Sizeof(buffer), #00);
FillChar(hashBuf, Sizeof(hashBuf), #00);
FillChar() is quicker than iterating in a loop. IIRC there are other similar functions but I don't remember their name atm.
Thanks, I changed it. Is there any benefit to using the control string #00 as opposed to simply writing 0?
One thing I find odd here is the buffer of 1kb you used, that is too small even for low end devices.
I suggest you use something like 32 or 64kb buffers at worst.
Actually I'm using the size 1024², which should be around 1MB, or am I mistaking something? I do feel my code could be faster though, it takes a while to hash a few GB (several seconds). Not sure how fast that should actually be running.
As far as generics goes, I tried compiling the following:
generic function f<T>(a: T): T;
begin
Result := a + a;
end;
Which yields the error message
unit1.pas(85,1) Fatal: Syntax error, "BEGIN" expected but "identifier GENERIC" found
So I think the compiler doesn't support that yet, since I copied that from another forum post.
I have an idea where I pass in an array of strings naming hash functions and it returns the hashes, like so:
var
hashes: Array of String[1..2];
begin
hashes[1] = 'SHA256';
hashes[2] = 'SHA1';
ComputeFileHashes(EdFileName.FileName, hashes);
EdSHA256.Text := hashes[1];
EdSHA1.Text := hashes[2];
end;
Do you think this is bad design (because a function parameter is used as input as well as output)?
P.S.: Would you recommend HashLib4Pascal over what I am currently using (DCPCrypt)?