I designed this add-on library (LibLoad compatible) to fulfill any need for cryptography that may arise.
The library has 5 cryptographic-ish functions:

hashlib_Checksum24()
hashlib_Checksum32()
hashlib_CRC32()
hashlib_SHA1()
hashlib_SHA256()

The first two are generic additive checksums, the first being 24 bit and the second being 32 bit.
The third is the same CRC algorithm I used in Blast, and used to use in VAPOR.
The last two are SHA1 and SHA256. I tested them against multiple programs and input strings and thus far they appear to be bug-less, but I suppose that merely means I didn't try hard enough.
PS: I wrote this in C, then poked through the asm and converted the syntax as needed for the toolchain.
Thanks to beckadamtheinventor for some asm magic to help me do some psuedo-64-bit enumeration as needed for the bitwidth fields.
Thanks for commandz for walking me through the process for compatibility with LibLoad.

Edit: I will post a link once it gets approved to cemetech archives
This kind of contradicts many cryptography libraries out there which allow you to pass chunks of data as it is streamed across. But neat Smile
MateoConLechuga wrote:
This kind of contradicts many cryptography libraries out there which allow you to pass chunks of data as it is streamed across. But neat Smile

I could support that by exposing the underlying functions, such as sha*_update.
The hash isn't actually rendered until you call sha*_final, so presumably if I allow the users to call those particular functions, it would be more portable. Perhaps I'll do that.
This seem very reasonable as more programs start to implement USB Serial and internet libraries privacy and encryption will be needed. Great Idea Razz
File has been submitted to the archives.

I have gone ahead and exposed the backend routines that the main ones use to compile the SHA*

They are as follows:
hashlib_sha1init
hashlib_sha1update
hashlib_sha1final

The init function takes a SHA-1 context structure as an argument and initializes it to appropriate starting values.
Init must always be called if you plan to use the other two, but if you use the main SHA1 function, it is done for you.
The update function takes the context, the segment size, and length, and updates the context.
The final function takes the context and a digest buffer and generates the hash.

The SHA256 function has a similar group of backend functions also exposed.
hashlib_sha256init
hashlib_sha256update
hashlib_sha256final

They do the same as their SHA1 counterparts.

Edit: for the record, i snagged an open-source implementation of the SHA routines and modified them to work on the CE. Sadly, to not break the hashes, much of the values needed to be uint32, and for the bit-width, I enlisted beck's help devising a psuedo 'uint64_t` implementation.

And then I spent 3 hours trying to figure out why the SHA256 was not coming out right, only to realize, 3 hours later that the routine used variables that were defined in TI's headers as tokens. 3 hours wasted... for a simple fix. Sigh.
I realize that I haven't shared much of an update on what's going on with this project lately so here it is.

beckadamtheinventor (bless his soul for the pain it's brought him lol) offered to do a rewrite of HASHLIB in assembly. The original was coded in C, based on B-Con's Crypto algorithms which is public domain. I modified the original code to be tailored to a 24-bit architecture, then compiled, formatted the assembly, and created the lib. I did this because my experience with assembly is practically non-existent. The downside was it was quite unoptimized.

For HASHLIB 2 (and later 3), the plan is to rewrite the routines in assembly, a process primarily being undertaken by BECK, with me performing some testing/debugging assistance. In addition we have plans to add another fun and proof-of-concept, but kind of useless feature to HASHLIB... RSA. The library will be able to generate RSA keys of 64-, 128-, or 256-bit length and use those keys to encrypt and decrypt data. It would do this by initializing a context, one for the private key (generated locally and used for encryption) and another for the public key (generated by some remote host and sent to the calculator, and used for decryption).

We did encounter a setback... the assembly SHA-1 algorithm was buggy and we still have not been able to resolve it. At first, I thought the issue may have been a SRLDRVCE bug since VAPOR crashed as soon as it tried to initiate a transfer. However, upon using the debugger, I realized that the crash occurred in the usb_handleEvents function after the first call to hashlib_sha1final. I also realized that the serial state was corrupt at this point and that the serial memory happened to be right after the sha1 output buffer in memory. This lead to the theory that sha1final was overflowing the digest buffer (the hash output was wrong as well which reenforced this theory) and corrupting the serial state which was after it. I passed this info to beck and command who eventually identified the culprit as sha1_update (or transform, not quite sure) in the assembly version. However, they were unable to figure out *why* the code was breaking.

On the topic of RSA, I have some questions regarding on-calc applications
What would be the fastest way to generate a prime number in a range?
Is Miller-Rabin the fastest primality test?
Would pairing calls to MR Primality test with calls to rand be the most effective implementation of a prime number generator?
Any assembly optimizations?
Update

No downloads yet, but I did complete the RSA algorithm in C.
It's a 64-bit implementation (each key is 64 bits long). Not cryptographically secure, I know, but this IS a calculator, and this is more a learning exercise for me.

The implementation can be found at: https://github.com/acagliano/hashlib-ce/blob/rsa/src/main.c#L404
Unlike some of the other things in the code here that are modified variants of public-domain algorithms, the code for the RSA bit I did myself (albeit relying on some pseudocode and algorithm explanations).

To sum:

# KeyGen #
<> Pick 2 random 16-bit primes, using randInt()
** If someone can suggest a randOddInt() implementation that would allow me to skip the first primality check (is odd?), I'll use it**
<> To verify primality:
<> check if divisible by 2
<> run 3 iterations of Miller-Rabin primality test. If all 3 return true, we accept the random prime
<> Calculate the key segments from the two primes
(Right now, I used 16-bit primes to stick within the uint32_t maximum integer range of the toolchain for each key segment. If support for larger numbers is added to either the toolchain or a library, I will adapt this code accordingly)
<> Used a modular exponentiation algorithm within Miller-Rabin as well as within Encrypt/Decrypt. (credit to beck for sending me info on that)
<> Used euclidean GCD algorithm for getting value of E (in keygen)
Update

This morning, I was running some randomness tests on the outputs of the CSPRNG I wrote for HASHLIB, on the output from CEmu, my Revision A and N calculators, and am still waiting on Revision L output from beck to test. I'll edit this post with more data when I receive it, but here's the tests so far. Apparently, not *perfect*, but pretty good.

FOR CEmu

Code:
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.09223278|  PASSED 
      diehard_operm5|   0|   1000000|     100|0.66870513|  PASSED 
  diehard_rank_32x32|   0|     40000|     100|0.09845641|  PASSED 
    diehard_rank_6x8|   0|    100000|     100|0.82620303|  PASSED 
   diehard_bitstream|   0|   2097152|     100|0.95994734|  PASSED 
        diehard_opso|   0|   2097152|     100|0.19697702|  PASSED 
        diehard_oqso|   0|   2097152|     100|0.35516172|  PASSED 
         diehard_dna|   0|   2097152|     100|0.14587179|  PASSED 
diehard_count_1s_str|   0|    256000|     100|0.68887947|  PASSED 
diehard_count_1s_byt|   0|    256000|     100|0.95972962|  PASSED 
 diehard_parking_lot|   0|     12000|     100|0.92308018|  PASSED 
    diehard_2dsphere|   2|      8000|     100|0.48625765|  PASSED 
    diehard_3dsphere|   3|      4000|     100|0.58272406|  PASSED 
     diehard_squeeze|   0|    100000|     100|0.99879350|   WEAK   
        diehard_sums|   0|       100|     100|0.44627543|  PASSED 
        diehard_runs|   0|    100000|     100|0.56501584|  PASSED 
        diehard_runs|   0|    100000|     100|0.42191409|  PASSED 
       diehard_craps|   0|    200000|     100|0.24492888|  PASSED 
       diehard_craps|   0|    200000|     100|0.82153686|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.41813999|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.16655827|  PASSED 
         sts_monobit|   1|    100000|     100|0.59591146|  PASSED 
            sts_runs|   2|    100000|     100|0.94356113|  PASSED 
          sts_serial|   1|    100000|     100|0.27710764|  PASSED 
          sts_serial|   2|    100000|     100|0.22237289|  PASSED 
          sts_serial|   3|    100000|     100|0.60387847|  PASSED 
          sts_serial|   3|    100000|     100|0.93221943|  PASSED 
          sts_serial|   4|    100000|     100|0.07090047|  PASSED 
          sts_serial|   4|    100000|     100|0.49396776|  PASSED 
          sts_serial|   5|    100000|     100|0.85157412|  PASSED 
          sts_serial|   5|    100000|     100|0.09812131|  PASSED 
          sts_serial|   6|    100000|     100|0.92521083|  PASSED 
          sts_serial|   6|    100000|     100|0.95430095|  PASSED 
          sts_serial|   7|    100000|     100|0.17341842|  PASSED 
          sts_serial|   7|    100000|     100|0.06464828|  PASSED 
          sts_serial|   8|    100000|     100|0.02343196|  PASSED 
          sts_serial|   8|    100000|     100|0.48271224|  PASSED 
          sts_serial|   9|    100000|     100|0.69836370|  PASSED 
          sts_serial|   9|    100000|     100|0.37271655|  PASSED 
          sts_serial|  10|    100000|     100|0.09107878|  PASSED 
          sts_serial|  10|    100000|     100|0.26137588|  PASSED 
          sts_serial|  11|    100000|     100|0.31273920|  PASSED 
          sts_serial|  11|    100000|     100|0.03748493|  PASSED 
          sts_serial|  12|    100000|     100|0.77757010|  PASSED 
          sts_serial|  12|    100000|     100|0.99515661|   WEAK   
          sts_serial|  13|    100000|     100|0.29102832|  PASSED 
          sts_serial|  13|    100000|     100|0.76912823|  PASSED 
          sts_serial|  14|    100000|     100|0.97972613|  PASSED 
          sts_serial|  14|    100000|     100|0.13936869|  PASSED 
          sts_serial|  15|    100000|     100|0.90970655|  PASSED 
          sts_serial|  15|    100000|     100|0.60189076|  PASSED 
          sts_serial|  16|    100000|     100|0.57431165|  PASSED 
          sts_serial|  16|    100000|     100|0.33760047|  PASSED 
         rgb_bitdist|   1|    100000|     100|0.25826243|  PASSED 
         rgb_bitdist|   2|    100000|     100|0.83838634|  PASSED 
         rgb_bitdist|   3|    100000|     100|0.69601893|  PASSED 
         rgb_bitdist|   4|    100000|     100|0.40179839|  PASSED 
         rgb_bitdist|   5|    100000|     100|0.88202950|  PASSED 
         rgb_bitdist|   6|    100000|     100|0.29559829|  PASSED 
         rgb_bitdist|   7|    100000|     100|0.50023327|  PASSED 
         rgb_bitdist|   8|    100000|     100|0.93939254|  PASSED 
         rgb_bitdist|   9|    100000|     100|0.57173326|  PASSED 
         rgb_bitdist|  10|    100000|     100|0.93600681|  PASSED 
         rgb_bitdist|  11|    100000|     100|0.68395627|  PASSED 
         rgb_bitdist|  12|    100000|     100|0.85837344|  PASSED 
rgb_minimum_distance|   2|     10000|    1000|0.02434412|  PASSED 
rgb_minimum_distance|   3|     10000|    1000|0.90176261|  PASSED 
rgb_minimum_distance|   4|     10000|    1000|0.99559799|   WEAK   
rgb_minimum_distance|   5|     10000|    1000|0.43643317|  PASSED 
    rgb_permutations|   2|    100000|     100|0.73755753|  PASSED 
    rgb_permutations|   3|    100000|     100|0.82537474|  PASSED 
    rgb_permutations|   4|    100000|     100|0.99722403|   WEAK   
    rgb_permutations|   5|    100000|     100|0.95358345|  PASSED 
      rgb_lagged_sum|   0|   1000000|     100|0.45759411|  PASSED 
      rgb_lagged_sum|   1|   1000000|     100|0.97173659|  PASSED 
      rgb_lagged_sum|   2|   1000000|     100|0.65774916|  PASSED 
      rgb_lagged_sum|   3|   1000000|     100|0.08431299|  PASSED 
      rgb_lagged_sum|   4|   1000000|     100|0.10083451|  PASSED 
      rgb_lagged_sum|   5|   1000000|     100|0.16441504|  PASSED 
      rgb_lagged_sum|   6|   1000000|     100|0.13463836|  PASSED 
      rgb_lagged_sum|   7|   1000000|     100|0.96608845|  PASSED 
      rgb_lagged_sum|   8|   1000000|     100|0.99281780|  PASSED 
      rgb_lagged_sum|   9|   1000000|     100|0.26141949|  PASSED 
      rgb_lagged_sum|  10|   1000000|     100|0.22627580|  PASSED 
      rgb_lagged_sum|  11|   1000000|     100|0.57940025|  PASSED 
      rgb_lagged_sum|  12|   1000000|     100|0.86760642|  PASSED 
      rgb_lagged_sum|  13|   1000000|     100|0.14726270|  PASSED 
      rgb_lagged_sum|  14|   1000000|     100|0.20203833|  PASSED 
      rgb_lagged_sum|  15|   1000000|     100|0.64306777|  PASSED 
      rgb_lagged_sum|  16|   1000000|     100|0.44349544|  PASSED 
      rgb_lagged_sum|  17|   1000000|     100|0.92797768|  PASSED 
      rgb_lagged_sum|  18|   1000000|     100|0.20410685|  PASSED 
      rgb_lagged_sum|  19|   1000000|     100|0.39539771|  PASSED 
      rgb_lagged_sum|  20|   1000000|     100|0.23093122|  PASSED 
      rgb_lagged_sum|  21|   1000000|     100|0.08507095|  PASSED 
      rgb_lagged_sum|  22|   1000000|     100|0.81748111|  PASSED 
      rgb_lagged_sum|  23|   1000000|     100|0.23791417|  PASSED 
      rgb_lagged_sum|  24|   1000000|     100|0.88737464|  PASSED 
      rgb_lagged_sum|  25|   1000000|     100|0.99309479|  PASSED 
      rgb_lagged_sum|  26|   1000000|     100|0.94429862|  PASSED 
      rgb_lagged_sum|  27|   1000000|     100|0.68425557|  PASSED 
      rgb_lagged_sum|  28|   1000000|     100|0.32645801|  PASSED 
      rgb_lagged_sum|  29|   1000000|     100|0.95226953|  PASSED 
      rgb_lagged_sum|  30|   1000000|     100|0.99497672|  PASSED 
      rgb_lagged_sum|  31|   1000000|     100|0.74729721|  PASSED 
      rgb_lagged_sum|  32|   1000000|     100|0.94854865|  PASSED 
     rgb_kstest_test|   0|     10000|    1000|0.71619495|  PASSED 
     dab_bytedistrib|   0|  51200000|       1|0.79373016|  PASSED 
             dab_dct| 256|     50000|       1|0.15973202|  PASSED 
Preparing to run test 207.  ntuple = 0
        dab_filltree|  32|  15000000|       1|0.81659075|  PASSED 
        dab_filltree|  32|  15000000|       1|0.67758100|  PASSED 
Preparing to run test 208.  ntuple = 0
       dab_filltree2|   0|   5000000|       1|0.97836744|  PASSED 
       dab_filltree2|   1|   5000000|       1|0.60753519|  PASSED 
Preparing to run test 209.  ntuple = 0
        dab_monobit2|  12|  65000000|       1|0.02189835|  PASSED 


FOR REV-A

Code:
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.52826567|  PASSED 
      diehard_operm5|   0|   1000000|     100|0.89680879|  PASSED 
  diehard_rank_32x32|   0|     40000|     100|0.33733993|  PASSED 
    diehard_rank_6x8|   0|    100000|     100|0.04026007|  PASSED 
   diehard_bitstream|   0|   2097152|     100|0.35586935|  PASSED 
        diehard_opso|   0|   2097152|     100|0.98975628|  PASSED 
        diehard_oqso|   0|   2097152|     100|0.26335265|  PASSED 
         diehard_dna|   0|   2097152|     100|0.64711525|  PASSED 
diehard_count_1s_str|   0|    256000|     100|0.80132203|  PASSED 
diehard_count_1s_byt|   0|    256000|     100|0.69913004|  PASSED 
 diehard_parking_lot|   0|     12000|     100|0.69592283|  PASSED 
    diehard_2dsphere|   2|      8000|     100|0.73077983|  PASSED 
    diehard_3dsphere|   3|      4000|     100|0.17651491|  PASSED 
     diehard_squeeze|   0|    100000|     100|0.21230553|  PASSED 
        diehard_sums|   0|       100|     100|0.00217425|   WEAK   
        diehard_runs|   0|    100000|     100|0.74021085|  PASSED 
        diehard_runs|   0|    100000|     100|0.01051619|  PASSED 
       diehard_craps|   0|    200000|     100|0.44749130|  PASSED 
       diehard_craps|   0|    200000|     100|0.35308338|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.27927791|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.14110196|  PASSED 
         sts_monobit|   1|    100000|     100|0.57903662|  PASSED 
            sts_runs|   2|    100000|     100|0.98097300|  PASSED 
          sts_serial|   1|    100000|     100|0.43461686|  PASSED 
          sts_serial|   2|    100000|     100|0.85471819|  PASSED 
          sts_serial|   3|    100000|     100|0.59710567|  PASSED 
          sts_serial|   3|    100000|     100|0.56125315|  PASSED 
          sts_serial|   4|    100000|     100|0.30084960|  PASSED 
          sts_serial|   4|    100000|     100|0.22481830|  PASSED 
          sts_serial|   5|    100000|     100|0.83146814|  PASSED 
          sts_serial|   5|    100000|     100|0.57193607|  PASSED 
          sts_serial|   6|    100000|     100|0.77664518|  PASSED 
          sts_serial|   6|    100000|     100|0.71604432|  PASSED 
          sts_serial|   7|    100000|     100|0.57278676|  PASSED 
          sts_serial|   7|    100000|     100|0.54849978|  PASSED 
          sts_serial|   8|    100000|     100|0.85994918|  PASSED 
          sts_serial|   8|    100000|     100|0.71933025|  PASSED 
          sts_serial|   9|    100000|     100|0.87137421|  PASSED 
          sts_serial|   9|    100000|     100|0.44681841|  PASSED 
          sts_serial|  10|    100000|     100|0.53493139|  PASSED 
          sts_serial|  10|    100000|     100|0.14734033|  PASSED 
          sts_serial|  11|    100000|     100|0.64018252|  PASSED 
          sts_serial|  11|    100000|     100|0.52667020|  PASSED 
          sts_serial|  12|    100000|     100|0.68721836|  PASSED 
          sts_serial|  12|    100000|     100|0.94913780|  PASSED 
          sts_serial|  13|    100000|     100|0.71315000|  PASSED 
          sts_serial|  13|    100000|     100|0.77345268|  PASSED 
          sts_serial|  14|    100000|     100|0.33325072|  PASSED 
          sts_serial|  14|    100000|     100|0.26571241|  PASSED 
          sts_serial|  15|    100000|     100|0.72725175|  PASSED 
          sts_serial|  15|    100000|     100|0.98956255|  PASSED 
          sts_serial|  16|    100000|     100|0.92207582|  PASSED 
          sts_serial|  16|    100000|     100|0.89467281|  PASSED 
         rgb_bitdist|   1|    100000|     100|0.44890938|  PASSED 
         rgb_bitdist|   2|    100000|     100|0.62308738|  PASSED 
         rgb_bitdist|   3|    100000|     100|0.58317984|  PASSED 
         rgb_bitdist|   4|    100000|     100|0.73614612|  PASSED 
         rgb_bitdist|   5|    100000|     100|0.46870884|  PASSED 
         rgb_bitdist|   6|    100000|     100|0.81817912|  PASSED 
         rgb_bitdist|   7|    100000|     100|0.33991482|  PASSED 
         rgb_bitdist|   8|    100000|     100|0.56492213|  PASSED 
         rgb_bitdist|   9|    100000|     100|0.32162358|  PASSED 
         rgb_bitdist|  10|    100000|     100|0.70469518|  PASSED 
         rgb_bitdist|  11|    100000|     100|0.08159467|  PASSED 
         rgb_bitdist|  12|    100000|     100|0.94699045|  PASSED 
rgb_minimum_distance|   2|     10000|    1000|0.24234084|  PASSED 
rgb_minimum_distance|   3|     10000|    1000|0.12530491|  PASSED 
rgb_minimum_distance|   4|     10000|    1000|0.51070555|  PASSED 
rgb_minimum_distance|   5|     10000|    1000|0.00839232|  PASSED 
    rgb_permutations|   2|    100000|     100|0.56311941|  PASSED 
    rgb_permutations|   3|    100000|     100|0.98995136|  PASSED 
    rgb_permutations|   4|    100000|     100|0.45018921|  PASSED 
    rgb_permutations|   5|    100000|     100|0.95017879|  PASSED 
      rgb_lagged_sum|   0|   1000000|     100|0.97582984|  PASSED 
      rgb_lagged_sum|   1|   1000000|     100|0.44242655|  PASSED 
      rgb_lagged_sum|   2|   1000000|     100|0.74801300|  PASSED 
      rgb_lagged_sum|   3|   1000000|     100|0.18708984|  PASSED 
      rgb_lagged_sum|   4|   1000000|     100|0.69647393|  PASSED 
      rgb_lagged_sum|   5|   1000000|     100|0.12452585|  PASSED 
      rgb_lagged_sum|   6|   1000000|     100|0.09181138|  PASSED 
      rgb_lagged_sum|   7|   1000000|     100|0.64181761|  PASSED 
      rgb_lagged_sum|   8|   1000000|     100|0.67863480|  PASSED 
      rgb_lagged_sum|   9|   1000000|     100|0.83917672|  PASSED 
      rgb_lagged_sum|  10|   1000000|     100|0.09855121|  PASSED 
      rgb_lagged_sum|  11|   1000000|     100|0.61024553|  PASSED 
      rgb_lagged_sum|  12|   1000000|     100|0.98748978|  PASSED 
      rgb_lagged_sum|  13|   1000000|     100|0.62979153|  PASSED 
      rgb_lagged_sum|  14|   1000000|     100|0.01409243|  PASSED 
      rgb_lagged_sum|  15|   1000000|     100|0.62056489|  PASSED 
      rgb_lagged_sum|  16|   1000000|     100|0.51760746|  PASSED 
      rgb_lagged_sum|  17|   1000000|     100|0.46860864|  PASSED 
      rgb_lagged_sum|  18|   1000000|     100|0.47769885|  PASSED 
      rgb_lagged_sum|  19|   1000000|     100|0.29647131|  PASSED 
      rgb_lagged_sum|  20|   1000000|     100|0.49490047|  PASSED 
      rgb_lagged_sum|  21|   1000000|     100|0.14434106|  PASSED 
      rgb_lagged_sum|  22|   1000000|     100|0.84185980|  PASSED 
      rgb_lagged_sum|  23|   1000000|     100|0.54392810|  PASSED 
      rgb_lagged_sum|  24|   1000000|     100|0.73818172|  PASSED 
      rgb_lagged_sum|  25|   1000000|     100|0.06957809|  PASSED 
      rgb_lagged_sum|  26|   1000000|     100|0.66698737|  PASSED 
      rgb_lagged_sum|  27|   1000000|     100|0.57722664|  PASSED 
      rgb_lagged_sum|  28|   1000000|     100|0.53116536|  PASSED 
      rgb_lagged_sum|  29|   1000000|     100|0.91131710|  PASSED 
      rgb_lagged_sum|  30|   1000000|     100|0.94758006|  PASSED 
      rgb_lagged_sum|  31|   1000000|     100|0.90318305|  PASSED 
      rgb_lagged_sum|  32|   1000000|     100|0.10337558|  PASSED 
     rgb_kstest_test|   0|     10000|    1000|0.00155495|   WEAK   
     dab_bytedistrib|   0|  51200000|       1|0.76888236|  PASSED 
             dab_dct| 256|     50000|       1|0.32284072|  PASSED 
Preparing to run test 207.  ntuple = 0
        dab_filltree|  32|  15000000|       1|0.60387054|  PASSED 
        dab_filltree|  32|  15000000|       1|0.58083051|  PASSED 
Preparing to run test 208.  ntuple = 0
       dab_filltree2|   0|   5000000|       1|0.56558917|  PASSED 
       dab_filltree2|   1|   5000000|       1|0.65817936|  PASSED 
Preparing to run test 209.  ntuple = 0
        dab_monobit2|  12|  65000000|       1|0.90787990|  PASSED 


FOR REV-L

Code:
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.90302783|  PASSED 
      diehard_operm5|   0|   1000000|     100|0.91316636|  PASSED 
  diehard_rank_32x32|   0|     40000|     100|0.98299195|  PASSED 
    diehard_rank_6x8|   0|    100000|     100|0.61654944|  PASSED 
   diehard_bitstream|   0|   2097152|     100|0.97689617|  PASSED 
        diehard_opso|   0|   2097152|     100|0.16253769|  PASSED 
        diehard_oqso|   0|   2097152|     100|0.44901944|  PASSED 
         diehard_dna|   0|   2097152|     100|0.69537380|  PASSED 
diehard_count_1s_str|   0|    256000|     100|0.34210418|  PASSED 
diehard_count_1s_byt|   0|    256000|     100|0.96672342|  PASSED 
 diehard_parking_lot|   0|     12000|     100|0.06065386|  PASSED 
    diehard_2dsphere|   2|      8000|     100|0.80511237|  PASSED 
    diehard_3dsphere|   3|      4000|     100|0.32131023|  PASSED 
     diehard_squeeze|   0|    100000|     100|0.03276551|  PASSED 
        diehard_sums|   0|       100|     100|0.87019459|  PASSED 
        diehard_runs|   0|    100000|     100|0.61639409|  PASSED 
        diehard_runs|   0|    100000|     100|0.57322187|  PASSED 
       diehard_craps|   0|    200000|     100|0.36906683|  PASSED 
       diehard_craps|   0|    200000|     100|0.11780949|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.01486475|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.90807808|  PASSED 
         sts_monobit|   1|    100000|     100|0.68787414|  PASSED 
            sts_runs|   2|    100000|     100|0.05025451|  PASSED 
          sts_serial|   1|    100000|     100|0.74280256|  PASSED 
          sts_serial|   2|    100000|     100|0.47240578|  PASSED 
          sts_serial|   3|    100000|     100|0.77165073|  PASSED 
          sts_serial|   3|    100000|     100|0.62963874|  PASSED 
          sts_serial|   4|    100000|     100|0.31811962|  PASSED 
          sts_serial|   4|    100000|     100|0.32315923|  PASSED 
          sts_serial|   5|    100000|     100|0.68745473|  PASSED 
          sts_serial|   5|    100000|     100|0.59115816|  PASSED 
          sts_serial|   6|    100000|     100|0.93796174|  PASSED 
          sts_serial|   6|    100000|     100|0.85337173|  PASSED 
          sts_serial|   7|    100000|     100|0.80262973|  PASSED 
          sts_serial|   7|    100000|     100|0.88277652|  PASSED 
          sts_serial|   8|    100000|     100|0.43168456|  PASSED 
          sts_serial|   8|    100000|     100|0.64914768|  PASSED 
          sts_serial|   9|    100000|     100|0.34521339|  PASSED 
          sts_serial|   9|    100000|     100|0.25991848|  PASSED 
          sts_serial|  10|    100000|     100|0.25189174|  PASSED 
          sts_serial|  10|    100000|     100|0.03437041|  PASSED 
          sts_serial|  11|    100000|     100|0.45031731|  PASSED 
          sts_serial|  11|    100000|     100|0.83956230|  PASSED 
          sts_serial|  12|    100000|     100|0.33883843|  PASSED 
          sts_serial|  12|    100000|     100|0.05518900|  PASSED 
          sts_serial|  13|    100000|     100|0.25892920|  PASSED 
          sts_serial|  13|    100000|     100|0.58016137|  PASSED 
          sts_serial|  14|    100000|     100|0.74370871|  PASSED 
          sts_serial|  14|    100000|     100|0.45347258|  PASSED 
          sts_serial|  15|    100000|     100|0.67668889|  PASSED 
          sts_serial|  15|    100000|     100|0.89040261|  PASSED 
          sts_serial|  16|    100000|     100|0.48409750|  PASSED 
          sts_serial|  16|    100000|     100|0.61891912|  PASSED 
         rgb_bitdist|   1|    100000|     100|0.92602371|  PASSED 
         rgb_bitdist|   2|    100000|     100|0.82137217|  PASSED 
         rgb_bitdist|   3|    100000|     100|0.07593271|  PASSED 
         rgb_bitdist|   4|    100000|     100|0.92959023|  PASSED 
         rgb_bitdist|   5|    100000|     100|0.96431070|  PASSED 
         rgb_bitdist|   6|    100000|     100|0.52137938|  PASSED 
         rgb_bitdist|   7|    100000|     100|0.86755828|  PASSED 
         rgb_bitdist|   8|    100000|     100|0.57921528|  PASSED 
         rgb_bitdist|   9|    100000|     100|0.85938201|  PASSED 
         rgb_bitdist|  10|    100000|     100|0.97528207|  PASSED 
         rgb_bitdist|  11|    100000|     100|0.38854502|  PASSED 
         rgb_bitdist|  12|    100000|     100|0.98614299|  PASSED 
rgb_minimum_distance|   2|     10000|    1000|0.04211185|  PASSED 
rgb_minimum_distance|   3|     10000|    1000|0.47508623|  PASSED 
rgb_minimum_distance|   4|     10000|    1000|0.58058505|  PASSED 
rgb_minimum_distance|   5|     10000|    1000|0.67666040|  PASSED 
    rgb_permutations|   2|    100000|     100|0.98386868|  PASSED 
    rgb_permutations|   3|    100000|     100|0.61295734|  PASSED 
    rgb_permutations|   4|    100000|     100|0.66420216|  PASSED 
    rgb_permutations|   5|    100000|     100|0.98544271|  PASSED 
      rgb_lagged_sum|   0|   1000000|     100|0.57857486|  PASSED 
      rgb_lagged_sum|   1|   1000000|     100|0.50542033|  PASSED 
      rgb_lagged_sum|   2|   1000000|     100|0.02640993|  PASSED 
      rgb_lagged_sum|   3|   1000000|     100|0.46042419|  PASSED 
      rgb_lagged_sum|   4|   1000000|     100|0.56821565|  PASSED 
      rgb_lagged_sum|   5|   1000000|     100|0.91279891|  PASSED 
      rgb_lagged_sum|   6|   1000000|     100|0.71775495|  PASSED 
      rgb_lagged_sum|   7|   1000000|     100|0.84934891|  PASSED 
      rgb_lagged_sum|   8|   1000000|     100|0.92054147|  PASSED 
      rgb_lagged_sum|   9|   1000000|     100|0.32272457|  PASSED 
      rgb_lagged_sum|  10|   1000000|     100|0.06448251|  PASSED 
      rgb_lagged_sum|  11|   1000000|     100|0.89572697|  PASSED 
      rgb_lagged_sum|  12|   1000000|     100|0.53075418|  PASSED 
      rgb_lagged_sum|  13|   1000000|     100|0.95861533|  PASSED 
      rgb_lagged_sum|  14|   1000000|     100|0.99144924|  PASSED 
      rgb_lagged_sum|  15|   1000000|     100|0.80814765|  PASSED 
      rgb_lagged_sum|  16|   1000000|     100|0.24132123|  PASSED 
      rgb_lagged_sum|  17|   1000000|     100|0.47093788|  PASSED 
      rgb_lagged_sum|  18|   1000000|     100|0.72779033|  PASSED 
      rgb_lagged_sum|  19|   1000000|     100|0.78539970|  PASSED 
      rgb_lagged_sum|  20|   1000000|     100|0.88071791|  PASSED 
      rgb_lagged_sum|  21|   1000000|     100|0.76316183|  PASSED 
      rgb_lagged_sum|  22|   1000000|     100|0.27357921|  PASSED 
      rgb_lagged_sum|  23|   1000000|     100|0.08498159|  PASSED 
      rgb_lagged_sum|  24|   1000000|     100|0.99698662|   WEAK   
      rgb_lagged_sum|  25|   1000000|     100|0.99929810|   WEAK   
      rgb_lagged_sum|  26|   1000000|     100|0.28347579|  PASSED 
      rgb_lagged_sum|  27|   1000000|     100|0.99829878|   WEAK   
      rgb_lagged_sum|  28|   1000000|     100|0.64919421|  PASSED 
      rgb_lagged_sum|  29|   1000000|     100|0.21717630|  PASSED 
      rgb_lagged_sum|  30|   1000000|     100|0.94733754|  PASSED 
      rgb_lagged_sum|  31|   1000000|     100|0.29438202|  PASSED 
      rgb_lagged_sum|  32|   1000000|     100|0.50727047|  PASSED 
     rgb_kstest_test|   0|     10000|    1000|0.14336782|  PASSED 
     dab_bytedistrib|   0|  51200000|       1|0.11933557|  PASSED 
             dab_dct| 256|     50000|       1|0.32442918|  PASSED 
Preparing to run test 207.  ntuple = 0
        dab_filltree|  32|  15000000|       1|0.05170555|  PASSED 
        dab_filltree|  32|  15000000|       1|0.18188168|  PASSED 
Preparing to run test 208.  ntuple = 0
       dab_filltree2|   0|   5000000|       1|0.59483751|  PASSED 
       dab_filltree2|   1|   5000000|       1|0.90122398|  PASSED 
Preparing to run test 209.  ntuple = 0
        dab_monobit2|  12|  65000000|       1|0.00938657|  PASSED 


FOR REV-N

Code:
#=============================================================================#
        test_name   |ntup| tsamples |psamples|  p-value |Assessment
#=============================================================================#
   diehard_birthdays|   0|       100|     100|0.63987186|  PASSED 
      diehard_operm5|   0|   1000000|     100|0.25293191|  PASSED 
  diehard_rank_32x32|   0|     40000|     100|0.11529442|  PASSED 
    diehard_rank_6x8|   0|    100000|     100|0.65175662|  PASSED 
   diehard_bitstream|   0|   2097152|     100|0.79387542|  PASSED 
        diehard_opso|   0|   2097152|     100|0.97418405|  PASSED 
        diehard_oqso|   0|   2097152|     100|0.18913330|  PASSED 
         diehard_dna|   0|   2097152|     100|0.60414116|  PASSED 
diehard_count_1s_str|   0|    256000|     100|0.12082042|  PASSED 
diehard_count_1s_byt|   0|    256000|     100|0.42768449|  PASSED 
 diehard_parking_lot|   0|     12000|     100|0.95126386|  PASSED 
    diehard_2dsphere|   2|      8000|     100|0.16671342|  PASSED 
    diehard_3dsphere|   3|      4000|     100|0.92190660|  PASSED 
     diehard_squeeze|   0|    100000|     100|0.59308835|  PASSED 
        diehard_sums|   0|       100|     100|0.35093051|  PASSED 
        diehard_runs|   0|    100000|     100|0.93035850|  PASSED 
        diehard_runs|   0|    100000|     100|0.96841611|  PASSED 
       diehard_craps|   0|    200000|     100|0.43092095|  PASSED 
       diehard_craps|   0|    200000|     100|0.28983112|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.57797840|  PASSED 
 marsaglia_tsang_gcd|   0|  10000000|     100|0.95716644|  PASSED 
         sts_monobit|   1|    100000|     100|0.64090491|  PASSED 
            sts_runs|   2|    100000|     100|0.91869429|  PASSED 
          sts_serial|   1|    100000|     100|0.36938015|  PASSED 
          sts_serial|   2|    100000|     100|0.87774078|  PASSED 
          sts_serial|   3|    100000|     100|0.62837622|  PASSED 
          sts_serial|   3|    100000|     100|0.06794685|  PASSED 
          sts_serial|   4|    100000|     100|0.38010541|  PASSED 
          sts_serial|   4|    100000|     100|0.47452750|  PASSED 
          sts_serial|   5|    100000|     100|0.66117632|  PASSED 
          sts_serial|   5|    100000|     100|0.94668763|  PASSED 
          sts_serial|   6|    100000|     100|0.16744582|  PASSED 
          sts_serial|   6|    100000|     100|0.32127196|  PASSED 
          sts_serial|   7|    100000|     100|0.99999797|   WEAK   
          sts_serial|   7|    100000|     100|0.40557334|  PASSED 
          sts_serial|   8|    100000|     100|0.37455720|  PASSED 
          sts_serial|   8|    100000|     100|0.35259958|  PASSED 
          sts_serial|   9|    100000|     100|0.82054951|  PASSED 
          sts_serial|   9|    100000|     100|0.98507491|  PASSED 
          sts_serial|  10|    100000|     100|0.59542117|  PASSED 
          sts_serial|  10|    100000|     100|0.83201448|  PASSED 
          sts_serial|  11|    100000|     100|0.83094678|  PASSED 
          sts_serial|  11|    100000|     100|0.80834691|  PASSED 
          sts_serial|  12|    100000|     100|0.10514457|  PASSED 
          sts_serial|  12|    100000|     100|0.31083971|  PASSED 
          sts_serial|  13|    100000|     100|0.37949015|  PASSED 
          sts_serial|  13|    100000|     100|0.33757127|  PASSED 
          sts_serial|  14|    100000|     100|0.87314748|  PASSED 
          sts_serial|  14|    100000|     100|0.19504193|  PASSED 
          sts_serial|  15|    100000|     100|0.97875001|  PASSED 
          sts_serial|  15|    100000|     100|0.99146237|  PASSED 
          sts_serial|  16|    100000|     100|0.50541584|  PASSED 
          sts_serial|  16|    100000|     100|0.30078409|  PASSED 
         rgb_bitdist|   1|    100000|     100|0.72807268|  PASSED 
         rgb_bitdist|   2|    100000|     100|0.02438900|  PASSED 
         rgb_bitdist|   3|    100000|     100|0.37027064|  PASSED 
         rgb_bitdist|   4|    100000|     100|0.95688638|  PASSED 
         rgb_bitdist|   5|    100000|     100|0.67810187|  PASSED 
         rgb_bitdist|   6|    100000|     100|0.68922840|  PASSED 
         rgb_bitdist|   7|    100000|     100|0.99674286|   WEAK   
         rgb_bitdist|   8|    100000|     100|0.10898965|  PASSED 
         rgb_bitdist|   9|    100000|     100|0.46212628|  PASSED 
         rgb_bitdist|  10|    100000|     100|0.63853865|  PASSED 
         rgb_bitdist|  11|    100000|     100|0.96366310|  PASSED 
         rgb_bitdist|  12|    100000|     100|0.33524174|  PASSED 
rgb_minimum_distance|   2|     10000|    1000|0.18770080|  PASSED 
rgb_minimum_distance|   3|     10000|    1000|0.87336958|  PASSED 
rgb_minimum_distance|   4|     10000|    1000|0.29080314|  PASSED 
rgb_minimum_distance|   5|     10000|    1000|0.73240366|  PASSED 
    rgb_permutations|   2|    100000|     100|0.94603468|  PASSED 
    rgb_permutations|   3|    100000|     100|0.93203704|  PASSED 
    rgb_permutations|   4|    100000|     100|0.12766175|  PASSED 
    rgb_permutations|   5|    100000|     100|0.09970950|  PASSED 
      rgb_lagged_sum|   0|   1000000|     100|0.59692762|  PASSED 
      rgb_lagged_sum|   1|   1000000|     100|0.63912776|  PASSED 
      rgb_lagged_sum|   2|   1000000|     100|0.53566562|  PASSED 
      rgb_lagged_sum|   3|   1000000|     100|0.83092670|  PASSED 
      rgb_lagged_sum|   4|   1000000|     100|0.76067250|  PASSED 
      rgb_lagged_sum|   5|   1000000|     100|0.94253740|  PASSED 
      rgb_lagged_sum|   6|   1000000|     100|0.55079109|  PASSED 
      rgb_lagged_sum|   7|   1000000|     100|0.52794969|  PASSED 
      rgb_lagged_sum|   8|   1000000|     100|0.97477599|  PASSED 
      rgb_lagged_sum|   9|   1000000|     100|0.84766320|  PASSED 
      rgb_lagged_sum|  10|   1000000|     100|0.03562090|  PASSED 
      rgb_lagged_sum|  11|   1000000|     100|0.33342384|  PASSED 
      rgb_lagged_sum|  12|   1000000|     100|0.28434615|  PASSED 
      rgb_lagged_sum|  13|   1000000|     100|0.57136279|  PASSED 
      rgb_lagged_sum|  14|   1000000|     100|0.93618151|  PASSED 
      rgb_lagged_sum|  15|   1000000|     100|0.57953554|  PASSED 
      rgb_lagged_sum|  16|   1000000|     100|0.46204952|  PASSED 
      rgb_lagged_sum|  17|   1000000|     100|0.30808734|  PASSED 
      rgb_lagged_sum|  18|   1000000|     100|0.45360402|  PASSED 
      rgb_lagged_sum|  19|   1000000|     100|0.37918014|  PASSED 
      rgb_lagged_sum|  20|   1000000|     100|0.12298836|  PASSED 
      rgb_lagged_sum|  21|   1000000|     100|0.73424156|  PASSED 
      rgb_lagged_sum|  22|   1000000|     100|0.99888723|   WEAK   
      rgb_lagged_sum|  23|   1000000|     100|0.77890362|  PASSED 
      rgb_lagged_sum|  24|   1000000|     100|0.80547863|  PASSED 
      rgb_lagged_sum|  25|   1000000|     100|0.49047445|  PASSED 
      rgb_lagged_sum|  26|   1000000|     100|0.12545794|  PASSED 
      rgb_lagged_sum|  27|   1000000|     100|0.48958265|  PASSED 
      rgb_lagged_sum|  28|   1000000|     100|0.13215154|  PASSED 
      rgb_lagged_sum|  29|   1000000|     100|0.21704994|  PASSED 
      rgb_lagged_sum|  30|   1000000|     100|0.36238427|  PASSED 
      rgb_lagged_sum|  31|   1000000|     100|0.32575873|  PASSED 
      rgb_lagged_sum|  32|   1000000|     100|0.11079717|  PASSED 
     rgb_kstest_test|   0|     10000|    1000|0.29132466|  PASSED 
     dab_bytedistrib|   0|  51200000|       1|0.90638357|  PASSED 
             dab_dct| 256|     50000|       1|0.83572373|  PASSED 
Preparing to run test 207.  ntuple = 0
        dab_filltree|  32|  15000000|       1|0.04401382|  PASSED 
        dab_filltree|  32|  15000000|       1|0.73108144|  PASSED 
Preparing to run test 208.  ntuple = 0
       dab_filltree2|   0|   5000000|       1|0.49651849|  PASSED 
       dab_filltree2|   1|   5000000|       1|0.83838244|  PASSED 
Preparing to run test 209.  ntuple = 0
        dab_monobit2|  12|  65000000|       1|0.28756011|  PASSED 
Ok, I need some assistance. This is crashing, and for the life of me I cannot figure out why.
Firstly, the source in C:


Code:

bool hashlib_PasswdBcrypt(uint8_t* bcrypt, const uint8_t* passwd, const uint8_t* verify, BLOWFISH_KEY* ctx){
    uint24_t cost = 0;
    uint8_t salt[16];
    uint8_t* magic = "OrpheanBeholderScryDoubt";
    size_t mstringlen = strlen(magic);
    size_t pstringlen = strlen(passwd);
    uint8_t bcrypt_out[24] = {0};
    if(verify==NULL){
        hashlib_RandomBytes(&salt, 16);
        cost = 12;
    } else {
        hashlib_b64decode(&salt, 22, verify+7);
        for(uint8_t i=3; verify[i] != '$'; i++){
            cost *= 10;
            cost += (verify[i]-'0');
        }
    }
   
    cost = 1<<cost;

    hashlib_BlowfishInit(ctx);
   
    hashlib_BlowfishLoadKey(passwd, salt, ctx, pstringlen);
    for(uint24_t i=0; i<cost; i++){
        hashlib_BlowfishLoadKey(passwd, NULL, ctx, pstringlen);
        hashlib_BlowfishLoadKey(&salt, NULL, ctx, 16);
    }
    for(uint8_t i = 0; i < 64; i++){
        hashlib_BlowfishEncrypt(&bcrypt_out, magic, ctx, mstringlen);
        memcpy(magic, &bcrypt_out, 24);
   }
    sprintf(bcrypt, "$2a$%u$", cost);
    hashlib_b64encode(bcrypt+7, &salt, 16);
    hashlib_b64encode(bcrypt+7+22, &bcrypt_out, 24);
    if(verify == NULL) return true;
    if(strncmp(bcrypt+3, verify+3, 57)) return false;
    return true;
}


Secondly, a link to the ASM code this compiles to:
https://github.com/acagliano/hashlib-ce/blob/rsa/src/hashlib.asm#L6767

On line 7007, the `ret` instruction causes the code to return to 0xCFEB8D, rather than the place in memory the function was called from.
This triggers a

Code:
[CEmu] Unknown debug Command: 0x9f,0xffffff
[CEmu] NMI reset caused by writing to flash at address 0x1d5da1 from unprivileged code. Hint: Possibly a null pointer dereference.
[CEmu] Reset caused by writing to bit 4 of port 0.

on CEmu, and crashes. I have zero clue why and how this is erroring in this way? Clearly the stack is garbled by something in this function, since the ret isn't going to the right place, but given this is compiled, I have no idea how this could be the case.


[EDIT] This crash is now resolved. The hash returned is still incorrect however.
UPDATE

A new version (v2) is out. https://www.cemetech.net/downloads/files/2123/x2373
This version sports the removal of the non-cryptographic hashes (checksum/CRC-32). It has the CSPRNG added, derived from data compiled in this topic. It also adds Blowfish encryption, Base64 encode/decode, and there are plans to add the encryption side of RSA as well, for variable key sizes between 512 and 1024 bits. I also included a whitepaper in the download, to present sourcing information, info about about algorithms I wrote myself, and credit people. Much thanks to Zeroko for information on randomness, and to beck and command for assistance with some C to Asm conversion of parts. The algorithms still are a tad slow, so bear with me. Optimizations will come at a later date, in v3 most likely.
UPDATE

Archives Download: https://www.cemetech.net/downloads/files/2123/x2386
Github: https://github.com/acagliano/hashlib/tree/stable

The repository is now set up such that cloning the project gives you the built library, documentation, PRNG statistics, and the .h and .lib files, but that moving to the `dev` branch gives you the C codebase. They are distinct because the compiled C undergoes significant manual tinkering before being built into the library.

This update of HASHLIB adds AES-128, AES-192, and AES-256 support. Believe it or not, the AES implementation is faster than Blowfish. The cipher uses Cipher Block Chaining mode. This means it takes a key of 128, 192, or 256 bits in size as well as an initialization vector that is a pseudorandom 16-byte string.

In addition, I have also added a padding scheme implementation function. You pass it your plaintext and PT size, as well as constants indicating the algorithm to pad for (Blowfish/AES) and the padding spec to use. The available options are:

Code:

enum _padding_schemes {
    FILL_ZERO,                  // ISO/IEC 9797-1, Method 1.  (pads with zeros)
    NEXTBIT_1_FILL_ZERO,        // ISO/IEC 9797-1, Method 2.  (pads with 0x80, and then zeros)
    FILL_RAND,                  // ANSI X9.23.   (pads with pseudorandomness)
    FILL_PAD_SIZE,              // PKCS#7.     (pads with the size of the padding)
};
UPDATE

New release available, however, this one I will not be uploading to the archives...the next one to upload will be the fully complete one. This download (v4) will be available from the github:

https://github.com/acagliano/hashlib/releases/latest

What's New, v4

1. AES-CBC-MAC.
A modification of the AES-CBC cipher mode that produces a MAC tag one block long, rather than an output ciphertext. This one does not take an IV, but requires a unique key schedule.

2. Added a helper function macro that takes the plaintext, an output buffer, two unique key schedules, a padding scheme spec, and a random IV, and outputs a message according to the following IPsec-derived standard:
a) AES-CBC encrypt the plaintext over k1 and the random IV.
b) Output the random IV followed by the ciphertext to the output buffer.
c) Pass the output buffer to the AES-CBC-MAC function for a constant IV and k2.
d) Output the MAC to the end of the output buffer.
The resulting output should be resistant to CCA.

3. A function that takes a ciphertext and some k2 (ks_mac) and attempts to validate the MAC of that ciphertext.

4. A buffer comparison function that is resistant to timing attacks by always comparing the entire buffer, regardless of whether (or if) some position in the comparison doesn't match. EDIT: jacobly supplied a new function in asm that actually IS resistant to this attack, mine written in compiled C apparently wasn't.
Me and Cags have been scratching our heads trying to figure out why the SHA256 functions in the assembly rewrite of hashlib are producing incorrect hashes. If someone would be willing to help us figure out what's going wrong or what area isn't being initialized correctly or at all that would be much appreciated Smile
https://github.com/acagliano/hashlib/tree/sha256-asm

Specifically this file: src/asm/sha256.asm
Ok, after much debugging pain, we have made some headway debugging the SHA routine. It now works for data less than 56 bytes in size (such that the hash only processes one block). However, beyond that, it still outputs the wrong hash. We have been working out brains last night and pretty much all morning/afternoon to fix both the initial bug and this one, but are thus far unable to trace the current bug for data lengths more than 1 block. We will keep at if, but if anyone wants to review the code and point out anything, feel free.

I personally suspect something in the initial logic of the Final function, or a segment of the update loop. Here is the link to the code, and the associated, working, C code.

Possibly bugged section of SHA_Update()
https://github.com/acagliano/hashlib/blob/sha256-asm/src/asm/sha256.asm#L91

Associated C:

Code:
for (i = 0; i < len; ++i) {
      ctx->data[ctx->datalen] = data[i];
      ctx->datalen++;
      if (ctx->datalen == 64) {
         sha256_transform(ctx, ctx->data);
         add64iu(&ctx->bitlen, 512);
         ctx->datalen = 0;
      }
   }



Possibly bugged SHA_Final()
https://github.com/acagliano/hashlib/blob/sha256-asm/src/asm/sha256.asm#L114

Associated C:

Code:
i = ctx->datalen;

   // Pad whatever data is left in the buffer.
   if (ctx->datalen < 56) {
      ctx->data[i++] = 0x80;
      while (i < 56)
         ctx->data[i++] = 0x00;
   }
   else {
      ctx->data[i++] = 0x80;
      while (i < 64)
         ctx->data[i++] = 0x00;
      sha256_transform(ctx, ctx->data);
      memset(ctx->data, 0, 56);
   }

   // Append to the padding the total message's length in bits and transform.
   add64iu(&ctx->bitlen,ctx->datalen * 8);
   for (x=0;x<8;x++){ //put this in a loop for efficiency
      ctx->data[63-x] = ctx->bitlen[x];
   }
   sha256_transform(ctx, ctx->data);

   // Since this implementation uses little endian byte ordering and SHA uses big endian,
   // reverse all the bytes when copying the final state to the output hash.
   for (i = 0; i < 4; ++i) {
      hash[i]      = (ctx->state[0] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 4]  = (ctx->state[1] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 8]  = (ctx->state[2] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 12] = (ctx->state[3] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 16] = (ctx->state[4] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 20] = (ctx->state[5] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 24] = (ctx->state[6] >> (24 - i * 8)) & 0x000000ff;
      hash[i + 28] = (ctx->state[7] >> (24 - i * 8)) & 0x000000ff;
   }
}


I prefer the former as the source of the bug (the Update function) (I may, and likely am wrong, however) because the file we are hashing to test has a remainder block size less than 56, meaning the logic that would run in SHA_Final would be the same logic as what runs for a single block of data, which is returning the correct result. Thus I suspect a bug in the Update function. I suspect there is no bug in the transform function anymore because getting a 1-block correct hash rules that out.
Hashlib sha256 hashing assembly rewrite has been completed!
Takes ~1.577 seconds to hash the entirety of the latest GRAPHX!
Very Happy Very Happy Very Happy Very Happy Very Happy
The Time Has Come!! for another progress update.

HASHLIB v6 is out on Github: https://github.com/acagliano/hashlib/releases/latest

Here's What's New:
(1) MGF1 hashing function is added. It uses SHA-256 and hashes a given length of data as well as a 4-byte counter.
(2) OAEP now uses MGF1 (as is standard) instead of cyclic SHA-256.
(3) SPRNG now minimizes entropy loss due to correlation (thanks, Zeroko!) and runs ~1.5x faster for generating large pools of random data. The entropy pool is reduced from 192 bytes to 119 bytes, but each time we update a byte in the pool from the entropy source, it is a composite of 7 distinct reads xor'd together.
(4) SPRNGRandom() rewritten in assembly. Thanks to jacobly for optimization and some small code corrections.
(5) SPRNG now uses FastMem for its SHA memory and entropy pool to accelerate even faster.
(6) AES ECB-mode single block encrypt/decrypt functions exposed to let skilled users construct their own cipher modes
Still waiting on vint powmod to be fixed in the bigintce library, and then RSA will be added for v7.
Another Update/Improvement

This update is not yet a release package, however, it can be downloaded from the stable branch of the github.

The RSA-OAEP encoding scheme has been updated from the PKCS#1 v1 standard to the one outlined in PKCS#1 v2. Have a look at this for details: https://datatracker.ietf.org/doc/html/rfc8017#section-7.1

The RSA-PSS encoding scheme is implemented as well for working with SSL-RSA signatures.
Sadly however, I am having difficulty testing these because from what I can tell, the libraries hide the underlying aspects of these schemes well. They seem to want you to pass padding and algorithm specs to a signature/encryption function rather than call the padding functions explicitly (which is fine, but RSA itself isn't actually implemented in hashlib yet, so, not really). If someone knows a way I can do this anyway, feel free to comment.

I also want to implement ECDSA signature verification, but as I know very little about elliptic curves and less about how ECDSA itself functions, it will likely be some time, if I do it at all. I have been referencing this: https://www.instructables.com/Understanding-how-ECDSA-protects-your-data/ as well as the wiki, but this stuff is not easy to understand (at least for me). If someone here has a reference for a more broken down tutorial, or even some code samples, feel free to share, and thanks in advance.
Update HASHLIB moves into RC-1

With all the thanks in the world to jacobly for the modular exponentiation function we needed for RSA, HASHLIB is now formally complete (apart from the possibility of adding ECDSA in the distant future) and will soon be released on github for testing.

As many of you may know and others will learn by reading this, HASHLIB contains the following crytographic implementations:

<> A secure PRNG that produces ~96 bits of entropy per 32-bit integer generated.
<> The SHA-256 cryptographic hash.
<> An implementation of Advanced Encryption Standard (AES), for 128, 192, and 256 bit keys.
<> An implementation of RSA encryption up to 2048 bits in key length.
<> An implementation of the appropriate padding schemes for the above encryptions.
<> An implementation of SSL signature verification using the RSA with SHA-256 signing algorithm.

Feel free to download and test against commonly used cryptography libraries and report back on compatibility or lack thereof.

https://github.com/acagliano/hashlib/releases/tag/v7-RC1
HASHLIB moves into v7.1-rc1

After thinking a bit about how some of the API is laid out (namely requiring users to pad the plaintext prior to passing it to the encryption algorithms), I decided to internalize that functionality. You still have access to the padding functions but those are only for if you need to pad something without encryption. Now, whenever you encrypt with AES or RSA, the padding scheme is applied automatically. For RSA, this is OAEP v2.2. For AES, this can be either PKCS#7 (default) or ISO-9797 M2.

This being said, I have a small request for those in the Cemetech community who may be knowledgeable on the field of crypto. I'd like to put together a cryptanalysis of HASHLIB without the biases of reviewing it myself. The repository that some of the code is sourced from is linked in HASHLIB's github, and the code is available for review there. It's important to note that some of it was written in pure assembly (SHA-256, powmod, and the SPRNG), while other parts (the AES functions and the RSA wrapper functions) were written in C.
https://github.com/acagliano/hashlib
I am aware the library likely offers no side channel resistance, but I am curious what sort of resistance it offers to other forms of "breaking" and if anyone has suggestions for improvement.
HASHLIB v8.0-rc1 update


Version 8 brings 2 new algorithms and significant security enhancements.
The HMAC variant of SHA-256 is implemented, allowing users to use hashes that integrate a key into the initial state.
The PBKDF2-HMAC algorithm is implemented, allowing users to generate a key from a password.

To protect against buffer leak, all user-facing functions erase the contents of the stack frame before returning. To protect against an adverse user mapping the memory or variables on the device while HASHLIB is doing its thing, we disable system interrupts during user-facing functions.

Here's the latest release for testing. Let me know if there are any issues.
https://github.com/acagliano/hashlib/releases/tag/v8-rc1
I'll move the release to stable if there are no issues reported after some time.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement