Skip to content

Commit c0b69df

Browse files
Optimize SSL/X509 state machines for size
The state machine implementations are the largest bits of the SSL engine, but they're also not performance sensitive like the encryption code. Optimize the FSMs for size, leaving everything else as -O2.
1 parent 28bebad commit c0b69df

12 files changed

+35
-1
lines changed

src/ssl/ssl_hs_client.c

+3
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ make_client_sign(br_ssl_client_context *ctx)
395395
ctx->eng.pad, sizeof ctx->eng.pad);
396396
}
397397

398+
/* State machine should be squeezed for size, not performance critical */
399+
#pragma GCC optimize ("Os")
400+
398401

399402

400403
static const unsigned char t0_datablock[] PROGMEM = {

src/ssl/ssl_hs_client.t0

+3
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ make_client_sign(br_ssl_client_context *ctx)
339339
ctx->eng.pad, sizeof ctx->eng.pad);
340340
}
341341

342+
/* State machine should be squeezed for size, not performance critical */
343+
#pragma GCC optimize ("Os")
344+
342345
}
343346

344347
\ =======================================================================

src/ssl/ssl_hs_server.c

+3
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ verify_CV_sig(br_ssl_server_context *ctx, size_t sig_len)
426426
return 0;
427427
}
428428

429+
/* State machine should be squeezed for size, not performance critical */
430+
#pragma GCC optimize ("Os")
431+
429432

430433

431434
static const unsigned char t0_datablock[] PROGMEM = {

src/ssl/ssl_hs_server.t0

+3
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ verify_CV_sig(br_ssl_server_context *ctx, size_t sig_len)
370370
return 0;
371371
}
372372

373+
/* State machine should be squeezed for size, not performance critical */
374+
#pragma GCC optimize ("Os")
375+
373376
}
374377

375378
\ =======================================================================

src/x509/pkey_decoder.c

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ br_pkey_decoder_push(br_pkey_decoder_context *ctx,
100100
br_pkey_decoder_run(&ctx->cpu);
101101
}
102102

103+
/* State machine should be squeezed for size, not performance critical */
104+
#pragma GCC optimize ("Os")
105+
103106

104107

105108
static const unsigned char t0_datablock[] PROGMEM = {

src/x509/pkey_decoder.t0

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ br_pkey_decoder_push(br_pkey_decoder_context *ctx,
4848
br_pkey_decoder_run(&ctx->cpu);
4949
}
5050

51+
/* State machine should be squeezed for size, not performance critical */
52+
#pragma GCC optimize ("Os")
53+
5154
}
5255

5356
addr: key_type

src/x509/skey_decoder.c

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ br_skey_decoder_push(br_skey_decoder_context *ctx,
100100
br_skey_decoder_run(&ctx->cpu);
101101
}
102102

103+
/* State machine should be squeezed for size, not performance critical */
104+
#pragma GCC optimize ("Os")
105+
103106

104107

105108
static const unsigned char t0_datablock[] PROGMEM = {

src/x509/skey_decoder.t0

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ br_skey_decoder_push(br_skey_decoder_context *ctx,
4848
br_skey_decoder_run(&ctx->cpu);
4949
}
5050

51+
/* State machine should be squeezed for size, not performance critical */
52+
#pragma GCC optimize ("Os")
53+
5154
}
5255

5356
addr: key_type

src/x509/x509_decoder.c

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ br_x509_decoder_push(br_x509_decoder_context *ctx,
113113
br_x509_decoder_run(&ctx->cpu);
114114
}
115115

116+
/* State machine should be squeezed for size, not performance critical */
117+
#pragma GCC optimize ("Os")
118+
116119

117120

118121
static const unsigned char t0_datablock[] PROGMEM = {

src/x509/x509_decoder.t0

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ br_x509_decoder_push(br_x509_decoder_context *ctx,
6161
br_x509_decoder_run(&ctx->cpu);
6262
}
6363

64+
/* State machine should be squeezed for size, not performance critical */
65+
#pragma GCC optimize ("Os")
66+
6467
}
6568

6669
addr: decoded

src/x509/x509_minimal.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ void br_x509_minimal_run(void *t0ctx);
158158
* -- Extensions: extension values are processed in due order.
159159
*
160160
* -- Basic Constraints: for all certificates except EE, must be
161-
* present, indicate a CA, and have a path legnth compatible with
161+
* present, indicate a CA, and have a path length compatible with
162162
* the chain length so far.
163163
*
164164
* -- Key Usage: for the EE, if present, must allow signatures
@@ -489,6 +489,8 @@ static int check_single_trust_anchor_CA(br_x509_minimal_context *ctx,
489489
return 0;
490490
}
491491

492+
/* State machine should be squeezed for size, not performance critical */
493+
#pragma GCC optimize ("Os")
492494

493495

494496

src/x509/x509_minimal.t0

+2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ static int check_single_trust_anchor_CA(br_x509_minimal_context *ctx,
437437
return 0;
438438
}
439439

440+
/* State machine should be squeezed for size, not performance critical */
441+
#pragma GCC optimize ("Os")
440442

441443
}
442444

0 commit comments

Comments
 (0)