aboutsummaryrefslogtreecommitdiff
path: root/networking/tls.c
AgeCommit message (Collapse)Author
2019-07-02libbb: reduce the overhead of single parameter bb_error_msg() callsJames Byrne
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-05-21*: slap on a few ALIGN1/2s where appropriateDenys Vlasenko
The result of looking at "grep -F -B2 '*fill*' busybox_unstripped.map" text data bss dec hex filename 952537 485 7296 960318 ea73e busybox_old 952527 485 7296 960308 ea734 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2019-01-08tls: add comment about dl.fedoraproject.org needing secp256r1 ECC curveDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-10tls: prepare for ECDH_anon ciphersDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-10tls: fix a potential (currently "disabled" by a macro) SHA1-related bugDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-10tls: if !ENABLE_FEATURE_TLS_SHA1, tls->MAC_size is always SHA256_OUTSIZE for ↵Denys Vlasenko
AES-CBC function old new delta tls_xread_record 634 636 +2 xwrite_encrypted 579 580 +1 tls_handshake 2095 2085 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/1 up/down: 3/-10) Total: -7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-12-10tls: introduce FEATURE_TLS_SHA1 to make SHA1 code optionalDenys Vlasenko
When disabled: function old new delta xwrite_encrypted 580 579 -1 prf_hmac_sha256 222 217 -5 hmac_begin 158 149 -9 static.ciphers 32 20 -12 tls_handshake 2115 2095 -20 hmac 87 61 -26 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/6 up/down: 0/-73) Total: -73 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-27tls: add ECDHE_PSK and remove ARIA cipher idsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: add _anon_ cipher definitionsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: enable TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 cipherDenys Vlasenko
function old new delta static.ciphers 30 32 +2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: cipher 009D is not yet supported, don't test for itDenys Vlasenko
function old new delta tls_handshake 2116 2108 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: speed up prf_hmac_sha256()Denys Vlasenko
function old new delta hmac_sha_precomputed - 58 +58 prf_hmac_sha256 181 222 +41 hmac_sha256 68 - -68 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/0 up/down: 99/-68) Total: 31 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: simplify hmac_begin()Denys Vlasenko
function old new delta hmac_begin 196 158 -38 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-26tls: add support for 8 more cipher ids - all tested to workDenys Vlasenko
function old new delta tls_handshake 2059 2116 +57 static.ciphers - 30 +30 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 1/0 up/down: 87/0) Total: 87 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: fix commentsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: add a comment on expanding list of supported ciphersDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: do not leak RSA keyDenys Vlasenko
function old new delta tls_handshake 1957 2059 +102 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: code shrinkDenys Vlasenko
function old new delta xwrite_and_update_handshake_hash 81 80 -1 tls_handshake 1987 1957 -30 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: code shrinkDenys Vlasenko
function old new delta tls_handshake 1993 1987 -6 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: code shrinkDenys Vlasenko
function old new delta aesgcm_GHASH 223 196 -27 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-25tls: actually fill in CIPHER_ID3 value in hello messageDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-24tls: fix is.gd again, fix AES-CBC using decrypt key instead of encryptDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-24tls: speed up xor'ing of aligned 16-byte buffersDenys Vlasenko
function old new delta xorbuf_aligned_AES_BLOCK_SIZE - 23 +23 xwrite_encrypted 585 580 -5 aesgcm_GHASH 233 228 -5 GMULT 192 187 -5 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/3 up/down: 23/-15) Total: 8 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-24tls: in AES-GCM decoding, avoid memmoveDenys Vlasenko
function old new delta xorbuf3 - 36 +36 xorbuf 24 12 -12 tls_xread_record 656 634 -22 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 36/-34) Total: 2 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23tls: make tls_get_random() FAST_FUNCDenys Vlasenko
function old new delta tls_handshake 1977 1985 +8 tls_get_random 32 28 -4 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 8/-4) Total: 4 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23tls: code shrinkDenys Vlasenko
function old new delta xwrite_encrypted 599 585 -14 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23tls: simplify aesgcm_GHASH()Denys Vlasenko
function old new delta xwrite_encrypted 604 599 -5 FlattenSzInBits 52 - -52 aesgcm_GHASH 395 262 -133 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/2 up/down: 0/-190) Total: -190 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23tls: in AES-CBC code, do not set key for every record - do it onceDenys Vlasenko
function old new delta aes_setkey 16 212 +196 tls_handshake 1941 1977 +36 aes_encrypt_1 382 396 +14 xwrite_encrypted 605 604 -1 tls_xread_record 659 656 -3 aes_encrypt_one_block 65 59 -6 aes_cbc_encrypt 172 121 -51 aesgcm_setkey 58 - -58 aes_cbc_decrypt 958 881 -77 KeyExpansion 188 - -188 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 3/5 up/down: 246/-384) Total: -138 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-23tls: add support for TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipherDenys Vlasenko
function old new delta xwrite_encrypted 209 605 +396 GHASH - 395 +395 aes_encrypt_1 - 382 +382 GMULT - 192 +192 tls_xread_record 489 659 +170 aes_encrypt_one_block - 65 +65 aesgcm_setkey - 58 +58 FlattenSzInBits - 52 +52 tls_handshake 1890 1941 +51 xwrite_and_update_handshake_hash 46 81 +35 xorbuf - 24 +24 aes_setkey - 16 +16 psRsaEncryptPub 413 421 +8 stty_main 1221 1227 +6 ssl_client_main 138 143 +5 next_token 841 845 +4 spawn_ssl_client 218 219 +1 volume_id_probe_hfs_hfsplus 564 563 -1 read_package_field 232 230 -2 i2cdetect_main 674 672 -2 fail_hunk 139 136 -3 parse_expr 891 883 -8 curve25519 802 793 -9 aes_cbc_decrypt 971 958 -13 xwrite_handshake_record 43 - -43 aes_cbc_encrypt 644 172 -472 ------------------------------------------------------------------------------ (add/remove: 9/1 grow/shrink: 9/8 up/down: 1860/-553) Total: 1307 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-18tls: add comment, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-13tls: code shrinkDenys Vlasenko
function old new delta tls_get_zeroed_outbuf - 28 +28 static.empty_client_cert 7 - -7 tls_handshake 1930 1890 -40 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/1 up/down: 28/-47) Total: -19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-13tls: tidy up recently added ECDSA codeDenys Vlasenko
function old new delta tls_handshake 1935 1930 -5 static.OID_ECDSA_KEY_ALG 21 11 -10 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-15) Total: -15 bytes text data bss dec hex filename 950036 477 7296 957809 e9d71 busybox_old 950048 477 7296 957821 e9d7d busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-13tls: add support for ECDHE-ECDSA-AES-128-CBC-SHA and x25519 curveDenys Vlasenko
function old new delta curve25519 - 835 +835 tls_handshake 1619 1935 +316 xc_diffadd - 230 +230 fe_mul__distinct - 149 +149 lm_sub - 103 +103 lm_add - 82 +82 fe_mul_c - 74 +74 fe_select - 45 +45 static.f25519_one - 32 +32 static.basepoint9 - 32 +32 static.OID_ECDSA_KEY_ALG - 21 +21 static.OID_RSA_KEY_ALG - 13 +13 static.supported_groups - 8 +8 static.empty_client_cert - 7 +7 der_binary_to_pstm 40 42 +2 static.expected 13 - -13 ------------------------------------------------------------------------------ (add/remove: 14/1 grow/shrink: 2/0 up/down: 1949/-13) Total: 1936 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-05tls: code shrinkDenys Vlasenko
function old new delta tls_handshake 1643 1619 -24 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-04tls: reorder a few more cipher idsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-04tls: move TLS_AES_128_GCM_SHA256 definition upDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-11-04tls: add more cipher ids, no code changesDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-06-24tls: fix to handle X.509 v1 certificates correctlyIvan Abrea
The syntax of public key certificates can be found in RFC 5280 section 4.1. The relevant part of the syntax is the following: TBSCertificate ::= SEQUENCE { version [0] EXPLICIT Version DEFAULT v1, serialNumber CertificateSerialNumber, ... remaining fields omitted ... } The version field has a default value of v1. RFC 5280 section 4.1.2.1 says the following: If only basic fields are present, the version SHOULD be 1 (the value is omitted from the certificate as the default value); however, the version MAY be 2 or 3. To help detect if the version field is present or not, the type of the version field has an explicit tag of [0]. Due to this tag, if the version field is present, its encoding will have an identifier octet that is distinct from that of the serialNumber field. ITU-T X.690 specifies how a value of such a type should be encoded with DER. There is a PDF of X.690 freely available from ITU-T. X.690 section 8.1.2 specifies the format of identifier octets which is the first component of every encoded value. Identifier octets encode the tag of a type. Bits 8 and 7 encode the tag class. Bit 6 will be 0 if the encoding is primitive and 1 if the encoding is constructed. Bits 5 to 1 encode the tag number. X.690 section 8.14 specifies what the identifier octet should be for explicitly tagged types. Section 8.14.3 says if implicit tagging is not used, then the encoding shall be constructed. The version field uses explicit tagging and not implicit tagging, so its encoding will be constructed. This means bit 6 of the identifier octet should be 1. X.690 section 8.14 and Annex A provide examples. Note from their examples that the notation for tags could look like [APPLICATION 2] where both the tag class and tag number are given. For this example, the tag class is 1 (application) and the tag number is 2. For notation like [0] where the tag class is omitted and only the tag number is given, the tag class will be context-specific. Putting this all together, the identifier octet for the DER encoding of the version field should have a tag class of 2 (context-specific), bit 6 as 1 (constructed), and a tag number of 0. Signed-off-by: Ivan Abrea <ivan@algosolutions.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-14tls: remove redundant floor preventionDenys Vlasenko
function old new delta tls_xread_record 499 489 -10 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06wget: initial support for ftps://Denys Vlasenko
function old new delta spawn_ssl_client - 185 +185 parse_url 409 461 +52 packed_usage 32259 32278 +19 tls_run_copy_loop 293 306 +13 ssl_client_main 128 138 +10 showmode 330 338 +8 P_FTPS - 5 +5 filter_datapoints 177 179 +2 deflate 907 905 -2 decode_one_format 723 716 -7 wget_main 2591 2440 -151 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 6/3 up/down: 294/-160) Total: 134 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2018-02-06tls: fix hash calculations if client cert is requested and sentDenys Vlasenko
Symptoms: connecting to openssl s_server -cert vsftpd.pem -port 990 -debug -cipher AES128-SHA works, but with "-verify 1" option added it does not. function old new delta tls_xread_record 474 499 +25 tls_handshake 1582 1607 +25 bad_record_die 98 110 +12 tls_run_copy_loop 282 293 +11 tls_xread_handshake_block 58 51 -7 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/1 up/down: 73/-7) Total: 66 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-07-04tls: use capped SNI len everywhereDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-04tls: do not compile in TLS_RSA_WITH_NULL_SHA256 code if unreachableDenys Vlasenko
function old new delta tls_handshake 1595 1588 -7 xwrite_encrypted 244 209 -35 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-03tls: avoid using int16 in pstm codeDenys Vlasenko
function old new delta pstm_div 1472 1522 +50 psRsaEncryptPub 403 413 +10 pstm_2expt 91 96 +5 pstm_clear 68 72 +4 pstm_init 39 42 +3 pstm_unsigned_bin_size 36 37 +1 pstm_montgomery_reduce 398 399 +1 pstm_init_size 45 46 +1 pstm_zero 39 38 -1 pstm_set 35 34 -1 pstm_read_unsigned_bin 112 109 -3 pstm_mulmod 123 120 -3 pstm_mod 116 113 -3 pstm_cmp 57 54 -3 pstm_sub 107 102 -5 pstm_to_unsigned_bin 157 151 -6 pstm_clamp 63 57 -6 pstm_add 116 108 -8 pstm_grow 81 72 -9 pstm_count_bits 57 48 -9 pstm_init_copy 84 72 -12 pstm_cmp_mag 93 78 -15 pstm_sqr_comba 567 551 -16 pstm_montgomery_calc_normalization 158 140 -18 pstm_copy 115 92 -23 pstm_lshd 133 109 -24 pstm_mul_comba 525 500 -25 pstm_mul_d 251 224 -27 s_pstm_sub 256 228 -28 s_pstm_add 370 337 -33 pstm_div_2d 444 409 -35 pstm_mul_2 195 156 -39 pstm_rshd 154 104 -50 pstm_mul_2d 247 186 -61 pstm_exptmod 1524 1463 -61 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/27 up/down: 75/-524) Total: -449 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-04-03tls: merge sha1 and sha256 hmac functionsDenys Vlasenko
function old new delta hmac_begin - 196 +196 hmac_sha256 61 68 +7 hmac 250 87 -163 hmac_sha256_begin 190 - -190 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 1/1 up/down: 203/-353) Total: -150 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-16tls: covert i/o loop from using select() to poll()Denys Vlasenko
function old new delta tls_run_copy_loop 377 282 -95 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-04tls: fold AES CBC en/decryption into single functionsDenys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-02-03wget/tls: session_id of zero length is ok (arxiv.org responds with such)Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24tls: can download kernels now :)Denys Vlasenko
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-24tls: if got CERTIFICATE_REQUEST, send an empty CERTIFICATEDenys Vlasenko
wolfssl test server is not satisfied by an empty one, but some real servers might be. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>