Skip to content

Commit 9bc2dd0

Browse files
committed
Merge branch 'fix/update_documentation_for_ds_apis' into 'master'
Digital Signature (ds):) Update the documentation for ds APIs Closes IDFGH-6600 See merge request espressif/esp-idf!16997
2 parents 60d7ea1 + bb7be62 commit 9bc2dd0

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

components/esp_hw_support/include/soc/esp32c3/esp_ds.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,19 @@ typedef struct {
101101

102102
/**
103103
* @brief Sign the message with a hardware key from specific key slot.
104+
* The function calculates a plain RSA signature with help of the DS peripheral.
105+
* The RSA encryption operation is as follows:
106+
* Z = XY mod M where,
107+
* Z is the signature, X is the input message,
108+
* Y and M are the RSA private key parameters.
104109
*
105110
* This function is a wrapper around \c esp_ds_finish_sign() and \c esp_ds_start_sign(), so do not use them
106111
* in parallel.
107112
* It blocks until the signing is finished and then returns the signature.
108113
*
109114
* @note This function locks the HMAC, SHA, AES and RSA components during its entire execution time.
110115
*
111-
* @param message the message to be signed; its length is determined by data->rsa_length
116+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
112117
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
113118
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
114119
* signing key data
@@ -134,11 +139,16 @@ esp_err_t esp_ds_sign(const void *message,
134139
*
135140
* This function yields a context object which needs to be passed to \c esp_ds_finish_sign() to finish the signing
136141
* process.
142+
* The function calculates a plain RSA signature with help of the DS peripheral.
143+
* The RSA encryption operation is as follows:
144+
* Z = XY mod M where,
145+
* Z is the signature, X is the input message,
146+
* Y and M are the RSA private key parameters.
137147
*
138148
* @note This function locks the HMAC, SHA, AES and RSA components, so the user has to ensure to call
139149
* \c esp_ds_finish_sign() in a timely manner.
140150
*
141-
* @param message the message to be signed; its length is determined by data->rsa_length
151+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
142152
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
143153
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
144154
* signing key data

components/esp_hw_support/include/soc/esp32h2/esp_ds.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,19 @@ typedef struct {
101101

102102
/**
103103
* @brief Sign the message with a hardware key from specific key slot.
104+
* The function calculates a plain RSA signature with help of the DS peripheral.
105+
* The RSA encryption operation is as follows:
106+
* Z = XY mod M where,
107+
* Z is the signature, X is the input message,
108+
* Y and M are the RSA private key parameters.
104109
*
105110
* This function is a wrapper around \c esp_ds_finish_sign() and \c esp_ds_start_sign(), so do not use them
106111
* in parallel.
107112
* It blocks until the signing is finished and then returns the signature.
108113
*
109114
* @note This function locks the HMAC, SHA, AES and RSA components during its entire execution time.
110115
*
111-
* @param message the message to be signed; its length is determined by data->rsa_length
116+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
112117
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
113118
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
114119
* signing key data
@@ -135,10 +140,16 @@ esp_err_t esp_ds_sign(const void *message,
135140
* This function yields a context object which needs to be passed to \c esp_ds_finish_sign() to finish the signing
136141
* process.
137142
*
143+
* The function calculates a plain RSA signature with help of the DS peripheral.
144+
* The RSA encryption operation is as follows:
145+
* Z = XY mod M where,
146+
* Z is the signature, X is the input message,
147+
* Y and M are the RSA private key parameters.
148+
*
138149
* @note This function locks the HMAC, SHA, AES and RSA components, so the user has to ensure to call
139150
* \c esp_ds_finish_sign() in a timely manner.
140151
*
141-
* @param message the message to be signed; its length is determined by data->rsa_length
152+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
142153
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
143154
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
144155
* signing key data

components/esp_hw_support/include/soc/esp32s2/esp_ds.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,15 @@ typedef struct {
9292
* in parallel.
9393
* It blocks until the signing is finished and then returns the signature.
9494
*
95+
* The function calculates a plain RSA signature with help of the DS peripheral.
96+
* The RSA encryption operation is as follows:
97+
* Z = XY mod M where,
98+
* Z is the signature, X is the input message,
99+
* Y and M are the RSA private key parameters.
100+
*
95101
* @note This function locks the HMAC, SHA, AES and RSA components during its entire execution time.
96102
*
97-
* @param message the message to be signed; its length is determined by data->rsa_length
103+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
98104
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
99105
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
100106
* signing key data
@@ -121,10 +127,16 @@ esp_err_t esp_ds_sign(const void *message,
121127
* This function yields a context object which needs to be passed to \c esp_ds_finish_sign() to finish the signing
122128
* process.
123129
*
130+
* The function calculates a plain RSA signature with help of the DS peripheral.
131+
* The RSA encryption operation is as follows:
132+
* Z = XY mod M where,
133+
* Z is the signature, X is the input message,
134+
* Y and M are the RSA private key parameters.
135+
*
124136
* @note This function locks the HMAC, SHA, AES and RSA components, so the user has to ensure to call
125137
* \c esp_ds_finish_sign() in a timely manner.
126138
*
127-
* @param message the message to be signed; its length is determined by data->rsa_length
139+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
128140
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
129141
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
130142
* signing key data

components/esp_hw_support/include/soc/esp32s3/esp_ds.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,15 @@ typedef struct {
9494
* in parallel.
9595
* It blocks until the signing is finished and then returns the signature.
9696
*
97+
* The function calculates a plain RSA signature with help of the DS peripheral.
98+
* The RSA encryption operation is as follows:
99+
* Z = XY mod M where,
100+
* Z is the signature, X is the input message,
101+
* Y and M are the RSA private key parameters.
102+
*
97103
* @note This function locks the HMAC, SHA, AES and RSA components during its entire execution time.
98104
*
99-
* @param message the message to be signed; its length is determined by data->rsa_length
105+
* @param message the message to be signed; its length should be (data->rsa_length + 1)*4 bytes
100106
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
101107
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
102108
* signing key data
@@ -123,10 +129,16 @@ esp_err_t esp_ds_sign(const void *message,
123129
* This function yields a context object which needs to be passed to \c esp_ds_finish_sign() to finish the signing
124130
* process.
125131
*
132+
* The function calculates a plain RSA signature with help of the DS peripheral.
133+
* The RSA encryption operation is as follows:
134+
* Z = XY mod M where,
135+
* Z is the signature, X is the input message,
136+
* Y and M are the RSA private key parameters.
137+
*
126138
* @note This function locks the HMAC, SHA, AES and RSA components, so the user has to ensure to call
127139
* \c esp_ds_finish_sign() in a timely manner.
128140
*
129-
* @param message the message to be signed; its length is determined by data->rsa_length
141+
* @param message the message to be signed; its length should be (data->rsa_length +1 )*4 bytes
130142
* @param data the encrypted signing key data (AES encrypted RSA key + IV)
131143
* @param key_id the HMAC key ID determining the HMAC key of the HMAC which will be used to decrypt the
132144
* signing key data

docs/en/api-reference/peripherals/ds.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ The first one is :cpp:func:`esp_ds_sign` and simply blocks until the calculation
4343
If software needs to do something else during the calculation, :cpp:func:`esp_ds_start_sign` can be called, followed by periodic calls to :cpp:func:`esp_ds_is_busy` to check when the calculation has finished.
4444
Once the calculation has finished, :cpp:func:`esp_ds_finish_sign` can be called to get the resulting signature.
4545

46+
The APIs :cpp:func:`esp_ds_sign` and :cpp:func:`esp_ds_start_sign` calculate a plain RSA signature with help of the DS peripheral. This signature needs to be converted to appropriate format for further use. For example, MbedTLS SSL stack supports PKCS#1 format. The API :cpp:func:`esp_ds_rsa_sign` can be used to obtain the signature directly in the PKCS#1 v1.5 format. It internally uses :cpp:func:`esp_ds_start_sign` and converts the signature into PKCS#1 v1.5 format.
47+
4648
.. note::
4749
Note that this is only the basic DS building block, the message length is fixed.
4850
To create signatures of arbitrary messages, the input is normally a hash of the actual message, padded up to the required length.
@@ -67,7 +69,7 @@ More details about the `configure_ds.py` script can be found at :example_file:`m
6769
The encrypted private key parameters obtained after the DS peripheral configuration are then to be kept in flash. Furthermore, they are to be passed to the DS peripheral which makes use of those parameters for the Digital Signature operation.
6870
:doc:`Non Volatile Storage<../storage/nvs_flash>` can be used to store the encrypted private key parameters in flash.
6971
The script :example_file:`configure_ds.py<protocols/mqtt/ssl_ds/configure_ds.py>` creates an NVS partition for the encrypted private key parameters. Then the script flashes this partition onto the {IDF_TARGET_NAME}.
70-
The application then needs to read the DS data from NVS, which can be done with the function `esp_read_ds_data_from_nvs` in file :example_file:`ssl_mutual_auth/main/app_main.c <protocols/mqtt/ssl_mutual_auth/main/app_main.c>`
72+
The application then needs to read the DS data from NVS, which can be done with the function ``esp_read_ds_data_from_nvs()`` in file :example_file:`ssl_ds/main/app_main.c <protocols/mqtt/ssl_ds/main/app_main.c>`
7173

7274
The process of initializing the DS peripheral and then performing the Digital Signature operation is done internally with help of `ESP-TLS`. Please refer to `Digital Signature with ESP-TLS` in :doc:`ESP-TLS <../protocols/esp_tls>` for more details.
7375
As mentioned in the `ESP-TLS` documentation, the application only needs to provide the encrypted private key parameters to the esp_tls context (as `ds_data`), which internally performs

0 commit comments

Comments
 (0)