aboutsummaryrefslogtreecommitdiff
path: root/networking
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2019-01-10 08:38:15 +0000
committerRon Yorston <rmy@pobox.com>2019-01-10 08:38:15 +0000
commitf99a280743e877c14ee90a3f9e93a34ca3476a27 (patch)
tree60ca3d17596e190c8c7cbca587168946598bee8a /networking
parent40d5dd07ea1f290eaed30a03fd598e33a8eaf495 (diff)
parent6ca8e347fed8c24655df692f22694baf7c572770 (diff)
downloadbusybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.gz
busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.tar.bz2
busybox-w32-f99a280743e877c14ee90a3f9e93a34ca3476a27.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'networking')
-rw-r--r--networking/Config.src11
-rw-r--r--networking/arp.c2
-rw-r--r--networking/arping.c2
-rw-r--r--networking/ether-wake.c2
-rw-r--r--networking/ftpgetput.c4
-rw-r--r--networking/hostname.c2
-rw-r--r--networking/ifplugd.c2
-rw-r--r--networking/ifupdown.c4
-rw-r--r--networking/inetd.c2
-rw-r--r--networking/ip.c4
-rw-r--r--networking/ipcalc.c2
-rw-r--r--networking/isrv_identd.c2
-rw-r--r--networking/libiproute/ipaddress.c4
-rw-r--r--networking/nbd-client.c8
-rw-r--r--networking/nslookup.c14
-rw-r--r--networking/ntpd.c2
-rw-r--r--networking/ping.c4
-rw-r--r--networking/pscan.c2
-rw-r--r--networking/route.c2
-rw-r--r--networking/slattach.c2
-rw-r--r--networking/ssl_client.c2
-rw-r--r--networking/tc.c2
-rw-r--r--networking/tcpudp.c2
-rw-r--r--networking/telnet.c205
-rw-r--r--networking/telnetd.c18
-rw-r--r--networking/tftp.c5
-rw-r--r--networking/tls.c79
-rw-r--r--networking/tls_aesgcm.c85
-rw-r--r--networking/tls_pstm.c109
-rw-r--r--networking/tls_pstm.h86
-rw-r--r--networking/tls_pstm_montgomery_reduce.c2
-rw-r--r--networking/tls_pstm_mul_comba.c2
-rw-r--r--networking/tls_pstm_sqr_comba.c2
-rw-r--r--networking/tls_rsa.c4
-rw-r--r--networking/traceroute.c2
-rw-r--r--networking/tunctl.c2
-rw-r--r--networking/udhcp/Config.src8
-rw-r--r--networking/udhcp/common.c33
-rw-r--r--networking/udhcp/common.h6
-rw-r--r--networking/udhcp/d6_dhcpc.c2
-rw-r--r--networking/udhcp/dhcpc.c8
-rw-r--r--networking/udhcp/dhcpd.c8
-rw-r--r--networking/vconfig.c2
-rw-r--r--networking/wget.c64
-rw-r--r--networking/whois.c2
-rw-r--r--networking/zcip.c2
46 files changed, 523 insertions, 296 deletions
diff --git a/networking/Config.src b/networking/Config.src
index 2ce5287de..04d644bc9 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -46,6 +46,17 @@ config VERBOSE_RESOLUTION_ERRORS
46 "can't resolve 'hostname.com'" and want to know more. 46 "can't resolve 'hostname.com'" and want to know more.
47 This may increase size of your executable a bit. 47 This may increase size of your executable a bit.
48 48
49config FEATURE_TLS_SHA1
50 bool "In TLS code, support ciphers which use deprecated SHA1"
51 depends on TLS
52 default n
53 help
54 Selecting this option increases interoperability with very old
55 servers, but slightly increases code size.
56
57 Most TLS servers support SHA256 today (2018), since SHA1 is
58 considered possibly insecure (although not yet definitely broken).
59
49INSERT 60INSERT
50 61
51source networking/udhcp/Config.in 62source networking/udhcp/Config.in
diff --git a/networking/arp.c b/networking/arp.c
index 177ab1571..71bfe3cbf 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -13,7 +13,7 @@
13 * modified for getopt32 by Arne Bernin <arne [at] alamut.de> 13 * modified for getopt32 by Arne Bernin <arne [at] alamut.de>
14 */ 14 */
15//config:config ARP 15//config:config ARP
16//config: bool "arp (11 kb)" 16//config: bool "arp (10 kb)"
17//config: default y 17//config: default y
18//config: select PLATFORM_LINUX 18//config: select PLATFORM_LINUX
19//config: help 19//config: help
diff --git a/networking/arping.c b/networking/arping.c
index 788fded3c..901578b68 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -6,7 +6,7 @@
6 * Busybox port: Nick Fedchik <nick@fedchik.org.ua> 6 * Busybox port: Nick Fedchik <nick@fedchik.org.ua>
7 */ 7 */
8//config:config ARPING 8//config:config ARPING
9//config: bool "arping (9.3 kb)" 9//config: bool "arping (9 kb)"
10//config: default y 10//config: default y
11//config: select PLATFORM_LINUX 11//config: select PLATFORM_LINUX
12//config: help 12//config: help
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
index 6677f07d5..acaac16f8 100644
--- a/networking/ether-wake.c
+++ b/networking/ether-wake.c
@@ -64,7 +64,7 @@
64 * filter. That configuration consumes more power. 64 * filter. That configuration consumes more power.
65 */ 65 */
66//config:config ETHER_WAKE 66//config:config ETHER_WAKE
67//config: bool "ether-wake (6.6 kb)" 67//config: bool "ether-wake (4.9 kb)"
68//config: default y 68//config: default y
69//config: select PLATFORM_LINUX 69//config: select PLATFORM_LINUX
70//config: help 70//config: help
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 84ca547ff..bff90538f 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -13,13 +13,13 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
14 */ 14 */
15//config:config FTPGET 15//config:config FTPGET
16//config: bool "ftpget (8 kb)" 16//config: bool "ftpget (7.8 kb)"
17//config: default y 17//config: default y
18//config: help 18//config: help
19//config: Retrieve a remote file via FTP. 19//config: Retrieve a remote file via FTP.
20//config: 20//config:
21//config:config FTPPUT 21//config:config FTPPUT
22//config: bool "ftpput (7.7 kb)" 22//config: bool "ftpput (7.5 kb)"
23//config: default y 23//config: default y
24//config: help 24//config: help
25//config: Store a remote file via FTP. 25//config: Store a remote file via FTP.
diff --git a/networking/hostname.c b/networking/hostname.c
index 8e3238d99..248d8b65a 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -10,7 +10,7 @@
10 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
11 */ 11 */
12//config:config HOSTNAME 12//config:config HOSTNAME
13//config: bool "hostname (5.6 kb)" 13//config: bool "hostname (5.5 kb)"
14//config: default y 14//config: default y
15//config: help 15//config: help
16//config: Show or set the system's host name. 16//config: Show or set the system's host name.
diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 9a67d24d8..026ff1cc8 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -7,7 +7,7 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9//config:config IFPLUGD 9//config:config IFPLUGD
10//config: bool "ifplugd (9.9 kb)" 10//config: bool "ifplugd (10 kb)"
11//config: default y 11//config: default y
12//config: select PLATFORM_LINUX 12//config: select PLATFORM_LINUX
13//config: help 13//config: help
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 80fce87a6..8a6efc976 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -17,7 +17,7 @@
17 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 17 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
18 */ 18 */
19//config:config IFUP 19//config:config IFUP
20//config: bool "ifup (17 kb)" 20//config: bool "ifup (14 kb)"
21//config: default y 21//config: default y
22//config: help 22//config: help
23//config: Activate the specified interfaces. This applet makes use 23//config: Activate the specified interfaces. This applet makes use
@@ -33,7 +33,7 @@
33//config: via busybox or via standalone utilities. 33//config: via busybox or via standalone utilities.
34//config: 34//config:
35//config:config IFDOWN 35//config:config IFDOWN
36//config: bool "ifdown (15 kb)" 36//config: bool "ifdown (13 kb)"
37//config: default y 37//config: default y
38//config: help 38//config: help
39//config: Deactivate the specified interfaces. 39//config: Deactivate the specified interfaces.
diff --git a/networking/inetd.c b/networking/inetd.c
index ca1a97268..8f871ee12 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -488,7 +488,7 @@ static void block_CHLD_HUP_ALRM(sigset_t *m)
488 sigaddset(m, SIGCHLD); 488 sigaddset(m, SIGCHLD);
489 sigaddset(m, SIGHUP); 489 sigaddset(m, SIGHUP);
490 sigaddset(m, SIGALRM); 490 sigaddset(m, SIGALRM);
491 sigprocmask(SIG_BLOCK, m, m); /* old sigmask is stored in m */ 491 sigprocmask2(SIG_BLOCK, m); /* old sigmask is stored in m */
492} 492}
493 493
494static void restore_sigmask(sigset_t *m) 494static void restore_sigmask(sigset_t *m)
diff --git a/networking/ip.c b/networking/ip.c
index 97d618cd9..034ee4fc8 100644
--- a/networking/ip.c
+++ b/networking/ip.c
@@ -9,7 +9,7 @@
9 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array 9 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
10 */ 10 */
11//config:config IP 11//config:config IP
12//config: bool "ip (34 kb)" 12//config: bool "ip (35 kb)"
13//config: default y 13//config: default y
14//config: select PLATFORM_LINUX 14//config: select PLATFORM_LINUX
15//config: help 15//config: help
@@ -28,7 +28,7 @@
28//config: Short form of "ip addr" 28//config: Short form of "ip addr"
29//config: 29//config:
30//config:config IPLINK 30//config:config IPLINK
31//config: bool "iplink (16 kb)" 31//config: bool "iplink (17 kb)"
32//config: default y 32//config: default y
33//config: select FEATURE_IP_LINK 33//config: select FEATURE_IP_LINK
34//config: select PLATFORM_LINUX 34//config: select PLATFORM_LINUX
diff --git a/networking/ipcalc.c b/networking/ipcalc.c
index cdae8eea8..67f768836 100644
--- a/networking/ipcalc.c
+++ b/networking/ipcalc.c
@@ -12,7 +12,7 @@
12 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 12 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
13 */ 13 */
14//config:config IPCALC 14//config:config IPCALC
15//config: bool "ipcalc (4.3 kb)" 15//config: bool "ipcalc (4.4 kb)"
16//config: default y 16//config: default y
17//config: help 17//config: help
18//config: ipcalc takes an IP address and netmask and calculates the 18//config: ipcalc takes an IP address and netmask and calculates the
diff --git a/networking/isrv_identd.c b/networking/isrv_identd.c
index 0c33dde4f..f564d604a 100644
--- a/networking/isrv_identd.c
+++ b/networking/isrv_identd.c
@@ -7,7 +7,7 @@
7 * Licensed under GPLv2, see file LICENSE in this source tree. 7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */ 8 */
9//config:config FAKEIDENTD 9//config:config FAKEIDENTD
10//config: bool "fakeidentd (8.9 kb)" 10//config: bool "fakeidentd (8.7 kb)"
11//config: default y 11//config: default y
12//config: select FEATURE_SYSLOG 12//config: select FEATURE_SYSLOG
13//config: help 13//config: help
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 9ec665b69..d088caf4c 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -327,6 +327,10 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM,
327 ifa->ifa_flags &= ~IFA_F_TENTATIVE; 327 ifa->ifa_flags &= ~IFA_F_TENTATIVE;
328 printf("tentative "); 328 printf("tentative ");
329 } 329 }
330 if (ifa->ifa_flags & IFA_F_DADFAILED) {
331 ifa->ifa_flags &= ~IFA_F_DADFAILED;
332 printf("dadfailed ");
333 }
330 if (ifa->ifa_flags & IFA_F_DEPRECATED) { 334 if (ifa->ifa_flags & IFA_F_DEPRECATED) {
331 ifa->ifa_flags &= ~IFA_F_DEPRECATED; 335 ifa->ifa_flags &= ~IFA_F_DEPRECATED;
332 printf("deprecated "); 336 printf("deprecated ");
diff --git a/networking/nbd-client.c b/networking/nbd-client.c
index 103756b59..0dc8d0c43 100644
--- a/networking/nbd-client.c
+++ b/networking/nbd-client.c
@@ -4,7 +4,7 @@
4 * Licensed under GPLv2, see file LICENSE in this source tree. 4 * Licensed under GPLv2, see file LICENSE in this source tree.
5 */ 5 */
6//config:config NBDCLIENT 6//config:config NBDCLIENT
7//config: bool "nbd-client (4.6 kb)" 7//config: bool "nbd-client (6 kb)"
8//config: default y 8//config: default y
9//config: help 9//config: help
10//config: Network block device client 10//config: Network block device client
@@ -163,7 +163,9 @@ int nbdclient_main(int argc, char **argv)
163 int sock, nbd; 163 int sock, nbd;
164 int ro; 164 int ro;
165 int proto_new; // 0 for old, 1 for new 165 int proto_new; // 0 for old, 1 for new
166#if BB_MMU
166 char *data; 167 char *data;
168#endif
167 169
168 // Make sure BLOCKDEV exists 170 // Make sure BLOCKDEV exists
169 nbd = xopen(device, O_RDWR); 171 nbd = xopen(device, O_RDWR);
@@ -200,7 +202,9 @@ int nbdclient_main(int argc, char **argv)
200 ioctl(nbd, NBD_SET_SIZE_BLOCKS, size_blocks); 202 ioctl(nbd, NBD_SET_SIZE_BLOCKS, size_blocks);
201 ioctl(nbd, NBD_CLEAR_SOCK); 203 ioctl(nbd, NBD_CLEAR_SOCK);
202 ro = !!(old_nbd_header.flags & htons(2)); 204 ro = !!(old_nbd_header.flags & htons(2));
205#if BB_MMU
203 data = old_nbd_header.data; 206 data = old_nbd_header.data;
207#endif
204 } else { 208 } else {
205 unsigned namelen; 209 unsigned namelen;
206 uint16_t handshake_flags; 210 uint16_t handshake_flags;
@@ -230,7 +234,9 @@ int nbdclient_main(int argc, char **argv)
230 ioctl(nbd, NBD_SET_FLAGS, 234 ioctl(nbd, NBD_SET_FLAGS,
231 ntohs(new_nbd_header.transmission_flags)); 235 ntohs(new_nbd_header.transmission_flags));
232 ro = !!(new_nbd_header.transmission_flags & htons(2)); 236 ro = !!(new_nbd_header.transmission_flags & htons(2));
237#if BB_MMU
233 data = new_nbd_header.data; 238 data = new_nbd_header.data;
239#endif
234 } 240 }
235 241
236 if (ioctl(nbd, BLKROSET, &ro) < 0) { 242 if (ioctl(nbd, BLKROSET, &ro) < 0) {
diff --git a/networking/nslookup.c b/networking/nslookup.c
index e153eb585..24e09d4f0 100644
--- a/networking/nslookup.c
+++ b/networking/nslookup.c
@@ -1,7 +1,7 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2 2
3//config:config NSLOOKUP 3//config:config NSLOOKUP
4//config: bool "nslookup (4.5 kb)" 4//config: bool "nslookup (9.7 kb)"
5//config: default y 5//config: default y
6//config: help 6//config: help
7//config: nslookup is a tool to query Internet name servers. 7//config: nslookup is a tool to query Internet name servers.
@@ -257,7 +257,7 @@ int nslookup_main(int argc, char **argv)
257struct ns { 257struct ns {
258 const char *name; 258 const char *name;
259 len_and_sockaddr *lsa; 259 len_and_sockaddr *lsa;
260 int failures; 260 //UNUSED: int failures;
261 int replies; 261 int replies;
262}; 262};
263 263
@@ -320,6 +320,7 @@ struct globals {
320 struct query *query; 320 struct query *query;
321 char *search; 321 char *search;
322 smalluint have_search_directive; 322 smalluint have_search_directive;
323 smalluint exitcode;
323} FIX_ALIASING; 324} FIX_ALIASING;
324#define G (*(struct globals*)bb_common_bufsiz1) 325#define G (*(struct globals*)bb_common_bufsiz1)
325#define INIT_G() do { \ 326#define INIT_G() do { \
@@ -593,7 +594,7 @@ static int send_queries(struct ns *ns)
593 594
594 /* Retry immediately on SERVFAIL */ 595 /* Retry immediately on SERVFAIL */
595 if (rcode == 2) { 596 if (rcode == 2) {
596 ns->failures++; 597 //UNUSED: ns->failures++;
597 if (servfail_retry) { 598 if (servfail_retry) {
598 servfail_retry--; 599 servfail_retry--;
599 write(pfd.fd, G.query[qn].query, G.query[qn].qlen); 600 write(pfd.fd, G.query[qn].query, G.query[qn].qlen);
@@ -612,9 +613,12 @@ static int send_queries(struct ns *ns)
612 if (rcode != 0) { 613 if (rcode != 0) {
613 printf("** server can't find %s: %s\n", 614 printf("** server can't find %s: %s\n",
614 G.query[qn].name, rcodes[rcode]); 615 G.query[qn].name, rcodes[rcode]);
616 G.exitcode = EXIT_FAILURE;
615 } else { 617 } else {
616 if (parse_reply(reply, recvlen) < 0) 618 if (parse_reply(reply, recvlen) < 0) {
617 printf("*** Can't find %s: Parse error\n", G.query[qn].name); 619 printf("*** Can't find %s: Parse error\n", G.query[qn].name);
620 G.exitcode = EXIT_FAILURE;
621 }
618 } 622 }
619 bb_putchar('\n'); 623 bb_putchar('\n');
620 n_replies++; 624 n_replies++;
@@ -988,7 +992,7 @@ int nslookup_main(int argc UNUSED_PARAM, char **argv)
988 free(G.query); 992 free(G.query);
989 } 993 }
990 994
991 return EXIT_SUCCESS; 995 return G.exitcode;
992} 996}
993 997
994#endif 998#endif
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 041cac762..855815ece 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -41,7 +41,7 @@
41 *********************************************************************** 41 ***********************************************************************
42 */ 42 */
43//config:config NTPD 43//config:config NTPD
44//config: bool "ntpd (17 kb)" 44//config: bool "ntpd (22 kb)"
45//config: default y 45//config: default y
46//config: select PLATFORM_LINUX 46//config: select PLATFORM_LINUX
47//config: help 47//config: help
diff --git a/networking/ping.c b/networking/ping.c
index 570184fee..b534c74c7 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -25,7 +25,7 @@
25 * The code was modified by Bart Visscher <magick@linux-fan.com> 25 * The code was modified by Bart Visscher <magick@linux-fan.com>
26 */ 26 */
27//config:config PING 27//config:config PING
28//config: bool "ping (9.5 kb)" 28//config: bool "ping (10 kb)"
29//config: default y 29//config: default y
30//config: select PLATFORM_LINUX 30//config: select PLATFORM_LINUX
31//config: help 31//config: help
@@ -33,7 +33,7 @@
33//config: elicit an ICMP ECHO_RESPONSE from a host or gateway. 33//config: elicit an ICMP ECHO_RESPONSE from a host or gateway.
34//config: 34//config:
35//config:config PING6 35//config:config PING6
36//config: bool "ping6 (10 kb)" 36//config: bool "ping6 (11 kb)"
37//config: default y 37//config: default y
38//config: depends on FEATURE_IPV6 38//config: depends on FEATURE_IPV6
39//config: help 39//config: help
diff --git a/networking/pscan.c b/networking/pscan.c
index 95b0a937d..2715ef2df 100644
--- a/networking/pscan.c
+++ b/networking/pscan.c
@@ -6,7 +6,7 @@
6 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
7 */ 7 */
8//config:config PSCAN 8//config:config PSCAN
9//config: bool "pscan (6.6 kb)" 9//config: bool "pscan (6 kb)"
10//config: default y 10//config: default y
11//config: help 11//config: help
12//config: Simple network port scanner. 12//config: Simple network port scanner.
diff --git a/networking/route.c b/networking/route.c
index 8387ce1bb..ac1d94c28 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -25,7 +25,7 @@
25 * remove ridiculous amounts of bloat. 25 * remove ridiculous amounts of bloat.
26 */ 26 */
27//config:config ROUTE 27//config:config ROUTE
28//config: bool "route (8.9 kb)" 28//config: bool "route (8.7 kb)"
29//config: default y 29//config: default y
30//config: select PLATFORM_LINUX 30//config: select PLATFORM_LINUX
31//config: help 31//config: help
diff --git a/networking/slattach.c b/networking/slattach.c
index e0a388926..c6feca248 100644
--- a/networking/slattach.c
+++ b/networking/slattach.c
@@ -13,7 +13,7 @@
13 * - The -F options allows disabling of RTS/CTS flow control. 13 * - The -F options allows disabling of RTS/CTS flow control.
14 */ 14 */
15//config:config SLATTACH 15//config:config SLATTACH
16//config: bool "slattach (6.1 kb)" 16//config: bool "slattach (6.2 kb)"
17//config: default y 17//config: default y
18//config: select PLATFORM_LINUX 18//config: select PLATFORM_LINUX
19//config: help 19//config: help
diff --git a/networking/ssl_client.c b/networking/ssl_client.c
index 49aec6b99..cd0ee5722 100644
--- a/networking/ssl_client.c
+++ b/networking/ssl_client.c
@@ -4,7 +4,7 @@
4 * Licensed under GPLv2, see file LICENSE in this source tree. 4 * Licensed under GPLv2, see file LICENSE in this source tree.
5 */ 5 */
6//config:config SSL_CLIENT 6//config:config SSL_CLIENT
7//config: bool "ssl_client (23 kb)" 7//config: bool "ssl_client (25 kb)"
8//config: default y 8//config: default y
9//config: select TLS 9//config: select TLS
10//config: help 10//config: help
diff --git a/networking/tc.c b/networking/tc.c
index 4fa3e47bf..3e9808328 100644
--- a/networking/tc.c
+++ b/networking/tc.c
@@ -7,7 +7,7 @@
7 * Bernhard Reutner-Fischer adjusted for busybox 7 * Bernhard Reutner-Fischer adjusted for busybox
8 */ 8 */
9//config:config TC 9//config:config TC
10//config: bool "tc (3.1 kb)" 10//config: bool "tc (8.3 kb)"
11//config: default y 11//config: default y
12//config: help 12//config: help
13//config: Show / manipulate traffic control settings 13//config: Show / manipulate traffic control settings
diff --git a/networking/tcpudp.c b/networking/tcpudp.c
index c914221ae..a0af64981 100644
--- a/networking/tcpudp.c
+++ b/networking/tcpudp.c
@@ -29,7 +29,7 @@
29 * - don't know how to retrieve ORIGDST for udp. 29 * - don't know how to retrieve ORIGDST for udp.
30 */ 30 */
31//config:config TCPSVD 31//config:config TCPSVD
32//config: bool "tcpsvd (13 kb)" 32//config: bool "tcpsvd (14 kb)"
33//config: default y 33//config: default y
34//config: help 34//config: help
35//config: tcpsvd listens on a TCP port and runs a program for each new 35//config: tcpsvd listens on a TCP port and runs a program for each new
diff --git a/networking/telnet.c b/networking/telnet.c
index 1e6be85bd..fa1628723 100644
--- a/networking/telnet.c
+++ b/networking/telnet.c
@@ -20,7 +20,7 @@
20 * by Fernando Silveira <swrh@gmx.net> 20 * by Fernando Silveira <swrh@gmx.net>
21 */ 21 */
22//config:config TELNET 22//config:config TELNET
23//config: bool "telnet (8.7 kb)" 23//config: bool "telnet (8.8 kb)"
24//config: default y 24//config: default y
25//config: help 25//config: help
26//config: Telnet is an interface to the TELNET protocol, but is also commonly 26//config: Telnet is an interface to the TELNET protocol, but is also commonly
@@ -94,19 +94,19 @@ enum {
94 IACBUFSIZE = 128, 94 IACBUFSIZE = 128,
95 95
96 CHM_TRY = 0, 96 CHM_TRY = 0,
97 CHM_ON = 1, 97 CHM_ON = 1,
98 CHM_OFF = 2, 98 CHM_OFF = 2,
99 99
100 UF_ECHO = 0x01, 100 UF_ECHO = 0x01,
101 UF_SGA = 0x02, 101 UF_SGA = 0x02,
102 102
103 TS_NORMAL = 0, 103 TS_NORMAL = 0,
104 TS_COPY = 1, 104 TS_COPY = 1,
105 TS_IAC = 2, 105 TS_IAC = 2,
106 TS_OPT = 3, 106 TS_OPT = 3,
107 TS_SUB1 = 4, 107 TS_SUB1 = 4,
108 TS_SUB2 = 5, 108 TS_SUB2 = 5,
109 TS_CR = 6, 109 TS_CR = 6,
110}; 110};
111 111
112typedef unsigned char byte; 112typedef unsigned char byte;
@@ -152,8 +152,10 @@ static void subneg(byte c);
152 152
153static void iac_flush(void) 153static void iac_flush(void)
154{ 154{
155 full_write(netfd, G.iacbuf, G.iaclen); 155 if (G.iaclen != 0) {
156 G.iaclen = 0; 156 full_write(netfd, G.iacbuf, G.iaclen);
157 G.iaclen = 0;
158 }
157} 159}
158 160
159static void doexit(int ev) NORETURN; 161static void doexit(int ev) NORETURN;
@@ -244,25 +246,34 @@ static void handle_net_output(int len)
244 246
245static void handle_net_input(int len) 247static void handle_net_input(int len)
246{ 248{
249 byte c;
247 int i; 250 int i;
248 int cstart = 0; 251 int cstart = cstart; /* for compiler */
249 252
250 for (i = 0; i < len; i++) { 253 i = 0;
251 byte c = G.buf[i]; 254 //bb_error_msg("[%u,'%.*s']", G.telstate, len, G.buf);
252 255 if (G.telstate == TS_NORMAL) { /* most typical state */
253 if (G.telstate == TS_NORMAL) { /* most typical state */ 256 while (i < len) {
254 if (c == IAC) { 257 c = G.buf[i];
255 cstart = i; 258 i++;
256 G.telstate = TS_IAC; 259 if (c == IAC) /* unlikely */
257 } 260 goto got_IAC;
258 else if (c == '\r') { 261 if (c != '\r') /* likely */
259 cstart = i + 1; 262 continue;
260 G.telstate = TS_CR; 263 G.telstate = TS_CR;
261 } 264 cstart = i;
262 /* No IACs were seen so far, no need to copy 265 goto got_special;
263 * bytes within G.buf: */
264 continue;
265 } 266 }
267 full_write(STDOUT_FILENO, G.buf, len);
268 return;
269 got_IAC:
270 G.telstate = TS_IAC;
271 cstart = i - 1;
272 got_special: ;
273 }
274
275 for (; i < len; i++) {
276 c = G.buf[i];
266 277
267 switch (G.telstate) { 278 switch (G.telstate) {
268 case TS_CR: 279 case TS_CR:
@@ -278,20 +289,19 @@ static void handle_net_input(int len)
278 /* Similar to NORMAL, but in TS_COPY we need to copy bytes */ 289 /* Similar to NORMAL, but in TS_COPY we need to copy bytes */
279 if (c == IAC) 290 if (c == IAC)
280 G.telstate = TS_IAC; 291 G.telstate = TS_IAC;
281 else 292 else {
282 G.buf[cstart++] = c; 293 G.buf[cstart++] = c;
283 if (c == '\r') 294 if (c == '\r')
284 G.telstate = TS_CR; 295 G.telstate = TS_CR;
296 }
285 break; 297 break;
286 298
287 case TS_IAC: /* Prev char was IAC */ 299 case TS_IAC: /* Prev char was IAC */
288 if (c == IAC) { /* IAC IAC -> one IAC */ 300 switch (c) {
301 case IAC: /* IAC IAC -> one IAC */
289 G.buf[cstart++] = c; 302 G.buf[cstart++] = c;
290 G.telstate = TS_COPY; 303 G.telstate = TS_COPY;
291 break; 304 break;
292 }
293 /* else */
294 switch (c) {
295 case SB: 305 case SB:
296 G.telstate = TS_SUB1; 306 G.telstate = TS_SUB1;
297 break; 307 break;
@@ -320,103 +330,83 @@ static void handle_net_input(int len)
320 } 330 }
321 } 331 }
322 332
323 if (G.telstate != TS_NORMAL) { 333 /* We had some IACs, or CR */
324 /* We had some IACs, or CR */ 334 iac_flush();
325 if (G.iaclen) 335 if (G.telstate == TS_COPY) /* we aren't in the middle of IAC */
326 iac_flush(); 336 G.telstate = TS_NORMAL;
327 if (G.telstate == TS_COPY) /* we aren't in the middle of IAC */ 337 if (cstart != 0)
328 G.telstate = TS_NORMAL; 338 full_write(STDOUT_FILENO, G.buf, cstart);
329 len = cstart;
330 }
331
332 if (len)
333 full_write(STDOUT_FILENO, G.buf, len);
334} 339}
335 340
336static void put_iac(int c) 341static void put_iac(int c)
337{ 342{
338 G.iacbuf[G.iaclen++] = c; 343 int iaclen = G.iaclen;
344 if (iaclen >= IACBUFSIZE) {
345 iac_flush();
346 iaclen = 0;
347 }
348 G.iacbuf[iaclen] = c; /* "... & 0xff" is implicit */
349 G.iaclen = iaclen + 1;
339} 350}
340 351
341static void put_iac2_merged(unsigned wwdd_and_c) 352static void put_iac2_msb_lsb(unsigned x_y)
342{ 353{
343 if (G.iaclen + 3 > IACBUFSIZE) 354 put_iac(x_y >> 8); /* "... & 0xff" is implicit */
344 iac_flush(); 355 put_iac(x_y); /* "... & 0xff" is implicit */
356}
357#define put_iac2_x_y(x,y) put_iac2_msb_lsb(((x)<<8) + (y))
358
359static void put_iac4_msb_lsb(unsigned x_y_z_t)
360{
361 put_iac2_msb_lsb(x_y_z_t >> 16);
362 put_iac2_msb_lsb(x_y_z_t); /* "... & 0xffff" is implicit */
363}
364#define put_iac4_x_y_z_t(x,y,z,t) put_iac4_msb_lsb(((x)<<24) + ((y)<<16) + ((z)<<8) + (t))
345 365
366static void put_iac3_IAC_x_y_merged(unsigned wwdd_and_c)
367{
346 put_iac(IAC); 368 put_iac(IAC);
347 put_iac(wwdd_and_c >> 8); 369 put_iac2_msb_lsb(wwdd_and_c);
348 put_iac(wwdd_and_c & 0xff);
349} 370}
350#define put_iac2(wwdd,c) put_iac2_merged(((wwdd)<<8) + (c)) 371#define put_iac3_IAC_x_y(wwdd,c) put_iac3_IAC_x_y_merged(((wwdd)<<8) + (c))
351 372
352#if ENABLE_FEATURE_TELNET_TTYPE 373#if ENABLE_FEATURE_TELNET_TTYPE
353static void put_iac_subopt(byte c, char *str) 374static void put_iac_subopt(byte c, char *str)
354{ 375{
355 int len = strlen(str) + 6; // ( 2 + 1 + 1 + strlen + 2 ) 376 put_iac4_x_y_z_t(IAC, SB, c, 0);
356
357 if (G.iaclen + len > IACBUFSIZE)
358 iac_flush();
359
360 put_iac(IAC);
361 put_iac(SB);
362 put_iac(c);
363 put_iac(0);
364 377
365 while (*str) 378 while (*str)
366 put_iac(*str++); 379 put_iac(*str++);
367 380
368 put_iac(IAC); 381 put_iac2_x_y(IAC, SE);
369 put_iac(SE);
370} 382}
371#endif 383#endif
372 384
373#if ENABLE_FEATURE_TELNET_AUTOLOGIN 385#if ENABLE_FEATURE_TELNET_AUTOLOGIN
374static void put_iac_subopt_autologin(void) 386static void put_iac_subopt_autologin(void)
375{ 387{
376 int len = strlen(G.autologin) + 6; // (2 + 1 + 1 + strlen + 2) 388 const char *p;
377 const char *p = "USER";
378
379 if (G.iaclen + len > IACBUFSIZE)
380 iac_flush();
381
382 put_iac(IAC);
383 put_iac(SB);
384 put_iac(TELOPT_NEW_ENVIRON);
385 put_iac(TELQUAL_IS);
386 put_iac(NEW_ENV_VAR);
387
388 while (*p)
389 put_iac(*p++);
390 389
391 put_iac(NEW_ENV_VALUE); 390 put_iac4_x_y_z_t(IAC, SB, TELOPT_NEW_ENVIRON, TELQUAL_IS);
391 put_iac4_x_y_z_t(NEW_ENV_VAR, 'U', 'S', 'E'); /* "USER" */
392 put_iac2_x_y('R', NEW_ENV_VALUE);
392 393
393 p = G.autologin; 394 p = G.autologin;
394 while (*p) 395 while (*p)
395 put_iac(*p++); 396 put_iac(*p++);
396 397
397 put_iac(IAC); 398 put_iac2_x_y(IAC, SE);
398 put_iac(SE);
399} 399}
400#endif 400#endif
401 401
402#if ENABLE_FEATURE_TELNET_WIDTH 402#if ENABLE_FEATURE_TELNET_WIDTH
403static void put_iac_naws(byte c, int x, int y) 403static void put_iac_naws(byte c, int x, int y)
404{ 404{
405 if (G.iaclen + 9 > IACBUFSIZE) 405 put_iac3_IAC_x_y(SB, c);
406 iac_flush();
407 406
408 put_iac(IAC); 407 put_iac4_msb_lsb((x << 16) + y);
409 put_iac(SB);
410 put_iac(c);
411 408
412 /* "... & 0xff" implicitly done below */ 409 put_iac2_x_y(IAC, SE);
413 put_iac(x >> 8);
414 put_iac(x);
415 put_iac(y >> 8);
416 put_iac(y);
417
418 put_iac(IAC);
419 put_iac(SE);
420} 410}
421#endif 411#endif
422 412
@@ -445,8 +435,8 @@ static void will_charmode(void)
445 G.telflags |= (UF_ECHO | UF_SGA); 435 G.telflags |= (UF_ECHO | UF_SGA);
446 setConMode(); 436 setConMode();
447 437
448 put_iac2(DO, TELOPT_ECHO); 438 put_iac3_IAC_x_y(DO, TELOPT_ECHO);
449 put_iac2(DO, TELOPT_SGA); 439 put_iac3_IAC_x_y(DO, TELOPT_SGA);
450 iac_flush(); 440 iac_flush();
451} 441}
452 442
@@ -456,24 +446,24 @@ static void do_linemode(void)
456 G.telflags &= ~(UF_ECHO | UF_SGA); 446 G.telflags &= ~(UF_ECHO | UF_SGA);
457 setConMode(); 447 setConMode();
458 448
459 put_iac2(DONT, TELOPT_ECHO); 449 put_iac3_IAC_x_y(DONT, TELOPT_ECHO);
460 put_iac2(DONT, TELOPT_SGA); 450 put_iac3_IAC_x_y(DONT, TELOPT_SGA);
461 iac_flush(); 451 iac_flush();
462} 452}
463 453
464static void to_notsup(char c) 454static void to_notsup(char c)
465{ 455{
466 if (G.telwish == WILL) 456 if (G.telwish == WILL)
467 put_iac2(DONT, c); 457 put_iac3_IAC_x_y(DONT, c);
468 else if (G.telwish == DO) 458 else if (G.telwish == DO)
469 put_iac2(WONT, c); 459 put_iac3_IAC_x_y(WONT, c);
470} 460}
471 461
472static void to_echo(void) 462static void to_echo(void)
473{ 463{
474 /* if server requests ECHO, don't agree */ 464 /* if server requests ECHO, don't agree */
475 if (G.telwish == DO) { 465 if (G.telwish == DO) {
476 put_iac2(WONT, TELOPT_ECHO); 466 put_iac3_IAC_x_y(WONT, TELOPT_ECHO);
477 return; 467 return;
478 } 468 }
479 if (G.telwish == DONT) 469 if (G.telwish == DONT)
@@ -489,9 +479,9 @@ static void to_echo(void)
489 G.telflags ^= UF_ECHO; 479 G.telflags ^= UF_ECHO;
490 480
491 if (G.telflags & UF_ECHO) 481 if (G.telflags & UF_ECHO)
492 put_iac2(DO, TELOPT_ECHO); 482 put_iac3_IAC_x_y(DO, TELOPT_ECHO);
493 else 483 else
494 put_iac2(DONT, TELOPT_ECHO); 484 put_iac3_IAC_x_y(DONT, TELOPT_ECHO);
495 485
496 setConMode(); 486 setConMode();
497 full_write1_str("\r\n"); /* sudden modec */ 487 full_write1_str("\r\n"); /* sudden modec */
@@ -509,9 +499,9 @@ static void to_sga(void)
509 499
510 G.telflags ^= UF_SGA; /* toggle */ 500 G.telflags ^= UF_SGA; /* toggle */
511 if (G.telflags & UF_SGA) 501 if (G.telflags & UF_SGA)
512 put_iac2(DO, TELOPT_SGA); 502 put_iac3_IAC_x_y(DO, TELOPT_SGA);
513 else 503 else
514 put_iac2(DONT, TELOPT_SGA); 504 put_iac3_IAC_x_y(DONT, TELOPT_SGA);
515} 505}
516 506
517#if ENABLE_FEATURE_TELNET_TTYPE 507#if ENABLE_FEATURE_TELNET_TTYPE
@@ -519,9 +509,9 @@ static void to_ttype(void)
519{ 509{
520 /* Tell server we will (or won't) do TTYPE */ 510 /* Tell server we will (or won't) do TTYPE */
521 if (G.ttype) 511 if (G.ttype)
522 put_iac2(WILL, TELOPT_TTYPE); 512 put_iac3_IAC_x_y(WILL, TELOPT_TTYPE);
523 else 513 else
524 put_iac2(WONT, TELOPT_TTYPE); 514 put_iac3_IAC_x_y(WONT, TELOPT_TTYPE);
525} 515}
526#endif 516#endif
527 517
@@ -530,9 +520,9 @@ static void to_new_environ(void)
530{ 520{
531 /* Tell server we will (or will not) do AUTOLOGIN */ 521 /* Tell server we will (or will not) do AUTOLOGIN */
532 if (G.autologin) 522 if (G.autologin)
533 put_iac2(WILL, TELOPT_NEW_ENVIRON); 523 put_iac3_IAC_x_y(WILL, TELOPT_NEW_ENVIRON);
534 else 524 else
535 put_iac2(WONT, TELOPT_NEW_ENVIRON); 525 put_iac3_IAC_x_y(WONT, TELOPT_NEW_ENVIRON);
536} 526}
537#endif 527#endif
538 528
@@ -540,7 +530,7 @@ static void to_new_environ(void)
540static void to_naws(void) 530static void to_naws(void)
541{ 531{
542 /* Tell server we will do NAWS */ 532 /* Tell server we will do NAWS */
543 put_iac2(WILL, TELOPT_NAWS); 533 put_iac3_IAC_x_y(WILL, TELOPT_NAWS);
544} 534}
545#endif 535#endif
546 536
@@ -649,6 +639,7 @@ int telnet_main(int argc UNUSED_PARAM, char **argv)
649 bb_show_usage(); 639 bb_show_usage();
650 640
651 xmove_fd(create_and_connect_stream_or_die(host, port), netfd); 641 xmove_fd(create_and_connect_stream_or_die(host, port), netfd);
642 printf("Connected to %s\n", host);
652 643
653 setsockopt_keepalive(netfd); 644 setsockopt_keepalive(netfd);
654 645
diff --git a/networking/telnetd.c b/networking/telnetd.c
index a6bafa21d..caef15181 100644
--- a/networking/telnetd.c
+++ b/networking/telnetd.c
@@ -865,11 +865,25 @@ int telnetd_main(int argc UNUSED_PARAM, char **argv)
865 skip3: 865 skip3:
866 if (/*ts->size2 < BUFSIZE &&*/ FD_ISSET(ts->ptyfd, &rdfdset)) { 866 if (/*ts->size2 < BUFSIZE &&*/ FD_ISSET(ts->ptyfd, &rdfdset)) {
867 /* Read from pty to buffer 2 */ 867 /* Read from pty to buffer 2 */
868 int eio = 0;
869 read_pty:
868 count = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2); 870 count = MIN(BUFSIZE - ts->rdidx2, BUFSIZE - ts->size2);
869 count = safe_read(ts->ptyfd, TS_BUF2(ts) + ts->rdidx2, count); 871 count = safe_read(ts->ptyfd, TS_BUF2(ts) + ts->rdidx2, count);
870 if (count <= 0) { 872 if (count <= 0) {
871 if (count < 0 && errno == EAGAIN) 873 if (count < 0) {
872 goto skip4; 874 if (errno == EAGAIN)
875 goto skip4;
876 /* login process might call vhangup(),
877 * which causes intermittent EIOs on read above
878 * (observed on kernel 4.12.0). Try up to 10 ms.
879 */
880 if (errno == EIO && eio < 10) {
881 eio++;
882 //bb_error_msg("EIO pty %u", eio);
883 usleep(1000);
884 goto read_pty;
885 }
886 }
873 goto kill_session; 887 goto kill_session;
874 } 888 }
875 ts->size2 += count; 889 ts->size2 += count;
diff --git a/networking/tftp.c b/networking/tftp.c
index 4cd39186a..d20d4ca4b 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -19,7 +19,7 @@
19 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 19 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
20 */ 20 */
21//config:config TFTP 21//config:config TFTP
22//config: bool "tftp (12 kb)" 22//config: bool "tftp (11 kb)"
23//config: default y 23//config: default y
24//config: help 24//config: help
25//config: Trivial File Transfer Protocol client. TFTP is usually used 25//config: Trivial File Transfer Protocol client. TFTP is usually used
@@ -41,9 +41,6 @@
41//config: In other words: it should be run from inetd in nowait mode, 41//config: In other words: it should be run from inetd in nowait mode,
42//config: or from udpsvd. Example: "udpsvd -E 0 69 tftpd DIR" 42//config: or from udpsvd. Example: "udpsvd -E 0 69 tftpd DIR"
43//config: 43//config:
44//config:comment "Common options for tftp/tftpd"
45//config: depends on TFTP || TFTPD
46//config:
47//config:config FEATURE_TFTP_GET 44//config:config FEATURE_TFTP_GET
48//config: bool "Enable 'tftp get' and/or tftpd upload code" 45//config: bool "Enable 'tftp get' and/or tftpd upload code"
49//config: default y 46//config: default y
diff --git a/networking/tls.c b/networking/tls.c
index 38eb79798..d2385efe8 100644
--- a/networking/tls.c
+++ b/networking/tls.c
@@ -6,6 +6,8 @@
6//config:config TLS 6//config:config TLS
7//config: bool #No description makes it a hidden option 7//config: bool #No description makes it a hidden option
8//config: default n 8//config: default n
9//Note:
10//Config.src also defines FEATURE_TLS_SHA1 option
9 11
10//kbuild:lib-$(CONFIG_TLS) += tls.o 12//kbuild:lib-$(CONFIG_TLS) += tls.o
11//kbuild:lib-$(CONFIG_TLS) += tls_pstm.o 13//kbuild:lib-$(CONFIG_TLS) += tls_pstm.o
@@ -400,7 +402,7 @@ static void hash_handshake(tls_state_t *tls, const char *fmt, const void *buffer
400 dump_hex(fmt, buffer, len); 402 dump_hex(fmt, buffer, len);
401 dbg(" (%u bytes) ", (int)len); 403 dbg(" (%u bytes) ", (int)len);
402 len = sha_peek(&tls->hsd->handshake_hash_ctx, h); 404 len = sha_peek(&tls->hsd->handshake_hash_ctx, h);
403 if (len == SHA1_OUTSIZE) 405 if (ENABLE_FEATURE_TLS_SHA1 && len == SHA1_OUTSIZE)
404 dump_hex("sha1:%s\n", h, len); 406 dump_hex("sha1:%s\n", h, len);
405 else 407 else
406 if (len == SHA256_OUTSIZE) 408 if (len == SHA256_OUTSIZE)
@@ -411,6 +413,12 @@ static void hash_handshake(tls_state_t *tls, const char *fmt, const void *buffer
411#endif 413#endif
412} 414}
413 415
416#if !ENABLE_FEATURE_TLS_SHA1
417# define TLS_MAC_SIZE(tls) SHA256_OUTSIZE
418#else
419# define TLS_MAC_SIZE(tls) (tls)->MAC_size
420#endif
421
414// RFC 2104: 422// RFC 2104:
415// HMAC(key, text) based on a hash H (say, sha256) is: 423// HMAC(key, text) based on a hash H (say, sha256) is:
416// ipad = [0x36 x INSIZE] 424// ipad = [0x36 x INSIZE]
@@ -427,6 +435,11 @@ typedef struct hmac_precomputed {
427} hmac_precomputed_t; 435} hmac_precomputed_t;
428 436
429typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC; 437typedef void md5sha_begin_func(md5sha_ctx_t *ctx) FAST_FUNC;
438#if !ENABLE_FEATURE_TLS_SHA1
439#define hmac_begin(pre,key,key_size,begin) \
440 hmac_begin(pre,key,key_size)
441#define begin sha256_begin
442#endif
430static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size, md5sha_begin_func *begin) 443static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size, md5sha_begin_func *begin)
431{ 444{
432 uint8_t key_xor_ipad[SHA_INSIZE]; 445 uint8_t key_xor_ipad[SHA_INSIZE];
@@ -467,6 +480,7 @@ static void hmac_begin(hmac_precomputed_t *pre, uint8_t *key, unsigned key_size,
467 md5sha_hash(&pre->hashed_key_xor_ipad, key_xor_ipad, SHA_INSIZE); 480 md5sha_hash(&pre->hashed_key_xor_ipad, key_xor_ipad, SHA_INSIZE);
468 md5sha_hash(&pre->hashed_key_xor_opad, key_xor_opad, SHA_INSIZE); 481 md5sha_hash(&pre->hashed_key_xor_opad, key_xor_opad, SHA_INSIZE);
469} 482}
483#undef begin
470 484
471static unsigned hmac_sha_precomputed_v( 485static unsigned hmac_sha_precomputed_v(
472 hmac_precomputed_t *pre, 486 hmac_precomputed_t *pre,
@@ -504,6 +518,10 @@ static unsigned hmac_sha_precomputed(hmac_precomputed_t *pre_init, uint8_t *out,
504 return len; 518 return len;
505} 519}
506 520
521#if !ENABLE_FEATURE_TLS_SHA1
522#define hmac(tls,out,key,key_size,...) \
523 hmac(out,key,key_size, __VA_ARGS__)
524#endif
507static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_size, ...) 525static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_size, ...)
508{ 526{
509 hmac_precomputed_t pre; 527 hmac_precomputed_t pre;
@@ -513,9 +531,9 @@ static unsigned hmac(tls_state_t *tls, uint8_t *out, uint8_t *key, unsigned key_
513 va_start(va, key_size); 531 va_start(va, key_size);
514 532
515 hmac_begin(&pre, key, key_size, 533 hmac_begin(&pre, key, key_size,
516 (tls->MAC_size == SHA256_OUTSIZE) 534 (ENABLE_FEATURE_TLS_SHA1 && tls->MAC_size == SHA1_OUTSIZE)
517 ? sha256_begin 535 ? sha1_begin
518 : sha1_begin 536 : sha256_begin
519 ); 537 );
520 len = hmac_sha_precomputed_v(&pre, out, va); 538 len = hmac_sha_precomputed_v(&pre, out, va);
521 539
@@ -685,7 +703,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
685 703
686 /* Calculate MAC signature */ 704 /* Calculate MAC signature */
687 hmac(tls, buf + size, /* result */ 705 hmac(tls, buf + size, /* result */
688 tls->client_write_MAC_key, tls->MAC_size, 706 tls->client_write_MAC_key, TLS_MAC_SIZE(tls),
689 &tls->write_seq64_be, sizeof(tls->write_seq64_be), 707 &tls->write_seq64_be, sizeof(tls->write_seq64_be),
690 xhdr, RECHDR_LEN, 708 xhdr, RECHDR_LEN,
691 buf, size, 709 buf, size,
@@ -693,7 +711,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
693 ); 711 );
694 tls->write_seq64_be = SWAP_BE64(1 + SWAP_BE64(tls->write_seq64_be)); 712 tls->write_seq64_be = SWAP_BE64(1 + SWAP_BE64(tls->write_seq64_be));
695 713
696 size += tls->MAC_size; 714 size += TLS_MAC_SIZE(tls);
697 715
698 // RFC 5246: 716 // RFC 5246:
699 // 6.2.3.1. Null or Standard Stream Cipher 717 // 6.2.3.1. Null or Standard Stream Cipher
@@ -778,7 +796,7 @@ static void xwrite_encrypted_and_hmac_signed(tls_state_t *tls, unsigned size, un
778 796
779 tls_get_random(buf - AES_BLOCK_SIZE, AES_BLOCK_SIZE); /* IV */ 797 tls_get_random(buf - AES_BLOCK_SIZE, AES_BLOCK_SIZE); /* IV */
780 dbg("before crypt: 5 hdr + %u data + %u hash bytes\n", 798 dbg("before crypt: 5 hdr + %u data + %u hash bytes\n",
781 size - tls->MAC_size, tls->MAC_size); 799 size - TLS_MAC_SIZE(tls), TLS_MAC_SIZE(tls));
782 800
783 /* Fill IV and padding in outbuf */ 801 /* Fill IV and padding in outbuf */
784 // RFC is talking nonsense: 802 // RFC is talking nonsense:
@@ -1093,7 +1111,7 @@ static int tls_xread_record(tls_state_t *tls, const char *expected)
1093 tls_aesgcm_decrypt(tls, p, sz); 1111 tls_aesgcm_decrypt(tls, p, sz);
1094 dbg("encrypted size:%u\n", sz); 1112 dbg("encrypted size:%u\n", sz);
1095 } else 1113 } else
1096 if (tls->min_encrypted_len_on_read > tls->MAC_size) { 1114 if (tls->min_encrypted_len_on_read > TLS_MAC_SIZE(tls)) {
1097 /* AES+SHA */ 1115 /* AES+SHA */
1098 uint8_t *p = tls->inbuf + RECHDR_LEN; 1116 uint8_t *p = tls->inbuf + RECHDR_LEN;
1099 int padding_len; 1117 int padding_len;
@@ -1112,7 +1130,7 @@ static int tls_xread_record(tls_state_t *tls, const char *expected)
1112 padding_len = p[sz - 1]; 1130 padding_len = p[sz - 1];
1113 dbg("encrypted size:%u type:0x%02x padding_length:0x%02x\n", sz, p[0], padding_len); 1131 dbg("encrypted size:%u type:0x%02x padding_length:0x%02x\n", sz, p[0], padding_len);
1114 padding_len++; 1132 padding_len++;
1115 sz -= tls->MAC_size + padding_len; /* drop MAC and padding */ 1133 sz -= TLS_MAC_SIZE(tls) + padding_len; /* drop MAC and padding */
1116 } else { 1134 } else {
1117 /* if nonzero, then it's TLS_RSA_WITH_NULL_SHA256: drop MAC */ 1135 /* if nonzero, then it's TLS_RSA_WITH_NULL_SHA256: drop MAC */
1118 /* else: no encryption yet on input, subtract zero = NOP */ 1136 /* else: no encryption yet on input, subtract zero = NOP */
@@ -1472,15 +1490,19 @@ static ALWAYS_INLINE void fill_handshake_record_hdr(void *buf, unsigned type, un
1472 1490
1473static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni) 1491static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1474{ 1492{
1475#define NUM_CIPHERS (13 + ALLOW_RSA_NULL_SHA256) 1493#define NUM_CIPHERS (7 + 6 * ENABLE_FEATURE_TLS_SHA1 + ALLOW_RSA_NULL_SHA256)
1476 static const uint8_t ciphers[] = { 1494 static const uint8_t ciphers[] = {
1477 0x00,(1 + NUM_CIPHERS) * 2, //len16_be 1495 0x00,2 + NUM_CIPHERS*2, //len16_be
1478 0x00,0xFF, //not a cipher - TLS_EMPTY_RENEGOTIATION_INFO_SCSV 1496 0x00,0xFF, //not a cipher - TLS_EMPTY_RENEGOTIATION_INFO_SCSV
1479 /* ^^^^^^ RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */ 1497 /* ^^^^^^ RFC 5746 Renegotiation Indication Extension - some servers will refuse to work with us otherwise */
1498#if ENABLE_FEATURE_TLS_SHA1
1480 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/ 1499 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1481 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/ 1500 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1482 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA 1501 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1483 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl) 1502 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl)
1503 // 0xC0,0x18, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
1504 // 0xC0,0x19, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
1505#endif
1484 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/ 1506 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1485 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1507 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1486 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256 1508 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
@@ -1491,12 +1513,16 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1491 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256 1513 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1492 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac" 1514 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac"
1493 //possibly these too: 1515 //possibly these too:
1516#if ENABLE_FEATURE_TLS_SHA1
1494 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 1517 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1495 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 1518 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1519#endif
1496 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 1520 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1497 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1521 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1522#if ENABLE_FEATURE_TLS_SHA1
1498 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA 1523 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1499 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA 1524 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1525#endif
1500 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256 1526 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1501 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256 1527 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1502 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256 1528 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
@@ -1511,9 +1537,17 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1511 0x00,0x04, //ext len 1537 0x00,0x04, //ext len
1512 0x00,0x02, //list len 1538 0x00,0x02, //list len
1513 0x00,0x1d, //curve_x25519 (RFC 7748) 1539 0x00,0x1d, //curve_x25519 (RFC 7748)
1540 //0x00,0x1e, //curve_x448 (RFC 7748)
1514 //0x00,0x17, //curve_secp256r1 1541 //0x00,0x17, //curve_secp256r1
1515 //0x00,0x18, //curve_secp384r1 1542 //0x00,0x18, //curve_secp384r1
1516 //0x00,0x19, //curve_secp521r1 1543 //0x00,0x19, //curve_secp521r1
1544//TODO: implement secp256r1 (at least): dl.fedoraproject.org immediately aborts
1545//if only x25519/x448 are advertised, seems to support only secpNNNr1 curves:
1546// openssl s_client -connect dl.fedoraproject.org:443 -debug -tls1_2 -cipher ECDHE-RSA-AES128-GCM-SHA256
1547//Peer signing digest: SHA512
1548//Peer signature type: RSA
1549//Server Temp Key: ECDH, P-256, 256 bits
1550//TLSv1.2, Cipher is ECDHE-RSA-AES128-GCM-SHA256
1517 }; 1551 };
1518 //static const uint8_t signature_algorithms[] = { 1552 //static const uint8_t signature_algorithms[] = {
1519 // 000d 1553 // 000d
@@ -1530,7 +1564,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1530 uint8_t session_id_len; 1564 uint8_t session_id_len;
1531 /* uint8_t session_id[]; */ 1565 /* uint8_t session_id[]; */
1532 uint8_t cipherid_len16_hi, cipherid_len16_lo; 1566 uint8_t cipherid_len16_hi, cipherid_len16_lo;
1533 uint8_t cipherid[(1 + NUM_CIPHERS) * 2]; /* actually variable */ 1567 uint8_t cipherid[2 + NUM_CIPHERS*2]; /* actually variable */
1534 uint8_t comprtypes_len; 1568 uint8_t comprtypes_len;
1535 uint8_t comprtypes[1]; /* actually variable */ 1569 uint8_t comprtypes[1]; /* actually variable */
1536 /* Extensions (SNI shown): 1570 /* Extensions (SNI shown):
@@ -1578,7 +1612,7 @@ static void send_client_hello_and_alloc_hsd(tls_state_t *tls, const char *sni)
1578 memset(record->rand32, 0x11, sizeof(record->rand32)); 1612 memset(record->rand32, 0x11, sizeof(record->rand32));
1579 /* record->session_id_len = 0; - already is */ 1613 /* record->session_id_len = 0; - already is */
1580 1614
1581 BUILD_BUG_ON(sizeof(ciphers) != 2 + (1 + NUM_CIPHERS) * 2 + 2); 1615 BUILD_BUG_ON(sizeof(ciphers) != 2 + 2 + NUM_CIPHERS*2 + 2);
1582 memcpy(&record->cipherid_len16_hi, ciphers, sizeof(ciphers)); 1616 memcpy(&record->cipherid_len16_hi, ciphers, sizeof(ciphers));
1583 1617
1584 ptr = (void*)(record + 1); 1618 ptr = (void*)(record + 1);
@@ -1675,31 +1709,42 @@ static void get_server_hello(tls_state_t *tls)
1675 1709
1676 /* Set up encryption params based on selected cipher */ 1710 /* Set up encryption params based on selected cipher */
1677#if 0 1711#if 0
1712#if ENABLE_FEATURE_TLS_SHA1
1678 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/ 1713 0xC0,0x09, // 1 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA - ok: wget https://is.gd/
1679 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/ 1714 0xC0,0x0A, // 2 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA - ok: wget https://is.gd/
1680 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA 1715 0xC0,0x13, // 3 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA
1681 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl) 1716 0xC0,0x14, // 4 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher ECDHE-RSA-AES256-SHA (might fail with older openssl)
1717 // 0xC0,0x18, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
1718 // 0xC0,0x19, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
1719#endif
1682 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/ 1720 0xC0,0x23, // 5 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 - ok: wget https://is.gd/
1683 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1721 // 0xC0,0x24, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1684 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256 1722 0xC0,0x27, // 6 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-SHA256
1685 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1723 // 0xC0,0x28, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1686 0xC0,0x2B, // 7 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/ 1724 0xC0,0x2B, // 7 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - ok: wget https://is.gd/
1687 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC" 1725 // 0xC0,0x2C, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 - wget https://is.gd/: "TLS error from peer (alert code 20): bad MAC"
1726//TODO: GCM_SHA384 ciphers can be supported, only need sha384-based PRF?
1688 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256 1727 0xC0,0x2F, // 8 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher ECDHE-RSA-AES128-GCM-SHA256
1689 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac" 1728 // 0xC0,0x30, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher ECDHE-RSA-AES256-GCM-SHA384: "decryption failed or bad record mac"
1690 //possibly these too: 1729 //possibly these too:
1730#if ENABLE_FEATURE_TLS_SHA1
1691 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA 1731 // 0xC0,0x35, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
1692 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA 1732 // 0xC0,0x36, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
1733#endif
1693 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 1734 // 0xC0,0x37, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
1694 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet 1735 // 0xC0,0x38, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 - can't do SHA384 yet
1736#if ENABLE_FEATURE_TLS_SHA1
1695 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA 1737 0x00,0x2F, // 9 TLS_RSA_WITH_AES_128_CBC_SHA - ok: openssl s_server ... -cipher AES128-SHA
1696 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA 1738 0x00,0x35, //10 TLS_RSA_WITH_AES_256_CBC_SHA - ok: openssl s_server ... -cipher AES256-SHA
1739#endif
1697 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256 1740 0x00,0x3C, //11 TLS_RSA_WITH_AES_128_CBC_SHA256 - ok: openssl s_server ... -cipher AES128-SHA256
1698 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256 1741 0x00,0x3D, //12 TLS_RSA_WITH_AES_256_CBC_SHA256 - ok: openssl s_server ... -cipher AES256-SHA256
1699 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256 1742 0x00,0x9C, //13 TLS_RSA_WITH_AES_128_GCM_SHA256 - ok: openssl s_server ... -cipher AES128-GCM-SHA256
1700 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac" 1743 // 0x00,0x9D, // TLS_RSA_WITH_AES_256_GCM_SHA384 - openssl s_server ... -cipher AES256-GCM-SHA384: "decryption failed or bad record mac"
1744#if ALLOW_RSA_NULL_SHA256
1701 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256 1745 0x00,0x3B, // TLS_RSA_WITH_NULL_SHA256
1702#endif 1746#endif
1747#endif
1703 cipherid1 = cipherid[1]; 1748 cipherid1 = cipherid[1];
1704 tls->cipher_id = 0x100 * cipherid[0] + cipherid1; 1749 tls->cipher_id = 0x100 * cipherid[0] + cipherid1;
1705 tls->key_size = AES256_KEYSIZE; 1750 tls->key_size = AES256_KEYSIZE;
@@ -1712,7 +1757,7 @@ static void get_server_hello(tls_state_t *tls)
1712 /* Odd numbered C0xx use AES128 (even ones use AES256) */ 1757 /* Odd numbered C0xx use AES128 (even ones use AES256) */
1713 tls->key_size = AES128_KEYSIZE; 1758 tls->key_size = AES128_KEYSIZE;
1714 } 1759 }
1715 if (cipherid1 <= 0x14) { 1760 if (ENABLE_FEATURE_TLS_SHA1 && cipherid1 <= 0x19) {
1716 tls->MAC_size = SHA1_OUTSIZE; 1761 tls->MAC_size = SHA1_OUTSIZE;
1717 } else 1762 } else
1718 if (cipherid1 >= 0x2B && cipherid1 <= 0x30) { 1763 if (cipherid1 >= 0x2B && cipherid1 <= 0x30) {
@@ -1723,13 +1768,13 @@ static void get_server_hello(tls_state_t *tls)
1723 } 1768 }
1724 } else { 1769 } else {
1725 /* All 00xx are RSA */ 1770 /* All 00xx are RSA */
1726 if (cipherid1 == 0x2F 1771 if ((ENABLE_FEATURE_TLS_SHA1 && cipherid1 == 0x2F)
1727 || cipherid1 == 0x3C 1772 || cipherid1 == 0x3C
1728 || cipherid1 == 0x9C 1773 || cipherid1 == 0x9C
1729 ) { 1774 ) {
1730 tls->key_size = AES128_KEYSIZE; 1775 tls->key_size = AES128_KEYSIZE;
1731 } 1776 }
1732 if (cipherid1 <= 0x35) { 1777 if (ENABLE_FEATURE_TLS_SHA1 && cipherid1 <= 0x35) {
1733 tls->MAC_size = SHA1_OUTSIZE; 1778 tls->MAC_size = SHA1_OUTSIZE;
1734 } else 1779 } else
1735 if (cipherid1 == 0x9C /*|| cipherid1 == 0x9D*/) { 1780 if (cipherid1 == 0x9C /*|| cipherid1 == 0x9D*/) {
@@ -2227,7 +2272,7 @@ void FAST_FUNC tls_handshake(tls_state_t *tls, const char *sni)
2227 tls->min_encrypted_len_on_read = tls->MAC_size; 2272 tls->min_encrypted_len_on_read = tls->MAC_size;
2228 } else 2273 } else
2229 if (!(tls->flags & ENCRYPTION_AESGCM)) { 2274 if (!(tls->flags & ENCRYPTION_AESGCM)) {
2230 unsigned mac_blocks = (unsigned)(tls->MAC_size + AES_BLOCK_SIZE-1) / AES_BLOCK_SIZE; 2275 unsigned mac_blocks = (unsigned)(TLS_MAC_SIZE(tls) + AES_BLOCK_SIZE-1) / AES_BLOCK_SIZE;
2231 /* all incoming packets now should be encrypted and have 2276 /* all incoming packets now should be encrypted and have
2232 * at least IV + (MAC padded to blocksize): 2277 * at least IV + (MAC padded to blocksize):
2233 */ 2278 */
diff --git a/networking/tls_aesgcm.c b/networking/tls_aesgcm.c
index 688df85fb..a4663cd79 100644
--- a/networking/tls_aesgcm.c
+++ b/networking/tls_aesgcm.c
@@ -35,38 +35,87 @@ static ALWAYS_INLINE void FlattenSzInBits(byte* buf, word32 sz)
35 35
36static void RIGHTSHIFTX(byte* x) 36static void RIGHTSHIFTX(byte* x)
37{ 37{
38 int i; 38#define l ((unsigned long*)x)
39 int carryOut = 0; 39#if 0
40 int carryIn = 0;
41 int borrow = x[15] & 0x01;
42 40
41 // Generic byte-at-a-time algorithm
42 int i;
43 byte carryIn = (x[15] & 0x01) ? 0xE1 : 0;
43 for (i = 0; i < AES_BLOCK_SIZE; i++) { 44 for (i = 0; i < AES_BLOCK_SIZE; i++) {
44 carryOut = x[i] & 0x01; 45 byte carryOut = (x[i] << 7); // zero, or 0x80
45 x[i] = (x[i] >> 1) | (carryIn ? 0x80 : 0); 46 x[i] = (x[i] >> 1) ^ carryIn;
47 carryIn = carryOut;
48 }
49
50#elif BB_BIG_ENDIAN
51
52 // Big-endian can shift-right in larger than byte chunks
53 // (we use the fact that 'x' is long-aligned)
54 unsigned long carryIn = (x[15] & 0x01)
55 ? ((unsigned long)0xE1 << (LONG_BIT-8))
56 : 0;
57# if ULONG_MAX <= 0xffffffff
58 int i;
59 for (i = 0; i < AES_BLOCK_SIZE/sizeof(long); i++) {
60 unsigned long carryOut = l[i] << (LONG_BIT-1); // zero, or 0x800..00
61 l[i] = (l[i] >> 1) ^ carryIn;
46 carryIn = carryOut; 62 carryIn = carryOut;
47 } 63 }
48 if (borrow) x[0] ^= 0xE1; 64# else
65 // 64-bit code: need to process only 2 words
66 unsigned long carryOut = l[0] << (LONG_BIT-1); // zero, or 0x800..00
67 l[0] = (l[0] >> 1) ^ carryIn;
68 l[1] = (l[1] >> 1) ^ carryOut;
69# endif
70
71#else /* LITTLE_ENDIAN */
72
73 // In order to use word-sized ops, little-endian needs to byteswap.
74 // On x86, code size increase is ~10 bytes compared to byte-by-byte.
75 unsigned long carryIn = (x[15] & 0x01)
76 ? ((unsigned long)0xE1 << (LONG_BIT-8))
77 : 0;
78# if ULONG_MAX <= 0xffffffff
79 int i;
80 for (i = 0; i < AES_BLOCK_SIZE/sizeof(long); i++) {
81 unsigned long ti = SWAP_BE32(l[i]);
82 unsigned long carryOut = ti << (LONG_BIT-1); // zero, or 0x800..00
83 ti = (ti >> 1) ^ carryIn;
84 l[i] = SWAP_BE32(ti);
85 carryIn = carryOut;
86 }
87# else
88 // 64-bit code: need to process only 2 words
89 unsigned long tt = SWAP_BE64(l[0]);
90 unsigned long carryOut = tt << (LONG_BIT-1); // zero, or 0x800..00
91 tt = (tt >> 1) ^ carryIn; l[0] = SWAP_BE64(tt);
92 tt = SWAP_BE64(l[1]);
93 tt = (tt >> 1) ^ carryOut; l[1] = SWAP_BE64(tt);
94# endif
95
96#endif /* LITTLE_ENDIAN */
97#undef l
49} 98}
50 99
100// Caller guarantees X is aligned
51static void GMULT(byte* X, byte* Y) 101static void GMULT(byte* X, byte* Y)
52{ 102{
53 byte Z[AES_BLOCK_SIZE] ALIGNED_long; 103 byte Z[AES_BLOCK_SIZE] ALIGNED_long;
54 byte V[AES_BLOCK_SIZE] ALIGNED_long; 104 //byte V[AES_BLOCK_SIZE] ALIGNED_long;
55 int i, j; 105 int i;
56 106
57 XMEMSET(Z, 0, AES_BLOCK_SIZE); 107 XMEMSET(Z, 0, AES_BLOCK_SIZE);
58 XMEMCPY(V, X, AES_BLOCK_SIZE); 108 //XMEMCPY(V, X, AES_BLOCK_SIZE);
59 for (i = 0; i < AES_BLOCK_SIZE; i++) 109 for (i = 0; i < AES_BLOCK_SIZE; i++) {
60 { 110 uint32_t y = 0x800000 | Y[i];
61 byte y = Y[i]; 111 for (;;) { // for every bit in Y[i], from msb to lsb
62 for (j = 0; j < 8; j++)
63 {
64 if (y & 0x80) { 112 if (y & 0x80) {
65 xorbuf_aligned_AES_BLOCK_SIZE(Z, V); 113 xorbuf_aligned_AES_BLOCK_SIZE(Z, X); // was V, not X
66 } 114 }
67 115 RIGHTSHIFTX(X); // was V, not X
68 RIGHTSHIFTX(V);
69 y = y << 1; 116 y = y << 1;
117 if ((int32_t)y < 0) // if bit 0x80000000 set = if 8 iterations done
118 break;
70 } 119 }
71 } 120 }
72 XMEMCPY(X, Z, AES_BLOCK_SIZE); 121 XMEMCPY(X, Z, AES_BLOCK_SIZE);
diff --git a/networking/tls_pstm.c b/networking/tls_pstm.c
index e12e6c9d4..e5544ab11 100644
--- a/networking/tls_pstm.c
+++ b/networking/tls_pstm.c
@@ -47,13 +47,18 @@
47//#include "../cryptoApi.h" 47//#include "../cryptoApi.h"
48#ifndef DISABLE_PSTM 48#ifndef DISABLE_PSTM
49 49
50#undef pstm_mul_2d
50static int32 pstm_mul_2d(pstm_int *a, int b, pstm_int *c); //bbox: was int16 b 51static int32 pstm_mul_2d(pstm_int *a, int b, pstm_int *c); //bbox: was int16 b
52#define pstm_mul_2d(a, b, c) (pstm_mul_2d(a, b, c), PSTM_OKAY)
51 53
52/******************************************************************************/ 54/******************************************************************************/
53/* 55/*
54 init an pstm_int for a given size 56 init an pstm_int for a given size
55 */ 57 */
56int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size) 58#undef pstm_init_size
59#define pstm_init_size(pool, a, size) \
60 pstm_init_size( a, size)
61int32 FAST_FUNC pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size)
57{ 62{
58//bbox 63//bbox
59// uint16 x; 64// uint16 x;
@@ -75,12 +80,17 @@ int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size)
75// } 80// }
76 return PSTM_OKAY; 81 return PSTM_OKAY;
77} 82}
83#undef pstm_init_size
84#define pstm_init_size(pool, a, size) (pstm_init_size(a, size), PSTM_OKAY)
78 85
79/******************************************************************************/ 86/******************************************************************************/
80/* 87/*
81 Init a new pstm_int. 88 Init a new pstm_int.
82*/ 89*/
83int32 pstm_init(psPool_t *pool, pstm_int * a) 90#undef pstm_init
91#define pstm_init(pool, a) \
92 pstm_init( a)
93static int32 pstm_init(psPool_t *pool, pstm_int * a)
84{ 94{
85//bbox 95//bbox
86// int32 i; 96// int32 i;
@@ -106,12 +116,15 @@ int32 pstm_init(psPool_t *pool, pstm_int * a)
106 116
107 return PSTM_OKAY; 117 return PSTM_OKAY;
108} 118}
119#undef pstm_init
120#define pstm_init(pool, a) (pstm_init(a), PSTM_OKAY)
109 121
110/******************************************************************************/ 122/******************************************************************************/
111/* 123/*
112 Grow as required 124 Grow as required
113 */ 125 */
114int32 pstm_grow(pstm_int * a, int size) 126#undef pstm_grow
127int32 FAST_FUNC pstm_grow(pstm_int * a, int size)
115{ 128{
116 int i; //bbox: was int16 129 int i; //bbox: was int16
117 pstm_digit *tmp; 130 pstm_digit *tmp;
@@ -142,11 +155,13 @@ int32 pstm_grow(pstm_int * a, int size)
142 } 155 }
143 return PSTM_OKAY; 156 return PSTM_OKAY;
144} 157}
158#define pstm_grow(a, size) (pstm_grow(a, size), PSTM_OKAY)
145 159
146/******************************************************************************/ 160/******************************************************************************/
147/* 161/*
148 copy, b = a (b must be pre-allocated) 162 copy, b = a (b must be pre-allocated)
149 */ 163 */
164#undef pstm_copy
150int32 pstm_copy(pstm_int * a, pstm_int * b) 165int32 pstm_copy(pstm_int * a, pstm_int * b)
151{ 166{
152 int32 res, n; 167 int32 res, n;
@@ -195,6 +210,7 @@ int32 pstm_copy(pstm_int * a, pstm_int * b)
195 b->sign = a->sign; 210 b->sign = a->sign;
196 return PSTM_OKAY; 211 return PSTM_OKAY;
197} 212}
213#define pstm_copy(a, b) (pstm_copy(a, b), PSTM_OKAY)
198 214
199/******************************************************************************/ 215/******************************************************************************/
200/* 216/*
@@ -204,7 +220,7 @@ int32 pstm_copy(pstm_int * a, pstm_int * b)
204 leading "used" digit will be non-zero. Typically very fast. Also fixes 220 leading "used" digit will be non-zero. Typically very fast. Also fixes
205 the sign if there are no more leading digits 221 the sign if there are no more leading digits
206*/ 222*/
207void pstm_clamp(pstm_int * a) 223void FAST_FUNC pstm_clamp(pstm_int * a)
208{ 224{
209/* decrease used while the most significant digit is zero. */ 225/* decrease used while the most significant digit is zero. */
210 while (a->used > 0 && a->dp[a->used - 1] == 0) { 226 while (a->used > 0 && a->dp[a->used - 1] == 0) {
@@ -220,7 +236,7 @@ void pstm_clamp(pstm_int * a)
220/* 236/*
221 clear one (frees). 237 clear one (frees).
222 */ 238 */
223void pstm_clear(pstm_int * a) 239void FAST_FUNC pstm_clear(pstm_int * a)
224{ 240{
225 int32 i; 241 int32 i;
226/* 242/*
@@ -248,6 +264,7 @@ void pstm_clear(pstm_int * a)
248/* 264/*
249 clear many (frees). 265 clear many (frees).
250 */ 266 */
267#if 0 //UNUSED
251void pstm_clear_multi(pstm_int *mp0, pstm_int *mp1, pstm_int *mp2, 268void pstm_clear_multi(pstm_int *mp0, pstm_int *mp1, pstm_int *mp2,
252 pstm_int *mp3, pstm_int *mp4, pstm_int *mp5, 269 pstm_int *mp3, pstm_int *mp4, pstm_int *mp5,
253 pstm_int *mp6, pstm_int *mp7) 270 pstm_int *mp6, pstm_int *mp7)
@@ -272,12 +289,13 @@ void pstm_clear_multi(pstm_int *mp0, pstm_int *mp1, pstm_int *mp2,
272 } 289 }
273 } 290 }
274} 291}
292#endif
275 293
276/******************************************************************************/ 294/******************************************************************************/
277/* 295/*
278 Set to zero. 296 Set to zero.
279 */ 297 */
280void pstm_zero(pstm_int * a) 298static void pstm_zero(pstm_int * a)
281{ 299{
282 int32 n; 300 int32 n;
283 pstm_digit *tmp; 301 pstm_digit *tmp;
@@ -296,7 +314,7 @@ void pstm_zero(pstm_int * a)
296/* 314/*
297 Compare maginitude of two ints (unsigned). 315 Compare maginitude of two ints (unsigned).
298 */ 316 */
299int32 pstm_cmp_mag(pstm_int * a, pstm_int * b) 317int32 FAST_FUNC pstm_cmp_mag(pstm_int * a, pstm_int * b)
300{ 318{
301 int n; //bbox: was int16 319 int n; //bbox: was int16
302 pstm_digit *tmpa, *tmpb; 320 pstm_digit *tmpa, *tmpb;
@@ -336,7 +354,7 @@ int32 pstm_cmp_mag(pstm_int * a, pstm_int * b)
336/* 354/*
337 Compare two ints (signed) 355 Compare two ints (signed)
338 */ 356 */
339int32 pstm_cmp(pstm_int * a, pstm_int * b) 357int32 FAST_FUNC pstm_cmp(pstm_int * a, pstm_int * b)
340{ 358{
341/* 359/*
342 compare based on sign 360 compare based on sign
@@ -364,7 +382,7 @@ int32 pstm_cmp(pstm_int * a, pstm_int * b)
364 pstm_ints can be initialized more precisely when they will populated 382 pstm_ints can be initialized more precisely when they will populated
365 using pstm_read_unsigned_bin since the length of the byte stream is known 383 using pstm_read_unsigned_bin since the length of the byte stream is known
366*/ 384*/
367int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, uint32 len) 385int32 FAST_FUNC pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, uint32 len)
368{ 386{
369 int32 size; 387 int32 size;
370/* 388/*
@@ -385,7 +403,7 @@ int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, uint32 len)
385 called pstm_init_for_read_unsigned_bin first. There is some grow logic 403 called pstm_init_for_read_unsigned_bin first. There is some grow logic
386 here if the default pstm_init was used but we don't really want to hit it. 404 here if the default pstm_init was used but we don't really want to hit it.
387*/ 405*/
388int32 pstm_read_unsigned_bin(pstm_int *a, unsigned char *b, int32 c) 406int32 FAST_FUNC pstm_read_unsigned_bin(pstm_int *a, unsigned char *b, int32 c)
389{ 407{
390 /* zero the int */ 408 /* zero the int */
391 pstm_zero (a); 409 pstm_zero (a);
@@ -460,7 +478,7 @@ int32 pstm_read_unsigned_bin(pstm_int *a, unsigned char *b, int32 c)
460/******************************************************************************/ 478/******************************************************************************/
461/* 479/*
462*/ 480*/
463int pstm_count_bits (pstm_int * a) 481static int pstm_count_bits(pstm_int * a)
464{ 482{
465 int r; //bbox: was int16 483 int r; //bbox: was int16
466 pstm_digit q; 484 pstm_digit q;
@@ -482,14 +500,14 @@ int pstm_count_bits (pstm_int * a)
482} 500}
483 501
484/******************************************************************************/ 502/******************************************************************************/
485int32 pstm_unsigned_bin_size(pstm_int *a) 503int32 FAST_FUNC pstm_unsigned_bin_size(pstm_int *a)
486{ 504{
487 int32 size = pstm_count_bits (a); 505 int32 size = pstm_count_bits (a);
488 return (size / 8 + ((size & 7) != 0 ? 1 : 0)); 506 return (size / 8 + ((size & 7) != 0 ? 1 : 0));
489} 507}
490 508
491/******************************************************************************/ 509/******************************************************************************/
492void pstm_set(pstm_int *a, pstm_digit b) 510static void pstm_set(pstm_int *a, pstm_digit b)
493{ 511{
494 pstm_zero(a); 512 pstm_zero(a);
495 a->dp[0] = b; 513 a->dp[0] = b;
@@ -500,7 +518,7 @@ void pstm_set(pstm_int *a, pstm_digit b)
500/* 518/*
501 Right shift 519 Right shift
502*/ 520*/
503void pstm_rshd(pstm_int *a, int x) 521static void pstm_rshd(pstm_int *a, int x)
504{ 522{
505 int y; //bbox: was int16 523 int y; //bbox: was int16
506 524
@@ -529,7 +547,8 @@ void pstm_rshd(pstm_int *a, int x)
529/* 547/*
530 Shift left a certain amount of digits. 548 Shift left a certain amount of digits.
531 */ 549 */
532int32 pstm_lshd(pstm_int * a, int b) 550#undef pstm_lshd
551static int32 pstm_lshd(pstm_int * a, int b)
533{ 552{
534 int x; //bbox: was int16 553 int x; //bbox: was int16
535 int32 res; 554 int32 res;
@@ -577,12 +596,13 @@ int32 pstm_lshd(pstm_int * a, int b)
577 } 596 }
578 return PSTM_OKAY; 597 return PSTM_OKAY;
579} 598}
599#define pstm_lshd(a, b) (pstm_lshd(a, b), PSTM_OKAY)
580 600
581/******************************************************************************/ 601/******************************************************************************/
582/* 602/*
583 computes a = 2**b 603 computes a = 2**b
584*/ 604*/
585int32 pstm_2expt(pstm_int *a, int b) 605static int32 pstm_2expt(pstm_int *a, int b)
586{ 606{
587 int z; //bbox: was int16 607 int z; //bbox: was int16
588 608
@@ -616,7 +636,7 @@ int32 pstm_2expt(pstm_int *a, int b)
616/* 636/*
617 637
618*/ 638*/
619int32 pstm_mul_2(pstm_int * a, pstm_int * b) 639int32 FAST_FUNC pstm_mul_2(pstm_int * a, pstm_int * b)
620{ 640{
621 int32 res; 641 int32 res;
622 int x, oldused; //bbox: was int16 642 int x, oldused; //bbox: was int16
@@ -682,7 +702,7 @@ int32 pstm_mul_2(pstm_int * a, pstm_int * b)
682/* 702/*
683 unsigned subtraction ||a|| >= ||b|| ALWAYS! 703 unsigned subtraction ||a|| >= ||b|| ALWAYS!
684*/ 704*/
685int32 s_pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c) 705int32 FAST_FUNC s_pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c)
686{ 706{
687 int oldbused, oldused; //bbox: was int16 707 int oldbused, oldused; //bbox: was int16
688 int32 x; 708 int32 x;
@@ -779,7 +799,7 @@ static int32 s_pstm_add(pstm_int *a, pstm_int *b, pstm_int *c)
779/* 799/*
780 800
781*/ 801*/
782int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c) 802int32 FAST_FUNC pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c)
783{ 803{
784 int32 res; 804 int32 res;
785 int sa, sb; //bbox: was int16 805 int sa, sb; //bbox: was int16
@@ -824,6 +844,7 @@ int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c)
824/* 844/*
825 c = a - b 845 c = a - b
826*/ 846*/
847#if 0 //UNUSED
827int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c) 848int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c)
828{ 849{
829 pstm_int tmp; 850 pstm_int tmp;
@@ -837,12 +858,13 @@ int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c)
837 pstm_clear(&tmp); 858 pstm_clear(&tmp);
838 return res; 859 return res;
839} 860}
861#endif
840 862
841/******************************************************************************/ 863/******************************************************************************/
842/* 864/*
843 setups the montgomery reduction 865 setups the montgomery reduction
844*/ 866*/
845int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho) 867static int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho)
846{ 868{
847 pstm_digit x, b; 869 pstm_digit x, b;
848 870
@@ -878,7 +900,7 @@ int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho)
878 * computes a = B**n mod b without division or multiplication useful for 900 * computes a = B**n mod b without division or multiplication useful for
879 * normalizing numbers in a Montgomery system. 901 * normalizing numbers in a Montgomery system.
880 */ 902 */
881int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b) 903static int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b)
882{ 904{
883 int32 x; 905 int32 x;
884 int bits; //bbox: was int16 906 int bits; //bbox: was int16
@@ -916,6 +938,7 @@ int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b)
916/* 938/*
917 c = a * 2**d 939 c = a * 2**d
918*/ 940*/
941#undef pstm_mul_2d
919static int32 pstm_mul_2d(pstm_int *a, int b, pstm_int *c) 942static int32 pstm_mul_2d(pstm_int *a, int b, pstm_int *c)
920{ 943{
921 pstm_digit carry, carrytmp, shift; 944 pstm_digit carry, carrytmp, shift;
@@ -956,11 +979,13 @@ static int32 pstm_mul_2d(pstm_int *a, int b, pstm_int *c)
956 pstm_clamp(c); 979 pstm_clamp(c);
957 return PSTM_OKAY; 980 return PSTM_OKAY;
958} 981}
982#define pstm_mul_2d(a, b, c) (pstm_mul_2d(a, b, c), PSTM_OKAY)
959 983
960/******************************************************************************/ 984/******************************************************************************/
961/* 985/*
962 c = a mod 2**d 986 c = a mod 2**d
963*/ 987*/
988#undef pstm_mod_2d
964static int32 pstm_mod_2d(pstm_int *a, int b, pstm_int *c) //bbox: was int16 b 989static int32 pstm_mod_2d(pstm_int *a, int b, pstm_int *c) //bbox: was int16 b
965{ 990{
966 int x; //bbox: was int16 991 int x; //bbox: was int16
@@ -991,13 +1016,15 @@ static int32 pstm_mod_2d(pstm_int *a, int b, pstm_int *c) //bbox: was int16 b
991 pstm_clamp (c); 1016 pstm_clamp (c);
992 return PSTM_OKAY; 1017 return PSTM_OKAY;
993} 1018}
1019#define pstm_mod_2d(a, b, c) (pstm_mod_2d(a, b, c), PSTM_OKAY)
994 1020
995 1021
996/******************************************************************************/ 1022/******************************************************************************/
997/* 1023/*
998 c = a * b 1024 c = a * b
999*/ 1025*/
1000int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c) 1026#undef pstm_mul_d
1027static int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c)
1001{ 1028{
1002 pstm_word w; 1029 pstm_word w;
1003 int32 res; 1030 int32 res;
@@ -1027,12 +1054,16 @@ int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c)
1027 pstm_clamp(c); 1054 pstm_clamp(c);
1028 return PSTM_OKAY; 1055 return PSTM_OKAY;
1029} 1056}
1057#define pstm_mul_d(a, b, c) (pstm_mul_d(a, b, c), PSTM_OKAY)
1030 1058
1031/******************************************************************************/ 1059/******************************************************************************/
1032/* 1060/*
1033 c = a / 2**b 1061 c = a / 2**b
1034*/ 1062*/
1035int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int b, pstm_int *c, 1063#undef pstm_div_2d
1064#define pstm_div_2d(pool, a, b, c, d) \
1065 pstm_div_2d( a, b, c, d)
1066static int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int b, pstm_int *c,
1036 pstm_int *d) 1067 pstm_int *d)
1037{ 1068{
1038 pstm_digit D, r, rr; 1069 pstm_digit D, r, rr;
@@ -1113,11 +1144,14 @@ LBL_DONE:
1113 } 1144 }
1114 return res; 1145 return res;
1115} 1146}
1147#undef pstm_div_2d
1148#define pstm_div_2d(pool, a, b, c, d) (pstm_div_2d(a, b, c, d), PSTM_OKAY)
1116 1149
1117/******************************************************************************/ 1150/******************************************************************************/
1118/* 1151/*
1119 b = a/2 1152 b = a/2
1120*/ 1153*/
1154#if 0 //UNUSED
1121int32 pstm_div_2(pstm_int * a, pstm_int * b) 1155int32 pstm_div_2(pstm_int * a, pstm_int * b)
1122{ 1156{
1123 int x, oldused; //bbox: was int16 1157 int x, oldused; //bbox: was int16
@@ -1161,12 +1195,16 @@ int32 pstm_div_2(pstm_int * a, pstm_int * b)
1161 pstm_clamp (b); 1195 pstm_clamp (b);
1162 return PSTM_OKAY; 1196 return PSTM_OKAY;
1163} 1197}
1198#endif
1164 1199
1165/******************************************************************************/ 1200/******************************************************************************/
1166/* 1201/*
1167 Creates "a" then copies b into it 1202 Creates "a" then copies b into it
1168 */ 1203 */
1169int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, int toSqr) 1204#undef pstm_init_copy
1205#define pstm_init_copy(pool, a, b, toSqr) \
1206 pstm_init_copy( a, b, toSqr)
1207static int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, int toSqr)
1170{ 1208{
1171 int x; //bbox: was int16 1209 int x; //bbox: was int16
1172 int32 res; 1210 int32 res;
@@ -1191,6 +1229,8 @@ int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, int toSqr)
1191 } 1229 }
1192 return pstm_copy(b, a); 1230 return pstm_copy(b, a);
1193} 1231}
1232#undef pstm_init_copy
1233#define pstm_init_copy(pool, a, b, toSqr) (pstm_init_copy(a, b, toSqr), PSTM_OKAY)
1194 1234
1195/******************************************************************************/ 1235/******************************************************************************/
1196/* 1236/*
@@ -1274,7 +1314,7 @@ static uint64 psDiv128(uint128 *numerator, uint64 denominator)
1274/* 1314/*
1275 a/b => cb + d == a 1315 a/b => cb + d == a
1276*/ 1316*/
1277int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, 1317static int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c,
1278 pstm_int *d) 1318 pstm_int *d)
1279{ 1319{
1280 pstm_int q, x, y, t1, t2; 1320 pstm_int q, x, y, t1, t2;
@@ -1487,7 +1527,7 @@ LBL_T1:pstm_clear (&t1);
1487 Swap the elements of two integers, for cases where you can't simply swap 1527 Swap the elements of two integers, for cases where you can't simply swap
1488 the pstm_int pointers around 1528 the pstm_int pointers around
1489*/ 1529*/
1490void pstm_exch(pstm_int * a, pstm_int * b) 1530static void pstm_exch(pstm_int * a, pstm_int * b)
1491{ 1531{
1492 pstm_int t; 1532 pstm_int t;
1493 1533
@@ -1500,7 +1540,7 @@ void pstm_exch(pstm_int * a, pstm_int * b)
1500/* 1540/*
1501 c = a mod b, 0 <= c < b 1541 c = a mod b, 0 <= c < b
1502*/ 1542*/
1503int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c) 1543static int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c)
1504{ 1544{
1505 pstm_int t; 1545 pstm_int t;
1506 int32 err; 1546 int32 err;
@@ -1527,7 +1567,7 @@ int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c)
1527/* 1567/*
1528 d = a * b (mod c) 1568 d = a * b (mod c)
1529*/ 1569*/
1530int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, 1570int32 FAST_FUNC pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c,
1531 pstm_int *d) 1571 pstm_int *d)
1532{ 1572{
1533 int32 res; 1573 int32 res;
@@ -1560,7 +1600,7 @@ int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c,
1560 * y = g**x (mod b) 1600 * y = g**x (mod b)
1561 * Some restrictions... x must be positive and < b 1601 * Some restrictions... x must be positive and < b
1562 */ 1602 */
1563int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P, 1603int32 FAST_FUNC pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P,
1564 pstm_int *Y) 1604 pstm_int *Y)
1565{ 1605{
1566 pstm_int M[32], res; /* Keep this winsize based: (1 << max_winsize) */ 1606 pstm_int M[32], res; /* Keep this winsize based: (1 << max_winsize) */
@@ -1801,7 +1841,7 @@ LBL_RES:pstm_clear(&res);
1801/* 1841/*
1802 1842
1803*/ 1843*/
1804int32 pstm_add(pstm_int *a, pstm_int *b, pstm_int *c) 1844int32 FAST_FUNC pstm_add(pstm_int *a, pstm_int *b, pstm_int *c)
1805{ 1845{
1806 int32 res; 1846 int32 res;
1807 int sa, sb; //bbox: was int16 1847 int sa, sb; //bbox: was int16
@@ -1862,6 +1902,7 @@ static void pstm_reverse (unsigned char *s, int len) //bbox: was int16 len
1862 No reverse. Useful in some of the EIP-154 PKA stuff where special byte 1902 No reverse. Useful in some of the EIP-154 PKA stuff where special byte
1863 order seems to come into play more often 1903 order seems to come into play more often
1864*/ 1904*/
1905#if 0 //UNUSED
1865int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, unsigned char *b) 1906int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, unsigned char *b)
1866{ 1907{
1867 int32 res; 1908 int32 res;
@@ -1883,11 +1924,12 @@ int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, unsigned char *b)
1883 pstm_clear(&t); 1924 pstm_clear(&t);
1884 return PS_SUCCESS; 1925 return PS_SUCCESS;
1885} 1926}
1927#endif
1886/******************************************************************************/ 1928/******************************************************************************/
1887/* 1929/*
1888 1930
1889*/ 1931*/
1890int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, unsigned char *b) 1932int32 FAST_FUNC pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, unsigned char *b)
1891{ 1933{
1892 int32 res; 1934 int32 res;
1893 int x; //bbox: was int16 1935 int x; //bbox: was int16
@@ -1910,11 +1952,12 @@ int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, unsigned char *b)
1910 return PS_SUCCESS; 1952 return PS_SUCCESS;
1911} 1953}
1912 1954
1955#if 0 //UNUSED
1913/******************************************************************************/ 1956/******************************************************************************/
1914/* 1957/*
1915 compare against a single digit 1958 compare against a single digit
1916*/ 1959*/
1917int32 pstm_cmp_d(pstm_int *a, pstm_digit b) 1960static int32 pstm_cmp_d(pstm_int *a, pstm_digit b)
1918{ 1961{
1919 /* compare based on sign */ 1962 /* compare based on sign */
1920 if ((b && a->used == 0) || a->sign == PSTM_NEG) { 1963 if ((b && a->used == 0) || a->sign == PSTM_NEG) {
@@ -2259,5 +2302,7 @@ LBL_Y: pstm_clear(&y);
2259LBL_X: pstm_clear(&x); 2302LBL_X: pstm_clear(&x);
2260 return res; 2303 return res;
2261} 2304}
2305#endif //UNUSED
2306
2262#endif /* !DISABLE_PSTM */ 2307#endif /* !DISABLE_PSTM */
2263/******************************************************************************/ 2308/******************************************************************************/
diff --git a/networking/tls_pstm.h b/networking/tls_pstm.h
index df705adce..bc7a0119a 100644
--- a/networking/tls_pstm.h
+++ b/networking/tls_pstm.h
@@ -136,148 +136,148 @@ typedef struct {
136#define pstm_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? PS_TRUE : PS_FALSE) 136#define pstm_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? PS_TRUE : PS_FALSE)
137#define pstm_abs(a, b) { pstm_copy(a, b); (b)->sign = 0; } 137#define pstm_abs(a, b) { pstm_copy(a, b); (b)->sign = 0; }
138 138
139extern void pstm_set(pstm_int *a, pstm_digit b); 139//made static:extern void pstm_set(pstm_int *a, pstm_digit b);
140 140
141extern void pstm_zero(pstm_int * a); 141//made static:extern void pstm_zero(pstm_int * a);
142 142
143//bbox: pool unused 143//bbox: pool unused
144#define pstm_init(pool, a) \ 144#define pstm_init(pool, a) \
145 pstm_init( a) 145 pstm_init( a)
146extern int32 pstm_init(psPool_t *pool, pstm_int * a); 146//made static:extern int32 pstm_init(psPool_t *pool, pstm_int * a);
147 147
148//bbox: pool unused 148//bbox: pool unused
149#define pstm_init_size(pool, a, size) \ 149#define pstm_init_size(pool, a, size) \
150 pstm_init_size( a, size) 150 pstm_init_size( a, size)
151extern int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size); 151extern int32 pstm_init_size(psPool_t *pool, pstm_int * a, uint32 size) FAST_FUNC;
152 152
153//bbox: pool unused 153//bbox: pool unused
154#define pstm_init_copy(pool, a, b, toSqr) \ 154#define pstm_init_copy(pool, a, b, toSqr) \
155 pstm_init_copy( a, b, toSqr) 155 pstm_init_copy( a, b, toSqr)
156extern int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b, 156//made static:extern int32 pstm_init_copy(psPool_t *pool, pstm_int * a, pstm_int * b,
157 int toSqr); //bbox: was int16 toSqr 157//made static: int toSqr); //bbox: was int16 toSqr
158 158
159extern int pstm_count_bits (pstm_int * a); //bbox: was returning int16 159//made static:extern int pstm_count_bits (pstm_int * a) FAST_FUNC; //bbox: was returning int16
160 160
161//bbox: pool unused 161//bbox: pool unused
162#define pstm_init_for_read_unsigned_bin(pool, a, len) \ 162#define pstm_init_for_read_unsigned_bin(pool, a, len) \
163 pstm_init_for_read_unsigned_bin( a, len) 163 pstm_init_for_read_unsigned_bin( a, len)
164extern int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a, 164extern int32 pstm_init_for_read_unsigned_bin(psPool_t *pool, pstm_int *a,
165 uint32 len); 165 uint32 len) FAST_FUNC;
166 166
167extern int32 pstm_read_unsigned_bin(pstm_int *a, unsigned char *b, int32 c); 167extern int32 pstm_read_unsigned_bin(pstm_int *a, unsigned char *b, int32 c) FAST_FUNC;
168 168
169extern int32 pstm_unsigned_bin_size(pstm_int *a); 169extern int32 pstm_unsigned_bin_size(pstm_int *a) FAST_FUNC;
170 170
171extern int32 pstm_copy(pstm_int * a, pstm_int * b); 171extern int32 pstm_copy(pstm_int * a, pstm_int * b);
172 172
173extern void pstm_exch(pstm_int * a, pstm_int * b); 173//made static:extern void pstm_exch(pstm_int * a, pstm_int * b);
174 174
175extern void pstm_clear(pstm_int * a); 175extern void pstm_clear(pstm_int * a) FAST_FUNC;
176 176
177extern void pstm_clear_multi(pstm_int *mp0, pstm_int *mp1, pstm_int *mp2, 177extern void pstm_clear_multi(pstm_int *mp0, pstm_int *mp1, pstm_int *mp2,
178 pstm_int *mp3, pstm_int *mp4, pstm_int *mp5, pstm_int *mp6, 178 pstm_int *mp3, pstm_int *mp4, pstm_int *mp5, pstm_int *mp6,
179 pstm_int *mp7); 179 pstm_int *mp7) FAST_FUNC;
180 180
181extern int32 pstm_grow(pstm_int * a, int size); //bbox: was int16 size 181extern int32 pstm_grow(pstm_int * a, int size) FAST_FUNC; //bbox: was int16 size
182 182
183extern void pstm_clamp(pstm_int * a); 183extern void pstm_clamp(pstm_int * a) FAST_FUNC;
184 184
185extern int32 pstm_cmp(pstm_int * a, pstm_int * b); 185extern int32 pstm_cmp(pstm_int * a, pstm_int * b) FAST_FUNC;
186 186
187extern int32 pstm_cmp_mag(pstm_int * a, pstm_int * b); 187extern int32 pstm_cmp_mag(pstm_int * a, pstm_int * b) FAST_FUNC;
188 188
189extern void pstm_rshd(pstm_int *a, int x); //bbox: was int16 x 189//made static:extern void pstm_rshd(pstm_int *a, int x); //bbox: was int16 x
190 190
191extern int32 pstm_lshd(pstm_int * a, int b); //bbox: was int16 b 191//made static:extern int32 pstm_lshd(pstm_int * a, int b); //bbox: was int16 b
192 192
193//bbox: pool unused 193//bbox: pool unused
194#define pstm_div(pool, a, b, c, d) \ 194#define pstm_div(pool, a, b, c, d) \
195 pstm_div( a, b, c, d) 195 pstm_div( a, b, c, d)
196extern int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, 196//made static:extern int32 pstm_div(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c,
197 pstm_int *d); 197//made static: pstm_int *d);
198 198
199//bbox: pool unused 199//bbox: pool unused
200#define pstm_div_2d(pool, a, b, c, d) \ 200#define pstm_div_2d(pool, a, b, c, d) \
201 pstm_div_2d( a, b, c, d) 201 pstm_div_2d( a, b, c, d)
202extern int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int b, pstm_int *c, 202//made static:extern int32 pstm_div_2d(psPool_t *pool, pstm_int *a, int b, pstm_int *c,
203 pstm_int *d); //bbox: was int16 b 203//made static: pstm_int *d); //bbox: was int16 b
204 204
205extern int32 pstm_div_2(pstm_int * a, pstm_int * b); 205extern int32 pstm_div_2(pstm_int * a, pstm_int * b) FAST_FUNC;
206 206
207extern int32 s_pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c); 207extern int32 s_pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c) FAST_FUNC;
208 208
209extern int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c); 209extern int32 pstm_sub(pstm_int *a, pstm_int *b, pstm_int *c) FAST_FUNC;
210 210
211//bbox: pool unused 211//bbox: pool unused
212#define pstm_sub_d(pool, a, b, c) \ 212#define pstm_sub_d(pool, a, b, c) \
213 pstm_sub_d( a, b, c) 213 pstm_sub_d( a, b, c)
214extern int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c); 214extern int32 pstm_sub_d(psPool_t *pool, pstm_int *a, pstm_digit b, pstm_int *c) FAST_FUNC;
215 215
216extern int32 pstm_mul_2(pstm_int * a, pstm_int * b); 216extern int32 pstm_mul_2(pstm_int * a, pstm_int * b) FAST_FUNC;
217 217
218//bbox: pool unused 218//bbox: pool unused
219#define pstm_mod(pool, a, b, c) \ 219#define pstm_mod(pool, a, b, c) \
220 pstm_mod( a, b, c) 220 pstm_mod( a, b, c)
221extern int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c); 221//made static:extern int32 pstm_mod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c);
222 222
223//bbox: pool unused 223//bbox: pool unused
224#define pstm_mulmod(pool, a, b, c, d) \ 224#define pstm_mulmod(pool, a, b, c, d) \
225 pstm_mulmod( a, b, c, d) 225 pstm_mulmod( a, b, c, d)
226extern int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c, 226extern int32 pstm_mulmod(psPool_t *pool, pstm_int *a, pstm_int *b, pstm_int *c,
227 pstm_int *d); 227 pstm_int *d) FAST_FUNC;
228 228
229//bbox: pool unused 229//bbox: pool unused
230#define pstm_exptmod(pool, G, X, P, Y) \ 230#define pstm_exptmod(pool, G, X, P, Y) \
231 pstm_exptmod( G, X, P, Y) 231 pstm_exptmod( G, X, P, Y)
232extern int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P, 232extern int32 pstm_exptmod(psPool_t *pool, pstm_int *G, pstm_int *X, pstm_int *P,
233 pstm_int *Y); 233 pstm_int *Y) FAST_FUNC;
234 234
235extern int32 pstm_2expt(pstm_int *a, int b); //bbox: was int16 b 235//made static:extern int32 pstm_2expt(pstm_int *a, int b); //bbox: was int16 b
236 236
237extern int32 pstm_add(pstm_int *a, pstm_int *b, pstm_int *c); 237extern int32 pstm_add(pstm_int *a, pstm_int *b, pstm_int *c) FAST_FUNC;
238 238
239//bbox: pool unused 239//bbox: pool unused
240#define pstm_to_unsigned_bin(pool, a, b) \ 240#define pstm_to_unsigned_bin(pool, a, b) \
241 pstm_to_unsigned_bin( a, b) 241 pstm_to_unsigned_bin( a, b)
242extern int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a, 242extern int32 pstm_to_unsigned_bin(psPool_t *pool, pstm_int *a,
243 unsigned char *b); 243 unsigned char *b) FAST_FUNC;
244 244
245//bbox: pool unused 245//bbox: pool unused
246#define pstm_to_unsigned_bin_nr(pool, a, b) \ 246#define pstm_to_unsigned_bin_nr(pool, a, b) \
247 pstm_to_unsigned_bin_nr( a, b) 247 pstm_to_unsigned_bin_nr( a, b)
248extern int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a, 248extern int32 pstm_to_unsigned_bin_nr(psPool_t *pool, pstm_int *a,
249 unsigned char *b); 249 unsigned char *b) FAST_FUNC;
250 250
251extern int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho); 251//made static:extern int32 pstm_montgomery_setup(pstm_int *a, pstm_digit *rho);
252 252
253//bbox: pool unused 253//bbox: pool unused
254#define pstm_montgomery_reduce(pool, a, m, mp, paD, paDlen) \ 254#define pstm_montgomery_reduce(pool, a, m, mp, paD, paDlen) \
255 pstm_montgomery_reduce( a, m, mp, paD, paDlen) 255 pstm_montgomery_reduce( a, m, mp, paD, paDlen)
256extern int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, 256extern int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m,
257 pstm_digit mp, pstm_digit *paD, uint32 paDlen); 257 pstm_digit mp, pstm_digit *paD, uint32 paDlen) FAST_FUNC;
258 258
259#define pstm_mul_comba(pool, A, B, C, paD, paDlen) \ 259#define pstm_mul_comba(pool, A, B, C, paD, paDlen) \
260 pstm_mul_comba( A, B, C, paD, paDlen) 260 pstm_mul_comba( A, B, C, paD, paDlen)
261extern int32 pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B, 261extern int32 pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B,
262 pstm_int *C, pstm_digit *paD, uint32 paDlen); 262 pstm_int *C, pstm_digit *paD, uint32 paDlen) FAST_FUNC;
263 263
264//bbox: pool unused 264//bbox: pool unused
265#define pstm_sqr_comba(pool, A, B, paD, paDlen) \ 265#define pstm_sqr_comba(pool, A, B, paD, paDlen) \
266 pstm_sqr_comba( A, B, paD, paDlen) 266 pstm_sqr_comba( A, B, paD, paDlen)
267extern int32 pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B, 267extern int32 pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B,
268 pstm_digit *paD, uint32 paDlen); 268 pstm_digit *paD, uint32 paDlen) FAST_FUNC;
269 269
270extern int32 pstm_cmp_d(pstm_int *a, pstm_digit b); 270//made static:extern int32 pstm_cmp_d(pstm_int *a, pstm_digit b);
271 271
272extern int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b); 272//made static:extern int32 pstm_montgomery_calc_normalization(pstm_int *a, pstm_int *b);
273 273
274extern int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c); 274//made static:extern int32 pstm_mul_d(pstm_int *a, pstm_digit b, pstm_int *c);
275 275
276//bbox: pool unused 276//bbox: pool unused
277#define pstm_invmod(pool, a, b, c) \ 277#define pstm_invmod(pool, a, b, c) \
278 pstm_invmod( a, b, c) 278 pstm_invmod( a, b, c)
279extern int32 pstm_invmod(psPool_t *pool, pstm_int * a, pstm_int * b, 279extern int32 pstm_invmod(psPool_t *pool, pstm_int * a, pstm_int * b,
280 pstm_int * c); 280 pstm_int * c) FAST_FUNC;
281 281
282#else /* DISABLE_PSTM */ 282#else /* DISABLE_PSTM */
283 typedef int32 pstm_int; 283 typedef int32 pstm_int;
diff --git a/networking/tls_pstm_montgomery_reduce.c b/networking/tls_pstm_montgomery_reduce.c
index 3391755e1..d46e2aa2b 100644
--- a/networking/tls_pstm_montgomery_reduce.c
+++ b/networking/tls_pstm_montgomery_reduce.c
@@ -340,7 +340,7 @@ asm( \
340#define LO 0 340#define LO 0
341 341
342/* computes x/R == x (mod N) via Montgomery Reduction */ 342/* computes x/R == x (mod N) via Montgomery Reduction */
343int32 pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m, 343int32 FAST_FUNC pstm_montgomery_reduce(psPool_t *pool, pstm_int *a, pstm_int *m,
344 pstm_digit mp, pstm_digit *paD, uint32 paDlen) 344 pstm_digit mp, pstm_digit *paD, uint32 paDlen)
345{ 345{
346 pstm_digit *c, *_c, *tmpm, mu; 346 pstm_digit *c, *_c, *tmpm, mu;
diff --git a/networking/tls_pstm_mul_comba.c b/networking/tls_pstm_mul_comba.c
index 6ba152bc1..ac4fcc3ef 100644
--- a/networking/tls_pstm_mul_comba.c
+++ b/networking/tls_pstm_mul_comba.c
@@ -754,7 +754,7 @@ static int32 pstm_mul_comba32(pstm_int *A, pstm_int *B, pstm_int *C)
754 754
755/******************************************************************************/ 755/******************************************************************************/
756 756
757int32 pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B, pstm_int *C, 757int32 FAST_FUNC pstm_mul_comba(psPool_t *pool, pstm_int *A, pstm_int *B, pstm_int *C,
758 pstm_digit *paD, uint32 paDlen) 758 pstm_digit *paD, uint32 paDlen)
759{ 759{
760#ifdef USE_1024_KEY_SPEED_OPTIMIZATIONS 760#ifdef USE_1024_KEY_SPEED_OPTIMIZATIONS
diff --git a/networking/tls_pstm_sqr_comba.c b/networking/tls_pstm_sqr_comba.c
index d5c74d2f0..8604132d6 100644
--- a/networking/tls_pstm_sqr_comba.c
+++ b/networking/tls_pstm_sqr_comba.c
@@ -1085,7 +1085,7 @@ static int32 pstm_sqr_comba32(pstm_int *A, pstm_int *B)
1085/******************************************************************************/ 1085/******************************************************************************/
1086/* 1086/*
1087 */ 1087 */
1088int32 pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B, pstm_digit *paD, 1088int32 FAST_FUNC pstm_sqr_comba(psPool_t *pool, pstm_int *A, pstm_int *B, pstm_digit *paD,
1089 uint32 paDlen) 1089 uint32 paDlen)
1090{ 1090{
1091#ifdef USE_1024_KEY_SPEED_OPTIMIZATIONS 1091#ifdef USE_1024_KEY_SPEED_OPTIMIZATIONS
diff --git a/networking/tls_rsa.c b/networking/tls_rsa.c
index 631397e4d..5fda1cb49 100644
--- a/networking/tls_rsa.c
+++ b/networking/tls_rsa.c
@@ -173,7 +173,9 @@ error:
173 res = PS_FAILURE; 173 res = PS_FAILURE;
174done: 174done:
175 if (type == PRIVKEY_TYPE && key->optimized) { 175 if (type == PRIVKEY_TYPE && key->optimized) {
176 pstm_clear_multi(&tmpa, &tmpb, NULL, NULL, NULL, NULL, NULL, NULL); 176 //pstm_clear_multi(&tmpa, &tmpb, NULL, NULL, NULL, NULL, NULL, NULL);
177 pstm_clear(&tmpa);
178 pstm_clear(&tmpb);
177 } 179 }
178 pstm_clear(&tmp); 180 pstm_clear(&tmp);
179 return res; 181 return res;
diff --git a/networking/traceroute.c b/networking/traceroute.c
index a027b928a..bdf451186 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -217,7 +217,7 @@
217//config: Utility to trace the route of IP packets. 217//config: Utility to trace the route of IP packets.
218//config: 218//config:
219//config:config TRACEROUTE6 219//config:config TRACEROUTE6
220//config: bool "traceroute6 (12 kb)" 220//config: bool "traceroute6 (13 kb)"
221//config: default y 221//config: default y
222//config: depends on FEATURE_IPV6 222//config: depends on FEATURE_IPV6
223//config: help 223//config: help
diff --git a/networking/tunctl.c b/networking/tunctl.c
index f2dc645a1..a0e3926e9 100644
--- a/networking/tunctl.c
+++ b/networking/tunctl.c
@@ -10,7 +10,7 @@
10 * Licensed under GPLv2, see file LICENSE in this source tree. 10 * Licensed under GPLv2, see file LICENSE in this source tree.
11 */ 11 */
12//config:config TUNCTL 12//config:config TUNCTL
13//config: bool "tunctl (6.4 kb)" 13//config: bool "tunctl (6.2 kb)"
14//config: default y 14//config: default y
15//config: select PLATFORM_LINUX 15//config: select PLATFORM_LINUX
16//config: help 16//config: help
diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src
index e5958804b..f16fc0a4f 100644
--- a/networking/udhcp/Config.src
+++ b/networking/udhcp/Config.src
@@ -4,7 +4,7 @@
4# 4#
5 5
6config UDHCPD 6config UDHCPD
7 bool "udhcpd" 7 bool "udhcpd (21 kb)"
8 default y 8 default y
9 select PLATFORM_LINUX 9 select PLATFORM_LINUX
10 help 10 help
@@ -44,7 +44,7 @@ config DHCPD_LEASES_FILE
44 of the file. Normally it is safe to leave it untouched. 44 of the file. Normally it is safe to leave it untouched.
45 45
46config DUMPLEASES 46config DUMPLEASES
47 bool "dumpleases (6.4 kb)" 47 bool "dumpleases (5.1 kb)"
48 default y 48 default y
49 help 49 help
50 dumpleases displays the leases written out by the udhcpd. 50 dumpleases displays the leases written out by the udhcpd.
@@ -52,7 +52,7 @@ config DUMPLEASES
52 by the absolute time that it expires in seconds from epoch. 52 by the absolute time that it expires in seconds from epoch.
53 53
54config DHCPRELAY 54config DHCPRELAY
55 bool "dhcprelay (5.8 kb)" 55 bool "dhcprelay (5.2 kb)"
56 default y 56 default y
57 help 57 help
58 dhcprelay listens for DHCP requests on one or more interfaces 58 dhcprelay listens for DHCP requests on one or more interfaces
@@ -60,7 +60,7 @@ config DHCPRELAY
60 server. 60 server.
61 61
62config UDHCPC 62config UDHCPC
63 bool "udhcpc" 63 bool "udhcpc (24 kb)"
64 default y 64 default y
65 select PLATFORM_LINUX 65 select PLATFORM_LINUX
66 help 66 help
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index e5fd74f91..fc4de5716 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -272,6 +272,15 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
272 goto complain; /* complain and return NULL */ 272 goto complain; /* complain and return NULL */
273 273
274 if (optionptr[OPT_CODE] == code) { 274 if (optionptr[OPT_CODE] == code) {
275 if (optionptr[OPT_LEN] == 0) {
276 /* So far no valid option with length 0 known.
277 * Having this check means that searching
278 * for DHCP_MESSAGE_TYPE need not worry
279 * that returned pointer might be unsafe
280 * to dereference.
281 */
282 goto complain; /* complain and return NULL */
283 }
275 log_option("option found", optionptr); 284 log_option("option found", optionptr);
276 return optionptr + OPT_DATA; 285 return optionptr + OPT_DATA;
277 } 286 }
@@ -289,6 +298,16 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
289 return NULL; 298 return NULL;
290} 299}
291 300
301uint8_t* FAST_FUNC udhcp_get_option32(struct dhcp_packet *packet, int code)
302{
303 uint8_t *r = udhcp_get_option(packet, code);
304 if (r) {
305 if (r[-OPT_DATA + OPT_LEN] != 4)
306 r = NULL;
307 }
308 return r;
309}
310
292/* Return the position of the 'end' option (no bounds checking) */ 311/* Return the position of the 'end' option (no bounds checking) */
293int FAST_FUNC udhcp_end_option(uint8_t *optionptr) 312int FAST_FUNC udhcp_end_option(uint8_t *optionptr)
294{ 313{
@@ -403,6 +422,7 @@ static NOINLINE void attach_option(
403 if (errno) 422 if (errno)
404 bb_error_msg_and_die("malformed hex string '%s'", buffer); 423 bb_error_msg_and_die("malformed hex string '%s'", buffer);
405 length = end - allocated; 424 length = end - allocated;
425 buffer = allocated;
406 } 426 }
407#if ENABLE_FEATURE_UDHCP_RFC3397 427#if ENABLE_FEATURE_UDHCP_RFC3397
408 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { 428 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
@@ -422,15 +442,14 @@ static NOINLINE void attach_option(
422 new->data = xmalloc(length + OPT_DATA); 442 new->data = xmalloc(length + OPT_DATA);
423 new->data[OPT_CODE] = optflag->code; 443 new->data[OPT_CODE] = optflag->code;
424 new->data[OPT_LEN] = length; 444 new->data[OPT_LEN] = length;
425 memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), 445 memcpy(new->data + OPT_DATA, buffer, length);
426 length);
427 } else { 446 } else {
428 new->data = xmalloc(length + D6_OPT_DATA); 447 new->data = xmalloc(length + D6_OPT_DATA);
429 new->data[D6_OPT_CODE] = optflag->code >> 8; 448 new->data[D6_OPT_CODE] = optflag->code >> 8;
430 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff; 449 new->data[D6_OPT_CODE + 1] = optflag->code & 0xff;
431 new->data[D6_OPT_LEN] = length >> 8; 450 new->data[D6_OPT_LEN] = length >> 8;
432 new->data[D6_OPT_LEN + 1] = length & 0xff; 451 new->data[D6_OPT_LEN + 1] = length & 0xff;
433 memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer), 452 memcpy(new->data + D6_OPT_DATA, buffer,
434 length); 453 length);
435 } 454 }
436 455
@@ -453,6 +472,8 @@ static NOINLINE void attach_option(
453 /* actually 255 is ok too, but adding a space can overlow it */ 472 /* actually 255 is ok too, but adding a space can overlow it */
454 473
455 existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); 474 existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length);
475// So far dhcp_optflags[] has no OPTION_STRING[_HOST] | OPTION_LIST items
476#if 0
456 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING 477 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING
457 || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST 478 || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST
458 ) { 479 ) {
@@ -460,7 +481,9 @@ static NOINLINE void attach_option(
460 existing->data[OPT_DATA + old_len] = ' '; 481 existing->data[OPT_DATA + old_len] = ' ';
461 old_len++; 482 old_len++;
462 } 483 }
463 memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length); 484#endif
485
486 memcpy(existing->data + OPT_DATA + old_len, buffer, length);
464 existing->data[OPT_LEN] = old_len + length; 487 existing->data[OPT_LEN] = old_len + length;
465 } /* else, ignore the data, we could put this in a second option in the future */ 488 } /* else, ignore the data, we could put this in a second option in the future */
466 } /* else, ignore the new data */ 489 } /* else, ignore the new data */
@@ -534,7 +557,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg,
534 if (retval) 557 if (retval)
535 retval = udhcp_str2nip(val, buffer + 4); 558 retval = udhcp_str2nip(val, buffer + 4);
536 break; 559 break;
537case_OPTION_STRING: 560 case_OPTION_STRING:
538 case OPTION_STRING: 561 case OPTION_STRING:
539 case OPTION_STRING_HOST: 562 case OPTION_STRING_HOST:
540#if ENABLE_FEATURE_UDHCP_RFC3397 563#if ENABLE_FEATURE_UDHCP_RFC3397
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index 7ad603d33..62f9a2a4a 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -119,7 +119,7 @@ enum {
119//#define DHCP_TIME_SERVER 0x04 /* RFC 868 time server (32-bit, 0 = 1.1.1900) */ 119//#define DHCP_TIME_SERVER 0x04 /* RFC 868 time server (32-bit, 0 = 1.1.1900) */
120//#define DHCP_NAME_SERVER 0x05 /* IEN 116 _really_ ancient kind of NS */ 120//#define DHCP_NAME_SERVER 0x05 /* IEN 116 _really_ ancient kind of NS */
121//#define DHCP_DNS_SERVER 0x06 121//#define DHCP_DNS_SERVER 0x06
122//#define DHCP_LOG_SERVER 0x07 /* port 704 UDP log (not syslog) 122//#define DHCP_LOG_SERVER 0x07 /* port 704 UDP log (not syslog) */
123//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */ 123//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */
124//#define DHCP_LPR_SERVER 0x09 124//#define DHCP_LPR_SERVER 0x09
125#define DHCP_HOST_NAME 0x0c /* 12: either client informs server or server gives name to client */ 125#define DHCP_HOST_NAME 0x0c /* 12: either client informs server or server gives name to client */
@@ -205,6 +205,10 @@ extern const uint8_t dhcp_option_lengths[] ALIGN1;
205unsigned FAST_FUNC udhcp_option_idx(const char *name, const char *option_strings); 205unsigned FAST_FUNC udhcp_option_idx(const char *name, const char *option_strings);
206 206
207uint8_t *udhcp_get_option(struct dhcp_packet *packet, int code) FAST_FUNC; 207uint8_t *udhcp_get_option(struct dhcp_packet *packet, int code) FAST_FUNC;
208/* Same as above + ensures that option length is 4 bytes
209 * (returns NULL if size is different)
210 */
211uint8_t *udhcp_get_option32(struct dhcp_packet *packet, int code) FAST_FUNC;
208int udhcp_end_option(uint8_t *optionptr) FAST_FUNC; 212int udhcp_end_option(uint8_t *optionptr) FAST_FUNC;
209void udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt) FAST_FUNC; 213void udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt) FAST_FUNC;
210#if ENABLE_UDHCPC || ENABLE_UDHCPD 214#if ENABLE_UDHCPC || ENABLE_UDHCPD
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 3c6129249..38c91cbb4 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -9,7 +9,7 @@
9 * Licensed under GPLv2, see file LICENSE in this source tree. 9 * Licensed under GPLv2, see file LICENSE in this source tree.
10 */ 10 */
11//config:config UDHCPC6 11//config:config UDHCPC6
12//config: bool "udhcpc6" 12//config: bool "udhcpc6 (21 kb)"
13//config: default n # not yet ready 13//config: default n # not yet ready
14//config: depends on FEATURE_IPV6 14//config: depends on FEATURE_IPV6
15//config: help 15//config: help
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 4b23e4d39..dcec8cdfd 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -531,7 +531,7 @@ static char **fill_envp(struct dhcp_packet *packet)
531 temp = udhcp_get_option(packet, code); 531 temp = udhcp_get_option(packet, code);
532 *curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name); 532 *curr = xmalloc_optname_optval(temp, &dhcp_optflags[i], opt_name);
533 putenv(*curr++); 533 putenv(*curr++);
534 if (code == DHCP_SUBNET) { 534 if (code == DHCP_SUBNET && temp[-OPT_DATA + OPT_LEN] == 4) {
535 /* Subnet option: make things like "$ip/$mask" possible */ 535 /* Subnet option: make things like "$ip/$mask" possible */
536 uint32_t subnet; 536 uint32_t subnet;
537 move_from_unaligned32(subnet, temp); 537 move_from_unaligned32(subnet, temp);
@@ -1691,7 +1691,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1691 * They say ISC DHCP client supports this case. 1691 * They say ISC DHCP client supports this case.
1692 */ 1692 */
1693 server_addr = 0; 1693 server_addr = 0;
1694 temp = udhcp_get_option(&packet, DHCP_SERVER_ID); 1694 temp = udhcp_get_option32(&packet, DHCP_SERVER_ID);
1695 if (!temp) { 1695 if (!temp) {
1696 bb_error_msg("no server ID, using 0.0.0.0"); 1696 bb_error_msg("no server ID, using 0.0.0.0");
1697 } else { 1697 } else {
@@ -1718,7 +1718,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1718 struct in_addr temp_addr; 1718 struct in_addr temp_addr;
1719 uint8_t *temp; 1719 uint8_t *temp;
1720 1720
1721 temp = udhcp_get_option(&packet, DHCP_LEASE_TIME); 1721 temp = udhcp_get_option32(&packet, DHCP_LEASE_TIME);
1722 if (!temp) { 1722 if (!temp) {
1723 bb_error_msg("no lease time with ACK, using 1 hour lease"); 1723 bb_error_msg("no lease time with ACK, using 1 hour lease");
1724 lease_seconds = 60 * 60; 1724 lease_seconds = 60 * 60;
@@ -1813,7 +1813,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
1813 uint32_t svid; 1813 uint32_t svid;
1814 uint8_t *temp; 1814 uint8_t *temp;
1815 1815
1816 temp = udhcp_get_option(&packet, DHCP_SERVER_ID); 1816 temp = udhcp_get_option32(&packet, DHCP_SERVER_ID);
1817 if (!temp) { 1817 if (!temp) {
1818 non_matching_svid: 1818 non_matching_svid:
1819 log1("received DHCP NAK with wrong" 1819 log1("received DHCP NAK with wrong"
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index a8cd3f03b..0c55fa5e4 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -378,7 +378,7 @@ struct config_keyword {
378#define OFS(field) offsetof(struct server_config_t, field) 378#define OFS(field) offsetof(struct server_config_t, field)
379 379
380static const struct config_keyword keywords[] = { 380static const struct config_keyword keywords[] = {
381 /* keyword handler variable address default */ 381 /* keyword handler variable address default */
382 {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"}, 382 {"start" , udhcp_str2nip , OFS(start_ip ), "192.168.0.20"},
383 {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"}, 383 {"end" , udhcp_str2nip , OFS(end_ip ), "192.168.0.254"},
384 {"interface" , read_str , OFS(interface ), "eth0"}, 384 {"interface" , read_str , OFS(interface ), "eth0"},
@@ -640,7 +640,7 @@ static void add_server_options(struct dhcp_packet *packet)
640static uint32_t select_lease_time(struct dhcp_packet *packet) 640static uint32_t select_lease_time(struct dhcp_packet *packet)
641{ 641{
642 uint32_t lease_time_sec = server_config.max_lease_sec; 642 uint32_t lease_time_sec = server_config.max_lease_sec;
643 uint8_t *lease_time_opt = udhcp_get_option(packet, DHCP_LEASE_TIME); 643 uint8_t *lease_time_opt = udhcp_get_option32(packet, DHCP_LEASE_TIME);
644 if (lease_time_opt) { 644 if (lease_time_opt) {
645 move_from_unaligned32(lease_time_sec, lease_time_opt); 645 move_from_unaligned32(lease_time_sec, lease_time_opt);
646 lease_time_sec = ntohl(lease_time_sec); 646 lease_time_sec = ntohl(lease_time_sec);
@@ -987,7 +987,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
987 } 987 }
988 988
989 /* Get SERVER_ID if present */ 989 /* Get SERVER_ID if present */
990 server_id_opt = udhcp_get_option(&packet, DHCP_SERVER_ID); 990 server_id_opt = udhcp_get_option32(&packet, DHCP_SERVER_ID);
991 if (server_id_opt) { 991 if (server_id_opt) {
992 uint32_t server_id_network_order; 992 uint32_t server_id_network_order;
993 move_from_unaligned32(server_id_network_order, server_id_opt); 993 move_from_unaligned32(server_id_network_order, server_id_opt);
@@ -1011,7 +1011,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
1011 } 1011 }
1012 1012
1013 /* Get REQUESTED_IP if present */ 1013 /* Get REQUESTED_IP if present */
1014 requested_ip_opt = udhcp_get_option(&packet, DHCP_REQUESTED_IP); 1014 requested_ip_opt = udhcp_get_option32(&packet, DHCP_REQUESTED_IP);
1015 if (requested_ip_opt) { 1015 if (requested_ip_opt) {
1016 move_from_unaligned32(requested_nip, requested_ip_opt); 1016 move_from_unaligned32(requested_nip, requested_ip_opt);
1017 } 1017 }
diff --git a/networking/vconfig.c b/networking/vconfig.c
index 8548c8c3b..3cc5f2460 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -7,7 +7,7 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
8 */ 8 */
9//config:config VCONFIG 9//config:config VCONFIG
10//config: bool "vconfig (2.5 kb)" 10//config: bool "vconfig (2.3 kb)"
11//config: default y 11//config: default y
12//config: select PLATFORM_LINUX 12//config: select PLATFORM_LINUX
13//config: help 13//config: help
diff --git a/networking/wget.c b/networking/wget.c
index ae5c945d0..3cae1192c 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -9,7 +9,7 @@
9 * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2. 9 * Kuhn's copyrights are licensed GPLv2-or-later. File as a whole remains GPLv2.
10 */ 10 */
11//config:config WGET 11//config:config WGET
12//config: bool "wget (35 kb)" 12//config: bool "wget (38 kb)"
13//config: default y 13//config: default y
14//config: help 14//config: help
15//config: wget is a utility for non-interactive download of files from HTTP 15//config: wget is a utility for non-interactive download of files from HTTP
@@ -123,14 +123,14 @@
123//usage:#define wget_trivial_usage 123//usage:#define wget_trivial_usage
124//usage: IF_FEATURE_WGET_LONG_OPTIONS( 124//usage: IF_FEATURE_WGET_LONG_OPTIONS(
125//usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n" 125//usage: "[-c|--continue] [--spider] [-q|--quiet] [-O|--output-document FILE]\n"
126//usage: " [--header 'header: value'] [-Y|--proxy on/off] [-P DIR]\n" 126//usage: " [-o|--output-file FILE] [--header 'header: value'] [-Y|--proxy on/off]\n"
127/* Since we ignore these opts, we don't show them in --help */ 127/* Since we ignore these opts, we don't show them in --help */
128/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */ 128/* //usage: " [--no-check-certificate] [--no-cache] [--passive-ftp] [-t TRIES]" */
129/* //usage: " [-nv] [-nc] [-nH] [-np]" */ 129/* //usage: " [-nv] [-nc] [-nH] [-np]" */
130//usage: " [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 130//usage: " [-P DIR] [-S|--server-response] [-U|--user-agent AGENT]" IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
131//usage: ) 131//usage: )
132//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS( 132//usage: IF_NOT_FEATURE_WGET_LONG_OPTIONS(
133//usage: "[-cq] [-O FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]" 133//usage: "[-cq] [-O FILE] [-o FILE] [-Y on/off] [-P DIR] [-S] [-U AGENT]"
134//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..." 134//usage: IF_FEATURE_WGET_TIMEOUT(" [-T SEC]") " URL..."
135//usage: ) 135//usage: )
136//usage:#define wget_full_usage "\n\n" 136//usage:#define wget_full_usage "\n\n"
@@ -147,6 +147,7 @@
147//usage: "\n -T SEC Network read timeout is SEC seconds" 147//usage: "\n -T SEC Network read timeout is SEC seconds"
148//usage: ) 148//usage: )
149//usage: "\n -O FILE Save to FILE ('-' for stdout)" 149//usage: "\n -O FILE Save to FILE ('-' for stdout)"
150//usage: "\n -o FILE Log messages to FILE"
150//usage: "\n -U STR Use STR for User-Agent header" 151//usage: "\n -U STR Use STR for User-Agent header"
151//usage: "\n -Y on/off Use proxy" 152//usage: "\n -Y on/off Use proxy"
152 153
@@ -231,9 +232,11 @@ struct globals {
231 unsigned char user_headers; /* Headers mentioned by the user */ 232 unsigned char user_headers; /* Headers mentioned by the user */
232#endif 233#endif
233 char *fname_out; /* where to direct output (-O) */ 234 char *fname_out; /* where to direct output (-O) */
235 char *fname_log; /* where to direct log (-o) */
234 const char *proxy_flag; /* Use proxies if env vars are set */ 236 const char *proxy_flag; /* Use proxies if env vars are set */
235 const char *user_agent; /* "User-Agent" header field */ 237 const char *user_agent; /* "User-Agent" header field */
236 int output_fd; 238 int output_fd;
239 int log_fd;
237 int o_flags; 240 int o_flags;
238#if ENABLE_FEATURE_WGET_TIMEOUT 241#if ENABLE_FEATURE_WGET_TIMEOUT
239 unsigned timeout_seconds; 242 unsigned timeout_seconds;
@@ -262,16 +265,17 @@ enum {
262 WGET_OPT_QUIET = (1 << 1), 265 WGET_OPT_QUIET = (1 << 1),
263 WGET_OPT_SERVER_RESPONSE = (1 << 2), 266 WGET_OPT_SERVER_RESPONSE = (1 << 2),
264 WGET_OPT_OUTNAME = (1 << 3), 267 WGET_OPT_OUTNAME = (1 << 3),
265 WGET_OPT_PREFIX = (1 << 4), 268 WGET_OPT_LOGNAME = (1 << 4),
266 WGET_OPT_PROXY = (1 << 5), 269 WGET_OPT_PREFIX = (1 << 5),
267 WGET_OPT_USER_AGENT = (1 << 6), 270 WGET_OPT_PROXY = (1 << 6),
268 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 7), 271 WGET_OPT_USER_AGENT = (1 << 7),
269 WGET_OPT_RETRIES = (1 << 8), 272 WGET_OPT_NETWORK_READ_TIMEOUT = (1 << 8),
270 WGET_OPT_nsomething = (1 << 9), 273 WGET_OPT_RETRIES = (1 << 9),
271 WGET_OPT_HEADER = (1 << 10) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 274 WGET_OPT_nsomething = (1 << 10),
272 WGET_OPT_POST_DATA = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 275 WGET_OPT_HEADER = (1 << 11) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
273 WGET_OPT_SPIDER = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 276 WGET_OPT_POST_DATA = (1 << 12) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
274 WGET_OPT_NO_CHECK_CERT = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS, 277 WGET_OPT_SPIDER = (1 << 13) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
278 WGET_OPT_NO_CHECK_CERT = (1 << 14) * ENABLE_FEATURE_WGET_LONG_OPTIONS,
275}; 279};
276 280
277enum { 281enum {
@@ -287,6 +291,10 @@ static void progress_meter(int flag)
287 if (option_mask32 & WGET_OPT_QUIET) 291 if (option_mask32 & WGET_OPT_QUIET)
288 return; 292 return;
289 293
294 /* Don't save progress to log file */
295 if (G.log_fd >= 0)
296 return;
297
290 if (flag == PROGRESS_START) 298 if (flag == PROGRESS_START)
291 bb_progress_init(&G.pmt, G.curfile); 299 bb_progress_init(&G.pmt, G.curfile);
292 300
@@ -900,6 +908,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp)
900 polldata.fd = fileno(dfp); 908 polldata.fd = fileno(dfp);
901 polldata.events = POLLIN | POLLPRI; 909 polldata.events = POLLIN | POLLPRI;
902#endif 910#endif
911 if (G.output_fd == 1)
912 fprintf(stderr, "writing to stdout\n");
913 else
914 fprintf(stderr, "saving to '%s'\n", G.fname_out);
903 progress_meter(PROGRESS_START); 915 progress_meter(PROGRESS_START);
904 916
905 if (G.chunked) 917 if (G.chunked)
@@ -1045,6 +1057,10 @@ static void NOINLINE retrieve_file_data(FILE *dfp)
1045 G.chunked = 0; /* makes it show 100% even for chunked download */ 1057 G.chunked = 0; /* makes it show 100% even for chunked download */
1046 G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */ 1058 G.got_clen = 1; /* makes it show 100% even for download of (formerly) unknown size */
1047 progress_meter(PROGRESS_END); 1059 progress_meter(PROGRESS_END);
1060 if (G.output_fd == 1)
1061 fprintf(stderr, "written to stdout\n");
1062 else
1063 fprintf(stderr, "'%s' saved\n", G.fname_out);
1048} 1064}
1049 1065
1050static void download_one_url(const char *url) 1066static void download_one_url(const char *url)
@@ -1404,6 +1420,8 @@ However, in real world it was observed that some web servers
1404 xclose(G.output_fd); 1420 xclose(G.output_fd);
1405 G.output_fd = -1; 1421 G.output_fd = -1;
1406 } 1422 }
1423 } else {
1424 fprintf(stderr, "remote file exists\n");
1407 } 1425 }
1408 1426
1409 if (dfp != sfp) { 1427 if (dfp != sfp) {
@@ -1433,6 +1451,7 @@ int wget_main(int argc UNUSED_PARAM, char **argv)
1433 "quiet\0" No_argument "q" 1451 "quiet\0" No_argument "q"
1434 "server-response\0" No_argument "S" 1452 "server-response\0" No_argument "S"
1435 "output-document\0" Required_argument "O" 1453 "output-document\0" Required_argument "O"
1454 "output-file\0" Required_argument "o"
1436 "directory-prefix\0" Required_argument "P" 1455 "directory-prefix\0" Required_argument "P"
1437 "proxy\0" Required_argument "Y" 1456 "proxy\0" Required_argument "Y"
1438 "user-agent\0" Required_argument "U" 1457 "user-agent\0" Required_argument "U"
@@ -1476,7 +1495,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1476#if ENABLE_FEATURE_WGET_LONG_OPTIONS 1495#if ENABLE_FEATURE_WGET_LONG_OPTIONS
1477#endif 1496#endif
1478 GETOPT32(argv, "^" 1497 GETOPT32(argv, "^"
1479 "cqSO:P:Y:U:T:+" 1498 "cqSO:o:P:Y:U:T:+"
1480 /*ignored:*/ "t:" 1499 /*ignored:*/ "t:"
1481 /*ignored:*/ "n::" 1500 /*ignored:*/ "n::"
1482 /* wget has exactly four -n<letter> opts, all of which we can ignore: 1501 /* wget has exactly four -n<letter> opts, all of which we can ignore:
@@ -1491,7 +1510,7 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1491 "-1" /* at least one URL */ 1510 "-1" /* at least one URL */
1492 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */ 1511 IF_FEATURE_WGET_LONG_OPTIONS(":\xff::") /* --header is a list */
1493 LONGOPTS 1512 LONGOPTS
1494 , &G.fname_out, &G.dir_prefix, 1513 , &G.fname_out, &G.fname_log, &G.dir_prefix,
1495 &G.proxy_flag, &G.user_agent, 1514 &G.proxy_flag, &G.user_agent,
1496 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL), 1515 IF_FEATURE_WGET_TIMEOUT(&G.timeout_seconds) IF_NOT_FEATURE_WGET_TIMEOUT(NULL),
1497 NULL, /* -t RETRIES */ 1516 NULL, /* -t RETRIES */
@@ -1553,12 +1572,25 @@ IF_DESKTOP( "no-parent\0" No_argument "\xf0")
1553 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC; 1572 G.o_flags = O_WRONLY | O_CREAT | O_TRUNC;
1554 } 1573 }
1555 1574
1575 G.log_fd = -1;
1576 if (G.fname_log) { /* -o FILE ? */
1577 if (!LONE_DASH(G.fname_log)) { /* not -o - ? */
1578 /* compat with wget: -o FILE can overwrite */
1579 G.log_fd = xopen(G.fname_log, O_WRONLY | O_CREAT | O_TRUNC);
1580 /* Redirect only stderr to log file, so -O - will work */
1581 xdup2(G.log_fd, STDERR_FILENO);
1582 }
1583 }
1584
1556 while (*argv) 1585 while (*argv)
1557 download_one_url(*argv++); 1586 download_one_url(*argv++);
1558 1587
1559 if (G.output_fd >= 0) 1588 if (G.output_fd >= 0)
1560 xclose(G.output_fd); 1589 xclose(G.output_fd);
1561 1590
1591 if (G.log_fd >= 0)
1592 xclose(G.log_fd);
1593
1562#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS 1594#if ENABLE_FEATURE_CLEAN_UP && ENABLE_FEATURE_WGET_LONG_OPTIONS
1563 free(G.extra_headers); 1595 free(G.extra_headers);
1564#endif 1596#endif
diff --git a/networking/whois.c b/networking/whois.c
index f3da32b4e..55e1de964 100644
--- a/networking/whois.c
+++ b/networking/whois.c
@@ -10,7 +10,7 @@
10 * Add proxy support 10 * Add proxy support
11 */ 11 */
12//config:config WHOIS 12//config:config WHOIS
13//config: bool "whois (6.6 kb)" 13//config: bool "whois (6.3 kb)"
14//config: default y 14//config: default y
15//config: help 15//config: help
16//config: whois is a client for the whois directory service 16//config: whois is a client for the whois directory service
diff --git a/networking/zcip.c b/networking/zcip.c
index 94e49adcb..434762f12 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -14,7 +14,7 @@
14 * certainly be used. Its naming is built over multicast DNS. 14 * certainly be used. Its naming is built over multicast DNS.
15 */ 15 */
16//config:config ZCIP 16//config:config ZCIP
17//config: bool "zcip (7.8 kb)" 17//config: bool "zcip (8.4 kb)"
18//config: default y 18//config: default y
19//config: select PLATFORM_LINUX 19//config: select PLATFORM_LINUX
20//config: select FEATURE_SYSLOG 20//config: select FEATURE_SYSLOG