Leancrypto 1.7.2
Post-Quantum Cryptographic Library
Data Structures | Functions
lc_x509_common.h File Reference
#include "ext_headers.h"
#include "lc_asn1.h"
#include "lc_hash.h"
#include "lc_sha3.h"
+ Include dependency graph for lc_x509_common.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  lc_tm
 

Functions

int lc_x509_sig_type_to_name (enum lc_sig_types pkey_algo, const char **alg)
 Convert a leancrypto public key algorithm reference into human readable form. More...
 
int lc_x509_sig_type_to_hash (enum lc_sig_types pkey_algo, const struct lc_hash **hash_algo)
 Obtain the hash type to be used with a given public key algorithm. More...
 
int lc_x509_oid_to_hash (enum OID oid, const struct lc_hash **hash_algo)
 Obtain the hash type to be used with a given OID. More...
 
enum OID lc_look_up_OID (const uint8_t *data, size_t datasize)
 Convert a binary representation of an OID to leancrypto internal reference. More...
 
int lc_gmtime (time64_t timeval, struct lc_tm *tm)
 Trivial conversion of time to human-readable time value. More...
 
int lc_OID_to_data (enum OID oid, const uint8_t **data, size_t *datalen)
 Conversion of OID to binary representation using an internal lookup table. More...
 
int lc_asn1_ber_encoder (const struct lc_asn1_encoder *encoder, void *context, uint8_t *data, size_t *in_out_avail_datalen)
 ASN.1 encoder with 10 level hierarchy. More...
 
int lc_asn1_ber_encoder_small (const struct lc_asn1_encoder *encoder, void *context, uint8_t *data, size_t *in_out_avail_datalen)
 ASN.1 encoder with 4 level hierarchy defined on stack. More...
 
int lc_asn1_ber_decoder (const struct lc_asn1_decoder *decoder, void *context, const uint8_t *data, size_t datalen)
 Decoder BER/DER/CER ASN.1 according to pattern. More...
 

Data Structure Documentation

◆ lc_tm

struct lc_tm

Definition at line 429 of file lc_x509_common.h.

Data Fields
unsigned char day
unsigned char hour
unsigned char min
unsigned char month
unsigned char sec
unsigned short year

Function Documentation

◆ lc_asn1_ber_decoder()

int lc_asn1_ber_decoder ( const struct lc_asn1_decoder *  decoder,
void *  context,
const uint8_t *  data,
size_t  datalen 
)

Decoder BER/DER/CER ASN.1 according to pattern.

Parameters
[in]decoderThe decoder definition (produced by asn1_compiler)
[in]contextThe caller's context (to be passed to the action functions)
[in]dataThe encoded data
[in]datalenThe size of the encoded data

Decode BER/DER/CER encoded ASN.1 data according to a bytecode pattern produced by asn1_compiler. Action functions are called on marked tags to allow the caller to retrieve significant data.

LIMITATIONS:

To keep down the amount of stack used by this function, the following limits have been imposed:

(1) This won't handle datalen > 65535 without increasing the size of the cons stack elements and length_too_long checking.

(2) The stack of constructed types is 10 deep. If the depth of non-leaf constructed types exceeds this, the decode will fail.

(3) The SET type (not the SET OF type) isn't really supported as tracking what members of the set have been seen is a pain.

◆ lc_asn1_ber_encoder()

int lc_asn1_ber_encoder ( const struct lc_asn1_encoder *  encoder,
void *  context,
uint8_t *  data,
size_t *  in_out_avail_datalen 
)

ASN.1 encoder with 10 level hierarchy.

See asn1_encoder_impl.h for details.

Parameters
[in]encoderEncoder definition
[in]contextArbitrary data handed to the decoding functions
[out]dataEncoded data
[in,out]in_out_avail_datalenLength of the encoded data
Returns
0 on success; < 0 on error

◆ lc_asn1_ber_encoder_small()

int lc_asn1_ber_encoder_small ( const struct lc_asn1_encoder *  encoder,
void *  context,
uint8_t *  data,
size_t *  in_out_avail_datalen 
)

ASN.1 encoder with 4 level hierarchy defined on stack.

See asn1_encoder_impl.h for details.

Parameters
[in]encoderEncoder definition
[in]contextArbitrary data handed to the decoding functions
[out]dataEncoded data
[in,out]in_out_avail_datalenLength of the encoded data
Returns
0 on success; < 0 on error

◆ lc_gmtime()

int lc_gmtime ( time64_t  timeval,
struct lc_tm *  tm 
)

Trivial conversion of time to human-readable time value.

It only shows UTC considering that Epoch is UTC (i.e. it does not apply any time-zone conversions).

Furthermore, it does not apply leap seconds.

Parameters
[in]timevalTime in seconds since Epoch
[out]tmDecoded time
Returns
0 on success; < 0 on error

◆ lc_look_up_OID()

enum OID lc_look_up_OID ( const uint8_t *  data,
size_t  datasize 
)

Convert a binary representation of an OID to leancrypto internal reference.

Parameters
[in]dataBinary OID data
[in]datasizeLength of data buffer
Returns
OID

◆ lc_OID_to_data()

int lc_OID_to_data ( enum OID  oid,
const uint8_t **  data,
size_t *  datalen 
)

Conversion of OID to binary representation using an internal lookup table.

Parameters
[in]oidOID reference to convert
[out]dataPointer to binary representation (reference into a leancrypto-internal database)
[out]datalenLength of the binary representation
Returns
0 on success; < 0 on error

◆ lc_x509_oid_to_hash()

int lc_x509_oid_to_hash ( enum OID  oid,
const struct lc_hash **  hash_algo 
)

Obtain the hash type to be used with a given OID.

Parameters
[in]oidOID to convert
[out]hash_algoHash reference (or NULL if none is to be used)
Returns
0 on success, < 0 on error

◆ lc_x509_sig_type_to_hash()

int lc_x509_sig_type_to_hash ( enum lc_sig_types  pkey_algo,
const struct lc_hash **  hash_algo 
)

Obtain the hash type to be used with a given public key algorithm.

Parameters
[in]pkey_algopublic key algorithm type
[out]hash_algoHash reference (or NULL if none is to be used)
Returns
0 on success, < 0 on error

◆ lc_x509_sig_type_to_name()

int lc_x509_sig_type_to_name ( enum lc_sig_types  pkey_algo,
const char **  alg 
)

Convert a leancrypto public key algorithm reference into human readable form.

Parameters
[in]pkey_algopublic key algorithm type
[out]algAlgorithm string
Returns
0 on success, < 0 on error