Skip to content
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

Optimize tlsv1.3 #9305

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dgud
Copy link
Contributor

@dgud dgud commented Jan 15, 2025

Some optimizations for tls.

dgud added 2 commits January 15, 2025 15:52
And remove the installation of src header files previously used,
I do this to avoid installing src headers in tests which can mess up
things during development and local testing.

Also remove some logging.
Some minor optimizations
@dgud dgud self-assigned this Jan 15, 2025
@dgud dgud requested review from IngelaAndin and u3s January 15, 2025 14:54
@dgud dgud added the team:PS Assigned to OTP team PS label Jan 15, 2025
Copy link
Contributor

github-actions bot commented Jan 15, 2025

CT Test Results

  1 files   11 suites   4m 7s ⏱️
 93 tests  91 ✅ 2 💤 0 ❌
109 runs  107 ✅ 2 💤 0 ❌

Results for commit 20612c9.

♻️ This comment has been updated with latest results.

To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass.

See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally.

Artifacts

// Erlang/OTP Github Action Bot

@dgud dgud added the testing currently being tested, tag is used by OTP internal CI label Jan 15, 2025
dgud added 2 commits January 16, 2025 09:58
Avoid several external calls for every data package.

Remove debug code for application data, i.e. fast path.
@dgud dgud force-pushed the dgud/ssl/optimize-tlsv1.3/OTP-19430 branch from 77457a5 to 20612c9 Compare January 16, 2025 08:58
@@ -47,7 +47,7 @@ setup(Name) ->
PeerOptions =
#{name => NameStr,
host => Host},
?CT_LOG("PeerOptions: ~p~n", [PeerOptions]),
%% io:format("PeerOptions: ~p~n", [PeerOptions]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we doing io:format here in this commented code?
I think we should be consistent through the file. Question is if we should keep it at all? Although it bothers me less in test code, I think in the normal case we do not want commented out code.

Copy link
Contributor

@u3s u3s Jan 20, 2025

Choose a reason for hiding this comment

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

I also dislike commented out code.

However, I like when a module has a DEBUG flag or macro that could be enabled if needed.
Maybe it would be better and easy to do than leaving commented out lines here and there?
Maybe CT_LOG should have a variant working conditionally? or maybe have ?DBG wrapping macro

?DBG(?CT_LOG()) so argument macro is only included when debug is true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a mistake and should not be included, when running measurements 1000 times you don't want to bother
with starting common tests and look at webpages.

@@ -363,6 +363,8 @@ wait_eoed(Type, Msg, State) ->
term(), #state{}) ->
gen_statem:state_function_result().
%%--------------------------------------------------------------------
connection(info, Msg, State) ->
tls_gen_connection:handle_info(Msg, connection, State);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as for client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To avoid those 2 function calls?

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I see.

Copy link
Contributor

Choose a reason for hiding this comment

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

But maybe it should be gen_info that is called, lets continue this when we see how #9273 turns out. To ensure that error handling is done correctly.

@@ -568,7 +568,6 @@ validate_tls_record_length(Versions, {_,Size0,_} = Q0, MaxFragLen,
%% Complete record
{Fragment, Q} = binary_from_front(Length, Q0),
Record = #ssl_tls{type = Type, version = Version, fragment = Fragment},
ssl_logger:debug(get(log_level), inbound, 'record', Record),
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to do this during handshaking, or we will loose OpenSSL debug logging compatibility?!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keep this but Comment out the code and comment why it is outcommented.

@@ -47,7 +47,7 @@ setup(Name) ->
PeerOptions =
#{name => NameStr,
host => Host},
?CT_LOG("PeerOptions: ~p~n", [PeerOptions]),
%% io:format("PeerOptions: ~p~n", [PeerOptions]),
Copy link
Contributor

@u3s u3s Jan 20, 2025

Choose a reason for hiding this comment

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

I also dislike commented out code.

However, I like when a module has a DEBUG flag or macro that could be enabled if needed.
Maybe it would be better and easy to do than leaving commented out lines here and there?
Maybe CT_LOG should have a variant working conditionally? or maybe have ?DBG wrapping macro

?DBG(?CT_LOG()) so argument macro is only included when debug is true?

ConnState = ConnState0#{security_parameters => SecParams,
cipher_state => CipherState,
sequence_number => 0},
ConnStateOld = maps:remove(aead_handle, ConnStateOld0),
Copy link
Contributor

Choose a reason for hiding this comment

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

why using Old suffix when you have indexed variables used already?

{Content, CipherTag} =
ssl_cipher:aead_encrypt(BulkCipherAlgo, Key, Nonce, Fragment, AAD, TagLen),
<<Content/binary, CipherTag/binary>>.
%% crypto:exor(<<0:(bit_size(IV)-64),?UINT64(Seq)>>, IV).
Copy link
Contributor

@u3s u3s Jan 20, 2025

Choose a reason for hiding this comment

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

why crypto call is commented above and replaced with hard code below?

are such low level operations wanted in ssl code? looks like crypto code?
if needed here, maybe explain reason in code comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not do it in erlang?
It is faster (if jit is running).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prefer doing things in erlang. This is no cryptographic algorithm. Actually Dan touched it last.

dc9ec91 (Péter Dimitrov 2019-01-08 13:36:53 +0100 294) %% per-record nonce.
dc9ec91 (Péter Dimitrov 2019-01-08 13:36:53 +0100 295) nonce(Seq, IV) ->
293db3c (Dan Gudmundsson 2024-01-17 09:22:03 +0100 296) crypto:exor(<<0:(bit_size(IV)-64),?UINT64(Seq)>>,

lib/ssl/src/tls_record_1_3.erl Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team:PS Assigned to OTP team PS testing currently being tested, tag is used by OTP internal CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants