View Source ecies (ecies v1.0.0)
Summary
Functions
Default elliptic curve secp256k1
and set of algorithms used for ECIES encryption/decryption.
Equivalent to generate_key(default_params()).
Generates a new key pair for elliptic curve specified in Params
under curve
key.
Equivalent to private_decrypt(PrivateKey, CipherData, default_params()).
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
Equivalent to public_encrypt(OthersPublicKey, PlainText, default_params()).
Encrypts the PlainText
using the OthersPublicKey
and returns encrypted data (binary cipher text by default).
Returns list of supported curves, ciphers and digest types (hashs) that can be used with ecies
library
Types
-type aead_cipher() ::
aes_ccm | aes_gcm | aes_128_ccm | aes_128_gcm | aes_192_ccm | aes_192_gcm | aes_256_ccm |
aes_256_gcm | chacha20_poly1305.
-type auth_tag() :: binary().
message authentication tag
-type cipher() :: 'xor' | atom().
all ciphers supported by crypto
-type cipher_text() :: binary().
-type cmac_cipher() :: aes_cbc | aes_128_cbc | aes_192_cbc | aes_256_cbc.
-type digest_type() ::
sha | sha224 | sha256 | sha384 | sha512 | sha3_224 | sha3_256 | sha3_384 | sha3_512 |
ripemd160 | blake2b | blake2s | md5 | md4 | sm3.
-type ecies_params() :: #{curve := named_curve(), compress_pubkey => boolean(), cipher => cipher(), kdf => kdf_type(), mac => mac_type(), s1 => binary(), s2 => binary(), key => {public_key(), private_key()}, iv => binary() | random | fun(), embedded_iv => boolean(), generate_key => fun(), shared_key => binary() | fun(), derive_keys => fun(), prepare_payload => fun(), decode => fun(), encode => as_tuple | raw | fun()}.
-type encrypted_data() :: binary() | {public_key(), cipher_text(), MAC :: auth_tag()}.
-type kdf_fun() :: fun((SharedKey :: binary(), Info :: binary(), Length :: pos_integer()) -> Result :: binary()).
-type kdf_type() :: {hkdf, digest_type()} | {kdf, digest_type()} | {concat_kdf, digest_type()} | kdf_fun().
-type mac_bits() :: pos_integer() | default.
-type mac_type() :: {hmac, digest_type(), mac_bits()} | {cmac, cmac_cipher(), mac_bits()} | {aead, mac_bits()}.
-type named_curve() :: crypto:ec_named_curve() | x25519 | x448.
-type plain_text() :: iodata().
-type private_key() :: binary().
-type public_key() :: binary().
Functions
-spec default_params() -> ecies_params().
Default elliptic curve secp256k1
and set of algorithms used for ECIES encryption/decryption.
By default ANSI-X9.63 key derivation function is used with AES-256 CBC encryption and HMAC-SHA256 with 256 bits output authentication tag
-spec generate_key() -> {public_key(), private_key()}.
Equivalent to generate_key(default_params()).
Generates a new key pair for default secp256k1
curve
-spec generate_key(#{curve := named_curve(), _ => _}) -> {public_key(), private_key()}.
Generates a new key pair for elliptic curve specified in Params
under curve
key.
-spec private_decrypt(private_key(), encrypted_data()) -> binary().
Equivalent to private_decrypt(PrivateKey, CipherData, default_params()).
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
Uses the default curve secp256k1
and other params returned from default_params/0
-spec private_decrypt(private_key(), encrypted_data(), ecies_params()) -> binary() | error.
Decrypts the CipherData
using the PrivateKey
and returns the PlainText
Uses the set of algorithms and elliptic curve defined in Params
argument
-spec public_encrypt(OthersPublicKey :: public_key(), PlainText :: plain_text()) -> CipherText :: binary().
Equivalent to public_encrypt(OthersPublicKey, PlainText, default_params()).
Encrypts the PlainText
using the OthersPublicKey
and returns the CipherText
Uses the default curve secp256k1
and other params returned from default_params/0
-spec public_encrypt(OthersPublicKey :: public_key(), plain_text(), ecies_params()) -> encrypted_data().
Encrypts the PlainText
using the OthersPublicKey
and returns encrypted data (binary cipher text by default).
Uses the set of algorithms and elliptic curve defined in Params
argument
-spec supports(hashs) -> [digest_type()]; (curves) -> [named_curve()]; (ciphers) -> [cipher()]; (cmac_ciphers) -> [cmac_cipher()]; (aead_ciphers) -> [aead_cipher()].
Returns list of supported curves, ciphers and digest types (hashs) that can be used with ecies
library