purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
c_api.cpp File Reference

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 UInt256purify::capi_detail::secp256k1_order ()
 
const UInt256purify::capi_detail::secp256k1_order_minus_one ()
 
Bytes purify::capi_detail::tagged_message (std::string_view prefix, const Bytes &message)
 
Result< UInt512purify::capi_detail::parse_secret_key (const unsigned char *secret_key)
 
Result< UInt512purify::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< UInt512purify::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.
 

Function Documentation

◆ purify_derive_bip340_key()

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 
)

◆ purify_derive_public_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] 
)
Parameters
out_public_keyOutput 64-byte packed Purify public key.
secret_keyInput 64-byte packed Purify secret. Aliasing: supported when out_public_key overlaps secret_key.
Returns
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_eval()

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 
)
Parameters
out_field_elementOutput 32-byte big-endian field element.
secret_keyInput 64-byte packed Purify secret.
messageMessage bytes. May be NULL only when message_len == 0.
message_lenMessage length in bytes. Aliasing: supported when out_field_element overlaps secret_key and/or message.
Returns
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_generate_key()

◆ purify_generate_key_from_seed()

purify_error_code purify_generate_key_from_seed ( purify_generated_key out,
const unsigned char *  seed,
size_t  seed_len 
)