Mbed TLS v4.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
TLS helper functions

Macros

#define MBEDTLS_ECDSA_DER_MAX_SIG_LEN(bits)
 Maximum size of a DER-encoded ECDSA signature for a given curve bit size. More...
 
#define MBEDTLS_ECDSA_DER_MAX_LEN   MBEDTLS_ECDSA_DER_MAX_SIG_LEN(PSA_VENDOR_ECC_MAX_CURVE_BITS)
 

Functions

static psa_algorithm_t mbedtls_md_psa_alg_from_type (mbedtls_md_type_t md_type)
 This function returns the PSA algorithm identifier associated with the given digest type. More...
 
static mbedtls_md_type_t mbedtls_md_type_from_psa_alg (psa_algorithm_t psa_alg)
 This function returns the given digest type associated with the PSA algorithm identifier. More...
 
int mbedtls_ecdsa_raw_to_der (size_t bits, const unsigned char *raw, size_t raw_len, unsigned char *der, size_t der_size, size_t *der_len)
 
int mbedtls_ecdsa_der_to_raw (size_t bits, const unsigned char *der, size_t der_len, unsigned char *raw, size_t raw_size, size_t *raw_len)
 

Detailed Description

Macro Definition Documentation

#define MBEDTLS_ECDSA_DER_MAX_LEN   MBEDTLS_ECDSA_DER_MAX_SIG_LEN(PSA_VENDOR_ECC_MAX_CURVE_BITS)

The maximal size of a DER-encoded ECDSA signature in Bytes.

Definition at line 136 of file psa_util.h.

#define MBEDTLS_ECDSA_DER_MAX_SIG_LEN (   bits)
Value:
(/*T,L of SEQUENCE*/ ((bits) >= 61 * 8 ? 3 : 2) + \
/*T,L of r,s*/ 2 * (((bits) >= 127 * 8 ? 3 : 2) + \
/*V of r,s*/ ((bits) + 8) / 8))

Maximum size of a DER-encoded ECDSA signature for a given curve bit size.

Parameters
bitsCurve size in bits.
Returns
Maximum signature size in bytes.
Note
This macro returns a compile-time constant if its argument is one. It may evaluate its argument multiple times.

Definition at line 130 of file psa_util.h.

Function Documentation

int mbedtls_ecdsa_der_to_raw ( size_t  bits,
const unsigned char *  der,
size_t  der_len,
unsigned char *  raw,
size_t  raw_size,
size_t *  raw_len 
)

Convert an ECDSA signature from DER ASN.1 format to raw format.

Parameters
bitsSize of each coordinate in bits.
derBuffer that contains the signature in DER format.
der_lenSize of der in bytes.
[out]rawBuffer that will be filled with the converted raw signature. It can overlap with der buffer.
raw_sizeSize of raw in bytes. Must be at least 2 * PSA_BITS_TO_BYTES(bits) bytes.
[out]raw_lenOn success it is updated with the amount of valid data (in bytes) written to raw. It's undefined in case of failure.
Returns
0 if successful.
PSA_ERROR_BUFFER_TOO_SMALL if raw_size is too small or if bits is larger than the largest supported curve.
MBEDTLS_ERR_ASN1_INVALID_DATA if the data in der is inconsistent with bits.
An MBEDTLS_ERR_ASN1_xxx error code if der is malformed.
int mbedtls_ecdsa_raw_to_der ( size_t  bits,
const unsigned char *  raw,
size_t  raw_len,
unsigned char *  der,
size_t  der_size,
size_t *  der_len 
)

Convert an ECDSA signature from raw format to DER ASN.1 format.

Parameters
bitsSize of each coordinate in bits.
rawBuffer that contains the signature in raw format.
raw_lenLength of raw in bytes. This must be PSA_BITS_TO_BYTES(bits) bytes.
[out]derBuffer that will be filled with the converted DER output. It can overlap with raw buffer.
der_sizeSize of der in bytes. It is enough if der_size is at least the size of the actual output. (The size of the output can vary depending on the presence of leading zeros in the data.) You can use MBEDTLS_ECDSA_DER_MAX_SIG_LEN(bits) to determine a size that is large enough for all signatures for a given value of bits.
[out]der_lenOn success it contains the amount of valid data (in bytes) written to der. It's undefined in case of failure.
Note
The behavior is undefined if der is null, even if der_size is 0.
Returns
0 if successful.
PSA_ERROR_BUFFER_TOO_SMALL if der_size is too small or if bits is larger than the largest supported curve.
MBEDTLS_ERR_ASN1_INVALID_DATA if one of the numbers in the signature is 0.
static psa_algorithm_t mbedtls_md_psa_alg_from_type ( mbedtls_md_type_t  md_type)
inlinestatic

This function returns the PSA algorithm identifier associated with the given digest type.

Parameters
md_typeThe type of digest to search for. Must not be NONE.
Warning
If md_type is MBEDTLS_MD_NONE, this function will not return PSA_ALG_NONE, but an invalid algorithm.
This function does not check if the algorithm is supported, it always returns the corresponding identifier.
Returns
The PSA algorithm identifier associated with md_type, regardless of whether it is supported or not.

Definition at line 87 of file psa_util.h.

References PSA_ALG_CATEGORY_HASH.

static mbedtls_md_type_t mbedtls_md_type_from_psa_alg ( psa_algorithm_t  psa_alg)
inlinestatic

This function returns the given digest type associated with the PSA algorithm identifier.

Parameters
psa_algThe PSA algorithm identifier to search for.
Warning
This function does not check if the algorithm is supported, it always returns the corresponding identifier.
Returns
The MD type associated with psa_alg, regardless of whether it is supported or not.

Definition at line 104 of file psa_util.h.

References PSA_ALG_HASH_MASK.