### Cryptonite Tutorial Example in Haskell Source: https://hackage.haskell.org/package/crypton/ite-cd/docs A tutorial or example demonstrating the usage of the cryptonite Haskell package. This would typically showcase common cryptographic operations and how to use the library's functions. It is part of the cryptonite package. ```Haskell module Crypto.Tutorial where -- Example usage and tutorials for the cryptonite library -- ... (example code snippets would be here) ``` -------------------------------- ### Crypton Tutorial and Examples Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs This section points to tutorial resources for using the Crypton package. ```APIDOC ## Crypton Tutorial ### Description Provides guidance and examples on how to use the Crypton package. ### Modules - `Crypto.Tutorial` ``` -------------------------------- ### Connect via SOCKS Proxy Source: https://hackage.haskell.org/package/crypton/-connection-0.4 Establishes a network connection to a specified host and port through a SOCKS proxy. This example demonstrates how to configure the `ConnectionParams` to use a simple SOCKS proxy running on localhost at port 1080. Requires the 'network-connection' library. ```haskell con <- connectTo ctx $ ConnectionParams { connectionHostname = "www.example.com", connectionPort = 4567, connectionUseSecure = Nothing, connectionUseSocks = Just $ SockSettingsSimple "localhost" 1080 } ``` -------------------------------- ### Connect via SOCKS Proxy in Haskell Source: https://hackage.haskell.org/package/crypton/-connection Establishes a network connection to a specified host and port through a SOCKS proxy. This example demonstrates configuring the connection parameters to include SOCKS proxy details. Requires the 'crypton' library. ```haskell con <- connectTo ctx $ ConnectionParams { connectionHostname = "www.example.com", connectionPort = 4567, connectionUseSecure = Nothing, connectionUseSocks = Just $ SockSettingsSimple "localhost" 1080 } ``` -------------------------------- ### Implement STARTTLS in Haskell Source: https://hackage.haskell.org/package/crypton/-connection Initiates an insecure connection, sends initial commands, switches to TLS using STARTTLS, and then sends secure data. This is useful for protocols like IMAP and SMTP. Requires 'crypton', 'bytestring', and 'default' libraries. ```haskell {-# LANGUAGE OverloadedStrings #-} import qualified Data.ByteString as B import Data.ByteString.Char8 () import Network.Connection import Data.Default main = do ctx <- initConnectionContext con <- connectTo ctx $ ConnectionParams { connectionHostname = "www.example.com", connectionPort = 4567, connectionUseSecure = Nothing, connectionUseSocks = Nothing } -- talk to the other side with no TLS: says hello and starttls connectionPut con "HELLO\n" connectionPut con "STARTTLS\n" -- switch to TLS connectionSetSecure ctx con def -- the connection is from now on using TLS, we can send secret for example connectionPut con "PASSWORD 123\n" connectionClose con ``` -------------------------------- ### Establish SSL/TLS Connection in Haskell Source: https://hackage.haskell.org/package/crypton/-connection Connects to a specified host and port using SSL/TLS encryption. This involves setting the 'connectionUseSecure' field to 'Just def' in the connection parameters. Requires the 'crypton' and 'default' libraries. ```haskell con <- connectTo ctx $ ConnectionParams { connectionHostname = "www.example.com", connectionPort = 4567, connectionUseSecure = Just def, connectionUseSocks = Nothing } ``` -------------------------------- ### Establish Basic Network Connection in Haskell Source: https://hackage.haskell.org/package/crypton/-connection Connects to a specified host and port without SOCKS or TLS, sends a byte, receives a byte, prints it, and closes the connection. Requires the 'crypton' and 'bytestring' libraries. ```haskell import qualified Data.ByteString as B import Network.Connection import Data.Default main = do ctx <- initConnectionContext con <- connectTo ctx $ ConnectionParams { connectionHostname = "www.example.com", connectionPort = 4567, connectionUseSecure = Nothing, connectionUseSocks = Nothing } connectionPut con (B.singleton 0xa) r <- connectionGet con 1 putStrLn $ show r connectionClose con ``` -------------------------------- ### Blake2s Hashing Methods (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-IO Details the methods for the Blake2s hash algorithm. It exposes functions to get the block size, digest size, and internal context size. It also includes low-level functions for managing the hash context during computation. ```Haskell hashBlockSize :: Blake2s bitlen -> Int hashDigestSize :: Blake2s bitlen -> Int hashInternalContextSize :: Blake2s bitlen -> Int hashInternalInit :: Ptr (Context (Blake2s bitlen)) -> IO () hashInternalUpdate :: Ptr (Context (Blake2s bitlen)) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context (Blake2s bitlen)) -> Ptr (Digest (Blake2s bitlen)) -> IO () ``` -------------------------------- ### Runtime Proof for IsAtMost Constraint in Haskell Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Number-Nat Provides a function `isAtMost` to get a runtime proof for the `IsAtMost` type-level constraint. It takes two proxy arguments representing the `value` and `bound` natural numbers. If `value <= bound` holds at the type level, it returns `Just` a proof; otherwise, it returns `Nothing`. ```Haskell isAtMost :: forall (value :: Nat) (bound :: Nat) proxy proxy'. (KnownNat value, KnownNat bound) => proxy value -> proxy' bound -> Maybe ((value <=? bound) :~: 'True) ``` -------------------------------- ### TripleDES Cipher Initialization and Properties (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Cipher-TripleDES Demonstrates how to initialize and query properties for different TripleDES cipher modes. This includes getting the cipher name, key size, and block size. It relies on the ByteArray and CryptoFailable types from the crypton library. ```Haskell cipherInit :: ByteArray key => key -> CryptoFailable DES_EEE3 Source # cipherName :: DES_EEE3 -> String Source # cipherKeySize :: DES_EEE3 -> KeySizeSpecifier Source # blockSize :: DES_EEE3 -> Int Source # ``` ```Haskell cipherInit :: ByteArray key => key -> CryptoFailable DES_EDE3 Source # cipherName :: DES_EDE3 -> String Source # cipherKeySize :: DES_EDE3 -> KeySizeSpecifier Source # blockSize :: DES_EDE3 -> Int Source # ``` ```Haskell cipherInit :: ByteArray key => key -> CryptoFailable DES_EEE2 Source # cipherName :: DES_EEE2 -> String Source # cipherKeySize :: DES_EEE2 -> KeySizeSpecifier Source # blockSize :: DES_EEE2 -> Int Source # ``` ```Haskell cipherInit :: ByteArray key => key -> CryptoFailable DES_EDE2 Source # cipherName :: DES_EDE2 -> String Source # cipherKeySize :: DES_EDE2 -> KeySizeSpecifier Source # blockSize :: DES_EDE2 -> Int Source # ``` -------------------------------- ### Install Crypton with Disabled AESNI Source: https://hackage.haskell.org/package/crypton/-0 This command installs the Crypton package while explicitly disabling AESNI support. This is an alternative method to ensure AESNI is not used during installation, which can be helpful for compatibility or specific build environments. ```bash cabal install --constraint="crypton -support_aesni" ``` -------------------------------- ### Install Cryptonite with AESNI Constraint Source: https://hackage.haskell.org/package/crypton/ite-0.15 This snippet shows how to install the Cryptonite package while explicitly disabling AESNI support. This is achieved by adding a package constraint to the `cabal install` command, ensuring that the build process avoids AESNI. This is an alternative to configuring the build. ```bash cabal install --constraint="cryptonite -support_aesni" ``` -------------------------------- ### AES256 Cipher Initialization and Properties (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Cipher-AES Defines how to initialize and get properties of the AES256 cipher. It requires a key and provides methods to get the cipher name and key size. ```haskell cipherInit :: ByteArray key => key -> CryptoFailable AES256 cipherName :: AES256 -> String cipherKeySize :: AES256 -> KeySizeSpecifier ``` -------------------------------- ### Blake2s Hashing Instances Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms This section details the instances for the Blake2s hashing algorithm, covering Data, Show, HashBlake2, and HashAlgorithm. ```APIDOC ## Blake2s Hashing Instances ### Description Details on the `Data`, `Show`, `HashBlake2`, and `HashAlgorithm` instances for `Blake2s bitlen`. ### Instances #### Data Instance Provides methods for accessing the internal structure of `Blake2s bitlen`. **Methods:** - `gfoldl` - `gunfold` - `toConstr` - `dataTypeOf` - `dataCast1` - `dataCast2` - `gmapT` - `gmapQl` - `gmapQr` - `gmapQ` - `gmapQi` - `gmapM` - `gmapMp` - `gmapMo` #### Show Instance Defines how to represent `Blake2s bitlen` values as strings. **Methods:** - `showsPrec` - `show` - `showList` #### HashBlake2 Instance Specifies properties related to Blake2 hashing for `Blake2s bitlen`. **Constraints:** - `IsDivisibleBy8 bitlen` - `KnownNat bitlen` - `IsAtLeast bitlen 8` - `IsAtMost bitlen 256` **Methods:** - `blake2InternalKeyedInit :: Ptr (Context (Blake2s bitlen)) -> Ptr Word8 -> Word32 -> IO ()` #### HashAlgorithm Instance Defines the core hashing algorithm properties for `Blake2s bitlen`. **Constraints:** - `IsDivisibleBy8 bitlen` - `KnownNat bitlen` - `IsAtLeast bitlen 8` - `IsAtMost bitlen 256` **Associated Types:** - `type HashBlockSize (Blake2s bitlen) = 64` - `type HashDigestSize (Blake2s bitlen)` - `type HashInternalContextSize (Blake2s bitlen) = 136` **Methods:** - `hashBlockSize :: Blake2s bitlen -> Int` - `hashDigestSize :: Blake2s bitlen -> Int` - `hashInternalContextSize :: Blake2s bitlen -> Int` - `hashInternalInit :: Ptr (Context (Blake2s bitlen)) -> IO ()` - `hashInternalUpdate :: Ptr (Context (Blake2s bitlen)) -> Ptr Word8 -> Word32 -> IO ()` - `hashInternalFinalize :: Ptr (Context (Blake2s bitlen)) -> Ptr (Digest (Blake2s bitlen)) -> IO ()` ``` -------------------------------- ### Get Current OTPTime using time package Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-OTP This snippet shows how to get the current OTPTime using the 'time' package. It imports `getPOSIXTime` and converts the POSIX time to an `OTPTime` by flooring the value. ```haskell import Data.Time.Clock.POSIX let getOTPTime = getPOSIXTime >>= \t -> return (floor t :: OTPTime) ``` -------------------------------- ### SHA3_256 Show Instance Methods Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms This section outlines the methods for the Show instance of SHA3_256. These functions enable the conversion of SHA3_256 values into human-readable String representations, essential for debugging and display purposes. ```Haskell showsPrec :: Int -> SHA3_256 -> ShowS show :: SHA3_256 -> String showList :: [SHA3_256] -> ShowS ``` -------------------------------- ### SHA1 Hash Algorithm Instances and Methods Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms This snippet details the various instances and methods associated with the SHA1 hash algorithm. It includes instances for Data, Show, HashAlgorithm, and HashAlgorithmPrefix, outlining specific functions for context manipulation, digest generation, and size retrieval. Dependencies include the 'crypton' package and potentially 'base' for core Haskell types. ```haskell instance Data SHA1 where -- Methods for Data instance (gfoldl, gunfold, toConstr, dataTypeOf, etc.) instance Show SHA1 where -- Methods for Show instance (showsPrec, show, showList) instance HashAlgorithm SHA1 where hashBlockSize :: SHA1 -> Int hashDigestSize :: SHA1 -> Int hashInternalContextSize :: SHA1 -> Int hashInternalInit :: Ptr (Context SHA1) -> IO () hashInternalUpdate :: Ptr (Context SHA1) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context SHA1) -> Ptr (Digest SHA1) -> IO () instance HashAlgorithmPrefix SHA1 where hashInternalFinalizePrefix :: Ptr (Context SHA1) -> Ptr Word8 -> Word32 -> Word32 -> Ptr (Digest SHA1) -> IO () -- Type definitions for HashAlgorithm instances type HashBlockSize SHA1 = 64 type HashDigestSize SHA1 = 20 type HashInternalContextSize SHA1 = 96 ``` -------------------------------- ### Blake2b Data and Show Instances (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Defines the Data and Show instances for Blake2b. The Data instance provides generic programming capabilities, while the Show instance allows Blake2b values to be converted to strings for display. ```haskell instance KnownNat bitlen => Data (Blake2b bitlen) where gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Blake2b bitlen -> c (Blake2b bitlen) gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Blake2b bitlen) toConstr :: Blake2b bitlen -> Constr dataTypeOf :: Blake2b bitlen -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Blake2b bitlen)) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Blake2b bitlen)) gmapT :: (forall b. Data b => b -> b) -> Blake2b bitlen -> Blake2b bitlen gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Blake2b bitlen -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Blake2b bitlen -> r gmapQ :: (forall d. Data d => d -> u) -> Blake2b bitlen -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> Blake2b bitlen -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> Blake2b bitlen -> m (Blake2b bitlen) gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Blake2b bitlen -> m (Blake2b bitlen) gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Blake2b bitlen -> m (Blake2b bitlen) instance Show (Blake2b bitlen) where showsPrec :: Int -> Blake2b bitlen -> ShowS show :: Blake2b bitlen -> String showList :: [Blake2b bitlen] -> ShowS ``` -------------------------------- ### Get Curve Size in Bits for Curve_P521R1 in Haskell Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Returns the size in bits of the Curve_P521R1 elliptic curve. ```Haskell curveSizeBits :: proxy Curve_P521R1 -> Int ``` -------------------------------- ### Crypton Package Overview Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs This entry provides a high-level overview of the Crypton Haskell package, including its main module and tutorial. It serves as an entry point for users to understand the package structure and learn how to use its functionalities. ```Haskell module Crypto.Hash ( module Crypto.Hash.SHA384, module Crypto.Hash.SHA512, module Crypto.Hash.SHA512t, module Crypto.Hash.SHAKE, module Crypto.Hash.Skein256, module Crypto.Hash.Skein512, module Crypto.Hash.Tiger, module Crypto.Hash.Whirlpool, module Crypto.Hash.Types ) where import Crypto.Hash.SHA384 import Crypto.Hash.SHA512 import Crypto.Hash.SHA512t import Crypto.Hash.SHAKE import Crypto.Hash.Skein256 import Crypto.Hash.Skein512 import Crypto.Hash.Tiger import Crypto.Hash.Whirlpool import Crypto.Hash.Types -- Main module for cryptographic hash functions. module Crypto.Tutorial ( runTutorial ) where -- | Runs the Crypton package tutorial. runTutorial :: IO () runTutorial = putStrLn "Running Crypton tutorial..." ``` -------------------------------- ### Get Curve Size in Bits for Curve_P384R1 in Haskell Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Returns the size in bits of the Curve_P384R1 elliptic curve. ```Haskell curveSizeBits :: proxy Curve_P384R1 -> Int ``` -------------------------------- ### Blake2bp Hashing Methods (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-IO Provides methods for interacting with the Blake2bp hash algorithm. This includes retrieving block size, digest size, and internal context size, as well as functions for initializing, updating, and finalizing the hash computation using mutable contexts. ```Haskell hashBlockSize :: Blake2bp bitlen -> Int hashDigestSize :: Blake2bp bitlen -> Int hashInternalContextSize :: Blake2bp bitlen -> Int hashInternalInit :: Ptr (Context (Blake2bp bitlen)) -> IO () hashInternalUpdate :: Ptr (Context (Blake2bp bitlen)) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context (Blake2bp bitlen)) -> Ptr (Digest (Blake2bp bitlen)) -> IO () ``` -------------------------------- ### Get Curve Size in Bits for Curve_Edwards25519 in Haskell Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Returns the size in bits of the Curve_Edwards25519 elliptic curve. ```Haskell curveSizeBits :: proxy Curve_Edwards25519 -> Int ``` -------------------------------- ### MD2 Hash Algorithm Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Documentation for the MD2 cryptographic hash algorithm, including its instances for Data, Show, HashAlgorithm, and HashAlgorithmASN1. ```APIDOC ## MD2 Hash Algorithm ### Description Documentation for the MD2 cryptographic hash algorithm. This section details its instances for various type classes and its associated type definitions. ### Instances #### Data Instance Provides methods for generic data manipulation. - `gfoldl` - `gunfold` - `toConstr` - `dataTypeOf` - `dataCast1` - `dataCast2` - `gmapT` - `gmapQl` - `gmapQr` - `gmapQ` - `gmapQi` - `gmapM` - `gmapMp` - `gmapMo` #### Show Instance Provides methods for converting MD2 to a String representation. - `showsPrec` - `show` - `showList` #### HashAlgorithm Instance Defines properties and methods related to the MD2 hash algorithm. - **Associated Types**: - `HashBlockSize MD2`: The size of a hash block in bytes. Defined as `16`. - `HashDigestSize MD2`: The size of the hash digest in bytes. Defined as `16`. - `HashInternalContextSize MD2`: The internal context size in bytes. Defined as `96`. - **Methods**: - `hashBlockSize :: MD2 -> Int` - `hashDigestSize :: MD2 -> Int` - `hashInternalContextSize :: MD2 -> Int` - `hashInternalInit :: Ptr (Context MD2) -> IO ()` - `hashInternalUpdate :: Ptr (Context MD2) -> Ptr Word8 -> Word32 -> IO ()` - `hashInternalFinalize :: Ptr (Context MD2) -> Ptr (Digest MD2) -> IO ()` #### HashAlgorithmASN1 Instance Provides ASN.1 related functionality for the MD2 hash algorithm. - `hashDigestASN1 :: ByteArray out => Digest MD2 -> out` - **Associated Types**: - `HashBlockSize MD2`: Defined as `16`. - `HashDigestSize MD2`: Defined as `16`. - `HashInternalContextSize MD2`: Defined as `96`. ``` -------------------------------- ### Get Curve Order Bits for Curve_P384R1 Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Returns the number of bits in the order of the P-384R1 elliptic curve. This is a fundamental property of the curve. ```Haskell curveOrderBits :: proxy Curve_P384R1 -> Int ``` -------------------------------- ### SHAKE256 Hashing Instances and Methods (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Details the instances for SHAKE256, including Data, Show, HashSHAKE, and HashAlgorithm. It outlines methods for context manipulation, outputting digest sizes, and internal hashing operations. ```Haskell instance KnownNat bitlen => Data (SHAKE256 bitlen) instance Show (SHAKE256 bitlen) instance KnownNat bitlen => HashSHAKE (SHAKE256 bitlen) instance KnownNat bitlen => HashAlgorithm (SHAKE256 bitlen) -- Methods for HashAlgorithm instance hashBlockSize :: SHAKE256 bitlen -> Int hashDigestSize :: SHAKE256 bitlen -> Int hashInternalContextSize :: SHAKE256 bitlen -> Int hashInternalInit :: Ptr (Context (SHAKE256 bitlen)) -> IO () hashInternalUpdate :: Ptr (Context (SHAKE256 bitlen)) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context (SHAKE256 bitlen)) -> Ptr (Digest (SHAKE256 bitlen)) -> IO () -- Associated types for HashAlgorithm instance type HashBlockSize (SHAKE256 bitlen) = 136 type HashDigestSize (SHAKE256 bitlen) type HashInternalContextSize (SHAKE256 bitlen) = 344 ``` -------------------------------- ### Get Elliptic Curve Size in Bits Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Retrieves the size of the elliptic curve in bits. This is a fundamental property of the curve used in cryptographic calculations. ```haskell curveSizeBits :: proxy curve -> Int ``` -------------------------------- ### Crypto.Hash.Tiger Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Documentation for the Tiger hash algorithm, including its instances for Data, Show, and HashAlgorithm. ```APIDOC ## Crypto.Hash.Tiger ### Description Documentation for the Tiger hash algorithm, including its instances for Data, Show, and HashAlgorithm. ### Instances #### Data Tiger Provides methods for generic data manipulation. - **gfoldl** (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tiger -> c Tiger - **gunfold** (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Tiger - **toConstr** Tiger -> Constr - **dataTypeOf** Tiger -> DataType - **dataCast1** (Typeable t => (forall d. Data d => c (t d))) -> Maybe (c Tiger) - **dataCast2** (Typeable t => (forall d e. (Data d, Data e) => c (t d e))) -> Maybe (c Tiger) - **gmapT** (forall b. Data b => b -> b) -> Tiger -> Tiger - **gmapQl** (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tiger -> r - **gmapQr** (forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tiger -> r) - **gmapQ** (forall d. Data d => d -> u) -> Tiger -> [u] - **gmapQi** Int -> (forall d. Data d => d -> u) -> Tiger -> u - **gmapM** Monad m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger - **gmapMp** MonadPlus m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger - **gmapMo** MonadPlus m => (forall d. Data d => d -> m d) -> Tiger -> m Tiger #### Show Tiger Provides methods for displaying Tiger values. - **showsPrec** Int -> Tiger -> ShowS - **show** Tiger -> String - **showList** [Tiger] -> ShowS #### HashAlgorithm Tiger Defines the properties and methods for the Tiger hash algorithm. - **Associated Types**: - **HashBlockSize** Tiger = 64 - **HashDigestSize** Tiger = 24 - **HashInternalContextSize** Tiger = 96 - **Methods**: - **hashBlockSize** :: Tiger -> Int - **hashDigestSize** :: Tiger -> Int - **hashInternalContextSize** :: Tiger -> Int - **hashInternalInit** :: Ptr (Context Tiger) -> IO () - **hashInternalUpdate** :: Ptr (Context Tiger) -> Ptr Word8 -> Word32 -> IO () - **hashInternalFinalize** :: Ptr (Context Tiger) -> Ptr (Digest Tiger) -> IO () ### Constants - **HashBlockSize** :: Tiger = 64 - **HashDigestSize** :: Tiger = 24 - **HashInternalContextSize** :: Tiger = 96 ``` -------------------------------- ### Get X-coordinate of ECC Point for Curve_P384R1 Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Extracts the x-coordinate of a point on the P-384R1 elliptic curve. Returns Nothing if the point is the point at infinity. ```Haskell pointX :: proxy Curve_P384R1 -> Point Curve_P384R1 -> Maybe (Scalar Curve_P384R1) ``` -------------------------------- ### Whirlpool Hash Algorithm Instances and Methods Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms This snippet outlines the instances for the Whirlpool data type, including Data, Show, and HashAlgorithm. It specifies associated types like block size, digest size, and context size, along with the low-level IO methods for initializing, updating, and finalizing the hash computation. ```Haskell instance Data Whirlpool where gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Whirlpool -> c Whirlpool gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Whirlpool toConstr :: Whirlpool -> Constr dataTypeOf :: Whirlpool -> DataType dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Whirlpool) dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Whirlpool) gmapT :: (forall b. Data b => b -> b) -> Whirlpool -> Whirlpool gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Whirlpool -> r gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Whirlpool -> r gmapQ :: (forall d. Data d => d -> u) -> Whirlpool -> [u] gmapQi :: Int -> (forall d. Data d => d -> u) -> Whirlpool -> u gmapM :: Monad m => (forall d. Data d => d -> m d) -> Whirlpool -> m Whirlpool gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Whirlpool -> m Whirlpool gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Whirlpool -> m Whirlpool instance Show Whirlpool where showsPrec :: Int -> Whirlpool -> ShowS show :: Whirlpool -> String showList :: [Whirlpool] -> ShowS instance HashAlgorithm Whirlpool where type HashBlockSize Whirlpool = 64 type HashDigestSize Whirlpool = 64 type HashInternalContextSize Whirlpool = 168 hashBlockSize :: Whirlpool -> Int hashDigestSize :: Whirlpool -> Int hashInternalContextSize :: Whirlpool -> Int hashInternalInit :: Ptr (Context Whirlpool) -> IO () hashInternalUpdate :: Ptr (Context Whirlpool) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context Whirlpool) -> Ptr (Digest Whirlpool) -> IO () ``` -------------------------------- ### Default TOTP Parameters Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-OTP Provides a default set of parameters for TOTP generation using the SHA1 hash algorithm. This is a convenient starting point for TOTP implementations. ```haskell defaultTOTPParams :: TOTPParams SHA1 ``` -------------------------------- ### PrivateKey Instances Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-PubKey-Rabin-Basic Details the instances for the PrivateKey data type, including GHC.Generics, Read, Show, and Eq. ```APIDOC ## PrivateKey Instances ### Description This section details the available instances for the `PrivateKey` data type, providing information on its generic programming capabilities, how it can be read from and shown as strings, and how equality is determined. ### Instances #### GHC.Generics Provides generic programming functions for `PrivateKey`. - `gfoldl` - `gunfold` - `toConstr` - `dataTypeOf` - `dataCast1` - `dataCast2` - `gmapT` - `gmapQl` - `gmapQr` - `gmapQ` - `gmapQi` - `gmapM` - `gmapMp` - `gmapMo` #### Read Defines how to parse a `PrivateKey` from a string representation. - `readsPrec` - `readList` - `readPrec` - `readListPrec` #### Show Defines how to convert a `PrivateKey` to its string representation. - `showsPrec` - `show` - `showList` #### Eq Defines equality comparison for `PrivateKey`. - `(==)` - `(/=)` ### Source Defined in `Crypto.PubKey.Rabin.Basic` ``` -------------------------------- ### Get X-coordinate of Point for Curve_P256R1 Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Extracts the X-coordinate of a Point on Curve_P256R1. Points on elliptic curves are typically represented by their (x, y) coordinates. This function returns the X-coordinate as a Maybe Scalar. ```haskell pointX :: proxy Curve_P256R1 -> Point Curve_P256R1 -> Maybe (Scalar Curve_P256R1) ``` -------------------------------- ### Get Curve Size in Bits for Curve_P256R1 Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Retrieves the size of the Curve_P256R1 in bits. This is a static property of the curve and does not require any monadic context. It returns an Int representing the bit size. ```haskell curveSizeBits :: proxy Curve_P256R1 -> Int ``` -------------------------------- ### Crypto.Number.F2m Module Documentation Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Number-F2m Provides basic arithmetic operations over F₂m, including addition, multiplication, squaring, exponentiation, modulo, square root, inversion, division, and solving quadratic equations. ```APIDOC ## Crypto.Number.F2m Module ### Description This module provides basic arithmetic operations over F₂m. Performance is not optimal and it doesn't provide protection against timing attacks. The `m` parameter is implicitly derived from the irreducible polynomial where applicable. ### Types * **BinaryPolynomial** (Integer) * Description: Binary Polynomial represented by an integer. ### Functions * **addF2m** * Description: Addition over F₂m. This is just a synonym of `xor`. * Method: N/A (Function Signature) * Signature: `Integer -> Integer -> Integer` * **mulF2m** * Description: Multiplication over F₂m. This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` * `Integer` * Returns: `Integer` * **squareF2m'** * Description: Squaring over F₂m without reduction by modulo. The implementation utilizes the fact that for binary polynomial S(x) we have S(x)² = S(x²). In other words, insert a zero bit between every bits of argument: 1101 -> 1010001. This function is undefined for negative arguments, because their bit representation is platform-dependent. * Method: N/A (Function Signature) * Signature: `Integer -> Integer` * **squareF2m** * Description: Squaring over F₂m. This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` * Returns: `Integer` * **powF2m** * Description: Exponentiation in F₂m by computing `a^b mod fx`. This implements an exponentiation by squaring based solution. It inherits the same restrictions as `squareF2m`. Negative exponents are disallowed. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` (a) * `Integer` (b) * Returns: `Integer` * **modF2m** * Description: Reduction by modulo over F₂m. This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` * Returns: `Integer` * **sqrtF2m** * Description: Square root in F₂m. We exploit the fact that `a^(2^m) = a`, or in particular, `a^(2^m - 1) = 1` from a classical result by Lagrange. Thus the square root is simply `a^(2^(m - 1))`. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` (a) * Returns: `Integer` * **invF2m** * Description: Modular inversion over F₂m. If `n` doesn't have an inverse, `Nothing` is returned. This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` * Returns: `Maybe Integer` * **divF2m** * Description: Division over F₂m. If the dividend doesn't have an inverse it returns `Nothing`. This function is undefined for negative arguments, because their bit representation is platform-dependent. Zero modulus is also prohibited. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` (Modulus) * `Integer` (Dividend) * `Integer` (Divisor) * Returns: `Maybe Integer` * **quadraticF2m** * Description: Solve a quadratic equation of the form `x² + x = a` in F₂m. * Method: N/A (Function Signature) * Arguments: * `BinaryPolynomial` * `Integer` (a) * Returns: `Maybe Integer` ``` -------------------------------- ### Elliptic Curve Basepoint Arithmetic Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Defines essential basepoint arithmetic operations for elliptic curves, including getting the curve order, scalar multiplication with the base point, and scalar conversions. ```Haskell class (EllipticCurveArith curve, Eq (Scalar curve)) => EllipticCurveBasepointArith curve where curveOrderBits :: proxy curve -> Int pointBaseSmul :: proxy curve -> Scalar curve -> Point curve pointsSmulVarTime :: proxy curve -> Scalar curve -> Scalar curve -> Point curve -> Point curve scalarToInteger :: proxy curve -> Scalar curve -> Integer scalarFromInteger :: proxy curve -> Integer -> CryptoFailable (Scalar curve) scalarAdd :: proxy curve -> Scalar curve -> Scalar curve -> Scalar curve scalarMul :: proxy curve -> Scalar curve -> Scalar curve -> Scalar curve ``` -------------------------------- ### Hashing Functions Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash Documentation for core hashing functions, including initialization, updates, finalization, and direct hashing of byte strings. ```APIDOC ## Hashing Functions ### Description This section details the primary functions for performing cryptographic hashing operations using the Crypton library. ### Functions * **`digestFromByteString :: (HashAlgorithm a, ByteArrayAccess ba) => ba -> Maybe (Digest a)`** * **Description**: Attempts to convert a byte array into a `Digest` of a specified algorithm. Returns `Nothing` if the byte array size does not match the algorithm's expected digest size. * **Method**: `digestFromByteString` * **`hashInitWith :: HashAlgorithm alg => alg -> Context alg`** * **Description**: Initializes a new hashing context for a given hash algorithm. * **Method**: `hashInitWith` * **`hashWith :: (ByteArrayAccess ba, HashAlgorithm alg) => alg -> ba -> Digest alg`** * **Description**: Computes the hash of a byte array using an explicitly provided hash algorithm. * **Method**: `hashWith` * **`hashPrefixWith :: (ByteArrayAccess ba, HashAlgorithmPrefix alg) => alg -> ba -> Int -> Digest alg`** * **Description**: Computes the hash of the first N bytes of a byte array using an explicit algorithm and prefix length. This function has a code path independent of N but is slower than `hashUpdate`. * **Method**: `hashPrefixWith` * **`hashInit :: HashAlgorithm a => Context a`** * **Description**: Initializes a new hashing context for the default hash algorithm. * **Method**: `hashInit` * **`hashUpdates :: (HashAlgorithm a, ByteArrayAccess ba) => Context a -> [ba] -> Context a`** * **Description**: Updates an existing hashing context with a list of byte arrays and returns the new context. * **Method**: `hashUpdates` * **`hashUpdate :: (ByteArrayAccess ba, HashAlgorithm a) => Context a -> ba -> Context a`** * **Description**: Updates a hashing context with a single byte array and returns the updated context. * **Method**: `hashUpdate` * **`hashFinalize :: HashAlgorithm a => Context a -> Digest a`** * **Description**: Finalizes the hashing context and returns the resulting digest. * **Method**: `hashFinalize` * **`hashFinalizePrefix :: (HashAlgorithmPrefix a, ByteArrayAccess ba) => Context a -> ba -> Int -> Digest a`** * **Description**: Updates the context with the first N bytes of a byte array and returns the digest. This is useful for excluding variable padding without leaking padding length. * **Method**: `hashFinalizePrefix` * **`hashBlockSize :: HashAlgorithm a => a -> Int`** * **Description**: Retrieves the block size of a given hash algorithm. * **Method**: `hashBlockSize` * **`hashDigestSize :: HashAlgorithm a => a -> Int`** * **Description**: Retrieves the digest size of a given hash algorithm. * **Method**: `hashDigestSize` * **`hash :: (ByteArrayAccess ba, HashAlgorithm a) => ba -> Digest a`** * **Description**: Computes the hash of a strict byte array. * **Method**: `hash` * **`hashPrefix :: (ByteArrayAccess ba, HashAlgorithmPrefix a) => ba -> Int -> Digest a`** * **Description**: Computes the hash of the first N bytes of a byte array, with a code path independent of N. * **Method**: `hashPrefix` * **`hashlazy :: HashAlgorithm a => ByteString -> Digest a`** * **Description**: Computes the hash of a lazy `ByteString`. * **Method**: `hashlazy` ``` -------------------------------- ### Get Curve Order in Bits for Curve_P256R1 Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-ECC Retrieves the order of the Curve_P256R1 in bits. The order of a curve is the number of points in its group, which is crucial for security parameter selection. This function returns an Int. ```haskell curveOrderBits :: proxy Curve_P256R1 -> Int ``` -------------------------------- ### MD5 Hash Algorithm Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Details about the MD5 cryptographic hash algorithm, including its instances, properties, and associated methods. ```APIDOC ## MD5 Hash Algorithm ### Description Provides details and instances for the MD5 cryptographic hash algorithm. ### Instances - **Data**: Details related to the `Data` instance for MD5. - **Show**: Details related to the `Show` instance for MD5. - **HashAlgorithm**: Properties and methods for MD5 as a `HashAlgorithm`. - `HashBlockSize`: The block size of the MD5 algorithm is 64. - `HashDigestSize`: The digest size of the MD5 algorithm is 16. - `HashInternalContextSize`: The internal context size of the MD5 algorithm is 96. - Methods: `hashBlockSize`, `hashDigestSize`, `hashInternalContextSize`, `hashInternalInit`, `hashInternalUpdate`, `hashInternalFinalize`. - **HashAlgorithmPrefix**: Methods for handling prefixes with MD5. - Method: `hashInternalFinalizePrefix`. - **HashAlgorithmASN1**: Methods for ASN.1 encoding of MD5 digests. - Method: `hashDigestASN1`. ### Request Example ```haskell -- Example of using MD5 (conceptual, actual usage depends on library functions) import Crypto.Hash.MD5 -- Assuming a function like hash :: ByteString -> Digest MD5 -- let digest = hash "some data" ``` ### Response #### Success Response (200) - **Digest MD5** (type): The resulting MD5 hash digest. #### Response Example ```haskell -- Example of a Digest MD5 (conceptual) -- "d41d8cd98f00b204e9800998ecf8427e" ``` ``` -------------------------------- ### Get Supported CPU Processor Options in Haskell Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-System-CPU Retrieves a list of processor options that are enabled at compile time and supported by the current CPU. This information is crucial for optimizing cryptographic operations. ```Haskell processorOptions :: [ProcessorOption] ``` -------------------------------- ### Get System Entropy in Haskell (crypton) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Random-Entropy The `getEntropy` function retrieves a specified number of bytes from the system's entropy source. It requires the `crypton` package and works with any type that is an instance of the `ByteArray` typeclass. ```Haskell getEntropy :: ByteArray byteArray => Int -> IO byteArray ``` -------------------------------- ### Blake2b Hashing Algorithm Instances (Haskell) Source: https://hackage.haskell.org/package/crypton/-1.0.6/docs/Crypto-Hash-Algorithms Details the HashAlgorithm and HashBlake2 instances for Blake2b, specifying block size, digest size, and context size. These instances are crucial for using Blake2b for cryptographic hashing. ```haskell instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashBlake2 (Blake2b bitlen) where blake2InternalKeyedInit :: Ptr (Context (Blake2b bitlen)) -> Ptr Word8 -> Word32 -> IO () instance (IsDivisibleBy8 bitlen, KnownNat bitlen, IsAtLeast bitlen 8, IsAtMost bitlen 512) => HashAlgorithm (Blake2b bitlen) where type HashBlockSize (Blake2b bitlen) = 128 type HashDigestSize (Blake2b bitlen) type HashInternalContextSize (Blake2b bitlen) = 248 hashInternalInit :: Ptr (Context (Blake2b bitlen)) -> IO () hashInternalUpdate :: Ptr (Context (Blake2b bitlen)) -> Ptr Word8 -> Word32 -> IO () hashInternalFinalize :: Ptr (Context (Blake2b bitlen)) -> Ptr (Digest (Blake2b bitlen)) -> IO () ```