Jump to content




SHA-256 in Pure Lua

utility lua api

66 replies to this topic

#61 LoganDark

  • Members
  • 231 posts
  • LocationMacintosh HD/Users/LoganDark

Posted 29 March 2016 - 02:24 PM

View PostAnavrins, on 29 March 2016 - 02:23 PM, said:

View PostLoganDark, on 29 March 2016 - 02:03 PM, said:

View PostAnavrins, on 19 February 2016 - 09:41 PM, said:

I ended up making my own take at implementing SHA256 in Lua and ended up being around 15x faster.
With some rough speed test I could only get up to 105 hash/sec, my implementation was able to get to 1500 hash/sec.
It's still not much compared to say, gpus, but it's quite something for CC.
I also noticed the same thing as Shazz, that any input that's (64*n)+55 bytes in length will produce the incorrect hash, I didn't go deep into the problem, but I know it's the pre-processing part that produces an incorrect padding.
That bug is not present in my implementation.
Here's the pastebin: 6UV4qfNF
Posted Image
It seems I'm having a little bit of an error trying to run your SHA algorithm after having an upcoming project of mine mostly finished.

Edit: just using sha256("msg")
What CC version are you using, this implies that your using an older version of CC which does not contain bit32.
In any case you can replace the bit32 parts with bit, though I haven't tested it.
Yeah, I bet Mimic is using a different version.

Edit: bit doesn't have a bad lshift
edit 2: I'll copy the functions from the bit32 API and put them in your hashing function. It should fix issues with older versions.
edit 3: not needed, bit does have a blshift but not an lshift. :P
edit 4: too long without yielding

Edit 5: I'm using the original API because it works on older versions. It may not be as fast, but that's the compromise you have to make when nobody considers the older versions...

Edited by LoganDark, 29 March 2016 - 02:36 PM.


#62 Anavrins

  • Members
  • 775 posts

Posted 29 March 2016 - 02:41 PM

View PostLoganDark, on 29 March 2016 - 02:24 PM, said:

Yeah, I bet Mimic is using a different version.
Edit: bit doesn't have a bad lshift
Ah yes, as much as I appreciate the work of it's dev, I find that mimic has a lot of issues.
There's nothing wrong with lshift, but definitely with rshift, with number approaching 2^32, I could only get correct results with my own implementation of it.
I ended up modifying the code so that it automatically uses bit if bit32 is not found, it's on the same pastebin link.
If you're getting too long without ending, it's probably your own code, I've tested it working up to inputs of 100000 in length without crashing, just make sure your input isn't this big :P

Edited by Anavrins, 29 March 2016 - 02:50 PM.


#63 LoganDark

  • Members
  • 231 posts
  • LocationMacintosh HD/Users/LoganDark

Posted 29 March 2016 - 02:49 PM

View PostAnavrins, on 29 March 2016 - 02:41 PM, said:

View PostLoganDark, on 29 March 2016 - 02:24 PM, said:

Yeah, I bet Mimic is using a different version.
Edit: bit doesn't have a bad lshift
Ah yes, as much as I appreciate the work of it's dev, I find that mimic has a lot of issues.
There's nothing wrong with lshift, but definitely with rshift, with number approaching 2^32, I could only get correct results with my own implementation of it.
I ended up modifying the code so that it automatically uses bit if bit32 is not found, it's on the same pastebin link.

Well, that won't be a problem unless someone creates an extremely long password.

#64 Anavrins

  • Members
  • 775 posts

Posted 29 March 2016 - 03:03 PM

View PostLoganDark, on 29 March 2016 - 02:49 PM, said:

Well, that won't be a problem unless someone creates an extremely long password.
It's not a problem because I'm simply not using it, so you can have passwords as long as you'd like.
Hash functions aren't only made for passwords, if I ever wanted to hash something that contained
a lot of 0xFF, bit.brshift would end up dealing with 0xFFFFFFFF, which is 2^32-1, and would break.
All in all, I was still definitely getting wrong results even when hashing just one letter, so better keep my brshift in there :P

Edited by Anavrins, 29 March 2016 - 03:10 PM.


#65 Waitdev_

  • Members
  • 432 posts
  • LocationWherever you want me to be

Posted 17 May 2016 - 12:06 PM

It's so awesome that you made this, do you mind if i put this in my new program? I've given you a bit of credit and put a link to this thread, is there anything else that you want me to do or is it fine the way I've done it? Thanks.

#66 LoganDark

  • Members
  • 231 posts
  • LocationMacintosh HD/Users/LoganDark

Posted 17 May 2016 - 05:22 PM

View PostWaitdev_, on 17 May 2016 - 12:06 PM, said:

It's so awesome that you made this, do you mind if i put this in my new program? I've given you a bit of credit and put a link to this thread, is there anything else that you want me to do or is it fine the way I've done it? Thanks.

I'm sure he won't mind. I've used it in the first, second and third versions of my password lock with no problem. ( ͡° ͜ʖ ͡°)

#67 Anavrins

  • Members
  • 775 posts

Posted 17 May 2016 - 06:12 PM

View PostWaitdev_, on 17 May 2016 - 12:06 PM, said:

It's so awesome that you made this, do you mind if i put this in my new program? I've given you a bit of credit and put a link to this thread, is there anything else that you want me to do or is it fine the way I've done it? Thanks.
If you're talking about my implementation, then sure, just keep the comment at the top and that should be fine :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users