Difference between revisions of "Unit Crypto"
Line 1,040: | Line 1,040: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function CipherCreate(Algorithm:LongWord; Vector,Key:Pointer; KeySize:LongWord):PCipherContext;</pre> | + | <pre style="border: 0; padding-bottom:0px;">function CipherCreate(Algorithm:LongWord; Vector,Key:Pointer; KeySize:LongWord):PCipherContext; overload;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a cipher context based on an algorithm and a key</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a cipher context based on an algorithm and a key</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,046: | Line 1,046: | ||
|- | |- | ||
! Note | ! Note | ||
− | | For block ciphers | + | | For block ciphers an initialization vector can be passed to enable CBC mode |
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function CipherCreate(Algorithm,Mode:LongWord; Nonce,Vector,Key:Pointer; VectorSize,KeySize:LongWord):PCipherContext; overload;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a cipher context based on an algorithm, mode and key</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | For block ciphers a Nonce or IV can be passed if the selected mode requires it | ||
|- | |- | ||
|} | |} | ||
Line 1,149: | Line 1,161: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function AESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function AESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encrypt a block of data using the AES cipher, if Vector is supplied use CBC mode else use ECB</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! KeySize | ||
+ | | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) | ||
+ | |- | ||
+ | ! Vector | ||
+ | | Vector must be 16 bytes (128 bits) long if supplied | ||
+ | |- | ||
+ | ! Size | ||
+ | | Size must be a multiple of 16 bytes long | ||
|- | |- | ||
! Note | ! Note | ||
− | | | + | | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
|- | |- | ||
|} | |} | ||
Line 1,161: | Line 1,182: | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function AESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function AESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Decrypt a block of data using the AES cipher, if Vector is supplied use CBC mode else use ECB</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! KeySize | ||
+ | | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) | ||
+ | |- | ||
+ | ! Vector | ||
+ | | Vector must be 16 bytes (128 bits) long if supplied | ||
+ | |- | ||
+ | ! Size | ||
+ | | Size must be a multiple of 16 bytes long | ||
|- | |- | ||
! Note | ! Note | ||
− | | | + | | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function AESCTREncryptData(Key:Pointer; KeySize:LongWord; Nonce,Plain,Crypt:Pointer; Size:LongWord):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encrypt a block of data with the supplied Key and Nonce using AES CTR mode</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! KeySize | ||
+ | | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) | ||
+ | |- | ||
+ | ! Nonce | ||
+ | | Nonce must be 16 bytes (128 bits) long | ||
+ | |- | ||
+ | ! Note | ||
+ | | Plain text and Crypt data pointers must be the same length (and can point to the same value) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function AESCTRDecryptData(Key:Pointer; KeySize:LongWord; Nonce,Crypt,Plain:Pointer; Size:LongWord):Boolean; inline;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Decrypt a block of data with the supplied Key and Nonce using AES CTR mode</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! KeySize | ||
+ | | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) | ||
+ | |- | ||
+ | ! Nonce | ||
+ | | Nonce must be 16 bytes (128 bits) long | ||
+ | |- | ||
+ | ! Note | ||
+ | | Plain text and Crypt data pointers must be the same length (and can point to the same value) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function AESGCMEncryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Plain,Crypt:Pointer; IVSize,AADSize,Size:LongWord; Tag:Pointer):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encrypt a block of data with the supplied Key, IV and AAD using AES GCM mode, return the authentication Tag</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Tag | ||
+ | | Tag must be 16 bytes (128 bits) long | ||
+ | |- | ||
+ | ! Note | ||
+ | | Plain text and Crypt data pointers must be the same length (and can point to the same value) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function AESGCMDecryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Crypt,Plain:Pointer; IVSize,AADSize,Size:LongWord; const Tag:Pointer):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Decrypt a block of data with the supplied Key, IV and AAD using AES GCM mode, validate the authentication Tag</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Tag | ||
+ | | Tag must be 16 bytes (128 bits) long | ||
+ | |- | ||
+ | ! Note | ||
+ | | Plain text and Crypt data pointers must be the same length (and can point to the same value) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function AESGCMGMAC(Key:Pointer; KeySize:LongWord; IV,AAD:Pointer; IVSize,AADSize:LongWord; Tag:Pointer):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate the GMAC authentication Tag for a given Key, IV and AAD using AES GCM mode</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Tag | ||
+ | | Tag must be 16 bytes (128 bits) long | ||
|- | |- | ||
|} | |} | ||
Line 1,367: | Line 1,475: | ||
<br /> | <br /> | ||
− | ''' | + | '''SHA384 functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function SHA384DigestData(Data:PSHA384Block; Digest:PSHA384Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a 384 bit SHA384 digest (Hash) from the supplied data</div> |
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Data | ||
+ | | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function SHA384DigestString(const Value:String; Digest:PSHA384Digest):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a 384 bit SHA384 digest (Hash) from the supplied string value</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,381: | Line 1,501: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
− | |||
− | |||
− | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function HMACSHA384DigestData(const Key:String; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA384 HMAC (Hashed Message Authentication Code) using the Key and Data</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Key | ||
+ | | If Key is more than 128 bytes it will be hashed to Key = SHA384(Key) instead. If Key is less than 128 bytes it will be padded with zeros. | ||
|- | |- | ||
! Note | ! Note | ||
− | | | + | | The SHA384 HMAC algorithm is: SHA384(Key xor oPad, SHA384(Key xor iPad, Data)). Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. |
|- | |- | ||
|} | |} | ||
Line 1,397: | Line 1,517: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function HMACSHA384DigestString(const Key,Value:String; Digest:PSHA384Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA384 HMAC (Hashed Message Authentication Code) using the Key and Value</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,409: | Line 1,529: | ||
<br /> | <br /> | ||
− | ''' | + | '''SHA512 functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function SHA512DigestData(Data:PSHA512Block; Digest:PSHA512Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a 512 bit SHA512 digest (Hash) from the supplied data</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! Data |
− | | | + | | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
|- | |- | ||
|} | |} | ||
Line 1,424: | Line 1,544: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function SHA512DigestString(const Value:String; Digest:PSHA512Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a 512 bit SHA512 digest (Hash) from the supplied string value</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,436: | Line 1,556: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function HMACSHA512DigestData(const Key:String; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA512 HMAC (Hashed Message Authentication Code) using the Key and Data</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Key | ||
+ | | If Key is more than 128 bytes it will be hashed to Key = SHA512(Key) instead. If Key is less than 128 bytes it will be padded with zeros. | ||
|- | |- | ||
! Note | ! Note | ||
− | | | + | | The SHA512 HMAC algorithm is: SHA512(Key xor oPad, SHA384(Key xor iPad, Data)). Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. |
|- | |- | ||
|} | |} | ||
Line 1,448: | Line 1,571: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function HMACSHA512DigestString(const Key,Value:String; Digest:PSHA512Digest):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA512 HMAC (Hashed Message Authentication Code) using the Key and Value</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,460: | Line 1,583: | ||
<br /> | <br /> | ||
− | ''' | + | '''RSA functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function RSAInitPrivateKey(Modulus,PublicExp,PrivateExp,P,Q,DP,DQ,QInv:PByte; ModulusLen,PublicExpLen,PrivateExpLen,PLen,QLen,DPLen,DQLen,QInvLen:Integer):PRSAContext;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,475: | Line 1,598: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function RSAInitPublicKey(Modulus,PublicExp:PByte; ModulusLen,PublicExpLen:Integer):PRSAContext;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,487: | Line 1,610: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function RSAFreeKey(Context:PRSAContext):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,499: | Line 1,622: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function RSAEncryptSign(Context:PRSAContext; const Input:PByte; Len:Word; Output:PByte; Sign:Boolean):Integer;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' The | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform PKCS1.5 Encryption or Signing</div> |
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Context | ||
+ | | The RSA context containing Private and/or Public keys | ||
+ | |- | ||
+ | ! Input | ||
+ | | The data to be encrypted | ||
+ | |- | ||
+ | ! Len | ||
+ | | The size of the input data in bytes (Must be <= Modulus length - 11 to make the padding at least 8 bytes as recommended by RFC2313) | ||
+ | |- | ||
+ | ! Output | ||
+ | | The buffer for the encrypted result (Must always be Modulus length) | ||
+ | |- | ||
+ | ! Sign | ||
+ | | If true then sign instead of encrypting | ||
+ | |- | ||
+ | ! Return | ||
+ | | The number of bytes encrypted or -1 on error | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function RSADecryptVerify(Context:PRSAContext; const Input:PByte; Output:PByte; Len:Integer; Verify:Boolean):Integer;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform PKCS1.5 Decryption or Verification</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Context | ||
+ | | The RSA context containing Private and/or Public keys | ||
+ | |- | ||
+ | ! Input | ||
+ | | The data to be decrypted (Must always be Modulus length) | ||
+ | |- | ||
+ | ! Output | ||
+ | | The buffer for the decrypted result | ||
+ | |- | ||
+ | ! Len | ||
+ | | The size of the output buffer in bytes | ||
+ | |- | ||
+ | ! Verify | ||
+ | | If true then verify instead of decrypting | ||
+ | |- | ||
+ | ! Return | ||
+ | | The number of bytes decrypted or -1 on error | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | '''Random functions''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function GetRandomBytes(Buffer:PByte; Count:Integer):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,511: | Line 1,691: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function GetRandomBytesNonZero(Buffer:PByte; Count:Integer):Boolean;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,523: | Line 1,703: | ||
<br /> | <br /> | ||
− | ''' | + | '''CRC functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function CRC16CCITT(CRC:Word; Data:PByte; Size:LongWord):Word;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,537: | Line 1,717: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | |||
+ | '''Base64 functions''' | ||
+ | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function Base64EncodeString(const Value:String):String;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encode a string using Base64 encoding and return the encoded result</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,550: | Line 1,733: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function Base64DecodeString(const Value:String):String;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Decode a Base64 encoded string and return the decoded result</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,562: | Line 1,745: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function Base64EncodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encode the source buffer using Base64 encoding and return the encoded result in the destination buffer</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
! Note | ! Note | ||
− | | | + | | On success DestLen contains the actual encoded length including a null terminator |
+ | If Dest is nil then return success (True) with the required size in DestLen | ||
|- | |- | ||
|} | |} | ||
Line 1,574: | Line 1,758: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function Base64DecodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Decode a Base64 encoded source buffer and return the decoded result in the destination buffer</div> |
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | On success DestLen contains the actual decoded length (Null terminator is not added to this value) | ||
+ | If Dest is nil then return success (True) with the required size in DestLen | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | |||
+ | '''Crypto helper functions''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">procedure BytesToLE32(Buffer:PByte; Count:LongWord);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Change the byte order of count longwords in the supplied buffer to little endian</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,586: | Line 1,786: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure BytesToBE32(Buffer:PByte; Count:LongWord);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Change the byte order of count longwords in the supplied buffer to big endian</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,598: | Line 1,798: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure BytesToLE64(Buffer:PByte; Count:LongWord);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Change the byte order of count quadwords in the supplied buffer to little endian</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,610: | Line 1,810: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure BytesToBE64(Buffer:PByte; Count:LongWord);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Change the byte order of count quadwords in the supplied buffer to big endian</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,622: | Line 1,822: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function LongWordToBE(Buffer:PByte):LongWord; inline;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,634: | Line 1,834: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure BEToLongWord(Value:LongWord; Buffer:PByte); inline;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,646: | Line 1,846: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">function QWordToBE(Buffer:PByte):QWord; inline;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,658: | Line 1,858: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure BEToQWord(Value:QWord; Buffer:PByte); inline;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,669: | Line 1,869: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | |||
+ | '''MD5 helper functions''' | ||
+ | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure MD5Init(var Context:TMD5Context);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize an MD5 context with constants</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,682: | Line 1,885: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">procedure MD5Update(var Context:TMD5Context; Data:Pointer; Size:LongWord);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add more bytes to the data buffer, add to the hash in 64 byte chunks</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,694: | Line 1,897: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure MD5Final(var Context:TMD5Context; var Digest:TMD5Digest);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Finalize the MD5 context by padding to a 64 Byte boundary, adding QWord count of bits processed and copying the hash to the digest</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,706: | Line 1,909: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function MD5DigestToString(Digest:PMD5Digest):String;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,718: | Line 1,921: | ||
<br /> | <br /> | ||
− | ''' | + | '''AES helper functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function AESKeySetup(Key:Pointer; KeySize:LongWord; AESKey:PAESKey):Boolean;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Create a pair of AES keys using the supplied key</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
|- | |- | ||
− | ! | + | ! KeySize |
− | | | + | | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
|- | |- | ||
|} | |} | ||
Line 1,733: | Line 1,936: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure AESEncryptBlock(Plain,Crypt:Pointer; AESKey:PAESKey);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' AES Encrypt a 16 byte (128 bit) block of data using the supplied key</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,745: | Line 1,948: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure AESDecryptBlock(Crypt,Plain:Pointer; AESKey:PAESKey);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' AES Decrypt a 16 byte (128 bit) block of data using the supplied key</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,756: | Line 1,959: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | |||
+ | '''DES helper functions''' | ||
+ | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
<pre style="border: 0; padding-bottom:0px;">function DESKeySetup(Key:Pointer; KeySize:LongWord; EncryptKey,DecryptKey:PDESKey):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function DESKeySetup(Key:Pointer; KeySize:LongWord; EncryptKey,DecryptKey:PDESKey):Boolean;</pre> | ||
Line 1,871: | Line 2,077: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function SHA1DigestToString(Digest:PSHA1Digest):String;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,882: | Line 2,088: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | |||
+ | '''SHA256 helper functions''' | ||
+ | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">procedure SHA256Init(var Context:TSHA256Context);</pre> |
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a SHA256 context with constants</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">procedure SHA256Process(var Context:TSHA256Context; Data:Pointer; Size:LongWord);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add more bytes to the data buffer, add to the hash in 64 byte chunks</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">procedure SHA256Complete(var Context:TSHA256Context; var Digest:TSHA256Digest);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Finalize the SHA256 context by padding to a 64 Byte boundary, adding QWord count of bits processed and copying the hash to the digest</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function SHA256DigestToString(Digest:PSHA256Digest):String;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,895: | Line 2,140: | ||
<br /> | <br /> | ||
− | ''' | + | '''SHA384 helper functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure SHA384Init(var Context:TSHA384Context);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a SHA384 context with constants</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,910: | Line 2,155: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure SHA384Process(var Context:TSHA384Context; Data:Pointer; Size:LongWord);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add more bytes to the data buffer, add to the hash in | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add more bytes to the data buffer, add to the hash in 128 byte chunks</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,922: | Line 2,167: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure SHA384Complete(var Context:TSHA384Context; var Digest:TSHA384Digest);</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Finalize the | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Finalize the SHA384 context by padding to a 128 Byte boundary, adding QWord count of bits processed and copying the hash to the digest</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,934: | Line 2,179: | ||
<br /> | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;"> | + | <pre style="border: 0; padding-bottom:0px;">function SHA384DigestToString(Digest:PSHA384Digest):String;</pre> |
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> |
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,945: | Line 2,190: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | |||
+ | '''SHA512 helper functions''' | ||
+ | |||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">function | + | <pre style="border: 0; padding-bottom:0px;">procedure SHA512Init(var Context:TSHA512Context);</pre> |
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a SHA512 context with constants</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">procedure SHA512Process(var Context:TSHA512Context; Data:Pointer; Size:LongWord);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add more bytes to the data buffer, add to the hash in 128 byte chunks</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">procedure SHA512Complete(var Context:TSHA512Context; var Digest:TSHA512Digest);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Finalize the SHA512 context by padding to a 128 Byte boundary, adding QWord count of bits processed and copying the hash to the digest</div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | ! Note | ||
+ | | None documented | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
+ | <pre style="border: 0; padding-bottom:0px;">function SHA512DigestToString(Digest:PSHA512Digest):String;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,958: | Line 2,242: | ||
<br /> | <br /> | ||
− | ''' | + | '''Base64 helper functions''' |
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;"> | ||
− | <pre style="border: 0; padding-bottom:0px;">procedure | + | <pre style="border: 0; padding-bottom:0px;">procedure Base64InitTables;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div> | ||
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> |
Revision as of 05:12, 18 April 2018
Return to Unit Reference
Description
Ultibo Crypto interface unit
To be documented
Constants
CRYPTO_CIPHER_ALG_*
CRYPTO_CIPHER_ALG_NONE = 0;
|
|
CRYPTO_CIPHER_ALG_AES = 1;
|
|
CRYPTO_CIPHER_ALG_DES = 2;
|
|
CRYPTO_CIPHER_ALG_3DES = 3;
|
|
CRYPTO_CIPHER_ALG_RC4 = 4;
|
CRYPTO_CIPHER_MODE_*
CRYPTO_CIPHER_MODE_ECB = 0;
|
Electronic Codebook |
CRYPTO_CIPHER_MODE_CBC = 1;
|
Cipher Block Chaining |
CRYPTO_CIPHER_MODE_CFB = 2;
|
Cipher Feedback |
CRYPTO_CIPHER_MODE_OFB = 3;
|
Output Feedback |
CRYPTO_CIPHER_MODE_CTR = 4;
|
Counter |
CRYPTO_CIPHER_MODE_CCM = 5;
|
Counter with CBC-MAC |
CRYPTO_CIPHER_MODE_GCM = 5;
|
Galois/Counter Mode |
CRYPTO_HASH_ALG_*
CRYPTO_HASH_ALG_NONE = 0;
|
|
CRYPTO_HASH_ALG_MD5 = 1;
|
|
CRYPTO_HASH_ALG_SHA1 = 2;
|
|
CRYPTO_HASH_ALG_SHA256 = 3;
|
|
CRYPTO_HASH_ALG_HMAC_MD5 = 4;
|
|
CRYPTO_HASH_ALG_HMAC_SHA1 = 5;
|
|
CRYPTO_HASH_ALG_HMAC_SHA256 = 6;
|
|
CRYPTO_HASH_ALG_SHA384 = 7;
|
|
CRYPTO_HASH_ALG_SHA512 = 8;
|
|
CRYPTO_HASH_ALG_HMAC_SHA384 = 9;
|
|
CRYPTO_HASH_ALG_HMAC_SHA512 = 10;
|
AES_BLOCK_*
AES_BLOCK_SIZE = 16;
|
128 bit blocks |
AES_KEY_*
AES_KEY_SIZE128 = 16;
|
128 bit keys |
AES_KEY_SIZE192 = 24;
|
192 bit keys |
AES_KEY_SIZE256 = 32;
|
256 bit keys |
DES_BLOCK_*
DES_BLOCK_SIZE = 8;
|
64 bit blocks |
DES_KEY_*
DES_KEY_SIZE = 8;
|
64 bit keys |
DES_KEYTYPE_*
DES_KEYTYPE_ENCRYPT = 0;
|
|
DES_KEYTYPE_DECRYPT = 1;
|
|
DES_BYTEBIT:array[0..7] of LongWord = (
| |
$80, $40, $20, $10, $08, $04, $02, $01);
|
DES3_BLOCK_*
DES3_BLOCK_SIZE = 8;
|
64 bit blocks |
DES3_KEY_*
DES3_KEY_SIZE = 24;
|
192 bit (3 x 64 bit) keys |
SHA1_*
SHA1_K20 = $5A827999;
|
|
SHA1_K40 = $6ED9EBA1;
|
|
SHA1_K60 = $8F1BBCDC;
|
|
SHA1_K80 = $CA62C1D6;
|
RSA_*
RSA_MODULUS_BYTES_MAX = 512;
|
4096 bit maximum |
BASE64_*
Base64EncodeTable:String = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
Type definitions
MD5 digest
PMD5Digest = ^TMD5Digest;
TMD5Digest = array[0..15] of Byte;
MD5 block
PMD5Block = ^TMD5Block;
TMD5Block = record
Data:Pointer;
|
|
Size:LongWord;
|
|
Next:PMD5Block;
|
MD5 context
PMD5Context = ^TMD5Context;
TMD5Context = record
Data:array[0..63] of Byte;
|
|
Buffer:array[0..3] of LongWord;
|
|
Count:QWord;
|
MD5 byte buffer
PMD5ByteBuffer = ^TMD5ByteBuffer;
TMD5ByteBuffer = array[0..63] of Byte;
MD5 long buffer
PMD5LongBuffer = ^TMD5LongBuffer;
TMD5LongBuffer = array[0..15] of LongWord;
AES key
PAESKey = ^TAESKey;
TAESKey = record
Rounds:LongWord;
|
|
EncryptKey:array[0..59] of LongWord;
|
|
DecryptKey:array[0..59] of LongWord;
|
AES context
PAESContext = ^TAESContext;
TAESContext = record
AESKey:TAESKey;
|
|
CBC:array[0..AES_BLOCK_SIZE - 1] of Byte;
|
|
CTR:array[0..AES_BLOCK_SIZE - 1] of Byte;
|
DES key
PDESKey = ^TDESKey;
TDESKey = array[0..31] of LongWord;
DES context
PDESContext = ^TDESContext;
TDESContext = record
EncryptKey:TDESKey;
|
|
DecryptKey:TDESKey;
|
|
CBC:array[0..DES_BLOCK_SIZE - 1] of Byte;
|
3DES key
PDES3Key = ^TDES3Key;
TDES3Key = record
EncryptKey:array[0..2] of TDESKey;
|
|
DecryptKey:array[0..2] of TDESKey;
|
3DES context
PDES3Context = ^TDES3Context;
TDES3Context = record
DES3Key:TDES3Key;
|
|
CBC:array[0..DES3_BLOCK_SIZE - 1] of Byte;
|
RC4 state
PRC4State = ^TRC4State;
TRC4State = array[0..255] of Byte;
RC4 context
PRC4Context = ^TRC4Context;
TRC4Context = record
Key:array[0..31] of Byte;
|
|
KeySize:LongWord;
|
|
Start:LongWord;
|
SHA1 digest
PSHA1Digest = ^TSHA1Digest;
TSHA1Digest = array[0..19] of Byte;
SHA1 block
PSHA1Block = ^TSHA1Block;
TSHA1Block = record
Data:Pointer;
|
|
Size:LongWord;
|
|
Next:PSHA1Block;
|
SHA1 context
PSHA1Context = ^TSHA1Context;
TSHA1Context = record
Data:array[0..63] of Byte;
|
|
State:array[0..4] of LongWord;
|
|
Count:QWord;
|
SHA1 byte buffer
PSHA1ByteBuffer = ^TSHA1ByteBuffer;
TSHA1ByteBuffer = array[0..63] of Byte;
SHA1 long buffer
PSHA1LongBuffer = ^TSHA1LongBuffer;
TSHA1LongBuffer = array[0..15] of LongWord;
SHA256 digest
PSHA256Digest = ^TSHA256Digest;
TSHA256Digest = array[0..31] of Byte;
SHA256 block
PSHA256Block = ^TSHA256Block;
TSHA256Block = record
Data:Pointer;
|
|
Size:LongWord;
|
|
Next:PSHA256Block;
|
SHA256 context
PSHA256Context = ^TSHA256Context;
TSHA256Context = record
Data:array[0..63] of Byte;
|
|
State:array[0..7] of LongWord;
|
|
Count:QWord;
|
SHA256 byte buffer
PSHA256ByteBuffer = ^TSHA256ByteBuffer;
TSHA256ByteBuffer = array[0..63] of Byte;
SHA256 long buffer
PSHA256LongBuffer = ^TSHA256LongBuffer;
TSHA256LongBuffer = array[0..15] of LongWord;
SHA256 algorithm
PSHA256_W = ^TSHA256_W;
TSHA256_W = array[0..63] of LongWord;
Note: This is the W array for the SHA256 algorithm | |
SHA512 digest
PSHA512Digest = ^TSHA512Digest;
TSHA512Digest = array[0..63] of Byte;
SHA512 block
PSHA512Block = ^TSHA512Block;
TSHA512Block = record
Data:Pointer;
|
|
Size:LongWord;
|
|
Next:PSHA512Block;
|
SHA512 context
PSHA512Context = ^TSHA512Context;
TSHA512Context = record
Data:array[0..127] of Byte;
|
|
State:array[0..7] of QWord;
|
|
Count:QWord;
|
SHA512 byte buffer
PSHA512ByteBuffer = ^TSHA512ByteBuffer;
TSHA512ByteBuffer = array[0..127] of Byte;
SHA512 algorithm
PSHA512_W = ^TSHA512_W;
TSHA512_W = array[0..79] of QWord;
Note: This is the W array for the SHA512 algorithm | |
SHA384 digest
PSHA384Digest = ^TSHA384Digest;
TSHA384Digest = array[0..47] of Byte;
SHA384 block
PSHA384Block = PSHA512Block;
TSHA384Block = TSHA512Block;
SHA384 context
PSHA384Context = PSHA512Context;
TSHA384Context = TSHA512Context;
SHA384 byte buffer
PSHA384ByteBuffer = PSHA512ByteBuffer;
TSHA384ByteBuffer = TSHA512ByteBuffer;
RSA context
PRSAContext = ^TRSAContext;
TRSAContext = record
M:PBigInt;
|
Modulus |
E:PBigInt;
|
Public exponent |
D:PBigInt;
|
Private exponent |
P:PBigInt;
|
p in m = pq |
Q:PBigInt;
|
q in m = pq |
DP:PBigInt;
|
d mod (p-1) |
DQ:PBigInt;
|
d mod (q-1) |
QInv:PBigInt;
|
q^-1 mod p |
ModulusLen:Integer;
|
|
Context:PBigIntContext;
|
Get random bytes
TGetRandomBytes = function(Buffer:PByte; Count:Integer):Boolean;
|
Base64 decode table
TBase64DecodeTable = array[0..255] of Char;
|
Hash context
PHashContext = ^THashContext;
THashContext = record
Algorithm:LongWord;
|
|
Key:array[0..127] of Byte;
|
|
KeySize:LongWord;
|
|
case Integer of
|
|
0:(MD5:TMD5Context);
|
|
1:(SHA1:TSHA1Context);
|
|
2:(SHA256:TSHA256Context);
|
|
3:(SHA384:TSHA384Context);
|
|
4:(SHA512:TSHA512Context);
|
Cipher context
PCipherContext = ^TCipherContext;
TCipherContext = record
Algorithm:LongWord;
|
|
Mode:LongWord;
|
|
case Integer of
|
|
0:(RC4:TRC4Context);
|
|
1:(DES:TDESContext);
|
|
2:(DES3:TDES3Context);
|
|
3:(AES:TAESContext);
|
Public variables
Crypto specific variables
CryptoGetRandomBytesHandler:TGetRandomBytes;
|
Function declarations
Initialization functions
procedure CryptoInit;
Note | None documented |
---|
Crypto functions
function HashCreate(Algorithm:LongWord; Key:Pointer; KeySize:LongWord):PHashContext;
Note | None documented |
---|
function HashDestroy(Context:PHashContext):Boolean;
Note | None documented |
---|
function HashUpdate(Context:PHashContext; Data:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
function HashFinish(Context:PHashContext; Digest:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
function CipherCreate(Algorithm:LongWord; Vector,Key:Pointer; KeySize:LongWord):PCipherContext; overload;
Note | For block ciphers an initialization vector can be passed to enable CBC mode |
---|
function CipherCreate(Algorithm,Mode:LongWord; Nonce,Vector,Key:Pointer; VectorSize,KeySize:LongWord):PCipherContext; overload;
Note | For block ciphers a Nonce or IV can be passed if the selected mode requires it |
---|
function CipherDestroy(Context:PCipherContext):Boolean;
Note | None documented |
---|
function CipherEncrypt(Context:PCipherContext; Plain,Crypt:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
function CipherDecrypt(Context:PCipherContext; Crypt,Plain:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
MD5 functions
function MD5DigestData(Data:PMD5Block; Digest:PMD5Digest):Boolean;
Data | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
---|
function MD5DigestString(const Value:String; Digest:PMD5Digest):Boolean;
Note | None documented |
---|
function HMACMD5DigestData(const Key:String; Data:PMD5Block; Digest:PMD5Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = MD5(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The MD5 HMAC algorithm is: MD5(Key xor oPad, MD5(Key xor iPad, Data)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
function HMACMD5DigestString(const Key,Value:String; Digest:PMD5Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = MD5(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The MD5 HMAC algorithm is: MD5(Key xor oPad, MD5(Key xor iPad, Value)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
AES functions
function AESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
KeySize | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
---|---|
Vector | Vector must be 16 bytes (128 bits) long if supplied |
Size | Size must be a multiple of 16 bytes long |
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
KeySize | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
---|---|
Vector | Vector must be 16 bytes (128 bits) long if supplied |
Size | Size must be a multiple of 16 bytes long |
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESCTREncryptData(Key:Pointer; KeySize:LongWord; Nonce,Plain,Crypt:Pointer; Size:LongWord):Boolean;
KeySize | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
---|---|
Nonce | Nonce must be 16 bytes (128 bits) long |
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESCTRDecryptData(Key:Pointer; KeySize:LongWord; Nonce,Crypt,Plain:Pointer; Size:LongWord):Boolean; inline;
KeySize | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
---|---|
Nonce | Nonce must be 16 bytes (128 bits) long |
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESGCMEncryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Plain,Crypt:Pointer; IVSize,AADSize,Size:LongWord; Tag:Pointer):Boolean;
Tag | Tag must be 16 bytes (128 bits) long |
---|---|
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESGCMDecryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Crypt,Plain:Pointer; IVSize,AADSize,Size:LongWord; const Tag:Pointer):Boolean;
Tag | Tag must be 16 bytes (128 bits) long |
---|---|
Note | Plain text and Crypt data pointers must be the same length (and can point to the same value) |
function AESGCMGMAC(Key:Pointer; KeySize:LongWord; IV,AAD:Pointer; IVSize,AADSize:LongWord; Tag:Pointer):Boolean;
Tag | Tag must be 16 bytes (128 bits) long |
---|
DES functions
function DESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
function DESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
3DES functions
function DES3EncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
function DES3DecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
Note | None documented |
---|
RC4 functions
function RC4EncryptData(Key:Pointer; KeySize:LongWord; Plain,Crypt:Pointer; Size,Start:LongWord):Boolean;
Start | Specify how many bytes of the RC4 cipher stream to skip to allow for previous blocks of data or to comply with RFC4345 requirements to discard the first 1536 bytes of the RC4 cipher stream |
---|
function RC4DecryptData(Key:Pointer; KeySize:LongWord; Crypt,Plain:Pointer; Size,Start:LongWord):Boolean; inline;
Note | None documented |
---|
SHA1 functions
function SHA1DigestData(Data:PSHA1Block; Digest:PSHA1Digest):Boolean;
Data | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
---|
function SHA1DigestString(const Value:String; Digest:PSHA1Digest):Boolean;
Note | None documented |
---|
function HMACSHA1DigestData(const Key:String; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = SHA1(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The SHA1 HMAC algorithm is: SHA1(Key xor oPad, SHA1(Key xor iPad, Data)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
function HMACSHA1DigestString(const Key,Value:String; Digest:PSHA1Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = SHA1(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The SHA1 HMAC algorithm is: SHA1(Key xor oPad, SHA1(Key xor iPad, Value)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
SHA256 functions
function SHA256DigestData(Data:PSHA256Block; Digest:PSHA256Digest):Boolean;
Data | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
---|
function SHA256DigestString(const Value:String; Digest:PSHA256Digest):Boolean;
Note | None documented |
---|
function HMACSHA256DigestData(const Key:String; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = SHA256(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The SHA256 HMAC algorithm is: SHA256(Key xor oPad, SHA256(Key xor iPad, Data)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
function HMACSHA256DigestString(const Key,Value:String; Digest:PSHA256Digest):Boolean;
Key | If Key is more than 64 bytes it will be hashed to Key = SHA256(Key) instead. If Key is less than 64 bytes it will be padded with zeros. |
---|---|
Note | The SHA256 HMAC algorithm is: SHA256(Key xor oPad, SHA256(Key xor iPad, Value)). Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. |
SHA384 functions
function SHA384DigestData(Data:PSHA384Block; Digest:PSHA384Digest):Boolean;
Data | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
---|
function SHA384DigestString(const Value:String; Digest:PSHA384Digest):Boolean;
Note | None documented |
---|
function HMACSHA384DigestData(const Key:String; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;
Key | If Key is more than 128 bytes it will be hashed to Key = SHA384(Key) instead. If Key is less than 128 bytes it will be padded with zeros. |
---|---|
Note | The SHA384 HMAC algorithm is: SHA384(Key xor oPad, SHA384(Key xor iPad, Data)). Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. |
function HMACSHA384DigestString(const Key,Value:String; Digest:PSHA384Digest):Boolean;
Note | None documented |
---|
SHA512 functions
function SHA512DigestData(Data:PSHA512Block; Digest:PSHA512Digest):Boolean;
Data | A linked list which can contain multiple independent blocks to be included in the hash. The data block itself does not form part of the hash. |
---|
function SHA512DigestString(const Value:String; Digest:PSHA512Digest):Boolean;
Note | None documented |
---|
function HMACSHA512DigestData(const Key:String; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;
Key | If Key is more than 128 bytes it will be hashed to Key = SHA512(Key) instead. If Key is less than 128 bytes it will be padded with zeros. |
---|---|
Note | The SHA512 HMAC algorithm is: SHA512(Key xor oPad, SHA384(Key xor iPad, Data)). Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. |
function HMACSHA512DigestString(const Key,Value:String; Digest:PSHA512Digest):Boolean;
Note | None documented |
---|
RSA functions
function RSAInitPrivateKey(Modulus,PublicExp,PrivateExp,P,Q,DP,DQ,QInv:PByte; ModulusLen,PublicExpLen,PrivateExpLen,PLen,QLen,DPLen,DQLen,QInvLen:Integer):PRSAContext;
Note | None documented |
---|
function RSAInitPublicKey(Modulus,PublicExp:PByte; ModulusLen,PublicExpLen:Integer):PRSAContext;
Note | None documented |
---|
function RSAFreeKey(Context:PRSAContext):Boolean;
Note | None documented |
---|
function RSAEncryptSign(Context:PRSAContext; const Input:PByte; Len:Word; Output:PByte; Sign:Boolean):Integer;
Context | The RSA context containing Private and/or Public keys |
---|---|
Input | The data to be encrypted |
Len | The size of the input data in bytes (Must be <= Modulus length - 11 to make the padding at least 8 bytes as recommended by RFC2313) |
Output | The buffer for the encrypted result (Must always be Modulus length) |
Sign | If true then sign instead of encrypting |
Return | The number of bytes encrypted or -1 on error |
function RSADecryptVerify(Context:PRSAContext; const Input:PByte; Output:PByte; Len:Integer; Verify:Boolean):Integer;
Context | The RSA context containing Private and/or Public keys |
---|---|
Input | The data to be decrypted (Must always be Modulus length) |
Output | The buffer for the decrypted result |
Len | The size of the output buffer in bytes |
Verify | If true then verify instead of decrypting |
Return | The number of bytes decrypted or -1 on error |
Random functions
function GetRandomBytes(Buffer:PByte; Count:Integer):Boolean;
Note | None documented |
---|
function GetRandomBytesNonZero(Buffer:PByte; Count:Integer):Boolean;
Note | None documented |
---|
CRC functions
function CRC16CCITT(CRC:Word; Data:PByte; Size:LongWord):Word;
Note | None documented |
---|
Base64 functions
function Base64EncodeString(const Value:String):String;
Note | None documented |
---|
function Base64DecodeString(const Value:String):String;
Note | None documented |
---|
function Base64EncodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;
Note | On success DestLen contains the actual encoded length including a null terminator
If Dest is nil then return success (True) with the required size in DestLen |
---|
function Base64DecodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;
Note | On success DestLen contains the actual decoded length (Null terminator is not added to this value)
If Dest is nil then return success (True) with the required size in DestLen |
---|
Crypto helper functions
procedure BytesToLE32(Buffer:PByte; Count:LongWord);
Note | None documented |
---|
procedure BytesToBE32(Buffer:PByte; Count:LongWord);
Note | None documented |
---|
procedure BytesToLE64(Buffer:PByte; Count:LongWord);
Note | None documented |
---|
procedure BytesToBE64(Buffer:PByte; Count:LongWord);
Note | None documented |
---|
function LongWordToBE(Buffer:PByte):LongWord; inline;
Note | None documented |
---|
procedure BEToLongWord(Value:LongWord; Buffer:PByte); inline;
Note | None documented |
---|
function QWordToBE(Buffer:PByte):QWord; inline;
Note | None documented |
---|
procedure BEToQWord(Value:QWord; Buffer:PByte); inline;
Note | None documented |
---|
MD5 helper functions
procedure MD5Init(var Context:TMD5Context);
Note | None documented |
---|
procedure MD5Update(var Context:TMD5Context; Data:Pointer; Size:LongWord);
Note | None documented |
---|
procedure MD5Final(var Context:TMD5Context; var Digest:TMD5Digest);
Note | None documented |
---|
function MD5DigestToString(Digest:PMD5Digest):String;
Note | None documented |
---|
AES helper functions
function AESKeySetup(Key:Pointer; KeySize:LongWord; AESKey:PAESKey):Boolean;
KeySize | Key size must be 16, 24 or 32 bytes (128, 192 or 256 bits) |
---|
procedure AESEncryptBlock(Plain,Crypt:Pointer; AESKey:PAESKey);
Note | None documented |
---|
procedure AESDecryptBlock(Crypt,Plain:Pointer; AESKey:PAESKey);
Note | None documented |
---|
DES helper functions
function DESKeySetup(Key:Pointer; KeySize:LongWord; EncryptKey,DecryptKey:PDESKey):Boolean;
Note | None documented |
---|
procedure DESEncryptBlock(Plain,Crypt:Pointer; EncryptKey:PDESKey);
Note | None documented |
---|
procedure DESDecryptBlock(Crypt,Plain:Pointer; DecryptKey:PDESKey);
Note | None documented |
---|
3DES helper functions
function DES3KeySetup(Key:Pointer; KeySize:LongWord; DES3Key:PDES3Key):Boolean;
Note | None documented |
---|
procedure DES3EncryptBlock(Plain,Crypt:Pointer; DES3Key:PDES3Key);
Note | None documented |
---|
procedure DES3DecryptBlock(Crypt,Plain:Pointer; DES3Key:PDES3Key);
Note | None documented |
---|
SHA1 helper functions
procedure SHA1Init(var Context:TSHA1Context);
Note | None documented |
---|
procedure SHA1Update(var Context:TSHA1Context; Data:Pointer; Size:LongWord);
Note | None documented |
---|
procedure SHA1Final(var Context:TSHA1Context; var Digest:TSHA1Digest);
Note | None documented |
---|
function SHA1DigestToString(Digest:PSHA1Digest):String;
Note | None documented |
---|
SHA256 helper functions
procedure SHA256Init(var Context:TSHA256Context);
Note | None documented |
---|
procedure SHA256Process(var Context:TSHA256Context; Data:Pointer; Size:LongWord);
Note | None documented |
---|
procedure SHA256Complete(var Context:TSHA256Context; var Digest:TSHA256Digest);
Note | None documented |
---|
function SHA256DigestToString(Digest:PSHA256Digest):String;
Note | None documented |
---|
SHA384 helper functions
procedure SHA384Init(var Context:TSHA384Context);
Note | None documented |
---|
procedure SHA384Process(var Context:TSHA384Context; Data:Pointer; Size:LongWord);
Note | None documented |
---|
procedure SHA384Complete(var Context:TSHA384Context; var Digest:TSHA384Digest);
Note | None documented |
---|
function SHA384DigestToString(Digest:PSHA384Digest):String;
Note | None documented |
---|
SHA512 helper functions
procedure SHA512Init(var Context:TSHA512Context);
Note | None documented |
---|
procedure SHA512Process(var Context:TSHA512Context; Data:Pointer; Size:LongWord);
Note | None documented |
---|
procedure SHA512Complete(var Context:TSHA512Context; var Digest:TSHA512Digest);
Note | None documented |
---|
function SHA512DigestToString(Digest:PSHA512Digest):String;
Note | None documented |
---|
Base64 helper functions
procedure Base64InitTables;
Note | None documented |
---|
Return to Unit Reference