Copyright | (c) Leo D 2023 |
---|---|
License | BSD-3-Clause |
Maintainer | leo@apotheca.io |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Public key cryptography is a collection of techniques allowing for encryption, signatures, and key agreement.
Synopsis
- newtype PrivKey = MkPrivKey {
- getPrivKeyForeignPtr :: ForeignPtr BotanPrivKeyStruct
- type CheckKeyFlags = Word32
- pattern CheckKeyNormalTests :: CheckKeyFlags
- pattern CheckKeyExpensiveTests :: CheckKeyFlags
- type PrivKeyExportFlags = Word32
- pattern PrivKeyExportDER :: PrivKeyExportFlags
- pattern PrivKeyExportPEM :: PrivKeyExportFlags
- withPrivKey :: PrivKey -> (BotanPrivKey -> IO a) -> IO a
- privKeyCreate :: ByteString -> ByteString -> RNG -> IO PrivKey
- privKeyLoad :: ByteString -> ByteString -> IO PrivKey
- privKeyDestroy :: PrivKey -> IO ()
- privKeyAlgoName :: PrivKey -> IO ByteString
- privKeyCheckKey :: PrivKey -> RNG -> CheckKeyFlags -> IO ()
- privKeyGetField :: MP -> PrivKey -> ByteString -> IO ()
- privKeyExport :: PrivKey -> PrivKeyExportFlags -> IO ByteString
- privKeyExportPubKey :: PrivKey -> IO PubKey
- newtype PubKey = MkPubKey {
- getPubKeyForeignPtr :: ForeignPtr BotanPubKeyStruct
- withPubKey :: PubKey -> (BotanPubKey -> IO a) -> IO a
- pubKeyLoad :: ByteString -> IO PubKey
- pubKeyDestroy :: PubKey -> IO ()
- pubKeyAlgoName :: PubKey -> IO ByteString
- pubKeyCheckKey :: PubKey -> RNG -> CheckKeyFlags -> IO Bool
- pubKeyEstimatedStrength :: PubKey -> IO Int
- pubKeyFingerprint :: PubKey -> HashName -> IO ByteString
- pubKeyGetField :: MP -> PubKey -> ByteString -> IO ()
- pubKeyExport :: PubKey -> PubKeyExportFlags -> IO ByteString
- type PKName = ByteString
- pattern RSA :: PKName
- pattern SM2 :: PKName
- pattern ElGamal :: PKName
- pattern DSA :: PKName
- pattern ECDSA :: PKName
- pattern ECKCDSA :: PKName
- pattern ECGDSA :: PKName
- pattern GOST_34_10 :: PKName
- pattern Ed25519 :: PKName
- pattern XMSS :: PKName
- pattern DH :: PKName
- pattern ECDH :: PKName
- pattern Curve25519 :: PKName
- pattern Dilithium :: PKName
- pattern Kyber :: PKName
- pattern McEliece :: PKName
- type DLGroupName = ByteString
- pattern FFDHE_IETF_2048 :: DLGroupName
- pattern FFDHE_IETF_3072 :: DLGroupName
- pattern FFDHE_IETF_4096 :: DLGroupName
- pattern FFDHE_IETF_6144 :: DLGroupName
- pattern FFDHE_IETF_8192 :: DLGroupName
- pattern MODP_IETF_1024 :: DLGroupName
- pattern MODP_IETF_1536 :: DLGroupName
- pattern MODP_IETF_2048 :: DLGroupName
- pattern MODP_IETF_3072 :: DLGroupName
- pattern MODP_IETF_4096 :: DLGroupName
- pattern MODP_IETF_6144 :: DLGroupName
- pattern MODP_IETF_8192 :: DLGroupName
- pattern MODP_SRP_1024 :: DLGroupName
- pattern MODP_SRP_1536 :: DLGroupName
- pattern MODP_SRP_2048 :: DLGroupName
- pattern MODP_SRP_3072 :: DLGroupName
- pattern MODP_SRP_4096 :: DLGroupName
- pattern MODP_SRP_6144 :: DLGroupName
- pattern MODP_SRP_8192 :: DLGroupName
- pattern DSA_JCE_1024 :: DLGroupName
- pattern DSA_BOTAN_2048 :: DLGroupName
- pattern DSA_BOTAN_3072 :: DLGroupName
- type ECGroupName = ByteString
- pattern Secp160k1 :: ECGroupName
- pattern Secp160r1 :: ECGroupName
- pattern Secp160r2 :: ECGroupName
- pattern Secp192k1 :: ECGroupName
- pattern Secp192r1 :: ECGroupName
- pattern Secp224k1 :: ECGroupName
- pattern Secp224r1 :: ECGroupName
- pattern Secp256k1 :: ECGroupName
- pattern Secp256r1 :: ECGroupName
- pattern Secp384r1 :: ECGroupName
- pattern Secp521r1 :: ECGroupName
- pattern Brainpool160r1 :: ECGroupName
- pattern Brainpool192r1 :: ECGroupName
- pattern Brainpool224r1 :: ECGroupName
- pattern Brainpool256r1 :: ECGroupName
- pattern Brainpool320r1 :: ECGroupName
- pattern Brainpool384r1 :: ECGroupName
- pattern Brainpool512r1 :: ECGroupName
- pattern X962_p192v2 :: ECGroupName
- pattern X962_p192v3 :: ECGroupName
- pattern X962_p239v1 :: ECGroupName
- pattern X962_p239v2 :: ECGroupName
- pattern X962_p239v3 :: ECGroupName
- pattern Gost_256A :: ECGroupName
- pattern Gost_512A :: ECGroupName
- pattern Frp256v1 :: ECGroupName
- pattern Sm2p256v1 :: ECGroupName
- type XMSSName = ByteString
- pattern XMSS_SHA2_10_256 :: XMSSName
- pattern XMSS_SHA2_16_256 :: XMSSName
- pattern XMSS_SHA2_20_256 :: XMSSName
- pattern XMSS_SHA2_10_512 :: XMSSName
- pattern XMSS_SHA2_16_512 :: XMSSName
- pattern XMSS_SHA2_20_512 :: XMSSName
- pattern XMSS_SHAKE_10_256 :: XMSSName
- pattern XMSS_SHAKE_16_256 :: XMSSName
- pattern XMSS_SHAKE_20_256 :: XMSSName
- pattern XMSS_SHAKE_10_512 :: XMSSName
- pattern XMSS_SHAKE_16_512 :: XMSSName
- pattern XMSS_SHAKE_20_512 :: XMSSName
- type EMEName = ByteString
- pattern EME_RAW :: EMEName
- pattern EME_PKCS1_v1_5 :: EMEName
- pattern EME_OAEP :: EMEName
- eme_raw :: EMEName
- eme_pkcs1_v1_5 :: EMEName
- eme_oaep :: HashName -> EMEName
- eme_hash :: HashName -> EMEName
- eme_sm2EncParam :: HashName -> EMEName
- type EMSAName = ByteString
- emsa_none :: EMSAName
- emsa_emsa4 :: HashName -> EMSAName
- emsa_hash :: HashName -> EMSAName
- emsa_ed25519Pure :: EMSAName
- emsa_ed25519Prehashed :: EMSAName
- emsa_ed25519GnuPG :: HashName -> EMSAName
- emsa_sm2SignParam :: ByteString -> HashName -> EMSAName
- createPrivKey :: (Ptr BotanPrivKey -> IO CInt) -> IO PrivKey
- createPubKey :: (Ptr BotanPubKey -> IO CInt) -> IO PubKey
- mkPrivKeyLoad1_name :: (Ptr BotanPrivKey -> BotanMP -> ConstPtr CChar -> IO BotanErrorCode) -> MP -> ByteString -> IO PrivKey
- mkPrivKeyLoad3 :: (Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> IO PrivKey
- mkPrivKeyLoad4 :: (Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> MP -> IO PrivKey
- mkPubKeyLoad2 :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> IO PubKey
- mkPubKeyLoad2_name :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> ConstPtr CChar -> IO BotanErrorCode) -> MP -> MP -> ByteString -> IO PubKey
- mkPubKeyLoad3 :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> IO PubKey
- mkPubKeyLoad4 :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> MP -> IO PubKey
Private keys
MkPrivKey | |
|
type CheckKeyFlags = Word32 Source #
pattern CheckKeyNormalTests :: CheckKeyFlags Source #
pattern CheckKeyExpensiveTests :: CheckKeyFlags Source #
type PrivKeyExportFlags = Word32 Source #
pattern PrivKeyExportDER :: PrivKeyExportFlags Source #
pattern PrivKeyExportPEM :: PrivKeyExportFlags Source #
:: ByteString | |
-> ByteString | algo_params: is specific to the algorithm. For RSA, specifies the modulus bit length. For ECC is the name of the curve. |
-> RNG | rng: a random number generator |
-> IO PrivKey | key: the new object will be placed here |
Create a new private key
:: ByteString | bits[] |
-> ByteString | password |
-> IO PrivKey | key |
Input currently assumed to be PKCS #8 structure; Set password to NULL to indicate no encryption expected Starting in 2.8.0, the rng parameter is unused and may be set to null
privKeyDestroy :: PrivKey -> IO () Source #
:: PrivKey | key |
-> IO ByteString | out[] |
View the private key's DER encoding privKeyViewDER :: BotanPrivKey -- ^ key -> BotanViewContext ctx -- ^ ctx -> FunPtr (BotanViewBinCallback ctx) -- ^ view -> IO CInt
View the private key's PEM encoding privKeyViewPEM :: BotanPrivKey -- ^ key -> BotanViewContext ctx -- ^ ctx -> FunPtr (BotanViewStrCallback ctx) -- ^ view -> IO CInt
:: PrivKey | key |
-> RNG | rng |
-> CheckKeyFlags | flags |
-> IO () |
Check the validity of a private key
:: MP | output |
-> PrivKey | key |
-> ByteString | field_name |
-> IO () |
Get arbitrary named fields from public or private keys
:: PrivKey | key |
-> PrivKeyExportFlags | flags |
-> IO ByteString | out[] |
On input *out_len is number of bytes in out[] On output *out_len is number of bytes written (or required) If out is not big enough no output is written, *out_len is set and 1 is returned Returns 0 on success and sets If some other error occurs a negative integer is returned.
Public Keys
MkPubKey | |
|
:: ByteString | bits[] |
-> IO PubKey | key |
pubKeyDestroy :: PubKey -> IO () Source #
:: PubKey | key |
-> IO ByteString | out[] |
:: PubKey | key |
-> RNG | rng |
-> CheckKeyFlags | flags |
-> IO Bool |
:: PubKey | key |
-> HashName | hash |
-> IO ByteString | out[] |
:: MP | output |
-> PubKey | key |
-> ByteString | field_name |
-> IO () |
Get arbitrary named fields from public or private keys
:: PubKey | key |
-> PubKeyExportFlags | flags |
-> IO ByteString | out[] |
PK Algorithms
type PKName = ByteString Source #
pattern GOST_34_10 :: PKName Source #
pattern Curve25519 :: PKName Source #
DLGroup
type DLGroupName = ByteString Source #
pattern FFDHE_IETF_2048 :: DLGroupName Source #
pattern FFDHE_IETF_3072 :: DLGroupName Source #
pattern FFDHE_IETF_4096 :: DLGroupName Source #
pattern FFDHE_IETF_6144 :: DLGroupName Source #
pattern FFDHE_IETF_8192 :: DLGroupName Source #
pattern MODP_IETF_1024 :: DLGroupName Source #
pattern MODP_IETF_1536 :: DLGroupName Source #
pattern MODP_IETF_2048 :: DLGroupName Source #
pattern MODP_IETF_3072 :: DLGroupName Source #
pattern MODP_IETF_4096 :: DLGroupName Source #
pattern MODP_IETF_6144 :: DLGroupName Source #
pattern MODP_IETF_8192 :: DLGroupName Source #
pattern MODP_SRP_1024 :: DLGroupName Source #
pattern MODP_SRP_1536 :: DLGroupName Source #
pattern MODP_SRP_2048 :: DLGroupName Source #
pattern MODP_SRP_3072 :: DLGroupName Source #
pattern MODP_SRP_4096 :: DLGroupName Source #
pattern MODP_SRP_6144 :: DLGroupName Source #
pattern MODP_SRP_8192 :: DLGroupName Source #
pattern DSA_JCE_1024 :: DLGroupName Source #
pattern DSA_BOTAN_2048 :: DLGroupName Source #
pattern DSA_BOTAN_3072 :: DLGroupName Source #
ECGroup
type ECGroupName = ByteString Source #
pattern Secp160k1 :: ECGroupName Source #
pattern Secp160r1 :: ECGroupName Source #
pattern Secp160r2 :: ECGroupName Source #
pattern Secp192k1 :: ECGroupName Source #
pattern Secp192r1 :: ECGroupName Source #
pattern Secp224k1 :: ECGroupName Source #
pattern Secp224r1 :: ECGroupName Source #
pattern Secp256k1 :: ECGroupName Source #
pattern Secp256r1 :: ECGroupName Source #
pattern Secp384r1 :: ECGroupName Source #
pattern Secp521r1 :: ECGroupName Source #
pattern Brainpool160r1 :: ECGroupName Source #
pattern Brainpool192r1 :: ECGroupName Source #
pattern Brainpool224r1 :: ECGroupName Source #
pattern Brainpool256r1 :: ECGroupName Source #
pattern Brainpool320r1 :: ECGroupName Source #
pattern Brainpool384r1 :: ECGroupName Source #
pattern Brainpool512r1 :: ECGroupName Source #
pattern X962_p192v2 :: ECGroupName Source #
pattern X962_p192v3 :: ECGroupName Source #
pattern X962_p239v1 :: ECGroupName Source #
pattern X962_p239v2 :: ECGroupName Source #
pattern X962_p239v3 :: ECGroupName Source #
pattern Gost_256A :: ECGroupName Source #
pattern Gost_512A :: ECGroupName Source #
pattern Frp256v1 :: ECGroupName Source #
pattern Sm2p256v1 :: ECGroupName Source #
XMSS
type XMSSName = ByteString Source #
pattern XMSS_SHA2_10_256 :: XMSSName Source #
pattern XMSS_SHA2_16_256 :: XMSSName Source #
pattern XMSS_SHA2_20_256 :: XMSSName Source #
pattern XMSS_SHA2_10_512 :: XMSSName Source #
pattern XMSS_SHA2_16_512 :: XMSSName Source #
pattern XMSS_SHA2_20_512 :: XMSSName Source #
pattern XMSS_SHAKE_10_256 :: XMSSName Source #
pattern XMSS_SHAKE_16_256 :: XMSSName Source #
pattern XMSS_SHAKE_20_256 :: XMSSName Source #
pattern XMSS_SHAKE_10_512 :: XMSSName Source #
pattern XMSS_SHAKE_16_512 :: XMSSName Source #
pattern XMSS_SHAKE_20_512 :: XMSSName Source #
EME
type EMEName = ByteString Source #
Encoding Method for Encryption
WARNING: Name is not completely accurate, may be changed to PKEncryptParams
pattern EME_PKCS1_v1_5 :: EMEName Source #
eme_sm2EncParam :: HashName -> EMEName Source #
EMSA
type EMSAName = ByteString Source #
Encoding Method for Signature with Appendix
WARNING: Name is not completely accurate, may be changed to PKSignParams
emsa_emsa4 :: HashName -> EMSAName Source #
emsa_ed25519GnuPG :: HashName -> EMSAName Source #
emsa_sm2SignParam :: ByteString -> HashName -> EMSAName Source #
Convenience
mkPrivKeyLoad1_name :: (Ptr BotanPrivKey -> BotanMP -> ConstPtr CChar -> IO BotanErrorCode) -> MP -> ByteString -> IO PrivKey Source #
mkPrivKeyLoad3 :: (Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> IO PrivKey Source #
mkPrivKeyLoad4 :: (Ptr BotanPrivKey -> BotanMP -> BotanMP -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> MP -> MP -> IO PrivKey Source #
mkPubKeyLoad2 :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> IO BotanErrorCode) -> MP -> MP -> IO PubKey Source #
mkPubKeyLoad2_name :: (Ptr BotanPubKey -> BotanMP -> BotanMP -> ConstPtr CChar -> IO BotanErrorCode) -> MP -> MP -> ByteString -> IO PubKey Source #