11.12.3.4.136. Function Se05x_API_WriteRSAKey

11.12.3.4.136.1. Function Documentation

smStatus_t Se05x_API_WriteRSAKey(pSe05xSession_t session_ctx, pSe05xPolicy_t policy, uint32_t objectID, uint16_t size, const uint8_t *p, size_t pLen, const uint8_t *q, size_t qLen, const uint8_t *dp, size_t dpLen, const uint8_t *dq, size_t dqLen, const uint8_t *qInv, size_t qInvLen, const uint8_t *pubExp, size_t pubExpLen, const uint8_t *priv, size_t privLen, const uint8_t *pubMod, size_t pubModLen, const SE05x_INS_t transient_type, const SE05x_KeyPart_t key_part, const SE05x_RSAKeyFormat_t rsa_format)

Se05x_API_WriteRSAKey

Creates or writes an RSA key or a key component.

Supported key sizes are listed in RSABitLength. Other values are not supported.

An RSA key creation requires multiple ADPUs to be sent:

  • The first APDU must contain:

    • Policy (optional, so only if non-default applies)

    • Object identifier

    • Key size

    • 1 of the key components.

  • Each next APDU must contain 1 of the key components.

The policy applies only once all key components are set.

Once an RSAKey object has been created, its format remains fixed and cannot be updated (so CRT or raw mode, no switch possible).

If the object already exists, P1KeyType is ignored.

For key pairs, if no component is present (TAG_3 until TAG_9), the key pair will be generated on chip; otherwise the key pair will be constructed starting with the given component.

For private keys or public keys, there should always be exactly one of the tags TAG_3 until TAG_10.

  • TLV[TAG_8] and TLV[TAG_10] must only contain a value if the key pair is to be set to a known value and P1KeyType is either P1_KEY_PAIR or P1_PUBLIC; otherwise the value must be absent and the length must be equal to 0.

  • TLV[TAG_9] must only contain a value it the key is to be set in raw mode to a known value and P1KeyType is either P1_KEY_PAIR or P1_PRIVATE; otherwise the value must be absent and the length must be equal to 0.

  • If TLV[TAG_3] up to TLV[TAG_10] are absent (except TLV[TAG_8]), the RSA key will be generated on chip in case the object does not yet exist; otherwise it will be regenerated. This only applies to RSA key pairs.

  • Keys can be set by setting the different components of a key; only 1 component can be set at a time in this case.

Field

Value

Description

P1

SE05x_KeyPart_t | P1_RSA

See SE05x_P1_t

P2

P2_DEFAULT or P2_RAW

See SE05x_P2_t; P2_RAW only in case P1KeyPart = P1_KEY_PAIR and TLV[TAG_3] until TLV[TAG_10] is empty and the must generate a raw RSA key pair; all other cases: P2_DEFAULT.

Payload

TLV[TAG_POLICY]

Byte array containing the object policy. [Optional: default policy applies] [Conditional: only when the object identifier is not in use yet]

TLV[TAG_1]

4-byte object identifier

TLV[TAG_2]

2-byte key size in bits (SE05x_RSABitLength_t) [Conditional: only when the object identifier is not in use yet]

TLV[TAG_3]

P component [Conditional: only when the object identifier is in CRT mode and the key is generated externally and P1KeyPart is either P1_KEY_PAIR or P1_PRIVATE]

TLV[TAG_4]

Q component [Conditional: only when the object identifier is in CRT mode and the key is generated externally and P1KeyPart is either P1_KEY_PAIR or P1_PRIVATE]

TLV[TAG_5]

DP component [Conditional: only when the object identifier is in CRT mode and the key is generated externally and P1KeyPart is either P1_KEY_PAIR or P1_PRIVATE]

TLV[TAG_6]

DQ component [Conditional: only when the object identifier is in CRT mode and the key is generated externally and P1KeyPart is either P1_KEY_PAIR or P1_PRIVATE]

TLV[TAG_7]

INV_Q component [Conditional: only when the object identifier is in CRT mode and the key is generated externally and P1KeyPart is either P1_KEY_PAIR or P1_PRIVATE]

TLV[TAG_8]

Public exponent

TLV[TAG_9]

Private Key (non-CRT mode only)

TLV[TAG_10]

Public Key (Modulus)

TLV[TAG_11]

4-byte version [Optional]

Return

The sm status.

Parameters
  • [in] session_ctx: The session context

  • [in] policy: The policy

  • [in] objectID: The object id

  • [in] size: The size

  • [in] p: The part p

  • [in] pLen: The p length

  • [in] q: The quarter

  • [in] qLen: The quarter length

  • [in] dp: The part dp

  • [in] dpLen: The dp length

  • [in] dq: The part dq

  • [in] dqLen: The dq length

  • [in] qInv: The quarter inv

  • [in] qInvLen: The quarter inv length

  • [in] pubExp: The pub exponent

  • [in] pubExpLen: The pub exponent length

  • [in] priv: The priv

  • [in] privLen: The priv length

  • [in] pubMod: The pub modifier

  • [in] pubModLen: The pub modifier length

  • [in] transient_type: The transient type

  • [in] key_part: The key part

  • [in] rsa_format: The rsa format