|
purify
C++ Purify implementation with native circuit and BPP support
|
C core implementation for Purify key validation, generation, derivation, and evaluation. More...
#include "purify.h"#include <algorithm>#include <array>#include <cstdint>#include <span>#include <string_view>#include "purify/curve.hpp"#include "purify/error.hpp"#include "purify/secret.hpp"#include "core.h"#include "error_bridge.hpp"Go to the source code of this file.
Namespaces | |
| namespace | purify |
| namespace | purify::capi_detail |
Functions | |
| bool | purify::capi_detail::ranges_overlap (const void *lhs, std::size_t lhs_size, const void *rhs, std::size_t rhs_size) noexcept |
| Bytes | purify::capi_detail::copy_bytes (const unsigned char *data, std::size_t size) |
| void | purify::capi_detail::clear_generated_key (purify_generated_key *out) noexcept |
| void | purify::capi_detail::clear_bip340_key (purify_bip340_key *out) noexcept |
| const UInt256 & | purify::capi_detail::secp256k1_order () |
| const UInt256 & | purify::capi_detail::secp256k1_order_minus_one () |
| Bytes | purify::capi_detail::tagged_message (std::string_view prefix, const Bytes &message) |
| Result< UInt512 > | purify::capi_detail::parse_secret_key (const unsigned char *secret_key) |
| Result< UInt512 > | purify::capi_detail::parse_public_key (const unsigned char *public_key) |
| void | purify::capi_detail::write_uint512 (const UInt512 &value, unsigned char *out) |
| void | purify::capi_detail::write_field_element (const FieldElement &value, unsigned char *out) |
| Result< UInt512 > | purify::capi_detail::derive_public_key_from_secret (const UInt512 &secret) |
| purify_error_code | purify_generate_key (purify_generated_key *out) |
| Generates one random Purify keypair. | |
| purify_error_code | purify_generate_key_from_seed (purify_generated_key *out, const unsigned char *seed, size_t seed_len) |
| Deterministically derives one Purify keypair from seed material. | |
| purify_error_code | purify_derive_public_key (unsigned char out_public_key[PURIFY_PUBLIC_KEY_BYTES], const unsigned char secret_key[PURIFY_SECRET_KEY_BYTES]) |
| Derives the packed public key corresponding to one packed Purify secret. | |
| purify_error_code | purify_derive_bip340_key (purify_bip340_key *out, const unsigned char secret_key[PURIFY_SECRET_KEY_BYTES], purify_secp_context *secp_context) |
| Derives one canonical BIP340 keypair from one packed Purify secret. | |
| purify_error_code | purify_eval (unsigned char out_field_element[PURIFY_FIELD_ELEMENT_BYTES], const unsigned char secret_key[PURIFY_SECRET_KEY_BYTES], const unsigned char *message, size_t message_len) |
| Evaluates the Purify PRF for one packed secret and message. | |
| purify_error_code purify_derive_bip340_key | ( | purify_bip340_key * | out, |
| const unsigned char | secret_key[PURIFY_SECRET_KEY_BYTES], | ||
| purify_secp_context * | secp_context | ||
| ) |
| out | Output BIP340 keypair. |
| secret_key | Input 64-byte packed Purify secret. |
| secp_context | Caller-owned reusable context created by purify_secp_context_create. Aliasing: supported when out overlaps secret_key. |
PURIFY_ERROR_OK on success. Definition at line 217 of file c_api.cpp.
References purify::bytes_from_ascii(), purify::capi_detail::clear_bip340_key(), purify::Expected< T, E >::error(), purify::Expected< T, E >::has_value(), purify::capi_detail::parse_secret_key(), purify_bip340_key_from_seckey(), PURIFY_ERROR_BACKEND_REJECTED_INPUT, PURIFY_ERROR_INTERNAL_MISMATCH, PURIFY_ERROR_MISSING_VALUE, PURIFY_ERROR_OK, scalar, purify::capi_detail::secp256k1_order_minus_one(), purify_bip340_key::secret_key, purify::detail::secure_clear_bytes(), purify::core_api_detail::to_core_error_code(), and purify_bip340_key::xonly_public_key.
Referenced by purify::derive_bip340_key().
| purify_error_code purify_derive_public_key | ( | unsigned char | out_public_key[PURIFY_PUBLIC_KEY_BYTES], |
| const unsigned char | secret_key[PURIFY_SECRET_KEY_BYTES] | ||
| ) |
| out_public_key | Output 64-byte packed Purify public key. |
| secret_key | Input 64-byte packed Purify secret. Aliasing: supported when out_public_key overlaps secret_key. |
PURIFY_ERROR_OK on success. Definition at line 196 of file c_api.cpp.
References purify::capi_detail::derive_public_key_from_secret(), purify::Expected< T, E >::error(), purify::Expected< T, E >::has_value(), purify::capi_detail::parse_secret_key(), PURIFY_ERROR_MISSING_VALUE, PURIFY_ERROR_OK, PURIFY_PUBLIC_KEY_BYTES, purify::core_api_detail::to_core_error_code(), and purify::capi_detail::write_uint512().
Referenced by purify::derive_key().
| purify_error_code purify_eval | ( | unsigned char | out_field_element[PURIFY_FIELD_ELEMENT_BYTES], |
| const unsigned char | secret_key[PURIFY_SECRET_KEY_BYTES], | ||
| const unsigned char * | message, | ||
| size_t | message_len | ||
| ) |
| out_field_element | Output 32-byte big-endian field element. |
| secret_key | Input 64-byte packed Purify secret. |
| message | Message bytes. May be NULL only when message_len == 0. |
| message_len | Message length in bytes. Aliasing: supported when out_field_element overlaps secret_key and/or message. |
PURIFY_ERROR_OK on success. Definition at line 263 of file c_api.cpp.
References purify::combine(), purify::capi_detail::copy_bytes(), purify::curve1(), purify::curve2(), purify::Expected< T, E >::error(), purify::Expected< T, E >::has_value(), purify::hash_to_curve(), purify::EllipticCurve::mul_secret_affine(), purify::capi_detail::parse_secret_key(), PURIFY_ERROR_MISSING_VALUE, PURIFY_ERROR_OK, PURIFY_FIELD_ELEMENT_BYTES, purify::capi_detail::tagged_message(), purify::core_api_detail::to_core_error_code(), purify::unpack_secret(), and purify::capi_detail::write_field_element().
Referenced by purify::eval().
| purify_error_code purify_generate_key | ( | purify_generated_key * | out | ) |
| out | Output bundle. |
PURIFY_ERROR_OK on success. Definition at line 134 of file c_api.cpp.
References purify::capi_detail::clear_generated_key(), purify::capi_detail::derive_public_key_from_secret(), purify::Expected< T, E >::error(), purify::Expected< T, E >::has_value(), purify::capi_detail::parse_secret_key(), purify_generated_key::public_key, purify_core_sample_secret_key(), PURIFY_ERROR_MISSING_VALUE, PURIFY_ERROR_OK, purify_generated_key::secret_key, purify::core_api_detail::to_core_error_code(), and purify::capi_detail::write_uint512().
Referenced by purify::generate_key().
| purify_error_code purify_generate_key_from_seed | ( | purify_generated_key * | out, |
| const unsigned char * | seed, | ||
| size_t | seed_len | ||
| ) |
| out | Output bundle. |
| seed | Seed bytes. May be NULL only when seed_len == 0. |
| seed_len | Seed length in bytes. Values shorter than 16 bytes are rejected. Aliasing: supported when seed points anywhere inside out. |
PURIFY_ERROR_OK on success. Definition at line 161 of file c_api.cpp.
References purify::capi_detail::clear_generated_key(), purify::capi_detail::copy_bytes(), purify::capi_detail::derive_public_key_from_secret(), purify::Expected< T, E >::error(), purify::Expected< T, E >::has_value(), purify::capi_detail::parse_secret_key(), purify_generated_key::public_key, purify_core_seed_secret_key(), PURIFY_ERROR_MISSING_VALUE, PURIFY_ERROR_OK, purify::capi_detail::ranges_overlap(), purify_generated_key::secret_key, purify::core_api_detail::to_core_error_code(), and purify::capi_detail::write_uint512().
Referenced by purify::generate_key().