Blowfish Encryption Componet

Everything else that doesn't fall into one of the other PB categories.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

newbie wrote:May be now someone can create an AES (Rindjael) code in PB ? :P
Have to reply.... :D There was several requests for this, each turned down. Even one request (will pay for source), but nobody is interested in payment, nor work :) So I do not think PB will ever support this.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

It's very sad :(

I think that a good AES lib would be a very great tool for PB.
I'll take a look at your other thread.
- Registered PB user -

Using PB 4.00
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Come soon :) when back home
Some functions in that lib:
AES128Decrypt(), AES128Encrypt()
AES192Decrypt(), AES192Encrypt()
AES256Decrypt(), AES256Encrypt()
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

can't wait for it, and I'm sure Shannara too ;)
- Registered PB user -

Using PB 4.00
kake26
Enthusiast
Enthusiast
Posts: 157
Joined: Sun Jan 25, 2004 7:21 pm
Contact:

Post by kake26 »

AES? I could crank one out in two seconds. The componet set for my lib also has a variety of other encryptions and hashes avail. I'd crank out another DLL, no native PB lib, cause that I don't do. I think on large scale global usage. DLL/SO libs do the trick nicely.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

DLL does not suit to everyone needs, and if you can do the DDL code in PB, why not post this code ?
It can then be added into a PB lib by someone else ?

Personally, I have quit visual basic mainly because of dependencies.

EDIT : if Sec does the PB lib, you can do the DLL, and everyone is happy ;)
- Registered PB user -

Using PB 4.00
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

newbie wrote:can't wait for it, and I'm sure Shannara too ;)
Not I, I am pretty much 100% against DLL use for PB. That is why I pretty much ignore this thread, it talks about using a DLL in PB instead of a PB lib.

I am pretty much like you, I got away from VB due to dependancies, and firmly believe to keep DLLs and other such dependencies away from PB. This component counters that so....

Adding AES support to this is well, nobody is interested :)
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

My sentence was not for the DLL, but for the Lib that Sec is making currently :D
- Registered PB user -

Using PB 4.00
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

Oops :) As long as the lib doesnt require the DLL to use... im all for it :D
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Code: Select all

;Test from fips-197.pdf
;PLAINTEXT: 00112233445566778899aabbccddeeff
;KEY: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f

Procedure.s bytetohex(bb.l)
 hexnum.s = "0123456789abcdef"
 bb = bb & $FF
 ProcedureReturn PeekS(@hexnum+ (bb>>4),1) + PeekS(@hexnum+ (bb & $0F),1)
EndProcedure

plain.s=Space(16)
PokeB(@plain,0)
For i = 1 To 15
 PokeB(@plain+i, PeekB(@plain+i-1)+$11)
Next i

key.s = Space(32)
For i = 0 To 31
 PokeB(@key+i,i)
Next i

AES256Encrypt(@plain,@key) ; notice: plain/cipher is at same place


Debug "#####ciphertext#####"
For i = 0 To 15
 Debug bytetohex(PeekB(@plain+i))
Next i

AES256Decrypt(@plain,@key) ; notice: plain/cipher is at same place

Debug "#####plaintext#####"
For i = 0 To 15
 Debug bytetohex(PeekB(@plain+i))
Next i

;other functions included
;AES128/192Encrypt()
;AES128/192Decrypt()
masm+sometweak ( url: AES.zip)
Hope you like. :wink:
Last edited by sec on Wed Aug 11, 2004 4:18 pm, edited 2 times in total.
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

8O

Sec should be the offcicial PB encryption algorithm manager ! :D

Your FIPS test works fine, no trouble, but from a user point of view, I am trying this :

Code: Select all

plain.s = "I am a fan of SEC now :-)"
key.s = MD5Fingerprint("toto", 4)
Debug "clear = " + plain
Debug "len(clear) = " + Str(Len(plain))
Debug "key = " + key

;-encryption
For a = 0 To Len(plain) Step 16
    AES256Encrypt(@plain + a, @key)
Next a

Debug "encrypted = " + plain

;- decryption
For a = 0 To Len(plain)  Step 16
    AES256Decrypt(@plain + a, @key)
Next a
Debug "clear = " + plain
I probably didn't understand what is AES, I thought it was encrypting by 128bits blocs, but I should do something wrong because the above example crash.
(if I just crypt/decrypt one time, the first 16 bytes of the text is correctly encrypted/decrypted).

If you can show how to use your AES lib as shown above, I think Shannara and me (no link lol) will be extremely happy :P

EDIT : the link to the PDF document is broken, it returns something like "the pdf document is corrupted".

official link : http://csrc.nist.gov/publications/fips/ ... ps-197.pdf
Last edited by newbie on Wed Aug 11, 2004 5:45 pm, edited 1 time in total.
- Registered PB user -

Using PB 4.00
sec
Enthusiast
Enthusiast
Posts: 792
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Post by sec »

Code: Select all

 FunctionName  || Key Length ||  BlockSize
AES128*            128 bit        128 bit
AES192*            192 bit        128 bit
AES256*            256 bit        128 bit
-----
128 bit = 16 byte
192 bit = 24 byte
256 bit = 32 byte
Your code would be:

Code: Select all

plain.s = "I am a fan of SEC now :-) lololo" 
key.s = MD5Fingerprint("toto", 4) 
Debug "clear = " + plain 
Debug "len(clear) = " + Str(Len(plain)) 
Debug "key = " + key 

;-encryption 
oldlen = Len(plain)
For a = 0 To oldlen Step 16 
    AES256Encrypt(@plain + a, @key) 
Next a 

Debug "encrypted = " + plain 

;- decryption 
For a = 0 To oldlen  Step 16 
    AES256Decrypt(@plain + a, @key) 
Next a 
Debug "clear = " + plain 
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

ok Sec, I have managed to code a complete example to use your lib, which works without any errors :

edited : this code is not good, see the posts on page 5

Code: Select all

Procedure AESEncrypt(*Buffer, *Key)
    For a = 0 To Len(PeekS(*Buffer)) Step 16
        AES256Encrypt(*Buffer + a, *Key)
    Next a
    ProcedureReturn *Buffer
EndProcedure

Procedure AESDecrypt(*Buffer, *Key)
    For a = 0 To Len(PeekS(*Buffer)) Step 16 
        AES256Decrypt(*Buffer + a, *Key)
    Next a
    ProcedureReturn *Buffer
EndProcedure


plain.s = "I am a fan of SEC now :-) lololoLOL" ; our plain text
key.s = MD5Fingerprint("toto", 4)               ; creating an AES key of 256 bits

Debug "clear = " + plain                        
Debug "len(clear) = " + Str(Len(plain))
Debug "key = " + key

length_required.l = Len(plain)                  ; length required for the buffer
Debug "length_required = " + Str(length_required)
    
*cypher_text = AllocateMemory(length_required)  ; creating the buffer to the right input/output size
PokeS(*cypher_text, plain, length_required)     ; copying our plain text into the buffer
Debug "LEN *cypher_text = " + Str(Len(PeekS(*cypher_text)))

;-encryption
*cypher_text = AESEncrypt(*cypher_text, @key)   ; encrypting our plain text

Debug "encrypted = " + PeekS(*cypher_text, length_required)
Debug "LEN encrypted = " + Str(Len(PeekS(*cypher_text, length_required)))

;- decryption
;let's assume that this is a break in the code, like for instance an encrypted file that we did not encrypt
;or any encrypted data for which we do not know the size of the plain text

;*cypher_text would be @plain_text$ for instance

*plain_text = AESDecrypt(*cypher_text, @key)    ; decrypting the cypher text

Debug "clear = " + PeekS(*plain_text);, length_required)
Debug "LEN clear = " + Str(Len(PeekS(*plain_text)))
These two functions can be easily combined with your libs, it's more convenient. If you have any correction to do, feel free to do it of course, I whish to learn :)

Even if this code works perfectly, I do not understand something.
From the FIPS PDF document about AES, the output cypher text size depends on the size of the plain text size, as follow :

0 <= Len(plain_text) <= 16 -> output size of 128 bits
( '<=' means less or equal)

So obviously, a 32 bytes string will have a 256 bits output.
But so, shouldn't a 33 bytes string have a 256 + 128 = 348 bits output ??
In the code, the plain text example is 35 bytes (280 bits), So if you take
the first 32 bytes, you need 256 bits of buffer + another 128 bits buffer for the remaining 3 bytes.
However in the code above, I only give 35 bytes of buffer (instead of 48 which crash ?!) and it works just fine.

I need to know if the code above is right and reliable (you know you can do a perfect lib, if it's not used right, especially for encryption, it will give BS and won't have the security level expected), and to understand what is
the problem with my understanding of the buffer encoding size.

Anyway, that's a _very_ great job from Sec, and I hope to know soon if Shannara has found what she was looking at for some time now :)
Last edited by newbie on Thu Aug 12, 2004 9:56 pm, edited 1 time in total.
- Registered PB user -

Using PB 4.00
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

"He", as mentioned in my title and my previous posts/threads concerning my wife :)

Anyways, this isn't. Turns out the code I need translated from VB to PB is a AES hybrid that was found and used on PSCode.com/vb. :( As mentioned in a different thread, that is what I use on the server and needed the equivilent for the PB client. However... if there was an encryption that is available via code (or regular lib, not dll) for both pb and vb, I would use that... :D
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

Sorry Shannara, your name sounds a lot more female than male in my native language :?
In addition your picture is a woman, so don't complain of being seen as a woman and not a man, Mr Shannara ;)

Apart of that, you have at least a full working code for PB :D
Personally I am still trying to understand my own code for now lol
- Registered PB user -

Using PB 4.00
Post Reply