module Cryptokit:sig
..end
ocamlc unix.cma nums.cma cryptokit.cma
or
ocamlopt unix.cmxa nums.cmxa cryptokit.cmxa
.class type transform =object
..end
val transform_string : transform -> string -> string
transform_string t s
runs the string s
through the
transform t
and returns the transformed string.
The transform t
is wiped before returning, hence can
no longer be used for further transformations.val transform_channel : transform ->
?len:int -> Pervasives.in_channel -> Pervasives.out_channel -> unit
transform_channel t ic oc
reads characters from input channel ic
,
runs them through the transform t
, and writes the transformed
data to the output channel oc
. If the optional len
argument
is provided, exactly len
characters are read from ic
and
transformed; End_of_file
is raised if ic
does not contain
at least len
characters. If len
is not provided, ic
is
read all the way to end of file.
The transform t
is wiped before returning, hence can
no longer be used for further transformations.val compose : transform -> transform -> transform
class type hash =object
..end
val hash_string : hash -> string -> string
hash_string h s
runs the string s
through the hash function h
and returns the hash value of s
.
The hash h
is wiped before returning, hence can
no longer be used for further hash computations.val hash_channel : hash -> ?len:int -> Pervasives.in_channel -> string
hash_channel h ic
reads characters from the input channel ic
,
computes their hash value and returns it.
If the optional len
argument is provided, exactly len
characters
are read from ic
and hashed; End_of_file
is raised if ic
does not contain at least len
characters.
If len
is not provided, ic
is read all the way to end of file.
The hash h
is wiped before returning, hence can
no longer be used for further hash computations.module Random:sig
..end
Random
module provides random and pseudo-random number generators
suitable for generating cryptographic keys, nonces, or challenges.
module Padding:sig
..end
Padding
module defines a generic interface
for padding input data to an integral number of blocks,
as well as two popular padding schemes.
module Cipher:sig
..end
Cipher
module implements the AES, DES, Triple-DES, ARCfour
and Blowfish symmetric ciphers.
module Hash:sig
..end
Hash
module implements unkeyed cryptographic hashes (SHA-1,
SHA-256, SHA-512, SHA-3, RIPEMD-160 and MD5), also known as
message digest functions.
module MAC:sig
..end
MAC
module implements message authentication codes, also
known as keyed hash functions.
module RSA:sig
..end
RSA
module implements RSA public-key cryptography.
module DH:sig
..end
DH
module implements Diffie-Hellman key agreement.
module Block:sig
..end
Block
module provides classes that implements
popular block ciphers, chaining modes, and wrapping of a block cipher
as a general transform or as a hash function.
module Stream:sig
..end
Stream
module provides classes that implement
the ARCfour stream cipher, and the wrapping of a stream cipher
as a general transform.
module Base64:sig
..end
Base64
module supports the encoding and decoding of
binary data in base 64 format, using only alphanumeric
characters that can safely be transmitted over e-mail or
in URLs.
module Hexa:sig
..end
Hexa
module supports the encoding and decoding of
binary data as hexadecimal strings.
module Zlib:sig
..end
Zlib
module supports the compression and decompression
of data, using the zlib
library.
type
error =
| |
Wrong_key_size |
(* |
The key is too long or too short for the given cipher.
| *) |
| |
Wrong_IV_size |
(* |
The initialization vector does not have the same size as
the block size.
| *) |
| |
Wrong_data_length |
(* |
The total length of the input data for a transform is not an
integral multiple of the input block size.
| *) |
| |
Bad_padding |
(* |
Incorrect padding bytes were found after decryption.
| *) |
| |
Output_buffer_overflow |
(* |
The output buffer for a transform exceeds the maximal length
of a Caml string.
| *) |
| |
Incompatible_block_size |
(* |
A combination of two block ciphers was attempted whereby
the ciphers have different block sizes, while they must have
the same.
| *) |
| |
Number_too_long |
(* |
Denotes an internal error in RSA key generation or encryption.
| *) |
| |
Seed_too_short |
(* |
The seed given to a pseudo random number generator is too short.
| *) |
| |
Message_too_long |
(* |
The message passed to RSA encryption or decryption is greater
than the modulus of the RSA key
| *) |
| |
Bad_encoding |
(* |
Illegal characters were found in an encoding of binary data
such as base 64 or hexadecimal.
| *) |
| |
Compression_error of |
(* |
Error during compression or decompression.
| *) |
| |
No_entropy_source |
(* | *) |
|
| |
Entropy_source_closed |
(* |
End of file on a device or EGD entropy source.
| *) |
| |
Compression_not_supported |
(* |
The data compression functions are not available.
| *) |
exception Error of error
val wipe_bytes : bytes -> unit
wipe_bytes b
overwrites b
with zeroes. Can be used
to reduce the memory lifetime of sensitive data.val wipe_string : string -> unit
wipe_string s
overwrites s
with zeroes. Can be used
to reduce the memory lifetime of sensitive data.
Note that strings are normally immutable and this operation
violates this immutability property. Therefore, this is
an unsafe operation, and it should be used only by code that
is the only owner of the string s
. See Bytes.unsafe_of_string
for more details on the ownership policy.val string_equal : string -> string -> bool
string_equal s1 s2
returns true
if the strings s1
and s2
have the same length and contain the same characters.
The execution time of this function is determined by the
lengths of s1
and s2
, but is independent of their contents.val bytes_equal : bytes -> bytes -> bool
Cryptokit.string_equal
, but for byte sequences.val xor_bytes : bytes -> int -> bytes -> int -> int -> unit
xor_bytes src spos dst dpos len
performs the xor (exclusive or)
of characters spos, ..., spos + len - 1
of src
with characters dpos, ..., dpos + len - 1
of dst
,
storing the result in dst
starting at position dpos
.val xor_string : string -> int -> bytes -> int -> int -> unit
xor_bytes
, but the source is a string instead of a
byte array.val mod_power : string -> string -> string -> string
mod_power a b c
computes a^b mod c
, where the
strings a
, b
, c
and the result are viewed as
arbitrary-precision integers in big-endian format.
Requires a < c
.val mod_mult : string -> string -> string -> string
mod_mult a b c
computes a*b mod c
, where the
strings a
, b
, c
and the result are viewed as
arbitrary-precision integers in big-endian format.