Skip to content

Commit a94f1be

Browse files
authored
PS-9139 [DOCS] - document new PS encryption UDFs functionality 8.0 (#461)
modified: docs/encryption-functions.md
1 parent d09a9a9 commit a94f1be

File tree

1 file changed

+108
-2
lines changed

1 file changed

+108
-2
lines changed

docs/encryption-functions.md

+108-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,58 @@
1-
# Encryption functions
1+
# Encryption user-defined functions
22

3-
Percona Server for MySQL 8.0.28-20 adds encryption functions and variables to manage the encryption range. The functions may take an algorithm argument. Encryption converts plaintext into ciphertext using a key and an encryption algorithm.
3+
The encryption user-defined functions (UDF) let you encrypt and decrypt data. You can choose different encryption algorithms and manage the range of data to encrypt.
4+
5+
## Version updates
6+
7+
Percona Server for MySQL 8.0.41 adds the following:
8+
9+
* Support for `pkcs1`, `oaep`, or `no` padding for RSA encrypt and decrypt operations
10+
11+
<details>
12+
<summary> `pkcs1` padding explanation</summary>
13+
`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.
14+
</details>
15+
16+
<details>
17+
<summary> `oeap` padding explanation</summary>
18+
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 weaknesses in the encryption algorithm or to recover the original message.
19+
</details>
20+
21+
<details>
22+
<summary> `no` padding explanation</summary>
23+
Using `no` padding means that the plaintext message is encrypted without adding an extra layer before performing the RSA encryption operation.
24+
</details>
25+
26+
* Support for `pkcs1` or `pkcs1_pss` padding for RSA sign and verify operations
27+
28+
<details>
29+
<summary> `pkcs1` padding explanation</summary>
30+
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.
31+
</details>
32+
<details>
33+
<summary> `pkcs1_pss` padding explanation</summary>
34+
The [`RSASSA-PSS`](https://en.wikipedia.org/wiki/PKCS_1) - [`Probabilistic Signature Scheme'](https://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding) 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 make it more resistant to various attacks.
35+
</details>
36+
37+
* [`encryption_udf.legacy_paddding_scheme`](#encryption_udflegacy_paddding_scheme) system variable
38+
39+
* Character set awareness
40+
41+
Percona Server for MySQL 8.0.28-20 adds encryption functions and variables to manage the encryption range.
42+
43+
## Charset Awareness
44+
45+
All component_encryption_udf functions now handle character sets intelligently:
46+
47+
• 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.
48+
49+
• 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.
50+
51+
• Function return values in PEM format: Assigned the ASCII charset.
52+
53+
• Function return values for operations like digest calculation, encryption, decryption, and signing: Assigned the binary charset.
54+
55+
## Use user-defined functions
456

557
You can also use the user-defined functions with the PEM format keys generated externally by the OpenSSL utility.
658

@@ -71,6 +123,10 @@ The following are the function’s parameters:
71123
* Valid
72124

73125
* Public or private key string that corresponds with the private or public key string used with the asymmetric_encrypt function.
126+
127+
* `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.
128+
129+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. It is used with the RSA algorithm and supports RSA encryption padding schemes like `no`, `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.
74130

75131
## asymmetric_derive(*pub_key_str, priv_key_str*)
76132

@@ -104,6 +160,8 @@ The parameters are the following:
104160

105161
* key_str - a key (either private or public) in the PEM format
106162

163+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. It is used with the RSA algorithm and supports RSA encryption padding schemes like `no`, `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.
164+
107165
## asymmetric_sign(*algorithm, digest_str, priv_key_str, digest_type*)
108166

109167
Signs a digest string using a private key string.
@@ -146,6 +204,9 @@ The parameters are the following:
146204
| | | shake128 | |
147205
| | | shake256 | |
148206

207+
208+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. 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.
209+
149210
## asymmetric_verify(*algorithm, digest_str, sig_str, pub_key_str, digest_type*)
150211

151212
Verifies whether the signature string matches the digest string.
@@ -168,6 +229,8 @@ The parameters are the following:
168229

169230
* digest_type - the supported values are listed in the digest type table of create_digest
170231

232+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. 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.
233+
171234
## create_asymmetric_priv_key(*algorithm, (key_len | dh_parameters)*)
172235

173236
Generates a private key using the given algorithm and key length for RSA or DSA
@@ -308,6 +371,49 @@ The variable sets the threshold limits for create_asymmetric_priv_key user-defin
308371

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

374+
### encryption_udf.legacy_paddding_scheme
375+
376+
The variable enables or disables the legacy padding scheme for certain encryption operations.
377+
378+
| Option | Description |
379+
|--------------|------------------|
380+
| command-line | Yes |
381+
| scope | Global |
382+
| data type | Boolean |
383+
| default | OFF |
384+
385+
This system variable is a BOOLEAN type and is set to `OFF` by default.
386+
387+
This variable controls how the functions `asymmetric_encrypt()`, `asymmetric_decrypt()`, `asymmetric_sign()`, and `asymmetric_verify()` behave when you don’t explicitly set the padding parameter.
388+
389+
• When encryption_udf.legacy_padding_scheme is OFF:
390+
391+
• asymmetric_encrypt() and asymmetric_decrypt() use OAEP encryption padding.
392+
393+
• asymmetric_sign() and asymmetric_verify() use PKCS1_PSS signature padding.
394+
395+
• When encryption_udf.legacy_padding_scheme is ON:
396+
397+
• asymmetric_encrypt() and asymmetric_decrypt() use PKCS1 encryption padding.
398+
399+
• asymmetric_sign() and asymmetric_verify() use PKCS1 signature padding.
400+
401+
The `asymmetric_encrypt()` and `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.
402+
403+
The padding schemes have the following limitations:
404+
405+
| Padding Scheme | Details |
406+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
407+
| `oeap` | The message you encrypt can be as long as your RSA key size in bytes - 42 bytes.|
408+
| `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. |
409+
| `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.|
410+
411+
Similarly, `asymmetric_sign()` and `asymmetric_verify()` also have an optional `padding` parameter, which can be 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.
412+
413+
#### Additional resources
414+
415+
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/)
416+
311417
### encryption_udf.rsa_bits_threshold
312418

313419
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.

0 commit comments

Comments
 (0)