M_Crypto (formerly Blowfish and Bcrypt project)

No, it relies on the classic framework.

Also, my implementation is memory-intensive so I’m not sure it would be practical on iOS. Other implementations recalculate values as they are needed but I cache them instead so using AES, for example, will retain about 1 MB of memory. I wouldn’t want to change that because the performance difference is dramatic, even in 64-bit with aggressive optimization. Something that takes milliseconds to encrypt now used to take up to a second before I made the change.

I just released v.2.2, now with GenerateUUID and a separate Scrypt module. Read about Scrypt here:

https://en.wikipedia.org/wiki/Scrypt

I just posted 2.2.1. The only difference is a dramatic speedup of Scrypt by a factor of about 3. It turns out using a MemoryBlock is way faster than copying values to and from an array.

In 64-bit aggressive, the Scrypt test took about 1.0s. Now it takes about 0.33s. In 32-bit, it went from about 3.5s to 1.5s.

I found a bug that could lead to a crash. I’ll release an update soon, but in the meantime, look in AES_MTC.InitMultiplyTables. In the loop, change the upper bound from 256 to 255.

  for i as integer = 0 to ptrs.Ubound
    dim p as ptr = ptrs( i )
    dim v as integer = values( i )
    
    for x as integer = 0 to 255 // <-- was 256, a bad, bad value
      p.Byte( x ) = Multiply( x, v )
    next
  next

Version 2.3 is out. The release notes:

  • Harness now allows multiple encryption windows.
  • Encryption window hides the encryption key unless that field has focus.
  • Fixed bug in AES that could lead to a crash (using a Ptr to overwrite the bounds of a MemoryBlock by one byte).
  • Refactored around new framework MemoryBlock.
  • Quicker initialization for AES.

I’ve been trying to figure out why AES decryption was so much slower (relatively speaking) than encryption. In 64-bit, encrypting 30k took about 2 ms with AES-256-CBC while decryption took about 40 ms. It turns out that I just forgot to add pragmas to the InvCipher method. It’s in the develop branch now, or you can just add this to the top of the method:

#if not DebugBuild
  #pragma BackgroundTasks False
  #pragma BoundsChecking False
  #pragma NilObjectChecking False
  #pragma StackOverflowChecking False
#endif

v.2.4 is out.

Hey, great set of classes, much appreciated! I have one issue/question. I am trying to switch from the MBS Blowfish plugin to your classes. I have some text that was encrypted using BlowfishMBS.Encrypt(“key”,string).

But when I take that encrypted output and plug it into your class, trying to decode with Blowfish, I always get the following error:

Data blocks must be an exact multiple of BlockSize

Am I doing something wrong, or is there something off about the MBS Blowfish implementation? Are your classes simply not compatible with MBS encryption output? I’ve tried every variation of settings I an in your example project, but it always results in the same error.

Any assistance would be most appreciated. Thank you.

Can you paste as hex the output you’re trying to decrypt? It might be that his implementation handles padding differently, but blowfish is blowfish.

I’m encrypting “hello, world” with MBS Blowfish using a key, and the output is “U1?MTk??” (without the quotes). MBS Blowfish decrypts it just fine.

Thanks for the quick response!

Using what key? And please paste the data as hex or Base64. Binary does not translate well to a forum.

I don’t know how to get the data as hex or base64. Please excuse my ignorance, I don’t know much about encryption. I’m going to generate a new encrypted string with a new key. MBS Encrypt only gives me the data in the format I sent. Here is the new test:

Plain text string: “hello, world”
Key: “TNLAC9XOFC3ZY714761905”
The output MBS gives me: “!?–?Ödÿ{??”

Let me know what I need to do to give you the entry in base64 or hex. I’ve always just stored the output directly from MBS and it worked fine. I do use ConvertEncodings.UTF on the string first.

Thank you very much.

I can reproduce the problem here. MBS produces 14 bytes of output, but Blowfish expects blocks in multiples of 8, so I don’t know how he’s padding internally or what other algorithm he might have applied. Perhaps @Christian Schmitz can shed more light.

Hmm that is strange. Bummer. Well thank you very much for looking into this.

I can tell you that I’ve tested my classes against other implementations with no compatibility issues.

I definitely believe you made it universal and compatible. I wonder if MBS does something to make it proprietary. Which would be a drag honestly. I’ll have to figure out some alternate method to get old encrypted data out and use your standard encryption algorithm going forward. No idea yet what I’ll do but I’ll figure something out.

Thanks again for your help.

For advice on how to encrypt stuff securely, see here:

https://forum.xojo.com/50188-tip-encrypting-stuff

Thank you, much appreciated. I’m just encrypting Data in a database, but I will continue researching more about encryption.

My main issue is getting data encrypted with MBS on 32 bit to be readable by new 64 bit builds. I may need to include a bundled 32 bit helper to decrypt MBS, but that will only work until 32 bit apps are completely killed next year.

Again, thanks for your help. Much appreciated.

I’ve just released v.2.5, found here:

https://github.com/ktekinay/M_Crypto

This release includes SHA256Digest_MTC and SHA512Digest_MTC classes that will let you calculate those respective hashes in blocks.