You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/encryption-functions.md
+87-4
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,46 @@
1
-
# Encryption functions
1
+
# Encryption user-defined functions
2
2
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` or `oaep` 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
+
15
+
The `oeap` (Optimal Asymmetric Encryption Padding) padding is designed for encryption and adds 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.
16
+
</details>
17
+
18
+
* Support for `PKCS1 PSS` padding for RSA sign and verify operations
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.
23
+
</details>
24
+
25
+
*[`encryption_udf.legacy_paddding_scheme`](#encryption_udflegacy_paddding_scheme) system variable
26
+
27
+
* Character set awareness
28
+
29
+
Percona Server for MySQL 8.0.28-20 adds encryption functions and variables to manage the encryption range.
30
+
31
+
## Charset Awareness
32
+
33
+
All component_encryption_udf functions now handle character sets intelligently:
34
+
35
+
• 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.
36
+
37
+
• 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.
38
+
39
+
• Function return values in PEM format: Assigned the ASCII charset.
40
+
41
+
• Function return values for operations like digest calculation, encryption, decryption, and signing: Assigned the binary charset.
42
+
43
+
## Use user-defined functions
4
44
5
45
You can also use the user-defined functions with the PEM format keys generated externally by the OpenSSL utility.
6
46
@@ -66,6 +106,8 @@ The following are the function’s parameters:
66
106
67
107
* algorithm - the encryption algorithm supports RSA to decrypt the string.
68
108
109
+
* 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.
110
+
69
111
* key_str - a string in the PEM format. The key string must have the following attributes:
70
112
71
113
* Valid
@@ -100,6 +142,8 @@ The parameters are the following:
100
142
101
143
* algorithm - the encryption algorithm supports RSA to encrypt the string.
102
144
145
+
* 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.
146
+
103
147
* 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)
104
148
105
149
* key_str - a key (either private or public) in the PEM format
@@ -116,7 +160,7 @@ A signature is a binary string.
116
160
117
161
The parameters are the following:
118
162
119
-
* algorithm - the encryption algorithm supports either RSA or DSA to encrypt the string.
163
+
* algorithm - the encryption algorithm supports either RSA or DSA to encrypt the string.
120
164
121
165
* digest_str - the digest binary string that is signed. Invoking create_digest generates the digest.
122
166
@@ -158,7 +202,7 @@ A `1` (success) or a `0` (failure).
158
202
159
203
The parameters are the following:
160
204
161
-
* algorithm - supports either ‘RSA’ or ‘DSA’.
205
+
* algorithm - supports either ‘RSA’ or ‘DSA’. Percona Server for MySQL 8.0.40 added support for PKCS1 PSS padding for RSA verify operations.
162
206
163
207
* digest_str - invoking create_digest generates this digest binary string.
164
208
@@ -308,6 +352,45 @@ The variable sets the threshold limits for create_asymmetric_priv_key user-defin
308
352
309
353
The range for this variable is from 1,024 to 9,984. The default value is 9,984.
310
354
355
+
### encryption_udf.legacy_paddding_scheme
356
+
357
+
The variable enables or disables the legacy padding scheme for certain encryption operations.
358
+
359
+
| Option | Description |
360
+
|--------------|------------------|
361
+
| command-line | Yes |
362
+
| scope | Global |
363
+
| data type | Boolean |
364
+
| default | OFF |
365
+
366
+
This system variable is a BOOLEAN type and is set to `OFF` by default.
367
+
368
+
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.
369
+
370
+
• When encryption_udf.legacy_padding_scheme is OFF:
371
+
372
+
• asymmetric_encrypt() and asymmetric_decrypt() use OAEP padding.
373
+
374
+
• asymmetric_sign() and asymmetric_verify() use PKCS1_PSS padding.
375
+
376
+
• When encryption_udf.legacy_padding_scheme is ON:
377
+
378
+
• asymmetric_encrypt() and asymmetric_decrypt() use PKCS1 padding.
379
+
380
+
• asymmetric_sign() and asymmetric_verify() use PKCS1 padding.
381
+
382
+
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.
383
+
384
+
The padding schemes have the following limitations:
|`oeap`| The message you encrypt can be as long as your RSA key size in bytes - 42 bytes.|
389
+
|`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. |
390
+
|`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.|
391
+
392
+
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.
393
+
311
394
### encryption_udf.rsa_bits_threshold
312
395
313
396
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