UltrafastSecp256k1 3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
ecies.hpp
Go to the documentation of this file.
1#ifndef SECP256K1_ECIES_HPP
2#define SECP256K1_ECIES_HPP
3#pragma once
4
5// ============================================================================
6// ECIES -- Elliptic Curve Integrated Encryption Scheme
7// ============================================================================
8// Implements ECIES as used by MetaMask / eth-ecies / bitcore-ecies:
9// encrypt(recipient_pubkey, plaintext) -> ciphertext envelope
10// decrypt(privkey, ciphertext_envelope) -> plaintext
11//
12// Envelope format (variable length):
13// [33 bytes ephemeral pubkey] [16 bytes IV] [N bytes AES-256-CBC ciphertext]
14// [32 bytes HMAC-SHA256 tag]
15//
16// Also provides a simpler AES-256-GCM variant:
17// [33 bytes ephemeral pubkey] [12 bytes nonce] [N bytes ciphertext + 16B tag]
18//
19// Key derivation: SHA-512(ECDH_raw_x) -> first 32 bytes = AES key,
20// last 32 bytes = HMAC key (CBC mode)
21// ============================================================================
22
23#include <array>
24#include <cstdint>
25#include <cstddef>
26#include <vector>
27#include "secp256k1/point.hpp"
28#include "secp256k1/scalar.hpp"
29
30namespace secp256k1 {
31
32// ECIES encrypt: returns envelope bytes
33// Returns empty vector on failure
34std::vector<std::uint8_t>
35ecies_encrypt(const fast::Point& recipient_pubkey,
36 const std::uint8_t* plaintext, std::size_t plaintext_len);
37
38// ECIES decrypt: returns plaintext bytes
39// Returns empty vector on failure (bad key, tampered ciphertext, etc.)
40std::vector<std::uint8_t>
42 const std::uint8_t* envelope, std::size_t envelope_len);
43
44} // namespace secp256k1
45
46#endif // SECP256K1_ECIES_HPP
std::vector< std::uint8_t > ecies_decrypt(const fast::Scalar &privkey, const std::uint8_t *envelope, std::size_t envelope_len)
std::vector< std::uint8_t > ecies_encrypt(const fast::Point &recipient_pubkey, const std::uint8_t *plaintext, std::size_t plaintext_len)