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
+149-29
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,68 @@ When choosing key lengths, consider the following:
12
12
13
13
* 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.
14
14
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.
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_padding) 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
+
15
77
The following table and sections describe the functions. For examples, see function examples.
16
78
17
79
| Function Name |
@@ -21,24 +83,28 @@ The following table and sections describe the functions. For examples, see funct
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.
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 ...`.
40
106
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.
42
108
43
109
The following is an example of the installation command:
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.
52
118
53
119
## User-defined functions described
54
120
@@ -64,13 +130,17 @@ A plaintext as a string.
64
130
65
131
The following are the function’s parameters:
66
132
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.
68
136
69
137
* key_str - a string in the PEM format. The key string must have the following attributes:
70
138
71
139
* Valid
72
140
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_encryptalgorithm-str-key_str) 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`](#encryption_udflegacy_padding) variable.
74
144
75
145
## asymmetric_derive(*pub_key_str, priv_key_str*)
76
146
@@ -104,6 +174,8 @@ The parameters are the following:
104
174
105
175
* key_str - a key (either private or public) in the PEM format
106
176
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`](#encryption_udflegacy_padding) variable.
@@ -116,7 +188,7 @@ A signature is a binary string.
116
188
117
189
The parameters are the following:
118
190
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.
120
192
121
193
* digest_str - the digest binary string that is signed. Invoking create_digest generates the digest.
122
194
@@ -146,10 +218,13 @@ The parameters are the following:
146
218
||| shake128 ||
147
219
||| shake256 ||
148
220
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`](#encryption_udflegacy_padding) variable.
Verifies whether the signature string matches the digest string.
152
226
227
+
153
228
### asymmetric_verify output
154
229
155
230
A `1` (success) or a `0` (failure).
@@ -168,6 +243,8 @@ The parameters are the following:
168
243
169
244
* digest_type - the supported values are listed in the digest type table of create_digest
170
245
246
+
* 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`](#encryption_udflegacy_padding) variable.
Generates a private key using the given algorithm and key length for RSA or DSA
@@ -221,12 +298,11 @@ If needed, execute `KILL [QUERY|CONNECTION] <id>` to terminate the generation of
221
298
222
299
Generating the DH parameters can take more time than generating the RSA keys or
223
300
the DSA keys.
224
-
OpenSSL defines the parameter length limits. To change the
225
-
maximum parameter length, use encryption_udf.dh_bits_threshold.
301
+
OpenSSL defines the parameter length limits. To change the maximum parameter length, use [`encryption_udf.dh_bits_threshold`](#encryption_udfdh_bits_threshold).
226
302
227
303
### create_dh_parameters output
228
304
229
-
A string in the PEM format and can be passed to create_asymmetric_private_key.
305
+
A string in the PEM format and can be passed to [`create_asymmetric_priv_key`](#create_asymmetric_priv_keyalgorithm-key_len-dh_parameters).
230
306
231
307
### create_dh_parameters parameters
232
308
@@ -236,7 +312,7 @@ The parameters are the following:
236
312
237
313
## create_digest(*digest_type, str*)
238
314
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.
315
+
Creates a digest from the given string using the given digest type. The digest string can be used with [`asymmetric_sign`](#asymmetric_signalgorithm-digest_str-priv_key_str-digest_type) and [`asymmetric_verify`](#asymmetric_verifyalgorithm-digest_str-sig_str-pub_key_str-digest_type).
240
316
241
317
### create_digest output
242
318
@@ -284,7 +360,7 @@ The variables are automatically registered when component_encryption_udf is inst
284
360
285
361
### `encryption_udf.dh_bits_threshold`
286
362
287
-
The variable sets the maximum limit for the create_dh_parameters user-defined function and takes precedence over the OpenSSL maximum length value.
363
+
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.
288
364
289
365
| Option | Description |
290
366
|--------------|------------------|
@@ -297,7 +373,7 @@ The range for this variable is from 1024 to 10,000. The default value is 10,000.
297
373
298
374
### encryption_udf.dsa_bits_threshold
299
375
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.
376
+
The variable sets the threshold limits for [`create_asymmetric_priv_key`](#create_asymmetric_priv_keyalgorithm-key_len-dh_parameters) user-defined function when the function is invoked with the DSA parameter and takes precedence over the OpenSSL maximum length value.
301
377
302
378
| Option | Description |
303
379
|--------------|------------------|
@@ -308,9 +384,53 @@ The variable sets the threshold limits for create_asymmetric_priv_key user-defin
308
384
309
385
The range for this variable is from 1,024 to 9,984. The default value is 9,984.
310
386
387
+
### encryption_udf.legacy_padding
388
+
389
+
The variable enables or disables the legacy padding scheme for certain encryption operations.
390
+
391
+
| Option | Description |
392
+
|--------------|------------------|
393
+
| command-line | Yes |
394
+
| scope | Global |
395
+
| data type | Boolean |
396
+
| default | OFF |
397
+
398
+
This system variable is a BOOLEAN type and set to `OFF` by default.
399
+
400
+
This variable controls how the functions [`asymmetric_encrypt()`](#asymmetric_encrypt), [`asymmetric_decrypt()`](#asymmetric_decrypt), [`asymmetric_sign()`](#asymmetric_signalgorithm-digest_str-priv_key_str-digest_type), and [`asymmetric_verify()`](#asymmetric_verifyalgorithm-digest_str-sig_str-pub_key_str-digest_type) behave when you don’t explicitly set the padding parameter.
401
+
402
+
• When encryption_udf.legacy_padding is OFF:
403
+
404
+
• [asymmetric_encrypt()](#asymmetric_encrypt) and [asymmetric_decrypt()](#asymmetric_decrypt) use OAEP encryption padding.
405
+
406
+
• [asymmetric_sign()](#asymmetric_sign) and [asymmetric_verify()](#asymmetric_verify) use PKCS1_PSS signature padding.
407
+
408
+
• When encryption_udf.legacy_padding is ON:
409
+
410
+
• [`asymmetric_encrypt()`](#asymmetric_encrypt) and [`asymmetric_decrypt()`](#asymmetric_decrypt) use PKCS1 encryption padding.
411
+
412
+
• [`asymmetric_sign()`](#asymmetric_signalgorithm-digest_str-priv_key_str-digest_type) and [`asymmetric_verify()`](#asymmetric_verifyalgorithm-digest_str-sig_str-pub_key_str-digest_type) use PKCS1 signature padding.
413
+
414
+
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`](#encryption_udflegacy_padding) value.
415
+
416
+
The padding schemes have the following limitations:
|`oaep`| The message you encrypt can be as long as your RSA key size in bytes - 42 bytes.|
421
+
|`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. |
422
+
|`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.|
423
+
424
+
Similarly, [`asymmetric_sign()`](#asymmetric_signalgorithm-digest_str-priv_key_str-digest_type) and [`asymmetric_verify()`](#asymmetric_verifyalgorithm-digest_str-sig_str-pub_key_str-digest_type) 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`](#encryption_udflegacy_padding). You can only use the padding parameter with RSA algorithms.
425
+
426
+
#### Additional resources
427
+
428
+
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/)
429
+
430
+
311
431
### encryption_udf.rsa_bits_threshold
312
432
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.
433
+
The variable sets the threshold limits for the [`create_asymmetric_priv_key`](#create_asymmetric_priv_keyalgorithm-key_len-dh_parameters) user-defined function when the function is invoked with the RSA parameter and takes precedence over the OpenSSL maximum length value.
314
434
315
435
| Option | Description |
316
436
|--------------|------------------|
@@ -325,15 +445,15 @@ The range for this variable is from 1,024 to 16,384. The default value is 16,384
0 commit comments