purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
core.c File Reference
#include "core.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "purify/secp_bridge.h"
#include <errno.h>
#include <stdio.h>
#include <unistd.h>

Go to the source code of this file.

Functions

static void purify_core_secure_clear (void *data, size_t size)
 
static int purify_core_compare_be (const unsigned char *lhs, const unsigned char *rhs, size_t size)
 
static purify_error_code purify_core_validate_below (const unsigned char *value, size_t size, const unsigned char *upper_bound)
 
static purify_error_code purify_core_hkdf_sha256 (unsigned char *out, size_t out_len, const unsigned char *ikm, size_t ikm_len, const unsigned char *salt, size_t salt_len, const unsigned char *info, size_t info_len)
 
const char * purify_error_name (purify_error_code code)
 Returns a stable programmatic name for one status code.
 
const char * purify_error_message (purify_error_code code)
 Returns a human-facing description for one status code.
 
purify_error_code purify_fill_secure_random (unsigned char *bytes, size_t bytes_len)
 Fills a caller-owned buffer with secure operating-system randomness.
 
purify_error_code purify_validate_secret_key (const unsigned char secret_key[PURIFY_SECRET_KEY_BYTES])
 Validates one packed Purify secret key.
 
purify_error_code purify_validate_public_key (const unsigned char public_key[PURIFY_PUBLIC_KEY_BYTES])
 Validates one packed Purify public key.
 
purify_error_code purify_core_sample_secret_key (unsigned char out_secret_key[PURIFY_SECRET_KEY_BYTES])
 
purify_error_code purify_core_seed_secret_key (unsigned char out_secret_key[PURIFY_SECRET_KEY_BYTES], const unsigned char *seed, size_t seed_len)
 

Variables

static const unsigned char kPackedSecretKeySpaceSize [PURIFY_SECRET_KEY_BYTES]
 
static const unsigned char kPackedPublicKeySpaceSize [PURIFY_PUBLIC_KEY_BYTES]
 
static const char *const kErrorNames []
 
static const char *const kErrorMessages []
 

Function Documentation

◆ purify_core_compare_be()

static int purify_core_compare_be ( const unsigned char *  lhs,
const unsigned char *  rhs,
size_t  size 
)
static

◆ purify_core_hkdf_sha256()

static purify_error_code purify_core_hkdf_sha256 ( unsigned char *  out,
size_t  out_len,
const unsigned char *  ikm,
size_t  ikm_len,
const unsigned char *  salt,
size_t  salt_len,
const unsigned char *  info,
size_t  info_len 
)
static

◆ purify_core_sample_secret_key()

purify_error_code purify_core_sample_secret_key ( unsigned char  out_secret_key[PURIFY_SECRET_KEY_BYTES])

◆ purify_core_secure_clear()

static void purify_core_secure_clear ( void *  data,
size_t  size 
)
static

◆ purify_core_seed_secret_key()

purify_error_code purify_core_seed_secret_key ( unsigned char  out_secret_key[PURIFY_SECRET_KEY_BYTES],
const unsigned char *  seed,
size_t  seed_len 
)

◆ purify_core_validate_below()

static purify_error_code purify_core_validate_below ( const unsigned char *  value,
size_t  size,
const unsigned char *  upper_bound 
)
static

◆ purify_error_message()

const char * purify_error_message ( purify_error_code  code)

Definition at line 251 of file core.c.

References kErrorMessages.

◆ purify_error_name()

const char * purify_error_name ( purify_error_code  code)

Definition at line 242 of file core.c.

References kErrorNames.

◆ purify_fill_secure_random()

purify_error_code purify_fill_secure_random ( unsigned char *  bytes,
size_t  bytes_len 
)
Parameters
bytesBuffer to fill. May be NULL only when bytes_len == 0.
bytes_lenBuffer length in bytes.
Returns
PURIFY_ERROR_OK on success.

Definition at line 260 of file core.c.

References PURIFY_ERROR_ENTROPY_UNAVAILABLE, PURIFY_ERROR_MISSING_VALUE, and PURIFY_ERROR_OK.

Referenced by purify::fill_secure_random(), purify_core_sample_secret_key(), and purify_secp_context_create().

◆ purify_validate_public_key()

purify_error_code purify_validate_public_key ( const unsigned char  public_key[PURIFY_PUBLIC_KEY_BYTES])
Parameters
public_key64-byte packed Purify public key.
Returns
PURIFY_ERROR_OK when the packed public key is canonical.

Definition at line 311 of file core.c.

References kPackedPublicKeySpaceSize, purify_core_validate_below(), and PURIFY_PUBLIC_KEY_BYTES.

Referenced by purify::capi_detail::parse_public_key().

◆ purify_validate_secret_key()

purify_error_code purify_validate_secret_key ( const unsigned char  secret_key[PURIFY_SECRET_KEY_BYTES])
Parameters
secret_key64-byte packed Purify secret.
Returns
PURIFY_ERROR_OK when the packed secret is canonical.

Definition at line 307 of file core.c.

References kPackedSecretKeySpaceSize, purify_core_validate_below(), and PURIFY_SECRET_KEY_BYTES.

Referenced by purify::capi_detail::parse_secret_key().

Variable Documentation

◆ kErrorMessages

const char* const kErrorMessages[]
static

Definition at line 105 of file core.c.

Referenced by purify_error_message().

◆ kErrorNames

const char* const kErrorNames[]
static

Definition at line 72 of file core.c.

Referenced by purify_error_name().

◆ kPackedPublicKeySpaceSize

const unsigned char kPackedPublicKeySpaceSize[PURIFY_PUBLIC_KEY_BYTES]
static
Initial value:
= {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd,
0x75, 0x5d, 0xb9, 0xcd, 0x5e, 0x91, 0x40, 0x77,
0x7f, 0xa4, 0xbd, 0x19, 0xa0, 0x6c, 0x82, 0x83,
0x9d, 0x67, 0x1c, 0xd5, 0x81, 0xc6, 0x9b, 0xc5,
0xe6, 0x97, 0xf5, 0xe4, 0x5b, 0xcd, 0x07, 0xc5,
0x2e, 0xc3, 0x73, 0xa8, 0xbd, 0xc5, 0x98, 0xb4,
0x49, 0x3f, 0x50, 0xa1, 0x38, 0x0e, 0x12, 0x81,
}

Definition at line 61 of file core.c.

Referenced by purify_validate_public_key().

◆ kPackedSecretKeySpaceSize

const unsigned char kPackedSecretKeySpaceSize[PURIFY_SECRET_KEY_BYTES]
static
Initial value:
= {
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x5d, 0x57, 0x6e, 0x73, 0x57, 0xa4, 0x50, 0x1d,
0xdf, 0xe9, 0x2f, 0x46, 0x68, 0x1b, 0x20, 0xa0,
0xb2, 0x92, 0x66, 0xf8, 0xfd, 0xd3, 0x36, 0x23,
0x17, 0x0b, 0xa9, 0x62, 0x08, 0xc6, 0x3e, 0x47,
0x58, 0xfb, 0xa2, 0xd2, 0xca, 0xf0, 0xc1, 0x8d,
0xc4, 0x8a, 0xf1, 0x1c, 0xeb, 0xe3, 0xf4, 0x64,
}

Definition at line 42 of file core.c.

Referenced by purify_core_sample_secret_key(), purify_core_seed_secret_key(), and purify_validate_secret_key().