Skip to content

Commit b070c25

Browse files
committed
PS-9713 [DOCS] - Document new PS Encryption UDFs functionality (inspired by upstream 8.4.4)
modified: docs/encryption-functions.md
1 parent 3431afe commit b070c25

File tree

1 file changed

+146
-31
lines changed

1 file changed

+146
-31
lines changed

docs/encryption-functions.md

+146-31
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,68 @@ When choosing key lengths, consider the following:
1212

1313
* If performance is important and the functions are frequently used, use symmetric encryption. Symmetric encryption functions are faster than asymmetric encryption functions. Moreover, asymmetric encryption has restrictions on the maximum length of a message being encrypted. For example, for RSA the algorithm maximum message size is the key length in bytes (key length in bits / 8) minus 11.
1414

15+
## Version updates
16+
17+
Percona Server for MySQL 8.4.4 adds the following:
18+
19+
* Support for `pkcs1`, `oaep`, or `no` padding for RSA encrypt and decrypt operations
20+
21+
<details>
22+
<summary> `pkcs1` padding explanation</summary>
23+
[`RSAES-PKCS1-v1_5`](https://en.wikipedia.org/wiki/PKCS_1) RSA encryption padding scheme prevents patterns that attackers could exploit by including a random sequence of bytes, which ensures that the ciphertext is different no matter how many times it is encrypted.
24+
</details>
25+
26+
<details>
27+
<summary> `oaep` padding explanation</summary>
28+
The [`RSAES-OAEP`](https://en.wikipedia.org/wiki/PKCS_1) - [`Optimal Asymmetric Encryption Padding`](https://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding) RSA encryption padding scheme adds a randomized mask generation function. This function makes it more difficult for attackers to exploit the encryption algorithm's weaknesses or recover the original message.
29+
</details>
30+
31+
<details>
32+
<summary> `no` padding explanation</summary>
33+
Using `no` padding means the plaintext message is encrypted without adding an extra layer before performing the RSA encryption operation.
34+
</details>
35+
36+
* Support for `pkcs1` or `pkcs1_pss` padding for RSA sign and verify operations
37+
38+
<details>
39+
<summary> `pkcs1` padding explanation</summary>
40+
The [`RSASSA-PKCS1-v1_5`](https://en.wikipedia.org/wiki/PKCS_1) is a deterministic RSA signature padding scheme that hashes a message, pads the hash with a specific structure, and encrypts it with the signer's private key for signature generation.
41+
</details>
42+
<details>
43+
<summary> `pkcs1_pss` padding explanation</summary>
44+
The [`RSASSA-PSS`](https://en.wikipedia.org/wiki/PKCS_1) - [`Probabilistic Signature Scheme'](https://en.wikipedia.org/wiki/Probabilistic_signature_scheme) is an RSA signature padding scheme used to add randomness to a message before signing it with a private key. This randomness helps to increase the security of the signature and makes it more resistant to various attacks.
45+
</details>
46+
47+
* [`encryption_udf.legacy_paddding_scheme`](#encryption_udflegacy_paddding_scheme) system variable
48+
49+
* Character set awareness
50+
51+
## Charset Awareness
52+
53+
All component_encryption_udf functions now handle character sets intelligently:
54+
55+
• Algorithms, digest names, padding schemes, keys, and parameters in PEM format: Automatically converted to the ASCII charset at the MySQL level before passing to the functions.
56+
57+
• Messages, data blocks, and signatures used for digest calculation, encryption, decryption, signing, or verification: Automatically converted to the binary charset at the MySQL level before passing to the functions.
58+
59+
• Function return values in PEM format: Assigned the ASCII charset.
60+
61+
• Function return values for operations like digest calculation, encryption, decryption, and signing: Assigned the binary charset.
62+
63+
## Use user-defined functions
64+
65+
You can also use the user-defined functions with the PEM format keys generated externally by the OpenSSL utility.
66+
67+
A digest uses plaintext and generates a hash value. This hash value can verify if the plaintext is unmodified. You can also sign or verify on digests to ensure that the original plaintext was not modified. You cannot decrypt the original text from the hash value.
68+
69+
When choosing key lengths, consider the following:
70+
71+
* Encryption strength increases with the key size and generation time.
72+
73+
* If performance is essential and the functions are frequently used, use symmetric encryption. Symmetric encryption functions are faster than asymmetric encryption functions. Moreover, asymmetric encryption restricts the maximum length of a message being encrypted. For example, the algorithm's maximum message size for RSA is the key length in bytes (key length in bits / 8) minus 11.
74+
75+
## Functions
76+
1577
The following table and sections describe the functions. For examples, see function examples.
1678

1779
| Function Name |
@@ -25,20 +87,24 @@ The following table and sections describe the functions. For examples, see funct
2587
| [create_asymmetric_pub_key(algorithm, priv_key_str)](#create_asymmetric_pub_keyalgorithm-priv_key_str) |
2688
| [create_dh_parameters(key_len)](#create_dh_parameterskey_len) |
2789
| [create_digest(digest_type, str)](#create_digestdigest_type-str) |
90+
| [create_digest(digest_type, str)](#create_digestdigest_type-str) |
2891

29-
The following table describes the Encryption threshold variables which can be used to set the maximum value for a key length based on the type of encryption.
92+
The following table describes the encryption threshold variables which can be used to set the maximum value for a key length based on the type of encryption used.
3093

3194
| Variable Name |
3295
|-----------------------------------|
3396
| [encryption_udf.dh_bits_threshold](#encryption_udfdh_bits_threshold) |
3497
| [encryption_udf.dsa_bits_threshold](#encryption_udfdsa_bits_threshold) |
98+
| [encryption_udf.legacy_padding](#encryption_udflegacy_padding)|
3599
| [encryption_udf.rsa_bits_threshold](#encryption_udfrsa_bits_threshold) |
36100

101+
102+
37103
## Install component_encryption_udf
38104

39105
Use the [Install Component Statement] to add the component_encryption_udf component. The functions and variables are available. The user-defined functions and the Encryption threshold variables are auto-registered. There is no requirement to invoke `CREATE FUNCTION ... SONAME ...`.
40106

41-
The `INSERT` privilege on the `mysql.component` system table is required to run the `INSTALL COMPONENT` statement. To register the component, the operation adds a row to this table.
107+
The `INSERT` privilege on the `mysql.component` system table is required to run the `INSTALL COMPONENT` statement. The operation adds a row to this table to register the component.
42108

43109
The following is an example of the installation command:
44110

@@ -48,7 +114,7 @@ mysql> INSTALL COMPONENT 'file://component_encryption_udf';
48114

49115
!!! note
50116

51-
If you are Compiling Percona Server for MySQL from Source, the Encryption UDF component is built by default when Percona Server for MySQL is built. Specify the `-DWITH_ENCRYPTION_UDF=OFF` cmake option to exclude it.
117+
When you build Percona Server for MySQL from source code, the Encryption UDF component is included by default. To exclude it, use the `-DWITH_ENCRYPTION_UDF=OFF` option with cmake.
52118

53119
## User-defined functions described
54120

@@ -64,13 +130,17 @@ A plaintext as a string.
64130

65131
The following are the function’s parameters:
66132

67-
* algorithm - the encryption algorithm supports RSA to decrypt the string.
133+
* algorithm - the encryption algorithm supports RSA in decrypting the string.
134+
135+
* `crypt_str` - an encrypted string produced by certain encryption functions like AES_ENCRYPT(). This string is typically stored as a binary or blog data type.
68136

69137
* key_str - a string in the PEM format. The key string must have the following attributes:
70138

71139
* Valid
72140

73-
* Public or private key string that corresponds with the private or public key string used with the asymmetric_encrypt function.
141+
* Public or private key string corresponding with the private or public key string used with the [`asymmetric_encrypt`](#asymmetric_encrypt) function.
142+
143+
* padding - An optional parameter introduced in Percona Server for MySQL 8.4.4. It is used with the RSA algorithm and supports RSA encryption padding schemes like pkcs1, or oaep. If you skip this parameter, the system determines its value based on the [`encryption_udf.legacy_padding_scheme`](#encryption_udf.legacy_padding_scheme) variable.
74144

75145
## asymmetric_derive(*pub_key_str, priv_key_str*)
76146

@@ -104,6 +174,8 @@ The parameters are the following:
104174

105175
* key_str - a key (either private or public) in the PEM format
106176

177+
* padding - An optional parameter introduced in Percona Server for MySQL 8.4.4. It is used with the RSA algorithm and supports RSA encryption padding schemes like pkcs1, or oaep. If you skip this parameter, the system determines its value based on the [`encryption_udf.legacy_padding_scheme`](#encryption_udf.legacy_padding_scheme) variable.
178+
107179
## asymmetric_sign(*algorithm, digest_str, priv_key_str, digest_type*)
108180

109181
Signs a digest string using a private key string.
@@ -116,7 +188,7 @@ A signature is a binary string.
116188

117189
The parameters are the following:
118190

119-
* algorithm - the encryption algorithm supports either RSA or DSA to encrypt the string.
191+
* algorithm - the encryption algorithm supports either RSA or DSA in encrypting the string.
120192

121193
* digest_str - the digest binary string that is signed. Invoking create_digest generates the digest.
122194

@@ -146,9 +218,7 @@ The parameters are the following:
146218
| | | shake128 | |
147219
| | | shake256 | |
148220

149-
## asymmetric_verify(*algorithm, digest_str, sig_str, pub_key_str, digest_type*)
150-
151-
Verifies whether the signature string matches the digest string.
221+
* padding - An optional parameter introduced in Percona Server for MySQL 8.4.4. It is used with the RSA algorithm and supports RSA signature padding schemes like `pkcs1`, or `pkcs1_pss`. If you skip this parameter, the system determines its value based on the [`encryption_udf.legacy_padding_scheme`](encryption_udf.legacy_padding_scheme) variable.
152222

153223
### asymmetric_verify output
154224

@@ -168,6 +238,8 @@ The parameters are the following:
168238

169239
* digest_type - the supported values are listed in the digest type table of create_digest
170240

241+
* padding - An optional parameter introduced in Percona Server for MySQL 8.4.4. It is used with the RSA algorithm and supports RSA signature padding schemes like `pkcs1`, or `pkcs1_pss`. If you skip this parameter, the system determines its value based on the [`encryption_udf.legacy_padding_scheme`](#encryption_udf.legacy_padding_scheme) variable.
242+
171243
## create_asymmetric_priv_key(*algorithm, (key_len | dh_parameters)*)
172244

173245
Generates a private key using the given algorithm and key length for RSA or DSA
@@ -221,12 +293,11 @@ If needed, execute `KILL [QUERY|CONNECTION] <id>` to terminate the generation of
221293

222294
Generating the DH parameters can take more time than generating the RSA keys or
223295
the DSA keys.
224-
OpenSSL defines the parameter length limits. To change the
225-
maximum parameter length, use encryption_udf.dh_bits_threshold.
296+
OpenSSL defines the parameter length limits. To change the maximum parameter length, use [`encryption_udf.dh_bits_threshold`](#encryption_udf.dh_bits_threshold).
226297

227298
### create_dh_parameters output
228299

229-
A string in the PEM format and can be passed to create_asymmetric_private_key.
300+
A string in the PEM format and can be passed to [create_asymmetric_private_key](#create_asymmetric_private_key).
230301

231302
### create_dh_parameters parameters
232303

@@ -236,7 +307,7 @@ The parameters are the following:
236307

237308
## create_digest(*digest_type, str*)
238309

239-
Creates a digest from the given string using the given digest type. The digest string can be used with asymmetric_sign and asymmetric_verify.
310+
Creates a digest from the given string using the given digest type. The digest string can be used with [`asymmetric_sign`](#asymmetric_sign) and [`asymmetric_verify`](#asymmetric_verify).
240311

241312
### create_digest output
242313

@@ -284,7 +355,7 @@ The variables are automatically registered when component_encryption_udf is inst
284355

285356
### `encryption_udf.dh_bits_threshold`
286357

287-
The variable sets the maximum limit for the create_dh_parameters user-defined function and takes precedence over the OpenSSL maximum length value.
358+
The variable sets the maximum limit for the [`create_dh_parameters`](#create_dh_parameters) user-defined function and takes precedence over the OpenSSL maximum length value.
288359

289360
| Option | Description |
290361
|--------------|------------------|
@@ -297,7 +368,7 @@ The range for this variable is from 1024 to 10,000. The default value is 10,000.
297368

298369
### encryption_udf.dsa_bits_threshold
299370

300-
The variable sets the threshold limits for create_asymmetric_priv_key user-defined function when the function is invoked with the DSA parameter and takes precedence over the OpenSSL maximum length value.
371+
The variable sets the threshold limits for [`create_asymmetric_priv_key`](#create_asymmetric_priv_key) user-defined function when the function is invoked with the DSA parameter and takes precedence over the OpenSSL maximum length value.
301372

302373
| Option | Description |
303374
|--------------|------------------|
@@ -308,9 +379,53 @@ The variable sets the threshold limits for create_asymmetric_priv_key user-defin
308379

309380
The range for this variable is from 1,024 to 9,984. The default value is 9,984.
310381

382+
### encryption_udf.legacy_padding
383+
384+
The variable enables or disables the legacy padding scheme for certain encryption operations.
385+
386+
| Option | Description |
387+
|--------------|------------------|
388+
| command-line | Yes |
389+
| scope | Global |
390+
| data type | Boolean |
391+
| default | OFF |
392+
393+
This system variable is a BOOLEAN type and set to `OFF` by default.
394+
395+
This variable controls how the functions [`asymmetric_encrypt()`](#asymmetric_encrypt), [`asymmetric_decrypt()`](#asymmetric_decrypt), [`asymmetric_sign()`](#asymmetric_sign), and [`asymmetric_verify()`](#asymmetric_verify) behave when you don’t explicitly set the padding parameter.
396+
397+
• When [encryption_udf.legacy_padding_scheme](#encryption_udf.legacy_padding_scheme) is OFF:
398+
399+
• [asymmetric_encrypt()](#asymmetric_encrypt) and [asymmetric_decrypt()](#asymmetric_decrypt) use OAEP encryption padding.
400+
401+
• [asymmetric_sign()](#asymmetric_sign) and [asymmetric_verify()](#asymmetric_verify) use PKCS1_PSS signature padding.
402+
403+
• When [encryption_udf.legacy_padding_scheme](#encryption_udf.legacy_padding_scheme) is ON:
404+
405+
• [`asymmetric_encrypt()`](#asymmetric_encrypt) and [`asymmetric_decrypt()`](#asymmetric_decrypt) use PKCS1 encryption padding.
406+
407+
• [`asymmetric_sign()`](#asymmetric_sign) and [`asymmetric_verify()`](#asymmetric_verify) use PKCS1 signature padding.
408+
409+
The [`asymmetric_encrypt()`](#asymmetric_encrypt) and [`asymmetric_decrypt()`](#asymmetric_decrypt) functions, when the encryption is `RSA`, can accept an optional parameter, `padding`. You can set this parameter to `no`, `pkcs1`, or `oaep`. If you don’t specify this parameter, it defaults based on the [`encryption_udf.legacy_padding_scheme`](#encryption_udf.legacy_padding_scheme) value.
410+
411+
The padding schemes have the following limitations:
412+
413+
| Padding Scheme | Details |
414+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
415+
| `oaep` | The message you encrypt can be as long as your RSA key size in bytes - 42 bytes.|
416+
| `no` | The message length must exactly match your RSA key size in bytes. For example, if your key is 1024 bits (128 bytes), the message must also be 128 bytes. If it doesn’t match, it will cause an error. |
417+
| `pkcs1` | Your message can be equal to or smaller than the RSA key size - 11 bytes. For instance, with a 1024-bit RSA key, your message can’t be longer than 117 bytes.|
418+
419+
Similarly, [`asymmetric_sign()`](#asymmetric_sign) and [`asymmetric_verify()`](#asymmetric_verify) also have an optional `padding` parameter, either `pkcs1` or `pkcs1_pss`. If not explicitly set, it follows the default based on [`encryption_udf.legacy_padding_scheme`](#encryption_udf.legacy_padding_scheme). You can only use the padding parameter with RSA algorithms.
420+
421+
#### Additional resources
422+
423+
For more information, read [`Digital Signatures: Another layer of Data Protection in Percona Server for MySQL`](https://www.percona.com/blog/digital-signatures-another-layer-of-data-protection-in-percona-server-for-mysql/)
424+
425+
311426
### encryption_udf.rsa_bits_threshold
312427

313-
The variable sets the threshold limits for the create_asymmetric_priv_key user-defined function when the function is invoked with the RSA parameter and takes precedence over the OpenSSL maximum length value.
428+
The variable sets the threshold limits for the [`create_asymmetric_priv_key`](#encryption_udf.create_asymmetric_priv_key) user-defined function when the function is invoked with the RSA parameter and takes precedence over the OpenSSL maximum length value.
314429

315430
| Option | Description |
316431
|--------------|------------------|
@@ -325,15 +440,15 @@ The range for this variable is from 1,024 to 16,384. The default value is 16,384
325440

326441
Code examples for the following operations:
327442

328-
* set the threshold variables
443+
* Set the threshold variables
329444

330-
* create a private key
445+
* Create a private key
331446

332-
* create a public key
447+
* Create a public key
333448

334-
* encrypt data
449+
* Encrypt data
335450

336-
* decrypt data
451+
* Decrypt data
337452

338453
```{.bash data-prompt="mysql>"}
339454
-- Set Global variable
@@ -360,11 +475,11 @@ mysql> SET @plaintext = asymmetric_decrypt('RSA', @ciphertext, @public_key);
360475

361476
Code examples for the following operations:
362477

363-
* generate a digest string
478+
* Generate a digest string
364479

365-
* generate a digest signature
480+
* Generate a digest signature
366481

367-
* verify the signature against the digest
482+
* Verify the signature against the digest
368483

369484
```{.bash data-prompt="mysql>"}
370485
-- Generate a digest string
@@ -380,13 +495,13 @@ mysql> SET @verify_signature = asymmetric_verify('RSA', @digest, @signature, @pu
380495

381496
Code examples for the following operations:
382497

383-
* generate a DH parameter
498+
* Generate a DH parameter
384499

385-
* generates two DH key pairs
500+
* Generates two DH key pairs
386501

387-
* generate a symmetric key using the public_1 and the private_2
502+
* Generate a symmetric key using the public_1 and the private_2
388503

389-
* generate a symmetric key using the public_2 and the private_1
504+
* Generate a symmetric key using the public_2 and the private_1
390505

391506
```{.bash data-prompt="mysql>"}
392507
-- Generate a DH parameter
@@ -409,11 +524,11 @@ mysql> SET symmetric_2 = asymmetric_derive(@public_2, @private_1);
409524

410525
Code examples for the following operations:
411526

412-
* create a private key using a `SET` statement
527+
* Create a private key using a `SET` statement
413528

414-
* create a private key using a `SELECT` statement
529+
* Create a private key using a `SELECT` statement
415530

416-
* create a private key using an `INSERT` statement
531+
* Create a private key using an `INSERT` statement
417532

418533
```{.bash data-prompt="mysql>"}
419534
mysql> SET @private_key1 = create_asymmetric_priv_key('RSA', 3072);

0 commit comments

Comments
 (0)