Commit d25fbe4
committed
PG-2278 Re-use cipher contexts for SMGR encryption
Profiling with perf revealed that EVP_CipherInit_ex() showed up quite a
lot when encrypting and decrypting tables, so to decrease how much it
shows up we make sure to only allocate and initialize contexts for SMGR
encryption once on loading pg_tde and then re-use those contexts but
re-initializing them with different keys and IVs on use, which is a lot
cheaper than doing a full initialization. This way of calling
EVP_CipherInit_ex() is poorly documented in OpenSSL.
While at it also remove a useless call to the finalize function which is
not necessary due to the lack of padding. It did not show up in
profiling but it also adds no value and there is precedence for us
skipping it in our AES-CTR code.
WAL encryption already has logic for reusing contexts so this
optimization is not as relevant there.1 parent a2ae945 commit d25fbe4
1 file changed
Lines changed: 25 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
39 | | - | |
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
43 | 59 | | |
44 | 60 | | |
45 | 61 | | |
46 | 62 | | |
47 | 63 | | |
48 | | - | |
49 | 64 | | |
50 | 65 | | |
| 66 | + | |
51 | 67 | | |
52 | | - | |
53 | 68 | | |
54 | 69 | | |
| 70 | + | |
55 | 71 | | |
56 | 72 | | |
57 | 73 | | |
| |||
94 | 110 | | |
95 | 111 | | |
96 | 112 | | |
97 | | - | |
98 | | - | |
| 113 | + | |
99 | 114 | | |
100 | 115 | | |
101 | | - | |
| 116 | + | |
102 | 117 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 118 | + | |
| 119 | + | |
107 | 120 | | |
108 | | - | |
| 121 | + | |
109 | 122 | | |
110 | 123 | | |
111 | 124 | | |
112 | | - | |
113 | | - | |
114 | 125 | | |
115 | 126 | | |
116 | 127 | | |
| |||
125 | 136 | | |
126 | 137 | | |
127 | 138 | | |
128 | | - | |
129 | | - | |
130 | 139 | | |
131 | 140 | | |
132 | 141 | | |
| |||
0 commit comments