Difference between revisions of "Unit Crypto"
(5 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
---- | ---- | ||
− | '''Ultibo Crypto | + | '''Ultibo Crypto Interface unit''' |
− | + | ||
− | + | ||
=== Constants === | === Constants === | ||
Line 101: | Line 99: | ||
|- | |- | ||
| <code>CRYPTO_HASH_ALG_HMAC_SHA512 = 10;</code> | | <code>CRYPTO_HASH_ALG_HMAC_SHA512 = 10;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>CRYPTO_HASH_ALG_SHA224 = 11;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>CRYPTO_HASH_ALG_HMAC_SHA224 = 12;</code> | ||
| | | | ||
|- | |- | ||
|} | |} | ||
</div></div> | </div></div> | ||
− | <br /> | + | <br /> |
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''MD5 digest size''' <code> MD5_DIGEST_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>MD5_DIGEST_SIZE = 16;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
<div style="font-size: 14px; padding-left: 12px;">'''AES block size''' <code> AES_BLOCK_* </code></div> | <div style="font-size: 14px; padding-left: 12px;">'''AES block size''' <code> AES_BLOCK_* </code></div> | ||
Line 131: | Line 146: | ||
| 256 bit keys | | 256 bit keys | ||
|- | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>AES_IV_SIZE = 16;</code> | ||
+ | | 128 bit initialization vector | ||
+ | |- | ||
|} | |} | ||
</div></div> | </div></div> | ||
Line 203: | Line 223: | ||
<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;" | ||
+ | |- | ||
+ | | <code>SHA1_DIGEST_SIZE = 20;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |colspan="2"| | ||
|- | |- | ||
| <code>SHA1_K20 = $5A827999;</code> | | <code>SHA1_K20 = $5A827999;</code> | ||
Line 219: | Line 244: | ||
</div></div> | </div></div> | ||
<br /> | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''SHA256 constants''' <code> SHA256_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SHA256_DIGEST_SIZE = 32;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''SHA384 constants''' <code> SHA384_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SHA384_DIGEST_SIZE = 48;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''SHA512 constants''' <code> SHA512_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SHA512_DIGEST_SIZE = 64;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
<div style="font-size: 14px; padding-left: 12px;">'''RSA constants''' <code> RSA_* </code></div> | <div style="font-size: 14px; padding-left: 12px;">'''RSA constants''' <code> RSA_* </code></div> | ||
Line 993: | Line 1,051: | ||
<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 HashCreate(Algorithm:LongWord; Key:Pointer; KeySize:LongWord):PHashContext;</pre> | <pre style="border: 0; padding-bottom:0px;">function HashCreate(Algorithm:LongWord; Key:Pointer; KeySize:LongWord):PHashContext;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a hash context based on an algorithm and | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a hash context based on an algorithm and (if applicable) 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;"> | ||
{| class="wikitable" style="font-size: 14px; background: white;" | {| class="wikitable" style="font-size: 14px; background: white;" | ||
Line 1,006: | Line 1,064: | ||
<pre style="border: 0; padding-bottom:0px;">function HashDestroy(Context:PHashContext):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function HashDestroy(Context:PHashContext):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Free a hash context allocated by HashCreate</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Free a hash context allocated by HashCreate</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 HashReset(Context:PHashContext):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Clear and reinitialize an existing hash context using the existing algorithm and key</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 HashReset(Context:PHashContext; Algorithm:LongWord; Key:Pointer; KeySize:LongWord):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Clear and reinitialize an existing hash context using a new algorithm and 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,040: | Line 1,122: | ||
<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 style="border: 0; padding-bottom:0px;">function CipherCreate(Algorithm:LongWord; Vector,Key:Pointer; KeySize:LongWord):PCipherContext;</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,052: | Line 1,134: | ||
<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,Mode:LongWord; Nonce,Vector,Key:Pointer; VectorSize,KeySize:LongWord):PCipherContext | + | <pre style="border: 0; padding-bottom:0px;">function CipherCreate(Algorithm,Mode:LongWord; Nonce,Vector,Key:Pointer; VectorSize,KeySize:LongWord):PCipherContext;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a cipher context based on an algorithm, mode and key</div> | <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;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,109: | Line 1,191: | ||
|- | |- | ||
! Data | ! Data | ||
− | | | + | | Data is 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,128: | Line 1,210: | ||
<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 HMACMD5DigestData(const Key:String; Data:PMD5Block; Digest:PMD5Digest):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function HMACMD5DigestData(const Key:String; Data:PMD5Block; Digest:PMD5Digest):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate an MD5 HMAC (Hashed Message Authentication Code) using the Key and Data</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 HMACMD5DigestData(Key:Pointer; KeySize:LongWord; Data:PMD5Block; Digest:PMD5Digest):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate an MD5 HMAC (Hashed Message Authentication Code) using the Key and Data</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate an MD5 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;"> | ||
Line 1,133: | Line 1,227: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = MD5(Key) instead | + | | 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 | ! Note | ||
− | | The MD5 HMAC algorithm is: MD5(Key xor oPad, MD5(Key xor iPad, Data)) | + | | The MD5 HMAC algorithm is: |
+ | MD5(Key xor oPad, MD5(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,148: | Line 1,245: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = MD5(Key) instead | + | | 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 | ! Note | ||
− | | The MD5 HMAC algorithm is: MD5(Key xor oPad, MD5(Key xor iPad, | + | | The MD5 HMAC algorithm is: |
+ | MD5(Key xor oPad, MD5(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,350: | Line 1,450: | ||
<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 RC4DecryptData(Key:Pointer; KeySize:LongWord; Crypt,Plain:Pointer; Size,Start:LongWord):Boolean; inline;</pre> | <pre style="border: 0; padding-bottom:0px;">function RC4DecryptData(Key:Pointer; KeySize:LongWord; Crypt,Plain:Pointer; Size,Start:LongWord):Boolean; inline;</pre> | ||
− | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' | + | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Encrypt the supplied data with a key using the RC4 cipher algorithm</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,370: | Line 1,470: | ||
|- | |- | ||
! Data | ! Data | ||
− | | | + | | Data is 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,389: | Line 1,489: | ||
<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 HMACSHA1DigestData(const Key:String; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function HMACSHA1DigestData(const Key:String; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA1 HMAC (Hashed Message Authentication Code) using the Key and Data</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 HMACSHA1DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA1 HMAC (Hashed Message Authentication Code) using the Key and Data</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA1 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;"> | ||
Line 1,394: | Line 1,506: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = SHA1(Key) instead | + | | 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 | ! Note | ||
− | | The SHA1 HMAC algorithm is: SHA1(Key xor oPad, SHA1(Key xor iPad, Data)) | + | | The SHA1 HMAC algorithm is: |
+ | SHA1(Key xor oPad, SHA1(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,409: | Line 1,524: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = SHA1(Key) instead | + | | 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 | ! Note | ||
− | | The SHA1 HMAC algorithm is: SHA1(Key xor oPad, SHA1(Key xor iPad, | + | | The SHA1 HMAC algorithm is: |
+ | SHA1(Key xor oPad, SHA1(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,427: | Line 1,545: | ||
|- | |- | ||
! Data | ! Data | ||
− | | | + | | Data is 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,446: | Line 1,564: | ||
<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 HMACSHA256DigestData(const Key:String; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;</pre> | <pre style="border: 0; padding-bottom:0px;">function HMACSHA256DigestData(const Key:String; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA256 HMAC (Hashed Message Authentication Code) using the Key and Data</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 HMACSHA256DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA256 HMAC (Hashed Message Authentication Code) using the Key and Data</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA256 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;"> | ||
Line 1,451: | Line 1,581: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = SHA256(Key) instead | + | | 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 | ! Note | ||
− | | The SHA256 HMAC algorithm is: SHA256(Key xor oPad, SHA256(Key xor iPad, | + | | The SHA256 HMAC algorithm is: |
+ | SHA256(Key xor oPad, SHA256(Key xor iPad, Value)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,466: | Line 1,599: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 64 bytes it will be hashed to Key = SHA256(Key) instead | + | | 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 | ! Note | ||
− | | The SHA256 HMAC algorithm is: SHA256(Key xor oPad, SHA256(Key xor iPad, Value)) | + | | The SHA256 HMAC algorithm is: |
+ | SHA256(Key xor oPad, SHA256(Key xor iPad, Value)) | ||
+ | <br />Where iPad is the byte $36 repeated 64 times, oPad is the byte $5c repeated 64 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,484: | Line 1,620: | ||
|- | |- | ||
! Data | ! Data | ||
− | | | + | | Data is 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,503: | Line 1,639: | ||
<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 HMACSHA384DigestData(const Key:String; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;</pre> | <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:''' 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;"> | ||
+ | {| 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 HMACSHA384DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA384 HMAC (Hashed Message Authentication Code) using the Key and Data</div> | <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;"> | ||
Line 1,508: | Line 1,656: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 128 bytes it will be hashed to Key = SHA384(Key) instead | + | | 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)) | + | | The SHA384 HMAC algorithm is: |
+ | SHA384(Key xor oPad, SHA384(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,538: | Line 1,689: | ||
|- | |- | ||
! Data | ! Data | ||
− | | | + | | Data is 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,557: | Line 1,708: | ||
<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 HMACSHA512DigestData(const Key:String; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;</pre> | <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:''' 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;"> | ||
+ | {| 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 HMACSHA512DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Generate a SHA512 HMAC (Hashed Message Authentication Code) using the Key and Data</div> | <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;"> | ||
Line 1,562: | Line 1,725: | ||
|- | |- | ||
! Key | ! Key | ||
− | | If Key is more than 128 bytes it will be hashed to Key = SHA512(Key) instead | + | | 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)) | + | | The SHA512 HMAC algorithm is: |
+ | SHA512(Key xor oPad, SHA384(Key xor iPad, Data)) | ||
+ | <br />Where iPad is the byte $36 repeated 128 times, oPad is the byte $5c repeated 128 times. | ||
|- | |- | ||
|} | |} | ||
Line 1,611: | Line 1,777: | ||
<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 RSAFreeKey(Context:PRSAContext):Boolean;</pre> | <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:''' Free an RSA context containing Private and/or Public keys</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,788: | ||
<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 RSAEncryptSign(Context:PRSAContext; const Input:PByte; Len: | + | <pre style="border: 0; padding-bottom:0px;">function RSAEncryptSign(Context:PRSAContext; const Input:PByte; Len:Integer; Output:PByte; Sign:Boolean):Integer;</pre> |
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Perform PKCS1.5 Encryption or Signing</div> | <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;"> | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
Line 1,875: | Line 2,041: | ||
<pre style="border: 0; padding-bottom:0px;">procedure MD5Init(var Context:TMD5Context);</pre> | <pre style="border: 0; padding-bottom:0px;">procedure MD5Init(var Context:TMD5Context);</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize an MD5 context with constants</div> | <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;"> | ||
+ | {| 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 MD5Transform(var Context:TMD5Context; Buffer:Pointer);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' The core MD5 algorithm, adds an additional 64 Bytes (16 LongWords) to the hash</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,962: | Line 2,140: | ||
'''DES helper functions''' | '''DES 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 DESCook(Raw1:PLongWord; Key:PDESKey);</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;"> | ||
+ | {| 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 DESKey(Key:PByte; KeyType:LongWord; CryptKey:PDESKey);</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;"> | ||
+ | {| 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 DESProcess(Block,Key:PLongWord);</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;"> | ||
+ | {| 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;"> | <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 2,043: | Line 2,257: | ||
<pre style="border: 0; padding-bottom:0px;">procedure SHA1Init(var Context:TSHA1Context);</pre> | <pre style="border: 0; padding-bottom:0px;">procedure SHA1Init(var Context:TSHA1Context);</pre> | ||
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a SHA1 context with constants</div> | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' Initialize a SHA1 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 SHA1Transform(var Context:TSHA1Context; Buffer:Pointer);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' The core SHA1 algorithm, adds an additional 64 Bytes (512 bits) to the hash</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 2,094: | Line 2,320: | ||
<pre style="border: 0; padding-bottom:0px;">procedure SHA256Init(var Context:TSHA256Context);</pre> | <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 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 SHA256Compress(var Context:TSHA256Context; Buffer:Pointer);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' The core SHA256 algorithm, adds an additional 64 Bytes (512 bits) to the hash</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 2,196: | Line 2,434: | ||
<pre style="border: 0; padding-bottom:0px;">procedure SHA512Init(var Context:TSHA512Context);</pre> | <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 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 SHA512Compress(var Context:TSHA512Context; Buffer:Pointer);</pre> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Description:''' The core SHA512 algorithm, adds an additional 128 Bytes (1024 bits) to the hash</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;" |
Latest revision as of 04:40, 31 August 2021
Return to Unit Reference
Contents
[hide]Description
Ultibo Crypto Interface unit
Constants
CRYPTO_CIPHER_ALG_*
CRYPTO_CIPHER_MODE_*
CRYPTO_HASH_ALG_*
MD5_DIGEST_*
AES_BLOCK_*
AES_KEY_*
DES_BLOCK_*
DES_KEY_*
DES_KEYTYPE_*
DES3_BLOCK_*
DES3_KEY_*
SHA1_*
SHA256_*
SHA384_*
SHA512_*
RSA_*
BASE64_*
Type definitions
MD5 digest
MD5 block
MD5 context
MD5 byte buffer
MD5 long buffer
AES key
AES context
DES key
DES context
3DES key
3DES context
RC4 state
RC4 context
SHA1 digest
SHA1 block
SHA1 context
SHA1 byte buffer
SHA1 long buffer
SHA256 digest
SHA256 block
SHA256 context
SHA256 byte buffer
SHA256 long buffer
SHA256 algorithm
SHA512 digest
SHA512 block
SHA512 context
SHA512 byte buffer
SHA512 algorithm
SHA384 digest
SHA384 block
SHA384 context
SHA384 byte buffer
RSA context
Get random bytes
TGetRandomBytes = function(Buffer:PByte; Count:Integer):Boolean;
|
Base64 decode table
TBase64DecodeTable = array[0..255] of Char;
|
Hash context
Cipher context
Public variables
Crypto specific variables
CryptoGetRandomBytesHandler:TGetRandomBytes;
|
Function declarations
Initialization functions
Crypto functions
function HashCreate(Algorithm:LongWord; Key:Pointer; KeySize:LongWord):PHashContext;
function HashDestroy(Context:PHashContext):Boolean;
function HashReset(Context:PHashContext):Boolean;
function HashReset(Context:PHashContext; Algorithm:LongWord; Key:Pointer; KeySize:LongWord):Boolean;
function HashUpdate(Context:PHashContext; Data:Pointer; Size:LongWord):Boolean;
function HashFinish(Context:PHashContext; Digest:Pointer; Size:LongWord):Boolean;
function CipherCreate(Algorithm:LongWord; Vector,Key:Pointer; KeySize:LongWord):PCipherContext;
function CipherCreate(Algorithm,Mode:LongWord; Nonce,Vector,Key:Pointer; VectorSize,KeySize:LongWord):PCipherContext;
function CipherDestroy(Context:PCipherContext):Boolean;
function CipherEncrypt(Context:PCipherContext; Plain,Crypt:Pointer; Size:LongWord):Boolean;
function CipherDecrypt(Context:PCipherContext; Crypt,Plain:Pointer; Size:LongWord):Boolean;
MD5 functions
function MD5DigestData(Data:PMD5Block; Digest:PMD5Digest):Boolean;
function MD5DigestString(const Value:String; Digest:PMD5Digest):Boolean;
function HMACMD5DigestData(const Key:String; Data:PMD5Block; Digest:PMD5Digest):Boolean;
function HMACMD5DigestData(Key:Pointer; KeySize:LongWord; Data:PMD5Block; Digest:PMD5Digest):Boolean;
function HMACMD5DigestString(const Key,Value:String; Digest:PMD5Digest):Boolean;
AES functions
function AESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
function AESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
function AESCTREncryptData(Key:Pointer; KeySize:LongWord; Nonce,Plain,Crypt:Pointer; Size:LongWord):Boolean;
function AESCTRDecryptData(Key:Pointer; KeySize:LongWord; Nonce,Crypt,Plain:Pointer; Size:LongWord):Boolean; inline;
function AESGCMEncryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Plain,Crypt:Pointer; IVSize,AADSize,Size:LongWord; Tag:Pointer):Boolean;
function AESGCMDecryptData(Key:Pointer; KeySize:LongWord; IV,AAD,Crypt,Plain:Pointer; IVSize,AADSize,Size:LongWord; const Tag:Pointer):Boolean;
function AESGCMGMAC(Key:Pointer; KeySize:LongWord; IV,AAD:Pointer; IVSize,AADSize:LongWord; Tag:Pointer):Boolean;
DES functions
function DESEncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
function DESDecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
3DES functions
function DES3EncryptData(Key:Pointer; KeySize:LongWord; Vector,Plain,Crypt:Pointer; Size:LongWord):Boolean;
function DES3DecryptData(Key:Pointer; KeySize:LongWord; Vector,Crypt,Plain:Pointer; Size:LongWord):Boolean;
RC4 functions
function RC4EncryptData(Key:Pointer; KeySize:LongWord; Plain,Crypt:Pointer; Size,Start:LongWord):Boolean;
function RC4DecryptData(Key:Pointer; KeySize:LongWord; Crypt,Plain:Pointer; Size,Start:LongWord):Boolean; inline;
SHA1 functions
function SHA1DigestData(Data:PSHA1Block; Digest:PSHA1Digest):Boolean;
function SHA1DigestString(const Value:String; Digest:PSHA1Digest):Boolean;
function HMACSHA1DigestData(const Key:String; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;
function HMACSHA1DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA1Block; Digest:PSHA1Digest):Boolean;
function HMACSHA1DigestString(const Key,Value:String; Digest:PSHA1Digest):Boolean;
SHA256 functions
function SHA256DigestData(Data:PSHA256Block; Digest:PSHA256Digest):Boolean;
function SHA256DigestString(const Value:String; Digest:PSHA256Digest):Boolean;
function HMACSHA256DigestData(const Key:String; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;
function HMACSHA256DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA256Block; Digest:PSHA256Digest):Boolean;
function HMACSHA256DigestString(const Key,Value:String; Digest:PSHA256Digest):Boolean;
SHA384 functions
function SHA384DigestData(Data:PSHA384Block; Digest:PSHA384Digest):Boolean;
function SHA384DigestString(const Value:String; Digest:PSHA384Digest):Boolean;
function HMACSHA384DigestData(const Key:String; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;
function HMACSHA384DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA384Block; Digest:PSHA384Digest):Boolean;
function HMACSHA384DigestString(const Key,Value:String; Digest:PSHA384Digest):Boolean;
SHA512 functions
function SHA512DigestData(Data:PSHA512Block; Digest:PSHA512Digest):Boolean;
function SHA512DigestString(const Value:String; Digest:PSHA512Digest):Boolean;
function HMACSHA512DigestData(const Key:String; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;
function HMACSHA512DigestData(Key:Pointer; KeySize:LongWord; Data:PSHA512Block; Digest:PSHA512Digest):Boolean;
function HMACSHA512DigestString(const Key,Value:String; Digest:PSHA512Digest):Boolean;
RSA functions
function RSAInitPrivateKey(Modulus,PublicExp,PrivateExp,P,Q,DP,DQ,QInv:PByte; ModulusLen,PublicExpLen,PrivateExpLen,PLen,QLen,DPLen,DQLen,QInvLen:Integer):PRSAContext;
function RSAInitPublicKey(Modulus,PublicExp:PByte; ModulusLen,PublicExpLen:Integer):PRSAContext;
function RSAFreeKey(Context:PRSAContext):Boolean;
function RSAEncryptSign(Context:PRSAContext; const Input:PByte; Len:Integer; Output:PByte; Sign:Boolean):Integer;
function RSADecryptVerify(Context:PRSAContext; const Input:PByte; Output:PByte; Len:Integer; Verify:Boolean):Integer;
Random functions
function GetRandomBytes(Buffer:PByte; Count:Integer):Boolean;
function GetRandomBytesNonZero(Buffer:PByte; Count:Integer):Boolean;
CRC functions
function CRC16CCITT(CRC:Word; Data:PByte; Size:LongWord):Word;
Base64 functions
function Base64EncodeString(const Value:String):String;
function Base64DecodeString(const Value:String):String;
function Base64EncodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;
function Base64DecodeBuffer(const Source:PChar; SourceLen:Integer; Dest:PChar; var DestLen:Integer):Boolean;
Crypto helper functions
procedure BytesToLE32(Buffer:PByte; Count:LongWord);
procedure BytesToBE32(Buffer:PByte; Count:LongWord);
procedure BytesToLE64(Buffer:PByte; Count:LongWord);
procedure BytesToBE64(Buffer:PByte; Count:LongWord);
procedure BEToLongWord(Value:LongWord; Buffer:PByte); inline;
MD5 helper functions
procedure MD5Init(var Context:TMD5Context);
procedure MD5Transform(var Context:TMD5Context; Buffer:Pointer);
procedure MD5Update(var Context:TMD5Context; Data:Pointer; Size:LongWord);
procedure MD5Final(var Context:TMD5Context; var Digest:TMD5Digest);
AES helper functions
function AESKeySetup(Key:Pointer; KeySize:LongWord; AESKey:PAESKey):Boolean;
procedure AESEncryptBlock(Plain,Crypt:Pointer; AESKey:PAESKey);
procedure AESDecryptBlock(Crypt,Plain:Pointer; AESKey:PAESKey);
DES helper functions
procedure DESKey(Key:PByte; KeyType:LongWord; CryptKey:PDESKey);
function DESKeySetup(Key:Pointer; KeySize:LongWord; EncryptKey,DecryptKey:PDESKey):Boolean;
procedure DESEncryptBlock(Plain,Crypt:Pointer; EncryptKey:PDESKey);
procedure DESDecryptBlock(Crypt,Plain:Pointer; DecryptKey:PDESKey);
3DES helper functions
function DES3KeySetup(Key:Pointer; KeySize:LongWord; DES3Key:PDES3Key):Boolean;
procedure DES3EncryptBlock(Plain,Crypt:Pointer; DES3Key:PDES3Key);
procedure DES3DecryptBlock(Crypt,Plain:Pointer; DES3Key:PDES3Key);
SHA1 helper functions
procedure SHA1Init(var Context:TSHA1Context);
procedure SHA1Transform(var Context:TSHA1Context; Buffer:Pointer);
procedure SHA1Update(var Context:TSHA1Context; Data:Pointer; Size:LongWord);
procedure SHA1Final(var Context:TSHA1Context; var Digest:TSHA1Digest);
SHA256 helper functions
procedure SHA256Init(var Context:TSHA256Context);
procedure SHA256Compress(var Context:TSHA256Context; Buffer:Pointer);
procedure SHA256Process(var Context:TSHA256Context; Data:Pointer; Size:LongWord);
procedure SHA256Complete(var Context:TSHA256Context; var Digest:TSHA256Digest);
SHA384 helper functions
procedure SHA384Init(var Context:TSHA384Context);
procedure SHA384Process(var Context:TSHA384Context; Data:Pointer; Size:LongWord);
procedure SHA384Complete(var Context:TSHA384Context; var Digest:TSHA384Digest);
SHA512 helper functions
procedure SHA512Init(var Context:TSHA512Context);
procedure SHA512Compress(var Context:TSHA512Context; Buffer:Pointer);
procedure SHA512Process(var Context:TSHA512Context; Data:Pointer; Size:LongWord);
procedure SHA512Complete(var Context:TSHA512Context; var Digest:TSHA512Digest);
Base64 helper functions
Return to Unit Reference