// //------------------ DOK FILE -------------------------------------------------- +Header cryptoLib =pkg bios =title Cryptography =short AES, SHA, DES, RC4, MD5, ... =desc Minimacy embeds most of the cryptographical algorithms. On top of that, the ROM contains more cryptographical packages (core.crypto.*) which handle ECB, CBC, GCM block ciphering, PEM and DER files, RSA, elliptic curves, hashmac and many more... All of these package are quite simple and understandable. Most of the cryptographic family has the same pattern: first create an engine, then feed it with data and retrieve the output. // // //------------------ PROTO ----------------------------------------------------- AES_BLOCK +Proto AES_BLOCK =type Int =mode constant =pkg bios =impl native =link =desc Length of AES blocks: 16 // // //------------------ PROTO ----------------------------------------------------- Aes +Proto Aes =type Aes =mode type =pkg bios =impl native =link =desc An AES engine. // // //------------------ PROTO ----------------------------------------------------- DES_BLOCK +Proto DES_BLOCK =type Int =mode constant =pkg bios =impl native =link =desc Length of DES blocks: 8 // // //------------------ PROTO ----------------------------------------------------- Des +Proto Des =type Des =mode type =pkg bios =impl native =link =desc A DES engine. // // //------------------ PROTO ----------------------------------------------------- Rc4 +Proto Rc4 =type Rc4 =mode type =pkg bios =impl native =link =desc A RC4 engine // // //------------------ PROTO ----------------------------------------------------- Sha1 +Proto Sha1 =type Sha1 =mode type =pkg bios =impl native =link =desc A Sha1 engine // // //------------------ PROTO ----------------------------------------------------- Sha256 +Proto Sha256 =type Sha256 =mode type =pkg bios =impl native =link =desc A Sha256 engine // // //------------------ PROTO ----------------------------------------------------- Sha384 +Proto Sha384 =type Sha384 =mode type =pkg bios =impl native =link =desc A Sha384 engine // // //------------------ PROTO ----------------------------------------------------- Sha512 +Proto Sha512 =type Sha512 =mode type =pkg bios =impl native =link =desc A Sha512 engine // // //------------------ PROTO ----------------------------------------------------- aesCreate +Proto aesCreate =type fun Str -> Aes =mode function =pkg bios =impl native =link =desc This function creates an AES engine with a key. The length of the key decides the variant of AES: - 16 bytes: AES128 - 24 bytes: AES192 - 32 bytes: AES256 // +arg key =type Str =desc A binary string // +arg result =type Aes =desc An AES engine // // //------------------ PROTO ----------------------------------------------------- aesDecryptBytes +Proto aesDecryptBytes =type fun Aes Bytes Int -> Aes =mode function =pkg bios =impl native =link =desc This function decrypts 16 bytes from position offset in src. The output is stored in the engine. See [[aesOutput]] to retrieve the output. // +arg engine =type Aes =desc An AES engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg result =type Aes =desc The AES engine // // //------------------ PROTO ----------------------------------------------------- aesDecrypt +Proto aesDecrypt =type fun Aes Str Int -> Aes =mode function =pkg bios =impl native =link =desc This function decrypts 16 bytes from position offset in src. The output is stored in the engine. See [[aesOutput]] to retrieve the output. // +arg engine =type Aes =desc An AES engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg result =type Aes =desc The AES engine // // //------------------ PROTO ----------------------------------------------------- aesEncryptBytes +Proto aesEncryptBytes =type fun Aes Bytes Int -> Aes =mode function =pkg bios =impl native =link =desc This function encrypts 16 bytes from position offset in src. The output is stored in the engine. See [[aesOutput]] to fetch the output. // +arg engine =type Aes =desc An AES engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg result =type Aes =desc The AES engine // // //------------------ PROTO ----------------------------------------------------- aesEncrypt +Proto aesEncrypt =type fun Aes Str Int -> Aes =mode function =pkg bios =impl native =link =desc This function encrypts 16 bytes from position offset in src. The output is stored in the engine. See [[aesOutput]] to fetch the output. // +arg engine =type Aes =desc An AES engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg result =type Aes =desc The AES engine // // //------------------ PROTO ----------------------------------------------------- aesOutput +Proto aesOutput =type fun Aes -> Str =mode function =pkg bios =impl native =link =desc This function fetches the last 16 bytes processed by the engine. // +arg engine =type Aes =desc An AES engine // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- aesWriteBytes +Proto aesWriteBytes =type fun Aes Bytes Int -> Aes =mode function =pkg bios =impl native =link =desc This function writes the last 16 bytes processed by the engine in the buffer at position offset. // +arg engine =type Aes =desc An AES engine // +arg buffer =type Bytes =desc A buffer of bytes // +arg offset =type Int =desc A positive position in the buffer // +arg result =type Aes =desc The AES engine // // //------------------ PROTO ----------------------------------------------------- desCreate +Proto desCreate =type fun Str -> Des =mode function =pkg bios =impl native =link =desc This function creates an DES engine with a 8-bytes key. // +arg key =type Str =desc A 8-bytes binary string // +arg result =type Des =desc The DES engine // // //------------------ PROTO ----------------------------------------------------- desDecrypt +Proto desDecrypt =type fun Des Str Int -> Des =mode function =pkg bios =impl native =link =desc This function decrypts 8 bytes from position offset in src. The output is stored in the engine. See [[desOutput]] to fetch the output. // +arg engine =type Des =desc A DES engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg result =type Des =desc The DES engine // // //------------------ PROTO ----------------------------------------------------- desEncrypt +Proto desEncrypt =type fun Des Str Int -> Des =mode function =pkg bios =impl native =link =desc This function encrypts 8 bytes from position offset in src. The output is stored in the engine. See [[desOutput]] to fetch the output. // +arg engine =type Des =desc A DES engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg result =type Des =desc The DES engine // // //------------------ PROTO ----------------------------------------------------- desOutput +Proto desOutput =type fun Des -> Str =mode function =pkg bios =impl native =link =desc This function fetches the last 8 bytes processed by the engine. // +arg engine =type Des =desc A DES engine // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- desWriteBytes +Proto desWriteBytes =type fun Des Bytes Int -> Des =mode function =pkg bios =impl native =link =desc This function writes the last 8 bytes processed by the engine in the buffer at position offset. // +arg engine =type Des =desc A DES engine // +arg buffer =type Bytes =desc A buffer of bytes // +arg offset =type Int =desc A positive position in the buffer // +arg result =type Des =desc The DES engine // // //------------------ PROTO ----------------------------------------------------- Md5 +Proto Md5 =type Md5 =mode type =pkg bios =impl native =link =desc A MD5 engine. // // //------------------ PROTO ----------------------------------------------------- md5Create +Proto md5Create =type fun -> Md5 =mode function =pkg bios =impl native =link =desc This function creates a new MD5 engine. // +arg result =type Md5 =desc A new MD5 engine // // //------------------ PROTO ----------------------------------------------------- md5Output +Proto md5Output =type fun Md5 -> Str =mode function =pkg bios =impl native =link =desc This function fetches the 16 bytes hash. // +arg engine =type Md5 =desc A MD5 engine // +arg result =type Str =desc A 16-bytes binary string // // //------------------ PROTO ----------------------------------------------------- md5ProcessBytes +Proto md5ProcessBytes =type fun Md5 Bytes Int Int -> Md5 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Md5 =desc A MD5 engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Md5 =desc The MD5 engine // // //------------------ PROTO ----------------------------------------------------- md5Process +Proto md5Process =type fun Md5 Str Int Int -> Md5 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Md5 =desc A MD5 engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Md5 =desc The MD5 engine // // //------------------ PROTO ----------------------------------------------------- rc4Create +Proto rc4Create =type fun Str -> Rc4 =mode function =pkg bios =impl native =link =desc This function creates a new RC4 engine with the specified key. // +arg key =type Str =desc A string // +arg result =type Rc4 =desc A new RC4 engine // // //------------------ PROTO ----------------------------------------------------- rc4Output +Proto rc4Output =type fun Rc4 Str Int Int -> Str =mode function =pkg bios =impl native =link =desc This function processes and outputs a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Rc4 =desc A RC4 engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Str =desc A string // // //------------------ PROTO ----------------------------------------------------- rc4WriteBytes +Proto rc4WriteBytes =type fun Rc4 Bytes Int Str Int Int -> Rc4 =mode function =pkg bios =impl native =link =desc This function processes and outputs a part of src, starting at position srcOffset, with a specific length len, or until the end when len is nil. Then the function writes the result in the buffer at position bufferOffset. // +arg engine =type Rc4 =desc A RC4 engine // +arg buffer =type Bytes =desc A buffer of bytes // +arg bufferOffset =type Int =desc A positive position in the buffer // +arg src =type Str =desc A string // +arg srcOffset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Rc4 =desc The RC4 engine // // //------------------ PROTO ----------------------------------------------------- sha1Create +Proto sha1Create =type fun -> Sha1 =mode function =pkg bios =impl native =link =desc This function creates a new Sha1 engine. // +arg result =type Sha1 =desc A new Sha1 engine // // //------------------ PROTO ----------------------------------------------------- sha1Output +Proto sha1Output =type fun Sha1 -> Str =mode function =pkg bios =impl native =link =desc This function fetches the 20 bytes hash. // +arg engine =type Sha1 =desc A Sha1 engine // +arg result =type Str =desc A 20-bytes binary string // // //------------------ PROTO ----------------------------------------------------- sha1Process +Proto sha1Process =type fun Sha1 Str Int Int -> Sha1 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha1 =desc A Sha1 engine // +arg src =type Str =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha1 =desc The Sha1 engine // // //------------------ PROTO ----------------------------------------------------- sha1ProcessBytes +Proto sha1ProcessBytes =type fun Sha1 Bytes Int Int -> Sha1 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha1 =desc A Sha1 engine // +arg src =type Bytes =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha1 =desc The Sha1 engine // // //------------------ PROTO ----------------------------------------------------- sha256Create +Proto sha256Create =type fun -> Sha256 =mode function =pkg bios =impl native =link =desc This function creates a new Sha256 engine. // +arg result =type Sha256 =desc A new Sha256 engine // // //------------------ PROTO ----------------------------------------------------- sha256Output +Proto sha256Output =type fun Sha256 -> Str =mode function =pkg bios =impl native =link =desc This function fetches the 32 bytes hash. // +arg engine =type Sha256 =desc A Sha256 engine // +arg result =type Str =desc A 32-bytes binary string // // //------------------ PROTO ----------------------------------------------------- sha256ProcessBytes +Proto sha256ProcessBytes =type fun Sha256 Bytes Int Int -> Sha256 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha256 =desc A Sha256 engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha256 =desc The Sha256 engine // // //------------------ PROTO ----------------------------------------------------- sha256Process +Proto sha256Process =type fun Sha256 Str Int Int -> Sha256 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha256 =desc A Sha256 engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha256 =desc The Sha256 engine // // //------------------ PROTO ----------------------------------------------------- sha384Create +Proto sha384Create =type fun -> Sha384 =mode function =pkg bios =impl native =link =desc This function creates a new Sha384 engine. // +arg result =type Sha384 =desc A new Sha384 engine // // //------------------ PROTO ----------------------------------------------------- sha384Output +Proto sha384Output =type fun Sha384 -> Str =mode function =pkg bios =impl native =link =desc This function fetches the 48 bytes hash. // +arg engine =type Sha384 =desc A Sha384 engine // +arg result =type Str =desc A 48-bytes binary string // // //------------------ PROTO ----------------------------------------------------- sha384ProcessBytes +Proto sha384ProcessBytes =type fun Sha384 Bytes Int Int -> Sha384 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha384 =desc A Sha384 engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha384 =desc The Sha384 engine // // //------------------ PROTO ----------------------------------------------------- sha384Process +Proto sha384Process =type fun Sha384 Str Int Int -> Sha384 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha384 =desc A Sha384 engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha384 =desc The Sha384 engine // // //------------------ PROTO ----------------------------------------------------- sha512Create +Proto sha512Create =type fun -> Sha512 =mode function =pkg bios =impl native =link =desc This function creates a new Sha512 engine. // +arg result =type Sha512 =desc A new Sha512 engine // // //------------------ PROTO ----------------------------------------------------- sha512Output +Proto sha512Output =type fun Sha512 -> Str =mode function =pkg bios =impl native =link =desc This function fetches the 64 bytes hash. // +arg engine =type Sha512 =desc A Sha512 engine // +arg result =type Str =desc A 64-bytes binary string // // //------------------ PROTO ----------------------------------------------------- sha512ProcessBytes +Proto sha512ProcessBytes =type fun Sha512 Bytes Int Int -> Sha512 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha512 =desc A Sha512 engine // +arg src =type Bytes =desc An array of bytes // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha512 =desc The Sha512 engine // // //------------------ PROTO ----------------------------------------------------- sha512Process +Proto sha512Process =type fun Sha512 Str Int Int -> Sha512 =mode function =pkg bios =impl native =link =desc This function processes a part of src, starting at position offset, with a specific length len, or until the end when len is nil. // +arg engine =type Sha512 =desc A Sha512 engine // +arg src =type Str =desc A string // +arg offset =type Int =desc A positive position in the string // +arg len =type Int =desc A length or nil. // +arg result =type Sha512 =desc The Sha512 engine // // //------------------ PROTO ----------------------------------------------------- strCrc32 +Proto strCrc32 =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the crc32 checksum of a string, with last as the initial value of the checksum. When you need to compute the checksum of a string, you may call [[strCrc32]] only once, with last=0. You may alternately split the string and chains the calls to [[strCrc32]]. The first time last is 0, then last is the result of the previous call. // +arg src =type Str =desc A string // +arg last =type Int =desc The current crc checksum // +arg result =type Int =desc The new crc checksum // // //------------------ PROTO ----------------------------------------------------- bytesCrc32 +Proto bytesCrc32 =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the crc32 checksum of an array of bytes, with last as the initial value of the checksum. When you need to compute the checksum of an array of bytes, you may call [[bytesCrc32]] only once, with last=0. You may alternately split the string and chains the calls to [[bytesCrc32]]. The first time last is 0, then last is the result of the previous call. // +arg src =type Bytes =desc Any array of bytes // +arg last =type Int =desc The current crc checksum // +arg result =type Int =desc The new crc checksum // // //------------------ PROTO ----------------------------------------------------- strAdler32 +Proto strAdler32 =type fun Str Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the adler32 checksum of a string, with last as the initial value of the checksum. When you need to compute the checksum of a string, you may call [[strAdler32]] only once, with last=1. You may alternately split the string and chains the calls to [[strAdler32]]. The first time last is 1, then last is the result of the previous call. // +arg src =type Str =desc A string // +arg last =type Int =desc The current adler checksum // +arg result =type Int =desc The new adler checksum // // //------------------ PROTO ----------------------------------------------------- bytesAdler32 +Proto bytesAdler32 =type fun Bytes Int -> Int =mode function =pkg bios =impl native =link =desc This function returns the adler32 checksum of an array of bytes, with last as the initial value of the checksum. When you need to compute the checksum of an array of bytes, you may call [[bytesAdler32]] only once, with last=1. You may alternately split the string and chains the calls to [[bytesAdler32]]. The first time last is 1, then last is the result of the previous call. // +arg src =type Bytes =desc Any array of bytes // +arg last =type Int =desc The current adler checksum // +arg result =type Int =desc The new adler checksum // // //------------------ PROTO ----------------------------------------------------- bytesCrc7 +Proto bytesCrc7 =type fun Bytes Int -> Int =mode Function =pkg bios =impl native =link =desc This function returns the crc7 checksum of an array of bytes, with last as the initial value of the checksum. When you need to compute the checksum of an array of bytes, you may call [[bytesCrc7]] only once, with last=0. You may alternately split the string and chains the calls to [[bytesCrc7]]. The first time last is 0, then last is the result of the previous call. // +arg src =type Bytes =desc Any array of bytes // +arg last =type Int =desc The current crc7 checksum // +arg result =type Int =desc The new crc7 checksum // // //------------------ PROTO ----------------------------------------------------- strCrc7 +Proto strCrc7 =type fun Str Int -> Int =mode Function =pkg bios =impl native =link =desc This function returns the crc7 checksum of a string, with last as the initial value of the checksum. When you need to compute the checksum of a string, you may call [[strCrc7]] only once, with last=0. You may alternately split the string and chains the calls to [[strCrc7]]. The first time last is 0, then last is the result of the previous call. // +arg src =type Str =desc A string // +arg last =type Int =desc The current crc7 checksum // +arg result =type Int =desc The new crc7 checksum