SHA512/384 Fingerprint and FileFingerprint

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

Code is updated in the first post for consistency. I like the new procedure. I tried to avoid the string functions in the 32bit version but it's in PB code and uses a string in a datasection that starts at the left side of the monitor and goes to the other side of the room. It's better than all the string functions but without line continuations it's kind of unwieldy. I'll study what you've done there and see if I can come up with something similar.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

In the HexBytes procedure, does it need the second push of edi?
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: SHA512/384 Fingerprint and FileFingerprint

Post by wilbert »

Thanks for updating Netmaestro.
In simple words, what the procedure does, is first split the two nibbles (a nibble is 4 bits) of a byte into two separate bytes so you have two bytes with a value from 0x0 to 0xf.
After the OR 0x3030 both bytes contain a value from 0x30 to 0x3f. Now 0 - 9 already have the proper ascii code but after 9 comes the colon character (:) instead of a.
So you check if both bytes are below that value and if not add an extra offset. With a different offset to add, you could create an uppercase output.
The second push of edi is popped as eax so the return value is the same as the output buffer address that is supplied to the function. That way the result can immediately be used for the PeekS function.
The Ascii parameter for the PeekS function is so it works both with the unicode setting on or off.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: SHA512/384 Fingerprint and FileFingerprint

Post by electrochrisso »

Hi NM, I get an illegal instruction. (executing binary data?) in with your latest update, when I use your test example. :(
Line 400... sha512_process( *ctx, @*ctx\buffer[0] )
PureBasic! Purely the best 8)
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: SHA512/384 Fingerprint and FileFingerprint

Post by Thorium »

electrochrisso wrote:Hi NM, I get an illegal instruction. (executing binary data?) in with your latest update, when I use your test example. :(
Line 400... sha512_process( *ctx, @*ctx\buffer[0] )
Whats your CPU?
It seems that is does not support one or more used instructions.

Time to specify CPU requirements.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

This one uses SSE, that could be it.
BERESHEIT
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: SHA512/384 Fingerprint and FileFingerprint

Post by electrochrisso »

Whats your CPU?
It seems that is does not support one or more used instructions.
Intel Atom N550 quadcore, 64bit but running on 32bit win7 Starter.
I will have a look into and see what this processor is missing, since it is fairly late model.
I will check out the SSE, what do I have to change if this is the case. :?:
PureBasic! Purely the best 8)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: SHA512/384 Fingerprint and FileFingerprint

Post by wilbert »

SSE2 was introduced by Intel in 2001 and AMD added support for it in 2003.
Since most people don't have a computer that old, it's not very likely not to have SSE2 support.
Your Atom does support SSE2 (also SSE3 and SSSE3) so that shouldn't be the problem.
What PureBasic version are you using ?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

Also, if you're on Windows, I have a compiled gui in the applications section called "HashSlinger". If these codes won't compile, you could see if the already compiled version will run or not.

One thing I can say about these discussions in the last days, I'm left thirsting for a better processor than my 1.8ghz Intel E2160. Maybe an I5 or so. I've never been a customer for the "very best".
BERESHEIT
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: SHA512/384 Fingerprint and FileFingerprint

Post by electrochrisso »

Sorry :oops: , I gave you the wrong computer, it is an AMD1800xp mobile processor, which is getting a bit old in the tooth, so this is probably the problem. I will test on my other computers.
PureBasic! Purely the best 8)
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: SHA512/384 Fingerprint and FileFingerprint

Post by wilbert »

You can check

Code: Select all

Procedure SupportsSSE2()
  !mov eax, 1
  !cpuid
  !xor eax, eax
  !bt edx, 26
  !rcl eax, 1
  ProcedureReturn
EndProcedure

Debug SupportsSSE2()
The SHA256/224 procedures from Netmaestro only need SSE if I'm correct and should be easy to adapt to work with MMX.
You could consider those if SHA256/224 is enough for you.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: SHA512/384 Fingerprint and FileFingerprint

Post by electrochrisso »

Hi wilbert, NM. Checked the processor out and it dosen't even have SSE at all :shock: , but does have the MMX though so I might play and see if I can adapt for fun. :)
I am only playing around with this stuff so if I need I just use 256/224 to be most computable as possible.
Thanks.
PureBasic! Purely the best 8)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

You won't have any luck with the 512/384 version but the 256/224 version only uses the SSE registers, not the commandset. You could change all xmm0-7 to mm0-7 then add !emms to the bottom of the process procedure and it should work.
BERESHEIT
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: SHA512/384 Fingerprint and FileFingerprint

Post by wilbert »

Netmaestro is right and it will only take a minute or so to make the changes.
You can simply do a search and replace to replace all xmm with mm and add the emms instruction Netmaestro mentioned.
There doesn't seem to be a significant decrease in speed so it should still be very fast. :)
For 512/384 this unfortunately isn't possible since it needs the SSE2 functionality.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: SHA512/384 Fingerprint and FileFingerprint

Post by netmaestro »

netmaestro wrote:One thing I can say about these discussions in the last days, I'm left thirsting for a better processor than my 1.8ghz Intel E2160
I never say something like this and then nothing happens very soon. Two years ago my son's computer died and I gave him mine so he could continue his remarkably unproductive lifestyle. I didn't have much money so I bought myself a Compaq SR5410F from the phone company (where is the eyerolling smiley when you need it!) and it had the Intel E2160 processor in it and the crappiest motherboard I've ever seen. If you type the part number of that mb into google you get 75 results of emus taking a dump. Well, it was on sale. Anyway I went shopping today and avoided the phone company. I bought an AMD Phenom II Black Edition processor with two real cores running at 3.2 ghz and an ASUS AM3 mobo with 2g (to start) DDR3 ram. Windows wouldn't run on it of course, and so I had to reinstall W7 and then all was good. I don't know why Windows can't just detect that the settings for devices have changed and then make the appropriate adjustments. New MB and proc, you have to reinstall the whole thing. End result, everything across the board runs approx. twice as fast. 1.8ghz->3.2ghz, 1mb cache->7mb cache, it has to make a difference. And last but not least, my king of the farm alpha male cat had something to sit and watch for an hour while I removed/installed components. 37 mice this summer and counting, he's a force of nature. And so is Purebasic :!:
BERESHEIT
Post Reply