Combines a high-level and low-level error code together. This function can be called directly however it is usually called via the #MBEDTLS_ERROR_ADD macro. While a value of zero is not a negative error code, it is still an error code (that denotes success) and can be combined with both a negative error code or another value of zero.
This function frees the components of an MPI context.
Initialize an MPI context. This makes the MPI ready to be set or freed, but does not define a value for the MPI.
Securely zeroize a buffer The function is meant to wipe the data contained in a buffer so that it can no longer be recovered even if the program memory is later compromised. Call this function on sensitive data stored on the stack before returning from a function, and on sensitive data stored on the heap before freeing the heap object. It is extremely difficult to guarantee that calls to mbedtls_platform_zeroize() are not removed by aggressive compiler optimizations in a portable way. For this reason, Mbed TLS provides the configuration option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure mbedtls_platform_zeroize() to use a suitable implementation for their platform and needs
Compare an MPI with an integer.
Get the tag and length of the element. Check for the requested tag. Updates the pointer to immediately behind the tag and length.
Convert an Mbed TLS error code to a PSA error code
Securely zeroize a buffer then free it. Similar to making consecutive calls to \c mbedtls_platform_zeroize() and \c mbedtls_free(), but has code size savings, and potential for optimisation in the future. Guaranteed to be a no-op if \p buf is \c NULL and \p len is 0.
Store integer value in MPI.
Write a length field in ASN.1 format.
Perform a multiplication of two MPIs: X = A * B
Write an ASN.1 tag in ASN.1 format.
Import an MPI from unsigned big endian binary data.
Allocate a local copy of an input buffer and copy the contents into it.
Free a local copy of an input buffer.
Perform a modular reduction. R = A mod B
Export X into unsigned binary data, big endian. Always fills the whole buffer, which will start with zeros if the number is smaller.
This function checks if the remaining size in a buffer is greater or equal than a needed space.
This function releases and clears the specified AES context.
This function returns the message-digest information associated with the given digest type.
This function frees the components of a point.
Unallocate all certificate data
Return the number of bits up to and including the most significant bit of value \c 1. * \note This is same as the one-based index of the most significant bit of value \c 1.
AES set key schedule (encryption or decryption)
This function feeds an input buffer into an ongoing SHA-512 checksum calculation.
Enlarge an MPI to the specified number of limbs.
This function initializes a point as zero.
Retrieve the lifetime from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
This function clears the internal structure of \p ctx and frees any embedded internal structure, but does not free \p ctx itself. If you have called mbedtls_md_setup() on \p ctx, you must call mbedtls_md_free() when you are no longer using the context. Calling this function if you have previously called mbedtls_md_init() and nothing else is optional. You must not call this function if you have not called mbedtls_md_init().
Free the components of a #mbedtls_pk_context.
Perform a signed subtraction of MPIs: X = A - B
Copy from a local copy of an output buffer back to the original, then free the local copy.
This function initializes a message-digest context without binding it to a particular message-digest algorithm. This function should always be called first. It prepares the context for mbedtls_md_setup() for binding it to a message-digest algorithm.
Return the total size of an MPI value in bytes.
Add a message fragment to a multipart hash operation. The application must call psa_hash_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
Allocate a local copy of an output buffer.
Quick access to an RSA context inside a PK context. \warning This function can only be used when the type of the context, as returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_RSA. Ensuring that is the caller's responsibility. Alternatively, you can check whether this function returns NULL.
Wrap a call to psa_unregister_read in the global key slot mutex. If threading is disabled, this simply calls psa_unregister_read.
Perform a signed subtraction of an MPI and an integer: X = A - b
Ensure that a value cannot be known at compile time.
Perform a right-shift on an MPI: X >>= count
Perform a signed addition of MPIs: X = A + B
This function frees and clears the cipher-specific context of \p ctx. Freeing \p ctx itself remains the responsibility of the caller.
This function releases and clears the specified AES context.
Boolean "or" operation. Functionally equivalent to: \p x || \p y
Constant-time buffer comparison without branches. This is equivalent to the standard memcmp function, but is likely to be compiled to code using bitwise operations rather than a branch, such that the time taken is constant w.r.t. the data pointed to by \p a and \p b, and w.r.t. whether \p a and \p b are equal or not. It is not constant-time w.r.t. \p n . This function can be used to write constant-time code by replacing branches with bit operations using masks.
Get a specific bit from an MPI.
Perform a modular exponentiation: X = A^E mod N
This function sets up an ECP group context from a standardized set of domain parameters.
Tell if a context can do the operation given by type
This function initializes the specified AES context. It must be the first API called before using the context.
Retrieve entropy from the accumulator (Maximum length: MBEDTLS_ENTROPY_BLOCK_SIZE) (Thread-safe if MBEDTLS_THREADING_C is enabled)
This function initializes the CTR_DRBG context, and prepares it for mbedtls_ctr_drbg_seed() or mbedtls_ctr_drbg_free().
- The \p custom string. In addition, if you do not pass a nonce in \p custom, the sum of the entropy length and the entropy nonce length must be: - at least 24 bytes for a 128-bit strength (maximum achievable strength when using AES-128); - at least 48 bytes for a 256-bit strength (maximum achievable strength when using AES-256).
This function resets CTR_DRBG context to the state immediately after initial call of mbedtls_ctr_drbg_init().
This function extracts the message-digest size from the message-digest information structure.
Get the description of a key given its identifier and policy constraints and lock it. The key must have allow all the usage flags set in \p usage. If \p alg is nonzero, the key must allow operations with this algorithm. If \p alg is zero, the algorithm is not checked. In case of a persistent key, the function loads the description of the key into a key slot if not already done. On success, the returned key slot has been registered for reading. It is the responsibility of the caller to then unregister once they have finished reading the contents of the slot. The caller unregisters by calling psa_unregister_read() or psa_unregister_read_under_mutex(). psa_unregister_read() must be called if and only if the caller already holds the global key slot mutex (when mutexes are enabled). psa_unregister_read_under_mutex() encapsulates the unregister with mutex lock and unlock operations.
Import an MPI from an ASCII string.
The generic cipher update function. It encrypts or decrypts using the given cipher context. Writes as many block-sized blocks of data as possible to output. Any data that cannot be written immediately is either added to the next block, or flushed when mbedtls_cipher_finish() is called. Exception: For MBEDTLS_MODE_ECB, expects a single block in size. For example, 16 Bytes for AES.
Free the data in the context
The random generator function for the PSA subsystem. This function is suitable as the `f_rng` random generator function parameter of many `mbedtls_xxx` functions. The implementation of this function depends on the configuration of the library.
Convert a number into a mbedtls_ct_condition_t.
PEM context memory freeing
AES-ECB block encryption/decryption
Quick access to an EC context inside a PK context. \warning This function can only be used when the type of the context, as returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_ECKEY, #MBEDTLS_PK_ECKEY_DH, or #MBEDTLS_PK_ECDSA. Ensuring that is the caller's responsibility. Alternatively, you can check whether this function returns NULL.
This function prepares a cipher context for use with the given cipher primitive.
Modify a specific bit in an MPI.
This function retrieves the length of RSA modulus in Bytes.
This function copies the contents of point \p Q into point \p P.
Return information associated with the given PK type
Initialize a PK context with the information given and allocates the type-specific PK subcontext.
Retrieve an integer ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
After calling mbedtls_ssl_handshake() to start the SSL handshake you can call this function to check whether the handshake is over for a given SSL context. This function should be also used to determine when to stop calling mbedtls_handshake_step() for that context.
This function clears a SHA-512 context.
This function initializes a SHA-512 context.
This function starts a SHA-384 or SHA-512 checksum calculation.
This function finishes the SHA-512 operation, and writes the result to the output buffer.
Initialize a certificate (chain)
Initialize a #mbedtls_pk_context (as NONE).
This function performs a scalar multiplication of a point by an integer: \p R = \p m * \p P. It is not thread-safe to use same group in multiple threads.
This function feeds an input buffer into an ongoing SHA-256 checksum calculation.
This function frees the components of an ECP group.
This function frees the components of a key pair.
Retrieve the key type from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
Abort a hash operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_hash_setup() again. You may call this function any time after the operation object has been initialized by one of the methods described in #psa_hash_operation_t. In particular, calling psa_hash_abort() after the operation has been terminated by a call to psa_hash_abort(), psa_hash_finish() or psa_hash_verify() is safe and has no effect.
This function frees the components of an RSA key.
This function sets the key to use with the given context.
This function retrieves the cipher-information structure associated with the given cipher type.
This function initializes the specified AES context. It must be the first API called before using the context.
This function gives the message-digest size associated to message-digest type.
Write an arbitrary-precision number (#MBEDTLS_ASN1_INTEGER) in ASN.1 format.
Update record layer This function roughly separates the implementation of the logic of (D)TLS from the implementation of the secure transport. The record layer takes as input an untrusted underlying transport (stream or datagram) and transforms it into a serially multiplexed, secure transport, which conceptually provides the following: (1) Three datagram based, content-agnostic transports for handshake, alert and CCS messages. (2) One stream- or datagram-based transport for application data. (3) Functionality for changing the underlying transform securing the contents. The interface to this functionality is given as follows: a Updating [Currently implemented by mbedtls_ssl_read_record] Check if and on which of the four 'ports' data is pending: Nothing, a controlling datagram of type (1), or application data (2). In any case data is present, internal buffers provide access to the data for the user to process it. Consumption of type (1) datagrams is done automatically on the next update, invalidating that the internal buffers for previous datagrams, while consumption of application data (2) is user-controlled. b Reading of application data [Currently manual adaption of ssl->in_offt pointer] As mentioned in the last paragraph, consumption of data is different from the automatic consumption of control datagrams (1) because application data is treated as a stream. c Tracking availability of application data [Currently manually through decreasing ssl->in_msglen] For efficiency and to retain datagram semantics for application data in case of DTLS, the record layer provides functionality for checking how much application data is still available in the internal buffer. d Changing the transformation securing the communication. Given an opaque implementation of the record layer in the above sense, it should be possible to implement the logic of (D)TLS on top of it without the need to know anything about the record layer's internals. This is done e.g. in all the handshake handling functions, and in the application data reading function mbedtls_ssl_read.
Read out the current state of the SHA digest loaded in the engine. If the SHA suffix padding block has been executed already, the value that is read is the SHA digest (in big endian format). Otherwise, the value that is read is an interim SHA state.
Perform a signed addition of an MPI and an integer: X = A + b
Compute the modular inverse: X = A^-1 mod N
This function initializes an ECP group context without loading any domain parameters.
This function clears a SHA-256 context.
This function feeds an input buffer into an ongoing SHA-1 checksum calculation. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function initializes a \p ctx as NONE.
Free referenced items in an SSL session including the peer certificate and clear memory
Boolean "and" operation. Functionally equivalent to: \p x && \p y
Read a buffer for PEM information and store the resulting data into the specified context buffers.
This function starts a SHA-224 or SHA-256 checksum calculation.
This function finishes the SHA-256 operation, and writes the result to the output buffer.
This function initializes a SHA-256 context.
Attach and enable use of a bundle for certificate verification Attach and enable use of a bundle for certificate verification through a verification callback. If no specific bundle has been set through esp_crt_bundle_set() it will default to the bundle defined in menuconfig and embedded in the binary.
Perform a left-shift on an MPI: X <<= count
This function imports a set of core parameters into an RSA context. Any sequence of calls to this function should be followed by a call to mbedtls_rsa_complete(), which checks and completes the provided information to a ready-for-use public or private RSA key.
Constant-flow char selection
Fill an MPI with a number of random bytes.
This function clears a GCM context and the underlying cipher sub-context.
Parse one DER-encoded or one or more concatenated PEM-encoded certificates and add them to the chained list. For CRTs in PEM encoding, the function parses permissively: if at least one certificate can be parsed, the function returns the number of certificates for which parsing failed (hence \c 0 if all certificates were parsed successfully). If no certificate could be parsed, the function returns the first (negative) error encountered during parsing. PEM encoded certificates may be interleaved by other data such as human readable descriptions of their content, as long as the certificates are enclosed in the PEM specific '-----{BEGIN/END} CERTIFICATE-----' delimiters.
Perform an unsigned subtraction of MPIs: X = |A| - |B|
Boolean "not equal" operation. Functionally equivalent to: \p x != \p y
Boolean "equals" operation. Functionally equivalent to: \p x == \p y
Unlock an engine previously locked with esp_sha_lock_engine() or esp_sha_try_lock_engine()
This function feeds an input buffer into an ongoing GCM encryption or decryption operation. You may call this function zero, one or more times to pass successive parts of the input: the plaintext to encrypt, or the ciphertext (not including the tag) to decrypt. After the last part of the input, call mbedtls_gcm_finish(). This function may produce output in one of the following ways: - Immediate output: the output length is always equal to the input length. - Buffered output: the output consists of a whole number of 16-byte blocks. If the total input length so far (not including associated data) is 16 \* *B* + *A* with *A* < 16 then the total output length is 16 \* *B*. In particular: - It is always correct to call this function with \p output_size >= \p input_length + 15. - If \p input_length is a multiple of 16 for all the calls to this function during an operation, then it is correct to use \p output_size = \p input_length.
AES-CTR buffer encryption/decryption Warning: You have to keep the maximum use of your counter in mind! Note: Due to the nature of CTR you should use the same key schedule for both encryption and decryption. So a context initialized with esp_aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
Perform the SSL handshake \warning If this function returns something other than \c 0, #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or #MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET or #MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA, you must stop using the SSL context for reading or writing, and either free it or call \c mbedtls_ssl_session_reset() on it before re-using it for a new connection; the current connection must be closed.
Parse a private key in PEM or DER format
Set the certificate verification mode Default: NONE on server, REQUIRED on client MBEDTLS_SSL_VERIFY_NONE: peer certificate is not checked (default on server) (insecure on client) MBEDTLS_SSL_VERIFY_OPTIONAL: peer certificate is checked, however the handshake continues even if verification failed; mbedtls_ssl_get_verify_result() can be called after the handshake is complete. MBEDTLS_SSL_VERIFY_REQUIRED: peer *must* present a valid certificate, handshake is aborted if verification failed. (default on client)
Retrieve the key size for a cipher info structure.
Retrieve the key size from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
Abort an AEAD operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_aead_encrypt_setup() or psa_aead_decrypt_setup() again. You may call this function any time after the operation object has been initialized as described in #psa_aead_operation_t. In particular, calling psa_aead_abort() after the operation has been terminated by a call to psa_aead_abort(), psa_aead_finish() or psa_aead_verify() is safe and has no effect.
Lock access to AES hardware unit AES hardware unit can only be used by one consumer at a time. esp_aes_xxx API calls automatically manage locking & unlocking of hardware, this function is only needed if you want to call ets_aes_xxx functions directly.
Unlock access to AES hardware unit esp_aes_xxx API calls automatically manage locking & unlocking of hardware, this function is only needed if you want to call ets_aes_xxx functions directly.
Set up a multipart hash operation. The sequence of operations to calculate a hash (message digest) is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_hash_operation_t, e.g. #PSA_HASH_OPERATION_INIT. -# Call psa_hash_setup() to specify the algorithm. -# Call psa_hash_update() zero, one or more times, passing a fragment of the message each time. The hash that is calculated is the hash of the concatenation of these messages in order. -# To calculate the hash, call psa_hash_finish(). To compare the hash with an expected value, call psa_hash_verify(). If an error occurs at any step after a call to psa_hash_setup(), the operation will need to be reset by a call to psa_hash_abort(). The application may call psa_hash_abort() at any time after the operation has been initialized. After a successful call to psa_hash_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A successful call to psa_hash_finish() or psa_hash_verify(). - A call to psa_hash_abort().
This function exports the core parameters of an RSA key. If this function runs successfully, the non-NULL buffers pointed to by \p N, \p P, \p Q, \p D, and \p E are fully written, with additional unused space filled leading by zero Bytes. Possible reasons for returning #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED: An alternative RSA implementation is in use, which stores the key externally, and either cannot or should not export it into RAM. A SW or HW implementation might not support a certain deduction. For example, \p P, \p Q from \p N, \p D, and \p E if the former are not part of the implementation. If the function fails due to an unsupported operation, the RSA context stays intact and remains usable.
Abort a PAKE operation. Aborting an operation frees all associated resources except for the \c operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_pake_setup() again. This function may be called at any time after the operation object has been initialized as described in #psa_pake_operation_t. In particular, calling psa_pake_abort() after the operation has been terminated by a call to psa_pake_abort() or psa_pake_get_implicit_key() is safe and has no effect.
Retrieve an integer ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Get the length of an ASN.1 element. Updates the pointer to immediately behind the length.
Compare pair of mbedtls_x509_time.
This function sets the encryption key.
This function performs an ARIA single-block encryption or decryption operation. It performs encryption or decryption (depending on whether the key was set for encryption on decryption) on the input data buffer defined in the \p input parameter. mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called before the first call to this API with the same context.
The length of the given slice in the key slot table.
This function associates a GCM context with a cipher algorithm and a key.
This function exports a point into unsigned binary data.
This function checks that a point is a valid public key on this curve. It only checks that the point is non-zero, has valid coordinates and lies on the curve. It does not verify that it is indeed a multiple of \c G. This additional check is computationally more expensive, is not required by standards, and should not be necessary if the group used has a small cofactor. In particular, it is useless for the NIST groups which all have a cofactor of 1.
This function finishes the SHA-1 operation, and writes the result to the output buffer. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function sets the padding mode, for cipher modes that use padding.
SHA-1 process data block (internal use only). \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function feeds an input buffer into an ongoing GCM encryption or decryption operation. You may call this function zero, one or more times to pass successive parts of the input: the plaintext to encrypt, or the ciphertext (not including the tag) to decrypt. After the last part of the input, call mbedtls_gcm_finish(). This function may produce output in one of the following ways: - Immediate output: the output length is always equal to the input length. - Buffered output: the output consists of a whole number of 16-byte blocks. If the total input length so far (not including associated data) is 16 \* *B* + *A* with *A* < 16 then the total output length is 16 \* *B*. In particular: - It is always correct to call this function with \p output_size >= \p input_length + 15. - If \p input_length is a multiple of 16 for all the calls to this function during an operation, then it is correct to use \p output_size = \p input_length.
This function clears a GCM context
Encode a buffer into base64 format
This function returns the block size of the given cipher info structure in bytes.
Finish the calculation of the hash of a message. The application must call psa_hash_setup() before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to psa_hash_update(). When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort(). \warning Applications should not call this function if they expect a specific value for the hash. Call psa_hash_verify() instead. Beware that comparing integrity or authenticity data such as hash values with a function such as \c memcmp is risky because the time taken by the comparison may leak information about the hashed data which could allow an attacker to guess a valid hash and thereby bypass security controls.
This function clears a SHA-1 context. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Compute the greatest common divisor: G = gcd(A, B)
This function sets padding for an already initialized RSA context.
Read and process the first round message (TLS: contents of the Client/ServerHello extension, excluding extension type and length bytes).
Read and process the second round message (TLS: contents of the Client/ServerKeyExchange).
Public function mbedtls_pk_ec() can be used to get direct access to the wrapped ecp_keypair structure pointed to the pk_ctx. However this is not ideal because it bypasses the PK module on the control of its internal structure (pk_context) fields. For backward compatibility we keep mbedtls_pk_ec() when ECP_C is defined, but we provide 2 very similar functions when only ECP_LIGHT is enabled and not ECP_C. These variants embed the "ro" or "rw" keywords in their name to make the usage of the returned pointer explicit. Of course the returned value is const or non-const accordingly.
Montgomery multiplication: X = A * B * R^-1 mod N (HAC 14.36) \p A and \p B must be in canonical form. That is, < \p N. \p X may be aliased to \p A or \p N, or even \p B (if \p AN_limbs == \p B_limbs) but may not overlap any parameters otherwise. \p A and \p B may alias each other, if \p AN_limbs == \p B_limbs. They may not alias \p N (since they must be in canonical form, they cannot == \p N).
Completely wipe a slot in memory, including its policy. Persistent storage is not affected. Sets the slot's state to PSA_SLOT_EMPTY. If multi-threading is enabled, the caller must hold the global key slot mutex.
This function initializes a SHA-1 context. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Perform a division with remainder of two MPIs: A = Q * B + R
This function starts a SHA-1 checksum calculation. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function initializes the specified GCM context, to make references valid, and prepares the context for mbedtls_gcm_setkey() or mbedtls_gcm_free(). The function does not bind the GCM context to a particular cipher, nor set the key. For this purpose, use mbedtls_gcm_setkey().
This function returns the size of the prime modulus in bytes.
This function checks if a point is the point at infinity.
Set the data required to verify peer certificate
Add a message fragment to a multipart MAC operation. The application must call psa_mac_sign_setup() or psa_mac_verify_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort().
Abort a cipher operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() again. You may call this function any time after the operation object has been initialized as described in #psa_cipher_operation_t. In particular, calling psa_cipher_abort() after the operation has been terminated by a call to psa_cipher_abort() or psa_cipher_finish() is safe and has no effect.
Return the number of bits of value \c 0 before the least significant bit of value \c 1.
Derive the shared secret (TLS: Pre-Master Secret).
Free a heap-allocated linked list presentation of an ASN.1 sequence, including the first element. There are two common ways to manage the memory used for the representation of a parsed ASN.1 sequence: - Allocate a head node `mbedtls_asn1_sequence *head` with mbedtls_calloc(). Pass this node as the `cur` argument to mbedtls_asn1_get_sequence_of(). When you have finished processing the sequence, call mbedtls_asn1_sequence_free() on `head`. - Allocate a head node `mbedtls_asn1_sequence *head` in any manner, for example on the stack. Make sure that `head->next == NULL`. Pass `head` as the `cur` argument to mbedtls_asn1_get_sequence_of(). When you have finished processing the sequence, call mbedtls_asn1_sequence_free() on `head->cur`, then free `head` itself in the appropriate manner.
Retrieve an AlgorithmIdentifier ASN.1 sequence. Updates the pointer to immediately behind the full AlgorithmIdentifier.
Free all entries in a mbedtls_asn1_named_data list.
Free all shallow entries in a mbedtls_asn1_named_data list, but do not free internal pointer targets.
Parse a single DER formatted certificate and add it to the end of the provided chained list.
Generic function to add to or replace an extension in the CRT
Write an int tag (#MBEDTLS_ASN1_INTEGER) and value in ASN.1 format.
Boolean "not" operation. Functionally equivalent to: ! \p x
Choose between a size_t value and 0. Functionally equivalent to: condition ? if1 : 0. Functionally equivalent to mbedtls_ct_size_if(condition, if1, 0) but results in smaller code size.
Boolean "greater than" operation. Functionally equivalent to: \p x > \p y
Boolean "greater or equal" operation. Functionally equivalent to: \p x >= \p y
Load the contents of a key buffer into an internal RSA representation
Load the contents of a key buffer into an internal ECP representation
Retrieve the metadata about the provided uid
This function finishes the GCM operation and generates the authentication tag. It wraps up the GCM stream, and generates the tag. The tag can have a maximum length of 16 Bytes.
Generate a random number uniformly in a range. This function generates a random number between \p min inclusive and \p N exclusive. The procedure complies with RFC 6979 §3.3 (deterministic ECDSA) when the RNG is a suitably parametrized instance of HMAC_DRBG and \p min is \c 1.
This function performs an RSA public key operation.
This function performs GCM encryption or decryption of a buffer. \warning When this function performs a decryption, it outputs the authentication tag and does not verify that the data is authentic. You should use this function to perform encryption only. For decryption, use mbedtls_gcm_auth_decrypt() instead.
This function finishes the GCM operation and generates the authentication tag. It wraps up the GCM stream, and generates the tag. The tag can have a maximum length of 16 Bytes.
Initialize MD5 context \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
MD5 process buffer \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
AES-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes)
This function associates a GCM context with a key.
This function sets up an ECDH context from an EC key. It is used by clients and servers in place of the ServerKeyExchange for static ECDH, and imports ECDH parameters from the EC key information of a certificate. \see ecp.h
This function derives and exports the shared secret. This is the last function used by both TLS client and servers. \see ecp.h
This function imports a point from unsigned binary data.
This function frees a context.
Read at most 'len' application data bytes \warning If this function returns something other than a positive value, #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, #MBEDTLS_ERR_SSL_CLIENT_RECONNECT or #MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET or #MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA, you must stop using the SSL context for reading or writing, and either free it or call \c mbedtls_ssl_session_reset() on it before re-using it for a new connection; the current connection must be closed.
Try to write exactly 'len' application data bytes \warning This function will do partial writes in some cases. If the return value is non-negative but less than length, the function must be called again with updated arguments: buf + ret, len - ret (if ret is the return value) until it returns a value equal to the last 'len' argument. \warning If this function returns something other than a non-negative value, #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or #MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET or #MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA, you must stop using the SSL context for reading or writing, and either free it or call \c mbedtls_ssl_session_reset() on it before re-using it for a new connection; the current connection must be closed.
Load reasonable default SSL configuration values. (You need to call mbedtls_ssl_config_init() first.)
This function processes a single data block within the ongoing SHA-256 computation. This function is for internal use only.
This function clones the state of a SHA-256 context.
This function returns the block size of the given cipher in bytes.
Retrieve the operation mode for a cipher info structure.
This function clones the state of a SHA-512 context.
This function processes a single data block within the ongoing SHA-512 computation. This function is for internal use only.
Abort a MAC operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_mac_sign_setup() or psa_mac_verify_setup() again. You may call this function any time after the operation object has been initialized by one of the methods described in #psa_mac_operation_t. In particular, calling psa_mac_abort() after the operation has been terminated by a call to psa_mac_abort(), psa_mac_sign_finish() or psa_mac_verify_finish() is safe and has no effect.
Abort a key derivation operation. Aborting an operation frees all associated resources except for the \c operation structure itself. Once aborted, the operation object can be reused for another operation by calling psa_key_derivation_setup() again. This function may be called at any time after the operation object has been initialized as described in #psa_key_derivation_operation_t. In particular, it is valid to call psa_key_derivation_abort() twice, or to call psa_key_derivation_abort() on an operation that has not been set up.
When the MBEDTLS_GCM_NON_AES_CIPHER_SOFT_FALLBACK is defined, for non-AES GCM operations we need to fallback to the software function definitions of the mbedtls GCM layer. Thus in this case we need declarations for the software funtions. Please refer mbedtls/include/mbedtls/gcm.h for function documentations
Perform a multiplication of an MPI with an unsigned integer: X = A * b
Perform a safe conditional copy of MPI which doesn't reveal whether the condition was true or not. \warning If \p assign is neither 0 nor 1, the result of this function is indeterminate, and the resulting value in \p X might be neither its original value nor the value in \p Y.
This function exports a point as a TLS ECPoint record defined in RFC 4492, Section 5.4.
This function checks if a context contains at least an RSA public key. If the function runs successfully, it is guaranteed that enough information is present to perform an RSA public key operation using mbedtls_rsa_public().
Generate and write the first round message (TLS: contents of the Client/ServerHello extension, excluding extension type and length bytes).
Generate and write the second round message (TLS: contents of the Client/ServerKeyExchange).
This clears an ECJPAKE context and frees any embedded data structure.
Get the size in bits of the underlying key
Store the certificate DN in printable form into buf; no more than size characters will be written.
Top-level functions, with filesystem support
Write an AlgorithmIdentifier sequence in ASN.1 format.
Free referenced items in an SSL transform context and clear memory
Return \c mbedtls_ecp_group_id for the specified TLS ID.
Choose between an unsigned value and 0. Functionally equivalent to: condition ? if1 : 0. Functionally equivalent to mbedtls_ct_uint_if(condition, if1, 0) but results in smaller code size.
Perform a fixed-size multiply accumulate operation: X += b * A \p X may be aliased to \p A (when \p X_limbs == \p A_limbs), but may not otherwise overlap. This function operates modulo `2^(biL*X_limbs)`.
This function updates the state of the HMAC_DRBG context.
This function resets HMAC_DRBG context to the state immediately after initial call of mbedtls_hmac_drbg_init().
Parse a PKCS#1 (ASN.1) encoded private RSA key.
Parse a PKCS#1 (ASN.1) encoded public RSA key.
Try to allocate a buffer to an empty key slot.
Abort a cipher operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation.
Generate and apply the MGF1 operation (from PKCS#1 v2.1) to a buffer.
Starts a montgomery multiplication calculation in hardware
This function starts a GCM encryption or decryption operation.
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a GCM encryption or decryption operation. Call this function after mbedtls_gcm_starts() to pass the associated data. If the associated data is empty, you do not need to call this function. You may not call this function after calling mbedtls_cipher_update().
This function performs GCM encryption or decryption of a buffer.
This function performs multiplication and addition of two points by integers: \p R = \p m * \p P + \p n * \p Q It is not thread-safe to use same group in multiple threads.
Parse a SubjectPublicKeyInfo DER structure
Write an OID tag (#MBEDTLS_ASN1_OID) and data in ASN.1 format.
This function initializes a key pair as an invalid one.
This function starts a GCM encryption or decryption operation.
MD5 final digest \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
XTS-AES buffer encryption/decryption
This function initializes the specified AES XTS context. It must be the first API called before using the context.
This function initializes the specified GCM context
AES-CFB128 buffer encryption/decryption. Note: Due to the nature of CFB you should use the same key schedule for both encryption and decryption. So a context initialized with esp_aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
This function calculates the SHA-512 or SHA-384 checksum of a buffer. The function allocates the context, performs the calculation, and frees the context. The SHA-512 result is calculated as output = SHA-512(input buffer).
This function starts a new CMAC computation by setting the CMAC key, and preparing to authenticate the input data. It must be called with an initialized cipher context. Once this function has completed, data can be supplied to the CMAC computation by calling mbedtls_cipher_cmac_update(). To start a CMAC computation using the same key as a previous CMAC computation, use mbedtls_cipher_cmac_finish().
This function feeds an input buffer into an ongoing CMAC computation. The CMAC computation must have previously been started by calling mbedtls_cipher_cmac_starts() or mbedtls_cipher_cmac_reset(). Call this function as many times as needed to input the data to be authenticated. Once all of the required data has been input, call mbedtls_cipher_cmac_finish() to obtain the result of the CMAC operation.
This function finishes an ongoing CMAC operation, and writes the result to the output buffer. It should be followed either by mbedtls_cipher_cmac_reset(), which starts another CMAC operation with the same key, or mbedtls_cipher_free(), which clears the cipher context.
This function initializes an ECDH context.
This function frees an ECDSA context.
Read at most 'len' characters. If no error occurs, the actual amount read is returned.
This function implements the AES-CMAC-PRF-128 pseudorandom function, as defined in RFC-4615: The Advanced Encryption Standard-Cipher-based Message Authentication Code-Pseudo-Random Function-128 (AES-CMAC-PRF-128) Algorithm for the Internet Key Exchange Protocol (IKE).
Initialize an SSL context Just makes the context ready for mbedtls_ssl_setup() or mbedtls_ssl_free()
Set up an SSL context for use \warning The conf structure will be accessed during the session. It must not be modified or freed as long as the session is active. \warning This function must be called exactly once per context. Calling mbedtls_ssl_setup again is not supported, even if no session is active.
Set the random number generator callback
Set the underlying BIO callbacks for write, read and read-with-timeout.
Initialize an SSL configuration context Just makes the context ready for mbedtls_ssl_config_defaults() or mbedtls_ssl_config_free().
Notify the peer that the connection is being closed
This function initializes the CCM context set in the \p ctx parameter and sets the encryption key.
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a GCM encryption or decryption operation. Call this function after mbedtls_gcm_starts() to pass the associated data. If the associated data is empty, you do not need to call this function. You may not call this function after calling mbedtls_cipher_update().
mbedtls_gcm_context::buf contains the partial state of the computation of the authentication tag. mbedtls_gcm_context::add_len and mbedtls_gcm_context::len indicate different stages of the computation: * len == 0 && add_len == 0: initial state * len == 0 && add_len % 16 != 0: the first `add_len % 16` bytes have a partial block of AD that has been xored in but not yet multiplied in. * len == 0 && add_len % 16 == 0: the authentication tag is correct if the data ends now. * len % 16 != 0: the first `len % 16` bytes have a partial block of ciphertext that has been xored in but not yet multiplied in. * len > 0 && len % 16 == 0: the authentication tag is correct if the data ends now.
The generic all-in-one encryption/decryption function, for all ciphers except AEAD constructs.
Perform an unsigned addition of MPIs: X = |A| + |B|
Perform a safe conditional swap which doesn't reveal whether the condition was true or not. \warning If \p swap is neither 0 nor 1, the result of this function is indeterminate, and both \p X and \p Y might end up with values different to either of the original ones.
This function retrieves the information defined in mbedtls_ecp_curve_info() for all supported curves.
This function imports a point from a TLS ECPoint record.
This function performs multiplication of a point by an integer: \p R = \p m * \p P in a restartable way. \see mbedtls_ecp_mul()
This function exports an elliptic curve private key.
This function generates a private key.
This function initializes an RSA context.
This function checks if a context contains an RSA private key and perform basic consistency checks. \warning This function should catch accidental misconfigurations like swapping of parameters, but it cannot establish full trust in neither the quality nor the consistency of the key material that was used to setup the given RSA context: Consistency: Imported parameters that are irrelevant for the implementation might be silently dropped. If dropped, the current function does not have access to them, and therefore cannot check them. See mbedtls_rsa_complete(). If you want to check the consistency of the entire content of a PKCS1-encoded RSA private key, for example, you should use mbedtls_rsa_validate_params() before setting up the RSA context. Additionally, if the implementation performs empirical checks, these checks substantiate but do not guarantee consistency. Quality: This function is not expected to perform extended quality assessments like checking that the prime factors are safe. Additionally, it is the responsibility of the user to ensure the trustworthiness of the source of his RSA parameters, which goes beyond what is effectively checkable by the library.
This function performs an RSA private key operation. \warning It is deprecated and a security risk to not provide a PRNG here and thereby prevent the use of blinding. Future versions of the library may enforce the presence of a PRNG.
This function retrieves the cipher-information structure associated with the given cipher ID, key size and mode.
Initialize an ECJPAKE context.
Set up an ECJPAKE context for use.
Retrieve an AlgorithmIdentifier ASN.1 sequence with NULL or no params. Updates the pointer to immediately behind the full AlgorithmIdentifier.
Verify signature, with options. (Includes verification of the padding depending on type.)
Make signature, including padding if relevant.
Retrieve a boolean ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Unallocate all data related to subject alternative name
Clear MD5 context \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Translate hash algorithm OID into md_type
Write a string in ASN.1 format using a specific string encoding tag.
This function writes a named bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format. As stated in RFC 5280 Appendix B, trailing zeroes are omitted when encoding named bitstrings in DER.
Convert an ECC curve identifier from the Mbed TLS encoding to PSA.
Convert an ECC curve identifier from the PSA encoding to Mbed TLS.
Boolean "less than" operation. Functionally equivalent to: \p x < \p y
Choose between two unsigned values. Functionally equivalent to: condition ? if1 : if0.
Choose between an error value and 0. The error value must be in the range [-32767..0]. Functionally equivalent to: condition ? if1 : 0. Functionally equivalent to mbedtls_ct_error_if(condition, if1, 0) but results in smaller code size.
Conditional memcpy. Functionally equivalent to: if (condition) { memcpy(dest, src1, len); } else { if (src2 != NULL) memcpy(dest, src2, len); } It will always read len bytes from src1. If src2 != NULL, it will always read len bytes from src2. If src2 == NULL, it will instead read len bytes from dest (as if src2 == dest).
Write a buffer of PEM information from a DER encoded buffer.
Change the state of a key slot. This function changes the state of the key slot from expected_state to new state. If the state of the slot was not expected_state, the state is unchanged. If multi-threading is enabled, the caller must hold the global key slot mutex.
Test whether a lifetime designates a key in an external cryptoprocessor.
For output buffers which contain "tags" (outputs that may be checked for validity like hashes, MACs and signatures), fill the unused part of the output buffer (the whole buffer on error, the trailing part on success) with something that isn't a valid tag (barring an attack on the tag and deliberately-crafted input), in case the caller doesn't check the return status properly.
Unregister from reading a key slot. This function decrements the key slot registered reader counter by one. If the state of the slot is PSA_SLOT_PENDING_DELETION, and there is only one registered reader (the caller), this function will call psa_wipe_key_slot(). If multi-threading is enabled, the caller must hold the global key slot mutex.
Enable the MPI hardware and acquire the lock
Disable the MPI hardware and release the lock
This function prepares an XTS context for encryption and sets the encryption key.
This function prepares an XTS context for decryption and sets the decryption key.
This function performs a GCM authenticated decryption of a buffer.
This function copies the contents of group \p src into group \p dst.
This function returns the message-digest information from the given context.
This function performs a private RSA operation to sign a message digest using PKCS#1. It is the generic wrapper for performing a PKCS#1 signature.
This function adds the message padding, then performs an RSA operation. It is the generic wrapper for performing a PKCS#1 encryption operation.
Write a public key to a SubjectPublicKeyInfo DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer
This function sets up the ECDH context with the information given. This function should be called after mbedtls_ecdh_init() but before mbedtls_ecdh_make_params(). There is no need to call this function before mbedtls_ecdh_read_params(). This is the first function used by a TLS server for ECDHE ciphersuites.
MD5 context setup \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function frees and clears the components of a DHM context.
This function calculates the SHA-224 or SHA-256 checksum of a buffer. The function allocates the context, performs the calculation, and frees the context. The SHA-256 result is calculated as output = SHA-256(input buffer).
Parse a public key in PEM or DER format
This function generates an ECDH keypair on an elliptic curve. This function performs the first of two core computations implemented during the ECDH key exchange. The second core computation is performed by mbedtls_ecdh_compute_shared(). \see ecp.h
The generic cipher finalization function. If data still needs to be flushed from an incomplete block, the data contained in it is padded to the size of the last block, and written to the \p output buffer.
This function initializes the specified AES XTS context. It must be the first API called before using the context.
This function generates an ECP key.
This function initializes an ECDSA context.
Free referenced items in an SSL context and clear memory
Free an SSL configuration context
Write at most 'len' characters. If no error occurs, the actual amount read is returned.
This function returns the size of the IV or nonce for the cipher info structure, in bytes.
Declare the type of a key. This function overwrites any key type previously set in \p attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Declare the size of a key. This function overwrites any key size previously set in \p attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Get the length in bytes of the underlying key
Read some data from a key derivation operation. This function calculates output bytes from a key derivation algorithm and return those bytes. If you view the key derivation's output as a stream of bytes, this function destructively reads the requested number of bytes from the stream. The operation's capacity decreases by the number of bytes read. If this function returns an error status other than #PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
This function performs an AES-OFB (Output Feedback Mode) encryption or decryption operation.
This function initializes the specified CCM context, to make references valid, and prepare the context for mbedtls_ccm_setkey() or mbedtls_ccm_free().
This function releases and clears the specified CCM context and underlying cipher sub-context.
This function encrypts a buffer using CCM.
This function performs a CCM authenticated decryption of a buffer.
This function starts a CCM encryption or decryption operation. This function and mbedtls_ccm_set_lengths() must be called before calling mbedtls_ccm_update_ad() or mbedtls_ccm_update(). This function can be called before or after mbedtls_ccm_set_lengths().
This function calculates the full generic CMAC on the input buffer with the provided key. The function allocates the context, performs the calculation, and frees the context. The CMAC result is calculated as output = generic CMAC(cmac key, input buffer).
This function releases and clears the specified AES XTS context.
Reset a key attribute structure to a freshly initialized state. You must initialize the attribute structure as described in the documentation of the type #psa_key_attributes_t before calling this function. Once the structure has been initialized, you may call this function at any time. This function frees any auxiliary resources that the structure may contain.
Import a key in binary format. This function supports any output from psa_export_key(). Refer to the documentation of psa_export_public_key() for the format of public keys and to the documentation of psa_export_key() for the format for other key types. The key data determines the key size. The attributes may optionally specify a key size; in this case it must match the size determined from the key data. A key size of 0 in \p attributes indicates that the key size is solely determined by the key data. Implementations must reject an attempt to import a key of size 0. This specification supports a single format for each key type. Implementations may support other formats as long as the standard format is supported. Implementations that support other formats should ensure that the formats are clearly unambiguous so as to minimize the risk that an invalid input is accidentally interpreted according to a different format.
Miller-Rabin primality test. \warning If \p X is potentially generated by an adversary, for example when validating cryptographic parameters that you didn't generate yourself and that are supposed to be prime, then \p rounds should be at least the half of the security strength of the cryptographic algorithm. On the other hand, if \p X is chosen uniformly or non-adversarially (as is the case when mbedtls_mpi_gen_prime calls this function), then \p rounds can be much lower.
This function resizes an MPI downwards, keeping at least the specified number of limbs. If \c X is smaller than \c nblimbs, it is resized up instead.
Import X from unsigned binary data, little endian
Export X into unsigned binary data, little endian. Always fills the whole buffer, which will end with zeros if the number is smaller.
Perform a modular reduction with respect to an integer. r = A mod b
This function sets a point to the point at infinity.
This function generates a keypair with a configurable base point.
This function completes an RSA context from a set of imported core parameters. To setup an RSA public key, precisely \c N and \c E must have been imported. To setup an RSA private key, sufficient information must be present for the other parameters to be derivable. The default implementation supports the following: Derive \c P, \c Q from \c N, \c D, \c E. Derive \c N, \c D from \c P, \c Q, \c E. Alternative implementations need not support these. If this function runs successfully, it guarantees that the RSA context can be used for RSA operations without the risk of failure or crash. \warning This function need not perform consistency checks for the imported parameters. In particular, parameters that are not needed by the implementation might be silently discarded and left unchecked. To check the consistency of the key material, see mbedtls_rsa_check_privkey().
This function performs an RSA operation, then removes the message padding. It is the generic wrapper for performing a PKCS#1 decryption operation. \warning When \p ctx->padding is set to #MBEDTLS_RSA_PKCS_V15, mbedtls_rsa_rsaes_pkcs1_v15_decrypt() is called, which is an inherently dangerous function (CWE-242).
This function exports CRT parameters of a private RSA key.
This function performs a PKCS#1 v2.1 PSS verification operation (RSASSA-PSS-VERIFY).
This function performs a public RSA operation and checks the message digest. This is the generic wrapper for performing a PKCS#1 verification.
This function declares the lengths of the message and additional data for a CCM encryption or decryption operation. This function and mbedtls_ccm_starts() must be called before calling mbedtls_ccm_update_ad() or mbedtls_ccm_update(). This function can be called before or after mbedtls_ccm_starts().
This function feeds an input buffer into an ongoing CCM encryption or decryption operation. You may call this function zero, one or more times to pass successive parts of the input: the plaintext to encrypt, or the ciphertext (not including the tag) to decrypt. After the last part of the input, call mbedtls_ccm_finish(). The lengths \p input_len of the data parts should eventually add up exactly to the plaintext length \c plaintext_len passed to mbedtls_ccm_set_lengths(). This function may produce output in one of the following ways: - Immediate output: the output length is always equal to the input length. - Buffered output: except for the last part of input data, the output consists of a whole number of 16-byte blocks. If the total input length so far (not including associated data) is 16 \* *B* + *A* with *A* < 16 then the total output length is 16 \* *B*. For the last part of input data, the output length is equal to the input length plus the number of bytes (*A*) buffered in the previous call to the function (if any). The function uses the plaintext length \c plaintext_len passed to mbedtls_ccm_set_lengths() to detect the last part of input data. In particular: - It is always correct to call this function with \p output_size >= \p input_len + 15. - If \p input_len is a multiple of 16 for all the calls to this function during an operation (not necessary for the last one) then it is correct to use \p output_size =\p input_len.
Check if an ECJPAKE context is ready for use.
Write the shared key material to be passed to a Key Derivation Function as described in RFC8236.
Retrieve a bitstring ASN.1 tag without unused bits and its value. Updates the pointer to the beginning of the bit/octet string.
Save session structure as serialized data in a buffer. On client, this can be used for saving session data, potentially in non-volatile storage, for resuming later. On server, this can be used for alternative implementations of session cache or session tickets. \see mbedtls_ssl_session_load()
Initialize SSL session structure
Verify signature (including padding if relevant).
Check usage of certificate against keyUsage extension.
Convert the certificate DN string \p name into a linked list of mbedtls_x509_name (equivalent to mbedtls_asn1_named_data).
This function clones the state of a SHA-1 context. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Clone (the state of) an MD5 context \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Decode a base64-formatted buffer
This function returns the given digest type associated with the PSA algorithm identifier. \warning This function does not check if the algorithm is supported, it always returns the corresponding identifier.
Free referenced items in an SSL handshake context and clear memory
This function performs an ARIA-CBC encryption or decryption operation on full blocks. It performs the operation defined in the \p mode parameter (encrypt/decrypt), on the input data buffer defined in the \p input parameter. It can be called as many times as needed, until all the input data is processed. mbedtls_aria_init(), and either mbedtls_aria_setkey_enc() or mbedtls_aria_setkey_dec() must be called before the first call to this API with the same context.
This function performs an ARIA-CFB128 encryption or decryption operation. It performs the operation defined in the \p mode parameter (encrypt or decrypt), on the input data buffer defined in the \p input parameter. For CFB, you must set up the context with mbedtls_aria_setkey_enc(), regardless of whether you are performing an encryption or decryption operation, that is, regardless of the \p mode parameter. This is because CFB mode uses the same key schedule for encryption and decryption.
This function performs an ARIA-CTR encryption or decryption operation. Due to the nature of CTR, you must use the same key schedule for both encryption and decryption operations. Therefore, you must use the context initialized with mbedtls_aria_setkey_enc() for both #MBEDTLS_ARIA_ENCRYPT and #MBEDTLS_ARIA_DECRYPT. \warning You must never reuse a nonce value with the same key. Doing so would void the encryption for the two messages encrypted with the same nonce and key. There are two common strategies for managing nonces with CTR: 1. You can handle everything as a single message processed over successive calls to this function. In that case, you want to set \p nonce_counter and \p nc_off to 0 for the first call, and then preserve the values of \p nonce_counter, \p nc_off and \p stream_block across calls to this function as they will be updated by this function. With this strategy, you must not encrypt more than 2**128 blocks of data with the same key. 2. You can encrypt separate messages by dividing the \p nonce_counter buffer in two areas: the first one used for a per-message nonce, handled by yourself, and the second one updated by this function internally. For example, you might reserve the first 12 bytes for the per-message nonce, and the last 4 bytes for internal use. In that case, before calling this function on a new message you need to set the first 12 bytes of \p nonce_counter to your chosen nonce value, the last 4 to 0, and \p nc_off to 0 (which will cause \p stream_block to be ignored). That way, you can encrypt at most 2**96 messages of up to 2**32 blocks each with the same key. The per-message nonce (or information sufficient to reconstruct it) needs to be communicated with the ciphertext and must be unique. The recommended way to ensure uniqueness is to use a message counter. An alternative is to generate random nonces, but this limits the number of messages that can be securely encrypted: for example, with 96-bit random nonces, you should not encrypt more than 2**32 messages with the same key. Note that for both strategies, sizes are measured in blocks and that an ARIA block is 16 bytes. \warning Upon return, \p stream_block contains sensitive data. Its content must not be written to insecure storage and should be securely discarded as soon as it's no longer needed.
This function sets the decryption key.
Choose between two mbedtls_mpi_uint values. Functionally equivalent to: condition ? if1 : if0.
Calculate initialisation value for fast Montgomery modular multiplication
Return the minimum number of bits required to represent the value held in the MPI.
HMAC_DRBG context initialization. This function makes the context ready for mbedtls_hmac_drbg_seed(), mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().
Entropy poll callback for a hardware source
Write a PKCS#1 (ASN.1) encoded private RSA key.
Parse a PKCS#1 (ASN.1) encoded public RSA key.
Whether a key custom production parameters structure is the default. Calls to a key generation driver with non-default custom production parameters require a driver supporting custom production parameters.
Prepare a key slot to receive key material. This function allocates a key slot and sets its metadata. If this function fails, call psa_fail_key_creation(). This function is intended to be used as follows: -# Call psa_start_key_creation() to allocate a key slot, prepare it with the specified attributes, and in case of a volatile key assign it a volatile key identifier. -# Populate the slot with the key material. -# Call psa_finish_key_creation() to finalize the creation of the slot. In case of failure at any step, stop the sequence and call psa_fail_key_creation(). On success, the key slot's state is PSA_SLOT_FILLING. It is the responsibility of the caller to change the slot's state to PSA_SLOT_EMPTY/FULL once key creation has finished.
Finalize the creation of a key once its key material has been set. This entails writing the key to persistent storage. If this function fails, call psa_fail_key_creation(). See the documentation of psa_start_key_creation() for the intended use of this function. If the finalization succeeds, the function sets the key slot's state to PSA_SLOT_FULL, and the key slot can no longer be accessed as part of the key creation process.
Abort the creation of a key. You may call this function after calling psa_start_key_creation(), or after psa_finish_key_creation() fails. In other circumstances, this function may not clean up persistent storage. See the documentation of psa_start_key_creation() for the intended use of this function. Sets the slot's state to PSA_SLOT_EMPTY.
Abort a MAC operation using Mbed TLS. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling mbedtls_psa_mac_sign_setup() or mbedtls_psa_mac_verify_setup() again. The PSA core may call this function any time after the operation object has been initialized by one of the methods described in #mbedtls_psa_mac_operation_t. In particular, calling mbedtls_psa_mac_abort() after the operation has been terminated by a call to mbedtls_psa_mac_abort(), mbedtls_psa_mac_sign_finish() or mbedtls_psa_mac_verify_finish() is safe and has no effect.
Abort an AEAD operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by the PSA core by it calling mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() again. The PSA core may call this function any time after the operation object has been initialized as described in #mbedtls_psa_aead_operation_t. In particular, calling mbedtls_psa_aead_abort() after the operation has been terminated by a call to mbedtls_psa_aead_abort() or mbedtls_psa_aead_finish() is safe and has no effect.
Get the key buffer size required to store the key material of a key associated with an opaque driver.
Abort an Mbed TLS hash operation. Aborting an operation frees all associated resources except for the \p operation structure itself. Once aborted, the operation object can be reused for another operation by calling mbedtls_psa_hash_setup() again. You may call this function any time after the operation object has been initialized by one of the methods described in #psa_hash_operation_t. In particular, calling mbedtls_psa_hash_abort() after the operation has been terminated by a call to mbedtls_psa_hash_abort(), mbedtls_psa_hash_finish() or mbedtls_psa_hash_verify() is safe and has no effect.
Export an RSA key to export representation
Get the description of a key given its identifier and lock it. The descriptions of volatile keys and loaded persistent keys are stored in key slots. This function returns a pointer to the key slot containing the description of a key given its identifier. In case of a persistent key, the function loads the description of the key into a key slot if not already done. On success, the returned key slot has been registered for reading. It is the responsibility of the caller to call psa_unregister_read(slot) when they have finished reading the contents of the slot. On failure, `*p_slot` is set to NULL. This ensures that it is always valid to call psa_unregister_read on the returned slot.
Set the IV for a symmetric encryption or decryption operation. This function sets the IV (initialization vector), nonce or initial counter value for the encryption or decryption operation.
Encrypt or decrypt a message fragment in an active cipher operation.
Finish encrypting or decrypting a message in a cipher operation.
Get a pointer to a slot given by slice and index.
Try and obtain exclusive access to a particular SHA engine
Write a subjectPublicKey to ASN.1 data Note: function works backwards in data buffer
This function sets the initialization vector (IV) or nonce.
This function performs a GCM authenticated decryption of a buffer.
Output = MD5( input buffer ) \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
This function initializes the DHM context.
This function derives and exports the shared secret \c (G^Y)^X mod \c P.
This function verifies the ECDSA signature of a previously-hashed message. \see ecp.h
Write a private key to a PKCS#1 or SEC1 DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer
This function computes the shared secret. This function performs the second of two core computations implemented during the ECDH key exchange. The first core computation is performed by mbedtls_ecdh_gen_public(). \see ecp.h
This function calculates the SHA-1 checksum of a buffer. The function allocates the context, performs the calculation, and frees the context. The SHA-1 result is calculated as output = SHA-1(input buffer). \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Reset an already initialized SSL context for re-use while retaining application-set variables, function pointers and data.
Set the list of allowed ciphersuites and the preference order. First in the list has the highest preference. For TLS 1.2, the notion of ciphersuite determines both the key exchange mechanism and the suite of symmetric algorithms to be used during and after the handshake. For TLS 1.3 (in development), the notion of ciphersuite only determines the suite of symmetric algorithms to be used during and after the handshake, while key exchange mechanisms are configured separately. In Mbed TLS, ciphersuites for both TLS 1.2 and TLS 1.3 are configured via this function. For users of TLS 1.3, there will be separate API for the configuration of key exchange mechanisms. The list of ciphersuites passed to this function may contain a mixture of TLS 1.2 and TLS 1.3 ciphersuite identifiers. This is useful if negotiation of TLS 1.3 should be attempted, but a fallback to TLS 1.2 would be tolerated. \warning The ciphersuites array \p ciphersuites is not copied. It must remain valid for the lifetime of the SSL configuration \p conf.
Set or reset the hostname to check against the received server certificate. It sets the ServerName TLS extension, too, if that extension is enabled. (client-side only) Hostname set to the one provided on success (cleared when NULL). On allocation failure hostname is cleared. On too long input failure, old hostname is unchanged.
Return the result of the certificate verification
Return the name of the current ciphersuite
Initialize a context Just makes the context ready to be used or freed safely.
Gracefully shutdown the connection and free associated data
Returns an informational string about the verification status of a certificate.
Translate an Mbed TLS error code into a string representation. The result is truncated if necessary and always includes a terminating null byte.
\def PSA_HASH_OPERATION_INIT This macro returns a suitable initializer for a hash operation object of type #psa_hash_operation_t. Return an initial value for a hash operation object.
Retrieve the key identifier from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
Declare usage flags for a key. Usage flags are part of a key's usage policy. They encode what kind of operations are permitted on the key. For more details, refer to the documentation of the type #psa_key_usage_t. This function overwrites any usage flags previously set in \p attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Declare the permitted algorithm policy for a key. The permitted algorithm policy of a key encodes which algorithm or algorithms are permitted to be used with this key. The following algorithm policies are supported: - 0 does not allow any cryptographic operation with the key. The key may be used for non-cryptographic actions such as exporting (if permitted by the usage flags). - An algorithm value permits this particular algorithm. - An algorithm wildcard built from #PSA_ALG_ANY_HASH allows the specified signature scheme with any hash algorithm. - An algorithm built from #PSA_ALG_AT_LEAST_THIS_LENGTH_MAC allows any MAC algorithm from the same base class (e.g. CMAC) which generates/verifies a MAC length greater than or equal to the length encoded in the wildcard algorithm. - An algorithm built from #PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG allows any AEAD algorithm from the same base class (e.g. CCM) which generates/verifies a tag length greater than or equal to the length encoded in the wildcard algorithm. This function overwrites any algorithm policy previously set in \p attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Finish the calculation of the MAC of a message. The application must call psa_mac_sign_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to psa_mac_update(). When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort(). \warning Applications should not call this function if they expect a specific value for the MAC. Call psa_mac_verify_finish() instead. Beware that comparing integrity or authenticity data such as MAC values with a function such as \c memcmp is risky because the time taken by the comparison may leak information about the MAC value which could allow an attacker to guess a valid MAC and thereby bypass security controls.
Internal AES block encryption function (Only exposed to allow overriding it, see AES_ENCRYPT_ALT)
Internal AES block decryption function (Only exposed to allow overriding it, see AES_DECRYPT_ALT)
Derive a key from an ongoing key derivation operation with custom production parameters. See the description of psa_key_derivation_out_key() for the operation of this function with the default production parameters. Mbed TLS currently does not currently support any non-default production parameters.
Generate a key or key pair using custom production parameters. See the description of psa_generate_key() for the operation of this function with the default production parameters. In addition, this function supports the following production customizations, described in more detail in the documentation of ::psa_custom_key_parameters_t: - RSA keys: generation with a custom public exponent.
Calculate the hash (digest) of a message.
The authenticated encryption (AEAD/NIST_KW) function.
The authenticated encryption (AEAD/NIST_KW) function.
Compare the absolute values of two MPIs.
This function retrieves curve information from an internal group identifier.
This function extracts an elliptic curve group ID from a TLS ECParameters record as defined in RFC 4492, Section 5.4.
This function exports an elliptic curve as a TLS ECParameters record as defined in RFC 4492, Section 5.4.
This function generates an ECP keypair.
This function reads an elliptic curve private key.
This function performs multiplication and addition of two points by integers: \p R = \p m * \p P + \p n * \p Q in a restartable way. \see \c mbedtls_ecp_muladd()
This function checks that an \c mbedtls_mpi is a valid private key for this curve.
This function imports core RSA parameters, in raw big-endian binary format, into an RSA context. Any sequence of calls to this function should be followed by a call to mbedtls_rsa_complete(), which checks and completes the provided information to a ready-for-use public or private RSA key.
This function performs a PKCS#1 v2.1 OAEP decryption operation (RSAES-OAEP-DECRYPT).
This function performs a PKCS#1 v2.1 OAEP encryption operation (RSAES-OAEP-ENCRYPT).
This function checks whether a given group can be used for ECDSA.
This function performs a PKCS#1 v2.1 PSS signature operation (RSASSA-PSS-SIGN).
This function computes the ECDSA signature of a previously-hashed message, in a restartable way. \see ecp.h
This function computes the ECDSA signature of a previously-hashed message, in a restartable way. \see ecp.h
This function verifies the ECDSA signature of a previously-hashed message, in a restartable manner \see ecp.h
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a CCM encryption or decryption operation. You may call this function zero, one or more times to pass successive parts of the additional data. The lengths \p ad_len of the data parts should eventually add up exactly to the total length of additional data \c total_ad_len passed to mbedtls_ccm_set_lengths(). You may not call this function after calling mbedtls_ccm_update().
This function finishes the CCM operation and generates the authentication tag. It wraps up the CCM stream, and generates the tag. The tag can have a maximum length of 16 Bytes.
Set the point format for future reads and writes.
Retrieve a bitstring ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Set the verification callback (Optional). If set, the provided verify callback is called for each certificate in the peer's CRT chain, including the trusted root. For more information, please see the documentation of \c mbedtls_x509_crt_verify().
Load serialized session data into a session structure. On client, this can be used for loading saved sessions before resuming them with mbedtls_ssl_set_session(). On server, this can be used for alternative implementations of session cache or session tickets. \warning If a peer certificate chain is associated with the session, the serialized state will only contain the peer's end-entity certificate and the result of the chain verification (unless verification was disabled), but not the rest of the chain. \see mbedtls_ssl_session_save() \see mbedtls_ssl_set_session()
Return the (maximum) number of bytes added by the record layer: header + encryption/MAC overhead (inc. padding)
Restartable version of \c mbedtls_pk_sign()
Parse a DER-encoded CRL and append it to the chained list
Restartable version of \c mbedtls_pk_verify()
This function generates a public key and exports it as a TLS ClientKeyExchange payload. This is the second function used by a TLS client for ECDH(E) ciphersuites. \see ecp.h
This function parses and processes the ECDHE payload of a TLS ClientKeyExchange message. This is the third function used by a TLS server for ECDH(E) ciphersuites. (It is called after mbedtls_ecdh_setup() and mbedtls_ecdh_make_params().) \see ecp.h
Get time in milliseconds. \warning This function returns a monotonically-increasing time value from a start time that will differ from platform to platform, and possibly from run to run of the process.
Store the certificate serial in printable form into buf; no more than size characters will be written.
Check a given mbedtls_x509_time against the system time and tell if it's in the past.
Check a given mbedtls_x509_time against the system time and tell if it's in the future.
This function parses an item in the SubjectAlternativeNames extension. Please note that this function might allocate additional memory for a subject alternative name, thus mbedtls_x509_free_subject_alt_name has to be called to dispose of this additional memory afterwards. \warning The target structure contains pointers to the raw data of the parsed certificate, and its lifetime is restricted by the lifetime of the certificate.
Adds an entropy source to poll (Thread-safe if MBEDTLS_THREADING_C is enabled)
Add data to the accumulator manually (Thread-safe if MBEDTLS_THREADING_C is enabled)
This function sets the amount of entropy grabbed on each seed or reseed. The default value is #MBEDTLS_CTR_DRBG_ENTROPY_LEN.
This function sets the amount of entropy grabbed as a nonce for the initial seeding. Call this function before calling mbedtls_ctr_drbg_seed() to read a nonce from the entropy source during the initial seeding.
This function reseeds the CTR_DRBG context, that is extracts data from the entropy source.
Translate an ASN.1 OID into its numeric representation (e.g. "\x2A\x86\x48\x86\xF7\x0D" into "1.2.840.113549")
Translate an X.509 extension OID into local values
Translate EC group identifier into AlgorithmIdentifier OID, for curves that are directly encoded at this level
Translate md_type and pk_type into SignatureAlgorithm OID
Return the maximum fragment length (payload, in bytes) for the output buffer. For the client, this is the configured value. For the server, it is the minimum of two - the configured value and the negotiated one. \sa mbedtls_ssl_conf_max_frag_len() \sa mbedtls_ssl_get_max_out_record_payload()
Write a boolean tag (#MBEDTLS_ASN1_BOOLEAN) and value in ASN.1 format.
Create or find a specific named_data entry for writing in a sequence or list based on the OID. If not already in there, a new entry is added to the head of the list. Warning: Destructive behaviour for the val data!
Find the preferred hash for a given signature algorithm.
Return TLS ID for the specified \c mbedtls_ecp_group_id.
Validate cipher suite against config in SSL context.
PKCS#5 PBKDF2 using HMAC without using the HMAC context
Increment a big-endian 16-byte value. This is quite performance-sensitive for AES-CTR and CTR-DRBG.
This function initializes the specified ARIA context. It must be the first API called before using the context.
This function releases and clears the specified ARIA context.
Choose between two size_t values. Functionally equivalent to: condition ? if1 : if0.
Boolean not-equals operation. Functionally equivalent to: \p x != \p y
Choose between an mbedtls_mpi_uint value and 0. Functionally equivalent to: condition ? if1 : 0. Functionally equivalent to mbedtls_ct_mpi_uint_if(condition, if1, 0) but results in smaller code size.
Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint into the storage form used by mbedtls_mpi.
Check if one unsigned MPI is less than another in constant time.
Perform a safe conditional copy of an MPI which doesn't reveal whether assignment was done or not.
Shift an MPI in-place right by a number of bits. Shifting by more bits than there are bit positions in \p X is valid and results in setting \p X to 0. This function's execution time depends on the value of \p count (and of course \p limbs).
Subtract two fixed-size large unsigned integers, returning the borrow. Calculate `A - B` where \p A and \p B have the same size. This function operates modulo `2^(biL*limbs)` and returns the carry (1 if there was a wraparound, i.e. if `A < B`, and 0 otherwise). \p X may be aliased to \p A or \p B, or even both, but may not overlap either otherwise.
Calculate the square of the Montgomery constant. (Needed for conversion and operations in Montgomery form.)
Fill an integer with a number of random bytes.
Convert an MPI into Montgomery form. \p X may be aliased to \p A, but may not otherwise overlap it. \p X may not alias \p N (it is in canonical form, so must be strictly less than \p N). Nor may it alias or overlap \p rr (this is unlikely to be required in practice.) This function is a thin wrapper around `mbedtls_mpi_core_montmul()` that is an alternative to calling `mbedtls_mpi_mod_raw_to_mont_rep()` when we don't want to allocate memory.
This function reseeds the HMAC_DRBG context, that is extracts data from the entropy source.
The PKCS#12 derivation function uses a password and a salt to produce pseudo-random bits for a particular "purpose". Depending on the given id, this function can produce an encryption/decryption key, an initialization vector or an integrity key.
This function creates a candidate public key from an LMOTS signature. This can then be compared to the real public key to determine the validity of the signature.
Register as a reader of a key slot. This function increments the key slot registered reader counter by one. If multi-threading is enabled, the caller must hold the global key slot mutex.
Test whether a key slot has any registered readers. If multi-threading is enabled, the caller must hold the global key slot mutex.
Get a key slot containing a transparent key and lock it. A transparent key is a key for which the key material is directly available, as opposed to a key in a secure element and/or to be used by a secure element. This is a temporary function that may be used instead of psa_get_and_lock_key_slot_with_policy() when there is no opaque key support for a cryptographic operation. On success, the returned key slot has been registered for reading. It is the responsibility of the caller to then unregister once they have finished reading the contents of the slot. The caller unregisters by calling psa_unregister_read() or psa_unregister_read_under_mutex(). psa_unregister_read() must be called if and only if the caller already holds the global key slot mutex (when mutexes are enabled). psa_unregister_read_under_mutex() encapsulates psa_unregister_read() with mutex lock and unlock operations.
Wipe key data from a slot. Preserves metadata such as the policy.
Validate the key bit size for unstructured keys.
Check whether a given key type is valid for use with a given MAC algorithm Upon successful return of this function, the behavior of #PSA_MAC_LENGTH when called with the validated \p algorithm and \p key_type is well-defined.
Copy key data (in export format) into an empty key slot. This function assumes that the slot does not contain any key material yet. On failure, the slot content is unchanged.
Add a message fragment to a multipart MAC operation using Mbed TLS. The PSA core calls mbedtls_psa_mac_sign_setup() or mbedtls_psa_mac_verify_setup() before calling this function. If this function returns an error status, the PSA core aborts the operation by calling mbedtls_psa_mac_abort().
Finish encrypting a message in an AEAD operation. The operation must have been set up by the PSA core with mbedtls_psa_aead_encrypt_setup(). This function finishes the authentication of the additional data formed by concatenating the inputs passed to preceding calls to mbedtls_psa_aead_update_ad() with the plaintext formed by concatenating the inputs passed to preceding calls to mbedtls_psa_aead_update(). This function has two output buffers: - \p ciphertext contains trailing ciphertext that was buffered from preceding calls to mbedtls_psa_aead_update(). - \p tag contains the authentication tag. Whether or not this function returns successfully, the PSA core subsequently calls mbedtls_psa_aead_abort() to deactivate the operation.
Set up a multipart hash operation using Mbed TLS routines. If an error occurs at any step after a call to mbedtls_psa_hash_setup(), the operation will need to be reset by a call to mbedtls_psa_hash_abort(). The core may call mbedtls_psa_hash_abort() at any time after the operation has been initialized. After a successful call to mbedtls_psa_hash_setup(), the core must eventually terminate the operation. The following events terminate an operation: - A successful call to mbedtls_psa_hash_finish() or mbedtls_psa_hash_verify(). - A call to mbedtls_psa_hash_abort().
Add a message fragment to a multipart Mbed TLS hash operation. The application must call mbedtls_psa_hash_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling mbedtls_psa_hash_abort().
Finish the calculation of the Mbed TLS-calculated hash of a message. The application must call mbedtls_psa_hash_setup() before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to mbedtls_psa_hash_update(). When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling mbedtls_psa_hash_abort().
Export an ECP key to export representation
Validate a key identifier.
Find a free key slot and reserve it to be filled with a key. This function finds a key slot that is free, sets its state to PSA_SLOT_FILLING and then returns the slot. On success, the key slot's state is PSA_SLOT_FILLING. It is the responsibility of the caller to change the slot's state to PSA_SLOT_EMPTY/FULL once key creation has finished. If multi-threading is enabled, the caller must hold the global key slot mutex.
Get Mbed TLS cipher information given the cipher algorithm PSA identifier as well as the PSA type and size of the key to be used with the cipher algorithm.
Get Mbed TLS cipher information given the cipher algorithm PSA identifier as well as the PSA type and size of the key to be used with the cipher algorithm.
Set the key for a multipart symmetric encryption operation.
Set the key for a multipart symmetric decryption operation.
This function copies a parameter of a DHM key.
This function parses DHM parameters in PEM or DER format.
Get the description in memory of a key given its identifier and lock it. The descriptions of volatile keys and loaded persistent keys are stored in key slots. This function returns a pointer to the key slot containing the description of a key given its identifier. The function searches the key slots containing the description of the key with \p key identifier. The function does only read accesses to the key slots. The function does not load any persistent key thus does not access any storage. For volatile key identifiers, only one key slot is queried as a volatile key with identifier key_id can only be stored in slot of index ( key_id - #PSA_KEY_ID_VOLATILE_MIN ). On success, the function locks the key slot. It is the responsibility of the caller to unlock the key slot when it does not access it anymore. If multi-threading is enabled, the caller must hold the global key slot mutex.
Remove the provided key and its associated data from the storage
Generate RSA-CRT parameters
Acquire exclusive access to the SHA shared memory block at SHA_TEXT_BASE This memory block is shared across all the SHA algorithm types. Caller should have already locked a SHA engine before calling this function. Note that it is possible to obtain exclusive access to the memory block even while it is in use by the SHA engine. Caller should use esp_sha_wait_idle() to ensure the SHA engine is not reading from the memory block in hardware. Call esp_sha_unlock_memory_block() when done.
Release exclusive access to the SHA register memory block at SHA_TEXT_BASE Caller should have already locked a SHA engine before calling this function. This function releases the critical section entered by esp_sha_lock_memory_block(). Call following esp_sha_lock_memory_block().
Load a Certificate Signing Request (CSR) in DER format
Generic function to add to or replace an extension in the CSR
Fill mbedtls_x509_time with provided mbedtls_time_t.
This function releases and clears the specified AES XTS context.
This function reads and verifies an ECDSA signature. \see ecp.h
Export an MPI to an ASCII string.
Perform a division with remainder of an MPI by an integer: A = Q * b + R
This function compares two points.
This function extracts the message-digest type from the message-digest information structure.
This function performs a PKCS#1 v1.5 decryption operation (RSAES-PKCS1-v1_5-DECRYPT). \warning This is an inherently dangerous function (CWE-242). Unless it is used in a side channel free and safe way (eg. implementing the TLS protocol as per 7.4.7.1 of RFC 5246), the calling code is vulnerable.
This function computes the ECDSA signature of a previously-hashed message. \see ecp.h
Perform a single step of the SSL handshake \warning Whilst in the past you may have used direct access to the context state (ssl->state) in order to ascertain when to stop calling this function and although you can still do so with something like ssl->MBEDTLS_PRIVATE(state) or by defining MBEDTLS_ALLOW_PRIVATE_ACCESS, this is now considered deprecated and could be broken in any future release. If you still find you have good reason for such direct access, then please do contact the team to explain this (raise an issue or post to the mailing list), so that we can add a solution to your problem that will be guaranteed to work in the future. \warning If this function returns something other than \c 0, #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS, #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS or #MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET or #MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA, you must stop using the SSL context for reading or writing, and either free it or call \c mbedtls_ssl_session_reset() on it before re-using it for a new connection; the current connection must be closed.
Translate pk_type into PublicKeyAlgorithm OID
Translate EC group identifier into NamedCurve OID
This function computes the ECDSA signature of a previously-hashed message, deterministic version. For more information, see RFC-6979: Deterministic Usage of the Digital Signature Algorithm (DSA) and Elliptic Curve Digital Signature Algorithm (ECDSA). \see ecp.h
This function resets the cipher state.
Decrypt message (including padding if relevant).
This function parses the DHM parameters in a TLS ServerKeyExchange handshake message (DHM modulus, generator, and public key).
This function creates a DHM key pair and exports the raw public key in big-endian format.
This function sets up an ECDSA context from an EC key pair. \see ecp.h
Configure a key export callback. (Default: none.) This API can be used for two purposes: - Debugging: Use this API to e.g. generate an NSSKeylog file and use it to inspect encrypted traffic in tools such as Wireshark. - Application-specific export: Use this API to implement key exporters, e.g. for EAP-TLS or DTLS-SRTP.
Set own certificate chain and private key
Configure allowed signature algorithms for use in TLS
Set the supported Application Layer Protocols.
TLS-PRF function for key derivation.
Set the EC J-PAKE password for current handshake.
Initiate a connection with host:port in the given protocol
Compare two key identifiers.
Check whether a key identifier is null.
This function checks if domain parameter A of the curve is \c -3.
This function returns the mode of operation for the cipher. For example, MBEDTLS_MODE_CBC.
This function returns the key length of the cipher.
Retrieve the algorithm policy from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
Return an initial value for a PAKE cipher suite object.
This function computes the ECDSA signature and writes it to a buffer, serialized as defined in RFC-4492: Elliptic Curve Cryptography (ECC) Cipher Suites for Transport Layer Security (TLS). \warning It is not thread-safe to use the same context in multiple threads. \see ecp.h
This function computes the ECDSA signature and writes it to a buffer, in a restartable way. \see \c mbedtls_ecdsa_write_signature()
This function reads and verifies an ECDSA signature, in a restartable way. \see \c mbedtls_ecdsa_read_signature()
Provide an input for key derivation or key agreement. Which inputs are required and in what order depends on the algorithm. Refer to the documentation of each key derivation or key agreement algorithm for information. This function passes direct inputs, which is usually correct for non-secret inputs. To pass a secret input, which should be in a key object, call psa_key_derivation_input_key() instead of this function. Refer to the documentation of individual step types (`PSA_KEY_DERIVATION_INPUT_xxx` values of type ::psa_key_derivation_step_t) for more information. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
AES-CFB8 buffer encryption/decryption. Note: Due to the nature of CFB you should use the same key schedule for both encryption and decryption. So a context initialized with esp_aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
Generate random bytes. \warning This function **can** fail! Callers MUST check the return status and MUST NOT use the content of the output buffer if the return status is not #PSA_SUCCESS.
Retrieve all the publicly-accessible attributes of a key.
Export a key in binary format. The output of this function can be passed to psa_import_key() to create an equivalent object. If the implementation of psa_import_key() supports other formats beyond the format specified here, the output from psa_export_key() must use the representation specified here, not the original representation. For standard key types, the output format is as follows: - For symmetric keys (including MAC keys), the format is the raw bytes of the key. - For DES, the key data consists of 8 bytes. The parity bits must be correct. - For Triple-DES, the format is the concatenation of the two or three DES keys. - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEY_PAIR), the format is the non-encrypted DER encoding of the representation defined by PKCS\#1 (RFC 8017) as `RSAPrivateKey`, version 0. ``` RSAPrivateKey ::= SEQUENCE { version INTEGER, -- must be 0 modulus INTEGER, -- n publicExponent INTEGER, -- e privateExponent INTEGER, -- d prime1 INTEGER, -- p prime2 INTEGER, -- q exponent1 INTEGER, -- d mod (p-1) exponent2 INTEGER, -- d mod (q-1) coefficient INTEGER, -- (inverse of q) mod p } ``` - For elliptic curve key pairs (key types for which #PSA_KEY_TYPE_IS_ECC_KEY_PAIR is true), the format is a representation of the private value as a `ceiling(m/8)`-byte string where `m` is the bit size associated with the curve, i.e. the bit size of the order of the curve's coordinate field. This byte string is in little-endian order for Montgomery curves (curve types `PSA_ECC_FAMILY_CURVEXXX`), and in big-endian order for Weierstrass curves (curve types `PSA_ECC_FAMILY_SECTXXX`, `PSA_ECC_FAMILY_SECPXXX` and `PSA_ECC_FAMILY_BRAINPOOL_PXXX`). For Weierstrass curves, this is the content of the `privateKey` field of the `ECPrivateKey` format defined by RFC 5915. For Montgomery curves, the format is defined by RFC 7748, and output is masked according to §5. For twisted Edwards curves, the private key is as defined by RFC 8032 (a 32-byte string for Edwards25519, a 57-byte string for Edwards448). - For Diffie-Hellman key exchange key pairs (key types for which #PSA_KEY_TYPE_IS_DH_KEY_PAIR is true), the format is the representation of the private key `x` as a big-endian byte string. The length of the byte string is the private key size in bytes (leading zeroes are not stripped). - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is true), the format is the same as for psa_export_public_key(). The policy on the key must have the usage flag #PSA_KEY_USAGE_EXPORT set.
Export a public key or the public part of a key pair in binary format. The output of this function can be passed to psa_import_key() to create an object that is equivalent to the public key. This specification supports a single format for each key type. Implementations may support other formats as long as the standard format is supported. Implementations that support other formats should ensure that the formats are clearly unambiguous so as to minimize the risk that an invalid input is accidentally interpreted according to a different format. For standard key types, the output format is as follows: - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the DER encoding of the representation defined by RFC 3279 §2.3.1 as `RSAPublicKey`. ``` RSAPublicKey ::= SEQUENCE { modulus INTEGER, -- n publicExponent INTEGER } -- e ``` - For elliptic curve keys on a twisted Edwards curve (key types for which #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true and #PSA_KEY_TYPE_ECC_GET_FAMILY returns #PSA_ECC_FAMILY_TWISTED_EDWARDS), the public key is as defined by RFC 8032 (a 32-byte string for Edwards25519, a 57-byte string for Edwards448). - For other elliptic curve public keys (key types for which #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true), the format is the uncompressed representation defined by SEC1 §2.3.3 as the content of an ECPoint. Let `m` be the bit size associated with the curve, i.e. the bit size of `q` for a curve over `F_q`. The representation consists of: - The byte 0x04; - `x_P` as a `ceiling(m/8)`-byte string, big-endian; - `y_P` as a `ceiling(m/8)`-byte string, big-endian. - For Diffie-Hellman key exchange public keys (key types for which #PSA_KEY_TYPE_IS_DH_PUBLIC_KEY is true), the format is the representation of the public key `y = g^x mod p` as a big-endian byte string. The length of the byte string is the length of the base prime `p` in bytes. Exporting a public key object or the public part of a key pair is always permitted, regardless of the key's usage flags.
Translate the high-level part of an Mbed TLS error code into a string representation. This function returns a const pointer to an un-modifiable string. The caller must not try to modify the string. It is intended to be used mostly for logging purposes.
Translate the low-level part of an Mbed TLS error code into a string representation. This function returns a const pointer to an un-modifiable string. The caller must not try to modify the string. It is intended to be used mostly for logging purposes.
Check if an MPI is less than the other in constant time.
Swap the contents of two MPIs.
This function retrieves the list of internal group identifiers of all supported curves in the order of preference.
This function retrieves curve information from a TLS NamedCurve value.
This function sets up an ECP group context from a TLS ECParameters record as defined in RFC 4492, Section 5.4.
This function exports an elliptic curve public key.
This function checks that the keypair objects \p pub and \p prv have the same group and the same public point, and that the private key in \p prv is consistent with the public key.
This function retrieves padding mode of initialized RSA context.
This function retrieves hash identifier of mbedtls_md_type_t type.
This function retrieves the length of the RSA modulus in bits.
This function generates an RSA keypair.
This function checks a public-private RSA key pair. It checks each of the contexts, and makes sure they match.
This function performs a PKCS#1 v1.5 encryption operation (RSAES-PKCS1-v1_5-ENCRYPT).
This function performs a PKCS#1 v1.5 signature operation (RSASSA-PKCS1-v1_5-SIGN).
This function performs a PKCS#1 v1.5 verification operation (RSASSA-PKCS1-v1_5-VERIFY).
This function performs a PKCS#1 v2.1 PSS verification operation (RSASSA-PSS-VERIFY).
Library deinitialization. This function clears all data associated with the PSA layer, including the whole key store. This function is not thread safe, it wipes every key slot regardless of state and reader count. It should only be called when no slot is in use. This is an Mbed TLS extension.
Parses and splits an ASN.1 "SEQUENCE OF ". Updates the pointer to immediately behind the full sequence tag. This function allocates memory for the sequence elements. You can free the allocated memory with mbedtls_asn1_sequence_free().
Traverse an ASN.1 SEQUENCE container and call a callback for each entry. This function checks that the input is a SEQUENCE of elements that each have a "must" tag, and calls a callback function on the elements that have a "may" tag. For example, to validate that the input is a SEQUENCE of `tag1` and call `cb` on each element, use ``` mbedtls_asn1_traverse_sequence_of(&p, end, 0xff, tag1, 0, 0, cb, ctx); ``` To validate that the input is a SEQUENCE of ANY and call `cb` on each element, use ``` mbedtls_asn1_traverse_sequence_of(&p, end, 0, 0, 0, 0, cb, ctx); ``` To validate that the input is a SEQUENCE of CHOICE {NULL, OCTET STRING} and call `cb` on each element that is an OCTET STRING, use ``` mbedtls_asn1_traverse_sequence_of(&p, end, 0xfe, 0x04, 0xff, 0x04, cb, ctx); ``` The callback is called on the elements with a "may" tag from left to right. If the input is not a valid SEQUENCE of elements with a "must" tag, the callback is called on the elements up to the leftmost point where the input is invalid. \warning This function is still experimental and may change at any time.
Find a specific named_data entry in a sequence or list based on the OID.
Return the name of the ciphersuite associated with the given ID
Set the current endpoint type
Set the transport type (TLS or DTLS). Default: TLS
Enable / Disable TLS 1.2 session tickets (client only, TLS 1.2 only). Enabled by default.
Return the current maximum outgoing record payload in bytes. \sa mbedtls_ssl_get_max_out_record_payload() \sa mbedtls_ssl_get_record_expansion()
Initiate an SSL renegotiation on the running connection. Client: perform the renegotiation right now. Server: request renegotiation, which will be performed during the next call to mbedtls_ssl_read() if honored by client. \warning If this function returns something other than \c 0, #MBEDTLS_ERR_SSL_WANT_READ, #MBEDTLS_ERR_SSL_WANT_WRITE, #MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS or #MBEDTLS_ERR_SSL_CRYPTO_IN_PROGRESS, you must stop using the SSL context for reading or writing, and either free it or call \c mbedtls_ssl_session_reset() on it before re-using it for a new connection; the current connection must be closed.
Get the length of the password in bytes from given inputs.
Get the password from given inputs.
Get the length of the user id in bytes from given inputs.
Get the length of the peer id in bytes from given inputs.
Get the user id from given inputs.
Get the peer id from given inputs.
Get the cipher suite from given inputs.
Encrypt message (including padding if relevant).
Parse one or more CRLs and append them to the chained list
Load one or more certificates and add them to the chained list. Parses permissively. If some certificates can be parsed, the result is the number of failed certificates it encountered. If none complete correctly, the first error is returned.
Restartable version of \c mbedtls_crt_verify_with_profile()
Check usage of certificate against extendedKeyUsage.
Verify the certificate revocation status
Write a built up certificate to a X509 DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer
This function generates an EC key pair and exports its in the format used in a TLS ServerKeyExchange handshake message. This is the second function used by a TLS server for ECDHE ciphersuites. (It is called after mbedtls_ecdh_setup().) \see ecp.h
This function parses the ECDHE parameters in a TLS ServerKeyExchange handshake message. \see ecp.h
This function parses a CN string as an IP address.
Trigger an extra gather poll for the accumulator (Thread-safe if MBEDTLS_THREADING_C is enabled)
Checkup routine Verifies the integrity of the hardware entropy source provided by the function 'mbedtls_hardware_poll()'. Note this is the only hardware entropy source that is known at link time, and other entropy sources configured dynamically at runtime by the function mbedtls_entropy_add_source() will not be tested.
This function turns prediction resistance on or off. The default value is off.
This function updates the state of the CTR_DRBG context.
This function updates a CTR_DRBG instance with additional data and uses it to generate random data. This function automatically reseeds if the reseed counter is exceeded or prediction resistance is enabled.
This function writes a seed file.
MD5 process data block (internal use only) \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Translate a string containing a dotted-decimal representation of an ASN.1 OID into its encoded form (e.g. "1.2.840.113549" into "\x2A\x86\x48\x86\xF7\x0D"). On success, this function allocates oid->buf from the heap. It must be freed by the caller using mbedtls_free().
Translate an X.509 attribute type OID into the short name (e.g. the OID for an X520 Common Name into "CN")
Translate PublicKeyAlgorithm OID into pk_type
Translate NamedCurve OID into an EC group identifier
Translate AlgorithmIdentifier OID into an EC group identifier, for curves that are directly encoded at this level
Translate SignatureAlgorithm OID into md_type and pk_type
Translate SignatureAlgorithm OID into description
Translate hmac algorithm OID into md_type
Translate Extended Key Usage OID into description
Translate certificate policies OID into description
Translate md_type into hash algorithm OID
Translate encryption algorithm OID into cipher_type
Translate PKCS#12 PBE algorithm OID into md_type and cipher_type
Return an offset into a buffer. This is just the addition of an offset to a pointer, except that this function also accepts an offset of 0 into a buffer whose pointer is null. (`p + n` has undefined behavior when `p` is null, even when `n == 0`. A null pointer is a valid buffer pointer when the size is 0, for example as the result of `malloc(0)` on some platforms.)
Return the maximum fragment length (payload, in bytes) for the input buffer. This is the negotiated maximum fragment length, or, if there is none, MBEDTLS_SSL_IN_CONTENT_LEN. If it is not defined either, the value is 2^14. This function works as its predecessor, \c mbedtls_ssl_get_max_frag_len(). \sa mbedtls_ssl_conf_max_frag_len() \sa mbedtls_ssl_get_max_in_record_payload()
Write a NULL tag (#MBEDTLS_ASN1_NULL) with zero data in ASN.1 format.
Write a bitstring tag (#MBEDTLS_ASN1_BIT_STRING) and value in ASN.1 format.
Write an octet string tag (#MBEDTLS_ASN1_OCTET_STRING) and value in ASN.1 format.
Given an SSL context and its associated configuration, write the TLS 1.2 specific extensions of the ClientHello message.
PKCS#5 PBES2 function \warning When decrypting: - This function validates the CBC padding and returns #MBEDTLS_ERR_PKCS5_PASSWORD_MISMATCH if the padding is invalid. Note that this can help active adversaries attempting to brute-forcing the password. Note also that there is no guarantee that an invalid password will be detected (the chances of a valid padding with a random password are about 1/255).
Choose between an mbedtls_ct_condition_t and 0. Functionally equivalent to: condition ? if1 : 0. Functionally equivalent to mbedtls_ct_bool_if(condition, if1, 0) but results in smaller code size.
Choose between two mbedtls_ct_condition_t values. Functionally equivalent to: condition ? if1 : if0.
Choose between two error values. The values must be in the range [-32767..0]. Functionally equivalent to: condition ? if1 : if0.
Conditionally set a block of memory to zero. Regardless of the condition, every byte will be read once and written to once. \warning Unlike mbedtls_platform_zeroize, this does not have the same guarantees about not being optimised away if the memory is never read again.
Shift some data towards the left inside a buffer. Functionally equivalent to: memmove(start, start + offset, total - offset); memset(start + (total - offset), 0, offset); Timing independence comes at the expense of performance.
Copy data from a secret position. Functionally equivalent to: memcpy(dst, src + offset, len) This function copies \p len bytes from \p src + \p offset to \p dst, with a code flow and memory access pattern that does not depend on \p offset, but only on \p offset_min, \p offset_max and \p len.
Perform a modular exponentiation: X = A^E mod N \warning This function is not constant time with respect to \p E (the exponent).
Compare a machine integer with an MPI. This function operates in constant time with respect to the values of \p min and \p A.
Perform a safe conditional swap of two MPIs which doesn't reveal whether the swap was done or not.
Import X from unsigned binary data, little-endian. The MPI needs to have enough limbs to store the full value (including any most significant zero bytes in the input).
Import X from unsigned binary data, big-endian. The MPI needs to have enough limbs to store the full value (including any most significant zero bytes in the input).
Export A into unsigned binary data, little-endian.
Export A into unsigned binary data, big-endian.
Shift an MPI in-place left by a number of bits. Shifting by more bits than there are bit positions in \p X will produce an unspecified result. This function's execution time depends on the value of \p count (and of course \p limbs).
Add two fixed-size large unsigned integers, returning the carry. Calculates `A + B` where `A` and `B` have the same size. This function operates modulo `2^(biL*limbs)` and returns the carry (1 if there was a wraparound, and 0 otherwise). \p X may be aliased to \p A or \p B.
Perform a known-size multiplication \p X may not be aliased to any of the inputs for this function. \p A may be aliased to \p B.
Generate a random number uniformly in a range. This function generates a random number between \p min inclusive and \p N exclusive. The procedure complies with RFC 6979 §3.3 (deterministic ECDSA) when the RNG is a suitably parametrized instance of HMAC_DRBG and \p min is \c 1.
Returns the number of limbs of working memory required for a call to `mbedtls_mpi_core_exp_mod()`.
Perform a modular exponentiation with public or secret exponent: X = A^E mod N, where \p A is already in Montgomery form. \warning This function is not constant time with respect to \p E (the exponent). \p X may be aliased to \p A, but not to \p RR or \p E, even if \p E_limbs == \p AN_limbs.
Perform a modular exponentiation with secret exponent: X = A^E mod N, where \p A is already in Montgomery form. \p X may be aliased to \p A, but not to \p RR or \p E, even if \p E_limbs == \p AN_limbs.
Subtract unsigned integer from known-size large unsigned integers. Return the borrow.
Determine if a given MPI has the value \c 0 in constant time with respect to the value (but not with respect to the number of limbs).
Convert an MPI from Montgomery form. \p X may be aliased to \p A, but may not otherwise overlap it. \p X may not alias \p N (it is in canonical form, so must be strictly less than \p N). This function is a thin wrapper around `mbedtls_mpi_core_montmul()` that is an alternative to calling `mbedtls_mpi_mod_raw_from_mont_rep()` when we don't want to allocate memory.
Count leading zero bits in a given integer. \warning The result is undefined if \p a == 0
This function turns prediction resistance on or off. The default value is off.
This function updates an HMAC_DRBG instance with additional data and uses it to generate random data. This function automatically reseeds if the reseed counter is exceeded or prediction resistance is enabled.
This function writes a seed file.
PKCS12 Password Based function (encryption / decryption) for cipher-based and mbedtls_md-based PBE's \warning When decrypting: - This function validates the CBC padding and returns #MBEDTLS_ERR_PKCS12_PASSWORD_MISMATCH if the padding is invalid. Note that this can help active adversaries attempting to brute-forcing the password. Note also that there is no guarantee that an invalid password will be detected (the chances of a valid padding with a random password are about 1/255).
Unallocate all PKCS #7 data and zeroize the memory. It doesn't free \p pkcs7 itself. This should be done by the caller.
This function is analogue to \c mbedtls_rsa_rsassa_pss_sign(). The only difference between them is that this function is more flexible on the parameters of \p ctx that are set with \c mbedtls_rsa_set_padding().
Export a key in binary format
Calculate the intersection of two algorithm usage policies. Return 0 (which allows no operation) on incompatibility.
Import a key in binary format.
Export a public key or the public part of a key pair in binary format.
Validate optional attributes during key creation. Some key attributes are optional during key creation. If they are specified in the attributes structure, check that they are consistent with the data in the slot. This function should be called near the end of key creation, after the slot in memory is fully populated but before saving persistent data.
Sign a message with a private key. For hash-and-sign algorithms, this includes the hashing step.
Verify the signature of a message with a public key, using a hash-and-sign verification algorithm.
Sign an already-calculated hash with a private key.
Verify the signature a hash or short message using a public key.
Get the number of ops that a hash signing operation has taken for the previous call. If no call or work has taken place, this will return zero.
Get the number of ops that a hash verification operation has taken for the previous call. If no call or work has taken place, this will return zero.
Start signing a hash or short message with a private key, in an interruptible manner.
Continue and eventually complete the action of signing a hash or short message with a private key, in an interruptible manner.
Abort a sign hash operation.
Start reading and verifying a hash or short message, in an interruptible manner.
Continue and eventually complete the action of signing a hash or short message with a private key, in an interruptible manner.
Abort a verify signed hash operation.
Perform a key agreement and return the raw shared secret, using built-in raw key agreement functions.
Internal function for raw key agreement Calls the driver wrapper which will hand off key agreement task to the driver's implementation if a driver is present. Fallback specified in the driver wrapper is built-in raw key agreement (psa_key_agreement_raw_builtin).
Process an authenticated encryption operation.
Process an authenticated decryption operation.
Get implicitly confirmed shared secret from a PAKE.
Set up a multipart MAC calculation operation using Mbed TLS.
Set up a multipart MAC verification operation using Mbed TLS.
Finish the calculation of the MAC of a message using Mbed TLS. The PSA core calls mbedtls_psa_mac_sign_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to mbedtls_psa_mac_update(). Whether this function returns successfully or not, the PSA core subsequently aborts the operation by calling mbedtls_psa_mac_abort().
Finish the calculation of the MAC of a message and compare it with an expected value using Mbed TLS. The PSA core calls mbedtls_psa_mac_verify_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to mbedtls_psa_mac_update(). It then compares the calculated MAC with the expected MAC passed as a parameter to this function. Whether this function returns successfully or not, the PSA core subsequently aborts the operation by calling mbedtls_psa_mac_abort().
Set the session information for a password-authenticated key exchange.
Get output for a step of a password-authenticated key exchange.
Provide input for a step of a password-authenticated key exchange.
Set the key for a multipart authenticated encryption operation. If an error occurs at any step after a call to mbedtls_psa_aead_encrypt_setup(), the operation is reset by the PSA core by a call to mbedtls_psa_aead_abort(). The PSA core may call mbedtls_psa_aead_abort() at any time after the operation has been initialized, and is required to when the operation is no longer needed.
Set the key for a multipart authenticated decryption operation. If an error occurs at any step after a call to mbedtls_psa_aead_decrypt_setup(), the PSA core resets the operation by a call to mbedtls_psa_aead_abort(). The PSA core may call mbedtls_psa_aead_abort() at any time after the operation has been initialized, and is required to when the operation is no longer needed.
Set the nonce for an authenticated encryption or decryption operation. This function sets the nonce for the authenticated encryption or decryption operation. The PSA core calls mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup() before calling this function. If this function returns an error status, the PSA core will call mbedtls_psa_aead_abort().
Declare the lengths of the message and additional data for AEAD. The PSA core calls this function before calling mbedtls_psa_aead_update_ad() or mbedtls_psa_aead_update() if the algorithm for the operation requires it. If the algorithm does not require it, calling this function is optional, but if this function is called then the implementation must enforce the lengths. The PSA core may call this function before or after setting the nonce with mbedtls_psa_aead_set_nonce(). - For #PSA_ALG_CCM, calling this function is required. - For the other AEAD algorithms defined in this specification, calling this function is not required. If this function returns an error status, the PSA core calls mbedtls_psa_aead_abort().
Pass additional data to an active AEAD operation. Additional data is authenticated, but not encrypted. The PSA core can call this function multiple times to pass successive fragments of the additional data. It will not call this function after passing data to encrypt or decrypt with mbedtls_psa_aead_update(). Before calling this function, the PSA core will: 1. Call either mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup(). 2. Set the nonce with mbedtls_psa_aead_set_nonce(). If this function returns an error status, the PSA core will call mbedtls_psa_aead_abort().
Encrypt or decrypt a message fragment in an active AEAD operation. Before calling this function, the PSA core will: 1. Call either mbedtls_psa_aead_encrypt_setup() or mbedtls_psa_aead_decrypt_setup(). The choice of setup function determines whether this function encrypts or decrypts its input. 2. Set the nonce with mbedtls_psa_aead_set_nonce(). 3. Call mbedtls_psa_aead_update_ad() to pass all the additional data. If this function returns an error status, the PSA core will call mbedtls_psa_aead_abort(). This function does not require the input to be aligned to any particular block boundary. If the implementation can only process a whole block at a time, it must consume all the input provided, but it may delay the end of the corresponding output until a subsequent call to mbedtls_psa_aead_update(), mbedtls_psa_aead_finish() provides sufficient input. The amount of data that can be delayed in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE.
Calculate the hash (digest) of a message using Mbed TLS routines.
Clone an Mbed TLS hash operation. This function copies the state of an ongoing hash operation to a new operation object. In other words, this function is equivalent to calling mbedtls_psa_hash_setup() on \p target_operation with the same algorithm that \p source_operation was set up for, then mbedtls_psa_hash_update() on \p target_operation with the same input that that was passed to \p source_operation. After this function returns, the two objects are independent, i.e. subsequent calls involving one of the objects do not affect the other object.
Calculate the MAC (message authentication code) of a message using Mbed TLS.
Import an RSA key in binary format.
Decrypt a short message with a private key. - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
Export a public RSA key or the public part of an RSA key pair in binary format.
Sign an already-calculated hash with an RSA private key.
Verify the signature a hash or short message using a public RSA key.
Encrypt a short message with a public key. - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
Load the public part of an internal ECP, if required.
Import an ECP key in binary format.
Export an ECP public key or the public part of an ECP key pair in binary format.
Sign an already-calculated hash with ECDSA.
Verify an ECDSA hash or short message signature.
Perform a key agreement and return the raw ECDH shared secret.
Perform a key agreement and return the FFDH shared secret.
Export a public key or the public part of a DH key pair in binary format.
Checks if persistent data is stored for the given key slot number This function checks if any key data or metadata exists for the key slot in the persistent storage.
Format key data and metadata and save to a location for given key slot. This function formats the key data and metadata and saves it to a persistent storage backend. The storage location corresponding to the key slot must be empty, otherwise this function will fail. This function should be called after loading the key into an internal slot to ensure the persistent key is not saved into a storage location corresponding to an already occupied non-persistent key, as well as ensuring the key data is validated. Note: This function will only succeed for key buffers which are not empty. If passed a NULL pointer or zero-length, the function will fail with #PSA_ERROR_INVALID_ARGUMENT.
Parses key data and metadata and load persistent key for given key slot number. This function reads from a storage backend, parses the key data and metadata and writes them to the appropriate output parameters. Note: This function allocates a buffer and returns a pointer to it through the data parameter. On successful return, the pointer is guaranteed to be valid and the buffer contains at least one byte of data. psa_free_persistent_key_data() must be called on the data buffer afterwards to zeroize and free this buffer.
Remove persistent data for the given key slot number.
Free the temporary buffer allocated by psa_load_persistent_key(). This function must be called at some point after psa_load_persistent_key() to zeroize and free the memory allocated to the buffer in that function.
Formats key data and metadata for persistent storage
Parses persistent storage data into key data and metadata
Initialize the key slot structures.
Delete all data from key slots in memory. This function is not thread safe, it wipes every key slot regardless of state and reader count. It should only be called when no slot is in use. This does not affect persistent storage.
Return a key slot to the free list. Call this function when a slot obtained from psa_reserve_free_key_slot() is no longer in use. If multi-threading is enabled, the caller must hold the global key slot mutex.
Validate a key's location. This function checks whether the key's attributes point to a location that is known to the PSA Core, and returns the driver function table if the key is to be found in an external location.
Validate the persistence of a key.
Encrypt a message using a symmetric cipher.
Decrypt a message using a symmetric cipher.
This function generates a DHM key pair and exports its public part together with the DHM parameters in the format used in a TLS ServerKeyExchange handshake message.
This function sets the prime modulus and generator.
This function returns the size of the prime modulus in bits.
This function imports the raw public value of the peer.
Get a pointer to the slot where the given volatile key is located.
Get a pointer to an entry in the persistent key cache.
create a new or modify an existing uid/value pair
Retrieve the value associated with a provided uid
Convert a single raw coordinate to DER ASN.1 format. The output der buffer is filled backward (i.e. starting from its end). \warning Raw and der buffer must not be overlapping.
Convert a single integer from ASN.1 DER format to raw. \warning Der and raw buffers must not be overlapping.
Generate Hash(M') as in RFC 8017 page 43 points 5 and 6.
Compute RSA prime moduli P, Q from public modulus N=PQ and a pair of private and public key.
Compute RSA private exponent from prime moduli and public key.
Check validity of core RSA parameters
Check validity of RSA CRT parameters
There is a need for the value of integer N' such that B^-1(B-1)-N^-1N'=1, where B^-1(B-1) mod N=1. Actually, only the least significant part of N' is needed, hence the definition N0'=N' mod b. We reproduce below the simple algorithm from an article by Dusse and Kaliski to efficiently find N0' from N0 and b
Starts a (X * Y) Mod M calculation in hardware. Rinv and M_prime needs to be precalculated in software.
Starts a (X * Y) calculation in hardware.
Special-case of (X * Y), where we use hardware montgomery mod multiplication to calculate result where either A or B are >2048 bits so can't use the standard multiplication method.
DigestAlgorithmIdentifier ::= AlgorithmIdentifier This is from x509.h
version Version Version ::= INTEGER
SignerInfo ::= SEQUENCE { version Version; issuerAndSerialNumber IssuerAndSerialNumber, digestAlgorithm DigestAlgorithmIdentifier, authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL, digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier, encryptedDigest EncryptedDigest, unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL, Returns 0 if the signerInfo is valid. Return negative error code for failure. Structure must not contain vales for authenticatedAttributes and unauthenticatedAttributes.
Load a Certificate Signing Request (CSR), DER or PEM format
Write a CSR (Certificate Signing Request) to a DER structure Note: data is written at the end of the buffer! Use the return value to determine where you should start using the buffer
Set the Diffie-Hellman public P and G values from big-endian binary presentations. (Default values: MBEDTLS_DHM_RFC3526_MODP_2048_[PG]_BIN)
Helper to Compute a hash from md_type
Platform-specific implementation of gmtime_r() The function is a thread-safe abstraction that behaves similarly to the gmtime_r() function from Unix/POSIX. Mbed TLS will try to identify the underlying platform and make use of an appropriate underlying implementation (e.g. gmtime_r() for POSIX and gmtime_s() for Windows). If this is not possible, then gmtime() will be used. In this case, calls from the library to gmtime() will be guarded by the mutex mbedtls_threading_gmtime_mutex if MBEDTLS_THREADING_C is enabled. It is recommended that calls from outside the library are also guarded by this mutex. If MBEDTLS_PLATFORM_GMTIME_R_ALT is defined, then Mbed TLS will unconditionally use the alternative implementation for mbedtls_platform_gmtime_r() supplied by the user at compile time.
This function retrieves curve information from a human-readable name.
This function copies the components of an RSA context.
Set the X.509 security profile used for verification
Enable / Disable renegotiation support for connection when initiated by peer (Default: MBEDTLS_SSL_RENEGOTIATION_DISABLED) \warning It is recommended to always disable renegotiation unless you know you need it and you know what you're doing. In the past, there have been several issues associated with renegotiation or a poor understanding of its properties.
Return the number of application data bytes remaining to be read from the current record.
Return the current TLS version
Check if a public-private pair of keys matches.
Verify a chain of certificates. The verify callback is a user-supplied callback that can clear / modify / add flags for a certificate. If set, the verification callback is called for each certificate in the chain (from the trust-ca down to the presented crt). The parameters for the callback are: (void *parameter, mbedtls_x509_crt *crt, int certificate_depth, int *flags). With the flags representing current flags for that specific certificate and the certificate depth from the bottom (Peer cert depth = 0). All flags left after returning from the callback are also returned to the application. The function should return 0 for anything (including invalid certificates) other than fatal error, as a non-zero return code immediately aborts the verification process. For fatal errors, a specific error code should be used (different from MBEDTLS_ERR_X509_CERT_VERIFY_FAILED which should not be returned at this point), or MBEDTLS_ERR_X509_FATAL_ERROR can be used if no better code is available.
Write an AlgorithmIdentifier sequence in ASN.1 format.
Set the debug callback The callback has the following argument: void * opaque context for the callback int debug level const char * file name int line number const char * message
Set the timer callbacks (Mandatory for DTLS.)
Register callbacks for DTLS cookies (Server only. DTLS only.) Default: dummy callbacks that fail, in order to force you to register working callbacks (and initialize their context). To disable HelloVerifyRequest, register NULL callbacks. \warning Disabling hello verification allows your server to be used for amplification in DoS attacks against other hosts. Only disable if you known this can't happen in your particular environment.
Set client's transport-level identification info. (Server only. DTLS only.) This is usually the IP address (and port), but could be anything identify the client depending on the underlying network stack. Used for HelloVerifyRequest with DTLS. This is *not* used to route the actual packets.
Set retransmit timeout values for the DTLS handshake. (DTLS only, no effect on TLS.)
Set the allowed groups in order of preference. On server: This only affects the choice of key agreement mechanism On client: this affects the list of groups offered for any use. The server can override our preference order. Both sides: limits the set of groups accepted for use in key sharing.
Initialize cookie context
Setup cookie context (generate keys)
Generate cookie, see \c mbedtls_ssl_cookie_write_t
Verify cookie, see \c mbedtls_ssl_cookie_write_t
Configure pre-shared keys (PSKs) and their identities to be used in PSK-based ciphersuites. Only one PSK can be registered, through either mbedtls_ssl_conf_psk() or mbedtls_ssl_conf_psk_opaque(). If you attempt to register more than one PSK, this function fails, though this may change in future versions, which may add support for multiple PSKs.
Set the maximum supported version sent from the client side and/or accepted at the server side.
Set the minimum supported version sent from the client side and/or accepted at the server side.
The SHA-224 checkup routine.
The SHA-256 checkup routine.
\def PSA_MAC_OPERATION_INIT This macro returns a suitable initializer for a MAC operation object of type #psa_mac_operation_t. Return an initial value for a MAC operation object.
\def PSA_AEAD_OPERATION_INIT This macro returns a suitable initializer for an AEAD operation object of type #psa_aead_operation_t. Return an initial value for an AEAD operation object.
\def PSA_CIPHER_OPERATION_INIT This macro returns a suitable initializer for a cipher operation object of type #psa_cipher_operation_t. Return an initial value for a cipher operation object.
\def PSA_KEY_DERIVATION_OPERATION_INIT This macro returns a suitable initializer for a key derivation operation object of type #psa_key_derivation_operation_t. Return an initial value for a key derivation operation object.
\def PSA_KEY_ATTRIBUTES_INIT This macro returns a suitable initializer for a key attribute structure of type #psa_key_attributes_t. Return an initial value for a key attributes structure.
Declare a key as persistent and set its key identifier. If the attribute structure currently declares the key as volatile (which is the default content of an attribute structure), this function sets the lifetime attribute to #PSA_KEY_LIFETIME_PERSISTENT. This function does not access storage, it merely stores the given value in the structure. The persistent key will be written to storage when the attribute structure is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_generate_key_custom(), psa_key_derivation_output_key(), psa_key_derivation_output_key_custom() or psa_copy_key(). This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Set the location of a persistent key. To make a key persistent, you must give it a persistent key identifier with psa_set_key_id(). By default, a key that has a persistent identifier is stored in the default storage area identifier by #PSA_KEY_LIFETIME_PERSISTENT. Call this function to choose a storage area, or to explicitly declare the key as volatile. This function does not access storage, it merely stores the given value in the structure. The persistent key will be written to storage when the attribute structure is passed to a key creation function such as psa_import_key(), psa_generate_key(), psa_generate_key_custom(), psa_key_derivation_output_key(), psa_key_derivation_output_key_custom() or psa_copy_key(). This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate each of its arguments exactly once.
Retrieve the usage flags from key attributes. This function may be declared as `static` (i.e. without external linkage). This function may be provided as a function-like macro, but in this case it must evaluate its argument exactly once.
This function returns the size of the IV or nonce of the cipher, in Bytes.
Retrieve the identifier for a cipher info structure.
Retrieve the PAKE algorithm from a PAKE cipher suite.
Declare the PAKE algorithm for the cipher suite. This function overwrites any PAKE algorithm previously set in \p cipher_suite.
Retrieve the primitive from a PAKE cipher suite.
Declare the primitive for a PAKE cipher suite. This function overwrites any primitive previously set in \p cipher_suite.
Retrieve the PAKE family from a PAKE cipher suite.
Retrieve the PAKE primitive bit-size from a PAKE cipher suite.
Retrieve the hash algorithm from a PAKE cipher suite.
Declare the hash algorithm for a PAKE cipher suite. This function overwrites any hash algorithm previously set in \p cipher_suite. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information.
Check whether a handle is null.
Declare the enrollment algorithm for a key. An operation on a key may indifferently use the algorithm set with psa_set_key_algorithm() or with this function. \warning Setting an enrollment algorithm is not recommended, because using the same key with different algorithms can allow some attacks based on arithmetic relations between different computations made with the same key, or can escalate harmless side channels into exploitable ones. Use this function only if it is necessary to support a protocol for which it has been verified that the usage of the key with multiple algorithms is safe.
Get the creation time of a session ticket.
Return an initial value for a PAKE operation object.
This function generates an ECDSA keypair on the given curve. \see ecp.h
Verify the signature of a message with a public key, using a hash-and-sign verification algorithm.
Sign a hash or short message with a private key. Note that to perform a hash-and-sign signature algorithm, you must first calculate the hash by calling psa_hash_setup(), psa_hash_update() and psa_hash_finish(), or alternatively by calling psa_hash_compute(). Then pass the resulting hash as the \p hash parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) to determine the hash algorithm to use.
Verify the signature of a hash or short message using a public key. Note that to perform a hash-and-sign signature algorithm, you must first calculate the hash by calling psa_hash_setup(), psa_hash_update() and psa_hash_finish(), or alternatively by calling psa_hash_compute(). Then pass the resulting hash as the \p hash parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) to determine the hash algorithm to use.
Encrypt a short message with a public key. - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
Decrypt a short message with a private key. - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is supported.
Set up a key derivation operation. A key derivation algorithm takes some inputs and uses them to generate a byte stream in a deterministic way. This byte stream can be used to produce keys and other cryptographic material. To derive a key: -# Start with an initialized object of type #psa_key_derivation_operation_t. -# Call psa_key_derivation_setup() to select the algorithm. -# Provide the inputs for the key derivation by calling psa_key_derivation_input_bytes() or psa_key_derivation_input_key() as appropriate. Which inputs are needed, in what order, and whether they may be keys and if so of what type depends on the algorithm. -# Optionally set the operation's maximum capacity with psa_key_derivation_set_capacity(). You may do this before, in the middle of or after providing inputs. For some algorithms, this step is mandatory because the output depends on the maximum capacity. -# To derive a key, call psa_key_derivation_output_key() or psa_key_derivation_output_key_custom(). To derive a byte string for a different purpose, call psa_key_derivation_output_bytes(). Successive calls to these functions use successive output bytes calculated by the key derivation algorithm. -# Clean up the key derivation operation object with psa_key_derivation_abort(). If this function returns an error, the key derivation operation object is not changed. If an error occurs at any step after a call to psa_key_derivation_setup(), the operation will need to be reset by a call to psa_key_derivation_abort(). Implementations must reject an attempt to derive a key of size 0.
Retrieve the current capacity of a key derivation operation. The capacity of a key derivation is the maximum number of bytes that it can return. When you get *N* bytes of output from a key derivation operation, this reduces its capacity by *N*.
Set the maximum capacity of a key derivation operation. The capacity of a key derivation operation is the maximum number of bytes that the key derivation operation can return from this point onwards.
Provide a numeric input for key derivation or key agreement. Which inputs are required and in what order depends on the algorithm. However, when an algorithm requires a particular order, numeric inputs usually come first as they tend to be configuration parameters. Refer to the documentation of each key derivation or key agreement algorithm for information. This function is used for inputs which are fixed-size non-negative integers. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
Provide an input for key derivation in the form of a key. Which inputs are required and in what order depends on the algorithm. Refer to the documentation of each key derivation or key agreement algorithm for information. This function obtains input from a key object, which is usually correct for secret inputs or for non-secret personalization strings kept in the key store. To pass a non-secret parameter which is not in the key store, call psa_key_derivation_input_bytes() instead of this function. Refer to the documentation of individual step types (`PSA_KEY_DERIVATION_INPUT_xxx` values of type ::psa_key_derivation_step_t) for more information. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
Perform a key agreement and use the shared secret as input to a key derivation. A key agreement algorithm takes two inputs: a private key \p private_key a public key \p peer_key. The result of this function is passed as input to a key derivation. The output of this key derivation can be extracted by reading from the resulting operation to produce keys and other cryptographic material. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
Derive a key from an ongoing key derivation operation. This function calculates output bytes from a key derivation algorithm and uses those bytes to generate a key deterministically. The key's location, usage policy, type and size are taken from \p attributes. If you view the key derivation's output as a stream of bytes, this function destructively reads as many bytes as required from the stream. The operation's capacity decreases by the number of bytes read. If this function returns an error status other than #PSA_ERROR_INSUFFICIENT_DATA, the operation enters an error state and must be aborted by calling psa_key_derivation_abort(). How much output is produced and consumed from the operation, and how the key is derived, depends on the key type and on the key size (denoted \c bits below): - For key types for which the key is an arbitrary sequence of bytes of a given size, this function is functionally equivalent to calling #psa_key_derivation_output_bytes and passing the resulting output to #psa_import_key. However, this function has a security benefit: if the implementation provides an isolation boundary then the key material is not exposed outside the isolation boundary. As a consequence, for these key types, this function always consumes exactly (\c bits / 8) bytes from the operation. The following key types defined in this specification follow this scheme: - #PSA_KEY_TYPE_AES; - #PSA_KEY_TYPE_ARIA; - #PSA_KEY_TYPE_CAMELLIA; - #PSA_KEY_TYPE_DERIVE; - #PSA_KEY_TYPE_HMAC; - #PSA_KEY_TYPE_PASSWORD_HASH. - For ECC keys on a Montgomery elliptic curve (#PSA_KEY_TYPE_ECC_KEY_PAIR(\c curve) where \c curve designates a Montgomery curve), this function always draws a byte string whose length is determined by the curve, and sets the mandatory bits accordingly. That is: - Curve25519 (#PSA_ECC_FAMILY_MONTGOMERY, 255 bits): draw a 32-byte string and process it as specified in RFC 7748 §5. - Curve448 (#PSA_ECC_FAMILY_MONTGOMERY, 448 bits): draw a 56-byte string and process it as specified in RFC 7748 §5. - For key types for which the key is represented by a single sequence of \c bits bits with constraints as to which bit sequences are acceptable, this function draws a byte string of length (\c bits / 8) bytes rounded up to the nearest whole number of bytes. If the resulting byte string is acceptable, it becomes the key, otherwise the drawn bytes are discarded. This process is repeated until an acceptable byte string is drawn. The byte string drawn from the operation is interpreted as specified for the output produced by psa_export_key(). The following key types defined in this specification follow this scheme: - #PSA_KEY_TYPE_DES. Force-set the parity bits, but discard forbidden weak keys. For 2-key and 3-key triple-DES, the three keys are generated successively (for example, for 3-key triple-DES, if the first 8 bytes specify a weak key and the next 8 bytes do not, discard the first 8 bytes, use the next 8 bytes as the first key, and continue reading output from the operation to derive the other two keys). - Finite-field Diffie-Hellman keys (#PSA_KEY_TYPE_DH_KEY_PAIR(\c group) where \c group designates any Diffie-Hellman group) and ECC keys on a Weierstrass elliptic curve (#PSA_KEY_TYPE_ECC_KEY_PAIR(\c curve) where \c curve designates a Weierstrass curve). For these key types, interpret the byte string as integer in big-endian order. Discard it if it is not in the range [0, *N* - 2] where *N* is the boundary of the private key domain (the prime *p* for Diffie-Hellman, the subprime *q* for DSA, or the order of the curve's base point for ECC). Add 1 to the resulting integer and use this as the private key *x*. This method allows compliance to NIST standards, specifically the methods titled "key-pair generation by testing candidates" in NIST SP 800-56A §5.6.1.1.4 for Diffie-Hellman, in FIPS 186-4 §B.1.2 for DSA, and in NIST SP 800-56A §5.6.1.2.2 or FIPS 186-4 §B.4.2 for elliptic curve keys. - For other key types, including #PSA_KEY_TYPE_RSA_KEY_PAIR, the way in which the operation output is consumed is implementation-defined. In all cases, the data that is read is discarded from the operation. The operation's capacity is decreased by the number of bytes read. For algorithms that take an input step #PSA_KEY_DERIVATION_INPUT_SECRET, the input to that step must be provided with psa_key_derivation_input_key(). Future versions of this specification may include additional restrictions on the derived key based on the attributes and strength of the secret key.
The SHA-384 checkup routine.
The SHA-512 checkup routine.
Calculate the MAC (message authentication code) of a message.
Calculate the MAC of a message and compare it with a reference value.
Set up a multipart MAC calculation operation. This function sets up the calculation of the MAC (message authentication code) of a byte string. To verify the MAC of a message against an expected value, use psa_mac_verify_setup() instead. The sequence of operations to calculate a MAC is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_mac_operation_t, e.g. #PSA_MAC_OPERATION_INIT. -# Call psa_mac_sign_setup() to specify the algorithm and key. -# Call psa_mac_update() zero, one or more times, passing a fragment of the message each time. The MAC that is calculated is the MAC of the concatenation of these messages in order. -# At the end of the message, call psa_mac_sign_finish() to finish calculating the MAC value and retrieve it. If an error occurs at any step after a call to psa_mac_sign_setup(), the operation will need to be reset by a call to psa_mac_abort(). The application may call psa_mac_abort() at any time after the operation has been initialized. After a successful call to psa_mac_sign_setup(), the application must eventually terminate the operation through one of the following methods: - A successful call to psa_mac_sign_finish(). - A call to psa_mac_abort().
Set up a multipart MAC verification operation. This function sets up the verification of the MAC (message authentication code) of a byte string against an expected value. The sequence of operations to verify a MAC is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_mac_operation_t, e.g. #PSA_MAC_OPERATION_INIT. -# Call psa_mac_verify_setup() to specify the algorithm and key. -# Call psa_mac_update() zero, one or more times, passing a fragment of the message each time. The MAC that is calculated is the MAC of the concatenation of these messages in order. -# At the end of the message, call psa_mac_verify_finish() to finish calculating the actual MAC of the message and verify it against the expected value. If an error occurs at any step after a call to psa_mac_verify_setup(), the operation will need to be reset by a call to psa_mac_abort(). The application may call psa_mac_abort() at any time after the operation has been initialized. After a successful call to psa_mac_verify_setup(), the application must eventually terminate the operation through one of the following methods: - A successful call to psa_mac_verify_finish(). - A call to psa_mac_abort().
Finish the calculation of the MAC of a message and compare it with an expected value. The application must call psa_mac_verify_setup() before calling this function. This function calculates the MAC of the message formed by concatenating the inputs passed to preceding calls to psa_mac_update(). It then compares the calculated MAC with the expected MAC passed as a parameter to this function. When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_mac_abort().
Encrypt a message using a symmetric cipher. This function encrypts a message with a random IV (initialization vector). Use the multipart operation interface with a #psa_cipher_operation_t object to provide other forms of IV.
Decrypt a message using a symmetric cipher. This function decrypts a message encrypted with a symmetric cipher.
Set the key for a multipart symmetric encryption operation. The sequence of operations to encrypt a message with a symmetric cipher is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_cipher_operation_t, e.g. #PSA_CIPHER_OPERATION_INIT. -# Call psa_cipher_encrypt_setup() to specify the algorithm and key. -# Call either psa_cipher_generate_iv() or psa_cipher_set_iv() to generate or set the IV (initialization vector). You should use psa_cipher_generate_iv() unless the protocol you are implementing requires a specific IV value. -# Call psa_cipher_update() zero, one or more times, passing a fragment of the message each time. -# Call psa_cipher_finish(). If an error occurs at any step after a call to psa_cipher_encrypt_setup(), the operation will need to be reset by a call to psa_cipher_abort(). The application may call psa_cipher_abort() at any time after the operation has been initialized. After a successful call to psa_cipher_encrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A successful call to psa_cipher_finish(). - A call to psa_cipher_abort().
Set the key for a multipart symmetric decryption operation. The sequence of operations to decrypt a message with a symmetric cipher is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_cipher_operation_t, e.g. #PSA_CIPHER_OPERATION_INIT. -# Call psa_cipher_decrypt_setup() to specify the algorithm and key. -# Call psa_cipher_set_iv() with the IV (initialization vector) for the decryption. If the IV is prepended to the ciphertext, you can call psa_cipher_update() on a buffer containing the IV followed by the beginning of the message. -# Call psa_cipher_update() zero, one or more times, passing a fragment of the message each time. -# Call psa_cipher_finish(). If an error occurs at any step after a call to psa_cipher_decrypt_setup(), the operation will need to be reset by a call to psa_cipher_abort(). The application may call psa_cipher_abort() at any time after the operation has been initialized. After a successful call to psa_cipher_decrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A successful call to psa_cipher_finish(). - A call to psa_cipher_abort().
Generate an IV for a symmetric encryption operation. This function generates a random IV (initialization vector), nonce or initial counter value for the encryption operation as appropriate for the chosen algorithm, key type and key size. The application must call psa_cipher_encrypt_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
Set the IV for a symmetric encryption or decryption operation. This function sets the IV (initialization vector), nonce or initial counter value for the encryption or decryption operation. The application must call psa_cipher_encrypt_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
Encrypt or decrypt a message fragment in an active cipher operation. Before calling this function, you must: 1. Call either psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup(). The choice of setup function determines whether this function encrypts or decrypts its input. 2. If the algorithm requires an IV, call psa_cipher_generate_iv() (recommended when encrypting) or psa_cipher_set_iv(). If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
Finish encrypting or decrypting a message in a cipher operation. The application must call psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() before calling this function. The choice of setup function determines whether this function encrypts or decrypts its input. This function finishes the encryption or decryption of the message formed by concatenating the inputs passed to preceding calls to psa_cipher_update(). When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_cipher_abort().
Library initialization. Applications must call this function before calling any other function in this module. Applications may call this function more than once. Once a call succeeds, subsequent calls are guaranteed to succeed. If the application calls other functions before calling psa_crypto_init(), the behavior is undefined. Implementations are encouraged to either perform the operation as if the library had been initialized or to return #PSA_ERROR_BAD_STATE or some other applicable error. In particular, implementations should not return a success status if the lack of initialization may have security implications, for example due to improper seeding of the random number generator.
Process an authenticated encryption operation.
Process an authenticated decryption operation.
Set the key for a multipart authenticated encryption operation. The sequence of operations to encrypt a message with authentication is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_aead_operation_t, e.g. #PSA_AEAD_OPERATION_INIT. -# Call psa_aead_encrypt_setup() to specify the algorithm and key. -# If needed, call psa_aead_set_lengths() to specify the length of the inputs to the subsequent calls to psa_aead_update_ad() and psa_aead_update(). See the documentation of psa_aead_set_lengths() for details. -# Call either psa_aead_generate_nonce() or psa_aead_set_nonce() to generate or set the nonce. You should use psa_aead_generate_nonce() unless the protocol you are implementing requires a specific nonce value. -# Call psa_aead_update_ad() zero, one or more times, passing a fragment of the non-encrypted additional authenticated data each time. -# Call psa_aead_update() zero, one or more times, passing a fragment of the message to encrypt each time. -# Call psa_aead_finish(). If an error occurs at any step after a call to psa_aead_encrypt_setup(), the operation will need to be reset by a call to psa_aead_abort(). The application may call psa_aead_abort() at any time after the operation has been initialized. After a successful call to psa_aead_encrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A successful call to psa_aead_finish(). - A call to psa_aead_abort().
Set the key for a multipart authenticated decryption operation. The sequence of operations to decrypt a message with authentication is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_aead_operation_t, e.g. #PSA_AEAD_OPERATION_INIT. -# Call psa_aead_decrypt_setup() to specify the algorithm and key. -# If needed, call psa_aead_set_lengths() to specify the length of the inputs to the subsequent calls to psa_aead_update_ad() and psa_aead_update(). See the documentation of psa_aead_set_lengths() for details. -# Call psa_aead_set_nonce() with the nonce for the decryption. -# Call psa_aead_update_ad() zero, one or more times, passing a fragment of the non-encrypted additional authenticated data each time. -# Call psa_aead_update() zero, one or more times, passing a fragment of the ciphertext to decrypt each time. -# Call psa_aead_verify(). If an error occurs at any step after a call to psa_aead_decrypt_setup(), the operation will need to be reset by a call to psa_aead_abort(). The application may call psa_aead_abort() at any time after the operation has been initialized. After a successful call to psa_aead_decrypt_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A successful call to psa_aead_verify(). - A call to psa_aead_abort().
Generate a random nonce for an authenticated encryption operation. This function generates a random nonce for the authenticated encryption operation with an appropriate size for the chosen algorithm, key type and key size. The application must call psa_aead_encrypt_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
Set the nonce for an authenticated encryption or decryption operation. This function sets the nonce for the authenticated encryption or decryption operation. The application must call psa_aead_encrypt_setup() or psa_aead_decrypt_setup() before calling this function. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
Declare the lengths of the message and additional data for AEAD. The application must call this function before calling psa_aead_update_ad() or psa_aead_update() if the algorithm for the operation requires it. If the algorithm does not require it, calling this function is optional, but if this function is called then the implementation must enforce the lengths. You may call this function before or after setting the nonce with psa_aead_set_nonce() or psa_aead_generate_nonce(). - For #PSA_ALG_CCM, calling this function is required. - For the other AEAD algorithms defined in this specification, calling this function is not required. - For vendor-defined algorithm, refer to the vendor documentation. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
Pass additional data to an active AEAD operation. Additional data is authenticated, but not encrypted. You may call this function multiple times to pass successive fragments of the additional data. You may not call this function after passing data to encrypt or decrypt with psa_aead_update(). Before calling this function, you must: 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort(). \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, there is no guarantee that the input is valid. Therefore, until you have called psa_aead_verify() and it has returned #PSA_SUCCESS, treat the input as untrusted and prepare to undo any action that depends on the input if psa_aead_verify() returns an error status.
Encrypt or decrypt a message fragment in an active AEAD operation. Before calling this function, you must: 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). The choice of setup function determines whether this function encrypts or decrypts its input. 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). 3. Call psa_aead_update_ad() to pass all the additional data. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort(). \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, there is no guarantee that the input is valid. Therefore, until you have called psa_aead_verify() and it has returned #PSA_SUCCESS: - Do not use the output in any way other than storing it in a confidential location. If you take any action that depends on the tentative decrypted data, this action will need to be undone if the input turns out not to be valid. Furthermore, if an adversary can observe that this action took place (for example through timing), they may be able to use this fact as an oracle to decrypt any message encrypted with the same key. - In particular, do not copy the output anywhere but to a memory or storage space that you have exclusive access to. This function does not require the input to be aligned to any particular block boundary. If the implementation can only process a whole block at a time, it must consume all the input provided, but it may delay the end of the corresponding output until a subsequent call to psa_aead_update(), psa_aead_finish() or psa_aead_verify() provides sufficient input. The amount of data that can be delayed in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE.
Finish encrypting a message in an AEAD operation. The operation must have been set up with psa_aead_encrypt_setup(). This function finishes the authentication of the additional data formed by concatenating the inputs passed to preceding calls to psa_aead_update_ad() with the plaintext formed by concatenating the inputs passed to preceding calls to psa_aead_update(). This function has two output buffers: - \p ciphertext contains trailing ciphertext that was buffered from preceding calls to psa_aead_update(). - \p tag contains the authentication tag. When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
Finish authenticating and decrypting a message in an AEAD operation. The operation must have been set up with psa_aead_decrypt_setup(). This function finishes the authenticated decryption of the message components: - The additional data consisting of the concatenation of the inputs passed to preceding calls to psa_aead_update_ad(). - The ciphertext consisting of the concatenation of the inputs passed to preceding calls to psa_aead_update(). - The tag passed to this function call. If the authentication tag is correct, this function outputs any remaining plaintext and reports success. If the authentication tag is not correct, this function returns #PSA_ERROR_INVALID_SIGNATURE. When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_aead_abort().
Sign a message with a private key. For hash-and-sign algorithms, this includes the hashing step.
Deprecated, see esp_aes_internal_decrypt
Deprecated, see esp_aes_internal_encrypt
This function encrypts a buffer using CCM*. \warning Passing \c 0 as \p tag_len means that the message is no longer authenticated.
This function performs a CCM* authenticated decryption of a buffer. \warning Passing \c 0 as \p tag_len means that the message is nos longer authenticated.
This function starts a new CMAC operation with the same key as the previous one. It should be called after finishing the previous CMAC operation with mbedtls_cipher_cmac_finish(). After calling this function, call mbedtls_cipher_cmac_update() to supply the new CMAC operation with data.
The CMAC checkup routine.
Derive a key from an ongoing key derivation operation with custom production parameters.
Perform a key agreement and return the raw shared secret. \warning The raw result of a key agreement algorithm such as finite-field Diffie-Hellman or elliptic curve Diffie-Hellman has biases and should not be used directly as key material. It should instead be passed as input to a key derivation algorithm. To chain a key agreement with a key derivation, use psa_key_derivation_key_agreement() and other functions from the key derivation interface.
Generate a key or key pair. The key is generated randomly. Its location, usage policy, type and size are taken from \p attributes. Implementations must reject an attempt to generate a key of size 0. The following type-specific considerations apply: - For RSA keys (#PSA_KEY_TYPE_RSA_KEY_PAIR), the public exponent is 65537. The modulus is a product of two probabilistic primes between 2^{n-1} and 2^n where n is the bit size specified in the attributes.
Generate a key or key pair using custom production parameters.
Set the maximum number of ops allowed to be executed by an interruptible function in a single call. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises. \warning With implementations that interpret this number as a hard limit, setting this number too small may result in an infinite loop, whereby each call results in immediate return with no ops done (as there is not enough time to execute any), and thus no result will ever be achieved.
Get the maximum number of ops allowed to be executed by an interruptible function in a single call. This will return the last value set by \c psa_interruptible_set_max_ops() or #PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED if that function has never been called. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Get the number of ops that a hash signing operation has taken so far. If the operation has completed, then this will represent the number of ops required for the entire operation. After initialization or calling \c psa_sign_hash_interruptible_abort() on the operation, a value of 0 will be returned. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises. This is a helper provided to help you tune the value passed to \c psa_interruptible_set_max_ops().
Get the number of ops that a hash verification operation has taken so far. If the operation has completed, then this will represent the number of ops required for the entire operation. After initialization or calling \c psa_verify_hash_interruptible_abort() on the operation, a value of 0 will be returned. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises. This is a helper provided to help you tune the value passed to \c psa_interruptible_set_max_ops().
Start signing a hash or short message with a private key, in an interruptible manner. \see \c psa_sign_hash_complete() \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Continue and eventually complete the action of signing a hash or short message with a private key, in an interruptible manner. \see \c psa_sign_hash_start() \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Abort a sign hash operation. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Start reading and verifying a hash or short message, in an interruptible manner. \see \c psa_verify_hash_complete() \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Continue and eventually complete the action of reading and verifying a hash or short message signed with a private key, in an interruptible manner. \see \c psa_verify_hash_start() \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Abort a verify hash operation. \warning This is a beta API, and thus subject to change at any point. It is not bound by the usual interface stability promises.
Remove non-essential copies of key material from memory. If the key identifier designates a volatile key, this functions does not do anything and returns successfully. If the key identifier designates a persistent key, then this function will free all resources associated with the key in volatile memory. The key data in persistent storage is not affected and the key can still be used.
Make a copy of a key. Copy key material from one location to another. This function is primarily useful to copy a key from one location to another, since it populates a key using the material from another key which may have a different lifetime. This function may be used to share a key with a different party, subject to implementation-defined restrictions on key sharing. The policy on the source key must have the usage flag #PSA_KEY_USAGE_COPY set. This flag is sufficient to permit the copy if the key has the lifetime #PSA_KEY_LIFETIME_VOLATILE or #PSA_KEY_LIFETIME_PERSISTENT. Some secure elements do not provide a way to copy a key without making it extractable from the secure element. If a key is located in such a secure element, then the key must have both usage flags #PSA_KEY_USAGE_COPY and #PSA_KEY_USAGE_EXPORT in order to make a copy of the key outside the secure element. The resulting key may only be used in a way that conforms to both the policy of the original key and the policy specified in the \p attributes parameter: - The usage flags on the resulting key are the bitwise-and of the usage flags on the source policy and the usage flags in \p attributes. - If both allow the same algorithm or wildcard-based algorithm policy, the resulting key has the same algorithm policy. - If either of the policies allows an algorithm and the other policy allows a wildcard-based algorithm policy that includes this algorithm, the resulting key allows the same algorithm. - If the policies do not allow any algorithm in common, this function fails with the status #PSA_ERROR_INVALID_ARGUMENT. The effect of this function on implementation-defined attributes is implementation-defined.
Destroy a key. This function destroys a key from both volatile memory and, if applicable, non-volatile storage. Implementations shall make a best effort to ensure that the key material cannot be recovered. This function also erases any metadata such as policies and frees resources associated with the key. If a key is currently in use in a multipart operation, then destroying the key will cause the multipart operation to fail. \warning We can only guarantee that the the key material will eventually be wiped from memory. With threading enabled and during concurrent execution, copies of the key material may still exist until all threads have finished using the key.
Calculate the hash (digest) of a message and compare it with a reference value.
Finish the calculation of the hash of a message and compare it with an expected value. The application must call psa_hash_setup() before calling this function. This function calculates the hash of the message formed by concatenating the inputs passed to preceding calls to psa_hash_update(). It then compares the calculated hash with the expected hash passed as a parameter to this function. When this function returns successfully, the operation becomes inactive. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_hash_abort().
Clone a hash operation. This function copies the state of an ongoing hash operation to a new operation object. In other words, this function is equivalent to calling psa_hash_setup() on \p target_operation with the same algorithm that \p source_operation was set up for, then psa_hash_update() on \p target_operation with the same input that that was passed to \p source_operation. After this function returns, the two objects are independent, i.e. subsequent calls involving one of the objects do not affect the other object.
This function adds additional data for AEAD ciphers. Currently supported with GCM and ChaCha20+Poly1305.
This function writes a tag for AEAD ciphers. Currently supported with GCM and ChaCha20+Poly1305. This must be called after mbedtls_cipher_finish().
This function checks the tag for AEAD ciphers. Currently supported with GCM and ChaCha20+Poly1305. This must be called after mbedtls_cipher_finish().
Read an MPI from a line in an opened file. The function returns \c 0 on an empty line. Leading whitespaces are ignored, as is a '0x' prefix for radix \c 16.
Export an MPI into an opened file.
This function imports a non-zero point from two ASCII strings.
Set the public key in a key pair object.
Calculate the public key from a private key in a key pair.
Query the group that a key pair belongs to.
This function exports generic key-pair parameters. Each of the output parameters can be a null pointer if you do not need that parameter.
This function returns the list of digests supported by the generic digest module.
This function returns the message-digest information associated with the given digest name.
This function returns the name of the message digest for the message-digest information structure given.
This function exports core parameters of an RSA key in raw big-endian binary format. If this function runs successfully, the non-NULL buffers pointed to by \p N, \p P, \p Q, \p D, and \p E are fully written, with additional unused space filled leading by zero Bytes. Possible reasons for returning #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED: An alternative RSA implementation is in use, which stores the key externally, and either cannot or should not export it into RAM. A SW or HW implementation might not support a certain deduction. For example, \p P, \p Q from \p N, \p D, and \p E if the former are not part of the implementation. If the function fails due to an unsupported operation, the RSA context stays intact and remains usable.
This function performs a PKCS#1 v2.1 PSS signature operation (RSASSA-PSS-SIGN).
This function retrieves the list of ciphers supported by the generic cipher module. For any cipher identifier in the returned list, you can obtain the corresponding generic cipher information structure via mbedtls_cipher_info_from_type(), which can then be used to prepare a cipher context via mbedtls_cipher_setup().
This function retrieves the cipher-information structure associated with the given cipher name.
Set the password for a password-authenticated key exchange from key ID. Call this function when the password, or a value derived from the password, is already present in the key store.
Set the user ID for a password-authenticated key exchange. Call this function to set the user ID. For PAKE algorithms that associate a user identifier with each side of the session you need to call psa_pake_set_peer() as well. For PAKE algorithms that associate a single user identifier with the session, call psa_pake_set_user() only. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information.
Set the peer ID for a password-authenticated key exchange. Call this function in addition to psa_pake_set_user() for PAKE algorithms that associate a user identifier with each side of the session. For PAKE algorithms that associate a single user identifier with the session, call psa_pake_set_user() only. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information.
Set the application role for a password-authenticated key exchange. Not all PAKE algorithms need to differentiate the communicating entities. It is optional to call this function for PAKEs that don't require a role to be specified. For such PAKEs the application role parameter is ignored, or #PSA_PAKE_ROLE_NONE can be passed as \c role. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information.
Get output for a step of a password-authenticated key exchange. Depending on the algorithm being executed, you might need to call this function several times or you might not need to call this at all. The exact sequence of calls to perform a password-authenticated key exchange depends on the algorithm in use. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_pake_abort().
Provide input for a step of a password-authenticated key exchange. Depending on the algorithm being executed, you might need to call this function several times or you might not need to call this at all. The exact sequence of calls to perform a password-authenticated key exchange depends on the algorithm in use. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information. If this function returns an error status, the operation enters an error state and must be aborted by calling psa_pake_abort().
Get implicitly confirmed shared secret from a PAKE. At this point there is a cryptographic guarantee that only the authenticated party who used the same password is able to compute the key. But there is no guarantee that the peer is the party it claims to be and was able to do so. That is, the authentication is only implicit. Since the peer is not authenticated yet, no action should be taken yet that assumes that the peer is who it claims to be. For example, do not access restricted files on the peer's behalf until an explicit authentication has succeeded. This function can be called after the key exchange phase of the operation has completed. It imports the shared secret output of the PAKE into the provided derivation operation. The input step #PSA_KEY_DERIVATION_INPUT_SECRET is used when placing the shared key material in the key derivation operation. The exact sequence of calls to perform a password-authenticated key exchange depends on the algorithm in use. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information. When this function returns successfully, \p operation becomes inactive. If this function returns an error status, both \p operation and \c key_derivation operations enter an error state and must be aborted by calling psa_pake_abort() and psa_key_derivation_abort() respectively.
Open a handle to an existing persistent key. Open a handle to a persistent key. A key is persistent if it was created with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key always has a nonzero key identifier, set with psa_set_key_id() when creating the key. Implementations may provide additional pre-provisioned keys that can be opened with psa_open_key(). Such keys have an application key identifier in the vendor range, as documented in the description of #psa_key_id_t. The application must eventually close the handle with psa_close_key() or psa_destroy_key() to release associated resources. If the application dies without calling one of these functions, the implementation should perform the equivalent of a call to psa_close_key(). Some implementations permit an application to open the same key multiple times. If this is successful, each call to psa_open_key() will return a different key handle.
Close a key handle. If the handle designates a volatile key, this will destroy the key material and free all associated resources, just like psa_destroy_key(). If this is the last open handle to a persistent key, then closing the handle will free all resources associated with the key in volatile memory. The key data in persistent storage is not affected and can be opened again later with a call to psa_open_key(). Closing the key handle makes the handle invalid, and the key handle must not be used again by the application.
Get statistics about resource consumption related to the PSA keystore.
Return the ID of the ciphersuite associated with the given name
Set a connection-specific verification callback (optional). If set, the provided verify callback is called for each certificate in the peer's CRT chain, including the trusted root. For more information, please see the documentation of \c mbedtls_x509_crt_verify().
Set the timeout period for mbedtls_ssl_read() (Default: no timeout.)
Check whether a buffer contains a valid and authentic record that has not been seen before. (DTLS only). This function does not change the user-visible state of the SSL context. Its sole purpose is to provide an indication of the legitimacy of an incoming record. This can be useful e.g. in distributed server environments using the DTLS Connection ID feature, in which connections might need to be passed between service instances on a change of peer address, but where such disruptive operations should only happen after the validity of incoming records has been confirmed.
Configure SSL session ticket callbacks (server only). (Default: none.)
Set a limit on the number of records with a bad MAC before terminating the connection. (DTLS only, no effect on TLS.) Default: 0 (disabled).
Set the session cache callbacks (server-side only) If not set, no session resuming is done (except if session tickets are enabled too). The session cache has the responsibility to check for stale entries based on timeout. See RFC 5246 for recommendations. Warning: session.peer_cert is cleared by the SSL/TLS layer on connection shutdown, so do not cache the pointer! Either set it to NULL or make a full copy of the certificate. The get callback is called once during the initial handshake to enable session resuming. The get function has the following parameters: (void *parameter, mbedtls_ssl_session *session) If a valid entry is found, it should fill the master of the session object with the cached values and return 0, return 1 otherwise. Optionally peer_cert can be set as well if it is properly present in cache entry. The set callback is called once during the initial handshake to enable session resuming after the entire handshake has been finished. The set function has the following parameters: (void *parameter, const mbedtls_ssl_session *session). The function should create a cache entry for future retrieval based on the data in the session structure and should keep in mind that the mbedtls_ssl_session object presented (and all its referenced data) is cleared by the SSL/TLS layer when the connection is terminated. It is recommended to add metadata to determine if an entry is still valid in the future. Return 0 if successfully cached, return 1 otherwise.
Load a session for session resumption. Sessions loaded through this call will be considered for session resumption in the next handshake. \sa mbedtls_ssl_get_session() \sa mbedtls_ssl_session_load()
Retrieve SNI extension value for the current handshake. Available in \c f_cert_cb of \c mbedtls_ssl_conf_cert_cb(), this is the same value passed to \c f_sni callback of \c mbedtls_ssl_conf_sni() and may be used instead of \c mbedtls_ssl_conf_sni().
Set own certificate and key for the current handshake
Set the data required to verify peer certificate for the current handshake
Set DN hints sent to client in CertificateRequest message
Set authmode for the current handshake.
Set server side ServerName TLS extension callback (optional, server-side only). If set, the ServerName callback is called whenever the server receives a ServerName TLS extension from the client during a handshake. The ServerName callback has the following parameters: (void *parameter, mbedtls_ssl_context *ssl, const unsigned char *hostname, size_t len). If a suitable certificate is found, the callback must set the certificate(s) and key(s) to use with \c mbedtls_ssl_set_hs_own_cert() (can be called repeatedly), and may optionally adjust the CA and associated CRL with \c mbedtls_ssl_set_hs_ca_chain() as well as the client authentication mode with \c mbedtls_ssl_set_hs_authmode(), then must return 0. If no matching name is found, the callback may return non-zero to abort the handshake.
Get the name of the negotiated Application Layer Protocol. This function should be called after the handshake is completed.
Enable or disable Encrypt-then-MAC (Default: MBEDTLS_SSL_ETM_ENABLED)
Enable or disable Extended Master Secret negotiation. (Default: MBEDTLS_SSL_EXTENDED_MS_ENABLED)
Whether to send a list of acceptable CAs in CertificateRequest messages. (Default: do send)
Set the maximum fragment length to emit and/or negotiate. (Typical: the smaller of #MBEDTLS_SSL_IN_CONTENT_LEN and #MBEDTLS_SSL_OUT_CONTENT_LEN, usually `2^14` bytes) (Server: set maximum fragment length to emit, usually negotiated by the client during handshake) (Client: set maximum fragment length to emit *and* negotiate with the server during handshake) (Default: #MBEDTLS_SSL_MAX_FRAG_LEN_NONE)
Pick the ciphersuites order according to the second parameter in the SSL Server module (MBEDTLS_SSL_SRV_C). (Default, if never called: MBEDTLS_SSL_SRV_CIPHERSUITE_ORDER_SERVER)
Prevent or allow legacy renegotiation. (Default: MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION) MBEDTLS_SSL_LEGACY_NO_RENEGOTIATION allows connections to be established even if the peer does not support secure renegotiation, but does not allow renegotiation to take place if not secure. (Interoperable and secure option) MBEDTLS_SSL_LEGACY_ALLOW_RENEGOTIATION allows renegotiations with non-upgraded peers. Allowing legacy renegotiation makes the connection vulnerable to specific man in the middle attacks. (See RFC 5746) (Most interoperable and least secure option) MBEDTLS_SSL_LEGACY_BREAK_HANDSHAKE breaks off connections if peer does not support secure renegotiation. Results in interoperability issues with non-upgraded peers that do not support renegotiation altogether. (Most secure option, interoperability issues)
Enforce renegotiation requests. (Default: enforced, max_records = 16) When we request a renegotiation, the peer can comply or ignore the request. This function allows us to decide whether to enforce our renegotiation requests by closing the connection if the peer doesn't comply. However, records could already be in transit from the peer when the request is emitted. In order to increase reliability, we can accept a number of records before the expected handshake records. The optimal value is highly dependent on the specific usage scenario. \warning On client, the grace period can only happen during mbedtls_ssl_read(), as opposed to mbedtls_ssl_write() and mbedtls_ssl_renegotiate() which always behave as if max_record was 0. The reason is, if we receive application data from the server, we need a place to write it, which only happens during mbedtls_ssl_read().
Set record counter threshold for periodic renegotiation. (Default: 2^48 - 1) Renegotiation is automatically triggered when a record counter (outgoing or incoming) crosses the defined threshold. The default value is meant to prevent the connection from being closed when the counter is about to reached its maximal value (it is not allowed to wrap). Lower values can be used to enforce policies such as "keys must be refreshed every N packets with cipher X". The renegotiation period can be disabled by setting conf->disable_renegotiation to MBEDTLS_SSL_RENEGOTIATION_DISABLED.
Check if there is data already read from the underlying transport but not yet processed.
Return the id of the current ciphersuite
Return the current maximum incoming record payload in bytes. \sa mbedtls_ssl_set_mtu() \sa mbedtls_ssl_get_max_in_record_payload() \sa mbedtls_ssl_get_record_expansion()
Return the peer certificate from the current connection. \warning You must not use the pointer returned by this function after any further call to the SSL API, including mbedtls_ssl_read() and mbedtls_ssl_write(); this is because the pointer might change during renegotiation, which happens transparently to the user. If you want to use the certificate across API calls, you must make a copy.
Export a session in order to resume it later. \sa mbedtls_ssl_set_session() \sa mbedtls_ssl_session_save()
This function dynamically sets the memory-management functions used by the library, during runtime.
This function performs any platform-specific initialization operations. Its implementation is platform-specific, and unless platform-specific code is provided, it does nothing.
This function performs any platform teardown operations. Its implementation is platform-specific, and unless platform-specific code is provided, it does nothing.
Set the session information for a password-authenticated key exchange. The sequence of operations to set up a password-authenticated key exchange is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_pake_operation_t, e.g. #PSA_PAKE_OPERATION_INIT. -# Call psa_pake_setup() to specify the cipher suite. -# Call \c psa_pake_set_xxx() functions on the operation to complete the setup. The exact sequence of \c psa_pake_set_xxx() functions that needs to be called depends on the algorithm in use. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information. A typical sequence of calls to perform a password-authenticated key exchange: -# Call psa_pake_output(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to get the key share that needs to be sent to the peer. -# Call psa_pake_input(operation, #PSA_PAKE_STEP_KEY_SHARE, ...) to provide the key share that was received from the peer. -# Depending on the algorithm additional calls to psa_pake_output() and psa_pake_input() might be necessary. -# Call psa_pake_get_implicit_key() for accessing the shared secret. Refer to the documentation of individual PAKE algorithm types (`PSA_ALG_XXX` values of type ::psa_algorithm_t such that #PSA_ALG_IS_PAKE(\c alg) is true) for more information. If an error occurs at any step after a call to psa_pake_setup(), the operation will need to be reset by a call to psa_pake_abort(). The application may call psa_pake_abort() at any time after the operation has been initialized. After a successful call to psa_pake_setup(), the application must eventually terminate the operation. The following events terminate an operation: - A call to psa_pake_abort(). - A successful call to psa_pake_get_implicit_key().
Make signature given a signature type.
Load one or more CRLs and append them to the chained list
Returns an informational string about the CRL.
Set Subject Alternative Name
Load and parse a private key
Load and parse a public key
Write a public key to a PEM string
Write a private key to a PKCS#1 or SEC1 PEM string
Retrieve an enumerated ASN.1 tag and its value. Updates the pointer to immediately behind the full tag.
Initialize an RSA-alt context
Determine valid PSA attributes that can be used to import a key into PSA. The attributes determined by this function are suitable for calling mbedtls_pk_import_into_psa() to create a PSA key with the same key material. The typical flow of operations involving this function is ``` psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; int ret = mbedtls_pk_get_psa_attributes(pk, &attributes); if (ret != 0) ...; // error handling omitted // Tweak attributes if desired psa_key_id_t key_id = 0; ret = mbedtls_pk_import_into_psa(pk, &attributes, &key_id); if (ret != 0) ...; // error handling omitted ```
Import a key into the PSA key store. This function is equivalent to calling psa_import_key() with the key material from \p pk. The typical way to use this function is: -# Call mbedtls_pk_get_psa_attributes() to obtain attributes for the given key. -# If desired, modify the attributes, for example: - To create a persistent key, call psa_set_key_identifier() and optionally psa_set_key_lifetime(). - To import only the public part of a key pair: psa_set_key_type(&attributes, PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR( psa_get_key_type(&attributes))); - Restrict the key usage if desired. -# Call mbedtls_pk_import_into_psa().
Create a PK context starting from a key stored in PSA. This key: - must be exportable and - must be an RSA or EC key pair or public key (FFDH is not supported in PK). The resulting PK object will be a transparent type: - #MBEDTLS_PK_RSA for RSA keys or - #MBEDTLS_PK_ECKEY for EC keys. Once this functions returns the PK object will be completely independent from the original PSA key that it was generated from. Calling mbedtls_pk_sign(), mbedtls_pk_verify(), mbedtls_pk_encrypt(), mbedtls_pk_decrypt() on the resulting PK context will perform the corresponding algorithm for that PK context type. * For ECDSA, the choice of deterministic vs randomized will be based on the compile-time setting #MBEDTLS_ECDSA_DETERMINISTIC. * For an RSA key, the output PK context will allow both encrypt/decrypt and sign/verify regardless of the original key's policy. The original key's policy determines the output key's padding mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS, otherwise PKCS1 v1.5 is set.
Create a PK context for the public key of a PSA key. The key must be an RSA or ECC key. It can be either a public key or a key pair, and only the public key is copied. The resulting PK object will be a transparent type: - #MBEDTLS_PK_RSA for RSA keys or - #MBEDTLS_PK_ECKEY for EC keys. Once this functions returns the PK object will be completely independent from the original PSA key that it was generated from. Calling mbedtls_pk_verify() or mbedtls_pk_encrypt() on the resulting PK context will perform the corresponding algorithm for that PK context type. For an RSA key, the output PK context will allow both encrypt and verify regardless of the original key's policy. The original key's policy determines the output key's padding mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS, otherwise PKCS1 v1.5 is set.
Parse a single DER formatted certificate and add it to the end of the provided chained list.
Parse a single DER formatted certificate and add it to the end of the provided chained list. This is a variant of mbedtls_x509_crt_parse_der() which takes temporary ownership of the CRT buffer until the CRT is destroyed.
Load one or more certificate files from a path and add them to the chained list. Parses permissively. If some certificates can be parsed, the result is the number of failed certificates it encountered. If none complete correctly, the first error is returned.
Returns an informational string about the certificate.
Verify a chain of certificates with respect to a configurable security profile.
Access the ca_istrue field
Initialize a CRT writing context
Set the version for a Certificate Default: MBEDTLS_X509_CRT_VERSION_3
Set the serial number for a Certificate.
Set the validity period for a Certificate Timestamps should be in string format for UTC timezone i.e. "YYYYMMDDhhmmss" e.g. "20131231235959" for December 31st 2013 at 23:59:59
Set the issuer name for a Certificate Issuer names should contain a comma-separated list of OID types and values: e.g. "C=UK,O=ARM,CN=Mbed TLS CA"
Set the subject name for a Certificate Subject names should contain a comma-separated list of OID types and values: e.g. "C=UK,O=ARM,CN=Mbed TLS Server 1"
Set the subject public key for the certificate
Set the issuer key used for signing the certificate
Set the MD algorithm to use for the signature (e.g. MBEDTLS_MD_SHA1)
Set the basicConstraints extension for a CRT
Set the subjectKeyIdentifier extension for a CRT Requires that mbedtls_x509write_crt_set_subject_key() has been called before
Set the authorityKeyIdentifier extension for a CRT Requires that mbedtls_x509write_crt_set_issuer_key() has been called before
Set the Key Usage Extension flags (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
Set the Extended Key Usage Extension (e.g. MBEDTLS_OID_SERVER_AUTH)
Set the Netscape Cert Type flags (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
Free the contents of a CRT write context
Write a built up certificate to a X509 PEM string
Return the ECP group for provided context.
Check whether a given group can be used for ECDH.
Create a receiving socket on bind_ip:port in the chosen protocol. If bind_ip == NULL, all interfaces are bound.
Accept a connection from a remote client
Set the socket non-blocking
Read at most 'len' characters, blocking for at most 'timeout' seconds. If no error occurs, the actual amount read is returned.
Read and update a seed file. Seed is added to this instance. No more than MBEDTLS_ENTROPY_MAX_SEED_SIZE bytes are read from the seed file. The rest is ignored.
Checkup routine This module self-test also calls the entropy self-test, mbedtls_entropy_source_self_test();
This function sets the reseed interval. The reseed interval is the number of calls to mbedtls_ctr_drbg_random() or mbedtls_ctr_drbg_random_with_add() after which the entropy function is called again. The default value is #MBEDTLS_CTR_DRBG_RESEED_INTERVAL.
This function reads and updates a seed file. The seed is added to this instance.
The CTR_DRBG checkup routine.
The SHA-1 checkup routine. \warning SHA-1 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Checkup routine \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Disable and dealloc the certification bundle Removes the certificate verification callback and deallocates used resources
Set the default certificate bundle used for verification Overrides the default certificate bundle only in case of successful initialization. In most use cases the bundle should be set through menuconfig. The bundle needs to be sorted by subject name since binary search is used to find certificates.
Check if the given CA certificate chain is the default "dummy" certificate chain attached by the esp_crt_bundle
Perform some consistency checks on the user-provided bundle data to try and make sure it actually is a certificate bundle.
Get the certificate at the given index within a bundle.
Return an offset into a read-only buffer. Similar to mbedtls_buffer_offset(), but for const pointers.
This function returns the PSA algorithm identifier associated with the given digest type. \warning If \p md_type is \c MBEDTLS_MD_NONE, this function will not return \c PSA_ALG_NONE, but an invalid algorithm. \warning This function does not check if the algorithm is supported, it always returns the corresponding identifier.
Write an enum tag (#MBEDTLS_ASN1_ENUMERATED) and value in ASN.1 format.
Write a string in ASN.1 format using the PrintableString string encoding tag (#MBEDTLS_ASN1_PRINTABLE_STRING).
Write a UTF8 string in ASN.1 format using the UTF8String string encoding tag (#MBEDTLS_ASN1_UTF8_STRING).
Write a string in ASN.1 format using the IA5String string encoding tag (#MBEDTLS_ASN1_IA5_STRING).
Convert an ECDSA signature from raw format to DER ASN.1 format.
Convert an ECDSA signature from DER ASN.1 format to raw format.
Return PSA EC info for the specified TLS ID.
This function parses and processes a TLS ServerKeyExchange payload. This is the first function used by a TLS client for ECDHE ciphersuites. \see ecp.h
Boolean "less than or equal" operation. Functionally equivalent to: \p x <= \p y
Returns the number of limbs of working memory required for a call to `mbedtls_mpi_core_montmul()`.
Conditional addition of two fixed-size large unsigned integers, returning the carry. Functionally equivalent to ``` if( cond ) X += A; return carry; ``` This function operates modulo `2^(biL*limbs)`. \warning If \p cond is neither 0 nor 1, the result of this function is unspecified, and the resulting value in \p X might be neither its original value nor \p X + \p A.
This function sets the amount of entropy grabbed on each seed or reseed. See the documentation of mbedtls_hmac_drbg_seed() for the default value.
Set the reseed interval. The reseed interval is the number of calls to mbedtls_hmac_drbg_random() or mbedtls_hmac_drbg_random_with_add() after which the entropy function is called again. The default value is #MBEDTLS_HMAC_DRBG_RESEED_INTERVAL.
This function reads and updates a seed file. The seed is added to this instance.
The HMAC_DRBG Checkup routine.
Initialize mbedtls_pkcs7 structure.
Parse a single DER formatted PKCS #7 detached signature.
Verification of PKCS #7 signature against a caller-supplied certificate. For each signer in the PKCS structure, this function computes a signature over the supplied data, using the supplied certificate and the same digest algorithm as specified by the signer. It then compares this signature against the signer's signature; verification succeeds if any comparison matches. This function does not use the certificates held within the PKCS #7 structure itself, and does not check that the certificate is signed by a trusted certification authority.
Verification of PKCS #7 signature against a caller-supplied certificate. For each signer in the PKCS structure, this function validates a signature over the supplied hash, using the supplied certificate and the same digest algorithm as specified by the signer. Verification succeeds if any signature is good. This function does not use the certificates held within the PKCS #7 structure itself, and does not check that the certificate is signed by a trusted certification authority.
This function initializes an LMS public context
This function uninitializes an LMS public context
This function imports an LMS public key into a public LMS context.
This function exports an LMS public key from a LMS public context that already contains a public key.
This function verifies a LMS signature, using a LMS context that contains a public key.
This function initializes a public LMOTS context
This function uninitializes a public LMOTS context
This function imports an LMOTS public key into a LMOTS context.
This function exports an LMOTS public key from a LMOTS context that already contains a public key.
This function verifies a LMOTS signature, using a LMOTS context that contains a public key. \warning This function is **not intended for use in production**, due to as-yet unsolved problems with handling stateful keys. The API for this function may change considerably in future versions.
Convert PSA status to MD error code.
Unsorted (yet!) from this point on until the next section header
Internal functions for RSA keys.
Calculate the key buffer size required to store the key material of a key associated with an opaque driver from input key data.
Return an offset into a buffer. This is just the addition of an offset to a pointer, except that this function also accepts an offset of 0 into a buffer whose pointer is null. (`p + n` has undefined behavior when `p` is null, even when `n == 0`. A null pointer is a valid buffer pointer when the size is 0, for example as the result of `malloc(0)` on some platforms.)
Test whether a key identifier is a volatile key identifier.
Deinitialize the PSA DRBG.
Configure entropy sources. This function may only be called before a call to psa_crypto_init(), or after a call to mbedtls_psa_crypto_free() and before any subsequent call to psa_crypto_init(). This function is only intended for test purposes. The functionality it provides is also useful for system integrators, but system integrators should configure entropy drivers instead of breaking through to the Mbed TLS API.
Copy from an input buffer to a local copy.
Copy from a local output buffer into a user-supplied one.
Test whether a policy permits an algorithm. The caller must test usage flags separately.
Restrict a key policy based on a constraint.
Tell if PSA is ready for this hash.
Tell if PSA is ready for this cipher.
Validate that a key policy is internally well-formed. This function only rejects invalid policies. It does not validate the consistency of the policy with respect to other attributes of the key such as the key type.
Validate the internal consistency of key attributes. This function only rejects invalid attribute values. If does not validate the consistency of the attributes with any key data that may be involved in the creation of the key. Call this function early in the key creation process.
Set the maximum number of ops allowed to be executed by an interruptible function in a single call.
Check whether the given key type is acceptable for the given input step of a key derivation. Secret inputs must have the type #PSA_KEY_TYPE_DERIVE. Non-secret inputs must have the type #PSA_KEY_TYPE_RAW_DATA. Both secret and non-secret inputs can alternatively have the type #PSA_KEY_TYPE_NONE, which is never the type of a key object, meaning that the input was passed as a buffer rather than via a key object.
Initialize the PSA random generator. Note: the mbedtls_threading_psa_rngdata_mutex should be held when calling this function if mutexes are enabled.
Deinitialize the PSA random generator. Note: the mbedtls_threading_psa_rngdata_mutex should be held when calling this function if mutexes are enabled.
Seed the PSA random generator.
Validate the key type and size for key generation
Process input for which the algorithm is set to ECB mode. This requires manual processing, since the PSA API is defined as being able to process arbitrary-length calls to psa_cipher_update() with ECB mode, but the underlying mbedtls_cipher_update only takes full blocks.
This function loads and parses DHM parameters from a file.
Store persistent data for the given key slot number. This function stores the given data buffer to a persistent storage.
Get data length for given key slot number.
Load persistent data for the given key slot number. This function reads data from a storage backend and returns the data in a buffer.
This function performs the unpadding part of a PKCS#1 v1.5 decryption operation (EME-PKCS1-v1_5 decoding).
Get the version string ("x.y.z").
Get the full version string ("Mbed TLS x.y.z").
Check if support for a feature was compiled into this Mbed TLS binary. This allows you to see at runtime if the library was for instance compiled with or without Multi-threading support.
Get the final timing delay
Set a pair of delays to watch (See \c mbedtls_timing_get_delay().)
Get the status of delays (Memory helper: number of delays passed.)
Calculate SHA1 or SHA2 sum of some data, using hardware SHA engine
Obtain exclusive access to a particular SHA engine Blocks until engine is available. Note: Can block indefinitely while a TLS connection is open, suggest using esp_sha_try_lock_engine() and failing over to software SHA.
Calculate the number of words needed to represent the input word in hardware
Enable/disables MPI operation complete interrupt
Clears the MPI operation complete interrupt status
Initialize an SSL cache context
Cache get callback implementation (Thread-safe if MBEDTLS_THREADING_C is enabled)
Cache set callback implementation (Thread-safe if MBEDTLS_THREADING_C is enabled)
Remove the cache entry by the session ID (Thread-safe if MBEDTLS_THREADING_C is enabled)
Set the cache timeout (Default: MBEDTLS_SSL_CACHE_DEFAULT_TIMEOUT (1 day)) A timeout of 0 indicates no timeout.
Set the maximum number of cache entries (Default: MBEDTLS_SSL_CACHE_DEFAULT_MAX_ENTRIES (50))
Free referenced items in a cache context and clear memory
Set expiration delay for cookies (Default MBEDTLS_SSL_COOKIE_TIMEOUT)
Initialize a ticket context. (Just make it ready for mbedtls_ssl_ticket_setup() or mbedtls_ssl_ticket_free().)
Rotate session ticket encryption key to new specified key. Provides for external control of session ticket encryption key rotation, e.g. for synchronization between different machines. If this function is not used, or if not called before ticket lifetime expires, then a new session ticket encryption key is generated internally in order to avoid unbounded session ticket encryption key lifetimes.
Prepare context to be actually used
Implementation of the ticket write callback
Implementation of the ticket parse callback
Free a context's content and zeroize it.
SignedData ::= SEQUENCE { version Version, digestAlgorithms DigestAlgorithmIdentifiers, contentInfo ContentInfo, certificates [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL, crls [0] IMPLICIT CertificateRevocationLists OPTIONAL, signerInfos SignerInfos }
DigestAlgorithmIdentifiers :: SET of DigestAlgorithmIdentifier
ContentInfo ::= SEQUENCE { contentType ContentType, content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
SignerInfos ::= SET of SignerInfo Return number of signers added to the signed data, 0 or higher is valid. Return negative error code for failure.
certificates :: SET OF ExtendedCertificateOrCertificate, ExtendedCertificateOrCertificate ::= CHOICE { certificate Certificate -- x509, extendedCertificate[0] IMPLICIT ExtendedCertificate } Return number of certificates added to the signed data, 0 or higher is valid. Return negative error code for failure.
EncryptedDigest ::= OCTET STRING
Parse a hexstring containing a DER-encoded string.
Load a Certificate Signing Request (CSR) in DER format
Load a Certificate Signing Request (CSR)
Returns an informational string about the CSR.
Set the subject name for a CSR Subject names should contain a comma-separated list of OID types and values: e.g. "C=UK,O=ARM,CN=Mbed TLS Server 1"
Set the key for a CSR (public key will be included, private key used to sign the CSR when writing it)
Set the MD algorithm to use for the signature (e.g. MBEDTLS_MD_SHA1)
Set the Key Usage Extension flags (e.g. MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_CERT_SIGN)
Set Subject Alternative Name
Set the Netscape Cert Type flags (e.g. MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT | MBEDTLS_X509_NS_CERT_TYPE_EMAIL)
Free the contents of a CSR context
Write a CSR (Certificate Signing Request) to a PEM string
Set the Diffie-Hellman public P and G values, read from existing context (server-side only)
Set the minimum length for Diffie-Hellman parameters. (Client-side only.) (Default: 1024 bits.)
Set the Maximum Transport Unit (MTU). Special value: 0 means unset (no limit). This represents the maximum size of a datagram payload handled by the transport layer (usually UDP) as determined by the network link and stack. In practice, this controls the maximum size datagram the DTLS layer will pass to the \c f_send() callback set using \c mbedtls_ssl_set_bio().
Manage support for mki(master key id) value in use_srtp extension. MKI is an optional part of SRTP used for key management and re-keying. See RFC3711 section 3.1 for details. The default value is #MBEDTLS_SSL_DTLS_SRTP_MKI_UNSUPPORTED.
Set the supported DTLS-SRTP protection profiles.
Set the mki_value for the current DTLS-SRTP session.
Get the negotiated DTLS-SRTP information: Protection profile and MKI value. \warning This function must be called after the handshake is completed. The value returned by this function must not be trusted or acted upon before the handshake completes.
Enable or disable anti-replay protection for DTLS. (DTLS only, no effect on TLS.) Default: enabled. \warning Disabling this is a security risk unless the application protocol handles duplicated packets in a safe way. You should not disable this without careful consideration. However, if your application already detects duplicated packets and needs information about them to adjust its transmission strategy, then you'll want to disable this.
Allow or disallow packing of multiple handshake records within a single datagram.
Set the pre-shared Key (PSK) for the current handshake.
Set the PSK callback (server-side only). If set, the PSK callback is called for each handshake where a PSK-based ciphersuite was negotiated. The caller provides the identity received and wants to receive the actual PSK data and length. The callback has the following parameters: - \c void*: The opaque pointer \p p_psk. - \c mbedtls_ssl_context*: The SSL context to which the operation applies. - \c const unsigned char*: The PSK identity selected by the client. - \c size_t: The length of the PSK identity selected by the client. If a valid PSK identity is found, the callback should use \c mbedtls_ssl_set_hs_psk() or \c mbedtls_ssl_set_hs_psk_opaque() on the SSL context to set the correct PSK and return \c 0. Any other return value will result in a denied PSK identity.
Get the first defined PSK by order of precedence: 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback 2. static PSK configured by \c mbedtls_ssl_conf_psk() Return a code and update the pair (PSK, PSK length) passed to this function
Set the SHA-1 mode for a mbedtls_sha1_context.
Set the user data in an SSL configuration to a pointer. You can retrieve this value later with mbedtls_ssl_conf_get_user_data_p().
Return the (D)TLS protocol version negotiated in the given connection.
Utility to initialize a key identifier at runtime.
This function returns a non-zero value if the key length for the given cipher is variable.
This function returns a non-zero value if the IV size for the given cipher is variable.
This function returns the type of the given cipher.
This function returns the name of the given cipher as a string.
This function returns the operation of the given cipher.
Retrieve the human-readable name for a cipher info structure.
Retrieve the enrollment algorithm policy from key attributes.
Get the current endpoint type
Return the SSL configuration structure associated with the given SSL context.
Set the certificate selection callback (server-side only). If set, the callback is always called for each handshake, after `ClientHello` processing has finished.
Get the session-id buffer.
Get the size of the session-id.
Set the user data in an SSL configuration to an integer. You can retrieve this value later with mbedtls_ssl_conf_get_user_data_n().
Retrieve the user data in an SSL configuration as a pointer. This is the value last set with mbedtls_ssl_conf_set_user_data_p(), or \c NULL if mbedtls_ssl_conf_set_user_data_p() has not previously been called. The value is undefined if mbedtls_ssl_conf_set_user_data_n() has been called without a subsequent call to mbedtls_ssl_conf_set_user_data_p().
Retrieve the user data in an SSL configuration as an integer. This is the value last set with mbedtls_ssl_conf_set_user_data_n(), or \c 0 if mbedtls_ssl_conf_set_user_data_n() has not previously been called. The value is undefined if mbedtls_ssl_conf_set_user_data_p() has been called without a subsequent call to mbedtls_ssl_conf_set_user_data_n().
Set the user data in an SSL context to a pointer. You can retrieve this value later with mbedtls_ssl_get_user_data_p().
Set the user data in an SSL context to an integer. You can retrieve this value later with mbedtls_ssl_get_user_data_n().
Retrieve the user data in an SSL context as a pointer. This is the value last set with mbedtls_ssl_set_user_data_p(), or \c NULL if mbedtls_ssl_set_user_data_p() has not previously been called. The value is undefined if mbedtls_ssl_set_user_data_n() has been called without a subsequent call to mbedtls_ssl_set_user_data_p().
Retrieve the user data in an SSL context as an integer. This is the value last set with mbedtls_ssl_set_user_data_n(), or \c 0 if mbedtls_ssl_set_user_data_n() has not previously been called. The value is undefined if mbedtls_ssl_set_user_data_p() has been called without a subsequent call to mbedtls_ssl_set_user_data_n().
Set DN hints sent to client in CertificateRequest message
Get the hostname that checked against the received server certificate. It is used to set the ServerName TLS extension, too, if that extension is enabled. (client-side only)
Query certificate for given extension type
Return the next relative DN in an X509 name.
This function initializes a SHA-3 context.
This function clears a SHA-3 context.
This function clones the state of a SHA-3 context.
This function starts a SHA-3 checksum calculation.
This function feeds an input buffer into an ongoing SHA-3 checksum calculation.
This function finishes the SHA-3 operation, and writes the result to the output buffer.
This function calculates the SHA-3 checksum of a buffer. The function allocates the context, performs the calculation, and frees the context. The SHA-3 result is calculated as output = SHA-3(id, input buffer, d).
Checkup routine for the algorithms implemented by this module: SHA3-224, SHA3-256, SHA3-384, SHA3-512.
Compare output data from a key derivation operation to an expected value. This function calculates output bytes from a key derivation algorithm and compares those bytes to an expected value in constant time. If you view the key derivation's output as a stream of bytes, this function destructively reads the expected number of bytes from the stream before comparing them. The operation's capacity decreases by the number of bytes read. This is functionally equivalent to the following code:
psa_key_derivation_output_bytes(operation, tmp, output_length);
if (memcmp(output, tmp, output_length) != 0)
return PSA_ERROR_INVALID_SIGNATURE;
except (1) it works even if the key's policy does not allow outputting the bytes, and (2) the comparison will be done in constant time. If this function returns an error status other than #PSA_ERROR_INSUFFICIENT_DATA or #PSA_ERROR_INVALID_SIGNATURE, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
Compare output data from a key derivation operation to an expected value stored in a key object. This function calculates output bytes from a key derivation algorithm and compares those bytes to an expected value, provided as key of type #PSA_KEY_TYPE_PASSWORD_HASH. If you view the key derivation's output as a stream of bytes, this function destructively reads the number of bytes corresponding to the length of the expected value from the stream before comparing them. The operation's capacity decreases by the number of bytes read. This is functionally equivalent to exporting the key and calling psa_key_derivation_verify_bytes() on the result, except that it works even if the key cannot be exported. If this function returns an error status other than #PSA_ERROR_INSUFFICIENT_DATA or #PSA_ERROR_INVALID_SIGNATURE, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().
This function encrypts or decrypts data. Since ChaCha20 is a stream cipher, the same operation is used for encrypting and decrypting data.
This function encrypts or decrypts data with ChaCha20 and the given key and nonce. Since ChaCha20 is a stream cipher, the same operation is used for encrypting and decrypting data. \warning You must never use the same (key, nonce) pair more than once. This would void any confidentiality guarantees for the messages encrypted with the same nonce and key.
The ChaCha20 checkup routine.
This function initializes the specified ChaCha20-Poly1305 context. It must be the first API called before using the context. It must be followed by a call to \c mbedtls_chachapoly_setkey() before any operation can be done, and to \c mbedtls_chachapoly_free() once all operations with that context have been finished. In order to encrypt or decrypt full messages at once, for each message you should make a single call to \c mbedtls_chachapoly_crypt_and_tag() or \c mbedtls_chachapoly_auth_decrypt(). In order to encrypt messages piecewise, for each message you should make a call to \c mbedtls_chachapoly_starts(), then 0 or more calls to \c mbedtls_chachapoly_update_aad(), then 0 or more calls to \c mbedtls_chachapoly_update(), then one call to \c mbedtls_chachapoly_finish(). \warning Decryption with the piecewise API is discouraged! Always use \c mbedtls_chachapoly_auth_decrypt() when possible! If however this is not possible because the data is too large to fit in memory, you need to: - call \c mbedtls_chachapoly_starts() and (if needed) \c mbedtls_chachapoly_update_aad() as above, - call \c mbedtls_chachapoly_update() multiple times and ensure its output (the plaintext) is NOT used in any other way than placing it in temporary storage at this point, - call \c mbedtls_chachapoly_finish() to compute the authentication tag and compared it in constant time to the tag received with the ciphertext. If the tags are not equal, you must immediately discard all previous outputs of \c mbedtls_chachapoly_update(), otherwise you can now safely use the plaintext.
This function releases and clears the specified ChaCha20-Poly1305 context.
This function sets the ChaCha20-Poly1305 symmetric encryption key.
This function starts a ChaCha20-Poly1305 encryption or decryption operation. \warning You must never use the same nonce twice with the same key. This would void any confidentiality and authenticity guarantees for the messages encrypted with the same nonce and key. \warning Decryption with the piecewise API is discouraged, see the warning on \c mbedtls_chachapoly_init().
This function feeds additional data to be authenticated into an ongoing ChaCha20-Poly1305 operation. The Additional Authenticated Data (AAD), also called Associated Data (AD) is only authenticated but not encrypted nor included in the encrypted output. It is usually transmitted separately from the ciphertext or computed locally by each party. You may call this function multiple times to process an arbitrary amount of AAD. It is permitted to call this function 0 times, if no AAD is used. This function cannot be called any more if data has been processed by \c mbedtls_chachapoly_update(), or if the context has been finished. \warning Decryption with the piecewise API is discouraged, see the warning on \c mbedtls_chachapoly_init().
Thus function feeds data to be encrypted or decrypted into an on-going ChaCha20-Poly1305 operation. The direction (encryption or decryption) depends on the mode that was given when calling \c mbedtls_chachapoly_starts(). You may call this function multiple times to process an arbitrary amount of data. It is permitted to call this function 0 times, if no data is to be encrypted or decrypted. \warning Decryption with the piecewise API is discouraged, see the warning on \c mbedtls_chachapoly_init().
This function finished the ChaCha20-Poly1305 operation and generates the MAC (authentication tag). \warning Decryption with the piecewise API is discouraged, see the warning on \c mbedtls_chachapoly_init().
This function performs a complete ChaCha20-Poly1305 authenticated encryption with the previously-set key. \warning You must never use the same nonce twice with the same key. This would void any confidentiality and authenticity guarantees for the messages encrypted with the same nonce and key.
This function performs a complete ChaCha20-Poly1305 authenticated decryption with the previously-set key.
The ChaCha20-Poly1305 checkup routine.
Initialize RIPEMD-160 context
Clone (the state of) a RIPEMD-160 context
RIPEMD-160 process buffer
RIPEMD-160 process data block (internal use only)
Output = RIPEMD-160( input buffer )
This is a wrapper for the main mbedtls/bignum.h. This wrapper provides a few additional ESP32-only functions. This is because we don't set MBEDTLS_BIGNUM_ALT in the same way we do for AES, SHA, etc. Because we still use most of the bignum.h implementation and just replace a few hardware accelerated functions (see MBEDTLS_MPI_EXP_MOD_ALT & MBEDTLS_MPI_MUL_MPI_ALT in esp_config.h). Lock access to RSA Accelerator (MPI/bignum operations) RSA Accelerator hardware unit can only be used by one consumer at a time.
Unlock access to RSA Accelerator (MPI/bignum operations) Has to be called once for each call to esp_mpi_acquire_hardware().
This function initializes the specified Poly1305 context. It must be the first API called before using the context. It is usually followed by a call to \c mbedtls_poly1305_starts(), then one or more calls to \c mbedtls_poly1305_update(), then one call to \c mbedtls_poly1305_finish(), then finally \c mbedtls_poly1305_free().
This function releases and clears the specified Poly1305 context.
This function sets the one-time authentication key. \warning The key must be unique and unpredictable for each invocation of Poly1305.
This functions feeds an input buffer into an ongoing Poly1305 computation. It is called between \c mbedtls_cipher_poly1305_starts() and \c mbedtls_cipher_poly1305_finish(). It can be called repeatedly to process a stream of data.
This function generates the Poly1305 Message Authentication Code (MAC).
This function calculates the Poly1305 MAC of the input buffer with the provided key. \warning The key must be unique and unpredictable for each invocation of Poly1305.
The Poly1305 checkup routine.
This function initializes the specified ChaCha20 context. It must be the first API called before using the context. It is usually followed by calls to \c mbedtls_chacha20_setkey() and \c mbedtls_chacha20_starts(), then one or more calls to to \c mbedtls_chacha20_update(), and finally to \c mbedtls_chacha20_free().
This function releases and clears the specified ChaCha20 context.
This function sets the encryption/decryption key.
This function sets the nonce and initial counter value. \warning You must never use the same nonce twice with the same key. This would void any confidentiality guarantees for the messages encrypted with the same nonce and key.
Inject an initial entropy seed for the random generator into secure storage. This function injects data to be used as a seed for the random generator used by the PSA Crypto implementation. On devices that lack a trusted entropy source (preferably a hardware random number generator), the Mbed PSA Crypto implementation uses this value to seed its random generator. On devices without a trusted entropy source, this function must be called exactly once in the lifetime of the device. On devices with a trusted entropy source, calling this function is optional. In all cases, this function may only be called before calling any other function in the PSA Crypto API, including psa_crypto_init(). When this function returns successfully, it populates a file in persistent storage. Once the file has been created, this function can no longer succeed. If any error occurs, this function does not change the system state. You can call this function again after correcting the reason for the error if possible. \warning This function **can** fail! Callers MUST check the return status. \warning If you use this function, you should use it as part of a factory provisioning process. The value of the injected seed is critical to the security of the device. It must be *secret*, *unpredictable* and (statistically) *unique per device*. You should be generate it randomly using a cryptographically secure random generator seeded from trusted entropy sources. You should transmit it securely to the device and ensure that its value is not leaked or stored anywhere beyond the needs of transmitting it from the point of generation to the call of this function, and erase all copies of the value once this function returns. This is an Mbed TLS extension.
Check and wait for the context to be ready for read/write
Closes down the connection and free associated data
MD5 context setup \warning MD5 is considered a weak message digest and its use constitutes a security risk. We recommend considering stronger message digests instead.
Set the threshold error level to handle globally all debug output. Debug messages that have a level over the threshold value are discarded. (Default value: 0 = No debug )
This function releases and clears the specified key wrapping context and underlying cipher sub-context.
This function encrypts a buffer using key wrapping.
This function decrypts a buffer using key wrapping.
The key wrapping checkup routine.
Initialize DES context \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
Clear DES context \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
Initialize Triple-DES context \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
Clear Triple-DES context \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
Set key parity on the given key to odd. DES keys are 56 bits long, but each byte is padded with a parity bit to allow verification. \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
This function initializes the specified key wrapping context to make references valid and prepare the context for mbedtls_nist_kw_setkey() or mbedtls_nist_kw_free().
This function initializes the key wrapping context set in the \p ctx parameter and sets the encryption key.
Internal function for key expansion. (Only exposed to allow overriding it, see MBEDTLS_DES_SETKEY_ALT) \warning DES/3DES are considered weak ciphers and their use constitutes a security risk. We recommend considering stronger ciphers instead.
This function initializes an x25519 context.
This function frees a context.
This function generates a public key and a TLS ServerKeyExchange payload. This is the first function used by a TLS server for x25519.
This function parses and processes a TLS ServerKeyExchange payload.
This function sets up an x25519 context from an EC key. It is used by clients and servers in place of the ServerKeyEchange for static ECDH, and imports ECDH parameters from the EC key information of a certificate. \see ecp.h
This function derives and exports the shared secret. This is the last function used by both TLS client and servers.
This function generates a public key and a TLS ClientKeyExchange payload. This is the second function used by a TLS client for x25519. \see ecp.h
This function generates a public key and a TLS ClientKeyExchange payload. This is the second function used by a TLS client for ECDH(E) ciphersuites. \see ecp.h
This function parses and processes a TLS ClientKeyExchange payload. This is the third function used by a TLS server for ECDH(E) ciphersuites. (It is called after mbedtls_ecdh_setup() and mbedtls_ecdh_make_params().) \see ecp.h
This function derives and exports the shared secret. This is the last function used by both TLS client and servers. \see ecp.h
This function parses and processes a TLS ClientKeyExchange payload. This is the second function used by a TLS server for x25519. \see ecp.h
This function sets up the ECDH context with the information given. This function should be called after mbedtls_ecdh_init() but before mbedtls_ecdh_make_params(). There is no need to call this function before mbedtls_ecdh_read_params(). This is the first function used by a TLS server for ECDHE ciphersuites.
This function frees a context.
This function generates a public key and a TLS ServerKeyExchange payload. This is the second function used by a TLS server for ECDHE ciphersuites. (It is called after mbedtls_ecdh_setup().) \see ecp.h
This function sets up an ECDH context from an EC key. It is used by clients and servers in place of the ServerKeyEchange for static ECDH, and imports ECDH parameters from the EC key information of a certificate. \see ecp.h
Initialize the context. This must be the first API call before using the context.
Set the key into the context.
Encrypt one block (16 bytes) with the configured key.
Set the block cipher to use with this context. This must be called after mbedtls_block_cipher_init().
Setup a residue structure. The residue will be set up with the buffer \p p and modulus \p N. The memory pointed to by \p p will be used by the resulting residue structure. The value at the pointed-to memory will be the initial value of \p r and must hold a value that is less than the modulus. This value will be used as-is and interpreted according to the value of the `N->int_rep` field. The modulus \p N will be the modulus associated with \p r. The residue \p r should only be used in operations where the modulus is \p N.
Unbind elements of a residue structure. This function removes the reference to the limb array that was passed to mbedtls_mpi_mod_residue_setup() to make it safe to free or use again. This function invalidates \p r and it must not be used until after mbedtls_mpi_mod_residue_setup() is called on it again.
Initialize a modulus structure.
Setup a modulus structure.
Setup an optimised-reduction compatible modulus structure.
Free elements of a modulus structure. This function frees any memory allocated by mbedtls_mpi_mod_modulus_setup(). \warning This function does not free the limb array passed to mbedtls_mpi_mod_modulus_setup() only removes the reference to it, making it safe to free or to use it again.
Multiply two residues, returning the residue modulo the specified modulus. The size of the operation is determined by \p N. \p A, \p B and \p X must all be associated with the modulus \p N and must all have the same number of limbs as \p N. \p X may be aliased to \p A or \p B, or even both, but may not overlap either otherwise. They may not alias \p N (since they must be in canonical form, they cannot == \p N).
Perform a fixed-size modular subtraction. Calculate `A - B modulo N`. \p A, \p B and \p X must all have the same number of limbs as \p N. \p X may be aliased to \p A or \p B, or even both, but may not overlap either otherwise.
Perform modular inversion of an MPI with respect to a modulus \p N. \p A and \p X must be associated with the modulus \p N and will therefore have the same number of limbs as \p N. \p X may be aliased to \p A. \warning Currently only supports prime moduli, but does not check for them.
Perform a fixed-size modular addition. Calculate `A + B modulo N`. \p A, \p B and \p X must all be associated with the modulus \p N and must all have the same number of limbs as \p N. \p X may be aliased to \p A or \p B, or even both, but may not overlap either otherwise.
Generate a random number uniformly in a range. This function generates a random number between \p min inclusive and \p N exclusive. The procedure complies with RFC 6979 §3.3 (deterministic ECDSA) when the RNG is a suitably parametrized instance of HMAC_DRBG and \p min is \c 1.
Read a residue from a byte buffer. The residue will be automatically converted to the internal representation based on the value of the `N->int_rep` field. The modulus \p N will be the modulus associated with \p r. The residue \p r should only be used in operations where the modulus is \p N or a modulus equivalent to \p N (in the sense that all their fields or memory pointed by their fields hold the same value).
Write a residue into a byte buffer. The modulus \p N must be the modulus associated with \p r (see mbedtls_mpi_mod_residue_setup() and mbedtls_mpi_mod_read()). The residue will be automatically converted from the internal representation based on the value of `N->int_rep` field. \warning If the buffer is smaller than `N->bits`, the number of leading zeroes is leaked through timing. If \p r is secret, the caller must ensure that \p buflen is at least (`N->bits`+7)/8.
Get the pointer to the decoded binary data in a PEM context.
Return an offset into a read-only buffer. Similar to mbedtls_buffer_offset(), but for const pointers.
Unregister all secure element drivers. \warning Do not call this function while the library is in the initialized state. This function is only intended to be called at the end of mbedtls_psa_crypto_free().
Initialize all secure element drivers. Called from psa_crypto_init().
Return the secure element driver information for a lifetime value.
Return the secure element driver table entry for a lifetime value.
Return the method table for a secure element driver.
Return the context of a secure element driver.
Find a free slot for a key that is to be created. This function calls the relevant method in the driver to find a suitable slot for a key with the given attributes.
Destroy a key in a secure element. This function calls the relevant driver method to destroy a key and updates the driver's persistent data.
Load the persistent data of a secure element driver.
Save the persistent data of a secure element driver.
Destroy the persistent data of a secure element driver. This is currently only used for testing.
Register an external cryptoprocessor (secure element) driver. This function is only intended to be used by driver code, not by application code. In implementations with separation between the PSA cryptography module and applications, this function should only be available to callers that run in the same memory space as the cryptography module, and should not be exposed to applications running in a different memory space. This function may be called before psa_crypto_init(). It is implementation-defined whether this function may be called after psa_crypto_init().
Get the maximum number of ops allowed to be executed by an interruptible function in a single call.
Initialize a CAMELLIA context.
Clear a CAMELLIA context.
Perform a CAMELLIA key schedule operation for encryption.
Perform a CAMELLIA key schedule operation for decryption.
Perform a CAMELLIA-ECB block encryption/decryption operation.
Perform a CAMELLIA-CBC buffer encryption/decryption operation.
Perform a CAMELLIA-CFB128 buffer encryption/decryption operation.
Perform a CAMELLIA-CTR buffer encryption/decryption operation. *note Due to the nature of CTR mode, you should use the same key for both encryption and decryption. In particular, calls to this function should be preceded by a key-schedule via mbedtls_camellia_setkey_enc() regardless of whether the mode is #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT. \warning You must never reuse a nonce value with the same key. Doing so would void the encryption for the two messages encrypted with the same nonce and key. There are two common strategies for managing nonces with CTR: 1. You can handle everything as a single message processed over successive calls to this function. In that case, you want to set \p nonce_counter and \p nc_off to 0 for the first call, and then preserve the values of \p nonce_counter, \p nc_off and \p stream_block across calls to this function as they will be updated by this function. With this strategy, you must not encrypt more than 2**128 blocks of data with the same key. 2. You can encrypt separate messages by dividing the \p nonce_counter buffer in two areas: the first one used for a per-message nonce, handled by yourself, and the second one updated by this function internally. For example, you might reserve the first \c 12 Bytes for the per-message nonce, and the last \c 4 Bytes for internal use. In that case, before calling this function on a new message you need to set the first \c 12 Bytes of \p nonce_counter to your chosen nonce value, the last four to \c 0, and \p nc_off to \c 0 (which will cause \p stream_block to be ignored). That way, you can encrypt at most \c 2**96 messages of up to \c 2**32 blocks each with the same key. The per-message nonce (or information sufficient to reconstruct it) needs to be communicated with the ciphertext and must be unique. The recommended way to ensure uniqueness is to use a message counter. An alternative is to generate random nonces, but this limits the number of messages that can be securely encrypted: for example, with 96-bit random nonces, you should not encrypt more than 2**32 messages with the same key. Note that for both strategies, sizes are measured in blocks and that a CAMELLIA block is \c 16 Bytes. \warning Upon return, \p stream_block contains sensitive data. Its content must not be written to insecure storage and should be securely discarded as soon as it's no longer needed.
Wait for the SHA engine to finish any current operation
Read out the result from the previous calculation.
Get the cache timeout A timeout of 0 indicates no timeout.
Print a field of the ECDH structure in the SSL context to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_ECDH() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Print a message to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_MSG() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Print the return value of a function to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_RET() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Output a buffer of size len bytes to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_BUF() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Print a MPI variable to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_MPI() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Print an ECP point to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_ECP() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Print a X.509 certificate structure to the debug output. This function is always used through the MBEDTLS_SSL_DEBUG_CRT() macro, which supplies the ssl context, file and line number parameters. \attention This function is intended for INTERNAL usage within the library only.
Sign an already-calculated hash with a private key using p256-m's ECDSA implementation
Verify the signature of a hash using a SECP256R1 public key using p256-m's ECDSA implementation.
Export SECP256R1 public key, from the private key.
Generate SECP256R1 ECC Key Pair. Interface function which calls the p256-m key generation function and places it in the key buffer provided by the caller (Mbed TLS) in the correct format. For a SECP256R1 curve this is the 32 bit private key.
Perform raw key agreement using p256-m's ECDH implementation
Set the EC J-PAKE opaque password for current handshake.