Skip to content

Commit 31a53d8

Browse files
committed
PS-9139 Document new PS Encryption UDFs functionality - 8.0
modified: docs/encryption-functions.md
1 parent 6abbdae commit 31a53d8

File tree

1 file changed

+95
-4
lines changed

1 file changed

+95
-4
lines changed

docs/encryption-functions.md

+95-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
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+
The `pkcs1` padding 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 `oeap` (Optimal Asymmetric Encryption Padding) padding 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 PSS` padding for RSA sign and verify operations
27+
28+
<details>
29+
<summary> `PKCS1 PSS` padding explanation</summary>
30+
PKCS PSS (Probabilistic Signature Scheme) is a cryptographic algorithm 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.
31+
</details>
32+
33+
* [`encryption_udf.legacy_paddding_scheme`](#encryption_udflegacy_paddding_scheme) system variable
34+
35+
* Character set awareness
36+
37+
Percona Server for MySQL 8.0.28-20 adds encryption functions and variables to manage the encryption range.
38+
39+
## Charset Awareness
40+
41+
All component_encryption_udf functions now handle character sets intelligently:
42+
43+
• 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.
44+
45+
• 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.
46+
47+
• Function return values in PEM format: Assigned the ASCII charset.
48+
49+
• Function return values for operations like digest calculation, encryption, decryption, and signing: Assigned the binary charset.
50+
51+
## Use user-defined functions
452

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

@@ -66,6 +114,8 @@ The following are the function’s parameters:
66114

67115
* algorithm - the encryption algorithm supports RSA to decrypt the string.
68116

117+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. It is used with the RSA algorithm and supports 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` variable.
118+
69119
* key_str - a string in the PEM format. The key string must have the following attributes:
70120

71121
* Valid
@@ -100,6 +150,8 @@ The parameters are the following:
100150

101151
* algorithm - the encryption algorithm supports RSA to encrypt the string.
102152

153+
* padding - An optional parameter introduced in Percona Server for MySQL 8.0.41. It is used with the RSA algorithm and supports 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` variable.
154+
103155
* str - measured in bytes. The length of the string must not be greater than the key_str modulus length in bytes - 11 (additional bytes used for PKCS1 padding)
104156

105157
* key_str - a key (either private or public) in the PEM format
@@ -116,7 +168,7 @@ A signature is a binary string.
116168

117169
The parameters are the following:
118170

119-
* algorithm - the encryption algorithm supports either RSA or DSA to encrypt the string.
171+
* algorithm - the encryption algorithm supports either RSA or DSA to encrypt the string.
120172

121173
* digest_str - the digest binary string that is signed. Invoking create_digest generates the digest.
122174

@@ -158,7 +210,7 @@ A `1` (success) or a `0` (failure).
158210

159211
The parameters are the following:
160212

161-
* algorithm - supports either ‘RSA’ or ‘DSA’.
213+
* algorithm - supports either ‘RSA’ or ‘DSA’. Percona Server for MySQL 8.0.40 added support for PKCS1 PSS padding for RSA verify operations.
162214

163215
* digest_str - invoking create_digest generates this digest binary string.
164216

@@ -308,6 +360,45 @@ The variable sets the threshold limits for create_asymmetric_priv_key user-defin
308360

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

363+
### encryption_udf.legacy_paddding_scheme
364+
365+
The variable enables or disables the legacy padding scheme for certain encryption operations.
366+
367+
| Option | Description |
368+
|--------------|------------------|
369+
| command-line | Yes |
370+
| scope | Global |
371+
| data type | Boolean |
372+
| default | OFF |
373+
374+
This system variable is a BOOLEAN type and is set to `OFF` by default.
375+
376+
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.
377+
378+
• When encryption_udf.legacy_padding_scheme is OFF:
379+
380+
• asymmetric_encrypt() and asymmetric_decrypt() use OAEP padding.
381+
382+
• asymmetric_sign() and asymmetric_verify() use PKCS1_PSS padding.
383+
384+
• When encryption_udf.legacy_padding_scheme is ON:
385+
386+
• asymmetric_encrypt() and asymmetric_decrypt() use PKCS1 padding.
387+
388+
• asymmetric_sign() and asymmetric_verify() use PKCS1 padding.
389+
390+
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` value.
391+
392+
The padding schemes have the following limitations:
393+
394+
| Padding Scheme | Details |
395+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
396+
| `oeap` | The message you encrypt can be as long as your RSA key size in bytes - 42 bytes.|
397+
| `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. |
398+
| `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.|
399+
400+
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`. You can only use the padding parameter with RSA algorithms.
401+
311402
### encryption_udf.rsa_bits_threshold
312403

313404
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)