AES encryption algorithm PureBasic LIB available !
Posted: Thu Aug 12, 2004 5:22 pm
Hi,
thanks to SEC from this forum, the PB community has now the possibility to use AES (Rijndael) by using the Sec's lib :
original thread : viewtopic.php?t=11943&postdays=0&postorder=asc&start=45
AES LIB : http://metawire.org/~sec/aesv2.zip
FIPS PDF document about AES : http://csrc.nist.gov/publications/fips/ ... ps-197.pdf
functions :
FIPS test :
This example is based on a single block of 16 bytes to encrypt.
To use it on data of any size, you can create two procedures to
encrypt/decrypt until the right position.
These procedure has too to do padding to fill the last incomplete block, because AES encrypt by block of 128 bits.
Thansk to SEC for his work
EDIT : the code to use Sec's Lib below :
viewtopic.php?p=66818#66818
thanks to SEC from this forum, the PB community has now the possibility to use AES (Rijndael) by using the Sec's lib :
original thread : viewtopic.php?t=11943&postdays=0&postorder=asc&start=45
AES LIB : http://metawire.org/~sec/aesv2.zip
FIPS PDF document about AES : http://csrc.nist.gov/publications/fips/ ... ps-197.pdf
functions :
Code: Select all
AES128Decrypt(), AES128Encrypt()
AES192Decrypt(), AES192Encrypt()
AES256Decrypt(), AES256Encrypt()
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()
To use it on data of any size, you can create two procedures to
encrypt/decrypt until the right position.
These procedure has too to do padding to fill the last incomplete block, because AES encrypt by block of 128 bits.
Thansk to SEC for his work

EDIT : the code to use Sec's Lib below :
viewtopic.php?p=66818#66818