Algorithms

Algorithm categories

PSA_ALG_NONE (macro)

An invalid algorithm identifier value.

#define PSA_ALG_NONE ((psa_algorithm_t)0)

Zero is not the encoding of any algorithm.

PSA_ALG_IS_HASH (macro)

Whether the specified algorithm is a hash algorithm.

#define PSA_ALG_IS_HASH(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a hash algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Hash algorithms for a list of defined hash algorithms.

PSA_ALG_IS_MAC (macro)

Whether the specified algorithm is a MAC algorithm.

#define PSA_ALG_IS_MAC(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a MAC algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See MAC algorithms for a list of defined MAC algorithms.

PSA_ALG_IS_CIPHER (macro)

Whether the specified algorithm is a symmetric cipher algorithm.

#define PSA_ALG_IS_CIPHER(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a symmetric cipher algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Cipher algorithms for a list of defined cipher algorithms.

PSA_ALG_IS_AEAD (macro)

Whether the specified algorithm is an authenticated encryption with associated data (AEAD) algorithm.

#define PSA_ALG_IS_AEAD(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is an AEAD algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See AEAD algorithms for a list of defined AEAD algorithms.

PSA_ALG_IS_SIGN (macro)

Whether the specified algorithm is a public-key signature algorithm.

#define PSA_ALG_IS_SIGN(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a public-key signature algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Asymmetric signature algorithms for a list of defined signature algorithms.

PSA_ALG_IS_ASYMMETRIC_ENCRYPTION (macro)

Whether the specified algorithm is a public-key encryption algorithm.

#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a public-key encryption algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Asymmetric encryption algorithms for a list of defined asymmetric encryption algorithms.

PSA_ALG_IS_KEY_AGREEMENT (macro)

Whether the specified algorithm is a key agreement algorithm.

#define PSA_ALG_IS_KEY_AGREEMENT(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a key agreement algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Key agreement algorithms for a list of defined key agreement algorithms.

PSA_ALG_IS_KEY_DERIVATION (macro)

Whether the specified algorithm is a key derivation algorithm.

#define PSA_ALG_IS_KEY_DERIVATION(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a key derivation algorithm, 0 otherwise. This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

See Key derivation algorithms for a list of defined key derivation algorithms.

PSA_ALG_IS_WILDCARD (macro)

Whether the specified algorithm encoding is a wildcard.

#define PSA_ALG_IS_WILDCARD(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

1 if alg is a wildcard algorithm encoding.

0 if alg is a non-wildcard algorithm encoding that is suitable for an operation.

This macro can return either 0 or 1 if alg is not a supported algorithm identifier.

Description

Wildcard algorithm values can only be used to set the usage algorithm field in a policy, wildcard values cannot be used to perform an operation.

See PSA_ALG_ANY_HASH for example of how a wildcard algorithm can be used in a key policy.

PSA_ALG_GET_HASH (macro)

Get the hash used by a composite algorithm.

#define PSA_ALG_GET_HASH(alg) /* specification-defined value */

Parameters

alg
An algorithm identifier (value of type psa_algorithm_t).

Returns

The underlying hash algorithm if alg is a composite algorithm that uses a hash algorithm.

PSA_ALG_NONE if alg is not a composite algorithm that uses a hash.

Description

The following composite algorithms require a hash algorithm:

Attribute accessors

psa_set_key_algorithm (function)

Declare the permitted algorithm policy for a key.

void psa_set_key_algorithm(psa_key_attributes_t * attributes,
                           psa_algorithm_t alg);

Parameters

attributes
The attribute object to write to.
alg
The permitted algorithm policy to write.

Returns: void

Description

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:

  • PSA_ALG_NONE does not allow any cryptographic operation with the key. The key can still 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.

This function overwrites any algorithm policy previously set in attributes.

Implementation note

This is a simple accessor function that is not required to validate its inputs. The following approaches can be used to provide an efficient implementation:

  • This function can be declared as static or inline, instead of using the default external linkage.
  • This function can be provided as a function-like macro. In this form, the macro must evaluate each of its arguments exactly once, as if it was a function call.

psa_get_key_algorithm (function)

Retrieve the algorithm policy from key attributes.

psa_algorithm_t psa_get_key_algorithm(const psa_key_attributes_t * attributes);

Parameters

attributes
The key attribute object to query.

Returns: psa_algorithm_t

The algorithm stored in the attribute object.

Description

Implementation note

This is a simple accessor function that is not required to validate its inputs. The following approaches can be used to provide an efficient implementation:

  • This function can be declared as static or inline, instead of using the default external linkage.
  • This function can be provided as a function-like macro. In this form, the macro must evaluate each of its arguments exactly once, as if it was a function call.