Skip to content

engineccl: Add data-driven test for ctr_stream #115365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023

Conversation

bdarnell
Copy link
Contributor

The previous tests verified that encryption was reversible, but there was no verification of the expected results and so there was no guarantee that changes to the implementation remained compatible with data previously written to disk. The new test captures the current results as the baseline.

Release note: None
Epic: None

@bdarnell bdarnell requested a review from a team as a code owner November 30, 2023 20:43
@bdarnell bdarnell requested a review from itsbilal November 30, 2023 20:43
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@bdarnell bdarnell force-pushed the ctr_stream_datadriven_test branch from df289ca to ac5afe7 Compare December 1, 2023 15:25
@bdarnell bdarnell requested a review from a team December 1, 2023 15:25
@bdarnell bdarnell requested review from a team as code owners December 1, 2023 15:25
@bdarnell bdarnell force-pushed the ctr_stream_datadriven_test branch from ac5afe7 to 9b1acff Compare December 1, 2023 15:26
@bdarnell bdarnell removed request for a team December 1, 2023 15:31
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @bdarnell and @itsbilal)


pkg/ccl/storageccl/engineccl/testdata/ctr_stream line 9 at r1 (raw file):

# inputs, you can use something like
#   head -c 16 /dev/random | od -An -tx1 -v
# (note that macOS `od` uses more whitespacae than linux `od`, so this file uses the linux `od` format).

[nit] whitespace, also line wrapping (typically at 80 in comments)


pkg/ccl/storageccl/engineccl/testdata/ctr_stream line 130 at r1 (raw file):


# When the 32-bit counter wraps around we see the same data again,
# but the files what this code is used for cannot get that large.

[nit] "but this code is used for encrypting files that cannot get that large"

The previous tests verified that encryption was reversible, but there
was no verification of the expected results and so there was no
guarantee that changes to the implementation remained compatible with
data previously written to disk. The new test captures the current
results as the baseline.

Release note: None
Epic: None
@bdarnell bdarnell force-pushed the ctr_stream_datadriven_test branch from 9b1acff to d513bd1 Compare December 4, 2023 20:52
@bdarnell
Copy link
Contributor Author

bdarnell commented Dec 5, 2023

bors r=RaduBerinde

@craig
Copy link
Contributor

craig bot commented Dec 5, 2023

Build succeeded:

@craig craig bot merged commit 9d70b9f into cockroachdb:master Dec 5, 2023
@bdarnell bdarnell deleted the ctr_stream_datadriven_test branch December 5, 2023 16:14
craig bot pushed a commit that referenced this pull request Jan 29, 2024
115549: engineccl: Reimplement FileCipherStreamV2 r=bdarnell a=bdarnell

First commit is from #115365. #115454 is related and makes v1 look a little better in the benchmarks. 

The new implementation, fileCipherStreamV2, is currently only hooked up
in tests and benchmarks. It's not used in production until we decide on
a feature flagging strategy.

The major change is to defer more to the standard library, and
specifically to pass larger batches to the stdlib at once. Previously we
made a separate call to the crypto library for every 16-byte block; now
we pass the entire buffer at once. The downside is random access is more
expensive. The previous implementation was basically constant-time,
while the new one performs multiple heap allocations for every "seek".

To summarize the performance results below, v2 is significantly slower
than v1 for tiny (16 byte) non-sequential operations. It is about the
same performance for small sequential operations, and substantially
faster for large sequential operations (about twice as fast as the
original version).

The FIPS version is now even faster (for large sequential writes) than
non-FIPS. This is because Go's implementation of CTR mode has not been
as extensively optimized as openssl's. There are open PRs that may
improve this in the future, such as golang/go#53503

```
goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) CPU @ 2.80GHz
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=false/block=16/-24                 7521            137392 ns/op         238.50 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=false/block=256/-24               15793             75349 ns/op         434.88 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=false/block=1024/-24              16778             71159 ns/op         460.49 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=false/block=16384/-24             17083             69697 ns/op         470.15 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=true/block=16/-24                  7797            137415 ns/op         238.46 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=true/block=256/-24                15794             75635 ns/op         433.24 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=true/block=1024/-24               16785             71195 ns/op         460.26 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=128/seq=true/block=16384/-24              17169             69813 ns/op         469.37 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=false/block=16/-24                 7510            142334 ns/op         230.22 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=false/block=256/-24               14797             81525 ns/op         401.94 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=false/block=1024/-24              15715             76005 ns/op         431.13 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=false/block=16384/-24             15985             74794 ns/op         438.11 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=true/block=16/-24                  7558            142334 ns/op         230.22 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=true/block=256/-24                14826             80456 ns/op         407.28 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=true/block=1024/-24               15757             76231 ns/op         429.85 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=192/seq=true/block=16384/-24              16063             74763 ns/op         438.29 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=false/block=16/-24                 7304            146606 ns/op         223.51 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=false/block=256/-24               13947             85653 ns/op         382.57 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=false/block=1024/-24              14589             81277 ns/op         403.16 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=false/block=16384/-24             14989             80079 ns/op         409.19 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=true/block=16/-24                  7274            145928 ns/op         224.55 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=true/block=256/-24                13935             85680 ns/op         382.45 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=true/block=1024/-24               14690             81366 ns/op         402.73 MB/s
BenchmarkFileCipherStream/fips=false/impl=v1/key=256/seq=true/block=16384/-24              15002             80120 ns/op         408.99 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=false/block=16/-24                  615           1896677 ns/op          17.28 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=false/block=256/-24                9006            119509 ns/op         274.19 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=false/block=1024/-24              23329             51281 ns/op         638.99 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=false/block=16384/-24             29162             40910 ns/op         800.97 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=true/block=16/-24                  8750            132576 ns/op         247.16 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=true/block=256/-24                26404             45361 ns/op         722.39 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=true/block=1024/-24               28626             41808 ns/op         783.78 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=128/seq=true/block=16384/-24              29336             40935 ns/op         800.48 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=false/block=16/-24                  574           2042367 ns/op          16.04 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=false/block=256/-24                8706            129528 ns/op         252.98 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=false/block=1024/-24              21183             56446 ns/op         580.52 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=false/block=16384/-24             26109             45655 ns/op         717.73 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=true/block=16/-24                  8504            137355 ns/op         238.56 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=true/block=256/-24                23960             50296 ns/op         651.50 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=true/block=1024/-24               25696             46679 ns/op         701.99 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=192/seq=true/block=16384/-24              26198             45587 ns/op         718.80 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=false/block=16/-24                  531           2206987 ns/op          14.85 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=false/block=256/-24                7694            139498 ns/op         234.90 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=false/block=1024/-24              19524             61046 ns/op         536.77 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=false/block=16384/-24             23745             50562 ns/op         648.07 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=true/block=16/-24                  8245            148016 ns/op         221.38 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=true/block=256/-24                21739             55280 ns/op         592.76 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=true/block=1024/-24               23212             51531 ns/op         635.89 MB/s
BenchmarkFileCipherStream/fips=false/impl=v2/key=256/seq=true/block=16384/-24              23805             50438 ns/op         649.66 MB/s
PASS
goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) CPU @ 2.80GHz
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=false/block=16/-24                  2050            569817 ns/op          57.51 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=false/block=256/-24                 2499            490116 ns/op          66.86 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=false/block=1024/-24                2473            478146 ns/op          68.53 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=false/block=16384/-24               2518            477786 ns/op          68.58 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=true/block=16/-24                   2067            566694 ns/op          57.82 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=true/block=256/-24                  2448            488315 ns/op          67.10 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=true/block=1024/-24                 2490            479422 ns/op          68.35 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=128/seq=true/block=16384/-24                2514            481941 ns/op          67.99 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=false/block=16/-24                  2008            568220 ns/op          57.67 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=false/block=256/-24                 2407            493184 ns/op          66.44 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=false/block=1024/-24                2428            480403 ns/op          68.21 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=false/block=16384/-24               2421            482593 ns/op          67.90 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=true/block=16/-24                   2040            573229 ns/op          57.16 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=true/block=256/-24                  2314            496560 ns/op          65.99 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=true/block=1024/-24                 2478            476019 ns/op          68.84 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=192/seq=true/block=16384/-24                2449            483360 ns/op          67.79 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=false/block=16/-24                  1998            574193 ns/op          57.07 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=false/block=256/-24                 2356            488059 ns/op          67.14 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=false/block=1024/-24                2454            482139 ns/op          67.96 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=false/block=16384/-24               2446            483249 ns/op          67.81 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=true/block=16/-24                   2020            565348 ns/op          57.96 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=true/block=256/-24                  2388            488736 ns/op          67.05 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=true/block=1024/-24                 2418            492126 ns/op          66.58 MB/s
BenchmarkFileCipherStream/fips=true/impl=v1/key=256/seq=true/block=16384/-24                2443            480180 ns/op          68.24 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=false/block=16/-24                   259           4733741 ns/op           6.92 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=false/block=256/-24                 3481            297358 ns/op         110.20 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=false/block=1024/-24               14671             82314 ns/op         398.08 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=false/block=16384/-24             135296              9077 ns/op        3609.94 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=true/block=16/-24                   2421            452063 ns/op          72.49 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=true/block=256/-24                 33729             36362 ns/op         901.15 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=true/block=1024/-24                81376             15570 ns/op        2104.61 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=128/seq=true/block=16384/-24              139063              8704 ns/op        3764.70 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=false/block=16/-24                   244           5070212 ns/op           6.46 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=false/block=256/-24                 3350            313168 ns/op         104.63 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=false/block=1024/-24               14427             85797 ns/op         381.93 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=false/block=16384/-24             114337             10014 ns/op        3272.32 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=true/block=16/-24                   2611            452229 ns/op          72.46 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=true/block=256/-24                 32545             37458 ns/op         874.79 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=true/block=1024/-24                72807             16660 ns/op        1966.85 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=192/seq=true/block=16384/-24              116131              9992 ns/op        3279.30 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=false/block=16/-24                   247           4896561 ns/op           6.69 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=false/block=256/-24                 3409            336213 ns/op          97.46 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=false/block=1024/-24               13916             86875 ns/op         377.18 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=false/block=16384/-24             101763             11161 ns/op        2936.06 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=true/block=16/-24                   2326            452598 ns/op          72.40 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=true/block=256/-24                 30164             37851 ns/op         865.70 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=true/block=1024/-24                68094             17592 ns/op        1862.67 MB/s
BenchmarkFileCipherStream/fips=true/impl=v2/key=256/seq=true/block=16384/-24              104826             11190 ns/op        2928.36 MB/s
```

Co-authored-by: Ben Darnell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants