1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Resetting differences to official PuTTY that are no longer needed

Most, if not all, were for compatibility with the classic C++Builder compiler (declarations in the middle of code + inline structure initializers)

Source commit: a9f38c3a07777e538c3c6e0fbdd38e9d68327dfa
This commit is contained in:
Martin Prikryl
2025-12-05 14:20:32 +00:00
parent c9ac0c1915
commit f670f4ebb1
109 changed files with 1691 additions and 4138 deletions

View File

@@ -1,520 +0,0 @@
/*
* Master list of configuration options living in the Conf data
* structure.
*
* Each CONF_OPTION directive defines a single CONF_foo primary key in
* Conf, and can be equipped with the following properties:
*
* - VALUE_TYPE: the type of data associated with that key
* - SUBKEY_TYPE: if the primary key goes with a subkey (that is, the
* primary key identifies some mapping from subkeys to values), the
* data type of the subkey
* - DEFAULT_INT, DEFAULT_STR, DEFAULT_BOOL: the default value for
* the key, if no save data is available. Must match VALUE_TYPE, if
* the key has no subkey. Otherwise, no default is permitted, and
* the default value of the mapping is assumed to be empty (and if
* not, then LOAD_CUSTOM code must override that).
* - SAVE_KEYWORD: the keyword used for the option in the Windows
* registry or ~/.putty/sessions save files.
* - STORAGE_ENUM: for int-typed settings with no subkeys, this
* identifies an enumeration in conf-enums.h which maps internal
* values of the setting in the Conf to values in the saved data.
* - LOAD_CUSTOM, SAVE_CUSTOM: suppress automated loading or saving
* (respectively) of this setting, in favour of manual code in
* settings.c load_open_settings() or save_open_settings()
* respectively.
* - NOT_SAVED: indicate that this setting is not part of saved
* session data at all.
*/
CONF_OPTION(host, NONE, STR, (int)"", false, false, false, "HostName", NULL)
/* default value depends on the value of CONF_protocol */
CONF_OPTION(port, NONE, INT, 0, false, true, false, "PortNumber", NULL)
/* PROT_SSH, PROT_TELNET etc */
/*
* Notionally SAVE_KEYWORD("Protocol"), but saving/loading is handled by
* custom code because the stored value is a string representation
* of the protocol name.
*/
CONF_OPTION(protocol, NONE, INT, 0, true, true, false, NULL, NULL)
CONF_OPTION(addressfamily, NONE, INT, ADDRTYPE_UNSPEC, false, false, false, "AddressFamily", &conf_enum_addressfamily)
CONF_OPTION(close_on_exit, NONE, INT, AUTO, false, false, false, "CloseOnExit", &conf_enum_off_auto_on)
CONF_OPTION(warn_on_close, NONE, BOOL, (int)true, false, false, false, "WarnOnClose", NULL)
/* in seconds */
/*
* Saving/loading is handled by custom code because for historical
* reasons this value corresponds to two save keywords,
* "PingInterval" (measured in minutes) and "PingIntervalSecs"
* (measured in seconds), which are added together on loading.
* Rationale: the value was once measured in minutes, and the
* seconds field was added later.
*/
CONF_OPTION(ping_interval, NONE, INT, 0, true, true, false, NULL, NULL)
CONF_OPTION(tcp_nodelay, NONE, BOOL, (int)true, false, false, false, "TCPNoDelay", NULL)
CONF_OPTION(tcp_keepalives, NONE, BOOL, (int)false, false, false, false, "TCPKeepalives", NULL)
/* logical host being contacted, for host key check */
CONF_OPTION(loghost, NONE, STR, (int)"", false, false, false, "LogHost", NULL)
/* Proxy options */
CONF_OPTION(proxy_exclude_list, NONE, STR, (int)"", false, false, false, "ProxyExcludeList", NULL)
CONF_OPTION(proxy_dns, NONE, INT, AUTO, false, false, false, "ProxyDNS", &conf_enum_off_auto_on)
CONF_OPTION(even_proxy_localhost, NONE, BOOL, (int)false, false, false, false, "ProxyLocalhost", NULL)
/* PROXY_NONE, PROXY_SOCKS4, ... */
/*
* Custom load code: there was an earlier keyword "ProxyType"
* using a different enumeration, in which SOCKS4 and SOCKS5
* shared a value, and a second keyword "ProxySOCKSVersion"
* disambiguated.
*/
CONF_OPTION(proxy_type, NONE, INT, 0, false, true, false, "ProxyMethod", &conf_enum_proxy_type)
CONF_OPTION(proxy_host, NONE, STR, (int)"proxy", false, false, false, "ProxyHost", NULL)
CONF_OPTION(proxy_port, NONE, INT, 80, false, false, false, "ProxyPort", NULL)
CONF_OPTION(proxy_username, NONE, STR, (int)"", false, false, false, "ProxyUsername", NULL)
CONF_OPTION(proxy_password, NONE, STR, (int)"", false, false, false, "ProxyPassword", NULL)
CONF_OPTION(proxy_telnet_command, NONE, STR, (int)"connect %host %port\\n", false, false, false, "ProxyTelnetCommand", NULL)
CONF_OPTION(proxy_log_to_term, NONE, INT, FORCE_OFF, false, false, false, "ProxyLogToTerm", &conf_enum_on_off_auto)
/* SSH options */
CONF_OPTION(remote_cmd, NONE, STR_AMBI, (int)"", false, false, false, "RemoteCommand", NULL)
/*
* Fallback command to try to run if remote_cmd fails. Only set
* internally by PSCP and PSFTP (so that they can try multiple
* methods of running an SFTP server at the remote end); never set
* by user configuration, or loaded or saved.
*/
CONF_OPTION(remote_cmd2, NONE, STR_AMBI, (int)"", false, false, true, NULL, NULL)
CONF_OPTION(nopty, NONE, BOOL, (int)false, false, false, false, "NoPTY", NULL)
CONF_OPTION(compression, NONE, BOOL, (int)false, false, false, false, "Compression", NULL)
/* indices in preference order: 0,...,KEX_MAX-1
* (lower is more preferred) */
/* KEX_* enum values */
/* necessary for preference lists */
CONF_OPTION(ssh_kexlist, INT, INT, 0, true, true, false, NULL, NULL)
/* indices in preference order: 0,...,HK_MAX-1
* (lower is more preferred) */
/* HK_* enum values */
/* necessary for preference lists */
CONF_OPTION(ssh_hklist, INT, INT, 0, true, true, false, NULL, NULL)
CONF_OPTION(ssh_prefer_known_hostkeys, NONE, BOOL, (int)true, false, false, false, "PreferKnownHostKeys", NULL)
/* in minutes */
CONF_OPTION(ssh_rekey_time, NONE, INT, 60, false, false, false, "RekeyTime", NULL)
/* string encoding e.g. "100K", "2M", "1G" */
CONF_OPTION(ssh_rekey_data, NONE, STR, (int)"1G", false, false, false, "RekeyBytes", NULL)
CONF_OPTION(tryagent, NONE, BOOL, (int)true, false, false, false, "TryAgent", NULL)
CONF_OPTION(agentfwd, NONE, BOOL, (int)false, false, false, false, "AgentFwd", NULL)
/* allow username switching in SSH-2 */
CONF_OPTION(change_username, NONE, BOOL, (int)false, false, false, false, "ChangeUsername", NULL)
/* indices in preference order: 0,...,CIPHER_MAX-1
* (lower is more preferred) */
/* CIPHER_* enum values */
/* necessary for preference lists */
CONF_OPTION(ssh_cipherlist, INT, INT, 0, true, true, false, NULL, NULL)
CONF_OPTION(keyfile, NONE, FILENAME, 0, false, false, false, "PublicKeyFile", NULL)
CONF_OPTION(detached_cert, NONE, FILENAME, 0, false, false, false, "DetachedCertificate", NULL)
CONF_OPTION(auth_plugin, NONE, STR, (int)"", false, false, false, "AuthPlugin", NULL)
/*
* Which SSH protocol to use.
*
* For historical reasons, the current legal values for CONF_sshprot
* are:
* 0 = SSH-1 only
* 3 = SSH-2 only
*
* We used to also support
* 1 = SSH-1 with fallback to SSH-2
* 2 = SSH-2 with fallback to SSH-1
*
* and we continue to use 0/3 in storage formats rather than the more
* obvious 1/2 to avoid surprises if someone saves a session and later
* downgrades PuTTY. So it's easier to use these numbers internally too.
*/
CONF_OPTION(sshprot, NONE, INT, 3, false, false, false, "SshProt", &conf_enum_ssh_protocol)
/*
* This means that we promise never to open any channel other
* than the main one, which means it can safely use a very large
* window in SSH-2.
*
* Only ever set internally by file transfer tools; never set by
* user configuration, or loaded or saved.
*/
CONF_OPTION(ssh_simple, NONE, BOOL, (int)false, false, false, true, NULL, NULL)
CONF_OPTION(ssh_connection_sharing, NONE, BOOL, (int)false, false, false, false, "ConnectionSharing", NULL)
CONF_OPTION(ssh_connection_sharing_upstream, NONE, BOOL, (int)true, false, false, false, "ConnectionSharingUpstream", NULL)
CONF_OPTION(ssh_connection_sharing_downstream, NONE, BOOL, (int)true, false, false, false, "ConnectionSharingDownstream", NULL)
/*
* Manually configured host keys to accept regardless of the state
* of the host key cache.
*
* This is conceptually a set rather than a dictionary: every
* value in this map is the empty string, and the set of subkeys
* that exist is the important data.
*/
/* necessary for mappings */
CONF_OPTION(ssh_manual_hostkeys, STR, STR, 0, true, true, false, NULL, NULL)
/* "des-cbc" unrecommended SSH-2 cipher */
CONF_OPTION(ssh2_des_cbc, NONE, BOOL, (int)false, false, false, false, "SSH2DES", NULL)
/* bypass "ssh-userauth" (SSH-2 only) */
CONF_OPTION(ssh_no_userauth, NONE, BOOL, (int)false, false, false, false, "SshNoAuth", NULL)
/* disable trivial types of auth */
CONF_OPTION(ssh_no_trivial_userauth, NONE, BOOL, (int)false, false, false, false, "SshNoTrivialAuth", NULL)
/* show USERAUTH_BANNERs (SSH-2 only) */
CONF_OPTION(ssh_show_banner, NONE, BOOL, (int)true, false, false, false, "SshBanner", NULL)
CONF_OPTION(try_tis_auth, NONE, BOOL, (int)false, false, false, false, "AuthTIS", NULL)
CONF_OPTION(try_ki_auth, NONE, BOOL, (int)true, false, false, false, "AuthKI", NULL)
/* attempt gssapi via ssh userauth */
/* under #ifndef NO_GSSAPI */
CONF_OPTION(try_gssapi_auth, NONE, BOOL, 0, true, true, false, NULL, NULL)
/* attempt gssapi via ssh kex */
/* under #ifndef NO_GSSAPI */
CONF_OPTION(try_gssapi_kex, NONE, BOOL, 0, true, true, false, NULL, NULL)
/* forward tgt via gss */
/* under #ifndef NO_GSSAPI */
CONF_OPTION(gssapifwd, NONE, BOOL, 0, true, true, false, NULL, NULL)
/* KEXGSS refresh interval (mins) */
/* under #ifndef NO_GSSAPI */
CONF_OPTION(gssapirekey, NONE, INT, 0, true, true, false, NULL, NULL)
/* indices in preference order: 0,...,ngsslibs
* (lower is more preferred; ngsslibs is a platform-
* dependent value) */
/* indices of GSSAPI lib types (platform-dependent) */
/* necessary for preference lists, also this
* setting is under #ifndef NO_GSSAPI */
CONF_OPTION(ssh_gsslist, INT, INT, 0, true, true, false, NULL, NULL)
/* under #ifndef NO_GSSAPI */
CONF_OPTION(ssh_gss_custom, NONE, FILENAME, 0, true, true, false, NULL, NULL)
/* run a subsystem rather than a command */
/*
* Only set internally by PSCP and PSFTP; never set by user
* configuration, or loaded or saved.
*/
CONF_OPTION(ssh_subsys, NONE, BOOL, (int)false, false, false, true, NULL, NULL)
/* fallback to go with remote_cmd2 */
/*
* Only set internally by PSCP and PSFTP; never set by user
* configuration, or loaded or saved.
*/
CONF_OPTION(ssh_subsys2, NONE, BOOL, (int)false, false, false, true, NULL, NULL)
/* avoid running a shell */
CONF_OPTION(ssh_no_shell, NONE, BOOL, (int)false, false, false, false, "SshNoShell", NULL)
/* host to connect to in `nc' mode */
/*
* Only set by the '-nc' command-line option and by the SSH proxy
* code. There's no GUI config option for this, and therefore it's
* also never loaded or saved.
*/
CONF_OPTION(ssh_nc_host, NONE, STR, (int)"", false, false, true, NULL, NULL)
/* port to connect to in `nc' mode */
/*
* Only set by the '-nc' command-line option and by the SSH proxy
* code. There's no GUI config option for this, and therefore it's
* also never loaded or saved.
*/
CONF_OPTION(ssh_nc_port, NONE, INT, 0, false, false, true, NULL, NULL)
/* Telnet options */
CONF_OPTION(termtype, NONE, STR, (int)"xterm", false, false, false, "TerminalType", NULL)
CONF_OPTION(termspeed, NONE, STR, (int)"38400,38400", false, false, false, "TerminalSpeed", NULL)
/*
* The full set of permitted subkeys is listed in
* ssh/ttymode-list.h, as the first parameter of each TTYMODE_CHAR
* or TTYMODE_FLAG macro.
*
* The permitted value strings are:
*
* - "N" means do not include a record for this mode at all in
* the terminal mode data in the "pty-req" channel request.
* Corresponds to setting the mode to 'Nothing' in the GUI.
* - "A" means use PuTTY's automatic default, matching the
* settings for GUI PuTTY's terminal window or Unix Plink's
* controlling tty. Corresponds to setting 'Auto' in the GUI.
* - "V" followed by further string data means send a custom
* value to the SSH server. Values are as documented in the
* manual.
*/
/* necessary for mappings */
CONF_OPTION(ttymodes, STR, STR, 0, true, true, false, NULL, NULL)
/* environment variable name */
/* environment variable value */
/* necessary for mappings */
CONF_OPTION(environmt, STR, STR, 0, true, true, false, NULL, NULL)
CONF_OPTION(username, NONE, STR_AMBI, (int)"", false, false, false, "UserName", NULL)
CONF_OPTION(username_from_env, NONE, BOOL, (int)false, false, false, false, "UserNameFromEnvironment", NULL)
CONF_OPTION(localusername, NONE, STR, (int)"", false, false, false, "LocalUserName", NULL)
CONF_OPTION(rfc_environ, NONE, BOOL, (int)false, false, false, false, "RFCEnviron", NULL)
CONF_OPTION(passive_telnet, NONE, BOOL, (int)false, false, false, false, "PassiveTelnet", NULL)
/* Serial port options */
CONF_OPTION(serline, NONE, STR, (int)"", false, false, false, "SerialLine", NULL)
CONF_OPTION(serspeed, NONE, INT, 9600, false, false, false, "SerialSpeed", NULL)
CONF_OPTION(serdatabits, NONE, INT, 8, false, false, false, "SerialDataBits", NULL)
CONF_OPTION(serstopbits, NONE, INT, 2, false, false, false, "SerialStopHalfbits", NULL)
CONF_OPTION(serparity, NONE, INT, SER_PAR_NONE, false, false, false, "SerialParity", &conf_enum_serparity)
CONF_OPTION(serflow, NONE, INT, SER_FLOW_XONXOFF, false, false, false, "SerialFlowControl", &conf_enum_serflow)
/* SUPDUP options */
CONF_OPTION(supdup_location, NONE, STR, (int)"The Internet", false, false, false, "SUPDUPLocation", NULL)
CONF_OPTION(supdup_ascii_set, NONE, INT, SUPDUP_CHARSET_ASCII, false, false, false, "SUPDUPCharset", &conf_enum_supdup_charset)
CONF_OPTION(supdup_more, NONE, BOOL, (int)false, false, false, false, "SUPDUPMoreProcessing", NULL)
CONF_OPTION(supdup_scroll, NONE, BOOL, (int)false, false, false, false, "SUPDUPScrolling", NULL)
/* Keyboard options */
CONF_OPTION(bksp_is_delete, NONE, BOOL, (int)true, false, false, false, "BackspaceIsDelete", NULL)
CONF_OPTION(rxvt_homeend, NONE, BOOL, (int)false, false, false, false, "RXVTHomeEnd", NULL)
CONF_OPTION(funky_type, NONE, INT, FUNKY_TILDE, false, false, false, "LinuxFunctionKeys", &conf_enum_funky_type)
CONF_OPTION(sharrow_type, NONE, INT, SHARROW_APPLICATION, false, false, false, "ShiftedArrowKeys", &conf_enum_sharrow_type)
/* totally disable app cursor keys */
CONF_OPTION(no_applic_c, NONE, BOOL, (int)false, false, false, false, "NoApplicationCursors", NULL)
/* totally disable app keypad */
CONF_OPTION(no_applic_k, NONE, BOOL, (int)false, false, false, false, "NoApplicationKeys", NULL)
/* totally disable mouse reporting */
CONF_OPTION(no_mouse_rep, NONE, BOOL, (int)false, false, false, false, "NoMouseReporting", NULL)
/* disable remote resizing */
CONF_OPTION(no_remote_resize, NONE, BOOL, (int)false, false, false, false, "NoRemoteResize", NULL)
/* disable alternate screen */
CONF_OPTION(no_alt_screen, NONE, BOOL, (int)false, false, false, false, "NoAltScreen", NULL)
/* disable remote retitling */
CONF_OPTION(no_remote_wintitle, NONE, BOOL, (int)false, false, false, false, "NoRemoteWinTitle", NULL)
/* disable ESC[3J */
CONF_OPTION(no_remote_clearscroll, NONE, BOOL, (int)false, false, false, false, "NoRemoteClearScroll", NULL)
/* disable destructive backspace */
CONF_OPTION(no_dbackspace, NONE, BOOL, (int)false, false, false, false, "NoDBackspace", NULL)
/* disable remote charset config */
CONF_OPTION(no_remote_charset, NONE, BOOL, (int)false, false, false, false, "NoRemoteCharset", NULL)
/* handling of remote window title queries */
/* older versions had a boolean "NoRemoteQTitle"
* before we ended up with three options */
CONF_OPTION(remote_qtitle_action, NONE, INT, 0, false, true, false, "RemoteQTitleAction", &conf_enum_remote_qtitle_action)
CONF_OPTION(app_cursor, NONE, BOOL, (int)false, false, false, false, "ApplicationCursorKeys", NULL)
CONF_OPTION(app_keypad, NONE, BOOL, (int)false, false, false, false, "ApplicationKeypad", NULL)
CONF_OPTION(nethack_keypad, NONE, BOOL, (int)false, false, false, false, "NetHackKeypad", NULL)
CONF_OPTION(telnet_keyboard, NONE, BOOL, (int)false, false, false, false, "TelnetKey", NULL)
CONF_OPTION(telnet_newline, NONE, BOOL, (int)true, false, false, false, "TelnetRet", NULL)
/* is it special? */
CONF_OPTION(alt_f4, NONE, BOOL, (int)true, false, false, false, "AltF4", NULL)
/* is it special? */
CONF_OPTION(alt_space, NONE, BOOL, (int)false, false, false, false, "AltSpace", NULL)
/* is it special? */
CONF_OPTION(alt_only, NONE, BOOL, (int)false, false, false, false, "AltOnly", NULL)
CONF_OPTION(localecho, NONE, INT, AUTO, false, false, false, "LocalEcho", &conf_enum_on_off_auto)
CONF_OPTION(localedit, NONE, INT, AUTO, false, false, false, "LocalEdit", &conf_enum_on_off_auto)
CONF_OPTION(alwaysontop, NONE, BOOL, (int)false, false, false, false, "AlwaysOnTop", NULL)
CONF_OPTION(fullscreenonaltenter, NONE, BOOL, (int)false, false, false, false, "FullScreenOnAltEnter", NULL)
CONF_OPTION(scroll_on_key, NONE, BOOL, (int)false, false, false, false, "ScrollOnKey", NULL)
CONF_OPTION(scroll_on_disp, NONE, BOOL, (int)true, false, false, false, "ScrollOnDisp", NULL)
CONF_OPTION(erase_to_scrollback, NONE, BOOL, (int)true, false, false, false, "EraseToScrollback", NULL)
CONF_OPTION(compose_key, NONE, BOOL, (int)false, false, false, false, "ComposeKey", NULL)
CONF_OPTION(ctrlaltkeys, NONE, BOOL, (int)true, false, false, false, "CtrlAltKeys", NULL)
/* under #ifdef OSX_META_KEY_CONFIG */
CONF_OPTION(osx_option_meta, NONE, BOOL, 0, true, true, false, NULL, NULL)
/* under #ifdef OSX_META_KEY_CONFIG */
CONF_OPTION(osx_command_meta, NONE, BOOL, 0, true, true, false, NULL, NULL)
/* initial window title */
CONF_OPTION(wintitle, NONE, STR, (int)"", false, false, false, "WinTitle", NULL)
/* Terminal options */
CONF_OPTION(savelines, NONE, INT, 2000, false, false, false, "ScrollbackLines", NULL)
CONF_OPTION(dec_om, NONE, BOOL, (int)false, false, false, false, "DECOriginMode", NULL)
CONF_OPTION(wrap_mode, NONE, BOOL, (int)true, false, false, false, "AutoWrapMode", NULL)
CONF_OPTION(lfhascr, NONE, BOOL, (int)false, false, false, false, "LFImpliesCR", NULL)
CONF_OPTION(cursor_type, NONE, INT, 0, false, false, false, "CurType", &conf_enum_cursor_type)
CONF_OPTION(blink_cur, NONE, BOOL, (int)false, false, false, false, "BlinkCur", NULL)
CONF_OPTION(beep, NONE, INT, BELL_DEFAULT, false, false, false, "Beep", &conf_enum_beep)
CONF_OPTION(beep_ind, NONE, INT, B_IND_DISABLED, false, false, false, "BeepInd", &conf_enum_beep_indication)
/* bell overload protection active? */
CONF_OPTION(bellovl, NONE, BOOL, (int)true, false, false, false, "BellOverload", NULL)
/* number of bells to cause overload */
CONF_OPTION(bellovl_n, NONE, INT, 5, false, false, false, "BellOverloadN", NULL)
/* time interval for overload (ticks) */
/*
* Loading and saving is done in custom code because the format is
* platform-dependent for historical reasons: on Unix, the stored
* value is multiplied by 1000. (And since TICKSPERSEC=1000 on
* that platform, it means the stored value is interpreted in
* microseconds.)
*/
CONF_OPTION(bellovl_t, NONE, INT, 0, true, true, false, NULL, NULL)
/* period of silence to re-enable bell (s) */
/*
* Loading and saving is done in custom code because the format is
* platform-dependent for historical reasons: on Unix, the stored
* value is multiplied by 1000. (And since TICKSPERSEC=1000 on
* that platform, it means the stored value is interpreted in
* microseconds.)
*/
CONF_OPTION(bellovl_s, NONE, INT, 0, true, true, false, NULL, NULL)
CONF_OPTION(bell_wavefile, NONE, FILENAME, 0, false, false, false, "BellWaveFile", NULL)
CONF_OPTION(scrollbar, NONE, BOOL, (int)true, false, false, false, "ScrollBar", NULL)
CONF_OPTION(scrollbar_in_fullscreen, NONE, BOOL, (int)false, false, false, false, "ScrollBarFullScreen", NULL)
CONF_OPTION(resize_action, NONE, INT, RESIZE_TERM, false, false, false, "LockSize", &conf_enum_resize_effect)
CONF_OPTION(bce, NONE, BOOL, (int)true, false, false, false, "BCE", NULL)
CONF_OPTION(blinktext, NONE, BOOL, (int)false, false, false, false, "BlinkText", NULL)
CONF_OPTION(win_name_always, NONE, BOOL, (int)true, false, false, false, "WinNameAlways", NULL)
CONF_OPTION(width, NONE, INT, 80, false, false, false, "TermWidth", NULL)
CONF_OPTION(height, NONE, INT, 24, false, false, false, "TermHeight", NULL)
CONF_OPTION(font, NONE, FONT, 0, false, false, false, "Font", NULL)
CONF_OPTION(font_quality, NONE, INT, FQ_DEFAULT, false, false, false, "FontQuality", &conf_enum_font_quality)
CONF_OPTION(logfilename, NONE, FILENAME, 0, false, false, false, "LogFileName", NULL)
CONF_OPTION(logtype, NONE, INT, LGTYP_NONE, false, false, false, "LogType", &conf_enum_log_type)
CONF_OPTION(logxfovr, NONE, INT, LGXF_ASK, false, false, false, "LogFileClash", &conf_enum_log_to_existing_file)
CONF_OPTION(logflush, NONE, BOOL, (int)true, false, false, false, "LogFlush", NULL)
CONF_OPTION(logheader, NONE, BOOL, (int)true, false, false, false, "LogHeader", NULL)
CONF_OPTION(logomitpass, NONE, BOOL, (int)true, false, false, false, "SSHLogOmitPasswords", NULL)
CONF_OPTION(logomitdata, NONE, BOOL, (int)false, false, false, false, "SSHLogOmitData", NULL)
CONF_OPTION(hide_mouseptr, NONE, BOOL, (int)false, false, false, false, "HideMousePtr", NULL)
CONF_OPTION(sunken_edge, NONE, BOOL, (int)false, false, false, false, "SunkenEdge", NULL)
/* in pixels */
CONF_OPTION(window_border, NONE, INT, 1, false, false, false, "WindowBorder", NULL)
CONF_OPTION(answerback, NONE, STR, (int)"PuTTY", false, false, false, "Answerback", NULL)
CONF_OPTION(printer, NONE, STR, (int)"", false, false, false, "Printer", NULL)
CONF_OPTION(no_arabicshaping, NONE, BOOL, (int)false, false, false, false, "DisableArabicShaping", NULL)
CONF_OPTION(no_bidi, NONE, BOOL, (int)false, false, false, false, "DisableBidi", NULL)
CONF_OPTION(no_bracketed_paste, NONE, BOOL, (int)false, false, false, false, "DisableBracketedPaste", NULL)
/* Colour options */
CONF_OPTION(ansi_colour, NONE, BOOL, (int)true, false, false, false, "ANSIColour", NULL)
CONF_OPTION(xterm_256_colour, NONE, BOOL, (int)true, false, false, false, "Xterm256Colour", NULL)
CONF_OPTION(true_colour, NONE, BOOL, (int)true, false, false, false, "TrueColour", NULL)
CONF_OPTION(system_colour, NONE, BOOL, (int)false, false, false, false, "UseSystemColours", NULL)
CONF_OPTION(try_palette, NONE, BOOL, (int)false, false, false, false, "TryPalette", NULL)
CONF_OPTION(bold_style, NONE, INT, 2, false, false, false, "BoldAsColour", &conf_enum_bold_style)
/*
* Subkeys in this setting are indexed based on the CONF_COLOUR_*
* enum values in putty.h. But each subkey identifies just one
* component of the RGB value. Subkey 3*a+b identifies colour #a,
* channel #b, where channels 0,1,2 mean R,G,B respectively.
*
* Values are 8-bit integers.
*/
/* necessary for mappings */
CONF_OPTION(colours, INT, INT, 0, true, true, false, NULL, NULL)
/* Selection options */
CONF_OPTION(mouse_is_xterm, NONE, INT, 0, false, false, false, "MouseIsXterm", &conf_enum_mouse_buttons)
CONF_OPTION(rect_select, NONE, BOOL, (int)false, false, false, false, "RectSelect", NULL)
CONF_OPTION(paste_controls, NONE, BOOL, (int)false, false, false, false, "PasteControls", NULL)
CONF_OPTION(rawcnp, NONE, BOOL, (int)false, false, false, false, "RawCNP", NULL)
CONF_OPTION(utf8linedraw, NONE, BOOL, (int)false, false, false, false, "UTF8linedraw", NULL)
CONF_OPTION(rtf_paste, NONE, BOOL, (int)false, false, false, false, "PasteRTF", NULL)
CONF_OPTION(mouse_override, NONE, BOOL, (int)true, false, false, false, "MouseOverride", NULL)
/* ASCII character codes (literally, just 00-7F) */
/* arbitrary equivalence-class value for that char */
/* necessary for mappings */
CONF_OPTION(wordness, INT, INT, 0, true, true, false, NULL, NULL)
/*
* What clipboard (if any) to copy text to as soon as it's
* selected with the mouse.
*/
/* platform-dependent bool-valued
* macro */
CONF_OPTION(mouseautocopy, NONE, BOOL, (int)CLIPUI_DEFAULT_AUTOCOPY, false, false, false, "MouseAutocopy", NULL)
/* clipboard used by one-mouse-click paste actions */
/*
* SAVE_KEYWORD("MousePaste"), but loading and saving is done by
* custom code, because the saved value is a string, and also sets
* CONF_mousepaste_custom
*/
CONF_OPTION(mousepaste, NONE, INT, 0, true, true, false, NULL, NULL)
/* clipboard used by Ctrl+Ins and Shift+Ins */
/*
* SAVE_KEYWORD("CtrlShiftIns"), but loading and saving is done by
* custom code, because the saved value is a string, and also sets
* CONF_ctrlshiftins_custom
*/
CONF_OPTION(ctrlshiftins, NONE, INT, 0, true, true, false, NULL, NULL)
/* clipboard used by Ctrl+Shift+C and Ctrl+Shift+V */
/*
* SAVE_KEYWORD("CtrlShiftCV"), but loading and saving is done by
* custom code, because the saved value is a string, and also sets
* CONF_ctrlshiftcv_custom
*/
CONF_OPTION(ctrlshiftcv, NONE, INT, 0, true, true, false, NULL, NULL)
/* Custom clipboard name if CONF_mousepaste is set to CLIPUI_CUSTOM */
/*
* Loading and saving is handled by custom code in conjunction
* with CONF_mousepaste
*/
CONF_OPTION(mousepaste_custom, NONE, STR, 0, true, true, false, NULL, NULL)
/* Custom clipboard name if CONF_ctrlshiftins is set to CLIPUI_CUSTOM */
/*
* Loading and saving is handled by custom code in conjunction
* with CONF_ctrlshiftins
*/
CONF_OPTION(ctrlshiftins_custom, NONE, STR, 0, true, true, false, NULL, NULL)
/* Custom clipboard name if CONF_ctrlshiftcv is set to CLIPUI_CUSTOM */
/*
* Loading and saving is handled by custom code in conjunction
* with CONF_ctrlshiftcv
*/
CONF_OPTION(ctrlshiftcv_custom, NONE, STR, 0, true, true, false, NULL, NULL)
/* Character-set translation */
CONF_OPTION(vtmode, NONE, INT, VT_UNICODE, false, false, false, "FontVTMode", &conf_enum_line_drawing)
CONF_OPTION(line_codepage, NONE, STR, (int)"", false, false, false, "LineCodePage", NULL)
CONF_OPTION(cjk_ambig_wide, NONE, BOOL, (int)false, false, false, false, "CJKAmbigWide", NULL)
CONF_OPTION(utf8_override, NONE, BOOL, (int)true, false, false, false, "UTF8Override", NULL)
CONF_OPTION(xlat_capslockcyr, NONE, BOOL, (int)false, false, false, false, "CapsLockCyr", NULL)
/* X11 forwarding */
CONF_OPTION(x11_forward, NONE, BOOL, (int)false, false, false, false, "X11Forward", NULL)
CONF_OPTION(x11_display, NONE, STR, (int)"", false, false, false, "X11Display", NULL)
CONF_OPTION(x11_auth, NONE, INT, X11_MIT, false, false, false, "X11AuthType", &conf_enum_x11_auth)
CONF_OPTION(xauthfile, NONE, FILENAME, 0, false, false, false, "X11AuthFile", NULL)
/* Port forwarding */
/* accept conns from hosts other than localhost */
CONF_OPTION(lport_acceptall, NONE, BOOL, (int)false, false, false, false, "LocalPortAcceptAll", NULL)
/* same for remote forwarded ports */
CONF_OPTION(rport_acceptall, NONE, BOOL, (int)false, false, false, false, "RemotePortAcceptAll", NULL)
/*
* Subkeys for 'portfwd' can have the following forms:
*
* [LR]localport
* [LR]localaddr:localport
*
* Dynamic forwardings are indicated by an 'L' key, and the
* special value "D". For all other forwardings, the value should
* be of the form 'host:port'.
*/
/* necessary for mappings */
CONF_OPTION(portfwd, STR, STR, 0, true, true, false, NULL, NULL)
/* SSH bug compatibility modes. All FORCE_ON/FORCE_OFF/AUTO */
CONF_OPTION(sshbug_ignore1, NONE, INT, AUTO, false, false, false, "BugIgnore1", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_plainpw1, NONE, INT, AUTO, false, false, false, "BugPlainPW1", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_rsa1, NONE, INT, AUTO, false, false, false, "BugRSA1", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_ignore2, NONE, INT, AUTO, false, false, false, "BugIgnore2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_derivekey2, NONE, INT, AUTO, false, false, false, "BugDeriveKey2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_rsapad2, NONE, INT, AUTO, false, false, false, "BugRSAPad2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_pksessid2, NONE, INT, AUTO, false, false, false, "BugPKSessID2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_rekey2, NONE, INT, AUTO, false, false, false, "BugRekey2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_maxpkt2, NONE, INT, AUTO, false, false, false, "BugMaxPkt2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_oldgex2, NONE, INT, AUTO, false, false, false, "BugOldGex2", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_winadj, NONE, INT, AUTO, false, false, false, "BugWinadj", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_chanreq, NONE, INT, AUTO, false, false, false, "BugChanReq", &conf_enum_auto_off_on)
CONF_OPTION(sshbug_dropstart, NONE, INT, FORCE_OFF, false, false, false, "BugDropStart", &conf_enum_off1_on2)
CONF_OPTION(sshbug_filter_kexinit, NONE, INT, FORCE_OFF, false, false, false, "BugFilterKexinit", &conf_enum_off1_on2)
CONF_OPTION(sshbug_rsa_sha2_cert_userauth, NONE, INT, AUTO, false, false, false, "BugRSASHA2CertUserauth", &conf_enum_auto_off_on)
/* there was an earlier keyword called "BuggyMAC" */
CONF_OPTION(sshbug_hmac2, NONE, INT, AUTO, false, true, false, "BugHMAC2", &conf_enum_auto_off_on)
/* Options for Unix. Should split out into platform-dependent part. */
/* used by Unix pterm */
CONF_OPTION(stamp_utmp, NONE, BOOL, (int)true, false, false, false, "StampUtmp", NULL)
/* used by Unix pterm */
CONF_OPTION(login_shell, NONE, BOOL, (int)true, false, false, false, "LoginShell", NULL)
CONF_OPTION(scrollbar_on_left, NONE, BOOL, (int)false, false, false, false, "ScrollbarOnLeft", NULL)
CONF_OPTION(shadowbold, NONE, BOOL, (int)false, false, false, false, "ShadowBold", NULL)
CONF_OPTION(boldfont, NONE, FONT, 0, false, false, false, "BoldFont", NULL)
CONF_OPTION(widefont, NONE, FONT, 0, false, false, false, "WideFont", NULL)
CONF_OPTION(wideboldfont, NONE, FONT, 0, false, false, false, "WideBoldFont", NULL)
/* in pixels */
CONF_OPTION(shadowboldoffset, NONE, INT, 1, false, false, false, "ShadowBoldOffset", NULL)
CONF_OPTION(crhaslf, NONE, BOOL, (int)false, false, false, false, "CRImpliesLF", NULL)
CONF_OPTION(winclass, NONE, STR, (int)"", false, false, false, "WindowClass", NULL)
/* WINSCP BEGIN */
CONF_OPTION(connect_timeout, NONE, INT, 0, false, false, true, NULL, NULL)
CONF_OPTION(sndbuf, NONE, INT, 0, false, false, true, NULL, NULL)
CONF_OPTION(srcaddr, NONE, STR, (int)"", false, false, true, NULL, NULL)
CONF_OPTION(force_remote_cmd2, NONE, BOOL, (int)false, false, false, true, NULL, NULL)
CONF_OPTION(change_password, NONE, BOOL, (int)false, false, false, true, NULL, NULL)
/* WINSCP END */

View File

@@ -142,11 +142,9 @@ static void aes_ni_key_expand(
// WINSCP
// WORKAROUND
// Cannot use _mm_setr_epi* - it results in the constant being stored in .rdata segment.
// objconv reports:
// Warning 1060: Different alignments specified for same segment, %s. Using highest alignment.rdata
// Despite that the code crashes.
// And consequently the code crashes.
// This macro is based on:
// Based on https://stackoverflow.com/q/35268036/850848
// https://stackoverflow.com/q/35268036/850848
#define _MM_SETR_EPI8(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af) \
{ (char)a0, (char)a1, (char)a2, (char)a3, (char)a4, (char)a5, (char)a6, (char)a7, \
(char)a8, (char)a9, (char)aa, (char)ab, (char)ac, (char)ad, (char)ae, (char)af }
@@ -278,7 +276,7 @@ static void aes_ni_next_message_gcm(ssh_cipher *ciph)
msg_counter <<= 32;
msg_counter |= (uint32_t)_mm_extract_epi32(ctx->iv, 1);
msg_counter++;
ctx->iv = _mm_set_epi32(fixed, (int)(msg_counter >> 32), (int)msg_counter, 1); // WINSCP
ctx->iv = _mm_set_epi32(fixed, (int)(msg_counter >> 32), (int)msg_counter, 1); // WINSCP VS
}
typedef __m128i (*aes_ni_fn)(__m128i v, const __m128i *keysched);
@@ -339,7 +337,7 @@ static inline void aes_encrypt_ecb_block_ni(
}
// WINSCP (fixes linker alignment issues for the following function)
const __m128i DUMMY; // WINSCP
const __m128i DUMMY; // WINSCP VS
static inline void aes_gcm_ni(
ssh_cipher *ciph, void *vblk, int blklen, aes_ni_fn encrypt)

View File

@@ -13,9 +13,7 @@ static ssh_cipher *aes_select(const ssh_cipheralg *alg)
{
const ssh_cipheralg *const *real_algs = (const ssh_cipheralg **)alg->extra;
{ // WINSCP
size_t i;
for (i = 0; real_algs[i]; i++) {
for (size_t i = 0; real_algs[i]; i++) {
const ssh_cipheralg *alg = real_algs[i];
const struct aes_extra *alg_extra =
(const struct aes_extra *)alg->extra;
@@ -27,7 +25,6 @@ static ssh_cipher *aes_select(const ssh_cipheralg *alg)
* the last non-NULL entry should be software-only AES, which is
* always available. */
unreachable("aes_select ran off the end of its list");
} // WINSCP
}
#if HAVE_AES_NI
@@ -42,7 +39,7 @@ static ssh_cipher *aes_select(const ssh_cipheralg *alg)
#define IF_NEON(...)
#endif
#define AES_SELECTOR_VTABLE_IMPL(mode_c, id, mode_display, bits, required_mac, flags) /*WINSCP*/ \
#define AES_SELECTOR_VTABLE(mode_c, id, mode_display, bits, ...) \
static const ssh_cipheralg * \
ssh_aes ## bits ## _ ## mode_c ## _impls[] = { \
IF_NI(&ssh_aes ## bits ## _ ## mode_c ## _ni,) \
@@ -51,56 +48,48 @@ static ssh_cipher *aes_select(const ssh_cipheralg *alg)
NULL, \
}; \
const ssh_cipheralg ssh_aes ## bits ## _ ## mode_c = { \
/* WINSCP */ \
/*.new =*/ aes_select, \
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
/*.ssh2_id =*/ id, \
/*.blksize =*/ 16, \
/*.real_keybits =*/ bits, \
/*.padded_keybytes =*/ bits/8, \
flags, \
/*.text_name =*/ "AES-" #bits " " mode_display \
.new = aes_select, \
.ssh2_id = id, \
.blksize = 16, \
.real_keybits = bits, \
.padded_keybytes = bits/8, \
.text_name = "AES-" #bits " " mode_display \
" (dummy selector vtable)", \
required_mac, /*WINSCP*/ \
/*.extra =*/ ssh_aes ## bits ## _ ## mode_c ## _impls, \
.extra = ssh_aes ## bits ## _ ## mode_c ## _impls, \
__VA_ARGS__ \
}
// WINSCP
#define AES_SELECTOR_VTABLE(mode_c, id, mode_display, bits, dummy) AES_SELECTOR_VTABLE_IMPL(mode_c, id, mode_display, bits, NULL, 0)
AES_SELECTOR_VTABLE_IMPL(cbc, "aes128-cbc", "CBC", 128, NULL, /*.flags =*/ SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE_IMPL(cbc, "aes192-cbc", "CBC", 192, NULL, /*.flags =*/ SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE_IMPL(cbc, "aes256-cbc", "CBC", 256, NULL, /*.flags =*/ SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE(cbc, "aes128-cbc", "CBC", 128, .flags = SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE(cbc, "aes192-cbc", "CBC", 192, .flags = SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE(cbc, "aes256-cbc", "CBC", 256, .flags = SSH_CIPHER_IS_CBC);
AES_SELECTOR_VTABLE(sdctr, "aes128-ctr", "SDCTR", 128, );
AES_SELECTOR_VTABLE(sdctr, "aes192-ctr", "SDCTR", 192, );
AES_SELECTOR_VTABLE(sdctr, "aes256-ctr", "SDCTR", 256, );
AES_SELECTOR_VTABLE_IMPL(gcm, "aes128-gcm@openssh.com", "GCM", 128,
/*.required_mac =*/ &ssh2_aesgcm_mac,
/*.flags =*/ SSH_CIPHER_SEPARATE_LENGTH);
AES_SELECTOR_VTABLE_IMPL(gcm, "aes256-gcm@openssh.com", "GCM", 256,
/*.required_mac =*/ &ssh2_aesgcm_mac,
/*.flags =*/ SSH_CIPHER_SEPARATE_LENGTH);
AES_SELECTOR_VTABLE(gcm, "aes128-gcm@openssh.com", "GCM", 128,
.required_mac = &ssh2_aesgcm_mac,
.flags = SSH_CIPHER_SEPARATE_LENGTH);
AES_SELECTOR_VTABLE(gcm, "aes256-gcm@openssh.com", "GCM", 256,
.required_mac = &ssh2_aesgcm_mac,
.flags = SSH_CIPHER_SEPARATE_LENGTH);
/* 192-bit AES-GCM is included only so that testcrypt can run standard
* test vectors against it. OpenSSH doesn't define a protocol id for
* it. Hence setting its ssh2_id to NULL here, and more importantly,
* leaving it out of aesgcm_list[] below. */
AES_SELECTOR_VTABLE_IMPL(gcm, NULL, "GCM", 192,
/*.required_mac =*/ &ssh2_aesgcm_mac,
/*.flags =*/ SSH_CIPHER_SEPARATE_LENGTH);
AES_SELECTOR_VTABLE(gcm, NULL, "GCM", 192,
.required_mac = &ssh2_aesgcm_mac,
.flags = SSH_CIPHER_SEPARATE_LENGTH);
static const ssh_cipheralg ssh_rijndael_lysator = {
/* Same as aes256_cbc, but with a different protocol ID */
/*.new =*/ aes_select,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/*.ssh2_id =*/ "rijndael-cbc@lysator.liu.se",
/*.blksize =*/ 16,
/*.real_keybits =*/ 256,
/*.padded_keybytes =*/ 256/8,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "AES-256 CBC (dummy selector vtable)",
NULL,
/*.extra =*/ ssh_aes256_cbc_impls,
.new = aes_select,
.ssh2_id = "rijndael-cbc@lysator.liu.se",
.blksize = 16,
.real_keybits = 256,
.padded_keybytes = 256/8,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "AES-256 CBC (dummy selector vtable)",
.extra = ssh_aes256_cbc_impls,
};
static const ssh_cipheralg *const aes_list[] = {

View File

@@ -888,8 +888,7 @@ static void aes_sw_setiv_sdctr(ssh_cipher *ciph, const void *viv)
const uint8_t *iv = (const uint8_t *)viv;
/* Import the initial counter value into the internal representation */
unsigned i; // WINSCP
for (i = 0; i < SDCTR_WORDS; i++)
for (unsigned i = 0; i < SDCTR_WORDS; i++)
ctx->iv.sdctr.counter[i] =
GET_BIGNUMINT_MSB_FIRST(
iv + 16 - BIGNUM_INT_BYTES - i*BIGNUM_INT_BYTES);

View File

@@ -56,10 +56,9 @@ static inline void aes_encrypt_ecb_block(ssh_cipher *ciph, void *blk)
#define AES_EXTRA_BITS(impl_c, bits) \
static struct aes_extra_mutable aes ## impl_c ## _extra_mut; \
static const struct aes_extra aes ## bits ## impl_c ## _extra = { \
/* WINSCP */ \
/*.check_available =*/ aes ## impl_c ## _available, \
/*.mut =*/ &aes ## impl_c ## _extra_mut, \
/*.encrypt_ecb_block =*/ &aes ## bits ## impl_c ## _encrypt_ecb_block, \
.check_available = aes ## impl_c ## _available, \
.mut = &aes ## impl_c ## _extra_mut, \
.encrypt_ecb_block = &aes ## bits ## impl_c ## _encrypt_ecb_block, \
}
#define AES_EXTRA(impl_c) \
@@ -75,74 +74,66 @@ static inline void aes_encrypt_ecb_block(ssh_cipher *ciph, void *blk)
static const char ssh_aes ## bits ## _cbc ## impl_c ## ssh2_id[] = "aes" #bits "-cbc"; /*WINSCP*/ \
static const char ssh_aes ## bits ## _cbc ## impl_c ## text_name[] = "AES-" #bits " CBC (" impl_display ")"; /*WINSCP*/ \
const ssh_cipheralg ssh_aes ## bits ## _cbc ## impl_c = { \
/*WINSCP*/ \
/*.new =*/ aes ## impl_c ## _new, \
/*.free =*/ aes ## impl_c ## _free, \
/*.setiv =*/ aes ## impl_c ## _setiv_cbc, \
/*.setkey =*/ aes ## impl_c ## _setkey, \
/*.encrypt =*/ aes ## bits ## impl_c ## _cbc_encrypt, \
/*.decrypt =*/ aes ## bits ## impl_c ## _cbc_decrypt, \
NULL, \
NULL, \
/*.next_message =*/ nullcipher_next_message, \
/*.ssh2_id =*/ ssh_aes ## bits ## _cbc ## impl_c ## ssh2_id, /*WINSCP*/ \
/*.blksize =*/ 16, \
/*.real_keybits =*/ bits, \
/*.padded_keybytes =*/ bits/8, \
/*.flags =*/ SSH_CIPHER_IS_CBC, \
/*.text_name =*/ ssh_aes ## bits ## _cbc ## impl_c ## text_name, /*WINSCP*/ \
NULL, \
/*.extra =*/ &aes ## bits ## impl_c ## _extra, \
.new = aes ## impl_c ## _new, \
.free = aes ## impl_c ## _free, \
.setiv = aes ## impl_c ## _setiv_cbc, \
.setkey = aes ## impl_c ## _setkey, \
.encrypt = aes ## bits ## impl_c ## _cbc_encrypt, \
.decrypt = aes ## bits ## impl_c ## _cbc_decrypt, \
.next_message = nullcipher_next_message, \
.ssh2_id = ssh_aes ## bits ## _cbc ## impl_c ## ssh2_id, /*WINSCP*/ \
.blksize = 16, \
.real_keybits = bits, \
.padded_keybytes = bits/8, \
.flags = SSH_CIPHER_IS_CBC, \
.text_name = ssh_aes ## bits ## _cbc ## impl_c ## text_name, /*WINSCP*/ \
.extra = &aes ## bits ## impl_c ## _extra, \
}
#define AES_SDCTR_VTABLE(impl_c, impl_display, bits) \
static const char ssh_aes ## bits ## _sdctr ## impl_c ## ssh2_id[] = "aes" #bits "-ctr"; /*WINSCP*/ \
static const char ssh_aes ## bits ## _sdctr ## impl_c ## text_name[] = "AES-" #bits " SDCTR (" impl_display ")"; /*WINSCP*/ \
const ssh_cipheralg ssh_aes ## bits ## _sdctr ## impl_c = { \
/*WINSCP*/ \
/*.new =*/ aes ## impl_c ## _new, \
/*.free =*/ aes ## impl_c ## _free, \
/*.setiv =*/ aes ## impl_c ## _setiv_sdctr, \
/*.setkey =*/ aes ## impl_c ## _setkey, \
/*.encrypt =*/ aes ## bits ## impl_c ## _sdctr, \
/*.decrypt =*/ aes ## bits ## impl_c ## _sdctr, \
NULL, \
NULL, \
/*.next_message =*/ nullcipher_next_message, \
/*.ssh2_id =*/ ssh_aes ## bits ## _sdctr ## impl_c ## ssh2_id, /*WINSCP*/ \
/*.blksize =*/ 16, \
/*.real_keybits =*/ bits, \
/*.padded_keybytes =*/ bits/8, \
/*.flags =*/ 0, \
/*.text_name =*/ ssh_aes ## bits ## _sdctr ## impl_c ## text_name, /*WINSCP*/ \
NULL, \
/*.extra =*/ &aes ## bits ## impl_c ## _extra, \
.new = aes ## impl_c ## _new, \
.free = aes ## impl_c ## _free, \
.setiv = aes ## impl_c ## _setiv_sdctr, \
.setkey = aes ## impl_c ## _setkey, \
.encrypt = aes ## bits ## impl_c ## _sdctr, \
.decrypt = aes ## bits ## impl_c ## _sdctr, \
.next_message = nullcipher_next_message, \
.ssh2_id = ssh_aes ## bits ## _sdctr ## impl_c ## ssh2_id, /*WINSCP*/ \
.blksize = 16, \
.real_keybits = bits, \
.padded_keybytes = bits/8, \
.flags = 0, \
.text_name = ssh_aes ## bits ## _sdctr ## impl_c ## text_name, /*WINSCP*/ \
.extra = &aes ## bits ## impl_c ## _extra, \
}
#define AES_GCM_VTABLE(impl_c, impl_display, bits) \
static const char ssh_aes ## bits ## _gcm ## impl_c ## ssh2_id[] = "aes" #bits "-gcm@openssh.com"; /*WINSCP*/ \
static const char ssh_aes ## bits ## _gcm ## impl_c ## text_name[] = "AES-" #bits " GCM (" impl_display ")"; /*WINSCP*/ \
const ssh_cipheralg ssh_aes ## bits ## _gcm ## impl_c = { \
/*.new =*/ aes ## impl_c ## _new, \
/*.free =*/ aes ## impl_c ## _free, \
/*.setiv =*/ aes ## impl_c ## _setiv_gcm, \
/*.setkey =*/ aes ## impl_c ## _setkey, \
/*.encrypt =*/ aes ## bits ## impl_c ## _gcm, \
/*.decrypt =*/ aes ## bits ## impl_c ## _gcm, \
/*.encrypt_length =*/ aesgcm_cipher_crypt_length, \
/*.decrypt_length =*/ aesgcm_cipher_crypt_length, \
/*.next_message =*/ aes ## impl_c ## _next_message_gcm, \
.new = aes ## impl_c ## _new, \
.free = aes ## impl_c ## _free, \
.setiv = aes ## impl_c ## _setiv_gcm, \
.setkey = aes ## impl_c ## _setkey, \
.encrypt = aes ## bits ## impl_c ## _gcm, \
.decrypt = aes ## bits ## impl_c ## _gcm, \
.encrypt_length = aesgcm_cipher_crypt_length, \
.decrypt_length = aesgcm_cipher_crypt_length, \
.next_message = aes ## impl_c ## _next_message_gcm, \
/* 192-bit AES-GCM is included only so that testcrypt can run \
* standard test vectors against it. OpenSSH doesn't define a \
* protocol id for it. So we set its ssh2_id to NULL. */ \
/*.ssh2_id =*/ bits==192 ? NULL : ssh_aes ## bits ## _gcm ## impl_c ## ssh2_id, \
/*.blksize =*/ 16, \
/*.real_keybits =*/ bits, \
/*.padded_keybytes =*/ bits/8, \
/*.flags =*/ SSH_CIPHER_SEPARATE_LENGTH, \
/*.text_name =*/ ssh_aes ## bits ## _gcm ## impl_c ## text_name, \
/*.required_mac =*/ &ssh2_aesgcm_mac, \
/*.extra =*/ &aes ## bits ## impl_c ## _extra, \
.ssh2_id = bits==192 ? NULL : ssh_aes ## bits ## _gcm ## impl_c ## ssh2_id, \
.blksize = 16, \
.real_keybits = bits, \
.padded_keybytes = bits/8, \
.flags = SSH_CIPHER_SEPARATE_LENGTH, \
.text_name = ssh_aes ## bits ## _gcm ## impl_c ## text_name, \
.required_mac = &ssh2_aesgcm_mac, \
.extra = &aes ## bits ## impl_c ## _extra, \
}
#define AES_ALL_VTABLES(impl_c, impl_display) \

View File

@@ -287,7 +287,6 @@ static void PREFIX(mac_genresult)(ssh2_mac *mac, unsigned char *output)
/*
* Consume the final block giving the lengths of the AAD and ciphertext.
*/
{ // WINSCP
unsigned char blk[16];
memset(blk, 0, 16);
PUT_64BIT_MSB_FIRST(blk, ctx->aadlen * 8);
@@ -301,7 +300,6 @@ static void PREFIX(mac_genresult)(ssh2_mac *mac, unsigned char *output)
smemclr(blk, sizeof(blk));
smemclr(ctx->partblk, 16);
} // WINSCP
}
static ssh2_mac *PREFIX(mac_new)(const ssh2_macalg *alg, ssh_cipher *cipher)
@@ -310,7 +308,6 @@ static ssh2_mac *PREFIX(mac_new)(const ssh2_macalg *alg, ssh_cipher *cipher)
if (!check_aesgcm_availability(extra))
return NULL;
{ // WINSCP
#ifdef SPECIAL_ALLOC
CONTEXT *ctx = PREFIX(alloc)();
#else
@@ -327,7 +324,6 @@ static ssh2_mac *PREFIX(mac_new)(const ssh2_macalg *alg, ssh_cipher *cipher)
BinarySink_INIT(ctx, PREFIX(mac_BinarySink_write));
BinarySink_DELEGATE_INIT(&ctx->mac, ctx);
return &ctx->mac;
} // WINSCP
}
static void PREFIX(set_prefix_lengths)(ssh2_mac *mac, size_t skip, size_t aad)
@@ -351,22 +347,22 @@ static void PREFIX(mac_free)(ssh2_mac *mac)
static struct aesgcm_extra_mutable PREFIX(extra_mut);
static const struct aesgcm_extra PREFIX(extra) = {
/*.check_available =*/ PREFIX(available),
/*.mut =*/ &PREFIX(extra_mut),
/*.set_prefix_lengths =*/ PREFIX(set_prefix_lengths),
.check_available = PREFIX(available),
.mut = &PREFIX(extra_mut),
.set_prefix_lengths = PREFIX(set_prefix_lengths),
};
const ssh2_macalg CAT(ssh2_aesgcm_mac_, AESGCM_FLAVOUR) = {
/*.new =*/ PREFIX(mac_new),
/*.free =*/ PREFIX(mac_free),
/*.setkey =*/ PREFIX(mac_setkey),
/*.start =*/ PREFIX(mac_start),
/*.genresult =*/ PREFIX(mac_genresult),
/*.next_message =*/ PREFIX(mac_next_message),
/*.text_name =*/ PREFIX(mac_text_name),
/*.name =*/ "",
/*.etm_name =*/ "", /* Not selectable independently */
/*.len =*/ 16,
/*.keylen =*/ 0,
/*.extra =*/ &PREFIX(extra),
.new = PREFIX(mac_new),
.free = PREFIX(mac_free),
.setkey = PREFIX(mac_setkey),
.start = PREFIX(mac_start),
.genresult = PREFIX(mac_genresult),
.next_message = PREFIX(mac_next_message),
.text_name = PREFIX(mac_text_name),
.name = "",
.etm_name = "", /* Not selectable independently */
.len = 16,
.keylen = 0,
.extra = &PREFIX(extra),
};

View File

@@ -100,24 +100,17 @@ static value128_t pmul(uint64_t x, uint64_t y)
value128_t r;
r.hi = r.lo = 0;
{ // WINSCP
uint64_t bit = 1 & y;
r.lo ^= x & -bit;
{ // WINSCP
unsigned i;
for (i = 1; i < 64; i++) {
for (unsigned i = 1; i < 64; i++) {
bit = 1 & (y >> i);
{ // WINSCP
uint64_t z = x & -bit;
r.lo ^= z << i;
r.hi ^= z >> (64-i);
} // WINSCP
}
} // WINSCP
return r;
} // WINSCP
}
/*
@@ -229,12 +222,10 @@ static void aesgcm_ref_poly_setkey_impl(aesgcm_ref_poly *ctx,
ctx->var.hi = GET_64BIT_MSB_FIRST(var);
ctx->var.lo = GET_64BIT_MSB_FIRST(var + 8);
{ // WINSCP
uint64_t bit = 1 & (ctx->var.hi >> 63);
ctx->var.hi = (ctx->var.hi << 1) ^ (ctx->var.lo >> 63);
ctx->var.lo = (ctx->var.lo << 1) ^ bit;
ctx->var.hi ^= 0xC200000000000000LL & -bit; // WINSCP
} // WINSCP
ctx->var.hi ^= 0xC200000000000000 & -bit;
}
static inline void aesgcm_ref_poly_setup(aesgcm_ref_poly *ctx,
@@ -299,7 +290,6 @@ static inline void aesgcm_ref_poly_coeff(aesgcm_ref_poly *ctx,
* This involves more bookkeeping instructions like XORs, but with
* any luck those are faster than the main multiplication.
*/
{ // WINSCP
uint64_t ah = ctx->acc.hi, al = ctx->acc.lo;
uint64_t bh = ctx->var.hi, bl = ctx->var.lo;
/* Compute the outer two terms */
@@ -346,23 +336,18 @@ static inline void aesgcm_ref_poly_coeff(aesgcm_ref_poly *ctx,
/* First step, adding to the middle two words of our number. After
* this the lowest word (in lo.lo) is ignored. */
{ // WINSCP
value128_t r1 = pmul(0xC200000000000000LL, lo.lo); // WINSCP
value128_t r1 = pmul(0xC200000000000000, lo.lo);
hi.lo ^= r1.hi ^ lo.lo;
lo.hi ^= r1.lo;
/* Second of those steps, adding to the top two words, and
* discarding lo.hi. */
{ // WINSCP
value128_t r2 = pmul(0xC200000000000000LL, lo.hi);
value128_t r2 = pmul(0xC200000000000000, lo.hi);
hi.hi ^= r2.hi ^ lo.hi;
hi.lo ^= r2.lo;
/* Now 'hi' is precisely what we have left. */
ctx->acc = hi;
} // WINSCP
} // WINSCP
} // WINSCP
}
static inline void aesgcm_ref_poly_output(aesgcm_ref_poly *ctx,

View File

@@ -15,8 +15,7 @@ static ssh2_mac *aesgcm_mac_selector_new(const ssh2_macalg *alg,
NULL,
};
size_t i; // WINSCP
for (i = 0; real_algs[i]; i++) {
for (size_t i = 0; real_algs[i]; i++) {
const ssh2_macalg *alg = real_algs[i];
const struct aesgcm_extra *alg_extra =
(const struct aesgcm_extra *)alg->extra;
@@ -31,11 +30,9 @@ static ssh2_mac *aesgcm_mac_selector_new(const ssh2_macalg *alg,
}
const ssh2_macalg ssh2_aesgcm_mac = {
/*.new =*/ aesgcm_mac_selector_new,
NULL, NULL, NULL, NULL, NULL, NULL, // WINSCP
/*.name =*/ "",
/*.etm_name =*/ "", /* Not selectable independently */
/*.len =*/ 16,
/*.keylen =*/ 0,
NULL, // WINSCP
.new = aesgcm_mac_selector_new,
.name = "",
.etm_name = "", /* Not selectable independently */
.len = 16,
.keylen = 0,
};

View File

@@ -79,20 +79,15 @@ static void aesgcm_sw_setkey_impl(aesgcm_sw *gcm, const unsigned char *var)
* logical specification so that's where the logical constant term
* lives. (See more detailed comment in aesgcm-ref-poly.c.)
*/
{ // WINSCP
size_t i;
for (i = 0; i < 128; i++) {
for (size_t i = 0; i < 128; i++) {
gcm->table[127 - i] = v;
/* Multiply v by x, which means shifting right (bit reversal
* again) and then adding 0xE1 at the top if we shifted a 1 out. */
{ // WINSCP
uint64_t lobit = v.lo & 1;
v.lo = (v.lo >> 1) ^ (v.hi << 63);
v.hi = (v.hi >> 1) ^ (0xE100000000000000ULL & -lobit);
} // WINSCP
}
} // WINSCP
}
static inline void aesgcm_sw_setup(aesgcm_sw *gcm, const unsigned char *mask)
@@ -112,38 +107,29 @@ static inline void aesgcm_sw_coeff(aesgcm_sw *gcm, const unsigned char *coeff)
* by XORing together the entries of 'table' corresponding to set
* bits. */
{ // WINSCP
value128_t out;
out.lo = out.hi = 0;
{ // WINSCP
const value128_t *tableptr = gcm->table;
size_t i;
for (i = 0; i < 64; i++) {
for (size_t i = 0; i < 64; i++) {
uint64_t bit = 1 & gcm->acc.lo;
gcm->acc.lo >>= 1;
{ // WINSCP
uint64_t mask = -bit;
out.hi ^= mask & tableptr->hi;
out.lo ^= mask & tableptr->lo;
tableptr++;
} // WINSCP
}
for (i = 0; i < 64; i++) {
for (size_t i = 0; i < 64; i++) {
uint64_t bit = 1 & gcm->acc.hi;
gcm->acc.hi >>= 1;
{ // WINSCP
uint64_t mask = -bit;
out.hi ^= mask & tableptr->hi;
out.lo ^= mask & tableptr->lo;
tableptr++;
} // WINSCP
}
gcm->acc = out;
} // WINSCP
} // WINSCP
}
static inline void aesgcm_sw_output(aesgcm_sw *gcm, unsigned char *output)

View File

@@ -104,41 +104,35 @@ static void arcfour_ssh2_block(ssh_cipher *cipher, void *blk, int len)
}
const ssh_cipheralg ssh_arcfour128_ssh2 = {
// WINSCP
/*.new =*/ arcfour_new,
/*.free =*/ arcfour_free,
/*.setiv =*/ arcfour_ssh2_setiv,
/*.setkey =*/ arcfour_ssh2_setkey,
/*.encrypt =*/ arcfour_ssh2_block,
/*.decrypt =*/ arcfour_ssh2_block,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "arcfour128",
/*.blksize =*/ 1,
/*.real_keybits =*/ 128,
/*.padded_keybytes =*/ 16,
/*.flags =*/ 0,
/*.text_name =*/ "Arcfour-128",
NULL, NULL, // WINSCP
.new = arcfour_new,
.free = arcfour_free,
.setiv = arcfour_ssh2_setiv,
.setkey = arcfour_ssh2_setkey,
.encrypt = arcfour_ssh2_block,
.decrypt = arcfour_ssh2_block,
.next_message = nullcipher_next_message,
.ssh2_id = "arcfour128",
.blksize = 1,
.real_keybits = 128,
.padded_keybytes = 16,
.flags = 0,
.text_name = "Arcfour-128",
};
const ssh_cipheralg ssh_arcfour256_ssh2 = {
// WINSCP
/*.new =*/ arcfour_new,
/*.free =*/ arcfour_free,
/*.setiv =*/ arcfour_ssh2_setiv,
/*.setkey =*/ arcfour_ssh2_setkey,
/*.encrypt =*/ arcfour_ssh2_block,
/*.decrypt =*/ arcfour_ssh2_block,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "arcfour256",
/*.blksize =*/ 1,
/*.real_keybits =*/ 256,
/*.padded_keybytes =*/ 32,
/*.flags =*/ 0,
/*.text_name =*/ "Arcfour-256",
NULL, NULL, // WINSCP
.new = arcfour_new,
.free = arcfour_free,
.setiv = arcfour_ssh2_setiv,
.setkey = arcfour_ssh2_setkey,
.encrypt = arcfour_ssh2_block,
.decrypt = arcfour_ssh2_block,
.next_message = nullcipher_next_message,
.ssh2_id = "arcfour256",
.blksize = 1,
.real_keybits = 256,
.padded_keybytes = 32,
.flags = 0,
.text_name = "Arcfour-256",
};
static const ssh_cipheralg *const arcfour_list[] = {

View File

@@ -89,11 +89,9 @@ strbuf *argon2_long_hash(unsigned length, ptrlen data)
{
ssh_hash *h = hprime_new(length);
put_datapl(h, data);
{ // WINSCP
strbuf *out = strbuf_new();
hprime_final(h, length, strbuf_append(out, length));
return out;
} // WINSCP
}
#endif
@@ -109,9 +107,10 @@ strbuf *argon2_long_hash(unsigned length, ptrlen data)
#ifdef WINSCP_VS
static inline uint64_t ror(uint64_t x, unsigned rotation)
{
#pragma warning(suppress: 4068)
#pragma warning(suppress: 4146)
#pragma warning(push)
#pragma warning(suppress: 4146) // WINSCP VS
unsigned lshift = 63 & -rotation, rshift = 63 & rotation;
#pragma warning(pop)
return (x << lshift) | (x >> rshift);
}
@@ -144,8 +143,7 @@ static inline void GB(uint64_t *a, uint64_t *b, uint64_t *c, uint64_t *d)
static inline void P(uint64_t *out, unsigned outstep,
uint64_t *in, unsigned instep)
{
unsigned i; // WINSCP
for (i = 0; i < 8; i++) {
for (unsigned i = 0; i < 8; i++) {
out[i*outstep] = in[i*instep];
out[i*outstep+1] = in[i*instep+1];
}
@@ -173,17 +171,16 @@ static inline void P(uint64_t *out, unsigned outstep,
{
uint64_t R[128], Q[128], Z[128];
unsigned i; // WINSCP
for (i = 0; i < 128; i++)
for (unsigned i = 0; i < 128; i++)
R[i] = GET_64BIT_LSB_FIRST(X + 8*i) ^ GET_64BIT_LSB_FIRST(Y + 8*i);
for (i = 0; i < 8; i++) // WINSCP
for (unsigned i = 0; i < 8; i++)
P(Q+16*i, 2, R+16*i, 2);
for (i = 0; i < 8; i++) // WINSCP
for (unsigned i = 0; i < 8; i++)
P(Z+2*i, 16, Q+2*i, 16);
for (i = 0; i < 128; i++) // WINSCP
for (unsigned i = 0; i < 128; i++)
PUT_64BIT_LSB_FIRST(out + 8*i,
GET_64BIT_LSB_FIRST(out + 8*i) ^ R[i] ^ Z[i]);
@@ -230,7 +227,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
ssh_hash_final(h, h0);
}
{ // WINSCP
// WINSCP struct blk { uint8_t data[1024]; };
/*
@@ -263,16 +259,14 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
* the long-output hash function H' to hash h0 itself plus the block's
* coordinates in the array.
*/
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < p; i++) {
for (size_t i = 0; i < p; i++) {
ssh_hash *h = hprime_new(1024);
put_data(h, h0, 64);
put_uint32_le(h, 0);
put_uint32_le(h, i);
hprime_final(h, 1024, B[i].data);
}
for (i = 0; i < p; i++) { // WINSCP
for (size_t i = 0; i < p; i++) {
ssh_hash *h = hprime_new(1024);
put_data(h, h0, 64);
put_uint32_le(h, 1);
@@ -297,18 +291,15 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
* independent, and then once we've mixed things up enough, switch over to
* dependent mode to force long serial chains of computation.
*/
{ // WINSCP
size_t jstart = 2;
bool d_mode = (y == 0);
struct blk out2i, tmp2i, in2i;
/* Outermost loop: t whole passes from left to right over the array */
size_t pass; // WINSCP
for (pass = 0; pass < t; pass++) {
for (size_t pass = 0; pass < t; pass++) {
/* Within that, we process the array in its four main slices */
unsigned slice; // WINSCP
for (slice = 0; slice < 4; slice++) {
for (unsigned slice = 0; slice < 4; slice++) {
/* In Argon2id mode, if we're half way through the first pass,
* this is the moment to switch d_mode from false to true */
@@ -317,9 +308,7 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
/* Loop over every segment in the slice (i.e. every row). So i is
* the y-coordinate of each block we process. */
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < p; i++) {
for (size_t i = 0; i < p; i++) {
argon2_internal_vs(jstart, SL, q, slice, d_mode, B, i, p, &in2i, pass, mprime, t, y, &tmp2i, &out2i); // WINSCP
@@ -333,8 +322,7 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
/* And within that segment, process the blocks from left to
* right, starting at 'jstart' (usually 0, but 2 in the first
* slice). */
size_t jpre; // WINSCP
for (jpre = jstart; jpre < SL; jpre++) {
for (size_t jpre = jstart; jpre < SL; jpre++) {
/* j is the x-coordinate of each block we process, made up
* of the slice number and the index 'jpre' within the
@@ -429,7 +417,6 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
* because it's already massively randomised from the real
* inputs).
*/
{ // WINSCP
uint32_t index_l = (pass == 0 && slice == 0) ? i : J2 % p;
/*
@@ -486,7 +473,6 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
}
/* Total number of blocks available to choose from */
{ // WINSCP
uint32_t Wsize = (Wend + q - Wstart) % q;
/* Fiddly computation from the spec that chooses from the
@@ -506,8 +492,6 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
* in our current output block. */
G_xor(B[i + p * j].data, B[i + p * jm1].data,
B[index_l + p * index_z].data);
} // WINSCP
} // WINSCP
}
#undef in2i
#undef tmp2i
@@ -522,7 +506,6 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
* case it still had its initial value of 2 to avoid the starting
* data. */
jstart = 0;
} // WINSCP
}
}
@@ -533,10 +516,8 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
* deliver to the caller.
*/
{ // WINSCP
struct blk C = B[p * (q-1)];
size_t i; // WINSCP
for (i = 1; i < p; i++)
for (size_t i = 1; i < p; i++)
memxor(C.data, C.data, B[i + p * (q-1)].data, 1024);
{
@@ -554,10 +535,6 @@ void argon2_internal_vs(size_t jstart, size_t SL, size_t q, unsigned slice, bool
smemclr(C.data, sizeof(C.data));
smemclr(B, mprime * sizeof(struct blk));
sfree(B);
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -600,7 +577,6 @@ void argon2_choose_passes(
while (true) {
unsigned long start_time = GETTICKCOUNT();
argon2(flavour, mem, b, parallel, taglen, P, S, K, X, out);
{ // WINSCP
unsigned long ticks = GETTICKCOUNT() - start_time;
/* But just in case computers get _too_ fast, we have to cap
@@ -617,7 +593,6 @@ void argon2_choose_passes(
b += a;
a = b - a;
}
} // WINSCP
}
}
#endif

View File

@@ -11,9 +11,7 @@
static inline uint64_t ror(uint64_t x, unsigned rotation)
{
#pragma option push -w-ngu // WINSCP
unsigned lshift = 63 & -rotation, rshift = 63 & rotation;
#pragma option pop // WINSCP
return (x << lshift) | (x >> rshift);
}
@@ -22,15 +20,14 @@ enum { R1 = 32, R2 = 24, R3 = 16, R4 = 63 };
/* RFC 7693 section 2.6 */
static const uint64_t iv[] = {
// WINSCP (ULL)
0x6a09e667f3bcc908ULL, /* floor(2^64 * frac(sqrt(2))) */
0xbb67ae8584caa73bULL, /* floor(2^64 * frac(sqrt(3))) */
0x3c6ef372fe94f82bULL, /* floor(2^64 * frac(sqrt(5))) */
0xa54ff53a5f1d36f1ULL, /* floor(2^64 * frac(sqrt(7))) */
0x510e527fade682d1ULL, /* floor(2^64 * frac(sqrt(11))) */
0x9b05688c2b3e6c1fULL, /* floor(2^64 * frac(sqrt(13))) */
0x1f83d9abfb41bd6bULL, /* floor(2^64 * frac(sqrt(17))) */
0x5be0cd19137e2179ULL, /* floor(2^64 * frac(sqrt(19))) */
0x6a09e667f3bcc908, /* floor(2^64 * frac(sqrt(2))) */
0xbb67ae8584caa73b, /* floor(2^64 * frac(sqrt(3))) */
0x3c6ef372fe94f82b, /* floor(2^64 * frac(sqrt(5))) */
0xa54ff53a5f1d36f1, /* floor(2^64 * frac(sqrt(7))) */
0x510e527fade682d1, /* floor(2^64 * frac(sqrt(11))) */
0x9b05688c2b3e6c1f, /* floor(2^64 * frac(sqrt(13))) */
0x1f83d9abfb41bd6b, /* floor(2^64 * frac(sqrt(17))) */
0x5be0cd19137e2179, /* floor(2^64 * frac(sqrt(19))) */
};
/* RFC 7693 section 2.7 */
@@ -78,9 +75,7 @@ static inline void f(uint64_t h[8], uint64_t m[16], uint64_t offset_hi,
v[12] ^= offset_lo;
v[13] ^= offset_hi;
v[14] ^= -(uint64_t)final;
{ // WINSCP
unsigned round; // WINSCP
for (round = 0; round < 12; round++) {
for (unsigned round = 0; round < 12; round++) {
const unsigned char *s = sigma[round];
g(v, 0, 4, 8, 12, m[s[ 0]], m[s[ 1]]);
g(v, 1, 5, 9, 13, m[s[ 2]], m[s[ 3]]);
@@ -91,21 +86,16 @@ static inline void f(uint64_t h[8], uint64_t m[16], uint64_t offset_hi,
g(v, 2, 7, 8, 13, m[s[12]], m[s[13]]);
g(v, 3, 4, 9, 14, m[s[14]], m[s[15]]);
}
{ // WINSCP
unsigned i; // WINSCP
for (i = 0; i < 8; i++)
for (unsigned i = 0; i < 8; i++)
h[i] ^= v[i] ^ v[i+8];
smemclr(v, sizeof(v));
} // WINSCP
} // WINSCP
}
static inline void f_outer(uint64_t h[8], uint8_t blk[128], uint64_t offset_hi,
uint64_t offset_lo, unsigned final)
{
uint64_t m[16];
unsigned i; // WINSCP
for (i = 0; i < 16; i++)
for (unsigned i = 0; i < 16; i++)
m[i] = GET_64BIT_LSB_FIRST(blk + 8*i);
f(h, m, offset_hi, offset_lo, final);
smemclr(m, sizeof(m));
@@ -129,14 +119,12 @@ static ssh_hash *blake2b_new_inner(unsigned hashlen)
{
assert(hashlen <= ssh_blake2b.hlen);
{ // WINSCP
blake2b *s = snew(blake2b);
s->hash.vt = &ssh_blake2b;
s->hashlen = hashlen;
BinarySink_INIT(s, blake2b_write);
BinarySink_DELEGATE_INIT(&s->hash, s);
return &s->hash;
} // WINSCP
}
static ssh_hash *blake2b_new(const ssh_hashalg *alg)
@@ -195,7 +183,6 @@ static void blake2b_write(BinarySink *bs, const void *vp, size_t len)
s->used = 0;
}
{ // WINSCP
size_t chunk = sizeof(s->block) - s->used;
if (chunk > len)
chunk = len;
@@ -207,7 +194,6 @@ static void blake2b_write(BinarySink *bs, const void *vp, size_t len)
s->lenlo += chunk;
s->lenhi += (s->lenlo < chunk);
} // WINSCP
}
}
@@ -218,25 +204,20 @@ static void blake2b_digest(ssh_hash *hash, uint8_t *digest)
memset(s->block + s->used, 0, sizeof(s->block) - s->used);
f_outer(s->h, s->block, s->lenhi, s->lenlo, 1);
{ // WINSCP
uint8_t hash_pre[128];
unsigned i; // WINSCP
for (i = 0; i < 8; i++)
for (unsigned i = 0; i < 8; i++)
PUT_64BIT_LSB_FIRST(hash_pre + 8*i, s->h[i]);
memcpy(digest, hash_pre, s->hashlen);
smemclr(hash_pre, sizeof(hash_pre));
} // WINSCP
}
const ssh_hashalg ssh_blake2b = {
// WINSCP
/*.new =*/ blake2b_new,
/*.reset =*/ blake2b_reset,
/*.copyfrom =*/ blake2b_copyfrom,
/*.digest =*/ blake2b_digest,
/*.free =*/ blake2b_free,
/*.hlen =*/ 64,
/*.blocklen =*/ 128,
.new = blake2b_new,
.reset = blake2b_reset,
.copyfrom = blake2b_copyfrom,
.digest = blake2b_digest,
.free = blake2b_free,
.hlen = 64,
.blocklen = 128,
HASHALG_NAMES_BARE("BLAKE2b-64"),
NULL, // WINSCP
};

View File

@@ -648,60 +648,50 @@ static void blowfish_ssh2_sdctr(ssh_cipher *cipher, void *blk, int len)
}
const ssh_cipheralg ssh_blowfish_ssh1 = {
// WINSCP
/*.new =*/ blowfish_new,
/*.free =*/ blowfish_free,
/*.setiv =*/ blowfish_ssh1_setiv,
/*.setkey =*/ blowfish_ssh_setkey,
/*.encrypt =*/ blowfish_ssh1_encrypt_blk,
/*.decrypt =*/ blowfish_ssh1_decrypt_blk,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
NULL, // WINSCP
/*.blksize =*/ 8,
/*.real_keybits =*/ 128,
/*.padded_keybytes =*/ SSH1_SESSION_KEY_LENGTH,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "Blowfish-256 CBC",
NULL, NULL, // WINSCP
.new = blowfish_new,
.free = blowfish_free,
.setiv = blowfish_ssh1_setiv,
.setkey = blowfish_ssh_setkey,
.encrypt = blowfish_ssh1_encrypt_blk,
.decrypt = blowfish_ssh1_decrypt_blk,
.next_message = nullcipher_next_message,
.blksize = 8,
.real_keybits = 128,
.padded_keybytes = SSH1_SESSION_KEY_LENGTH,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "Blowfish-256 CBC",
};
const ssh_cipheralg ssh_blowfish_ssh2 = {
// WINSCP
/*.new =*/ blowfish_new,
/*.free =*/ blowfish_free,
/*.setiv =*/ blowfish_ssh2_setiv,
/*.setkey =*/ blowfish_ssh_setkey,
/*.encrypt =*/ blowfish_ssh2_encrypt_blk,
/*.decrypt =*/ blowfish_ssh2_decrypt_blk,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "blowfish-cbc",
/*.blksize =*/ 8,
/*.real_keybits =*/ 128,
/*.padded_keybytes =*/ 16,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "Blowfish-128 CBC",
NULL, NULL, // WINSCP
.new = blowfish_new,
.free = blowfish_free,
.setiv = blowfish_ssh2_setiv,
.setkey = blowfish_ssh_setkey,
.encrypt = blowfish_ssh2_encrypt_blk,
.decrypt = blowfish_ssh2_decrypt_blk,
.next_message = nullcipher_next_message,
.ssh2_id = "blowfish-cbc",
.blksize = 8,
.real_keybits = 128,
.padded_keybytes = 16,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "Blowfish-128 CBC",
};
const ssh_cipheralg ssh_blowfish_ssh2_ctr = {
// WINSCP
/*.new =*/ blowfish_new,
/*.free =*/ blowfish_free,
/*.setiv =*/ blowfish_ssh2_setiv,
/*.setkey =*/ blowfish_ssh_setkey,
/*.encrypt =*/ blowfish_ssh2_sdctr,
/*.decrypt =*/ blowfish_ssh2_sdctr,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "blowfish-ctr",
/*.blksize =*/ 8,
/*.real_keybits =*/ 256,
/*.padded_keybytes =*/ 32,
/*.flags =*/ 0,
/*.text_name =*/ "Blowfish-256 SDCTR",
NULL, NULL, // WINSCP
.new = blowfish_new,
.free = blowfish_free,
.setiv = blowfish_ssh2_setiv,
.setkey = blowfish_ssh_setkey,
.encrypt = blowfish_ssh2_sdctr,
.decrypt = blowfish_ssh2_sdctr,
.next_message = nullcipher_next_message,
.ssh2_id = "blowfish-ctr",
.blksize = 8,
.real_keybits = 256,
.padded_keybytes = 32,
.flags = 0,
.text_name = "Blowfish-256 SDCTR",
};
static const ssh_cipheralg *const blowfish_list[] = {

View File

@@ -774,7 +774,7 @@ static void poly1305_init(struct poly1305 *ctx)
static void poly1305_key(struct poly1305 *ctx, ptrlen key)
{
pinitassert(key.len == 32); /* Takes a 256 bit key */
assert(key.len == 32); /* Takes a 256 bit key */
unsigned char key_copy[16];
memcpy(key_copy, key.ptr, 16);
@@ -959,20 +959,18 @@ static const char *poly_text_name(ssh2_mac *mac)
}
const ssh2_macalg ssh2_poly1305 = {
// WINSCP
/*.new =*/ poly_ssh2_new,
/*.free =*/ poly_ssh2_free,
/*.setkey =*/ poly_setkey,
/*.start =*/ poly_start,
/*.genresult =*/ poly_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ poly_text_name,
/*.name =*/ "",
/*.etm_name =*/ "", /* Not selectable individually, just part of
.new = poly_ssh2_new,
.free = poly_ssh2_free,
.setkey = poly_setkey,
.start = poly_start,
.genresult = poly_genresult,
.next_message = nullmac_next_message,
.text_name = poly_text_name,
.name = "",
.etm_name = "", /* Not selectable individually, just part of
* ChaCha20-Poly1305 */
/*.len =*/ 16,
/*.keylen =*/ 0,
NULL, // WINSCP
.len = 16,
.keylen = 0,
};
static ssh_cipher *ccp_new(const ssh_cipheralg *alg)
@@ -1056,24 +1054,22 @@ static void ccp_decrypt_length(ssh_cipher *cipher, void *blk, int len,
}
const ssh_cipheralg ssh2_chacha20_poly1305 = {
// WINSCP
/*.new =*/ ccp_new,
/*.free =*/ ccp_free,
/*.setiv =*/ ccp_iv,
/*.setkey =*/ ccp_key,
/*.encrypt =*/ ccp_encrypt,
/*.decrypt =*/ ccp_decrypt,
/*.encrypt_length =*/ ccp_encrypt_length,
/*.decrypt_length =*/ ccp_decrypt_length,
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "chacha20-poly1305@openssh.com",
/*.blksize =*/ 1,
/*.real_keybits =*/ 512,
/*.padded_keybytes =*/ 64,
/*.flags =*/ SSH_CIPHER_SEPARATE_LENGTH,
/*.text_name =*/ "ChaCha20",
/*.required_mac =*/ &ssh2_poly1305,
NULL, // WINSCP
.new = ccp_new,
.free = ccp_free,
.setiv = ccp_iv,
.setkey = ccp_key,
.encrypt = ccp_encrypt,
.decrypt = ccp_decrypt,
.encrypt_length = ccp_encrypt_length,
.decrypt_length = ccp_decrypt_length,
.next_message = nullcipher_next_message,
.ssh2_id = "chacha20-poly1305@openssh.com",
.blksize = 1,
.real_keybits = 512,
.padded_keybytes = 64,
.flags = SSH_CIPHER_SEPARATE_LENGTH,
.text_name = "ChaCha20",
.required_mac = &ssh2_poly1305,
};
static const ssh_cipheralg *const ccp_list[] = {

View File

@@ -74,11 +74,11 @@
*/
static inline uint32_t rol(uint32_t x, unsigned c)
{
return (x << (31 & c)) | (x >> (31 & -(int/*WINSCP*/)c));
return (x << (31 & c)) | (x >> (31 & -c));
}
static inline uint32_t ror(uint32_t x, unsigned c)
{
return rol(x, -(int/*WINSCP*/)c);
return rol(x, -c);
}
/*
@@ -275,7 +275,6 @@ static inline uint32_t des_S(uint32_t si6420, uint32_t si7531)
*/
/* Set up the gadgets */
{ // WINSCP
uint32_t c40 = ((si6420 ) & 0x00FC00FC) | 0xFF00FF00;
uint32_t c62 = ((si6420 >> 8) & 0x00FC00FC) | 0xFF00FF00;
uint32_t c51 = ((si7531 ) & 0x00FC00FC) | 0xFF00FF00;
@@ -284,15 +283,13 @@ static inline uint32_t des_S(uint32_t si6420, uint32_t si7531)
" c51=%08"PRIx32" c73=%08"PRIx32"\n", c40, c62, c51, c73);
/* Iterate over the table */
{ // WINSCP
static const struct tbl { uint32_t t40, t62, t51, t73; } tbl[32] = {
#define TABLE32(a, b) { ((uint32_t)a##LL), (a##LL>>32), ((uint32_t)b##LL), (b##LL>>32) }, // WINSCP
#define TABLE32(a, b) { ((uint32_t)a), (a>>32), ((uint32_t)b), (b>>32) },
SBOX_ITERATION(TABLE32)
#undef TABLE32
};
uint32_t s40 = 0, s62 = 0, s51 = 0, s73 = 0;
const struct tbl *t, *limit; // WINSCP
for (t = tbl, limit = tbl + 32; t < limit; t++) {
for (const struct tbl *t = tbl, *limit = tbl + 32; t < limit; t++) {
s40 ^= c40 & t->t40; c40 += 0x00080008;
s62 ^= c62 & t->t62; c62 += 0x00080008;
s51 ^= c51 & t->t51; c51 += 0x00080008;
@@ -324,8 +321,6 @@ static inline uint32_t des_S(uint32_t si6420, uint32_t si7531)
/* Recombine and return */
return (s40 >> 12) | (s62 >> 4) | (s51 >> 8) | (s73);
} // WINSCP
} // WINSCP
#endif /* SIXTY_FOUR_BIT */
@@ -463,20 +458,17 @@ static void des_key_setup(uint64_t key, des_keysched *sched)
* 28-bit integers starting at bits 0 and 32. */
uint64_t CD = bitsel(key, PC1, lenof(PC1));
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < 16; i++) {
for (size_t i = 0; i < 16; i++) {
/* Rotate each 28-bit half of CD left by 1 or 2 bits (varying
* between rounds) */
CD <<= leftshifts[i];
CD = (CD & 0x0FFFFFFF0FFFFFFFLL) | ((CD & 0xF0000000F0000000LL) >> 28); // WINSCP
CD = (CD & 0x0FFFFFFF0FFFFFFF) | ((CD & 0xF0000000F0000000) >> 28);
/* Select key bits from the rotated word to use during the
* actual cipher */
sched->k7531[i] = bitsel(CD, PC2_7531, lenof(PC2_7531));
sched->k6420[i] = bitsel(CD, PC2_6420, lenof(PC2_6420));
}
} // WINSCP
}
/*
@@ -691,42 +683,36 @@ static void des_cbc_decrypt(ssh_cipher *ciph, void *vdata, int len)
}
const ssh_cipheralg ssh_des = {
// WINSCP
/*.new =*/ des_cbc_new,
/*.free =*/ des_cbc_free,
/*.setiv =*/ des_cbc_setiv,
/*.setkey =*/ des_cbc_setkey,
/*.encrypt =*/ des_cbc_encrypt,
/*.decrypt =*/ des_cbc_decrypt,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "des-cbc",
/*.blksize =*/ 8,
/*.real_keybits =*/ 56,
/*.padded_keybytes =*/ 8,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "single-DES CBC",
NULL, NULL, // WINSCP
.new = des_cbc_new,
.free = des_cbc_free,
.setiv = des_cbc_setiv,
.setkey = des_cbc_setkey,
.encrypt = des_cbc_encrypt,
.decrypt = des_cbc_decrypt,
.next_message = nullcipher_next_message,
.ssh2_id = "des-cbc",
.blksize = 8,
.real_keybits = 56,
.padded_keybytes = 8,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "single-DES CBC",
};
const ssh_cipheralg ssh_des_sshcom_ssh2 = {
/* Same as ssh_des_cbc, but with a different SSH-2 ID */
// WINSCP
/*.new =*/ des_cbc_new,
/*.free =*/ des_cbc_free,
/*.setiv =*/ des_cbc_setiv,
/*.setkey =*/ des_cbc_setkey,
/*.encrypt =*/ des_cbc_encrypt,
/*.decrypt =*/ des_cbc_decrypt,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "des-cbc@ssh.com",
/*.blksize =*/ 8,
/*.real_keybits =*/ 56,
/*.padded_keybytes =*/ 8,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "single-DES CBC",
NULL, NULL, // WINSCP
.new = des_cbc_new,
.free = des_cbc_free,
.setiv = des_cbc_setiv,
.setkey = des_cbc_setkey,
.encrypt = des_cbc_encrypt,
.decrypt = des_cbc_decrypt,
.next_message = nullcipher_next_message,
.ssh2_id = "des-cbc@ssh.com",
.blksize = 8,
.real_keybits = 56,
.padded_keybytes = 8,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "single-DES CBC",
};
static const ssh_cipheralg *const des_list[] = {
@@ -766,8 +752,7 @@ static void des3_cbc1_setkey(ssh_cipher *ciph, const void *vkey)
{
struct des3_cbc1_ctx *ctx = container_of(ciph, struct des3_cbc1_ctx, ciph);
const uint8_t *key = (const uint8_t *)vkey;
size_t i; // WINSCP
for (i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
des_key_setup(GET_64BIT_MSB_FIRST(key + 8*i), &ctx->sched[i]);
}
@@ -791,12 +776,10 @@ static void des3_cbc1_cbc_encrypt(ssh_cipher *ciph, void *vdata, int len)
lr = des_inner_cipher(lr, &ctx->sched[0], ENCIPHER);
lr = des_inner_cipher(lr, &ctx->sched[1], DECIPHER);
lr = des_inner_cipher(lr, &ctx->sched[2], ENCIPHER);
{ // WINSCP
LR ciphertext = des_FP(lr);
des_store_lr(data, ciphertext);
ctx->iv = ciphertext;
} // WINSCP
}
}
@@ -812,33 +795,28 @@ static void des3_cbc1_cbc_decrypt(ssh_cipher *ciph, void *vdata, int len)
lr = des_inner_cipher(lr, &ctx->sched[2], DECIPHER);
lr = des_inner_cipher(lr, &ctx->sched[1], ENCIPHER);
lr = des_inner_cipher(lr, &ctx->sched[0], DECIPHER);
{ // WINSCP
LR cipher_out = des_FP(lr);
LR plaintext = des_xor_lr(cipher_out, ctx->iv);
des_store_lr(data, plaintext);
ctx->iv = ciphertext;
} // WINSCP
}
}
const ssh_cipheralg ssh_3des_ssh2 = {
// WINSCP
/*.new =*/ des3_cbc1_new,
/*.free =*/ des3_cbc1_free,
/*.setiv =*/ des3_cbc1_setiv,
/*.setkey =*/ des3_cbc1_setkey,
/*.encrypt =*/ des3_cbc1_cbc_encrypt,
/*.decrypt =*/ des3_cbc1_cbc_decrypt,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "3des-cbc",
/*.blksize =*/ 8,
/*.real_keybits =*/ 168,
/*.padded_keybytes =*/ 24,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "triple-DES CBC",
NULL, NULL, // WINSCP
.new = des3_cbc1_new,
.free = des3_cbc1_free,
.setiv = des3_cbc1_setiv,
.setkey = des3_cbc1_setkey,
.encrypt = des3_cbc1_cbc_encrypt,
.decrypt = des3_cbc1_cbc_decrypt,
.next_message = nullcipher_next_message,
.ssh2_id = "3des-cbc",
.blksize = 8,
.real_keybits = 168,
.padded_keybytes = 24,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "triple-DES CBC",
};
/* ----------------------------------------------------------------------
@@ -875,8 +853,7 @@ static void des3_sdctr_setkey(ssh_cipher *ciph, const void *vkey)
struct des3_sdctr_ctx *ctx = container_of(
ciph, struct des3_sdctr_ctx, ciph);
const uint8_t *key = (const uint8_t *)vkey;
size_t i; // WINSCP
for (i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
des_key_setup(GET_64BIT_MSB_FIRST(key + 8*i), &ctx->sched[i]);
}
@@ -887,8 +864,7 @@ static void des3_sdctr_setiv(ssh_cipher *ciph, const void *viv)
const uint8_t *iv = (const uint8_t *)viv;
/* Import the initial counter value into the internal representation */
unsigned i = 0; // WINSCP
for (i = 0; i < SDCTR_WORDS; i++)
for (unsigned i = 0; i < SDCTR_WORDS; i++)
ctx->counter[i] = GET_BIGNUMINT_MSB_FIRST(
iv + 8 - BIGNUM_INT_BYTES - i*BIGNUM_INT_BYTES);
}
@@ -901,54 +877,44 @@ static void des3_sdctr_encrypt_decrypt(ssh_cipher *ciph, void *vdata, int len)
uint8_t iv_buf[8];
for (; len > 0; len -= 8, data += 8) {
/* Format the counter value into the buffer. */
unsigned i; // WINSCP
for (i = 0; i < SDCTR_WORDS; i++)
for (unsigned i = 0; i < SDCTR_WORDS; i++)
PUT_BIGNUMINT_MSB_FIRST(
iv_buf + 8 - BIGNUM_INT_BYTES - i*BIGNUM_INT_BYTES,
ctx->counter[i]);
/* Increment the counter. */
{ // WINSCP
BignumCarry carry = 1;
for (i = 0; i < SDCTR_WORDS; i++) // WINSCP
for (unsigned i = 0; i < SDCTR_WORDS; i++)
BignumADC(ctx->counter[i], carry, ctx->counter[i], 0, carry);
/* Triple-encrypt the counter value from the IV. */
{ // WINSCP
LR lr = des_IP(des_load_lr(iv_buf));
lr = des_inner_cipher(lr, &ctx->sched[0], ENCIPHER);
lr = des_inner_cipher(lr, &ctx->sched[1], DECIPHER);
lr = des_inner_cipher(lr, &ctx->sched[2], ENCIPHER);
{ // WINSCP
LR keystream = des_FP(lr);
LR input = des_load_lr(data);
LR output = des_xor_lr(input, keystream);
des_store_lr(data, output);
} // WINSCP
} // WINSCP
} // WINSCP
}
smemclr(iv_buf, sizeof(iv_buf));
}
const ssh_cipheralg ssh_3des_ssh2_ctr = {
// WINSCP
/*.new =*/ des3_sdctr_new,
/*.free =*/ des3_sdctr_free,
/*.setiv =*/ des3_sdctr_setiv,
/*.setkey =*/ des3_sdctr_setkey,
/*.encrypt =*/ des3_sdctr_encrypt_decrypt,
/*.decrypt =*/ des3_sdctr_encrypt_decrypt,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
/*.ssh2_id =*/ "3des-ctr",
/*.blksize =*/ 8,
/*.real_keybits =*/ 168,
/*.padded_keybytes =*/ 24,
/*.flags =*/ 0,
/*.text_name =*/ "triple-DES SDCTR",
NULL, NULL, // WINSCP
.new = des3_sdctr_new,
.free = des3_sdctr_free,
.setiv = des3_sdctr_setiv,
.setkey = des3_sdctr_setkey,
.encrypt = des3_sdctr_encrypt_decrypt,
.decrypt = des3_sdctr_encrypt_decrypt,
.next_message = nullcipher_next_message,
.ssh2_id = "3des-ctr",
.blksize = 8,
.real_keybits = 168,
.padded_keybytes = 24,
.flags = 0,
.text_name = "triple-DES SDCTR",
};
static const ssh_cipheralg *const des3_list[] = {
@@ -988,8 +954,7 @@ static void des3_cbc3_setkey(ssh_cipher *ciph, const void *vkey)
{
struct des3_cbc3_ctx *ctx = container_of(ciph, struct des3_cbc3_ctx, ciph);
const uint8_t *key = (const uint8_t *)vkey;
size_t i; // WINSCP
for (i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
des_key_setup(GET_64BIT_MSB_FIRST(key + 8*i), &ctx->sched[i]);
}
@@ -1012,11 +977,8 @@ static void des3_cbc3_setiv(ssh_cipher *ciph, const void *viv)
/* But we store the IVs in permuted form, so that we can handle
* all three CBC layers without having to do IP/FP in between. */
iv = des_IP(iv);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < 3; i++)
for (size_t i = 0; i < 3; i++)
ctx->iv[i] = iv;
} // WINSCP
}
static void des3_cbc3_cbc_encrypt(ssh_cipher *ciph, void *vdata, int len)
@@ -1034,7 +996,6 @@ static void des3_cbc3_cbc_encrypt(ssh_cipher *ciph, void *vdata, int len)
lr = des_inner_cipher(lr, &ctx->sched[0], ENCIPHER);
ctx->iv[0] = lr;
{ // WINSCP
LR ciphertext = lr;
lr = des_inner_cipher(ciphertext, &ctx->sched[1], DECIPHER);
lr = des_xor_lr(lr, ctx->iv[1]);
@@ -1045,7 +1006,6 @@ static void des3_cbc3_cbc_encrypt(ssh_cipher *ciph, void *vdata, int len)
ctx->iv[2] = lr;
des_store_lr(data, des_FP(lr));
} // WINSCP
}
}
@@ -1078,20 +1038,16 @@ static void des3_cbc3_cbc_decrypt(ssh_cipher *ciph, void *vdata, int len)
}
const ssh_cipheralg ssh_3des_ssh1 = {
// WINSCP
/*.new =*/ des3_cbc3_new,
/*.free =*/ des3_cbc3_free,
/*.setiv =*/ des3_cbc3_setiv,
/*.setkey =*/ des3_cbc3_setkey,
/*.encrypt =*/ des3_cbc3_cbc_encrypt,
/*.decrypt =*/ des3_cbc3_cbc_decrypt,
NULL, NULL, // WINSCP
/*.next_message =*/ nullcipher_next_message,
NULL, // WINSCP
/*.blksize =*/ 8,
/*.real_keybits =*/ 168,
/*.padded_keybytes =*/ 24,
/*.flags =*/ SSH_CIPHER_IS_CBC,
/*.text_name =*/ "triple-DES inner-CBC",
NULL, NULL, // WINSCP
.new = des3_cbc3_new,
.free = des3_cbc3_free,
.setiv = des3_cbc3_setiv,
.setkey = des3_cbc3_setkey,
.encrypt = des3_cbc3_cbc_encrypt,
.decrypt = des3_cbc3_cbc_decrypt,
.next_message = nullcipher_next_message,
.blksize = 8,
.real_keybits = 168,
.padded_keybytes = 24,
.flags = SSH_CIPHER_IS_CBC,
.text_name = "triple-DES inner-CBC",
};

View File

@@ -22,7 +22,7 @@ static void dh_group1_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 2412 section E.2:
spigot -B16 '2^1024 - 2^960 - 1 + 2^64 * ( floor(2^894 pi) + 129093 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -31,7 +31,7 @@ static void dh_group14_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 3526 section 3:
spigot -B16 '2^2048 - 2^1984 - 1 + 2^64 * ( floor(2^1918 pi) + 124476 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AACAA68FFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -40,7 +40,7 @@ static void dh_group15_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 3526 section 4:
spigot -B16 '2^3072 - 2^3008 - 1 + 2^64 * ( floor(2^2942 pi) + 1690314 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -49,7 +49,7 @@ static void dh_group16_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 3526 section 5:
spigot -B16 '2^4096 - 2^4032 - 1 + 2^64 * ( floor(2^3966 pi) + 240904 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199FFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -58,7 +58,7 @@ static void dh_group17_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 3526 section 6:
spigot -B16 '2^6144 - 2^6080 - 1 + 2^64 * ( floor(2^6014 pi) + 929484 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -67,7 +67,7 @@ static void dh_group18_construct(dh_ctx *ctx)
/* Command to recompute, from the expression in RFC 3526 section 7:
spigot -B16 '2^8192 - 2^8128 - 1 + 2^64 * ( floor(2^8062 pi) + 4743158 )'
*/
ctx->p = MP_LITERAL_WINSCP_STR("0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF");
ctx->p = MP_LITERAL(0xFFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C93402849236C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AACC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E438777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F5683423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD922222E04A4037C0713EB57A81A23F0C73473FC646CEA306B4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A364597E899A0255DC164F31CC50846851DF9AB48195DED7EA1B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F924009438B481C6CD7889A002ED5EE382BC9190DA6FC026E479558E4475677E9AA9E3050E2765694DFC81F56E880B96E7160C980DD98EDD3DFFFFFFFFFFFFFFFFF);
ctx->g = mp_from_integer(2);
}
@@ -76,12 +76,11 @@ static const struct dh_extra extra_group1 = {
};
const ssh_kex ssh_diffiehellman_group1_sha1 = {
/*.name =*/ "diffie-hellman-group1-sha1",
/*.groupname =*/ "group1",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_group1,
.name = "diffie-hellman-group1-sha1",
.groupname = "group1",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha1,
.extra = &extra_group1,
};
static const ssh_kex *const group1_list[] = {
@@ -95,12 +94,11 @@ static const struct dh_extra extra_group18 = {
};
const ssh_kex ssh_diffiehellman_group18_sha512 = {
/*.name =*/ "diffie-hellman-group18-sha512",
/*.groupname =*/ "group18",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group18,
.name = "diffie-hellman-group18-sha512",
.groupname = "group18",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha512,
.extra = &extra_group18,
};
static const ssh_kex *const group18_list[] = {
@@ -116,12 +114,11 @@ static const struct dh_extra extra_group17 = {
};
const ssh_kex ssh_diffiehellman_group17_sha512 = {
/*.name =*/ "diffie-hellman-group17-sha512",
/*.groupname =*/ "group17",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group17,
.name = "diffie-hellman-group17-sha512",
.groupname = "group17",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha512,
.extra = &extra_group17,
};
static const ssh_kex *const group17_list[] = {
@@ -137,12 +134,11 @@ static const struct dh_extra extra_group16 = {
};
const ssh_kex ssh_diffiehellman_group16_sha512 = {
/*.name =*/ "diffie-hellman-group16-sha512",
/*.groupname =*/ "group16",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group16,
.name = "diffie-hellman-group16-sha512",
.groupname = "group16",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha512,
.extra = &extra_group16,
};
static const ssh_kex *const group16_list[] = {
@@ -158,12 +154,11 @@ static const struct dh_extra extra_group15 = {
};
const ssh_kex ssh_diffiehellman_group15_sha512 = {
/*.name =*/ "diffie-hellman-group15-sha512",
/*.groupname =*/ "group15",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group15,
.name = "diffie-hellman-group15-sha512",
.groupname = "group15",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha512,
.extra = &extra_group15,
};
static const ssh_kex *const group15_list[] = {
@@ -179,21 +174,19 @@ static const struct dh_extra extra_group14 = {
};
const ssh_kex ssh_diffiehellman_group14_sha256 = {
/*.name =*/ "diffie-hellman-group14-sha256",
/*.groupname =*/ "group14",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha256,
NULL, // WINSCP
/*.extra =*/ &extra_group14,
.name = "diffie-hellman-group14-sha256",
.groupname = "group14",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha256,
.extra = &extra_group14,
};
const ssh_kex ssh_diffiehellman_group14_sha1 = {
/*.name =*/ "diffie-hellman-group14-sha1",
/*.groupname =*/ "group14",
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_group14,
.name = "diffie-hellman-group14-sha1",
.groupname = "group14",
.main_type = KEXTYPE_DH,
.hash = &ssh_sha1,
.extra = &extra_group14,
};
static const ssh_kex *const group14_list[] = {
@@ -208,21 +201,19 @@ const ssh_kexes ssh_diffiehellman_group14 = {
static const struct dh_extra extra_gex = { true };
static const ssh_kex ssh_diffiehellman_gex_sha256 = {
/*.name =*/ "diffie-hellman-group-exchange-sha256",
/*.groupname =*/ NULL,
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha256,
NULL, // WINSCP
/*.extra =*/ &extra_gex,
.name = "diffie-hellman-group-exchange-sha256",
.groupname = NULL,
.main_type = KEXTYPE_DH,
.hash = &ssh_sha256,
.extra = &extra_gex,
};
static const ssh_kex ssh_diffiehellman_gex_sha1 = {
/*.name =*/ "diffie-hellman-group-exchange-sha1",
/*.groupname =*/ NULL,
/*.main_type =*/ KEXTYPE_DH,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_gex,
.name = "diffie-hellman-group-exchange-sha1",
.groupname = NULL,
.main_type = KEXTYPE_DH,
.hash = &ssh_sha1,
.extra = &extra_gex,
};
static const ssh_kex *const gex_list[] = {
@@ -233,57 +224,51 @@ static const ssh_kex *const gex_list[] = {
const ssh_kexes ssh_diffiehellman_gex = { lenof(gex_list), gex_list };
static const ssh_kex ssh_gssk5_diffiehellman_gex_sha1 = {
/*.name =*/ "gss-gex-sha1-" GSS_KRB5_OID_HASH,
/*.groupname =*/ NULL,
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_gex,
.name = "gss-gex-sha1-" GSS_KRB5_OID_HASH,
.groupname = NULL,
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha1,
.extra = &extra_gex,
};
static const ssh_kex ssh_gssk5_diffiehellman_group18_sha512 = {
/*.name =*/ "gss-group18-sha512-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group18",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group18,
.name = "gss-group18-sha512-" GSS_KRB5_OID_HASH,
.groupname = "group18",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha512,
.extra = &extra_group18,
};
static const ssh_kex ssh_gssk5_diffiehellman_group17_sha512 = {
/*.name =*/ "gss-group17-sha512-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group17",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group17,
.name = "gss-group17-sha512-" GSS_KRB5_OID_HASH,
.groupname = "group17",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha512,
.extra = &extra_group17,
};
static const ssh_kex ssh_gssk5_diffiehellman_group16_sha512 = {
/*.name =*/ "gss-group16-sha512-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group16",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group16,
.name = "gss-group16-sha512-" GSS_KRB5_OID_HASH,
.groupname = "group16",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha512,
.extra = &extra_group16,
};
static const ssh_kex ssh_gssk5_diffiehellman_group15_sha512 = {
/*.name =*/ "gss-group15-sha512-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group15",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha512,
NULL, // WINSCP
/*.extra =*/ &extra_group15,
.name = "gss-group15-sha512-" GSS_KRB5_OID_HASH,
.groupname = "group15",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha512,
.extra = &extra_group15,
};
static const ssh_kex ssh_gssk5_diffiehellman_group14_sha256 = {
/*.name =*/ "gss-group14-sha256-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group14",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha256,
NULL, // WINSCP
/*.extra =*/ &extra_group14,
.name = "gss-group14-sha256-" GSS_KRB5_OID_HASH,
.groupname = "group14",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha256,
.extra = &extra_group14,
};
static const ssh_kex *const gssk5_sha2_kex_list[] = {
@@ -299,21 +284,19 @@ const ssh_kexes ssh_gssk5_sha2_kex = {
};
static const ssh_kex ssh_gssk5_diffiehellman_group14_sha1 = {
/*.name =*/ "gss-group14-sha1-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group14",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_group14,
.name = "gss-group14-sha1-" GSS_KRB5_OID_HASH,
.groupname = "group14",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha1,
.extra = &extra_group14,
};
static const ssh_kex ssh_gssk5_diffiehellman_group1_sha1 = {
/*.name =*/ "gss-group1-sha1-" GSS_KRB5_OID_HASH,
/*.groupname =*/ "group1",
/*.main_type =*/ KEXTYPE_GSS,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &extra_group1,
.name = "gss-group1-sha1-" GSS_KRB5_OID_HASH,
.groupname = "group1",
.main_type = KEXTYPE_GSS,
.hash = &ssh_sha1,
.extra = &extra_group1,
};
static const ssh_kex *const gssk5_sha1_kex_list[] = {
@@ -347,7 +330,7 @@ bool dh_is_gex(const ssh_kex *kex)
dh_ctx *dh_setup_group(const ssh_kex *kex)
{
const struct dh_extra *extra = (const struct dh_extra *)kex->extra;
pinitassert(!extra->gex);
assert(!extra->gex);
dh_ctx *ctx = snew(dh_ctx);
extra->construct(ctx);
dh_init(ctx);
@@ -439,12 +422,10 @@ const char *dh_validate_f(dh_ctx *ctx, mp_int *f)
} else {
mp_int *pm1 = mp_copy(ctx->p);
mp_sub_integer_into(pm1, pm1, 1);
{ // WINSCP
unsigned cmp = mp_cmp_hs(f, pm1);
mp_free(pm1);
if (cmp)
return "f value received is too large";
} // WINSCP
}
return NULL;
}

View File

@@ -60,13 +60,11 @@ static void append_hex_to_strbuf(strbuf *sb, mp_int *x)
if (sb->len > 0)
put_byte(sb, ',');
put_data(sb, "0x", 2);
{ // WINSCP
char *hex = mp_get_hex(x);
size_t hexlen = strlen(hex);
put_data(sb, hex, hexlen);
smemclr(hex, hexlen);
sfree(hex);
} // WINSCP
}
static char *dsa_cache_str(ssh_key *key)
@@ -143,7 +141,6 @@ static bool dsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
}
/* Now we're sitting on a 40-byte string for sure. */
{ // WINSCP
mp_int *r = mp_from_bytes_be(make_ptrlen(sig.ptr, 20));
mp_int *s = mp_from_bytes_be(make_ptrlen((const char *)sig.ptr + 20, 20));
if (!r || !s) {
@@ -155,7 +152,6 @@ static bool dsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
}
/* Basic sanity checks: 0 < r,s < q */
{ // WINSCP
unsigned invalid = 0;
invalid |= mp_eq_integer(r, 0);
invalid |= mp_eq_integer(s, 0);
@@ -170,7 +166,6 @@ static bool dsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
/*
* Step 1. w <- s^-1 mod q.
*/
{ // WINSCP
mp_int *w = mp_invert(s, dsa->q);
if (!w) {
mp_free(r);
@@ -182,7 +177,6 @@ static bool dsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
* Step 2. u1 <- SHA(message) * w mod q.
*/
hash_simple(&ssh_sha1, data, hash);
{ // WINSCP
mp_int *sha = mp_from_bytes_be(make_ptrlen(hash, 20));
mp_int *u1 = mp_modmul(sha, w, dsa->q);
@@ -215,10 +209,6 @@ static bool dsa_verify(ssh_key *key, ptrlen sig, ptrlen data)
mp_free(v);
mp_free(r);
mp_free(s);
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
return toret;
}
@@ -358,7 +348,6 @@ static void dsa_sign(ssh_key *key, ptrlen data, unsigned flags, BinarySink *bs)
hash_simple(&ssh_sha1, data, digest);
{ // WINSCP
/* Generate any valid exponent k, using the RFC 6979 deterministic
* procedure. */
mp_int *k = rfc6979(&ssh_sha1, dsa->q, dsa->x, data);
@@ -371,11 +360,9 @@ static void dsa_sign(ssh_key *key, ptrlen data, unsigned flags, BinarySink *bs)
mp_int *r = mp_mod(gkp, dsa->q); /* r = (g^k mod p) mod q */
mp_free(gkp);
{ // WINSCP
mp_int *hash = mp_from_bytes_be(make_ptrlen(digest, 20));
mp_int *xr = mp_mul(dsa->x, r);
mp_int *hxr = mp_add(xr, hash); /* hash + x*r */
{ // WINSCP
mp_int *s = mp_modmul(kinv, hxr, dsa->q); /* s = k^-1 * (hash+x*r) mod q */
mp_free(hxr);
mp_free(xr);
@@ -391,37 +378,30 @@ static void dsa_sign(ssh_key *key, ptrlen data, unsigned flags, BinarySink *bs)
put_byte(bs, mp_get_byte(s, 19 - i));
mp_free(r);
mp_free(s);
} // WINSCP
} // WINSCP
} // WINSCP
}
static char *dsa_alg_desc(const ssh_keyalg *self) { return dupstr("DSA"); }
const ssh_keyalg ssh_dsa = {
// WINSCP
/*.new_pub =*/ dsa_new_pub,
/*.new_priv =*/ dsa_new_priv,
/*.new_priv_openssh =*/ dsa_new_priv_openssh,
/*.freekey =*/ dsa_freekey,
/*.invalid =*/ dsa_invalid,
/*.sign =*/ dsa_sign,
/*.verify =*/ dsa_verify,
/*.public_blob =*/ dsa_public_blob,
/*.private_blob =*/ dsa_private_blob,
/*.openssh_blob =*/ dsa_openssh_blob,
/*.has_private =*/ dsa_has_private,
/*.cache_str =*/ dsa_cache_str,
/*.components =*/ dsa_components,
/*.base_key =*/ nullkey_base_key,
NULL, NULL, NULL, NULL, // WINSCP
/*.pubkey_bits =*/ dsa_pubkey_bits,
/*.supported_flags =*/ nullkey_supported_flags,
/*.alternate_ssh_id =*/ nullkey_alternate_ssh_id,
/*.alg_desc =*/ dsa_alg_desc,
/*.variable_size =*/ nullkey_variable_size_yes,
NULL, // WINSCP
/*.ssh_id =*/ "ssh-dss",
/*.cache_id =*/ "dss",
NULL, false, NULL, // WINSCP
.new_pub = dsa_new_pub,
.new_priv = dsa_new_priv,
.new_priv_openssh = dsa_new_priv_openssh,
.freekey = dsa_freekey,
.invalid = dsa_invalid,
.sign = dsa_sign,
.verify = dsa_verify,
.public_blob = dsa_public_blob,
.private_blob = dsa_private_blob,
.openssh_blob = dsa_openssh_blob,
.has_private = dsa_has_private,
.cache_str = dsa_cache_str,
.components = dsa_components,
.base_key = nullkey_base_key,
.pubkey_bits = dsa_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.alternate_ssh_id = nullkey_alternate_ssh_id,
.alg_desc = dsa_alg_desc,
.variable_size = nullkey_variable_size_yes,
.ssh_id = "ssh-dss",
.cache_id = "dss",
};

View File

@@ -145,7 +145,7 @@ void ecc_weierstrass_point_free(WeierstrassPoint *wp)
WeierstrassPoint *ecc_weierstrass_point_new_from_x(
WeierstrassCurve *wc, mp_int *xorig, unsigned desired_y_parity)
{
pinitassert(wc->sc);
assert(wc->sc);
/*
* The curve equation is y^2 = x^3 + ax + b, which is already
@@ -169,7 +169,6 @@ WeierstrassPoint *ecc_weierstrass_point_new_from_x(
mp_free(x2_plus_a);
mp_free(x3_plus_ax);
{ // WINSCP
mp_int *y = monty_modsqrt(wc->sc, rhs, &success);
mp_free(rhs);
@@ -188,16 +187,13 @@ WeierstrassPoint *ecc_weierstrass_point_new_from_x(
* Choose whichever of y and p-y has the specified parity (of its
* lowest positive residue mod p).
*/
{ // WINSCP
mp_int *tmp = monty_export(wc->mc, y);
unsigned flip = (mp_get_bit(tmp, 0) ^ desired_y_parity) & 1;
mp_sub_into(tmp, wc->p, y);
mp_select_into(y, y, tmp, flip);
mp_free(tmp);
} // WINSCP
return ecc_weierstrass_point_new_imported(wc, x, y);
} // WINSCP
}
static void ecc_weierstrass_cond_overwrite(
@@ -240,7 +236,6 @@ static inline void ecc_weierstrass_epilogue(
out->X = monty_sub(wc->mc, lambda_n2, lambda_d2_xsum);
/* Make the output y-coordinate */
{ // WINSCP
mp_int *lambda_d2_Px = monty_mul(wc->mc, lambda_d2, Px);
mp_int *xdiff = monty_sub(wc->mc, lambda_d2_Px, out->X);
mp_int *lambda_n_xdiff = monty_mul(wc->mc, lambda_n, xdiff);
@@ -259,7 +254,6 @@ static inline void ecc_weierstrass_epilogue(
mp_free(lambda_n_xdiff);
mp_free(lambda_d2_Px);
mp_free(lambda_d3_Py);
} // WINSCP
}
/*
@@ -287,7 +281,6 @@ static inline void ecc_weierstrass_add_prologue(
*Px = monty_mul(wc->mc, P->X, Qz2);
*Py = monty_mul(wc->mc, P->Y, Qz3);
*Qx = monty_mul(wc->mc, Q->X, Pz2);
{ // WINSCP
mp_int *Qy = monty_mul(wc->mc, Q->Y, Pz3);
/* Common denominator */
@@ -302,7 +295,6 @@ static inline void ecc_weierstrass_add_prologue(
mp_free(Qz2);
mp_free(Qz3);
mp_free(Qy);
} // WINSCP
}
WeierstrassPoint *ecc_weierstrass_add(WeierstrassPoint *P, WeierstrassPoint *Q)
@@ -310,7 +302,6 @@ WeierstrassPoint *ecc_weierstrass_add(WeierstrassPoint *P, WeierstrassPoint *Q)
WeierstrassCurve *wc = P->wc;
assert(Q->wc == wc);
{ // WINSCP
WeierstrassPoint *S = ecc_weierstrass_point_new_empty(wc);
mp_int *Px, *Py, *Qx, *denom, *lambda_n, *lambda_d;
@@ -334,7 +325,6 @@ WeierstrassPoint *ecc_weierstrass_add(WeierstrassPoint *P, WeierstrassPoint *Q)
mp_free(lambda_d);
return S;
} // WINSCP
}
/*
@@ -397,7 +387,6 @@ WeierstrassPoint *ecc_weierstrass_add_general(
WeierstrassCurve *wc = P->wc;
assert(Q->wc == wc);
{ // WINSCP
WeierstrassPoint *S = ecc_weierstrass_point_new_empty(wc);
/* Parameters for the epilogue, and slope of the line if P != Q */
@@ -406,12 +395,10 @@ WeierstrassPoint *ecc_weierstrass_add_general(
P, Q, &Px, &Py, &Qx, &denom, &lambda_n, &lambda_d);
/* Slope if P == Q */
{ // WINSCP
mp_int *lambda_n_tangent, *lambda_d_tangent;
ecc_weierstrass_tangent_slope(P, &lambda_n_tangent, &lambda_d_tangent);
/* Select between those slopes depending on whether P == Q */
{ // WINSCP
unsigned same_x_coord = mp_eq_integer(lambda_d, 0);
unsigned same_y_coord = mp_eq_integer(lambda_n, 0);
unsigned equality = same_x_coord & same_y_coord;
@@ -432,7 +419,6 @@ WeierstrassPoint *ecc_weierstrass_add_general(
* z==0 already. Detect that and use it to normalise the other two
* coordinates to zero.
*/
{ // WINSCP
unsigned output_id = mp_eq_integer(S->Z, 0);
mp_cond_clear(S->X, output_id);
mp_cond_clear(S->Y, output_id);
@@ -447,10 +433,6 @@ WeierstrassPoint *ecc_weierstrass_add_general(
mp_free(lambda_d_tangent);
return S;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
WeierstrassPoint *ecc_weierstrass_multiply(WeierstrassPoint *B, mp_int *n)
@@ -468,13 +450,11 @@ WeierstrassPoint *ecc_weierstrass_multiply(WeierstrassPoint *B, mp_int *n)
*/
unsigned not_started_yet = 1;
size_t bitindex; // WINSCP
for (bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
for (size_t bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
unsigned nbit = mp_get_bit(n, bitindex);
WeierstrassPoint *sum = ecc_weierstrass_add(k_B, kplus1_B);
ecc_weierstrass_cond_swap(k_B, kplus1_B, nbit);
{ // WINSCP
WeierstrassPoint *other = ecc_weierstrass_double(k_B);
ecc_weierstrass_point_free(k_B);
ecc_weierstrass_point_free(kplus1_B);
@@ -485,7 +465,6 @@ WeierstrassPoint *ecc_weierstrass_multiply(WeierstrassPoint *B, mp_int *n)
ecc_weierstrass_cond_overwrite(k_B, B, not_started_yet);
ecc_weierstrass_cond_overwrite(kplus1_B, two_B, not_started_yet);
not_started_yet &= ~nbit;
} // WINSCP
}
ecc_weierstrass_point_free(two_B);
@@ -603,20 +582,16 @@ MontgomeryCurve *ecc_montgomery_curve(
mc->a = monty_import(mc->mc, a);
mc->b = monty_import(mc->mc, b);
{ // WINSCP
mp_int *four = mp_from_integer(4);
mp_int *fourinverse = mp_invert(four, mc->p);
mp_int *aplus2 = mp_copy(a);
mp_add_integer_into(aplus2, aplus2, 2);
{ // WINSCP
mp_int *aplus2over4 = mp_modmul(aplus2, fourinverse, mc->p);
mc->aplus2over4 = monty_import(mc->mc, aplus2over4);
mp_free(four);
mp_free(fourinverse);
mp_free(aplus2);
mp_free(aplus2over4);
} // WINSCP
} // WINSCP
return mc;
}
@@ -702,7 +677,6 @@ MontgomeryPoint *ecc_montgomery_diff_add(
* do a division during the main arithmetic.
*/
{ // WINSCP
MontgomeryPoint *S = ecc_montgomery_point_new_empty(mc);
mp_int *Px_m_Pz = monty_sub(mc->mc, P->X, P->Z);
@@ -730,7 +704,6 @@ MontgomeryPoint *ecc_montgomery_diff_add(
mp_free(Zpre2);
return S;
} // WINSCP
}
MontgomeryPoint *ecc_montgomery_double(MontgomeryPoint *P)
@@ -765,7 +738,6 @@ MontgomeryPoint *ecc_montgomery_double(MontgomeryPoint *P)
mp_int *Px_m_Pz_2 = monty_mul(mc->mc, Px_m_Pz, Px_m_Pz);
mp_int *Px_p_Pz_2 = monty_mul(mc->mc, Px_p_Pz, Px_p_Pz);
D->X = monty_mul(mc->mc, Px_m_Pz_2, Px_p_Pz_2);
{ // WINSCP
mp_int *XZ = monty_mul(mc->mc, P->X, P->Z);
mp_int *twoXZ = monty_add(mc->mc, XZ, XZ);
mp_int *fourXZ = monty_add(mc->mc, twoXZ, twoXZ);
@@ -782,7 +754,6 @@ MontgomeryPoint *ecc_montgomery_double(MontgomeryPoint *P)
mp_free(fourXZ);
mp_free(fourXZ_scaled);
mp_free(Zpre);
} // WINSCP
return D;
}
@@ -834,13 +805,11 @@ MontgomeryPoint *ecc_montgomery_multiply(MontgomeryPoint *B, mp_int *n)
MontgomeryPoint *kplus1_B = ecc_montgomery_point_copy(two_B);
unsigned not_started_yet = 1;
size_t bitindex; // WINSCP
for (bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
for (size_t bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
unsigned nbit = mp_get_bit(n, bitindex);
MontgomeryPoint *sum = ecc_montgomery_diff_add(k_B, kplus1_B, B);
ecc_montgomery_cond_swap(k_B, kplus1_B, nbit);
{ // WINSCP
MontgomeryPoint *other = ecc_montgomery_double(k_B);
ecc_montgomery_point_free(k_B);
ecc_montgomery_point_free(kplus1_B);
@@ -851,7 +820,6 @@ MontgomeryPoint *ecc_montgomery_multiply(MontgomeryPoint *B, mp_int *n)
ecc_montgomery_cond_overwrite(k_B, B, not_started_yet);
ecc_montgomery_cond_overwrite(kplus1_B, two_B, not_started_yet);
not_started_yet &= ~nbit;
} // WINSCP
}
ecc_montgomery_point_free(two_B);
@@ -991,7 +959,7 @@ void ecc_edwards_point_free(EdwardsPoint *ep)
EdwardsPoint *ecc_edwards_point_new_from_y(
EdwardsCurve *ec, mp_int *yorig, unsigned desired_x_parity)
{
pinitassert(ec->sc);
assert(ec->sc);
/*
* The curve equation is ax^2 + y^2 = 1 + dx^2y^2, which
@@ -1030,13 +998,11 @@ EdwardsPoint *ecc_edwards_point_new_from_y(
* Choose whichever of x and p-x has the specified parity (of its
* lowest positive residue mod p).
*/
{ // WINSCP
mp_int *tmp = monty_export(ec->mc, x);
unsigned flip = (mp_get_bit(tmp, 0) ^ desired_x_parity) & 1;
mp_sub_into(tmp, ec->p, x);
mp_select_into(x, x, tmp, flip);
mp_free(tmp);
} // WINSCP
return ecc_edwards_point_new_imported(ec, x, y);
}
@@ -1064,7 +1030,6 @@ EdwardsPoint *ecc_edwards_add(EdwardsPoint *P, EdwardsPoint *Q)
EdwardsCurve *ec = P->ec;
assert(Q->ec == ec);
{ // WINSCP
EdwardsPoint *S = ecc_edwards_point_new_empty(ec);
/*
@@ -1119,7 +1084,6 @@ EdwardsPoint *ecc_edwards_add(EdwardsPoint *P, EdwardsPoint *Q)
mp_free(H);
return S;
} // WINSCP
}
static void ecc_edwards_normalise(EdwardsPoint *ep)
@@ -1147,13 +1111,11 @@ EdwardsPoint *ecc_edwards_multiply(EdwardsPoint *B, mp_int *n)
*/
unsigned not_started_yet = 1;
size_t bitindex; // WINSCP
for (bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
for (size_t bitindex = mp_max_bits(n); bitindex-- > 0 ;) {
unsigned nbit = mp_get_bit(n, bitindex);
EdwardsPoint *sum = ecc_edwards_add(k_B, kplus1_B);
ecc_edwards_cond_swap(k_B, kplus1_B, nbit);
{ // WINSCP
EdwardsPoint *other = ecc_edwards_add(k_B, k_B);
ecc_edwards_point_free(k_B);
ecc_edwards_point_free(kplus1_B);
@@ -1164,7 +1126,6 @@ EdwardsPoint *ecc_edwards_multiply(EdwardsPoint *B, mp_int *n)
ecc_edwards_cond_overwrite(k_B, B, not_started_yet);
ecc_edwards_cond_overwrite(kplus1_B, two_B, not_started_yet);
not_started_yet &= ~nbit;
} // WINSCP
}
ecc_edwards_point_free(two_B);

File diff suppressed because it is too large Load Diff

View File

@@ -47,7 +47,6 @@ static ssh2_mac *hmac_new_inner(struct hmac *ctx, const ssh2_macalg *alg)
ctx->hashalg->text_basename, extra->suffix);
if (extra->annotation || ctx->hashalg->annotation) {
put_fmt(ctx->text_name, " (");
{ // WINSCP
const char *sep = "";
if (extra->annotation) {
put_fmt(ctx->text_name, "%s%s", sep, extra->annotation);
@@ -58,7 +57,6 @@ static ssh2_mac *hmac_new_inner(struct hmac *ctx, const ssh2_macalg *alg)
sep = ", ";
}
put_fmt(ctx->text_name, ")");
} // WINSCP
}
ctx->mac.vt = alg;
@@ -107,10 +105,8 @@ static void hmac_key(ssh2_mac *mac, ptrlen key)
sb = strbuf_new_nm();
strbuf_append(sb, ctx->hashalg->hlen);
hash_simple(ctx->hashalg, key, sb->u);
{ // WINSCP
kp = sb->u;
klen = sb->len;
} // WINSCP
} else {
/*
* A short enough key is used as is.
@@ -120,22 +116,19 @@ static void hmac_key(ssh2_mac *mac, ptrlen key)
}
ssh_hash_reset(ctx->h_outer);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < klen; i++)
for (size_t i = 0; i < klen; i++)
put_byte(ctx->h_outer, PAD_OUTER ^ kp[i]);
for (i = klen; i < ctx->hashalg->blocklen; i++)
for (size_t i = klen; i < ctx->hashalg->blocklen; i++)
put_byte(ctx->h_outer, PAD_OUTER);
ssh_hash_reset(ctx->h_inner);
for (i = 0; i < klen; i++)
for (size_t i = 0; i < klen; i++)
put_byte(ctx->h_inner, PAD_INNER ^ kp[i]);
for (i = klen; i < ctx->hashalg->blocklen; i++)
for (size_t i = klen; i < ctx->hashalg->blocklen; i++)
put_byte(ctx->h_inner, PAD_INNER);
if (sb)
strbuf_free(sb);
} // WINSCP
}
static void hmac_start(ssh2_mac *mac)
@@ -175,88 +168,84 @@ static const char *hmac_text_name(ssh2_mac *mac)
static const struct hmac_extra ssh_hmac_sha512_extra = { &ssh_sha512, "" };
const ssh2_macalg ssh_hmac_sha512 = {
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha2-512",
/*.etm_name =*/ "hmac-sha2-512-etm@openssh.com",
/*.len =*/ 64,
/*.keylen =*/ 64,
/*.extra =*/ &ssh_hmac_sha512_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha2-512",
.etm_name = "hmac-sha2-512-etm@openssh.com",
.len = 64,
.keylen = 64,
.extra = &ssh_hmac_sha512_extra,
};
static const struct hmac_extra ssh_hmac_sha256_extra = { &ssh_sha256, "" };
const ssh2_macalg ssh_hmac_sha256 = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha2-256",
/*.etm_name =*/ "hmac-sha2-256-etm@openssh.com",
/*.len =*/ 32,
/*.keylen =*/ 32,
/*.extra =*/ &ssh_hmac_sha256_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha2-256",
.etm_name = "hmac-sha2-256-etm@openssh.com",
.len = 32,
.keylen = 32,
.extra = &ssh_hmac_sha256_extra,
};
static const struct hmac_extra ssh_hmac_md5_extra = { &ssh_md5, "" };
const ssh2_macalg ssh_hmac_md5 = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-md5",
/*.etm_name =*/ "hmac-md5-etm@openssh.com",
/*.len =*/ 16,
/*.keylen =*/ 16,
/*.extra =*/ &ssh_hmac_md5_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-md5",
.etm_name = "hmac-md5-etm@openssh.com",
.len = 16,
.keylen = 16,
.extra = &ssh_hmac_md5_extra,
};
static const struct hmac_extra ssh_hmac_sha1_extra = { &ssh_sha1, "" };
const ssh2_macalg ssh_hmac_sha1 = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha1",
/*.etm_name =*/ "hmac-sha1-etm@openssh.com",
/*.len =*/ 20,
/*.keylen =*/ 20,
/*.extra =*/ &ssh_hmac_sha1_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha1",
.etm_name = "hmac-sha1-etm@openssh.com",
.len = 20,
.keylen = 20,
.extra = &ssh_hmac_sha1_extra,
};
static const struct hmac_extra ssh_hmac_sha1_96_extra = { &ssh_sha1, "-96" };
const ssh2_macalg ssh_hmac_sha1_96 = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha1-96",
/*.etm_name =*/ "hmac-sha1-96-etm@openssh.com",
/*.len =*/ 12,
/*.keylen =*/ 20,
/*.extra =*/ &ssh_hmac_sha1_96_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha1-96",
.etm_name = "hmac-sha1-96-etm@openssh.com",
.len = 12,
.keylen = 20,
.extra = &ssh_hmac_sha1_96_extra,
};
static const struct hmac_extra ssh_hmac_sha1_buggy_extra = {
@@ -264,19 +253,17 @@ static const struct hmac_extra ssh_hmac_sha1_buggy_extra = {
};
const ssh2_macalg ssh_hmac_sha1_buggy = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha1",
NULL, // WINSCP
/*.len =*/ 20,
/*.keylen =*/ 16,
/*.extra =*/ &ssh_hmac_sha1_buggy_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha1",
.len = 20,
.keylen = 16,
.extra = &ssh_hmac_sha1_buggy_extra,
};
static const struct hmac_extra ssh_hmac_sha1_96_buggy_extra = {
@@ -284,19 +271,17 @@ static const struct hmac_extra ssh_hmac_sha1_96_buggy_extra = {
};
const ssh2_macalg ssh_hmac_sha1_96_buggy = {
// WINSCP
/*.new =*/ hmac_new,
/*.free =*/ hmac_free,
/*.setkey =*/ hmac_key,
/*.start =*/ hmac_start,
/*.genresult =*/ hmac_genresult,
/*.next_message =*/ nullmac_next_message,
/*.text_name =*/ hmac_text_name,
/*.name =*/ "hmac-sha1-96",
NULL, // WINSCP
/*.len =*/ 12,
/*.keylen =*/ 16,
/*.extra =*/ &ssh_hmac_sha1_96_buggy_extra,
.new = hmac_new,
.free = hmac_free,
.setkey = hmac_key,
.start = hmac_start,
.genresult = hmac_genresult,
.next_message = nullmac_next_message,
.text_name = hmac_text_name,
.name = "hmac-sha1-96",
.len = 12,
.keylen = 16,
.extra = &ssh_hmac_sha1_96_buggy_extra,
};
ssh2_mac *hmac_new_from_hash(const ssh_hashalg *hash)

View File

@@ -51,17 +51,12 @@ static void reformat_mpint_be(ptrlen input, BinarySink *output, size_t bytes)
{
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, input);
{ // WINSCP
mp_int *mp = get_mp_ssh2(src);
assert(!get_err(src));
assert(get_avail(src) == 0);
{ // WINSCP
size_t i; // WINSCP
for (i = bytes; i-- > 0 ;)
for (size_t i = bytes; i-- > 0 ;)
put_byte(output, mp_get_byte(mp, i));
mp_free(mp);
} // WINSCP
} // WINSCP
}
static void reformat_mpint_be_32(ptrlen input, BinarySink *output)
@@ -93,7 +88,6 @@ struct hybrid_client_state {
static ecdh_key *hybrid_client_new(const ssh_kex *kex, bool is_server)
{
assert(!is_server);
{ // WINSCP
hybrid_client_state *s = snew(hybrid_client_state);
s->alg = kex->extra;
s->ek.vt = &hybrid_client_vt;
@@ -101,7 +95,6 @@ static ecdh_key *hybrid_client_new(const ssh_kex *kex, bool is_server)
s->pq_dk = pq_kem_keygen(s->alg->pq_alg, BinarySink_UPCAST(s->pq_ek));
s->classical = ecdh_key_new(s->alg->classical_alg, is_server);
return &s->ek;
} // WINSCP
}
static void hybrid_client_free(ecdh_key *ek)
@@ -136,7 +129,6 @@ static bool hybrid_client_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, remoteKey);
{ // WINSCP
ssh_hash *h = ssh_hash_new(s->alg->combining_hash);
ptrlen pq_ciphertext = get_data(src, s->alg->pq_alg->c_len);
@@ -149,7 +141,6 @@ static bool hybrid_client_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
return false; /* pq ciphertext didn't validate */
}
{ // WINSCP
ptrlen classical_data = get_data(src, get_avail(src));
strbuf *classical_key = strbuf_new();
if (!ecdh_key_getkey(s->classical, classical_data,
@@ -165,25 +156,21 @@ static bool hybrid_client_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
* Finish up: compute the final output hash and return it encoded
* as a string.
*/
{ // WINSCP
unsigned char hashdata[MAX_HASH_LEN];
ssh_hash_final(h, hashdata);
put_stringpl(bs, make_ptrlen(hashdata, s->alg->combining_hash->hlen));
smemclr(hashdata, sizeof(hashdata));
return true;
} // WINSCP
} // WINSCP
} // WINSCP
}
static const ecdh_keyalg hybrid_client_vt = {
/*.new =*/ hybrid_client_new, /* but normally the selector calls this */
/*.free =*/ hybrid_client_free,
/*.getpublic =*/ hybrid_client_getpublic,
/*.getkey =*/ hybrid_client_getkey,
/*.description =*/ hybrid_description,
/*.packet_naming_ctx =*/ SSH2_PKTCTX_HYBRIDKEX,
.new = hybrid_client_new, /* but normally the selector calls this */
.free = hybrid_client_free,
.getpublic = hybrid_client_getpublic,
.getkey = hybrid_client_getkey,
.description = hybrid_description,
.packet_naming_ctx = SSH2_PKTCTX_HYBRIDKEX,
};
/* ----------------------------------------------------------------------
@@ -204,14 +191,12 @@ struct hybrid_server_state {
static ecdh_key *hybrid_server_new(const ssh_kex *kex, bool is_server)
{
assert(is_server);
{ // WINSCP
hybrid_server_state *s = snew(hybrid_server_state);
s->alg = kex->extra;
s->ek.vt = &hybrid_server_vt;
s->pq_ciphertext = strbuf_new_nm();
s->classical = ecdh_key_new(s->alg->classical_alg, is_server);
return &s->ek;
} // WINSCP
}
static void hybrid_server_free(ecdh_key *ek)
@@ -235,7 +220,6 @@ static bool hybrid_server_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, remoteKey);
{ // WINSCP
ssh_hash *h = ssh_hash_new(s->alg->combining_hash);
ptrlen pq_ek = get_data(src, s->alg->pq_alg->ek_len);
@@ -250,7 +234,6 @@ static bool hybrid_server_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
return false; /* pq encryption key didn't validate */
}
{ // WINSCP
ptrlen classical_data = get_data(src, get_avail(src));
strbuf *classical_key = strbuf_new();
if (!ecdh_key_getkey(s->classical, classical_data,
@@ -266,16 +249,12 @@ static bool hybrid_server_getkey(ecdh_key *ek, ptrlen remoteKey, BinarySink *bs)
* Finish up: compute the final output hash and return it encoded
* as a string.
*/
{ // WINSCP
unsigned char hashdata[MAX_HASH_LEN];
ssh_hash_final(h, hashdata);
put_stringpl(bs, make_ptrlen(hashdata, s->alg->combining_hash->hlen));
smemclr(hashdata, sizeof(hashdata));
return true;
} // WINSCP
} // WINSCP
} // WINSCP
}
static void hybrid_server_getpublic(ecdh_key *ek, BinarySink *bs)
@@ -286,12 +265,12 @@ static void hybrid_server_getpublic(ecdh_key *ek, BinarySink *bs)
}
static const ecdh_keyalg hybrid_server_vt = {
/*.new =*/ hybrid_server_new, /* but normally the selector calls this */
/*.free =*/ hybrid_server_free,
/*.getpublic =*/ hybrid_server_getpublic,
/*.getkey =*/ hybrid_server_getkey,
/*.description =*/ hybrid_description,
/*.packet_naming_ctx =*/ SSH2_PKTCTX_HYBRIDKEX,
.new = hybrid_server_new, /* but normally the selector calls this */
.free = hybrid_server_free,
.getkey = hybrid_server_getkey,
.getpublic = hybrid_server_getpublic,
.description = hybrid_description,
.packet_naming_ctx = SSH2_PKTCTX_HYBRIDKEX,
};
/* ----------------------------------------------------------------------
@@ -310,10 +289,9 @@ static ecdh_key *hybrid_selector_new(const ssh_kex *kex, bool is_server)
static const ecdh_keyalg hybrid_selector_vt = {
/* This is a never-instantiated vtable which only implements the
* functions that don't require an instance. */
/*.new =*/ hybrid_selector_new,
NULL, NULL, NULL, // WINSCP
/*.description =*/ hybrid_description,
/*.packet_naming_ctx =*/ SSH2_PKTCTX_HYBRIDKEX,
.new = hybrid_selector_new,
.description = hybrid_description,
.packet_naming_ctx = SSH2_PKTCTX_HYBRIDKEX,
};
/* ----------------------------------------------------------------------
@@ -321,28 +299,26 @@ static const ecdh_keyalg hybrid_selector_vt = {
*/
static const hybrid_alg ssh_ntru_curve25519_hybrid = {
/*.combining_hash =*/ &ssh_sha512,
/*.pq_alg =*/ &ssh_ntru,
/*.classical_alg =*/ &ssh_ec_kex_curve25519,
/*.reformat =*/ reformat_mpint_be_32,
.combining_hash = &ssh_sha512,
.pq_alg = &ssh_ntru,
.classical_alg = &ssh_ec_kex_curve25519,
.reformat = reformat_mpint_be_32,
};
static const ssh_kex ssh_ntru_curve25519 = {
/*.name =*/ "sntrup761x25519-sha512",
NULL, // WINSCP
/*.main_type =*/ KEXTYPE_ECDH,
/*.hash =*/ &ssh_sha512,
/*.ecdh_vt =*/ &hybrid_selector_vt,
/*.extra =*/ &ssh_ntru_curve25519_hybrid,
.name = "sntrup761x25519-sha512",
.main_type = KEXTYPE_ECDH,
.hash = &ssh_sha512,
.ecdh_vt = &hybrid_selector_vt,
.extra = &ssh_ntru_curve25519_hybrid,
};
static const ssh_kex ssh_ntru_curve25519_openssh = {
/*.name =*/ "sntrup761x25519-sha512@openssh.com",
NULL, // WINSCP
/*.main_type =*/ KEXTYPE_ECDH,
/*.hash =*/ &ssh_sha512,
/*.ecdh_vt =*/ &hybrid_selector_vt,
/*.extra =*/ &ssh_ntru_curve25519_hybrid,
.name = "sntrup761x25519-sha512@openssh.com",
.main_type = KEXTYPE_ECDH,
.hash = &ssh_sha512,
.ecdh_vt = &hybrid_selector_vt,
.extra = &ssh_ntru_curve25519_hybrid,
};
static const ssh_kex *const ntru_hybrid_list[] = {
@@ -355,19 +331,18 @@ const ssh_kexes ssh_ntru_hybrid_kex = {
};
static const hybrid_alg ssh_mlkem768_curve25519_hybrid = {
/*.combining_hash =*/ &ssh_sha256,
/*.pq_alg =*/ &ssh_mlkem768,
/*.classical_alg =*/ &ssh_ec_kex_curve25519,
/*.reformat =*/ reformat_mpint_be_32,
.combining_hash = &ssh_sha256,
.pq_alg = &ssh_mlkem768,
.classical_alg = &ssh_ec_kex_curve25519,
.reformat = reformat_mpint_be_32,
};
static const ssh_kex ssh_mlkem768_curve25519 = {
/*.name =*/ "mlkem768x25519-sha256",
NULL, // WINSCP
/*.main_type =*/ KEXTYPE_ECDH,
/*.hash =*/ &ssh_sha256,
/*.ecdh_vt =*/ &hybrid_selector_vt,
/*.extra =*/ &ssh_mlkem768_curve25519_hybrid,
.name = "mlkem768x25519-sha256",
.main_type = KEXTYPE_ECDH,
.hash = &ssh_sha256,
.ecdh_vt = &hybrid_selector_vt,
.extra = &ssh_mlkem768_curve25519_hybrid,
};
static const ssh_kex *const mlkem_curve25519_hybrid_list[] = {
@@ -379,35 +354,33 @@ const ssh_kexes ssh_mlkem_curve25519_hybrid_kex = {
};
static const hybrid_alg ssh_mlkem768_p256_hybrid = {
/*.combining_hash =*/ &ssh_sha256,
/*.pq_alg =*/ &ssh_mlkem768,
/*.classical_alg =*/ &ssh_ec_kex_nistp256,
/*.reformat =*/ reformat_mpint_be_32,
.combining_hash = &ssh_sha256,
.pq_alg = &ssh_mlkem768,
.classical_alg = &ssh_ec_kex_nistp256,
.reformat = reformat_mpint_be_32,
};
static const ssh_kex ssh_mlkem768_p256 = {
/*.name =*/ "mlkem768nistp256-sha256",
NULL, // WINSCP
/*.main_type =*/ KEXTYPE_ECDH,
/*.hash =*/ &ssh_sha256,
/*.ecdh_vt =*/ &hybrid_selector_vt,
/*.extra =*/ &ssh_mlkem768_p256_hybrid,
.name = "mlkem768nistp256-sha256",
.main_type = KEXTYPE_ECDH,
.hash = &ssh_sha256,
.ecdh_vt = &hybrid_selector_vt,
.extra = &ssh_mlkem768_p256_hybrid,
};
static const hybrid_alg ssh_mlkem1024_p384_hybrid = {
/*.combining_hash =*/ &ssh_sha384,
/*.pq_alg =*/ &ssh_mlkem1024,
/*.classical_alg =*/ &ssh_ec_kex_nistp384,
/*.reformat =*/ reformat_mpint_be_48,
.combining_hash = &ssh_sha384,
.pq_alg = &ssh_mlkem1024,
.classical_alg = &ssh_ec_kex_nistp384,
.reformat = reformat_mpint_be_48,
};
static const ssh_kex ssh_mlkem1024_p384 = {
/*.name =*/ "mlkem1024nistp384-sha384",
NULL, // WINSCP
/*.main_type =*/ KEXTYPE_ECDH,
/*.hash =*/ &ssh_sha384,
/*.ecdh_vt =*/ &hybrid_selector_vt,
/*.extra =*/ &ssh_mlkem1024_p384_hybrid,
.name = "mlkem1024nistp384-sha384",
.main_type = KEXTYPE_ECDH,
.hash = &ssh_sha384,
.ecdh_vt = &hybrid_selector_vt,
.extra = &ssh_mlkem1024_p384_hybrid,
};
static const ssh_kex *const mlkem_nist_hybrid_list[] = {

View File

@@ -89,21 +89,17 @@ static inline void md5_block_pad(md5_block *blk, BinarySink *bs)
put_byte(bs, 0x80);
put_padding(bs, pad, 0);
{ // WINSCP
unsigned char buf[8];
PUT_64BIT_LSB_FIRST(buf, final_len);
put_data(bs, buf, 8);
smemclr(buf, 8);
} // WINSCP
assert(blk->used == 0 && "Should have exactly hit a block boundary");
}
static inline uint32_t rol(uint32_t x, unsigned y)
{
#pragma option push -w-ngu // WINSCP
return (x << (31 & y)) | (x >> (31 & -y));
#pragma option pop // WINSCP
}
static inline uint32_t Ch(uint32_t ctrl, uint32_t if1, uint32_t if0)
@@ -135,34 +131,31 @@ static inline void md5_round(
static void md5_do_block(uint32_t *core, const uint8_t *block)
{
uint32_t message_words[16];
size_t i; // WINSCP
for (i = 0; i < 16; i++)
for (size_t i = 0; i < 16; i++)
message_words[i] = GET_32BIT_LSB_FIRST(block + 4*i);
{ // WINSCP
uint32_t a = core[0], b = core[1], c = core[2], d = core[3];
size_t t = 0;
size_t u; // WINSCP
for (u = 0; u < 4; u++) {
for (size_t u = 0; u < 4; u++) {
md5_round(t++, message_words, &a, &b, &c, &d, F);
md5_round(t++, message_words, &d, &a, &b, &c, F);
md5_round(t++, message_words, &c, &d, &a, &b, F);
md5_round(t++, message_words, &b, &c, &d, &a, F);
}
for (u = 0; u < 4; u++) {
for (size_t u = 0; u < 4; u++) {
md5_round(t++, message_words, &a, &b, &c, &d, G);
md5_round(t++, message_words, &d, &a, &b, &c, G);
md5_round(t++, message_words, &c, &d, &a, &b, G);
md5_round(t++, message_words, &b, &c, &d, &a, G);
}
for (u = 0; u < 4; u++) {
for (size_t u = 0; u < 4; u++) {
md5_round(t++, message_words, &a, &b, &c, &d, H);
md5_round(t++, message_words, &d, &a, &b, &c, H);
md5_round(t++, message_words, &c, &d, &a, &b, H);
md5_round(t++, message_words, &b, &c, &d, &a, H);
}
for (u = 0; u < 4; u++) {
for (size_t u = 0; u < 4; u++) {
md5_round(t++, message_words, &a, &b, &c, &d, I);
md5_round(t++, message_words, &d, &a, &b, &c, I);
md5_round(t++, message_words, &c, &d, &a, &b, I);
@@ -173,7 +166,6 @@ static void md5_do_block(uint32_t *core, const uint8_t *block)
core[1] += b;
core[2] += c;
core[3] += d;
} // WINSCP
smemclr(message_words, sizeof(message_words));
}
@@ -236,21 +228,18 @@ static void md5_digest(ssh_hash *hash, uint8_t *digest)
{
md5 *s = container_of(hash, md5, hash);
size_t i; // WINSCP
md5_block_pad(&s->blk, BinarySink_UPCAST(s));
for (i = 0; i < 4; i++)
for (size_t i = 0; i < 4; i++)
PUT_32BIT_LSB_FIRST(digest + 4*i, s->core[i]);
}
const ssh_hashalg ssh_md5 = {
// WINSCP
/*.new =*/ md5_new,
/*.reset =*/ md5_reset,
/*.copyfrom =*/ md5_copyfrom,
/*.digest =*/ md5_digest,
/*.free =*/ md5_free,
/*.hlen =*/ 16,
/*.blocklen =*/ 64,
.new = md5_new,
.reset = md5_reset,
.copyfrom = md5_copyfrom,
.digest = md5_digest,
.free = md5_free,
.hlen = 16,
.blocklen = 64,
HASHALG_NAMES_BARE("MD5"),
NULL, // WINSCP
};

View File

@@ -36,13 +36,13 @@ struct mlkem_params {
* Specific parameter sets.
*/
const mlkem_params mlkem_params_512 = {
/*.k =*/ 2, /*.eta_1 =*/ 3, /*.eta_2 =*/ 2, /*.d_u =*/ 10, /*.d_v =*/ 4,
.k = 2, .eta_1 = 3, .eta_2 = 2, .d_u = 10, .d_v = 4,
};
const mlkem_params mlkem_params_768 = {
/*.k =*/ 3, /*.eta_1 =*/ 2, /*.eta_2 =*/ 2, /*.d_u =*/ 10, /*.d_v =*/ 4,
.k = 3, .eta_1 = 2, .eta_2 = 2, .d_u = 10, .d_v = 4,
};
const mlkem_params mlkem_params_1024 = {
/*.k =*/ 4, /*.eta_1 =*/ 2, /*.eta_2 =*/ 2, /*.d_u =*/ 11, /*.d_v =*/ 5,
.k = 4, .eta_1 = 2, .eta_2 = 2, .d_u = 11, .d_v = 5,
};
#define KMAX 4
@@ -120,13 +120,10 @@ static void mlkem_ntt(uint16_t *v)
const uint64_t Qrecip = reciprocal_for_reduction(Q);
size_t next_power = 1;
size_t len; // WINSCP
for (len = 128; len >= 2; len /= 2) {
size_t start; // WINSCP
for (start = 0; start < 256; start += 2*len) {
for (size_t len = 128; len >= 2; len /= 2) {
for (size_t start = 0; start < 256; start += 2*len) {
uint16_t mult = powers_reversed_order[next_power++];
size_t j; // WINSCP
for (j = start; j < start + len; j++) {
for (size_t j = start; j < start + len; j++) {
uint16_t t = reduce(mult * v[j + len], Q, Qrecip);
v[j + len] = reduce(v[j] + Q - t, Q, Qrecip);
v[j] = reduce(v[j] + t, Q, Qrecip);
@@ -143,13 +140,10 @@ static void mlkem_inverse_ntt(uint16_t *v)
const uint64_t Qrecip = reciprocal_for_reduction(Q);
size_t next_power = 127;
size_t len; // WINSCP
for (len = 2; len <= 128; len *= 2) {
size_t start; // WINSCP
for (start = 0; start < 256; start += 2*len) {
for (size_t len = 2; len <= 128; len *= 2) {
for (size_t start = 0; start < 256; start += 2*len) {
uint16_t mult = powers_reversed_order[next_power--];
size_t j; // WINSCP
for (j = start; j < start + len; j++) {
for (size_t j = start; j < start + len; j++) {
uint16_t t = v[j];
v[j] = reduce(t + v[j + len], Q, Qrecip);
v[j + len] = reduce(mult * (v[j + len] + Q - t), Q, Qrecip);
@@ -157,11 +151,8 @@ static void mlkem_inverse_ntt(uint16_t *v)
}
}
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < 256; i++)
for (size_t i = 0; i < 256; i++)
v[i] = reduce(v[i] * 3303, Q, Qrecip);
} // WINSCP
}
/*
@@ -175,8 +166,7 @@ static void mlkem_multiply_ntts(
{
const uint64_t Qrecip = reciprocal_for_reduction(Q);
size_t i; // WINSCP
for (i = 0; i < 128; i++) {
for (size_t i = 0; i < 128; i++) {
uint16_t a0 = a[2*i], a1 = a[2*i+1];
uint16_t b0 = b[2*i], b1 = b[2*i+1];
uint16_t mult = powers_odd_reversed_order[i];
@@ -247,7 +237,6 @@ static void mlkem_matrix_alloc(mlkem_matrix_storage *storage, ...)
va_end(ap);
storage->data = snewn(256 * storage->n, uint16_t);
{ // WINSCP
size_t pos = 0;
va_start(ap, storage);
while ((m = va_arg(ap, mlkem_matrix *)) != NULL) {
@@ -258,7 +247,6 @@ static void mlkem_matrix_alloc(mlkem_matrix_storage *storage, ...)
pos += nrows * ncols;
}
va_end(ap);
} // WINSCP
}
/* Clear and free the storage allocated by mlkem_matrix_alloc. */
@@ -279,20 +267,15 @@ static void mlkem_matrix_add(mlkem_matrix *out, const mlkem_matrix *left,
assert(out->nrows == right->nrows);
assert(out->ncols == right->ncols);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < out->nrows; i++) {
size_t j; // WINSCP
for (j = 0; j < out->ncols; j++) {
for (size_t i = 0; i < out->nrows; i++) {
for (size_t j = 0; j < out->ncols; j++) {
const uint16_t *lv = left->data + 256*(i * left->ncols + j);
const uint16_t *rv = right->data + 256*(i * right->ncols + j);
uint16_t *ov = out->data + 256*(i * out->ncols + j);
size_t p; // WINSCP
for (p = 0; p < 256; p++)
for (size_t p = 0; p < 256; p++)
ov[p] = reduce(lv[p] + rv[p] , Q, Qrecip);
}
}
} // WINSCP
}
/* Subtract matrices. */
@@ -306,35 +289,28 @@ static void mlkem_matrix_sub(mlkem_matrix *out, const mlkem_matrix *left,
assert(out->nrows == right->nrows);
assert(out->ncols == right->ncols);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < out->nrows; i++) {
size_t j; // WINSCP
for (j = 0; j < out->ncols; j++) {
for (size_t i = 0; i < out->nrows; i++) {
for (size_t j = 0; j < out->ncols; j++) {
const uint16_t *lv = left->data + 256*(i * left->ncols + j);
const uint16_t *rv = right->data + 256*(i * right->ncols + j);
uint16_t *ov = out->data + 256*(i * out->ncols + j);
size_t p; // WINSCP
for (p = 0; p < 256; p++)
for (size_t p = 0; p < 256; p++)
ov[p] = reduce(lv[p] + Q - rv[p] , Q, Qrecip);
}
}
} // WINSCP
}
/* Convert every element of a matrix into NTT representation. */
static void mlkem_matrix_ntt(mlkem_matrix *m)
{
size_t i; // WINSCP
for (i = 0; i < m->nrows * m->ncols; i++)
for (size_t i = 0; i < m->nrows * m->ncols; i++)
mlkem_ntt(m->data + i * 256);
}
/* Convert every element of a matrix out of NTT representation. */
static void mlkem_matrix_inverse_ntt(mlkem_matrix *m)
{
size_t i; // WINSCP
for (i = 0; i < m->nrows * m->ncols; i++)
for (size_t i = 0; i < m->nrows * m->ncols; i++)
mlkem_inverse_ntt(m->data + i * 256);
}
@@ -359,35 +335,25 @@ static void mlkem_matrix_mul(mlkem_matrix *out, const mlkem_matrix *left,
assert(left_ncols == right->nrows);
assert(right->ncols == out->ncols);
{ // WINSCP
uint16_t work[256];
size_t i; // WINSCP
for (i = 0; i < out->nrows; i++) {
size_t j; // WINSCP
for (j = 0; j < out->ncols; j++) {
for (size_t i = 0; i < out->nrows; i++) {
for (size_t j = 0; j < out->ncols; j++) {
uint16_t *thisout = out->data + 256 * (i * out->ncols + j);
memset(thisout, 0, 256 * sizeof(uint16_t));
{ // WINSCP
size_t k; // WINSCP
for (k = 0; k < right->nrows; k++) {
for (size_t k = 0; k < right->nrows; k++) {
size_t left_index = left_transposed ?
k * left->ncols + i : i * left->ncols + k;
const uint16_t *lv = left->data + 256*left_index;
const uint16_t *rv = right->data + 256*(k * right->ncols + j);
mlkem_multiply_ntts(work, lv, rv);
{ // WINSCP
size_t p; // WINSCP
for (p = 0; p < 256; p++)
for (size_t p = 0; p < 256; p++)
thisout[p] = reduce(thisout[p] + work[p], Q, Qrecip);
} // WINSCP
}
} // WINSCP
}
}
smemclr(work, sizeof(work));
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -408,10 +374,8 @@ static void mlkem_sample_ntt(uint16_t *output, ptrlen seed); /* forward ref */
*/
static void mlkem_matrix_from_seed(mlkem_matrix *m, const void *rho)
{
unsigned r; // WINSCP
for (r = 0; r < m->nrows; r++) {
unsigned c; // WINSCP
for (c = 0; c < m->ncols; c++) {
for (unsigned r = 0; r < m->nrows; r++) {
for (unsigned c = 0; c < m->ncols; c++) {
unsigned char seedbuf[34];
memcpy(seedbuf, rho, 32);
seedbuf[32] = c;
@@ -442,13 +406,10 @@ static void mlkem_sample_ntt(uint16_t *output, ptrlen seed)
unsigned char bytebuf[4];
bytebuf[3] = '\0';
{ // WINSCP
size_t pos; // WINSCP
for (pos = 0; pos < 256 ;) {
for (size_t pos = 0; pos < 256 ;) {
/* Read 3 bytes into the low-order end of bytebuf. The fourth
* byte is always 0, so this gives us a random 24-bit integer. */
shake_xof_read(sx, &bytebuf, 3);
{ // WINSCP
uint32_t random24 = GET_32BIT_LSB_FIRST(bytebuf);
/*
@@ -467,11 +428,9 @@ static void mlkem_sample_ntt(uint16_t *output, ptrlen seed)
output[pos++] = d1;
if (d2 < Q && pos < 256)
output[pos++] = d2;
} // WINSCP
}
shake_xof_free(sx);
} // WINSCP
}
/*
@@ -493,39 +452,30 @@ static void mlkem_matrix_poly_cbd(
unsigned char seedbuf[33];
memcpy(seedbuf, sigma, 32);
{ // WINSCP
unsigned char *randombuf = snewn(eta * 64, unsigned char);
unsigned r; // WINSCP
for (r = 0; r < v->nrows * v->ncols; r++) {
for (unsigned r = 0; r < v->nrows * v->ncols; r++) {
seedbuf[32] = r + offset;
{ // WINSCP
ShakeXOF *sx = shake256_xof_from_input(make_ptrlen(seedbuf, 33));
shake_xof_read(sx, randombuf, eta * 64);
shake_xof_free(sx);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < 256; i++) {
for (size_t i = 0; i < 256; i++) {
unsigned x = 0, y = 0;
size_t j; // WINSCP
for (j = 0; j < eta; j++) {
for (size_t j = 0; j < eta; j++) {
size_t bitpos = 2 * i * eta + j;
x += 1 & ((randombuf[bitpos >> 3]) >> (bitpos & 7));
}
for (j = 0; j < eta; j++) {
for (size_t j = 0; j < eta; j++) {
size_t bitpos = 2 * i * eta + eta + j;
y += 1 & ((randombuf[bitpos >> 3]) >> (bitpos & 7));
}
v->data[256 * r + i] = reduce(x + Q - y, Q, Qrecip);
}
} // WINSCP
} // WINSCP
}
smemclr(seedbuf, sizeof(seedbuf));
smemclr(randombuf, eta * 64);
sfree(randombuf);
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -549,8 +499,7 @@ static void mlkem_byte_encode_lossless(
{
unsigned char *out = (unsigned char *)outv;
uint32_t buffer = 0, bufbits = 0;
size_t i; // WINSCP
for (i = 0; i < 256*n; i++) {
for (size_t i = 0; i < 256*n; i++) {
buffer |= (uint32_t) in[i] << bufbits;
bufbits += 12;
while (bufbits >= 8) {
@@ -575,8 +524,7 @@ static bool mlkem_byte_decode_lossless(
{
const unsigned char *in = (const unsigned char *)inv;
uint32_t buffer = 0, bufbits = 0;
size_t i; // WINSCP
for (i = 0; i < 384*n; i++) {
for (size_t i = 0; i < 384*n; i++) {
buffer |= (uint32_t) in[i] << bufbits;
bufbits += 8;
while (bufbits >= 12) {
@@ -609,8 +557,7 @@ static void mlkem_byte_encode_compressed(
unsigned char *out = (unsigned char *)outv;
uint32_t buffer = 0, bufbits = 0;
size_t i; // WINSCP
for (i = 0; i < 256*n; i++) {
for (size_t i = 0; i < 256*n; i++) {
uint32_t dividend = ((uint32_t)in[i] << (d+1)) + Q;
uint32_t quotient;
reduce_with_quot(dividend, &quotient, 2*Q, Qrecip);
@@ -644,8 +591,7 @@ static void mlkem_byte_decode_compressed(
{
const unsigned char *in = (const unsigned char *)inv;
uint32_t buffer = 0, bufbits = 0;
size_t i; // WINSCP
for (i = 0; i < 32*d*n; i++) {
for (size_t i = 0; i < 32*d*n; i++) {
buffer |= (uint32_t) in[i] << bufbits;
bufbits += 8;
while (bufbits >= d) {
@@ -704,11 +650,9 @@ void mlkem_keygen_rho_sigma(
* The encryption key is the vector t, plus the random seed rho
* from which anyone can reconstruct the matrix A.
*/
{ // WINSCP
unsigned char ek[1568];
mlkem_byte_encode_lossless(ek, t->data, params->k);
memcpy(ek + 384 * params->k, rho, 32);
{ // WINSCP
size_t eklen = 384 * params->k + 32;
put_data(ek_out, ek, eklen);
@@ -716,10 +660,8 @@ void mlkem_keygen_rho_sigma(
* The decryption key (for the internal "K-PKE" public-key system)
* is the vector s.
*/
{ // WINSCP
unsigned char dk[1536];
mlkem_byte_encode_lossless(dk, s->data, params->k);
{ // WINSCP
size_t dklen = 384 * params->k;
/*
@@ -735,10 +677,8 @@ void mlkem_keygen_rho_sigma(
*/
put_data(dk_out, dk, dklen);
put_data(dk_out, ek, eklen);
{ // WINSCP
ssh_hash *h = ssh_hash_new(&ssh_sha3_256);
put_data(h, ek, eklen);
{ // WINSCP
unsigned char ekhash[32];
ssh_hash_final(h, ekhash);
put_data(dk_out, ekhash, 32);
@@ -748,12 +688,6 @@ void mlkem_keygen_rho_sigma(
smemclr(ek, sizeof(ek));
smemclr(ekhash, sizeof(ekhash));
smemclr(dk, sizeof(dk));
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -834,7 +768,6 @@ bool mlkem_encaps_internal(
* the output shared secret, plus some randomness for making up
* the vectors below.
*/
{ // WINSCP
unsigned char kr[64];
unsigned char ekhash[32];
ssh_hash *h;
@@ -847,7 +780,6 @@ bool mlkem_encaps_internal(
put_data(h, m, 32);
put_data(h, ekhash, 32);
ssh_hash_final(h, kr);
{ // WINSCP
const unsigned char *k = kr, *r = kr + 32;
/*
@@ -909,7 +841,6 @@ bool mlkem_encaps_internal(
* The ciphertext consists of u and v, both encoded lossily, with
* different numbers of bits retained per element.
*/
{ // WINSCP
char c[1568];
mlkem_byte_encode_compressed(c, u->data, params->d_u, params->k);
mlkem_byte_encode_compressed(c + 32 * params->k * params->d_u,
@@ -926,9 +857,6 @@ bool mlkem_encaps_internal(
mlkem_matrix_storage_free(storage);
return true;
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -939,11 +867,9 @@ bool mlkem_encaps(BinarySink *ciphertext, BinarySink *kout,
{
unsigned char m[32];
random_read(m, 32);
{ // WINSCP
bool success = mlkem_encaps_internal(ciphertext, kout, params, ek, m);
smemclr(m, sizeof(m));
return success;
} // WINSCP
}
/*
@@ -964,7 +890,6 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
* Further validation: extract the encryption key from the middle
* of dk, hash it, and check the hash matches.
*/
{ // WINSCP
const unsigned char *dkp = (const unsigned char *)dk.ptr;
const unsigned char *cp = (const unsigned char *)c.ptr;
ptrlen ek = make_ptrlen(dkp + 384*params->k, 384*params->k + 32);
@@ -976,7 +901,6 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
if (!smemeq(ekhash, dkp + 768*params->k + 32, 32))
return false;
{ // WINSCP
mlkem_matrix_storage storage[1];
mlkem_matrix u[1], v[1], s[1], w[1];
mlkem_matrix_alloc(storage,
@@ -1030,7 +954,6 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
* that makes you not worry about spontaneous hash collisions),
* but it's not actually impossible.
*/
{ // WINSCP
unsigned char m[32];
mlkem_byte_encode_compressed(m, w->data, 1, 1);
@@ -1044,12 +967,10 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
* This is also where we get the output secret k from: the
* encapsulation function creates it as half of the hash of m.
*/
{ // WINSCP
unsigned char c_regen[1568], k[32];
buffer_sink c_sink[1], k_sink[1];
buffer_sink_init(c_sink, c_regen, sizeof(c_regen));
buffer_sink_init(k_sink, k, sizeof(k));
{ // WINSCP
bool success = mlkem_encaps_internal(
BinarySink_UPCAST(c_sink), BinarySink_UPCAST(k_sink), params, ek, m);
/* If any application of ML-KEM uses a dk given to it by someone
@@ -1069,7 +990,6 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
* k_reject is that secret; for constant-time reasons we generate
* it unconditionally.
*/
{ // WINSCP
unsigned char k_reject[32];
h = ssh_hash_new(&ssh_shake256_32bytes);
put_data(h, dkp + 768 * params->k + 64, 32);
@@ -1080,11 +1000,9 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
* Now replace k with k_reject if the ciphertexts didn't match.
*/
assert((void *)c_sink->out == (void *)(c_regen + c.len));
{ // WINSCP
unsigned match = smemeq(c.ptr, c_regen, c.len);
unsigned mask = match - 1;
size_t i; // WINSCP
for (i = 0; i < 32; i++)
for (size_t i = 0; i < 32; i++)
k[i] ^= mask & (k[i] ^ k_reject[i]);
/*
@@ -1098,13 +1016,6 @@ bool mlkem_decaps(BinarySink *k_out, const mlkem_params *params,
smemclr(k, sizeof(k));
smemclr(k_reject, sizeof(k_reject));
return true;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1146,34 +1057,34 @@ static void mlkem_vt_free_dk(pq_kem_dk *dk)
}
const pq_kemalg ssh_mlkem512 = {
/*.keygen =*/ mlkem_vt_keygen,
/*.encaps =*/ mlkem_vt_encaps,
/*.decaps =*/ mlkem_vt_decaps,
/*.free_dk =*/ mlkem_vt_free_dk,
/*.extra =*/ &mlkem_params_512,
/*.description =*/ "ML-KEM-512",
/*.ek_len =*/ 384 * 2 + 32,
/*.c_len =*/ 32 * (10 * 2 + 4),
.keygen = mlkem_vt_keygen,
.encaps = mlkem_vt_encaps,
.decaps = mlkem_vt_decaps,
.free_dk = mlkem_vt_free_dk,
.extra = &mlkem_params_512,
.description = "ML-KEM-512",
.ek_len = 384 * 2 + 32,
.c_len = 32 * (10 * 2 + 4),
};
const pq_kemalg ssh_mlkem768 = {
/*.keygen =*/ mlkem_vt_keygen,
/*.encaps =*/ mlkem_vt_encaps,
/*.decaps =*/ mlkem_vt_decaps,
/*.free_dk =*/ mlkem_vt_free_dk,
/*.extra =*/ &mlkem_params_768,
/*.description =*/ "ML-KEM-768",
/*.ek_len =*/ 384 * 3 + 32,
/*.c_len =*/ 32 * (10 * 3 + 4),
.keygen = mlkem_vt_keygen,
.encaps = mlkem_vt_encaps,
.decaps = mlkem_vt_decaps,
.free_dk = mlkem_vt_free_dk,
.extra = &mlkem_params_768,
.description = "ML-KEM-768",
.ek_len = 384 * 3 + 32,
.c_len = 32 * (10 * 3 + 4),
};
const pq_kemalg ssh_mlkem1024 = {
/*.keygen =*/ mlkem_vt_keygen,
/*.encaps =*/ mlkem_vt_encaps,
/*.decaps =*/ mlkem_vt_decaps,
/*.free_dk =*/ mlkem_vt_free_dk,
/*.extra =*/ &mlkem_params_1024,
/*.description =*/ "ML-KEM-1024",
/*.ek_len =*/ 384 * 4 + 32,
/*.c_len =*/ 32 * (11 * 4 + 5),
.keygen = mlkem_vt_keygen,
.encaps = mlkem_vt_encaps,
.decaps = mlkem_vt_decaps,
.free_dk = mlkem_vt_free_dk,
.extra = &mlkem_params_1024,
.description = "ML-KEM-1024",
.ek_len = 384 * 4 + 32,
.c_len = 32 * (11 * 4 + 5),
};

File diff suppressed because it is too large Load Diff

View File

@@ -161,32 +161,20 @@ void ntru_ring_multiply(uint16_t *out, const uint16_t *a, const uint16_t *b,
* haven't tried it.
*/
uint32_t *unreduced = snewn(2*p, uint32_t);
{ // WINSCP
unsigned i;
for (i = 0; i < 2*p; i++)
for (unsigned i = 0; i < 2*p; i++)
unreduced[i] = 0;
} // WINSCP
{ // WINSCP
unsigned i, j;
for (i = 0; i < p; i++)
for (j = 0; j < p; j++)
for (unsigned i = 0; i < p; i++)
for (unsigned j = 0; j < p; j++)
unreduced[i+j] = REDUCE(unreduced[i+j] + a[i] * b[j]);
} // WINSCP
{ // WINSCP
unsigned i;
for (i = 2*p - 1; i >= p; i--) {
for (unsigned i = 2*p - 1; i >= p; i--) {
unreduced[i-p] += unreduced[i];
unreduced[i-p+1] += unreduced[i];
unreduced[i] = 0;
}
} // WINSCP
{ // WINSCP
unsigned i;
for (i = 0; i < p; i++)
for (unsigned i = 0; i < p; i++)
out[i] = REDUCE(unreduced[i]);
} // WINSCP
smemclr(unreduced, 2*p * sizeof(*unreduced));
sfree(unreduced);
@@ -256,31 +244,20 @@ unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
memcpy(A, in, p*sizeof(uint16_t));
A[p] = 0;
Ac[0] = 1;
{ // WINSCP
size_t i;
for (i = 1; i < SIZE; i++)
for (size_t i = 1; i < SIZE; i++)
Ac[i] = 0;
} // WINSCP
/* Initialise B to the quotient polynomial of the ring, x^p-x-1
* And Bc = 0 */
B[0] = B[1] = q-1;
{ // WINSCP
size_t i;
for (i = 2; i < p; i++)
for (size_t i = 2; i < p; i++)
B[i] = 0;
} // WINSCP
B[p] = 1;
{ // WINSCP
size_t i;
for (i = 0; i < SIZE; i++)
for (size_t i = 0; i < SIZE; i++)
Bc[i] = 0;
} // WINSCP
/* Run the gcd-finding algorithm. */
{ // WINSCP
size_t i;
for (i = 0; i < STEPS; i++) {
for (size_t i = 0; i < STEPS; i++) {
/*
* First swap round so that A is the one we'll be dividing by x.
*
@@ -294,35 +271,25 @@ unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
unsigned B_is_bigger = 0;
{
unsigned not_seen_top_term_of_A = 1, not_seen_top_term_of_B = 1;
{ // WINSCP
size_t j;
for (j = SIZE; j-- > 0 ;) {
for (size_t j = SIZE; j-- > 0 ;) {
not_seen_top_term_of_A &= iszero(A[j]);
not_seen_top_term_of_B &= iszero(B[j]);
B_is_bigger |= (~not_seen_top_term_of_B &
not_seen_top_term_of_A);
}
} // WINSCP
}
{ // WINSCP
unsigned need_swap = x_divides_B | (~x_divides_A & B_is_bigger);
uint16_t swap_mask = (uint64_t)-(int64_t)need_swap; // WINSCP
{ // WINSCP
size_t j;
for (j = 0; j < SIZE; j++) {
uint16_t swap_mask = -need_swap;
for (size_t j = 0; j < SIZE; j++) {
uint16_t diff = (A[j] ^ B[j]) & swap_mask;
A[j] ^= diff;
B[j] ^= diff;
}
} // WINSCP
{ // WINSCP
size_t j;
for (j = 0; j < SIZE; j++) {
for (size_t j = 0; j < SIZE; j++) {
uint16_t diff = (Ac[j] ^ Bc[j]) & swap_mask;
Ac[j] ^= diff;
Bc[j] ^= diff;
}
} // WINSCP
/*
* Replace A with a linear combination of both A and B that
@@ -336,19 +303,12 @@ unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
* value), but it will take the same length of time as doing
* something, which is just what we want.
*/
{ // WINSCP
uint16_t Amult = B[0], Bmult = q - A[0];
{ // WINSCP
size_t j; // WINSCP
for (j = 0; j < SIZE; j++)
for (size_t j = 0; j < SIZE; j++)
A[j] = REDUCE(Amult * A[j] + Bmult * B[j]);
} // WINSCP
/* And do the same transformation to Ac */
{ // WINSCP
size_t j;
for (j = 0; j < SIZE; j++)
for (size_t j = 0; j < SIZE; j++)
Ac[j] = REDUCE(Amult * Ac[j] + Bmult * Bc[j]);
} // WINSCP
/*
* Now divide A by x, and compensate by multiplying Ac by
@@ -359,51 +319,33 @@ unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
* for n>0 just moves down to the x^{n-1} term, and only the
* constant term has to be dealt with in an interesting way.
*/
{ // WINSCP
size_t j;
for (j = 1; j < SIZE; j++)
for (size_t j = 1; j < SIZE; j++)
A[j-1] = A[j];
} // WINSCP
A[SIZE-1] = 0;
{ // WINSCP
uint16_t Ac0 = Ac[0];
{ // WINSCP
size_t j;
for (j = 1; j < p; j++)
for (size_t j = 1; j < p; j++)
Ac[j-1] = Ac[j];
} // WINSCP
Ac[p-1] = Ac0;
Ac[0] = REDUCE(Ac[0] + q - Ac0);
} // WINSCP
} // WINSCP
}
} // WINSCP
/*
* Now we expect that A is 0, and B is a constant. If so, then
* they are coprime, and we're going to return success. If not,
* they have a common factor.
*/
{ // WINSCP
unsigned success = iszero(A[0]) & (1 ^ iszero(B[0]));
{ // WINSCP
size_t j;
for (j = 1; j < SIZE; j++)
for (size_t j = 1; j < SIZE; j++)
success &= iszero(A[j]) & iszero(B[j]);
} // WINSCP
/*
* So we're going to return Bc, but first, scale it by the
* multiplicative inverse of the constant we ended up with in
* B[0].
*/
{ // WINSCP
uint16_t scale = INVERT(B[0]);
{ // WINSCP
size_t i;
for (i = 0; i < p; i++)
for (size_t i = 0; i < p; i++)
out[i] = REDUCE(scale * Bc[i]);
} // WINSCP
smemclr(A, SIZE * sizeof(*A));
sfree(A);
@@ -415,9 +357,6 @@ unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
sfree(Bc);
return success;
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -440,14 +379,11 @@ void ntru_mod3(uint16_t *out, const uint16_t *in, unsigned p, unsigned q)
unsigned bias = q/2;
uint16_t adjust = 3 - reduce(bias-1, 3, recip3);
{ // WINSCP
unsigned i;
for (i = 0; i < p; i++) {
for (unsigned i = 0; i < p; i++) {
uint16_t val = reduce(in[i] + bias, q, qrecip);
uint16_t residue = reduce(val + adjust, 3, recip3);
out[i] = residue - 1;
}
} // WINSCP
}
/*
@@ -462,11 +398,8 @@ void ntru_round3(uint16_t *out, const uint16_t *in, unsigned p, unsigned q)
SETUP;
unsigned bias = q/2;
ntru_mod3(out, in, p, q);
{ // WINSCP
unsigned i;
for (i = 0; i < p; i++)
for (unsigned i = 0; i < p; i++)
out[i] = REDUCE(in[i] + bias) - bias - out[i];
} // WINSCP
}
/*
@@ -476,8 +409,7 @@ void ntru_round3(uint16_t *out, const uint16_t *in, unsigned p, unsigned q)
static void ntru_normalise(uint16_t *out, const uint16_t *in,
unsigned p, unsigned q)
{
unsigned i; // WINSCP
for (i = 0; i < p; i++)
for (unsigned i = 0; i < p; i++)
out[i] = in[i] + q * (in[i] >> 15);
}
@@ -488,8 +420,7 @@ void ntru_bias(uint16_t *out, const uint16_t *in, unsigned bias,
unsigned p, unsigned q)
{
SETUP;
unsigned i; // WINSCP
for (i = 0; i < p; i++)
for (unsigned i = 0; i < p; i++)
out[i] = REDUCE(in[i] + bias);
}
@@ -500,8 +431,7 @@ void ntru_scale(uint16_t *out, const uint16_t *in, uint16_t scale,
unsigned p, unsigned q)
{
SETUP;
unsigned i; // WINSCP
for (i = 0; i < p; i++)
for (unsigned i = 0; i < p; i++)
out[i] = REDUCE(in[i] * scale);
}
@@ -512,8 +442,7 @@ void ntru_scale(uint16_t *out, const uint16_t *in, uint16_t scale,
static void ntru_expand(
uint16_t *out, const uint16_t *in, unsigned p, unsigned q)
{
size_t i; // WINSCP
for (i = 0; i < p; i++) {
for (size_t i = 0; i < p; i++) {
uint16_t v = in[i];
/* Map 2 to q-1, and leave 0 and 1 unchanged */
v += (v >> 1) * (q-3);
@@ -658,20 +587,14 @@ NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n)
* 'ms_new' is the list output from the current pass. After each
* pass we swap the arrays round.
*/
{ // WINSCP
uint32_t *ms = snewn(n, uint32_t);
uint32_t *msnew = snewn(n, uint32_t);
{ // WINSCP
size_t i;
for (i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
ms[i] = ms_in[i];
} // WINSCP
while (n > 1) {
size_t nnew = 0;
{ // WINSCP
size_t i;
for (i = 0; i < n; i += 2) {
for (size_t i = 0; i < n; i += 2) {
if (i+1 == n) {
/*
* Odd element at the end of the input list: just copy
@@ -686,7 +609,6 @@ NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n)
* Normal case: consume two elements from the input list
* and combine them.
*/
{ // WINSCP
uint32_t m1 = ms[i], m2 = ms[i+1], m = m1*m2;
sched_append(sched, ENC_COMBINE_BASE + m1);
@@ -704,20 +626,16 @@ NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n)
* list and append to the fifo.
*/
msnew[nnew++] = m;
} // WINSCP
}
} // WINSCP
/*
* End of pass. The output list of (m_i) now becomes the input
* list.
*/
{ // WINSCP
uint32_t *tmp = ms;
ms = msnew;
n = nnew;
msnew = tmp;
} // WINSCP
}
/*
@@ -729,7 +647,6 @@ NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n)
* only possible actual value is 0).
*/
assert(n == 1);
{ // WINSCP
uint32_t m = ms[0];
while (m > 1) {
sched_append(sched, ENC_BYTE);
@@ -740,8 +657,6 @@ NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n)
sfree(msnew);
return sched;
} // WINSCP
} // WINSCP
}
void ntru_encode_schedule_free(NTRUEncodeSchedule *sched)
@@ -756,13 +671,10 @@ void ntru_encode_schedule_free(NTRUEncodeSchedule *sched)
size_t ntru_encode_schedule_length(NTRUEncodeSchedule *sched)
{
size_t len = 0;
{ // WINSCP
size_t i;
for (i = 0; i < sched->nops; i++)
for (size_t i = 0; i < sched->nops; i++)
if (sched->ops[i] == ENC_BYTE)
len++;
return len;
} // WINSCP
}
/*
@@ -782,11 +694,8 @@ void ntru_encode(NTRUEncodeSchedule *sched, const uint16_t *rs_in,
{
size_t n = sched->nvals;
uint32_t *rs = snewn(n, uint32_t);
{ // WINSCP
size_t i;
for (i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
rs[i] = rs_in[i];
} // WINSCP
/*
* The head and tail pointers of the queue are both 'full'. That
@@ -803,12 +712,9 @@ void ntru_encode(NTRUEncodeSchedule *sched, const uint16_t *rs_in,
* full slot for the BYTE command, so in this case, it's easier to
* do it the less usual way.
*/
{ // WINSCP
size_t head = 0, tail = n-1;
{ // WINSCP
size_t i;
for (i = 0; i < sched->nops; i++) {
for (size_t i = 0; i < sched->nops; i++) {
uint16_t op = sched->ops[i];
switch (op) {
case ENC_BYTE:
@@ -825,17 +731,14 @@ void ntru_encode(NTRUEncodeSchedule *sched, const uint16_t *rs_in,
default: {
uint32_t r1 = rs[head];
head = (head + 1) % n;
{ // WINSCP
uint32_t r2 = rs[head];
head = (head + 1) % n;
tail = (tail + 1) % n;
rs[tail] = r1 + (op - ENC_COMBINE_BASE) * r2;
break;
} // WINSCP
}
}
}
} // WINSCP
/*
* Expect that we've ended up with a single zero in the queue, at
@@ -847,7 +750,6 @@ void ntru_encode(NTRUEncodeSchedule *sched, const uint16_t *rs_in,
smemclr(rs, n * sizeof(*rs));
sfree(rs);
} // WINSCP
}
/*
@@ -875,18 +777,14 @@ void ntru_decode(NTRUEncodeSchedule *sched, uint16_t *rs_out, ptrlen data)
size_t head = sched->endpos, tail = head;
rs[tail] = 0;
{ // WINSCP
size_t i;
for (i = sched->nops; i-- > 0 ;) {
for (size_t i = sched->nops; i-- > 0 ;) {
uint16_t op = sched->ops[i];
switch (op) {
case ENC_BYTE: {
assert(pos > base);
{ // WINSCP
uint8_t byte = *--pos;
rs[tail] = (rs[tail] << 8) | byte;
break;
} // WINSCP
}
case ENC_COPY: {
uint32_t r = rs[tail];
@@ -899,7 +797,6 @@ void ntru_decode(NTRUEncodeSchedule *sched, uint16_t *rs_out, ptrlen data)
uint32_t r = rs[tail];
tail = (tail + n - 1) % n;
{ // WINSCP
uint32_t m = op - ENC_COMBINE_BASE;
uint64_t mrecip = reciprocal_for_reduction(m);
@@ -911,21 +808,16 @@ void ntru_decode(NTRUEncodeSchedule *sched, uint16_t *rs_out, ptrlen data)
head = (head + n - 1) % n;
rs[head] = r1;
break;
} // WINSCP
}
}
}
} // WINSCP
assert(pos == base);
assert(head == 0);
assert(tail == n-1);
{ // WINSCP
size_t i;
for (i = 0; i < n; i++)
for (size_t i = 0; i < n; i++)
rs_out[i] = rs[i];
} // WINSCP
smemclr(rs, n * sizeof(*rs));
sfree(rs);
}
@@ -999,11 +891,8 @@ void ntru_gen_short(uint16_t *v, unsigned p, unsigned w)
* Initial value before zeroing out some terms: p randomly chosen
* values in {1,2}.
*/
{ // WINSCP
size_t i;
for (i = 0; i < p; i++)
for (size_t i = 0; i < p; i++)
v[i] = 1 + mp_get_bit(randdata, --randbitpos);
} // WINSCP
/*
* Hereafter we're going to extract random bits by multiplication,
@@ -1015,19 +904,15 @@ void ntru_gen_short(uint16_t *v, unsigned p, unsigned w)
* Zero out some terms, leaving a randomly selected w of them
* nonzero.
*/
{ // WINSCP
uint32_t nonzeros_left = w;
mp_int *x = mp_new(64);
{ // WINSCP
size_t i;
for (i = p; i-- > 0 ;) {
for (size_t i = p; i-- > 0 ;) {
/*
* Pick a random number out of the number of terms remaning.
*/
mp_mul_integer_into(randdata, randdata, i+1);
mp_rshift_fixed_into(x, randdata, randbitpos);
mp_reduce_mod_2to(randdata, randbitpos);
{ // WINSCP
size_t j = mp_get_integer(x);
/*
@@ -1035,15 +920,12 @@ void ntru_gen_short(uint16_t *v, unsigned p, unsigned w)
* number nonzero. Otherwise we're zeroing it out.
*/
uint32_t keep = (uint32_t)(j - nonzeros_left) >> 31;
v[i] &= (uint32_t)-(int32_t)keep; /* clear this field if keep == 0 */ // WINSCP
v[i] &= -keep; /* clear this field if keep == 0 */
nonzeros_left -= keep; /* decrement counter if keep == 1 */
} // WINSCP
}
} // WINSCP
mp_free(x);
mp_free(randdata);
} // WINSCP
}
/*
@@ -1086,22 +968,18 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
*/
uint16_t *g = snewn(p, uint16_t);
mp_int *x = mp_new(64);
{ // WINSCP
size_t i;
for (i = 0; i < p; i++) {
for (size_t i = 0; i < p; i++) {
mp_mul_integer_into(randdata, randdata, 3);
mp_rshift_fixed_into(x, randdata, randbitpos);
mp_reduce_mod_2to(randdata, randbitpos);
g[i] = mp_get_integer(x);
}
} // WINSCP
mp_free(x);
mp_free(randdata);
/*
* Try to invert g over Z_3, and fail if it isn't invertible.
*/
{ // WINSCP
uint16_t *ginv = snewn(p, uint16_t);
if (!ntru_ring_invert(ginv, g, p, 3)) {
ring_free(g, p);
@@ -1113,7 +991,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
* Fine; we have g. Now make up an f, and convert it to a
* polynomial over q.
*/
{ // WINSCP
uint16_t *f = snewn(p, uint16_t);
ntru_gen_short(f, p, w);
ntru_expand(f, f, p, q);
@@ -1121,7 +998,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
/*
* Multiply f by 3.
*/
{ // WINSCP
uint16_t *f3 = snewn(p, uint16_t);
ntru_scale(f3, f, 3, p, q);
@@ -1131,7 +1007,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
* 0. And f is nonzero because it came from ntru_gen_short (hence,
* w of its components are nonzero), hence so is 3*f.
*/
{ // WINSCP
uint16_t *f3inv = snewn(p, uint16_t);
bool expect_always_success = ntru_ring_invert(f3inv, f3, p, q);
assert(expect_always_success);
@@ -1140,10 +1015,8 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
* Make the public key, by converting g to a polynomial over q and
* then multiplying by f3inv.
*/
{ // WINSCP
uint16_t *g_q = snewn(p, uint16_t);
ntru_expand(g_q, g, p, q);
{ // WINSCP
uint16_t *h = snewn(p, uint16_t);
ntru_ring_multiply(h, g_q, f3inv, p, q);
@@ -1151,7 +1024,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
* Make up rho, used to substitute for the plaintext in the
* session hash in case of confirmation failure.
*/
{ // WINSCP
uint16_t *rho = snewn(p, uint16_t);
ntru_gen_short(rho, p, w);
@@ -1159,7 +1031,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
* And we're done! Free everything except the pieces we're
* returning.
*/
{ // WINSCP
NTRUKeyPair *keypair = snew(NTRUKeyPair);
keypair->p = p;
keypair->q = q;
@@ -1173,14 +1044,6 @@ NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w)
ring_free(g, p);
ring_free(g_q, p);
return keypair;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -1205,7 +1068,6 @@ void ntru_encrypt(uint16_t *ciphertext, const uint16_t *plaintext,
uint16_t *r_q = snewn(p, uint16_t);
ntru_expand(r_q, plaintext, p, q);
{ // WINSCP
uint16_t *unrounded = snewn(p, uint16_t);
ntru_ring_multiply(unrounded, r_q, pubkey, p, q);
@@ -1214,7 +1076,6 @@ void ntru_encrypt(uint16_t *ciphertext, const uint16_t *plaintext,
ring_free(r_q, p);
ring_free(unrounded, p);
} // WINSCP
}
/*
@@ -1246,14 +1107,9 @@ void ntru_decrypt(uint16_t *plaintext, const uint16_t *ciphertext,
* secret about the private key in some way.)
*/
{ // WINSCP
unsigned weight = p;
{ // WINSCP
size_t i;
for (i = 0; i < p; i++)
for (size_t i = 0; i < p; i++)
weight -= iszero(plaintext[i]);
} // WINSCP
{ // WINSCP
unsigned ok = iszero(weight ^ w);
/*
@@ -1261,22 +1117,14 @@ void ntru_decrypt(uint16_t *plaintext, const uint16_t *ciphertext,
* 0s.
*/
unsigned mask = ok - 1;
{ // WINSCP
size_t i;
for (i = 0; i < w; i++) {
for (size_t i = 0; i < w; i++) {
uint16_t diff = (1 ^ plaintext[i]) & mask;
plaintext[i] ^= diff;
}
} // WINSCP
{ // WINSCP
size_t i;
for (i = w; i < p; i++) {
for (size_t i = w; i < p; i++) {
uint16_t diff = (0 ^ plaintext[i]) & mask;
plaintext[i] ^= diff;
}
} // WINSCP
} // WINSCP
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1298,16 +1146,11 @@ void ntru_decrypt(uint16_t *plaintext, const uint16_t *ciphertext,
static NTRUEncodeSchedule *ntru_encode_pubkey_schedule(unsigned p, unsigned q)
{
uint16_t *ms = snewn(p, uint16_t);
{ // WINSCP
size_t i;
for (i = 0; i < p; i++)
for (size_t i = 0; i < p; i++)
ms[i] = q;
} // WINSCP
{ // WINSCP
NTRUEncodeSchedule *sched = ntru_encode_schedule(ms, p);
sfree(ms);
return sched;
} // WINSCP
}
/*
@@ -1321,13 +1164,11 @@ void ntru_encode_pubkey(const uint16_t *pubkey, unsigned p, unsigned q,
ntru_bias(biased_pubkey, pubkey, q / 2, p, q);
/* Encode it */
{ // WINSCP
NTRUEncodeSchedule *sched = ntru_encode_pubkey_schedule(p, q);
ntru_encode(sched, biased_pubkey, bs);
ntru_encode_schedule_free(sched);
ring_free(biased_pubkey, p);
} // WINSCP
}
/*
@@ -1388,16 +1229,11 @@ static NTRUEncodeSchedule *ntru_encode_ciphertext_schedule(
{
unsigned m = ciphertext_m(q);
uint16_t *ms = snewn(p, uint16_t);
{ // WINSCP
size_t i;
for (i = 0; i < p; i++)
for (size_t i = 0; i < p; i++)
ms[i] = m;
} // WINSCP
{ // WINSCP
NTRUEncodeSchedule *sched = ntru_encode_schedule(ms, p);
sfree(ms);
return sched;
} // WINSCP
}
/*
@@ -1419,13 +1255,11 @@ void ntru_encode_ciphertext(const uint16_t *ciphertext, unsigned p, unsigned q,
ntru_scale(biased_ciphertext, biased_ciphertext, INVERT(3), p, q);
/* Encode. */
{ // WINSCP
NTRUEncodeSchedule *sched = ntru_encode_ciphertext_schedule(p, q);
ntru_encode(sched, biased_ciphertext, bs);
ntru_encode_schedule_free(sched);
ring_free(biased_ciphertext, p);
} // WINSCP
}
ptrlen ntru_decode_ciphertext(uint16_t *ct, NTRUKeyPair *keypair,
@@ -1471,9 +1305,7 @@ void ntru_encode_plaintext(const uint16_t *plaintext, unsigned p,
BinarySink *bs)
{
unsigned byte = 0, bitpos = 0;
{ // WINSCP
size_t i;
for (i = 0; i < p; i++) {
for (size_t i = 0; i < p; i++) {
unsigned encoding = (plaintext[i] + 1) * iszero(plaintext[i] >> 1);
byte |= encoding << bitpos;
bitpos += 2;
@@ -1483,7 +1315,6 @@ void ntru_encode_plaintext(const uint16_t *plaintext, unsigned p,
bitpos = 0;
}
}
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1521,7 +1352,6 @@ static void ntru_confirmation_hash(
ssh_hash *hconfirm = ssh_hash_new(&ssh_sha512);
put_byte(hconfirm, 2); /* initial byte 2 */
{ // WINSCP
uint8_t hashdata[64];
/* Compute H(3 || r) and add it to the main hash */
@@ -1532,7 +1362,6 @@ static void ntru_confirmation_hash(
put_data(hconfirm, hashdata, 32);
/* Compute H(4 || K) and add it to the main hash */
{ // WINSCP
ssh_hash *h4K = ssh_hash_new(&ssh_sha512);
put_byte(h4K, 4);
ntru_encode_pubkey(pubkey, p, q, BinarySink_UPCAST(h4K));
@@ -1545,8 +1374,6 @@ static void ntru_confirmation_hash(
/* And copy the first 32 bytes into the caller's output array */
memcpy(out, hashdata, 32);
smemclr(hashdata, sizeof(hashdata));
} // WINSCP
} // WINSCP
}
/*
@@ -1583,7 +1410,6 @@ static void ntru_session_hash(
ssh_hash *hsession = ssh_hash_new(&ssh_sha512);
put_byte(hsession, ok); /* initial byte 1 or 0 */
{ // WINSCP
uint8_t hashdata[64];
/* Compute H(3 || r), or maybe H(3 || rho), and add it to the main hash */
@@ -1603,7 +1429,6 @@ static void ntru_session_hash(
/* And copy the first 32 bytes into the caller's output array */
memcpy(out, hashdata, 32);
smemclr(hashdata, sizeof(hashdata));
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1641,7 +1466,6 @@ static bool ntru_vt_encaps(const pq_kemalg *alg, BinarySink *c, BinarySink *k,
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, ek);
{ // WINSCP
uint16_t *pubkey = snewn(p_LIVE, uint16_t);
ntru_decode_pubkey(pubkey, p_LIVE, q_LIVE, src);
@@ -1652,17 +1476,14 @@ static bool ntru_vt_encaps(const pq_kemalg *alg, BinarySink *c, BinarySink *k,
}
/* Invent a valid NTRU plaintext. */
{ // WINSCP
uint16_t *plaintext = snewn(p_LIVE, uint16_t);
ntru_gen_short(plaintext, p_LIVE, w_LIVE);
/* Encrypt the plaintext, and encode the ciphertext into a strbuf,
* so we can reuse it for both the session hash and sending to the
* client. */
{ // WINSCP
uint16_t *ciphertext = snewn(p_LIVE, uint16_t);
ntru_encrypt(ciphertext, plaintext, pubkey, p_LIVE, q_LIVE);
{ // WINSCP
strbuf *ciphertext_encoded = strbuf_new_nm();
ntru_encode_ciphertext(ciphertext, p_LIVE, q_LIVE,
BinarySink_UPCAST(ciphertext_encoded));
@@ -1670,13 +1491,11 @@ static bool ntru_vt_encaps(const pq_kemalg *alg, BinarySink *c, BinarySink *k,
/* Compute the confirmation hash, and append that to the data sent
* to the other side. */
{ // WINSCP
uint8_t confhash[32];
ntru_confirmation_hash(confhash, plaintext, pubkey, p_LIVE, q_LIVE);
put_data(c, confhash, 32);
/* Compute the session hash, i.e. the output shared secret. */
{ // WINSCP
uint8_t sesshash[32];
ntru_session_hash(sesshash, 1, plaintext, p_LIVE,
ptrlen_from_strbuf(ciphertext_encoded),
@@ -1691,12 +1510,6 @@ static bool ntru_vt_encaps(const pq_kemalg *alg, BinarySink *c, BinarySink *k,
smemclr(sesshash, sizeof(sesshash));
return true;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
static bool ntru_vt_decaps(pq_kem_dk *dk, BinarySink *k, ptrlen c)
@@ -1707,7 +1520,6 @@ static bool ntru_vt_decaps(pq_kem_dk *dk, BinarySink *k, ptrlen c)
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, c);
{ // WINSCP
uint16_t *ciphertext = snewn(p_LIVE, uint16_t);
ptrlen ciphertext_encoded = ntru_decode_ciphertext(
ciphertext, ndk->keypair, src);
@@ -1720,28 +1532,23 @@ static bool ntru_vt_decaps(pq_kem_dk *dk, BinarySink *k, ptrlen c)
}
/* Decrypt the ciphertext to recover the sender's plaintext */
{ // WINSCP
uint16_t *plaintext = snewn(p_LIVE, uint16_t);
ntru_decrypt(plaintext, ciphertext, ndk->keypair);
/* Make the confirmation hash */
{ // WINSCP
uint8_t confhash[32];
ntru_confirmation_hash(confhash, plaintext, ndk->keypair->h,
p_LIVE, q_LIVE);
/* Check it matches the one the server sent */
{ // WINSCP
unsigned ok = smemeq(confhash, confirmation_hash.ptr, 32);
/* If not, substitute in rho for the plaintext in the session hash */
unsigned mask = ok-1;
size_t i; // WINSCP
for (i = 0; i < p_LIVE; i++)
for (size_t i = 0; i < p_LIVE; i++)
plaintext[i] ^= mask & (plaintext[i] ^ ndk->keypair->rho[i]);
/* Compute the session hash, whether or not we did that */
{ // WINSCP
uint8_t sesshash[32];
ntru_session_hash(sesshash, ok, plaintext, p_LIVE, ciphertext_encoded,
confirmation_hash);
@@ -1753,11 +1560,6 @@ static bool ntru_vt_decaps(pq_kem_dk *dk, BinarySink *k, ptrlen c)
smemclr(sesshash, sizeof(sesshash));
return true;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
static void ntru_vt_free_dk(pq_kem_dk *dk)
@@ -1769,12 +1571,11 @@ static void ntru_vt_free_dk(pq_kem_dk *dk)
}
const pq_kemalg ssh_ntru = {
/*.keygen =*/ ntru_vt_keygen,
/*.encaps =*/ ntru_vt_encaps,
/*.decaps =*/ ntru_vt_decaps,
/*.free_dk =*/ ntru_vt_free_dk,
NULL, // WINSCP
/*.description =*/ "NTRU Prime",
/*.ek_len =*/ 1158,
/*.c_len =*/ 1039,
.keygen = ntru_vt_keygen,
.encaps = ntru_vt_encaps,
.decaps = ntru_vt_decaps,
.free_dk = ntru_vt_free_dk,
.description = "NTRU Prime",
.ek_len = 1158,
.c_len = 1039,
};

View File

@@ -147,9 +147,7 @@ static inline bool blobtrans_read(BlobTransformer *bt, BinarySource *src,
blob_fmt blob)
{
size_t nparts = bt->nparts;
{ // WINSCP
size_t i;
for (i = 0; i < blob.len; i++)
for (size_t i = 0; i < blob.len; i++)
if (nparts < blob.fmt[i]+1)
nparts = blob.fmt[i]+1;
@@ -159,7 +157,7 @@ static inline bool blobtrans_read(BlobTransformer *bt, BinarySource *src,
bt->parts[bt->nparts++] = make_ptrlen(NULL, 0);
}
for (i = 0; i < blob.len; i++) {
for (size_t i = 0; i < blob.len; i++) {
size_t j = blob.fmt[i];
ptrlen part = get_string(src);
if (bt->parts[j].ptr) {
@@ -177,15 +175,13 @@ static inline bool blobtrans_read(BlobTransformer *bt, BinarySource *src,
}
return true;
} // WINSCP
}
static inline void blobtrans_write(BlobTransformer *bt, BinarySink *bs,
blob_fmt blob)
{
size_t i; // WINSCP
for (i = 0; i < blob.len; i++) {
pinitassert(i < bt->nparts);
for (size_t i = 0; i < blob.len; i++) {
assert(i < bt->nparts);
ptrlen part = bt->parts[blob.fmt[i]];
assert(part.ptr);
put_stringpl(bs, part);
@@ -245,46 +241,46 @@ static const ssh_keyalg *opensshcert_related_alg(const ssh_keyalg *self,
#define KEYALG_DEF(name, ssh_alg_id_prefix, ssh_key_id_prefix, fmt_prefix) \
static const struct opensshcert_extra opensshcert_##name##_extra = { \
/*.pub_fmt =*/ { /*.fmt =*/ fmt_prefix ## _pub_fmt, \
/*.len =*/ lenof(fmt_prefix ## _pub_fmt) }, \
/*.base_ossh_fmt =*/ { /*.fmt =*/ fmt_prefix ## _base_ossh_fmt, \
/*.len =*/ lenof(fmt_prefix ## _base_ossh_fmt) }, \
/*.cert_ossh_fmt =*/ { /*.fmt =*/ fmt_prefix ## _cert_ossh_fmt, \
/*.len =*/ lenof(fmt_prefix ## _cert_ossh_fmt) }, \
/*.cert_key_ssh_id =*/ ssh_key_id_prefix "-cert-v01@openssh.com", \
/*.base_key_ssh_id =*/ ssh_key_id_prefix, \
.pub_fmt = { .fmt = fmt_prefix ## _pub_fmt, \
.len = lenof(fmt_prefix ## _pub_fmt) }, \
.base_ossh_fmt = { .fmt = fmt_prefix ## _base_ossh_fmt, \
.len = lenof(fmt_prefix ## _base_ossh_fmt) }, \
.cert_ossh_fmt = { .fmt = fmt_prefix ## _cert_ossh_fmt, \
.len = lenof(fmt_prefix ## _cert_ossh_fmt) }, \
.cert_key_ssh_id = ssh_key_id_prefix "-cert-v01@openssh.com", \
.base_key_ssh_id = ssh_key_id_prefix, \
}; \
\
const ssh_keyalg opensshcert_##name = { \
/*.new_pub =*/ opensshcert_new_pub, \
/*.new_priv =*/ opensshcert_new_priv, \
/*.new_priv_openssh =*/ opensshcert_new_priv_openssh, \
/*.freekey =*/ opensshcert_freekey, \
/*.invalid =*/ opensshcert_invalid, \
/*.sign =*/ opensshcert_sign, \
/*.verify =*/ opensshcert_verify, \
/*.public_blob =*/ opensshcert_public_blob, \
/*.private_blob =*/ opensshcert_private_blob, \
/*.openssh_blob =*/ opensshcert_openssh_blob, \
/*.has_private =*/ opensshcert_has_private, \
/*.cache_str =*/ opensshcert_cache_str, \
/*.components =*/ opensshcert_components, \
/*.base_key =*/ opensshcert_base_key, \
/*.ca_public_blob =*/ opensshcert_ca_public_blob, \
/*.check_cert =*/ opensshcert_check_cert, \
/*.cert_id_string =*/ opensshcert_cert_id_string, \
/*.cert_info =*/ opensshcert_cert_info, \
/*.pubkey_bits =*/ opensshcert_pubkey_bits, \
/*.supported_flags =*/ opensshcert_supported_flags, \
/*.alternate_ssh_id =*/ opensshcert_alternate_ssh_id, \
/*.alg_desc =*/ opensshcert_alg_desc, \
/*.variable_size =*/ opensshcert_variable_size, \
/*.related_alg =*/ opensshcert_related_alg, \
/*.ssh_id =*/ ssh_alg_id_prefix "-cert-v01@openssh.com", \
/*.cache_id =*/ "opensshcert-" ssh_key_id_prefix, \
/*.extra =*/ &opensshcert_##name##_extra, \
/*.is_certificate =*/ true, \
/*.base_alg =*/ &name, \
.new_pub = opensshcert_new_pub, \
.new_priv = opensshcert_new_priv, \
.new_priv_openssh = opensshcert_new_priv_openssh, \
.freekey = opensshcert_freekey, \
.invalid = opensshcert_invalid, \
.sign = opensshcert_sign, \
.verify = opensshcert_verify, \
.public_blob = opensshcert_public_blob, \
.private_blob = opensshcert_private_blob, \
.openssh_blob = opensshcert_openssh_blob, \
.has_private = opensshcert_has_private, \
.cache_str = opensshcert_cache_str, \
.components = opensshcert_components, \
.base_key = opensshcert_base_key, \
.ca_public_blob = opensshcert_ca_public_blob, \
.check_cert = opensshcert_check_cert, \
.cert_id_string = opensshcert_cert_id_string, \
.cert_info = opensshcert_cert_info, \
.pubkey_bits = opensshcert_pubkey_bits, \
.supported_flags = opensshcert_supported_flags, \
.alternate_ssh_id = opensshcert_alternate_ssh_id, \
.alg_desc = opensshcert_alg_desc, \
.variable_size = opensshcert_variable_size, \
.related_alg = opensshcert_related_alg, \
.ssh_id = ssh_alg_id_prefix "-cert-v01@openssh.com", \
.cache_id = "opensshcert-" ssh_key_id_prefix, \
.extra = &opensshcert_##name##_extra, \
.is_certificate = true, \
.base_alg = &name, \
};
KEYALG_LIST(KEYALG_DEF)
#undef KEYALG_DEF
@@ -307,14 +303,12 @@ static strbuf *get_base_public_blob(BinarySource *src,
* does ensure that the right amount of data is copied so that
* src ends up in the right position to read the remaining
* certificate fields. */
{ // WINSCP
BLOBTRANS_DECLARE(bt);
blobtrans_read(bt, src, extra->pub_fmt);
blobtrans_write(bt, BinarySink_UPCAST(basepub), extra->pub_fmt);
blobtrans_clear(bt);
return basepub;
} // WINSCP
}
static opensshcert_key *opensshcert_new_shared(
@@ -329,13 +323,11 @@ static opensshcert_key *opensshcert_new_shared(
if (!ptrlen_eq_string(get_string(src), extra->cert_key_ssh_id))
return NULL;
{ // WINSCP
opensshcert_key *ck = snew(opensshcert_key);
memset(ck, 0, sizeof(*ck));
ck->sshk.vt = self;
ck->nonce = strbuf_dup(get_string(src));
{ // WINSCP
strbuf *basepub = get_base_public_blob(src, extra);
ck->serial = get_uint64(src);
ck->type = get_uint32(src);
@@ -358,8 +350,6 @@ static opensshcert_key *opensshcert_new_shared(
*basepub_out = basepub;
return ck;
} // WINSCP
} // WINSCP
}
static ssh_key *opensshcert_new_pub(const ssh_keyalg *self, ptrlen pub)
@@ -412,7 +402,6 @@ static ssh_key *opensshcert_new_priv_openssh(
if (!ck)
return NULL;
{ // WINSCP
strbuf *baseossh = strbuf_new();
/* Make the base OpenSSH key blob out of the public key blob
@@ -426,7 +415,6 @@ static ssh_key *opensshcert_new_priv_openssh(
/* blobtrans_read might fail in this case, because we're reading
* from two sources and they might fail to match */
{ // WINSCP
bool success = blobtrans_read(bt, pubsrc, extra->pub_fmt) &&
blobtrans_read(bt, src, extra->cert_ossh_fmt);
@@ -442,7 +430,6 @@ static ssh_key *opensshcert_new_priv_openssh(
strbuf_free(basepub);
{ // WINSCP
BinarySource osshsrc[1];
BinarySource_BARE_INIT_PL(osshsrc, ptrlen_from_strbuf(baseossh));
ck->basekey = ssh_key_new_priv_openssh(self->base_alg, osshsrc);
@@ -454,9 +441,6 @@ static ssh_key *opensshcert_new_priv_openssh(
}
return &ck->sshk;
} // WINSCP
} // WINSCP
} // WINSCP
}
static void opensshcert_freekey(ssh_key *key)
@@ -501,13 +485,11 @@ static ssh_key *opensshcert_ca_pub_key(
if (algname)
*algname = pubkey_blob_to_alg_name(alg_source);
{ // WINSCP
const ssh_keyalg *ca_alg = pubkey_blob_to_alg(alg_source);
if (!ca_alg)
return NULL; /* don't even recognise the certifying key type */
return ssh_key_new_pub(ca_alg, ca_keyblob);
} // WINSCP
}
static void opensshcert_signature_preimage(opensshcert_key *ck, BinarySink *bs)
@@ -516,10 +498,8 @@ static void opensshcert_signature_preimage(opensshcert_key *ck, BinarySink *bs)
put_stringz(bs, extra->cert_key_ssh_id);
put_stringpl(bs, ptrlen_from_strbuf(ck->nonce));
{ // WINSCP
strbuf *basepub = strbuf_new();
ssh_key_public_blob(ck->basekey, BinarySink_UPCAST(basepub));
{ // WINSCP
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(basepub));
get_string(src); /* skip initial key type string */
@@ -536,8 +516,6 @@ static void opensshcert_signature_preimage(opensshcert_key *ck, BinarySink *bs)
put_stringpl(bs, ptrlen_from_strbuf(ck->extensions));
put_stringpl(bs, ptrlen_from_strbuf(ck->reserved));
put_stringpl(bs, ptrlen_from_strbuf(ck->signature_key));
} // WINSCP
} // WINSCP
}
static void opensshcert_public_blob(ssh_key *key, BinarySink *bs)
@@ -563,23 +541,17 @@ static void opensshcert_openssh_blob(ssh_key *key, BinarySink *bs)
ssh_key_public_blob(key, BinarySink_UPCAST(cert));
put_stringsb(bs, cert);
{ // WINSCP
strbuf *baseossh = strbuf_new_nm();
ssh_key_openssh_blob(ck->basekey, BinarySink_UPCAST(baseossh));
{ // WINSCP
BinarySource basesrc[1];
BinarySource_BARE_INIT_PL(basesrc, ptrlen_from_strbuf(baseossh));
{ // WINSCP
BLOBTRANS_DECLARE(bt);
blobtrans_read(bt, basesrc, extra->base_ossh_fmt);
blobtrans_write(bt, bs, extra->cert_ossh_fmt);
blobtrans_clear(bt);
strbuf_free(baseossh);
} // WINSCP
} // WINSCP
} // WINSCP
}
static void opensshcert_ca_public_blob(ssh_key *key, BinarySink *bs)
@@ -620,30 +592,21 @@ static void opensshcert_string_list_key_components(
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(input));
{ // WINSCP
const char *titles[2]; // WINSCP
titles[0] = title;
titles[1] = title2;
{ // WINSCP
const char *titles[2] = { title, title2 };
size_t ntitles = (title2 ? 2 : 1);
unsigned index = 0;
while (get_avail(src)) {
size_t ti; // WINSCP
for (ti = 0; ti < ntitles; ti++) {
for (size_t ti = 0; ti < ntitles; ti++) {
ptrlen value = get_string(src);
if (get_err(src))
break;
{ // WINSCP
char *name = dupprintf("%s_%u", titles[ti], index);
key_components_add_text_pl(kc, name, value);
sfree(name);
} // WINSCP
}
index++;
}
} // WINSCP
} // WINSCP
}
static key_components *opensshcert_components(ssh_key *key)
@@ -680,7 +643,7 @@ static key_components *opensshcert_components(ssh_key *key)
ptrlen_from_strbuf(date));
strbuf_free(date);
}
if (ck->valid_before != 0xFFFFFFFFFFFFFFFFLL ) { // WINSCP
if (ck->valid_before != 0xFFFFFFFFFFFFFFFF) {
strbuf *date = strbuf_new();
opensshcert_time_to_iso8601(BinarySink_UPCAST(date), ck->valid_before);
key_components_add_text_pl(kc, "cert_valid_before_date",
@@ -696,7 +659,6 @@ static key_components *opensshcert_components(ssh_key *key)
key_components_add_binary(kc, "cert_ca_key", ptrlen_from_strbuf(
ck->signature_key));
{ // WINSCP
ptrlen ca_algname;
ssh_key *ca_key = opensshcert_ca_pub_key(ck, make_ptrlen(NULL, 0),
&ca_algname);
@@ -704,8 +666,7 @@ static key_components *opensshcert_components(ssh_key *key)
if (ca_key) {
key_components *kc_ca_key = ssh_key_components(ca_key);
size_t i; // WINSCP
for (i = 0; i < kc_ca_key->ncomponents; i++) {
for (size_t i = 0; i < kc_ca_key->ncomponents; i++) {
key_component *comp = &kc_ca_key->components[i];
char *subname = dupcat("cert_ca_key_", comp->name);
key_components_add_copy(kc, subname, comp);
@@ -718,7 +679,6 @@ static key_components *opensshcert_components(ssh_key *key)
key_components_add_binary(kc, "cert_ca_sig", ptrlen_from_strbuf(
ck->signature));
return kc;
} // WINSCP
}
static SeatDialogText *opensshcert_cert_info(ssh_key *key)
@@ -758,7 +718,6 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(
ck->valid_principals));
{ // WINSCP
const char *sep = "";
strbuf_clear(tmp);
while (get_avail(src)) {
@@ -771,14 +730,13 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
}
seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT,
"%s", tmp->s);
} // WINSCP
}
seat_dialog_text_append(text, SDT_MORE_INFO_KEY,
"Validity period");
strbuf_clear(tmp);
if (ck->valid_after == 0) {
if (ck->valid_before == 0xFFFFFFFFFFFFFFFFLL) { // WINSCP
if (ck->valid_before == 0xFFFFFFFFFFFFFFFF) {
put_dataz(tmp, "forever");
} else {
put_dataz(tmp, "until ");
@@ -786,7 +744,7 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
ck->valid_before);
}
} else {
if (ck->valid_before == 0xFFFFFFFFFFFFFFFFLL) { // WINSCP
if (ck->valid_before == 0xFFFFFFFFFFFFFFFF) {
put_dataz(tmp, "after ");
opensshcert_time_to_iso8601(BinarySink_UPCAST(tmp),
ck->valid_after);
@@ -819,24 +777,20 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
ptrlen_eq_string(key, "source-address")) {
BinarySource src2[1];
BinarySource_BARE_INIT_PL(src2, value);
{ // WINSCP
ptrlen addresslist = get_string(src2);
seat_dialog_text_append(text, SDT_MORE_INFO_KEY,
"Permitted client IP addresses");
seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT,
"%.*s", PTRLEN_PRINTF(addresslist));
} // WINSCP
} else if (ck->type == SSH_CERT_TYPE_USER &&
ptrlen_eq_string(key, "force-command")) {
BinarySource src2[1];
BinarySource_BARE_INIT_PL(src2, value);
{ // WINSCP
ptrlen command = get_string(src2);
seat_dialog_text_append(text, SDT_MORE_INFO_KEY,
"Forced remote command");
seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT,
"%.*s", PTRLEN_PRINTF(command));
} // WINSCP
}
}
}
@@ -850,7 +804,6 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
* things that _aren't_ enabled.
*/
{ // WINSCP
bool x11_ok = false, agent_ok = false, portfwd_ok = false;
bool pty_ok = false, user_rc_ok = false;
@@ -914,7 +867,6 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
seat_dialog_text_append(text, SDT_MORE_INFO_VALUE_SHORT,
"%" PRIu64, ck->serial);
{ // WINSCP
char *fp = ssh2_fingerprint_blob(ptrlen_from_strbuf(ck->signature_key),
SSH_FPTYPE_DEFAULT);
seat_dialog_text_append(text, SDT_MORE_INFO_KEY,
@@ -930,8 +882,6 @@ static SeatDialogText *opensshcert_cert_info(ssh_key *key)
strbuf_free(tmp);
return text;
} // WINSCP
} // WINSCP
#endif
}
@@ -942,13 +892,11 @@ static int opensshcert_pubkey_bits(const ssh_keyalg *self, ptrlen blob)
get_string(src); /* key type */
get_string(src); /* nonce */
{ // WINSCP
strbuf *basepub = get_base_public_blob(src, self->extra);
int bits = ssh_key_public_bits(
self->base_alg, ptrlen_from_strbuf(basepub));
strbuf_free(basepub);
return bits;
} // WINSCP
}
static unsigned opensshcert_supported_flags(const ssh_keyalg *self)
@@ -961,8 +909,7 @@ static const char *opensshcert_alternate_ssh_id(const ssh_keyalg *self,
{
const char *base_id = ssh_keyalg_alternate_ssh_id(self->base_alg, flags);
size_t i; // WINSCP
for (i = 0; i < lenof(opensshcert_all_keyalgs); i++) {
for (size_t i = 0; i < lenof(opensshcert_all_keyalgs); i++) {
const ssh_keyalg *alg_i = opensshcert_all_keyalgs[i];
if (!strcmp(base_id, alg_i->base_alg->ssh_id))
return alg_i->ssh_id;
@@ -987,8 +934,7 @@ static bool opensshcert_variable_size(const ssh_keyalg *self)
static const ssh_keyalg *opensshcert_related_alg(const ssh_keyalg *self,
const ssh_keyalg *base)
{
size_t i; // WINSCP
for (i = 0; i < lenof(opensshcert_all_keyalgs); i++) {
for (size_t i = 0; i < lenof(opensshcert_all_keyalgs); i++) {
const ssh_keyalg *alg_i = opensshcert_all_keyalgs[i];
if (base == alg_i->base_alg)
return alg_i;
@@ -1053,7 +999,6 @@ static bool opensshcert_check_cert(
/* Check which signature algorithm is actually in use, because
* that might be a reason to reject the certificate (e.g. ssh-rsa
* when we wanted rsa-sha2-*). */
{ // WINSCP
const ssh_keyalg *sig_alg = ssh_key_alg(ca_key);
if ((sig_alg == &ssh_rsa && !opts->permit_rsa_sha1) ||
(sig_alg == &ssh_rsa_sha256 && !opts->permit_rsa_sha256) ||
@@ -1070,7 +1015,6 @@ static bool opensshcert_check_cert(
goto out;
}
{ // WINSCP
uint32_t expected_type = host ? SSH_CERT_TYPE_HOST : SSH_CERT_TYPE_USER;
if (ck->type != expected_type) {
put_fmt(error, "Certificate type is ");
@@ -1142,7 +1086,6 @@ static bool opensshcert_check_cert(
host ? "hostname" : "username");
BinarySource_BARE_INIT_PL(
src, ptrlen_from_strbuf(ck->valid_principals));
{ // WINSCP
const char *sep = "";
while (get_avail(src)) {
ptrlen valid_principal = get_string(src);
@@ -1157,7 +1100,6 @@ static bool opensshcert_check_cert(
put_fmt(error, "\"");
goto out;
principal_ok:;
} // WINSCP
}
/*
@@ -1207,8 +1149,6 @@ static bool opensshcert_check_cert(
ssh_key_free(ca_key);
strbuf_free(preimage);
return result;
} // WINSCP
} // WINSCP
}
static bool opensshcert_verify(ssh_key *key, ptrlen sig, ptrlen data)

View File

@@ -114,9 +114,7 @@ prng *prng_new(const ssh_hashalg *hashalg)
pi->keymaker = NULL;
pi->generator = NULL;
memset(pi->counter, 0, sizeof(pi->counter));
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < NCOLLECTORS; i++)
for (size_t i = 0; i < NCOLLECTORS; i++)
pi->collectors[i] = ssh_hash_new(pi->hashalg);
pi->until_reseed = 0;
BinarySink_INIT(&pi->Prng, prng_seed_BinarySink_write);
@@ -124,7 +122,6 @@ prng *prng_new(const ssh_hashalg *hashalg)
pi->Prng.savesize = pi->hashalg->hlen * 4;
return &pi->Prng;
} // WINSCP
}
void prng_free(prng *pr)
@@ -132,9 +129,7 @@ void prng_free(prng *pr)
prng_impl *pi = container_of(pr, prng_impl, Prng);
smemclr(pi->counter, sizeof(pi->counter));
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < NCOLLECTORS; i++)
for (size_t i = 0; i < NCOLLECTORS; i++)
ssh_hash_free(pi->collectors[i]);
if (pi->generator)
ssh_hash_free(pi->generator);
@@ -142,7 +137,6 @@ void prng_free(prng *pr)
ssh_hash_free(pi->keymaker);
smemclr(pi, sizeof(*pi));
sfree(pi);
} // WINSCP
}
void prng_seed_begin(prng *pr)
@@ -211,17 +205,12 @@ static inline void prng_generate(prng_impl *pi, void *outbuf)
prngdebug("prng_generate\n");
put_byte(h, 'G');
{ // WINSCP
unsigned i; // WINSCP
for (i = 0; i < 128; i += 8)
for (unsigned i = 0; i < 128; i += 8)
put_byte(h, pi->counter[i/BIGNUM_INT_BITS] >> (i%BIGNUM_INT_BITS));
{ // WINSCP
BignumCarry c = 1;
for (i = 0; i < lenof(pi->counter); i++)
for (unsigned i = 0; i < lenof(pi->counter); i++)
BignumADC(pi->counter[i], c, pi->counter[i], 0, c);
ssh_hash_final(h, outbuf);
} // WINSCP
} // WINSCP
}
void prng_read(prng *pr, void *vout, size_t size)
@@ -233,30 +222,26 @@ void prng_read(prng *pr, void *vout, size_t size)
prngdebug("prng_read %"SIZEu"\n", size);
{ // WINSCP
uint8_t *out = (uint8_t *)vout;
while (size > 0) {
prng_generate(pi, buf);
{ // WINSCP
size_t to_use = size > pi->hashalg->hlen ? pi->hashalg->hlen : size;
memcpy(out, buf, to_use);
out += to_use;
size -= to_use;
} // WINSCP
}
smemclr(buf, sizeof(buf));
prng_seed_begin(&pi->Prng);
prng_seed_finish(&pi->Prng);
} // WINSCP
}
void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data)
{
prng_impl *pi = container_of(pr, prng_impl, Prng);
pinitassert(source_id < NOISE_MAX_SOURCES);
assert(source_id < NOISE_MAX_SOURCES);
uint32_t counter = ++pi->source_counters[source_id];
size_t index = 0;
@@ -278,13 +263,10 @@ void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data)
prng_reseed_time_ms() - pi->last_reseed_time >= 100) {
prng_seed_begin(&pi->Prng);
{ // WINSCP
unsigned char buf[MAX_HASH_LEN];
uint32_t reseed_index = ++pi->reseeds;
prngdebug("prng entropy reseed #%"PRIu32"\n", reseed_index);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < NCOLLECTORS; i++) {
for (size_t i = 0; i < NCOLLECTORS; i++) {
prngdebug("emptying collector %"SIZEu"\n", i);
ssh_hash_digest(pi->collectors[i], buf);
put_data(&pi->Prng, buf, pi->hashalg->hlen);
@@ -295,8 +277,6 @@ void prng_add_entropy(prng *pr, unsigned source_id, ptrlen data)
}
smemclr(buf, sizeof(buf));
prng_seed_finish(&pi->Prng);
} // WINSCP
} // WINSCP
}
}

View File

@@ -143,7 +143,6 @@ static mp_int *bits2int(ptrlen b, RFC6979 *s)
{
if (b.len > s->qbytes)
b.len = s->qbytes;
{ // WINSCP
mp_int *x = mp_from_bytes_be(b);
/*
@@ -161,14 +160,12 @@ static mp_int *bits2int(ptrlen b, RFC6979 *s)
mp_rshift_fixed_into(x, x, b.len * 8 - s->qbits);
return x;
} // WINSCP
}
static void BinarySink_put_int2octets(BinarySink *bs, mp_int *x, RFC6979 *s)
{
mp_int *x_mod_q = mp_mod(x, s->q);
size_t i; // WINSCP
for (i = s->qbytes; i-- > 0 ;)
for (size_t i = s->qbytes; i-- > 0 ;)
put_byte(bs, mp_get_byte(x_mod_q, i));
mp_free(x_mod_q);
}
@@ -199,13 +196,11 @@ RFC6979 *rfc6979_new(const ssh_hashalg *hashalg, mp_int *q, mp_int *x)
/* In each attempt, we concatenate enough hash blocks to be
* greater than qbits in size. */
{ // WINSCP
size_t hbits = 8 * s->hlen;
s->T_nblocks = (s->qbits + hbits - 1) / hbits;
s->T = snewn(s->T_nblocks * s->hlen, unsigned char);
return s;
} // WINSCP
}
void rfc6979_setup(RFC6979 *s, ptrlen message)
@@ -268,8 +263,7 @@ RFC6979Result rfc6979_attempt(RFC6979 *s)
/* 3.2 (h) 1: set T to the empty string */
/* 3.2 (h) 2: make lots of output by concatenating MACs of V */
size_t i; // WINSCP
for (i = 0; i < s->T_nblocks; i++) {
for (size_t i = 0; i < s->T_nblocks; i++) {
ssh2_mac_start(s->mac);
put_data(s->mac, s->V, s->hlen);
ssh2_mac_genresult(s->mac, s->V);
@@ -317,7 +311,6 @@ RFC6979Result rfc6979_attempt(RFC6979 *s)
ssh2_mac_start(s->mac);
put_data(s->mac, s->V, s->hlen);
put_byte(s->mac, 0);
{ // WINSCP
unsigned char K[MAX_HASH_LEN];
ssh2_mac_genresult(s->mac, K);
ssh2_mac_setkey(s->mac, make_ptrlen(K, s->hlen));
@@ -328,7 +321,6 @@ RFC6979Result rfc6979_attempt(RFC6979 *s)
ssh2_mac_genresult(s->mac, s->V);
return result;
} // WINSCP
}
void rfc6979_free(RFC6979 *s)
@@ -354,7 +346,6 @@ mp_int *rfc6979(
{
RFC6979 *s = rfc6979_new(hashalg, q, x);
rfc6979_setup(s, message);
{ // WINSCP
RFC6979Result result;
while (true) {
result = rfc6979_attempt(s);
@@ -365,5 +356,4 @@ mp_int *rfc6979(
}
rfc6979_free(s);
return result.k;
} // WINSCP
}

View File

@@ -104,7 +104,6 @@ bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
data[0] = 0;
data[1] = 2;
{ // WINSCP
size_t npad = key->bytes - length - 3;
/*
* Generate a sequence of nonzero padding bytes. We do this in a
@@ -130,12 +129,10 @@ bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
mp_free(tmp);
for (i = 2; i < key->bytes - length - 1; i++) {
mp_mul_integer_into(randval, randval, 255);
{ // WINSCP
uint8_t byte = mp_get_byte(randval, random_bits / 8);
assert(byte != 255);
data[i] = byte + 1;
mp_reduce_mod_2to(randval, random_bits);
} // WINSCP
}
mp_free(randval);
data[key->bytes - length - 1] = 0;
@@ -153,7 +150,6 @@ bool rsa_ssh1_encrypt(unsigned char *data, int length, RSAKey *key)
mp_free(b2);
return true;
} // WINSCP
}
/*
@@ -183,16 +179,12 @@ static mp_int *crt_modpow(mp_int *base, mp_int *exp, mp_int *mod,
/*
* Do the two modpows.
*/
{ // WINSCP
mp_int *base_mod_p = mp_mod(base, p);
presult = mp_modpow(base_mod_p, pexp, p);
mp_free(base_mod_p);
} // WINSCP
{ // WINSCP
mp_int *base_mod_q = mp_mod(base, q);
qresult = mp_modpow(base_mod_q, qexp, q);
mp_free(base_mod_q);
} // WINSCP
/*
* Recombine the results. We want a value which is congruent to
@@ -206,10 +198,8 @@ static mp_int *crt_modpow(mp_int *base, mp_int *exp, mp_int *mod,
*
* (If presult-qresult < 0, we add p to it to keep it positive.)
*/
{ // WINSCP
unsigned presult_too_small = mp_cmp_hs(qresult, presult);
mp_cond_add_into(presult, presult, p, presult_too_small);
} // WINSCP
diff = mp_sub(presult, qresult);
multiplier = mp_mul(iqmp, q);
@@ -261,8 +251,7 @@ bool rsa_ssh1_decrypt_pkcs1(mp_int *input, RSAKey *key,
{
mp_int *b = rsa_ssh1_decrypt(input, key);
size_t i; // WINSCP
for (i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;) {
for (size_t i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;) {
put_byte(data, mp_get_byte(b, i));
}
mp_free(b);
@@ -294,13 +283,11 @@ static void append_hex_to_strbuf(strbuf *sb, mp_int *x)
if (sb->len > 0)
put_byte(sb, ',');
put_data(sb, "0x", 2);
{ // WINSCP
char *hex = mp_get_hex(x);
size_t hexlen = strlen(hex);
put_data(sb, hex, hexlen);
smemclr(hex, hexlen);
sfree(hex);
} // WINSCP
}
char *rsastr_fmt(RSAKey *key)
@@ -332,13 +319,10 @@ char *rsa_ssh1_fingerprint(RSAKey *key)
*/
ssh_hash *hash = ssh_hash_new(&ssh_md5);
{ // WINSCP
size_t i; // WINSCP
for (i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;)
for (size_t i = (mp_get_nbits(key->modulus) + 7) / 8; i-- > 0 ;)
put_byte(hash, mp_get_byte(key->modulus, i));
for (i = (mp_get_nbits(key->exponent) + 7) / 8; i-- > 0 ;)
for (size_t i = (mp_get_nbits(key->exponent) + 7) / 8; i-- > 0 ;)
put_byte(hash, mp_get_byte(key->exponent, i));
} // WINSCP
ssh_hash_final(hash, digest);
out = strbuf_new();
@@ -357,8 +341,7 @@ char *rsa_ssh1_fingerprint(RSAKey *key)
char **rsa_ssh1_fake_all_fingerprints(RSAKey *key)
{
char **fingerprints = snewn(SSH_N_FPTYPES, char *);
unsigned i; // WINSCP
for (i = 0; i < SSH_N_FPTYPES; i++)
for (unsigned i = 0; i < SSH_N_FPTYPES; i++)
fingerprints[i] = NULL;
fingerprints[SSH_FPTYPE_MD5] = rsa_ssh1_fingerprint(key);
return fingerprints;
@@ -409,7 +392,6 @@ bool rsa_verify(RSAKey *key)
* should instead flip them round into the canonical order of
* p > q. This also involves regenerating iqmp.
*/
{ // WINSCP
mp_int *p_new = mp_max(key->p, key->q);
mp_int *q_new = mp_min(key->p, key->q);
mp_free(key->p);
@@ -420,7 +402,6 @@ bool rsa_verify(RSAKey *key)
key->iqmp = mp_invert(key->q, key->p);
return ok;
} // WINSCP
}
void rsa_ssh1_public_blob(BinarySink *bs, RSAKey *key,
@@ -758,7 +739,7 @@ static unsigned char *rsa_pkcs1_signature_string(
size_t nbytes, const ssh_hashalg *halg, ptrlen data)
{
size_t fixed_parts = rsa_pkcs1_length_of_fixed_parts(halg);
pinitassert(nbytes >= fixed_parts);
assert(nbytes >= fixed_parts);
size_t padding = nbytes - fixed_parts;
ptrlen asn1_prefix = rsa_pkcs1_prefix_for_hash(halg);
@@ -772,11 +753,9 @@ static unsigned char *rsa_pkcs1_signature_string(
memcpy(bytes + 2 + padding, asn1_prefix.ptr, asn1_prefix.len);
{ // WINSCP
ssh_hash *h = ssh_hash_new(halg);
put_datapl(h, data);
ssh_hash_final(h, bytes + 2 + padding + asn1_prefix.len);
} // WINSCP
return bytes;
}
@@ -819,20 +798,16 @@ static bool rsa2_verify(ssh_key *key, ptrlen sig, ptrlen data)
out = mp_modpow(in, rsa->exponent, rsa->modulus);
mp_free(in);
{ // WINSCP
unsigned diff = 0;
unsigned char *bytes = rsa_pkcs1_signature_string(nbytes, halg, data);
size_t i; // WINSCP
for (i = 0; i < nbytes; i++)
for (size_t i = 0; i < nbytes; i++)
diff |= bytes[nbytes-1 - i] ^ mp_get_byte(out, i);
smemclr(bytes, nbytes);
sfree(bytes);
mp_free(out);
return diff == 0;
} // WINSCP
}
static void rsa2_sign(ssh_key *key, ptrlen data,
@@ -893,11 +868,8 @@ static void rsa2_sign(ssh_key *key, ptrlen data,
nbytes = (mp_get_nbits(rsa->modulus) + 7) / 8;
}
put_uint32(bs, nbytes);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < nbytes; i++)
for (size_t i = 0; i < nbytes; i++)
put_byte(bs, mp_get_byte(out, nbytes - 1 - i));
} // WINSCP
mp_free(out);
}
@@ -939,67 +911,48 @@ static const struct ssh2_rsa_extra
rsa_sha256_extra = { SSH_AGENT_RSA_SHA2_256 },
rsa_sha512_extra = { SSH_AGENT_RSA_SHA2_512 };
// WINSCP
#define COMMON_KEYALG_FIELDS \
/*.new_pub =*/ rsa2_new_pub, \
/*.new_priv =*/ rsa2_new_priv, \
/*.new_priv_openssh =*/ rsa2_new_priv_openssh, \
/*.freekey =*/ rsa2_freekey, \
/*.invalid =*/ rsa2_invalid, \
/*.sign =*/ rsa2_sign, \
/*.verify =*/ rsa2_verify, \
/*.public_blob =*/ rsa2_public_blob, \
/*.private_blob =*/ rsa2_private_blob, \
/*.openssh_blob =*/ rsa2_openssh_blob, \
/*.has_private =*/ rsa2_has_private, \
/*.cache_str =*/ rsa2_cache_str, \
/*.components =*/ rsa2_components, \
/*.base_key =*/ nullkey_base_key, \
NULL, NULL, NULL, NULL, \
/*.pubkey_bits =*/ rsa2_pubkey_bits
#define COMMON_KEYALG_FIELDS1a \
/*.alg_desc =*/ rsa2_alg_desc, \
/*.variable_size =*/ nullkey_variable_size_yes, \
NULL
#define COMMON_KEYALG_FIELDS2 \
/*.cache_id =*/ "rsa2"
#define COMMON_KEYALG_FIELDS3 \
false, NULL
.new_pub = rsa2_new_pub, \
.new_priv = rsa2_new_priv, \
.new_priv_openssh = rsa2_new_priv_openssh, \
.freekey = rsa2_freekey, \
.invalid = rsa2_invalid, \
.sign = rsa2_sign, \
.verify = rsa2_verify, \
.public_blob = rsa2_public_blob, \
.private_blob = rsa2_private_blob, \
.openssh_blob = rsa2_openssh_blob, \
.has_private = rsa2_has_private, \
.cache_str = rsa2_cache_str, \
.components = rsa2_components, \
.base_key = nullkey_base_key, \
.pubkey_bits = rsa2_pubkey_bits, \
.alg_desc = rsa2_alg_desc, \
.variable_size = nullkey_variable_size_yes, \
.cache_id = "rsa2"
const ssh_keyalg ssh_rsa = {
// WINSCP
COMMON_KEYALG_FIELDS,
/*.supported_flags =*/ ssh_rsa_supported_flags,
/*.alternate_ssh_id =*/ ssh_rsa_alternate_ssh_id,
COMMON_KEYALG_FIELDS1a,
/*.ssh_id =*/ "ssh-rsa",
COMMON_KEYALG_FIELDS2,
/*.extra =*/ &rsa_extra,
COMMON_KEYALG_FIELDS3,
.ssh_id = "ssh-rsa",
.supported_flags = ssh_rsa_supported_flags,
.alternate_ssh_id = ssh_rsa_alternate_ssh_id,
.extra = &rsa_extra,
};
const ssh_keyalg ssh_rsa_sha256 = {
// WINSCP
COMMON_KEYALG_FIELDS,
/*.supported_flags =*/ nullkey_supported_flags,
/*.alternate_ssh_id =*/ nullkey_alternate_ssh_id,
COMMON_KEYALG_FIELDS1a,
/*.ssh_id =*/ "rsa-sha2-256",
COMMON_KEYALG_FIELDS2,
/*.extra =*/ &rsa_sha256_extra,
COMMON_KEYALG_FIELDS3,
.ssh_id = "rsa-sha2-256",
.supported_flags = nullkey_supported_flags,
.alternate_ssh_id = nullkey_alternate_ssh_id,
.extra = &rsa_sha256_extra,
};
const ssh_keyalg ssh_rsa_sha512 = {
// WINSCP
COMMON_KEYALG_FIELDS,
/*.supported_flags =*/ nullkey_supported_flags,
/*.alternate_ssh_id =*/ nullkey_alternate_ssh_id,
COMMON_KEYALG_FIELDS1a,
/*.ssh_id =*/ "rsa-sha2-512",
COMMON_KEYALG_FIELDS2,
/*.extra =*/ &rsa_sha512_extra,
COMMON_KEYALG_FIELDS3,
.ssh_id = "rsa-sha2-512",
.supported_flags = nullkey_supported_flags,
.alternate_ssh_id = nullkey_alternate_ssh_id,
.extra = &rsa_sha512_extra,
};
RSAKey *ssh_rsakex_newkey(ptrlen data)
@@ -1090,7 +1043,6 @@ strbuf *ssh_rsakex_encrypt(RSAKey *rsa, const ssh_hashalg *h, ptrlen in)
assert(in.len > 0 && in.len <= k - 2*HLEN - 2);
/* The length of the output data wants to be precisely k. */
{ // WINSCP
strbuf *toret = strbuf_new_nm();
int outlen = k;
unsigned char *out = strbuf_append(toret, outlen);
@@ -1139,7 +1091,6 @@ strbuf *ssh_rsakex_encrypt(RSAKey *rsa, const ssh_hashalg *h, ptrlen in)
* And we're done.
*/
return toret;
} // WINSCP
}
mp_int *ssh_rsakex_decrypt(
@@ -1215,21 +1166,17 @@ static const struct ssh_rsa_kex_extra ssh_rsa_kex_extra_sha1 = { 1024 };
static const struct ssh_rsa_kex_extra ssh_rsa_kex_extra_sha256 = { 2048 };
static const ssh_kex ssh_rsa_kex_sha1 = {
/*.name =*/ "rsa1024-sha1",
NULL,
/*.main_type =*/ KEXTYPE_RSA,
/*.hash =*/ &ssh_sha1,
NULL, // WINSCP
/*.extra =*/ &ssh_rsa_kex_extra_sha1,
.name = "rsa1024-sha1",
.main_type = KEXTYPE_RSA,
.hash = &ssh_sha1,
.extra = &ssh_rsa_kex_extra_sha1,
};
static const ssh_kex ssh_rsa_kex_sha256 = {
/*.name =*/ "rsa2048-sha256",
NULL,
/*.main_type =*/ KEXTYPE_RSA,
/*.hash =*/ &ssh_sha256,
NULL, // WINSCP
/*.extra =*/ &ssh_rsa_kex_extra_sha256,
.name = "rsa2048-sha256",
.main_type = KEXTYPE_RSA,
.hash = &ssh_sha256,
.extra = &ssh_rsa_kex_extra_sha256,
};
static const ssh_kex *const rsa_kex_list[] = {

View File

@@ -22,9 +22,7 @@ static ssh_hash *sha1_select(const ssh_hashalg *alg)
NULL,
};
{ // WINSCP
size_t i;
for (i = 0; real_algs[i]; i++) {
for (size_t i = 0; real_algs[i]; i++) {
const ssh_hashalg *alg = real_algs[i];
const struct sha1_extra *alg_extra =
(const struct sha1_extra *)alg->extra;
@@ -36,18 +34,11 @@ static ssh_hash *sha1_select(const ssh_hashalg *alg)
* the last non-NULL entry should be software-only SHA-1, which
* is always available. */
unreachable("sha1_select ran off the end of its list");
} // WINSCP
}
const ssh_hashalg ssh_sha1 = {
// WINSCP
/*.new =*/ sha1_select,
NULL,
NULL,
NULL,
NULL,
/*.hlen =*/ 20,
/*.blocklen =*/ 64,
.new = sha1_select,
.hlen = 20,
.blocklen = 64,
HASHALG_NAMES_ANNOTATED("SHA-1", "dummy selector vtable"),
NULL,
};

View File

@@ -13,7 +13,7 @@ static bool sha1_sw_available(void)
static inline uint32_t rol(uint32_t x, unsigned y)
{
return (x << (31 & y)) | (x >> (31 & (uint32_t)(-(int32_t)y))); // WINSCP
return (x << (31 & y)) | (x >> (31 & -y));
}
static inline uint32_t Ch(uint32_t ctrl, uint32_t if1, uint32_t if0)
@@ -45,50 +45,38 @@ static void sha1_sw_block(uint32_t *core, const uint8_t *block)
uint32_t w[SHA1_ROUNDS];
uint32_t a,b,c,d,e;
{ // WINSCP
size_t t;
for (t = 0; t < 16; t++)
for (size_t t = 0; t < 16; t++)
w[t] = GET_32BIT_MSB_FIRST(block + 4*t);
{ // WINSCP
size_t t;
for (t = 16; t < SHA1_ROUNDS; t++)
for (size_t t = 16; t < SHA1_ROUNDS; t++)
w[t] = rol(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1);
a = core[0]; b = core[1]; c = core[2]; d = core[3];
e = core[4];
{ // WINSCP
size_t t = 0;
size_t u;
for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Ch(b,c,d), SHA1_STAGE0_CONSTANT);
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Ch(a,b,c), SHA1_STAGE0_CONSTANT);
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Ch(e,a,b), SHA1_STAGE0_CONSTANT);
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Ch(d,e,a), SHA1_STAGE0_CONSTANT);
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Ch(c,d,e), SHA1_STAGE0_CONSTANT);
}
{ // WINSCP
size_t u;
for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Par(b,c,d), SHA1_STAGE1_CONSTANT);
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Par(a,b,c), SHA1_STAGE1_CONSTANT);
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Par(e,a,b), SHA1_STAGE1_CONSTANT);
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Par(d,e,a), SHA1_STAGE1_CONSTANT);
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Par(c,d,e), SHA1_STAGE1_CONSTANT);
}
{ // WINSCP
size_t u;
for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Maj(b,c,d), SHA1_STAGE2_CONSTANT);
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Maj(a,b,c), SHA1_STAGE2_CONSTANT);
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Maj(e,a,b), SHA1_STAGE2_CONSTANT);
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Maj(d,e,a), SHA1_STAGE2_CONSTANT);
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Maj(c,d,e), SHA1_STAGE2_CONSTANT);
}
{ // WINSCP
size_t u;
for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Par(b,c,d), SHA1_STAGE3_CONSTANT);
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Par(a,b,c), SHA1_STAGE3_CONSTANT);
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Par(e,a,b), SHA1_STAGE3_CONSTANT);
@@ -99,12 +87,6 @@ static void sha1_sw_block(uint32_t *core, const uint8_t *block)
core[0] += a; core[1] += b; core[2] += c; core[3] += d; core[4] += e;
smemclr(w, sizeof(w));
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
typedef struct sha1_sw {
@@ -166,11 +148,8 @@ static void sha1_sw_digest(ssh_hash *hash, uint8_t *digest)
sha1_sw *s = container_of(hash, sha1_sw, hash);
sha1_block_pad(&s->blk, BinarySink_UPCAST(s));
{ // WINSCP
size_t i;
for (i = 0; i < 5; i++)
for (size_t i = 0; i < 5; i++)
PUT_32BIT_MSB_FIRST(digest + 4*i, s->core[i]);
} // WINSCP
}
SHA1_VTABLE(sw, "unaccelerated");

View File

@@ -38,21 +38,19 @@ static inline bool check_availability(const struct sha1_extra *extra)
#define SHA1_VTABLE(impl_c, impl_display) \
static struct sha1_extra_mutable sha1_ ## impl_c ## _extra_mut; \
static const struct sha1_extra sha1_ ## impl_c ## _extra = { \
/* WINSCP */ \
/*.check_available =*/ sha1_ ## impl_c ## _available, \
/*.mut =*/ &sha1_ ## impl_c ## _extra_mut, \
.check_available = sha1_ ## impl_c ## _available, \
.mut = &sha1_ ## impl_c ## _extra_mut, \
}; \
const ssh_hashalg ssh_sha1_ ## impl_c = { \
/* WINSCP */ \
/*.new =*/ sha1_ ## impl_c ## _new, \
/*.reset =*/ sha1_ ## impl_c ## _reset, \
/*.copyfrom =*/ sha1_ ## impl_c ## _copyfrom, \
/*.digest =*/ sha1_ ## impl_c ## _digest, \
/*.free =*/ sha1_ ## impl_c ## _free, \
/*.hlen =*/ 20, \
/*.blocklen =*/ 64, \
.new = sha1_ ## impl_c ## _new, \
.reset = sha1_ ## impl_c ## _reset, \
.copyfrom = sha1_ ## impl_c ## _copyfrom, \
.digest = sha1_ ## impl_c ## _digest, \
.free = sha1_ ## impl_c ## _free, \
.hlen = 20, \
.blocklen = 64, \
HASHALG_NAMES_BARE("SHA-1"), \
/*.extra =*/ &sha1_ ## impl_c ## _extra, \
.extra = &sha1_ ## impl_c ## _extra, \
}
extern const uint32_t sha1_initial_state[5];
@@ -104,12 +102,9 @@ static inline void sha1_block_pad(sha1_block *blk, BinarySink *bs)
size_t pad = 1 + (63 & (55 - blk->used));
put_byte(bs, 0x80);
{ // WINSCP
size_t i;
for (i = 1; i < pad; i++)
for (size_t i = 1; i < pad; i++)
put_byte(bs, 0);
put_uint64(bs, final_len);
assert(blk->used == 0 && "Should have exactly hit a block boundary");
} // WINSCP
}

View File

@@ -22,9 +22,7 @@ static ssh_hash *sha256_select(const ssh_hashalg *alg)
NULL,
};
{ // WINSCP
size_t i;
for (i = 0; real_algs[i]; i++) {
for (size_t i = 0; real_algs[i]; i++) {
const ssh_hashalg *alg = real_algs[i];
const struct sha256_extra *alg_extra =
(const struct sha256_extra *)alg->extra;
@@ -36,18 +34,11 @@ static ssh_hash *sha256_select(const ssh_hashalg *alg)
* the last non-NULL entry should be software-only SHA-256, which
* is always available. */
unreachable("sha256_select ran off the end of its list");
} // WINSCP
}
const ssh_hashalg ssh_sha256 = {
// WINSCP
/*.new =*/ sha256_select,
NULL,
NULL,
NULL,
NULL,
/*.hlen =*/ 32,
/*.blocklen =*/ 64,
.new = sha256_select,
.hlen = 32,
.blocklen = 64,
HASHALG_NAMES_ANNOTATED("SHA-256", "dummy selector vtable"),
NULL,
};

View File

@@ -19,7 +19,10 @@ static bool sha256_sw_available(void)
static inline uint32_t ror(uint32_t x, unsigned y)
{
return (x << (31 & /*WINSCP*/(uint32_t)(-(int32_t)y))) | (x >> (31 & y));
#pragma warning(push)
#pragma warning(suppress: 4146) // WINSCP VS
return (x << (31 & -y)) | (x >> (31 & y));
#pragma warning(pop)
}
static inline uint32_t Ch(uint32_t ctrl, uint32_t if1, uint32_t if0)
@@ -158,11 +161,8 @@ static void sha256_sw_digest(ssh_hash *hash, uint8_t *digest)
sha256_sw *s = container_of(hash, sha256_sw, hash);
sha256_block_pad(&s->blk, BinarySink_UPCAST(s));
{ // WINSCP
size_t i;
for (i = 0; i < 8; i++)
for (size_t i = 0; i < 8; i++)
PUT_32BIT_MSB_FIRST(digest + 4*i, s->core[i]);
} // WINSCP
}
SHA256_VTABLE(sw, "unaccelerated");

View File

@@ -38,21 +38,19 @@ static inline bool check_availability(const struct sha256_extra *extra)
#define SHA256_VTABLE(impl_c, impl_display) \
static struct sha256_extra_mutable sha256_ ## impl_c ## _extra_mut; \
static const struct sha256_extra sha256_ ## impl_c ## _extra = { \
/* WINSCP */ \
/*.check_available =*/ sha256_ ## impl_c ## _available, \
/*.mut =*/ &sha256_ ## impl_c ## _extra_mut, \
.check_available = sha256_ ## impl_c ## _available, \
.mut = &sha256_ ## impl_c ## _extra_mut, \
}; \
const ssh_hashalg ssh_sha256_ ## impl_c = { \
/* WINSCP */ \
/*.new =*/ sha256_ ## impl_c ## _new, \
/*.reset =*/ sha256_ ## impl_c ## _reset, \
/*.copyfrom =*/ sha256_ ## impl_c ## _copyfrom, \
/*.digest =*/ sha256_ ## impl_c ## _digest, \
/*.free =*/ sha256_ ## impl_c ## _free, \
/*.hlen =*/ 32, \
/*.blocklen =*/ 64, \
.new = sha256_ ## impl_c ## _new, \
.reset = sha256_ ## impl_c ## _reset, \
.copyfrom = sha256_ ## impl_c ## _copyfrom, \
.digest = sha256_ ## impl_c ## _digest, \
.free = sha256_ ## impl_c ## _free, \
.hlen = 32, \
.blocklen = 64, \
HASHALG_NAMES_BARE("SHA-256"), \
/*.extra =*/ &sha256_ ## impl_c ## _extra, \
.extra = &sha256_ ## impl_c ## _extra, \
}
extern const uint32_t sha256_initial_state[8];

View File

@@ -9,9 +9,7 @@
static inline uint64_t rol(uint64_t x, unsigned shift)
{
unsigned L = (+shift) & 63;
#pragma option push -w-ngu // WINSCP
unsigned R = (-shift) & 63;
#pragma option pop // WINSCP
return (x << L) | (x >> R);
}
@@ -39,36 +37,25 @@ static void keccak_transform(keccak_core_state A)
uint64_t B[5][5];
} u;
unsigned round; // WINSCP
for (round = 0; round < NROUNDS; round++) {
for (unsigned round = 0; round < NROUNDS; round++) {
/* theta step */
unsigned x; // WINSCP
for (x = 0; x < 5; x++)
for (unsigned x = 0; x < 5; x++)
u.C[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4];
for (x = 0; x < 5; x++) { // WINSCP
for (unsigned x = 0; x < 5; x++) {
uint64_t D = rol(u.C[(x+1) % 5], 1) ^ u.C[(x+4) % 5];
{ // WINSCP
unsigned y; // WINSCP
for (y = 0; y < 5; y++)
for (unsigned y = 0; y < 5; y++)
A[x][y] ^= D;
} // WINSCP
}
/* rho and pi steps */
for (x = 0; x < 5; x++) // WINSCP
{ // WINSCP
unsigned y; // WINSCP
for (y = 0; y < 5; y++)
for (unsigned x = 0; x < 5; x++)
for (unsigned y = 0; y < 5; y++)
u.B[y][(2*x+3*y) % 5] = rol(A[x][y], rotation_counts[x][y]);
} // WINSCP
/* chi step */
for (x = 0; x < 5; x++) // WINSCP
{ // WINSCP
unsigned y; // WINSCP
for (y = 0; y < 5; y++)
for (unsigned x = 0; x < 5; x++)
for (unsigned y = 0; y < 5; y++)
A[x][y] = u.B[x][y] ^ (u.B[(x+2)%5][y] & ~u.B[(x+1)%5][y]);
} // WINSCP
/* iota step */
A[0][0] ^= round_constants[round];
@@ -98,12 +85,9 @@ static void keccak_accumulate(keccak_state *s, const void *vdata, size_t len)
len -= b;
data += b;
{ // WINSCP
size_t n = 0;
unsigned y; // WINSCP
for (y = 0; y < 5; y++) {
unsigned x; // WINSCP
for (x = 0; x < 5; x++) {
for (unsigned y = 0; y < 5; y++) {
for (unsigned x = 0; x < 5; x++) {
if (n >= s->bytes_wanted)
break;
@@ -114,7 +98,6 @@ static void keccak_accumulate(keccak_state *s, const void *vdata, size_t len)
keccak_transform(s->A);
s->bytes_got = 0;
} // WINSCP
}
memcpy(s->bytes + s->bytes_got, data, len);
@@ -142,26 +125,20 @@ static void keccak_output(keccak_state *s, void *voutput)
keccak_accumulate(s, padding, len);
}
{ // WINSCP
size_t n = 0;
unsigned y; // WINSCP
for (y = 0; y < 5; y++) {
unsigned x; // WINSCP
for (x = 0; x < 5; x++) {
for (unsigned y = 0; y < 5; y++) {
for (unsigned x = 0; x < 5; x++) {
size_t to_copy = s->hash_bytes - n;
if (to_copy == 0)
break;
if (to_copy > 8)
to_copy = 8;
{ // WINSCP
unsigned char outbytes[8];
PUT_64BIT_LSB_FIRST(outbytes, s->A[x][y]);
memcpy(output + n, outbytes, to_copy);
n += to_copy;
} // WINSCP
}
}
} // WINSCP
}
static void keccak_init(keccak_state *s, unsigned hashbits, unsigned ratebits,
@@ -217,15 +194,14 @@ print(textwrap.indent("\n".join(textwrap.wrap(", ".join(
*/
static const uint64_t round_constants[24] = {
// WINSCP (ULL)
0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL,
0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL,
0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL,
0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL,
0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL,
0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL,
0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
};
/*
@@ -306,16 +282,14 @@ static void sha3_reset(ssh_hash *hash)
#define DEFINE_SHA3(bits) \
const ssh_hashalg ssh_sha3_##bits = { \
/* WINSCP */ \
/*.new =*/ keccak_new, \
/*.reset =*/ sha3_reset, \
/*.copyfrom =*/ keccak_copyfrom, \
/*.digest =*/ keccak_digest, \
/*.free =*/ keccak_free, \
/*.hlen =*/ bits/8, \
/*.blocklen =*/ 200 - 2*(bits/8), \
.new = keccak_new, \
.reset = sha3_reset, \
.copyfrom = keccak_copyfrom, \
.digest = keccak_digest, \
.free = keccak_free, \
.hlen = bits/8, \
.blocklen = 200 - 2*(bits/8), \
HASHALG_NAMES_BARE("SHA3-" #bits), \
NULL, /* WINSCP */ \
}
DEFINE_SHA3(224);
@@ -342,16 +316,14 @@ static void shake256_reset(ssh_hash *hash)
#define DEFINE_SHAKE(param, hashbytes) \
const ssh_hashalg ssh_shake##param##_##hashbytes##bytes = { \
/* WINSCP */ \
/*.new =*/ keccak_new, \
/*.reset =*/ shake##param##_reset, \
/*.copyfrom =*/ keccak_copyfrom, \
/*.digest =*/ keccak_digest, \
/*.free =*/ keccak_free, \
/*.hlen =*/ hashbytes, \
/*.blocklen =*/ 0, \
.new = keccak_new, \
.reset = shake##param##_reset, \
.copyfrom = keccak_copyfrom, \
.digest = keccak_digest, \
.free = keccak_free, \
.hlen = hashbytes, \
.blocklen = 0, \
HASHALG_NAMES_BARE("SHAKE" #param), \
NULL, /*NULL*/ \
}
DEFINE_SHAKE(256, 114); /* used by Ed448 */
@@ -398,15 +370,13 @@ void shake_xof_read(ShakeXOF *sx, void *output_v, size_t size)
if (sx->pos == 0) {
/* Copy the 64-bit words from the Keccak state into the
* output buffer of bytes */
unsigned y, x; // WINSCP
for (y = 0; y < 5; y++)
for (x = 0; x < 5; x++)
for (unsigned y = 0; y < 5; y++)
for (unsigned x = 0; x < 5; x++)
PUT_64BIT_LSB_FIRST(sx->buf + 8 * (5*y+x),
sx->state.A[x][y]);
}
/* Read a chunk from the byte buffer */
{ // WINSCP
size_t this_size = sx->bytes_per_transform - sx->pos;
if (this_size > size)
this_size = size;
@@ -420,7 +390,6 @@ void shake_xof_read(ShakeXOF *sx, void *output_v, size_t size)
keccak_transform(sx->state.A);
sx->pos = 0;
}
} // WINSCP
}
}

View File

@@ -30,9 +30,7 @@ static ssh_hash *sha512_select(const ssh_hashalg *alg)
const ssh_hashalg *const *real_algs =
(const ssh_hashalg *const *)alg->extra;
{ // WINSCP
size_t i;
for (i = 0; real_algs[i]; i++) {
for (size_t i = 0; real_algs[i]; i++) {
const ssh_hashalg *alg = real_algs[i];
const struct sha512_extra *alg_extra =
(const struct sha512_extra *)alg->extra;
@@ -44,23 +42,20 @@ static ssh_hash *sha512_select(const ssh_hashalg *alg)
* the last non-NULL entry should be software-only SHA-512, which
* is always available. */
unreachable("sha512_select ran off the end of its list");
} // WINSCP
}
const ssh_hashalg ssh_sha512 = {
/*.new =*/ sha512_select,
NULL, NULL, NULL, NULL, // WINSCP
/*.hlen =*/ 64,
/*.blocklen =*/ 128,
.new = sha512_select,
.hlen = 64,
.blocklen = 128,
HASHALG_NAMES_ANNOTATED("SHA-512", "dummy selector vtable"),
/*.extra =*/ real_sha512_algs,
.extra = real_sha512_algs,
};
const ssh_hashalg ssh_sha384 = {
/*.new =*/ sha512_select,
NULL, NULL, NULL, NULL, // WINSCP
/*.hlen =*/ 48,
/*.blocklen =*/ 128,
.new = sha512_select,
.hlen = 48,
.blocklen = 128,
HASHALG_NAMES_ANNOTATED("SHA-384", "dummy selector vtable"),
/*.extra =*/ real_sha384_algs,
.extra = real_sha384_algs,
};

View File

@@ -13,9 +13,7 @@ static bool sha512_sw_available(void)
static inline uint64_t ror(uint64_t x, unsigned y)
{
#pragma option push -w-ngu // WINSCP
return (x << (63 & -y)) | (x >> (63 & y));
#pragma option pop // WINSCP
}
static inline uint64_t Ch(uint64_t ctrl, uint64_t if1, uint64_t if0)
@@ -156,11 +154,8 @@ static void sha512_sw_digest(ssh_hash *hash, uint8_t *digest)
sha512_sw *s = container_of(hash, sha512_sw, hash);
sha512_block_pad(&s->blk, BinarySink_UPCAST(s));
{ // WINSCP
size_t i;
for (i = 0; i < hash->vt->hlen / 8; i++)
for (size_t i = 0; i < hash->vt->hlen / 8; i++)
PUT_64BIT_MSB_FIRST(digest + 8*i, s->core[i]);
} // WINSCP
}
/*

View File

@@ -40,40 +40,36 @@ static inline bool check_availability(const struct sha512_extra *extra)
#define SHA512_VTABLES(impl_c, impl_display) \
static struct sha512_extra_mutable sha512_ ## impl_c ## _extra_mut; \
static const struct sha512_extra sha384_ ## impl_c ## _extra = { \
/* WINSCP */ \
/*.initial_state =*/ sha384_initial_state, \
/*.check_available =*/ sha512_ ## impl_c ## _available, \
/*.mut =*/ &sha512_ ## impl_c ## _extra_mut, \
.initial_state = sha384_initial_state, \
.check_available = sha512_ ## impl_c ## _available, \
.mut = &sha512_ ## impl_c ## _extra_mut, \
}; \
static const struct sha512_extra sha512_ ## impl_c ## _extra = { \
/* WINSCP */ \
/*.initial_state =*/ sha512_initial_state, \
/*.check_available =*/ sha512_ ## impl_c ## _available, \
/*.mut =*/ &sha512_ ## impl_c ## _extra_mut, \
.initial_state = sha512_initial_state, \
.check_available = sha512_ ## impl_c ## _available, \
.mut = &sha512_ ## impl_c ## _extra_mut, \
}; \
const ssh_hashalg ssh_sha384_ ## impl_c = { \
/* WINSCP */ \
/*.new =*/ sha512_ ## impl_c ## _new, \
/*.reset =*/ sha512_ ## impl_c ## _reset, \
/*.copyfrom =*/ sha512_ ## impl_c ## _copyfrom, \
/*.digest =*/ sha384_ ## impl_c ## _digest, \
/*.free =*/ sha512_ ## impl_c ## _free, \
/*.hlen =*/ 48, \
/*.blocklen =*/ 128, \
.new = sha512_ ## impl_c ## _new, \
.reset = sha512_ ## impl_c ## _reset, \
.copyfrom = sha512_ ## impl_c ## _copyfrom, \
.digest = sha384_ ## impl_c ## _digest, \
.free = sha512_ ## impl_c ## _free, \
.hlen = 48, \
.blocklen = 128, \
HASHALG_NAMES_ANNOTATED("SHA-384", impl_display), \
/*.extra =*/ &sha384_ ## impl_c ## _extra, \
.extra = &sha384_ ## impl_c ## _extra, \
}; \
const ssh_hashalg ssh_sha512_ ## impl_c = { \
/* WINSCP */ \
/*.new =*/ sha512_ ## impl_c ## _new, \
/*.reset =*/ sha512_ ## impl_c ## _reset, \
/*.copyfrom =*/ sha512_ ## impl_c ## _copyfrom, \
/*.digest =*/ sha512_ ## impl_c ## _digest, \
/*.free =*/ sha512_ ## impl_c ## _free, \
/*.hlen =*/ 64, \
/*.blocklen =*/ 128, \
.new = sha512_ ## impl_c ## _new, \
.reset = sha512_ ## impl_c ## _reset, \
.copyfrom = sha512_ ## impl_c ## _copyfrom, \
.digest = sha512_ ## impl_c ## _digest, \
.free = sha512_ ## impl_c ## _free, \
.hlen = 64, \
.blocklen = 128, \
HASHALG_NAMES_ANNOTATED("SHA-512", impl_display), \
/*.extra =*/ &sha512_ ## impl_c ## _extra, \
.extra = &sha512_ ## impl_c ## _extra, \
}
extern const uint64_t sha512_initial_state[8];
@@ -107,7 +103,6 @@ static inline bool sha512_block_write(
*len -= chunk;
blk->used += chunk;
{ // WINSCP
size_t chunkbits = chunk << 3;
blk->lenlo += chunkbits;
@@ -119,7 +114,6 @@ static inline bool sha512_block_write(
}
return false;
} // WINSCP
}
static inline void sha512_block_pad(sha512_block *blk, BinarySink *bs)

1
source/putty/defs.h vendored
View File

@@ -63,6 +63,7 @@
#define SCNu64 "I64u"
#define SIZEx "Ix"
#define SIZEu "Iu"
uintmax_t strtoumax(const char *nptr, char **endptr, int base);
/* Also, define a LEGACY_WINDOWS flag to enable other workarounds */
#define LEGACY_WINDOWS
#else

View File

@@ -40,12 +40,10 @@ static const char *sk_error_socket_error(Socket *s)
}
static const SocketVtable ErrorSocket_sockvt = {
// WINSCP
/*.plug =*/ sk_error_plug,
/*.close =*/ sk_error_close,
NULL, NULL, NULL, NULL,
/*.socket_error =*/ sk_error_socket_error,
/*.endpoint_info =*/ nullsock_endpoint_info,
.plug = sk_error_plug,
.close = sk_error_close,
.socket_error = sk_error_socket_error,
.endpoint_info = nullsock_endpoint_info,
/* other methods are NULL */
};

10
source/putty/import.c vendored
View File

@@ -94,12 +94,10 @@ bool import_encrypted(const Filename *filename, int type, char **comment)
if (!lf)
return false; /* couldn't even open the file */
{ // WINSCP
bool toret = import_encrypted_s(filename, BinarySource_UPCAST(lf),
type, comment);
lf_free(lf);
return toret;
} // WINSCP
}
/*
@@ -118,12 +116,10 @@ int import_ssh1(const Filename *filename, int type,
if (!lf)
return false;
{ // WINSCP
int toret = import_ssh1_s(BinarySource_UPCAST(lf),
type, key, passphrase, errmsg_p);
lf_free(lf);
return toret;
} // WINSCP
}
/*
@@ -148,12 +144,10 @@ ssh2_userkey *import_ssh2(const Filename *filename, int type,
if (!lf)
return false;
{ // WINSCP
ssh2_userkey *toret = import_ssh2_s(BinarySource_UPCAST(lf),
type, passphrase, errmsg_p);
lf_free(lf);
return toret;
} // WINSCP
}
/*
@@ -714,7 +708,6 @@ static ssh2_userkey *openssh_pem_read(
put_stringz(blob, key->keytype == OP_DSA ? "ssh-dss" : "ssh-rsa");
{ // WINSCP
ptrlen rsa_modulus = PTRLEN_LITERAL("");
for (i = 0; i < num_integers; i++) {
@@ -781,7 +774,6 @@ static ssh2_userkey *openssh_pem_read(
errmsg = "unable to create key data structure";
goto error;
}
} // WINSCP
} else {
unreachable("Bad key type from load_openssh_pem_key");
@@ -2259,7 +2251,7 @@ static bool sshcom_write(
outblob->len - (lenpos + 8));
/* Pad encrypted blob to a multiple of cipher block size. */
if (passphrase) {
int padding = -(ssize_t)(outblob->len - (lenpos+4)) & 7; // WINSCP
int padding = -(outblob->len - (lenpos+4)) & 7;
uint8_t padding_buf[8];
random_read(padding_buf, padding);
put_data(outblob, padding_buf, padding);

View File

@@ -369,11 +369,8 @@ void log_packet(LogContext *ctx, int direction, int type,
/* (Re-)initialise dumpdata as necessary
* (start of row, or if we've just stopped omitting) */
if (!output_pos && !omitted)
{
// WINSCP: otherwise it fails with access violation with codeguard on
sprintf(dumpdata, " %08"SIZEx, p-(p%16));
sprintf(dumpdata + strlen(dumpdata), "%*s\r\n", 1+3*16+2+16, "");
}
sprintf(dumpdata, " %08"SIZEx"%*s\r\n",
p-(p%16), 1+3*16+2+16, "");
/* Deal with the current byte. */
if (blktype == PKTLOG_OMIT) {

8
source/putty/misc.h vendored
View File

@@ -190,12 +190,10 @@ static inline ptrlen make_ptrlen_startend(const void *startv, const void *endv)
{
const char *start = (const char *)startv, *end = (const char *)endv;
assert(end >= start);
{ // WINSCP
ptrlen pl;
pl.ptr = start;
pl.len = end - start;
return pl;
} // WINSCP
}
static inline ptrlen ptrlen_from_asciz(const char *str)
@@ -525,12 +523,6 @@ static inline char *stripctrl_string(StripCtrlChars *sccpub, const char *str)
}
#endif
#ifdef MPEXT
// Recent PuTTY code uses C99 standard that allows code before initialization.
// Frequently that code are assertions. This assert implementation allows being used before code.
#define pinitassert(P) const int __assert_dummy = 1/((int)(P))
#endif
/*
* A mechanism for loading a file from disk into a memory buffer where
* it can be picked apart as a BinarySource.

13
source/putty/mpint.h vendored
View File

@@ -92,18 +92,7 @@ static inline mp_int *mp__from_string_literal(const char *lit)
else
return mp_from_decimal(lit);
}
// WINSCP
static inline mp_int *mp__from_string_literal_check(const char *lit)
{
// WORKAROUND: C++Builder seems to limit stringified code to about 256 characters.
// So make sure this is not the case.
// If it is, we need to call mp__from_string_literal directly (MP_LITERAL_WINSCP_STR)
// with a string (as in dh_group*_construct).
assert(strlen(lit) < 200);
return mp__from_string_literal(lit);
}
#define MP_LITERAL(number) mp__from_string_literal_check(#number)
#define MP_LITERAL_WINSCP_STR(number) mp__from_string_literal(number)
#define MP_LITERAL(number) mp__from_string_literal(#number)
/*
* Create an mp_int with the value 2^power.

View File

@@ -250,15 +250,12 @@ static inline size_t sk_write_oob(Socket *s, const void *data, size_t len)
static inline void sk_write_eof(Socket *s)
{ s->vt->write_eof(s); }
#ifdef __cplusplus
#define WINSCP_ENUM_CAST(TYPE, EXPR) static_cast<TYPE>(EXPR)
#else
#define WINSCP_ENUM_CAST(TYPE, EXPR) (EXPR)
#endif
#ifndef __cplusplus
static inline void plug_log(
Plug *p, Socket *s, int type, SockAddr *addr, int port,
const char *msg, int code)
{ p->vt->log(p, s, WINSCP_ENUM_CAST(PlugLogType, type), addr, port, msg, code); }
{ p->vt->log(p, s, type, addr, port, msg, code); }
#endif
static inline void plug_closing(Plug *p, PlugCloseType type, const char *msg)
{ p->vt->closing(p, type, msg); }
static inline void plug_closing_normal(Plug *p)

View File

@@ -78,18 +78,13 @@ void http_digest_response(BinarySink *bs, ptrlen username, ptrlen password,
enable_dit(); /* just in case main() forgot */
{ // WINSCP
unsigned char ncbuf[4];
PUT_32BIT_MSB_FIRST(ncbuf, nonce_count);
{ // WINSCP
unsigned char client_nonce_raw[33];
random_read(client_nonce_raw, lenof(client_nonce_raw));
{ // WINSCP
char client_nonce_base64[lenof(client_nonce_raw) / 3 * 4];
{ // WINSCP
unsigned i;
for (i = 0; i < lenof(client_nonce_raw)/3; i++)
for (unsigned i = 0; i < lenof(client_nonce_raw)/3; i++)
base64_encode_atom(client_nonce_raw + 3*i, 3,
client_nonce_base64 + 4*i);
@@ -99,7 +94,6 @@ void http_digest_response(BinarySink *bs, ptrlen username, ptrlen password,
* "MD5-sess" which as far as I know don't sensibly apply to
* proxies and HTTP CONNECT).
*/
{ // WINSCP
ssh_hash *h = ssh_hash_new(alg);
put_datapl(h, username);
put_byte(h, ':');
@@ -195,9 +189,4 @@ void http_digest_response(BinarySink *bs, ptrlen username, ptrlen password,
smemclr(rsphash, lenof(rsphash));
smemclr(client_nonce_raw, lenof(client_nonce_raw));
smemclr(client_nonce_base64, lenof(client_nonce_base64));
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}

View File

@@ -328,7 +328,6 @@ static HttpAuthDetails *parse_http_auth_header(HttpProxyNegotiator *s)
(!get_token(s) && !get_quoted_string(s)))
return auth_error(d, "parse error in Digest algorithm "
"field");
{ // WINSCP
bool found = false;
size_t i;
@@ -353,7 +352,6 @@ static HttpAuthDetails *parse_http_auth_header(HttpProxyNegotiator *s)
}
d->digest_hash = i;
} // WINSCP
} else if (!stricmp(s->token->s, "qop")) {
if (!get_separator(s, '=') ||
!get_quoted_string(s))
@@ -419,16 +417,13 @@ static void proxy_http_process_queue(ProxyNegotiator *pn)
if (s->next_auth->auth_type == AUTH_BASIC) {
put_datalit(pn->output, "Proxy-Authorization: Basic ");
{ // WINSCP
strbuf *base64_input = strbuf_new_nm();
put_datapl(base64_input, ptrlen_from_strbuf(s->username));
put_byte(base64_input, ':');
put_datapl(base64_input, ptrlen_from_strbuf(s->password));
{ // WINSCP
char base64_output[4];
size_t i, e; // WINSCP
for (i = 0, e = base64_input->len; i < e; i += 3) {
for (size_t i = 0, e = base64_input->len; i < e; i += 3) {
base64_encode_atom(base64_input->u + i,
e-i > 3 ? 3 : e-i, base64_output);
put_data(pn->output, base64_output, 4);
@@ -436,8 +431,6 @@ static void proxy_http_process_queue(ProxyNegotiator *pn)
strbuf_free(base64_input);
smemclr(base64_output, sizeof(base64_output));
put_datalit(pn->output, "\r\n");
} // WINSCP
} // WINSCP
} else if (s->next_auth->auth_type == AUTH_DIGEST) {
put_datalit(pn->output, "Proxy-Authorization: Digest ");
@@ -526,7 +519,6 @@ static void proxy_http_process_queue(ProxyNegotiator *pn)
}
/* Parse the header name */
{ // WINSCP
HttpHeader hdr = HDR_UNKNOWN;
{
#define CHECK_HEADER(id, string) \
@@ -611,7 +603,6 @@ static void proxy_http_process_queue(ProxyNegotiator *pn)
http_auth_details_free(auth);
}
}
} // WINSCP
} while (s->header->len > 0);
/* Read and ignore the entire response document */
@@ -783,9 +774,8 @@ static void proxy_http_process_queue(ProxyNegotiator *pn)
}
const struct ProxyNegotiatorVT http_proxy_negotiator_vt = {
// WINSCP
/*.new =*/ proxy_http_new,
/*.process_queue =*/ proxy_http_process_queue,
/*.free =*/ proxy_http_free,
/*.type =*/ "HTTP",
.new = proxy_http_new,
.free = proxy_http_free,
.process_queue = proxy_http_process_queue,
.type = "HTTP",
};

View File

@@ -16,11 +16,9 @@ Seat *interactor_borrow_seat(Interactor *itr)
return tempseat_get_real(clientseat);
/* Otherwise, make a new TempSeat and give that to the client. */
{ // WINSCP
Seat *tempseat = tempseat_new(clientseat);
interactor_set_seat(itr, tempseat);
return clientseat;
} // WINSCP
}
static Interactor *interactor_toplevel(Interactor *itr, unsigned *level_out)
@@ -57,7 +55,6 @@ void interactor_return_seat(Interactor *itr)
*
* However, this may be overridden by the tempseat_flush call.
*/
{ // WINSCP
Seat *realseat = tempseat_get_real(tempseat);
seat_set_trust_status(realseat, true);
@@ -70,12 +67,9 @@ void interactor_return_seat(Interactor *itr)
* interactor_announce, then all Interactors from now on will
* announce themselves even if they have nothing to say.
*/
{ // WINSCP
Interactor *itr_top = interactor_toplevel(itr, NULL);
if (itr_top->last_to_talk)
interactor_announce(itr);
} // WINSCP
} // WINSCP
}
InteractionReadySeat interactor_announce(Interactor *itr)
@@ -84,11 +78,9 @@ InteractionReadySeat interactor_announce(Interactor *itr)
assert(!is_tempseat(seat) &&
"Shouldn't call announce when someone else is using our seat");
{ // WINSCP
InteractionReadySeat iseat;
iseat.seat = seat;
{ // WINSCP
unsigned level;
Interactor *itr_top = interactor_toplevel(itr, &level);
@@ -109,7 +101,6 @@ InteractionReadySeat interactor_announce(Interactor *itr)
if (itr_top->last_to_talk != NULL)
seat_antispoof_msg(iseat, ""); /* leave a separating blank line */
{ // WINSCP
char *desc = interactor_description(itr);
char *adjective = (level == 0 ? dupstr("primary") :
level == 1 ? dupstr("proxy") :
@@ -123,10 +114,7 @@ InteractionReadySeat interactor_announce(Interactor *itr)
sfree(msg);
itr_top->last_to_talk = itr;
} // WINSCP
}
return iseat;
} // WINSCP
} // WINSCP
}

View File

@@ -61,7 +61,7 @@ static void local_proxy_opener_free(DeferredSocketOpener *opener)
}
static const DeferredSocketOpenerVtable LocalProxyOpener_openervt = {
/*WINSCP .free =*/ local_proxy_opener_free,
.free = local_proxy_opener_free,
};
static char *local_proxy_opener_description(Interactor *itr)
@@ -88,11 +88,10 @@ static void local_proxy_opener_set_seat(Interactor *itr, Seat *seat)
}
static const InteractorVtable LocalProxyOpener_interactorvt = {
// WINSCP
/*.description =*/ local_proxy_opener_description,
/*.logpolicy =*/ local_proxy_opener_logpolicy,
/*.get_seat =*/ local_proxy_opener_get_seat,
/*.set_seat =*/ local_proxy_opener_set_seat,
.description = local_proxy_opener_description,
.logpolicy = local_proxy_opener_logpolicy,
.get_seat = local_proxy_opener_get_seat,
.set_seat = local_proxy_opener_set_seat,
};
static void local_proxy_opener_cleanup_interactor(LocalProxyOpener *lp)
@@ -162,12 +161,10 @@ static void local_proxy_opener_coroutine(void *vctx)
return;
} else if (spr.kind == SPRK_SW_ABORT) {
local_proxy_opener_cleanup_interactor(lp);
{ // WINSCP
char *err = spr_get_error_message(spr);
plug_closing_error(lp->plug, err);
sfree(err);
return; /* without crStop, as above */
} // WINSCP
}
crReturnV;
}
@@ -222,13 +219,11 @@ static void local_proxy_opener_coroutine(void *vctx)
* Now we're ready to actually do the platform-specific socket
* setup.
*/
{ // WINSCP
char *cmd = lp->formatted_cmd;
lp->formatted_cmd = NULL;
local_proxy_opener_cleanup_interactor(lp);
{ // WINSCP
char *error_msg = platform_setup_local_proxy(lp->socket, cmd);
burnstr(cmd);
@@ -243,8 +238,6 @@ static void local_proxy_opener_coroutine(void *vctx)
return;
}
} // WINSCP
} // WINSCP
crFinishV;
}
@@ -274,9 +267,7 @@ void local_proxy_opener_set_socket(DeferredSocketOpener *opener,
Socket *socket)
{
assert(opener->vt == &LocalProxyOpener_openervt);
{ // WINSCP
LocalProxyOpener *lp = container_of(opener, LocalProxyOpener, opener);
lp->socket = socket;
queue_toplevel_callback(get_callback_set(lp->plug), local_proxy_opener_coroutine, lp);
} // WINSCP
}

View File

@@ -233,7 +233,6 @@ static void proxy_negotiate(ProxySocket *ps)
if (ps->pn->reconnect) {
sk_close(ps->sub_socket);
{ // WINSCP
SockAddr *proxy_addr = sk_addr_dup(ps->proxy_addr);
ps->sub_socket = sk_new(proxy_addr, ps->proxy_port,
ps->proxy_privport, ps->proxy_oobinline,
@@ -252,7 +251,6 @@ static void proxy_negotiate(ProxySocket *ps)
* wanted the latter, they could have read it out of the input
* queue before asking us to close the connection.) */
bufchain_clear(&ps->pending_input_data);
} // WINSCP
}
while (bufchain_size(&ps->output_from_negotiator)) {
@@ -448,24 +446,22 @@ static SocketEndpointInfo *sk_proxy_endpoint_info(Socket *s, bool peer)
}
static const SocketVtable ProxySocket_sockvt = {
// WINSCP
/*.plug =*/ sk_proxy_plug,
/*.close =*/ sk_proxy_close,
/*.write =*/ sk_proxy_write,
/*.write_oob =*/ sk_proxy_write_oob,
/*.write_eof =*/ sk_proxy_write_eof,
/*.set_frozen =*/ sk_proxy_set_frozen,
/*.socket_error =*/ sk_proxy_socket_error,
/*.endpoint_info =*/ sk_proxy_endpoint_info,
.plug = sk_proxy_plug,
.close = sk_proxy_close,
.write = sk_proxy_write,
.write_oob = sk_proxy_write_oob,
.write_eof = sk_proxy_write_eof,
.set_frozen = sk_proxy_set_frozen,
.socket_error = sk_proxy_socket_error,
.endpoint_info = sk_proxy_endpoint_info,
};
static const PlugVtable ProxySocket_plugvt = {
// WINSCP
/*.log =*/ plug_proxy_log,
/*.closing =*/ plug_proxy_closing,
/*.receive =*/ plug_proxy_receive,
/*.sent =*/ plug_proxy_sent,
/*.accepting =*/ plug_proxy_accepting
.log = plug_proxy_log,
.closing = plug_proxy_closing,
.receive = plug_proxy_receive,
.sent = plug_proxy_sent,
.accepting = plug_proxy_accepting
};
static char *proxy_description(Interactor *itr)
@@ -496,11 +492,10 @@ static void proxy_set_seat(Interactor *itr, Seat *seat)
}
static const InteractorVtable ProxySocket_interactorvt = {
// WINSCP
/*.description =*/ proxy_description,
/*.logpolicy =*/ proxy_logpolicy,
/*.get_seat =*/ proxy_get_seat,
/*.set_seat =*/ proxy_set_seat,
.description = proxy_description,
.logpolicy = proxy_logpolicy,
.get_seat = proxy_get_seat,
.set_seat = proxy_set_seat,
};
static void proxy_prompts_callback(void *ctx)
@@ -589,7 +584,6 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
ps->clientseat = interactor_borrow_seat(ps->clientitr);
}
{ // WINSCP
const ProxyNegotiatorVT *vt;
switch (type) {
case PROXY_HTTP:
@@ -684,7 +678,6 @@ Socket *new_connection(SockAddr *addr, const char *hostname,
proxy_negotiate(ps);
return &ps->sock;
} // WINSCP
}
/* no proxy, so just return the direct socket */

View File

@@ -129,9 +129,8 @@ static void proxy_socks4_process_queue(ProxyNegotiator *pn)
}
const struct ProxyNegotiatorVT socks4_proxy_negotiator_vt = {
// WINSCP
/*.new =*/ proxy_socks4_new,
/*.process_queue =*/ proxy_socks4_process_queue,
/*.free =*/ proxy_socks4_free,
/*.type =*/ "SOCKS 4",
.new = proxy_socks4_new,
.free = proxy_socks4_free,
.process_queue = proxy_socks4_process_queue,
.type = "SOCKS 4",
};

View File

@@ -143,8 +143,7 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
{
bool found = false;
size_t i; // WINSCP
for (i = 0; i < s->auth_methods_offered->len; i++)
for (size_t i = 0; i < s->auth_methods_offered->len; i++)
if (s->auth_methods_offered->u[i] == data[1]) {
found = true;
break;
@@ -253,7 +252,6 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
* byte version
* byte 0 for success, >0 for failure
*/
{ // WINSCP
unsigned char data[2];
crMaybeWaitUntilV(bufchain_try_fetch_consume(pn->input, data, 2));
@@ -268,7 +266,6 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
pn->error = dupstr("SOCKS 5 server rejected our password");
crStopV;
}
} // WINSCP
} else if (s->auth_method == SOCKS5_AUTH_CHAP) {
assert(socks5_chap_available);
@@ -398,28 +395,23 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
case ADDRTYPE_IPV4: {
/* IPv4: address is 4 raw bytes */
put_byte(pn->output, SOCKS5_ADDR_IPV4);
{ // WINSCP
char buf[4];
sk_addrcopy(pn->ps->remote_addr, buf);
put_data(pn->output, buf, sizeof(buf));
break;
} // WINSCP
}
case ADDRTYPE_IPV6: {
/* IPv6: address is 16 raw bytes */
put_byte(pn->output, SOCKS5_ADDR_IPV6);
{ // WINSCP
char buf[16];
sk_addrcopy(pn->ps->remote_addr, buf);
put_data(pn->output, buf, sizeof(buf));
break;
} // WINSCP
}
case ADDRTYPE_NAME: {
/* Hostname: address is a pstring (Pascal-style string,
* unterminated but with a one-byte prefix length) */
put_byte(pn->output, SOCKS5_ADDR_HOSTNAME);
{ // WINSCP
char hostname[512];
sk_getaddr(pn->ps->remote_addr, hostname, lenof(hostname));
if (!put_pstring(pn->output, hostname)) {
@@ -427,7 +419,6 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
"SOCKS 5 cannot support host names longer than 255 chars");
crStopV;
}
} // WINSCP
break;
}
default:
@@ -500,9 +491,8 @@ static void proxy_socks5_process_queue(ProxyNegotiator *pn)
}
const struct ProxyNegotiatorVT socks5_proxy_negotiator_vt = {
// WINSCP
/*.new =*/ proxy_socks5_new,
/*.process_queue =*/ proxy_socks5_process_queue,
/*.free =*/ proxy_socks5_free,
/*.type =*/ "SOCKS 5",
.new = proxy_socks5_new,
.free = proxy_socks5_free,
.process_queue = proxy_socks5_process_queue,
.type = "SOCKS 5",
};

View File

@@ -362,9 +362,8 @@ static void proxy_telnet_process_queue(ProxyNegotiator *pn)
}
const struct ProxyNegotiatorVT telnet_proxy_negotiator_vt = {
// WINSCP
/*.new =*/ proxy_telnet_new,
/*.process_queue =*/ proxy_telnet_process_queue,
/*.free =*/ proxy_telnet_free,
/*.type =*/ "Telnet",
.new = proxy_telnet_new,
.free = proxy_telnet_free,
.process_queue = proxy_telnet_process_queue,
.type = "Telnet",
};

View File

@@ -1890,10 +1890,8 @@ struct ConfKeyInfo {
int value_type;
union {
// WINSCP changed order, because only the first member can be initialized
// and char* can be casted to int, but not to bool
int ival;
bool bval;
int ival;
const char *sval;
} default_value;

View File

@@ -452,8 +452,7 @@ static void wprefs(settings_w *sesskey, const char *name,
{
strbuf *sb = strbuf_new();
int i; // WINSCP
for (i = 0; i < nvals; i++) {
for (int i = 0; i < nvals; i++) {
const char *s = val2key(mapping, nvals,
conf_get_int_int(conf, primary, i));
if (s)
@@ -541,8 +540,7 @@ void save_open_settings(settings_w *sesskey, Conf *conf)
const char *p;
/* Save the settings simple enough to handle automatically */
size_t key; // WINSCP
for (key = 0; key < N_CONFIG_OPTIONS; key++) {
for (size_t key = 0; key < N_CONFIG_OPTIONS; key++) {
const ConfKeyInfo *info = &conf_key_info[key];
if (!info->save_custom && !info->not_saved) {
/* Mappings are handled individually below */
@@ -565,7 +563,6 @@ void save_open_settings(settings_w *sesskey, Conf *conf)
cp_to = CP_UTF8;
}
{ // WINSCP
size_t wlen;
wchar_t *wide = dup_mb_to_wc_c(
cp_from, orig, strlen(orig), &wlen);
@@ -587,7 +584,6 @@ void save_open_settings(settings_w *sesskey, Conf *conf)
burnwcs(wide);
burnstr(converted);
} // WINSCP
break;
}
case CONF_TYPE_INT: {
@@ -699,7 +695,6 @@ bool load_settings(const char *section, Conf *conf)
settings_r *sesskey;
sesskey = open_settings_r(section);
{ // WINSCP
bool exists = (sesskey != NULL);
load_open_settings(sesskey, conf);
close_settings_r(sesskey);
@@ -708,7 +703,6 @@ bool load_settings(const char *section, Conf *conf)
add_session_to_jumplist(section);
return exists;
} // WINSCP
}
void load_open_settings(settings_r *sesskey, Conf *conf)
@@ -716,36 +710,8 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
int i;
char *prot;
// WINSCP BEGIN Testing that our conf.winscp.h projection is valid
assert(conf_key_info[CONF_host].subkey_type == CONF_TYPE_NONE);
assert(conf_key_info[CONF_host].value_type == CONF_TYPE_STR);
assert(strcmp(conf_key_info[CONF_host].default_value.sval, "") == 0);
assert(!conf_key_info[CONF_host].save_custom);
assert(!conf_key_info[CONF_host].load_custom);
assert(!conf_key_info[CONF_host].not_saved);
assert(strcmp(conf_key_info[CONF_host].save_keyword, "HostName") == 0);
assert(conf_key_info[CONF_host].storage_enum == NULL);
assert(conf_key_info[CONF_close_on_exit].default_value.ival == AUTO);
assert(conf_key_info[CONF_proxy_type].storage_enum == &conf_enum_proxy_type);
assert(conf_key_info[CONF_remote_cmd2].not_saved);
assert(strcmp(conf_key_info[CONF_proxy_host].default_value.sval, "proxy") == 0);
assert(conf_key_info[CONF_ssh_kexlist].subkey_type == CONF_TYPE_INT);
assert(conf_key_info[CONF_ssh_kexlist].save_custom);
assert(conf_key_info[CONF_ssh_kexlist].load_custom);
assert(conf_key_info[CONF_ssh_kexlist].save_keyword == NULL);
assert(conf_key_info[CONF_ssh_prefer_known_hostkeys].default_value.bval == true);
// WINSCP END
{ // WINSCP
/* Load the settings simple enough to handle automatically */
size_t key; // WINSCP
for (key = 0; key < N_CONFIG_OPTIONS; key++) {
for (size_t key = 0; key < N_CONFIG_OPTIONS; key++) {
const ConfKeyInfo *info = &conf_key_info[key];
if (info->not_saved) {
/* Mappings are assumed to default to empty */
@@ -794,7 +760,6 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
assert(success && "unmapped default");
/* Now retrieve the stored value */
{ // WINSCP
int storageval = gppi_raw(sesskey, info->save_keyword,
defstorage);
@@ -805,7 +770,6 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
info->storage_enum, storageval, &confval))
confval = info->default_value.ival;
conf_set_int(conf, key, confval);
} // WINSCP
}
break;
case CONF_TYPE_BOOL:
@@ -1085,7 +1049,6 @@ void load_open_settings(settings_r *sesskey, Conf *conf)
}
}
gppmap(sesskey, "SSHManualHostKeys", conf, CONF_ssh_manual_hostkeys);
} // WINSCP
}
bool do_defaults(const char *session, Conf *conf)

6
source/putty/ssh.h vendored
View File

@@ -855,9 +855,9 @@ static inline void ssh_hash_digest_nondestructive(ssh_hash *h,
/* Handy macros for defining all those text-name fields at once */
#define HASHALG_NAMES_BARE(base) \
/*.text_basename =*/ base, /*.annotation =*/ NULL, /*.text_name =*/ base
.text_basename = base, .annotation = NULL, .text_name = base
#define HASHALG_NAMES_ANNOTATED(base, ann) \
/*.text_basename =*/ base, /*.annotation =*/ ann, /*.text_name =*/ base " (" ann ")"
.text_basename = base, .annotation = ann, .text_name = base " (" ann ")"
#ifndef WINSCP_VS
@@ -893,7 +893,6 @@ enum kexlist {
NKEXLIST
};
#pragma option push -w-mnc // WINSCP
struct ssh_keyalg {
/* Constructors that create an ssh_key */
ssh_key *(*new_pub) (const ssh_keyalg *self, ptrlen pub);
@@ -937,7 +936,6 @@ struct ssh_keyalg {
bool is_certificate; /* is this a certified key type? */
const ssh_keyalg *base_alg; /* if so, for what underlying key alg? */
};
#pragma option pop // WINSCP
static inline ssh_key *ssh_key_new_pub(const ssh_keyalg *self, ptrlen pub)
{ return self->new_pub(self, pub); }

View File

@@ -149,29 +149,28 @@ static char *agentf_log_close_msg(Channel *chan);
static void agentf_set_input_wanted(Channel *chan, bool wanted);
static const ChannelVtable agentf_channelvt = {
// WINSCP
/*.free =*/ agentf_free,
/*.open_confirmation =*/ chan_remotely_opened_confirmation,
/*.open_failed =*/ chan_remotely_opened_failure,
/*.send =*/ agentf_send,
/*.send_eof =*/ agentf_send_eof,
/*.set_input_wanted =*/ agentf_set_input_wanted,
/*.log_close_msg =*/ agentf_log_close_msg,
/*.want_close =*/ chan_default_want_close,
/*.rcvd_exit_status =*/ chan_no_exit_status,
/*.rcvd_exit_signal =*/ chan_no_exit_signal,
/*.rcvd_exit_signal_numeric =*/ chan_no_exit_signal_numeric,
/*.run_shell =*/ chan_no_run_shell,
/*.run_command =*/ chan_no_run_command,
/*.run_subsystem =*/ chan_no_run_subsystem,
/*.enable_x11_forwarding =*/ chan_no_enable_x11_forwarding,
/*.enable_agent_forwarding =*/ chan_no_enable_agent_forwarding,
/*.allocate_pty =*/ chan_no_allocate_pty,
/*.set_env =*/ chan_no_set_env,
/*.send_break =*/ chan_no_send_break,
/*.send_signal =*/ chan_no_send_signal,
/*.change_window_size =*/ chan_no_change_window_size,
/*.request_response =*/ chan_no_request_response,
.free = agentf_free,
.open_confirmation = chan_remotely_opened_confirmation,
.open_failed = chan_remotely_opened_failure,
.send = agentf_send,
.send_eof = agentf_send_eof,
.set_input_wanted = agentf_set_input_wanted,
.log_close_msg = agentf_log_close_msg,
.want_close = chan_default_want_close,
.rcvd_exit_status = chan_no_exit_status,
.rcvd_exit_signal = chan_no_exit_signal,
.rcvd_exit_signal_numeric = chan_no_exit_signal_numeric,
.run_shell = chan_no_run_shell,
.run_command = chan_no_run_command,
.run_subsystem = chan_no_run_subsystem,
.enable_x11_forwarding = chan_no_enable_x11_forwarding,
.enable_agent_forwarding = chan_no_enable_agent_forwarding,
.allocate_pty = chan_no_allocate_pty,
.set_env = chan_no_set_env,
.send_break = chan_no_send_break,
.send_signal = chan_no_send_signal,
.change_window_size = chan_no_change_window_size,
.request_response = chan_no_request_response,
};
Channel *agentf_new(SshChannel *c, struct callback_set *callback_set) // WINSCP
@@ -190,7 +189,7 @@ Channel *agentf_new(SshChannel *c, struct callback_set *callback_set) // WINSCP
static void agentf_free(Channel *chan)
{
pinitassert(chan->vt == &agentf_channelvt);
assert(chan->vt == &agentf_channelvt);
agentf *af = container_of(chan, agentf, chan);
if (af->pending)
@@ -202,7 +201,7 @@ static void agentf_free(Channel *chan)
static size_t agentf_send(Channel *chan, bool is_stderr,
const void *data, size_t length)
{
pinitassert(chan->vt == &agentf_channelvt);
assert(chan->vt == &agentf_channelvt);
agentf *af = container_of(chan, agentf, chan);
bufchain_add(&af->inbuffer, data, length);
agentf_try_forward(af);
@@ -220,7 +219,7 @@ static size_t agentf_send(Channel *chan, bool is_stderr,
static void agentf_send_eof(Channel *chan)
{
pinitassert(chan->vt == &agentf_channelvt);
assert(chan->vt == &agentf_channelvt);
agentf *af = container_of(chan, agentf, chan);
af->rcvd_eof = true;
@@ -238,7 +237,7 @@ static char *agentf_log_close_msg(Channel *chan)
static void agentf_set_input_wanted(Channel *chan, bool wanted)
{
pinitassert(chan->vt == &agentf_channelvt);
assert(chan->vt == &agentf_channelvt);
agentf *af = container_of(chan, agentf, chan);
af->input_wanted = wanted;

View File

@@ -26,15 +26,14 @@ static void ssh2_bare_bpp_handle_output(BinaryPacketProtocol *bpp);
static PktOut *ssh2_bare_bpp_new_pktout(int type);
static const BinaryPacketProtocolVtable ssh2_bare_bpp_vtable = {
// WINSCP
/*.free =*/ ssh2_bare_bpp_free,
/*.handle_input =*/ ssh2_bare_bpp_handle_input,
/*.handle_output =*/ ssh2_bare_bpp_handle_output,
/*.new_pktout =*/ ssh2_bare_bpp_new_pktout,
/*.queue_disconnect =*/ ssh2_bpp_queue_disconnect, /* in common.c */
.free = ssh2_bare_bpp_free,
.handle_input = ssh2_bare_bpp_handle_input,
.handle_output = ssh2_bare_bpp_handle_output,
.new_pktout = ssh2_bare_bpp_new_pktout,
.queue_disconnect = ssh2_bpp_queue_disconnect, /* in common.c */
/* packet size limit, per protocol spec in sharing.c comment */
/*.packet_size_limit =*/ 0x4000,
.packet_size_limit = 0x4000,
};
BinaryPacketProtocol *ssh2_bare_bpp_new(LogContext *logctx)

View File

@@ -50,13 +50,12 @@ static void ssh2_bpp_handle_output(BinaryPacketProtocol *bpp);
static PktOut *ssh2_bpp_new_pktout(int type);
static const BinaryPacketProtocolVtable ssh2_bpp_vtable = {
// WINSCP
/*.free =*/ ssh2_bpp_free,
/*.handle_input =*/ ssh2_bpp_handle_input,
/*.handle_output =*/ ssh2_bpp_handle_output,
/*.new_pktout =*/ ssh2_bpp_new_pktout,
/*.queue_disconnect =*/ ssh2_bpp_queue_disconnect, /* in common.c */
/*.packet_size_limit =*/ 0xFFFFFFFF, /* no special limit for this bpp */
.free = ssh2_bpp_free,
.handle_input = ssh2_bpp_handle_input,
.handle_output = ssh2_bpp_handle_output,
.new_pktout = ssh2_bpp_new_pktout,
.queue_disconnect = ssh2_bpp_queue_disconnect, /* in common.c */
.packet_size_limit = 0xFFFFFFFF, /* no special limit for this bpp */
};
BinaryPacketProtocol *ssh2_bpp_new(
@@ -902,16 +901,13 @@ static void ssh2_bpp_format_packet(struct ssh2_bpp_state *s, PktOut *pkt)
ignore_pkt = ssh2_bpp_new_pktout(SSH2_MSG_IGNORE);
put_uint32(ignore_pkt, length);
{ // WINSCP
size_t origlen = ignore_pkt->length;
size_t i; // WINSCP
for (i = 0; i < length; i++)
for (size_t i = 0; i < length; i++)
put_byte(ignore_pkt, 0); /* make space for random padding */
random_read(ignore_pkt->data + origlen, length);
ssh2_bpp_format_packet_inner(s, ignore_pkt);
bufchain_add(s->bpp.out_raw, ignore_pkt->data, ignore_pkt->length);
ssh_free_pktout(ignore_pkt);
} // WINSCP
}
}

View File

@@ -317,28 +317,28 @@ static bool zombiechan_want_close(Channel *chan, bool sent_eof, bool rcvd_eof);
static char *zombiechan_log_close_msg(Channel *chan) { return NULL; }
static const ChannelVtable zombiechan_channelvt = {
/*.free =*/ zombiechan_free,
/*.open_confirmation =*/ zombiechan_do_nothing,
/*.open_failed =*/ zombiechan_open_failure,
/*.send =*/ zombiechan_send,
/*.send_eof =*/ zombiechan_do_nothing,
/*.set_input_wanted =*/ zombiechan_set_input_wanted,
/*.log_close_msg =*/ zombiechan_log_close_msg,
/*.want_close =*/ zombiechan_want_close,
/*.rcvd_exit_status =*/ chan_no_exit_status,
/*.rcvd_exit_signal =*/ chan_no_exit_signal,
/*.rcvd_exit_signal_numeric =*/ chan_no_exit_signal_numeric,
/*.run_shell =*/ chan_no_run_shell,
/*.run_command =*/ chan_no_run_command,
/*.run_subsystem =*/ chan_no_run_subsystem,
/*.enable_x11_forwarding =*/ chan_no_enable_x11_forwarding,
/*.enable_agent_forwarding =*/ chan_no_enable_agent_forwarding,
/*.allocate_pty =*/ chan_no_allocate_pty,
/*.set_env =*/ chan_no_set_env,
/*.send_break =*/ chan_no_send_break,
/*.send_signal =*/ chan_no_send_signal,
/*.change_window_size =*/ chan_no_change_window_size,
/*.request_response =*/ chan_no_request_response,
.free = zombiechan_free,
.open_confirmation = zombiechan_do_nothing,
.open_failed = zombiechan_open_failure,
.send = zombiechan_send,
.send_eof = zombiechan_do_nothing,
.set_input_wanted = zombiechan_set_input_wanted,
.log_close_msg = zombiechan_log_close_msg,
.want_close = zombiechan_want_close,
.rcvd_exit_status = chan_no_exit_status,
.rcvd_exit_signal = chan_no_exit_signal,
.rcvd_exit_signal_numeric = chan_no_exit_signal_numeric,
.run_shell = chan_no_run_shell,
.run_command = chan_no_run_command,
.run_subsystem = chan_no_run_subsystem,
.enable_x11_forwarding = chan_no_enable_x11_forwarding,
.enable_agent_forwarding = chan_no_enable_agent_forwarding,
.allocate_pty = chan_no_allocate_pty,
.set_env = chan_no_set_env,
.send_break = chan_no_send_break,
.send_signal = chan_no_send_signal,
.change_window_size = chan_no_change_window_size,
.request_response = chan_no_request_response,
};
Channel *zombiechan_new(void)
@@ -850,7 +850,6 @@ void ssh2_bpp_queue_disconnect(BinaryPacketProtocol *bpp,
bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
{
#pragma warn -osh
static const unsigned valid_bitmap[] = {
SSH2_BITMAP_WORD(0),
SSH2_BITMAP_WORD(1),
@@ -861,7 +860,6 @@ bool ssh2_bpp_check_unimplemented(BinaryPacketProtocol *bpp, PktIn *pktin)
SSH2_BITMAP_WORD(6),
SSH2_BITMAP_WORD(7),
};
#pragma warn +osh
if (pktin->type < 0x100 &&
!((valid_bitmap[pktin->type >> 5] >> (pktin->type & 0x1F)) & 1)) {
@@ -903,8 +901,7 @@ SeatPromptResult verify_ssh_host_key(
*/
if (conf_get_str_nthstrkey(conf, CONF_ssh_manual_hostkeys, 0)) {
if (fingerprints) {
size_t i; // WINSCP
for (i = 0; i < SSH_N_FPTYPES; i++) {
for (size_t i = 0; i < SSH_N_FPTYPES; i++) {
/*
* Each fingerprint string we've been given will have
* things like 'ssh-rsa 2048' at the front of it. Strip
@@ -914,14 +911,11 @@ SeatPromptResult verify_ssh_host_key(
const char *fingerprint = fingerprints[i];
if (!fingerprint)
continue;
{ // WINSCP
const char *p = strrchr(fingerprint, ' ');
fingerprint = p ? p+1 : fingerprint;
if (conf_get_str_str_opt(conf, CONF_ssh_manual_hostkeys,
fingerprint))
return SPR_OK;
} // WINSCP
}
}
@@ -956,7 +950,6 @@ SeatPromptResult verify_ssh_host_key(
/*
* Next, check the host key cache.
*/
{ // WINSCP
int storage_status = 1; // WINSCP check_stored_host_key(host, port, keytype, keystr);
if (storage_status == 0) /* matching key was found in the cache */
return SPR_OK;
@@ -965,7 +958,6 @@ SeatPromptResult verify_ssh_host_key(
* The key is either missing from the cache, or does not match.
* Either way, fall back to an interactive prompt from the Seat.
*/
{ // WINSCP
SeatDialogText *text = seat_dialog_text_new();
const SeatDialogPromptDescriptions *pds =
seat_prompt_descriptions(iseat.seat);
@@ -976,7 +968,6 @@ SeatPromptResult verify_ssh_host_key(
seat_dialog_text_append(
text, SDT_TITLE, "%s Security Alert", appname);
{ // WINSCP
HelpCtx helpctx;
if (key && ssh_key_alg(key)->is_certificate) {
@@ -1118,16 +1109,11 @@ SeatPromptResult verify_ssh_host_key(
fingerprints[SSH_FPTYPE_MD5]);
}
{ // WINSCP
SeatPromptResult toret = seat_confirm_ssh_host_key(
iseat, host, port, keytype, keystr, text, helpctx, callback, ctx,
fingerprints, key && ssh_key_alg(key)->is_certificate, ca_count, false); // WINSCP
seat_dialog_text_free(text);
return toret;
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
SeatPromptResult confirm_weak_crypto_primitive(
@@ -1188,13 +1174,11 @@ SeatPromptResult confirm_weak_crypto_primitive(
seat_dialog_text_append(text, SDT_PROMPT, "Continue with connection?");
{ // WINSCP
SeatPromptResult toret = seat_confirm_weak_crypto_primitive(
iseat, text, callback, ctx,
algtype, algname, wcr); // WINSCP
seat_dialog_text_free(text);
return toret;
} // WINSCP
}
SeatPromptResult confirm_weak_cached_hostkey(
@@ -1217,11 +1201,8 @@ SeatPromptResult confirm_weak_cached_hostkey(
"The server also provides the following types of host key "
"above the threshold, which we do not have stored:");
{ // WINSCP
const char **p; // WINSCP
for (p = betteralgs; *p; p++)
for (const char **p = betteralgs; *p; p++)
seat_dialog_text_append(text, SDT_DISPLAY, "%s", *p);
} // WINSCP
/* In batch mode, we print the above information and then this
* abort message, and stop. */
@@ -1234,12 +1215,10 @@ SeatPromptResult confirm_weak_cached_hostkey(
seat_dialog_text_append(text, SDT_PROMPT, "Continue with connection?");
{ // WINSCP
SeatPromptResult toret = seat_confirm_weak_cached_hostkey(
iseat, text, callback, ctx);
seat_dialog_text_free(text);
return toret;
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1301,11 +1280,10 @@ void ssh1_compute_session_id(
RSAKey *hostkey, RSAKey *servkey)
{
ssh_hash *hash = ssh_hash_new(&ssh_md5);
size_t i; // WINSCP
for (i = (mp_get_nbits(hostkey->modulus) + 7) / 8; i-- ;)
for (size_t i = (mp_get_nbits(hostkey->modulus) + 7) / 8; i-- ;)
put_byte(hash, mp_get_byte(hostkey->modulus, i));
for (i = (mp_get_nbits(servkey->modulus) + 7) / 8; i-- ;)
for (size_t i = (mp_get_nbits(servkey->modulus) + 7) / 8; i-- ;)
put_byte(hash, mp_get_byte(servkey->modulus, i));
put_data(hash, cookie, 8);
ssh_hash_final(hash, session_id);
@@ -1324,10 +1302,8 @@ void ssh_spr_close(Ssh *ssh, SeatPromptResult spr, const char *context)
ssh_user_close(ssh, "User aborted at %s", context);
} else {
assert(spr.kind == SPRK_SW_ABORT);
{ // WINSCP
char *err = spr_get_error_message(spr);
ssh_sw_abort(ssh, "%s", err);
sfree(err);
} // WINSCP
}
}

View File

@@ -104,7 +104,6 @@ static ChanopenResult chan_open_auth_agent(
* If possible, make a stream-oriented connection to the agent and
* set up an ordinary port-forwarding type channel over it.
*/
{ // WINSCP
Plug *plug;
Channel *ch = portfwd_raw_new(&s->cl, &plug, true);
Socket *skt = agent_connect(plug);
@@ -122,7 +121,6 @@ static ChanopenResult chan_open_auth_agent(
*/
CHANOPEN_RETURN_SUCCESS(agentf_new(sc, callback_set));
}
} // WINSCP
}
ChanopenResult ssh2_connection_parse_channel_open(
@@ -229,12 +227,10 @@ static void ssh2_rportfwd_globreq_response(struct ssh2_connection_state *s,
ppl_logevent("Remote port forwarding from %s refused",
rpf->log_description);
{ // WINSCP
struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
assert(realpf == rpf);
portfwdmgr_close(s->portfwdmgr, rpf->pfr);
free_rportfwd(rpf);
} // WINSCP
}
}
@@ -304,10 +300,8 @@ void ssh2_rportfwd_remove(ConnectionLayer *cl, struct ssh_rportfwd *rpf)
}
assert(s->rportfwds);
{ // WINSCP
struct ssh_rportfwd *realpf = del234(s->rportfwds, rpf);
assert(realpf == rpf);
} // WINSCP
free_rportfwd(rpf);
}

View File

@@ -24,16 +24,15 @@ static void ssh2_connection_reconfigure(PacketProtocolLayer *ppl, Conf *conf);
static unsigned int ssh2_connection_winscp_query(PacketProtocolLayer *ppl, int query);
static const PacketProtocolLayerVtable ssh2_connection_vtable = {
// WINSCP
/*.free =*/ ssh2_connection_free,
/*.process_queue =*/ ssh2_connection_process_queue,
/*.get_specials =*/ ssh2_connection_get_specials,
/*.special_cmd =*/ ssh2_connection_special_cmd,
/*.reconfigure =*/ ssh2_connection_reconfigure,
/*.queued_data_size =*/ ssh_ppl_default_queued_data_size,
/*.final_output =*/ ssh_ppl_default_final_output,
/*.name =*/ "ssh-connection",
ssh2_connection_winscp_query,
.free = ssh2_connection_free,
.process_queue = ssh2_connection_process_queue,
.get_specials = ssh2_connection_get_specials,
.special_cmd = ssh2_connection_special_cmd,
.reconfigure = ssh2_connection_reconfigure,
.queued_data_size = ssh_ppl_default_queued_data_size,
.final_output = ssh_ppl_default_final_output,
.name = "ssh-connection",
.winscp_query = ssh2_connection_winscp_query,
};
static SshChannel *ssh2_lportfwd_open(
@@ -69,32 +68,31 @@ static bool ssh2_get_wants_user_input(ConnectionLayer *cl);
static void ssh2_got_user_input(ConnectionLayer *cl);
static const ConnectionLayerVtable ssh2_connlayer_vtable = {
// WINSCP
/*.rportfwd_alloc =*/ ssh2_rportfwd_alloc,
/*.rportfwd_remove =*/ ssh2_rportfwd_remove,
/*.lportfwd_open =*/ ssh2_lportfwd_open,
/*.session_open =*/ ssh2_session_open,
/*.serverside_x11_open =*/ ssh2_serverside_x11_open,
/*.serverside_agent_open =*/ ssh2_serverside_agent_open,
/*.add_x11_display =*/ ssh2_add_x11_display,
/*.add_sharing_x11_display =*/ ssh2_add_sharing_x11_display,
/*.remove_sharing_x11_display =*/ ssh2_remove_sharing_x11_display,
/*.send_packet_from_downstream =*/ ssh2_send_packet_from_downstream,
/*.alloc_sharing_channel =*/ ssh2_alloc_sharing_channel,
/*.delete_sharing_channel =*/ ssh2_delete_sharing_channel,
/*.sharing_queue_global_request =*/ ssh2_sharing_queue_global_request,
/*.sharing_no_more_downstreams =*/ ssh2_sharing_no_more_downstreams,
/*.agent_forwarding_permitted =*/ ssh2_agent_forwarding_permitted,
/*.terminal_size =*/ ssh2_terminal_size,
/*.stdout_unthrottle =*/ ssh2_stdout_unthrottle,
/*.stdin_backlog =*/ ssh2_stdin_backlog,
/*.throttle_all_channels =*/ ssh2_throttle_all_channels,
/*.ldisc_option =*/ ssh2_ldisc_option,
/*.set_ldisc_option =*/ ssh2_set_ldisc_option,
/*.enable_x_fwd =*/ ssh2_enable_x_fwd,
/*.set_wants_user_input =*/ ssh2_set_wants_user_input,
/*.get_wants_user_input =*/ ssh2_get_wants_user_input,
/*.got_user_input =*/ ssh2_got_user_input,
.rportfwd_alloc = ssh2_rportfwd_alloc,
.rportfwd_remove = ssh2_rportfwd_remove,
.lportfwd_open = ssh2_lportfwd_open,
.session_open = ssh2_session_open,
.serverside_x11_open = ssh2_serverside_x11_open,
.serverside_agent_open = ssh2_serverside_agent_open,
.add_x11_display = ssh2_add_x11_display,
.add_sharing_x11_display = ssh2_add_sharing_x11_display,
.remove_sharing_x11_display = ssh2_remove_sharing_x11_display,
.send_packet_from_downstream = ssh2_send_packet_from_downstream,
.alloc_sharing_channel = ssh2_alloc_sharing_channel,
.delete_sharing_channel = ssh2_delete_sharing_channel,
.sharing_queue_global_request = ssh2_sharing_queue_global_request,
.sharing_no_more_downstreams = ssh2_sharing_no_more_downstreams,
.agent_forwarding_permitted = ssh2_agent_forwarding_permitted,
.terminal_size = ssh2_terminal_size,
.stdout_unthrottle = ssh2_stdout_unthrottle,
.stdin_backlog = ssh2_stdin_backlog,
.throttle_all_channels = ssh2_throttle_all_channels,
.ldisc_option = ssh2_ldisc_option,
.set_ldisc_option = ssh2_set_ldisc_option,
.enable_x_fwd = ssh2_enable_x_fwd,
.set_wants_user_input = ssh2_set_wants_user_input,
.get_wants_user_input = ssh2_get_wants_user_input,
.got_user_input = ssh2_got_user_input,
};
static char *ssh2_channel_open_failure_error_text(PktIn *pktin)
@@ -138,28 +136,27 @@ static void ssh2channel_x11_sharing_handover(
static void ssh2channel_hint_channel_is_simple(SshChannel *c);
static const SshChannelVtable ssh2channel_vtable = {
// WINSCP
/*.write =*/ ssh2channel_write,
/*.write_eof =*/ ssh2channel_write_eof,
/*.initiate_close =*/ ssh2channel_initiate_close,
/*.unthrottle =*/ ssh2channel_unthrottle,
/*.get_conf =*/ ssh2channel_get_conf,
/*.window_override_removed =*/ ssh2channel_window_override_removed,
/*.x11_sharing_handover =*/ ssh2channel_x11_sharing_handover,
/*.send_exit_status =*/ ssh2channel_send_exit_status,
/*.send_exit_signal =*/ ssh2channel_send_exit_signal,
/*.send_exit_signal_numeric =*/ ssh2channel_send_exit_signal_numeric,
/*.request_x11_forwarding =*/ ssh2channel_request_x11_forwarding,
/*.request_agent_forwarding =*/ ssh2channel_request_agent_forwarding,
/*.request_pty =*/ ssh2channel_request_pty,
/*.send_env_var =*/ ssh2channel_send_env_var,
/*.start_shell =*/ ssh2channel_start_shell,
/*.start_command =*/ ssh2channel_start_command,
/*.start_subsystem =*/ ssh2channel_start_subsystem,
/*.send_serial_break =*/ ssh2channel_send_serial_break,
/*.send_signal =*/ ssh2channel_send_signal,
/*.send_terminal_size_change =*/ ssh2channel_send_terminal_size_change,
/*.hint_channel_is_simple =*/ ssh2channel_hint_channel_is_simple,
.write = ssh2channel_write,
.write_eof = ssh2channel_write_eof,
.initiate_close = ssh2channel_initiate_close,
.unthrottle = ssh2channel_unthrottle,
.get_conf = ssh2channel_get_conf,
.window_override_removed = ssh2channel_window_override_removed,
.x11_sharing_handover = ssh2channel_x11_sharing_handover,
.send_exit_status = ssh2channel_send_exit_status,
.send_exit_signal = ssh2channel_send_exit_signal,
.send_exit_signal_numeric = ssh2channel_send_exit_signal_numeric,
.request_x11_forwarding = ssh2channel_request_x11_forwarding,
.request_agent_forwarding = ssh2channel_request_agent_forwarding,
.request_pty = ssh2channel_request_pty,
.send_env_var = ssh2channel_send_env_var,
.start_shell = ssh2channel_start_shell,
.start_command = ssh2channel_start_command,
.start_subsystem = ssh2channel_start_subsystem,
.send_serial_break = ssh2channel_send_serial_break,
.send_signal = ssh2channel_send_signal,
.send_terminal_size_change = ssh2channel_send_terminal_size_change,
.hint_channel_is_simple = ssh2channel_hint_channel_is_simple,
};
static void ssh2_channel_check_close(struct ssh2_channel *c);
@@ -539,11 +536,9 @@ static bool ssh2_connection_filter_queue(struct ssh2_connection_state *s)
case SSH2_MSG_CHANNEL_OPEN_FAILURE: {
assert(c->halfopen);
{ // WINSCP
char *err = ssh2_channel_open_failure_error_text(pktin);
chan_open_failed(c->chan, err);
sfree(err);
} // WINSCP
del234(s->channels, c);
ssh2_channel_free(c);

View File

@@ -43,21 +43,12 @@ static Ssh_gss_stat ssh_gssapi_acquire_cred(struct ssh_gss_library *lib,
time_t *expiry)
{
struct gssapi_functions *gss = &lib->u.gssapi;
#ifdef MPEXT
gss_OID_set_desc k5only;
#else
gss_OID_set_desc k5only = { 1, GSS_MECH_KRB5 };
#endif
gss_cred_id_t cred;
OM_uint32 dummy;
OM_uint32 time_rec;
gssapi_ssh_gss_ctx *gssctx = snew(gssapi_ssh_gss_ctx);
#ifdef MPEXT
k5only.count = 1;
k5only.elements = GSS_MECH_KRB5;
#endif
gssctx->ctx = GSS_C_NO_CONTEXT;
gssctx->expiry = 0;

View File

@@ -158,7 +158,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
return;
}
}
{ // WINSCP
mp_int *K = dh_find_K(s->dh_ctx, s->f);
put_mp_ssh2(s->kex_shared_secret, K);
mp_free(K);
@@ -187,7 +186,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
mp_free(s->g); s->g = NULL;
mp_free(s->p); s->p = NULL;
}
} // WINSCP
} else if (s->kex_alg->main_type == KEXTYPE_ECDH) {
char *desc = ecdh_keyalg_description(s->kex_alg);
ppl_logevent("Doing %s, using hash %s", desc,
@@ -232,7 +230,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
{
ptrlen keydata = get_string(pktin);
put_stringpl(s->exhash, keydata);
{ // WINSCP
bool ok = ecdh_key_getkey(s->ecdh_key, keydata,
BinarySink_UPCAST(s->kex_shared_secret));
if (!get_err(pktin) && !ok) {
@@ -241,7 +238,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
*aborted = true;
return;
}
} // WINSCP
}
s->sigdata = get_string(pktin);
@@ -288,12 +284,10 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
if (s->kex_alg->main_type == KEXTYPE_GSS_ECDH) {
s->ecdh_key = ecdh_key_new(s->kex_alg, false);
{ // WINSCP
char *desc = ecdh_keyalg_description(s->kex_alg);
ppl_logevent("Doing GSSAPI (with Kerberos V5) %s with hash %s",
desc, ssh_hash_alg(s->exhash)->text_name);
sfree(desc);
} // WINSCP
} else if (dh_is_gex(s->kex_alg)) {
/*
* Work out how big a DH group we will need to allow that
@@ -524,11 +518,9 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
*aborted = true;
return;
}
{ // WINSCP
mp_int *K = dh_find_K(s->dh_ctx, s->f);
put_mp_ssh2(s->kex_shared_secret, K);
mp_free(K);
} // WINSCP
}
/* We assume everything from now on will be quick, and it might
@@ -635,11 +627,9 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
return;
}
{ // WINSCP
int nbits = klen - (2*s->kex_alg->hash->hlen*8 + 49);
assert(nbits > 0);
{ // WINSCP
strbuf *buf, *outstr;
mp_int *tmp = mp_random_bits(nbits - 1);
@@ -675,8 +665,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
put_stringsb(s->exhash, outstr); /* frees outstr */
strbuf_free(buf);
} // WINSCP
} // WINSCP
}
ssh_rsakex_freekey(s->rsa_kex_key);
@@ -846,7 +834,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
* triggered on purpose to populate the transient cache.
*/
assert(s->hkey); /* only KEXTYPE_GSS* lets this be null */
{ // WINSCP
char *fingerprint = ssh2_double_fingerprint(
s->hkey, SSH_FPTYPE_DEFAULT);
@@ -867,7 +854,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
}
sfree(fingerprint);
} // WINSCP
}
} else
#endif /* NO_GSSAPI */
@@ -909,11 +895,7 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
}
}
{ // WINSCP
ssh2_userkey uk; // WINSCP
uk.key = s->hkey; // WINSCP
uk.comment = NULL; // WINSCP
{ // WINSCP
ssh2_userkey uk = { .key = s->hkey, .comment = NULL };
char **fingerprints = ssh2_all_fingerprints(s->hkey);
FingerprintType fptype_default =
@@ -936,7 +918,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
ppl_logevent("%s", base_fp);
sfree(base_fp);
{ // WINSCP
strbuf *id_string = strbuf_new();
#ifndef WINSCP
StripCtrlChars *id_string_scc = stripctrl_new(
@@ -950,14 +931,9 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
ppl_logevent("Certificate ID string is \"%s\"", id_string->s);
strbuf_free(id_string);
{ // WINSCP
strbuf *ca_pub = strbuf_new();
ssh_key_ca_public_blob(s->hkey, BinarySink_UPCAST(ca_pub));
{ // WINSCP
host_ca hca_search;
smemclr(&hca_search, sizeof(hca_search));
hca_search.ca_public_key = ca_pub;
{ // WINSCP
host_ca hca_search = { .ca_public_key = ca_pub };
host_ca *hca_found = find234(s->host_cas, &hca_search, NULL);
char *ca_fp = ssh2_fingerprint_blob(ptrlen_from_strbuf(ca_pub),
@@ -968,7 +944,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
strbuf_free(ca_pub);
{ // WINSCP
strbuf *error = strbuf_new();
bool cert_ok = false;
@@ -1000,15 +975,9 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
strbuf_free(error);
/* now fall through into normal host key checking */
}
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
} // WINSCP
}
{
{ // WINSCP
char *keydisp = ssh2_pubkey_openssh_str(&uk);
int ca_count = ssh_key_alg(s->hkey)->is_certificate ?
@@ -1021,7 +990,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
ssh2_free_all_fingerprints(fingerprints);
sfree(keydisp);
} // WINSCP
#ifdef FUZZING
s->spr = SPR_OK;
#endif
@@ -1053,13 +1021,10 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
*/
strbuf_clear(s->hostkeyblob);
ssh_key_public_blob(s->hkey, BinarySink_UPCAST(s->hostkeyblob));
} // WINSCP
} // WINSCP
} else if (s->cross_certifying) {
assert(s->hkey);
assert(ssh_key_alg(s->hkey) == s->cross_certifying);
{ // WINSCP
char *fingerprint = ssh2_double_fingerprint(
s->hkey, SSH_FPTYPE_DEFAULT);
ppl_logevent("Storing additional host key for this host:");
@@ -1074,7 +1039,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
*/
strbuf_clear(s->hostkeyblob);
ssh_key_public_blob(s->hkey, BinarySink_UPCAST(s->hostkeyblob));
} // WINSCP
} else {
/*
* In a rekey, we never present an interactive host key
@@ -1084,7 +1048,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
*/
strbuf *thisblob = strbuf_new();
ssh_key_public_blob(s->hkey, BinarySink_UPCAST(thisblob));
{ // WINSCP
bool match = ptrlen_eq_ptrlen(ptrlen_from_strbuf(thisblob),
ptrlen_from_strbuf(s->hostkeyblob));
strbuf_free(thisblob);
@@ -1096,7 +1059,6 @@ void ssh2kex_coroutine(struct ssh2_transport_state *s, bool *aborted)
return;
#endif
}
} // WINSCP
}
sfree(s->keystr);

View File

@@ -27,29 +27,28 @@ static bool mainchan_rcvd_exit_signal_numeric(
static void mainchan_request_response(Channel *chan, bool success);
static const ChannelVtable mainchan_channelvt = {
// WINSCP
/*.free =*/ mainchan_free,
/*.open_confirmation =*/ mainchan_open_confirmation,
/*.open_failed =*/ mainchan_open_failure,
/*.send =*/ mainchan_send,
/*.send_eof =*/ mainchan_send_eof,
/*.set_input_wanted =*/ mainchan_set_input_wanted,
/*.log_close_msg =*/ mainchan_log_close_msg,
/*.want_close =*/ chan_default_want_close,
/*.rcvd_exit_status =*/ mainchan_rcvd_exit_status,
/*.rcvd_exit_signal =*/ mainchan_rcvd_exit_signal,
/*.rcvd_exit_signal_numeric =*/ mainchan_rcvd_exit_signal_numeric,
/*.run_shell =*/ chan_no_run_shell,
/*.run_command =*/ chan_no_run_command,
/*.run_subsystem =*/ chan_no_run_subsystem,
/*.enable_x11_forwarding =*/ chan_no_enable_x11_forwarding,
/*.enable_agent_forwarding =*/ chan_no_enable_agent_forwarding,
/*.allocate_pty =*/ chan_no_allocate_pty,
/*.set_env =*/ chan_no_set_env,
/*.send_break =*/ chan_no_send_break,
/*.send_signal =*/ chan_no_send_signal,
/*.change_window_size =*/ chan_no_change_window_size,
/*.request_response =*/ mainchan_request_response,
.free = mainchan_free,
.open_confirmation = mainchan_open_confirmation,
.open_failed = mainchan_open_failure,
.send = mainchan_send,
.send_eof = mainchan_send_eof,
.set_input_wanted = mainchan_set_input_wanted,
.log_close_msg = mainchan_log_close_msg,
.want_close = chan_default_want_close,
.rcvd_exit_status = mainchan_rcvd_exit_status,
.rcvd_exit_signal = mainchan_rcvd_exit_signal,
.rcvd_exit_signal_numeric = mainchan_rcvd_exit_signal_numeric,
.run_shell = chan_no_run_shell,
.run_command = chan_no_run_command,
.run_subsystem = chan_no_run_subsystem,
.enable_x11_forwarding = chan_no_enable_x11_forwarding,
.enable_agent_forwarding = chan_no_enable_agent_forwarding,
.allocate_pty = chan_no_allocate_pty,
.set_env = chan_no_set_env,
.send_break = chan_no_send_break,
.send_signal = chan_no_send_signal,
.change_window_size = chan_no_change_window_size,
.request_response = mainchan_request_response,
};
typedef enum MainChanType {
@@ -114,7 +113,7 @@ mainchan *mainchan_new(
static void mainchan_free(Channel *chan)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
conf_free(mc->conf);
sfree(mc);
@@ -227,7 +226,7 @@ static void mainchan_try_fallback_command(mainchan *mc)
static void mainchan_request_response(Channel *chan, bool success)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
@@ -347,7 +346,7 @@ static void mainchan_ready(mainchan *mc)
static void mainchan_open_failure(Channel *chan, const char *errtext)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
ssh_sw_abort_deferred(mc->ppl->ssh,
@@ -357,14 +356,14 @@ static void mainchan_open_failure(Channel *chan, const char *errtext)
static size_t mainchan_send(Channel *chan, bool is_stderr,
const void *data, size_t length)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
return seat_output(mc->ppl->seat, is_stderr, data, length);
}
static void mainchan_send_eof(Channel *chan)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
@@ -385,7 +384,7 @@ static void mainchan_send_eof(Channel *chan)
static void mainchan_set_input_wanted(Channel *chan, bool wanted)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
/*
@@ -404,7 +403,7 @@ static char *mainchan_log_close_msg(Channel *chan)
static bool mainchan_rcvd_exit_status(Channel *chan, int status)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
PacketProtocolLayer *ppl = mc->ppl; /* for ppl_logevent */
@@ -429,7 +428,7 @@ static void mainchan_log_exit_signal_common(
static bool mainchan_rcvd_exit_signal(
Channel *chan, ptrlen signame, bool core_dumped, ptrlen msg)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
int exitcode;
char *signame_str;
@@ -464,7 +463,7 @@ static bool mainchan_rcvd_exit_signal(
static bool mainchan_rcvd_exit_signal_numeric(
Channel *chan, int signum, bool core_dumped, ptrlen msg)
{
pinitassert(chan->vt == &mainchan_channelvt);
assert(chan->vt == &mainchan_channelvt);
mainchan *mc = container_of(chan, mainchan, chan);
char *signum_str;

View File

@@ -303,9 +303,7 @@ static void pfd_receive(Plug *plug, int urgent, const char *data, size_t len)
/* Search the method list for AUTH_NONE, which is the
* only one this client code can speak */
{ // WINSCP
size_t i;
for (i = 0; i < methods.len; i++) {
for (size_t i = 0; i < methods.len; i++) {
unsigned char this_method =
((const unsigned char *)methods.ptr)[i];
if (this_method == SOCKS5_AUTH_NONE) {
@@ -333,7 +331,6 @@ static void pfd_receive(Plug *plug, int urgent, const char *data, size_t len)
pf->socks_state = SOCKS_5_CONNECT;
pf->socksbuf_consumed = src->pos;
break;
} // WINSCP
case SOCKS_5_CONNECT:
/* SOCKS 5 connect message */
@@ -422,12 +419,10 @@ static void pfd_sent(Plug *plug, size_t bufsize)
}
static const PlugVtable PortForwarding_plugvt = {
// WINSCP
/*.log =*/ nullplug_log,
/*.closing =*/ pfd_closing,
/*.receive =*/ pfd_receive,
/*.sent =*/ pfd_sent,
NULL,
.log = nullplug_log,
.closing = pfd_closing,
.receive = pfd_receive,
.sent = pfd_sent,
};
static void pfd_chan_free(Channel *chan);
@@ -440,29 +435,28 @@ static void pfd_set_input_wanted(Channel *chan, bool wanted);
static char *pfd_log_close_msg(Channel *chan);
static const ChannelVtable PortForwarding_channelvt = {
// WINSCP
/*.free =*/ pfd_chan_free,
/*.open_confirmation =*/ pfd_open_confirmation,
/*.open_failed =*/ pfd_open_failure,
/*.send =*/ pfd_send,
/*.send_eof =*/ pfd_send_eof,
/*.set_input_wanted =*/ pfd_set_input_wanted,
/*.log_close_msg =*/ pfd_log_close_msg,
/*.want_close =*/ chan_default_want_close,
/*.rcvd_exit_status =*/ chan_no_exit_status,
/*.rcvd_exit_signal =*/ chan_no_exit_signal,
/*.rcvd_exit_signal_numeric =*/ chan_no_exit_signal_numeric,
/*.run_shell =*/ chan_no_run_shell,
/*.run_command =*/ chan_no_run_command,
/*.run_subsystem =*/ chan_no_run_subsystem,
/*.enable_x11_forwarding =*/ chan_no_enable_x11_forwarding,
/*.enable_agent_forwarding =*/ chan_no_enable_agent_forwarding,
/*.allocate_pty =*/ chan_no_allocate_pty,
/*.set_env =*/ chan_no_set_env,
/*.send_break =*/ chan_no_send_break,
/*.send_signal =*/ chan_no_send_signal,
/*.change_window_size =*/ chan_no_change_window_size,
/*.request_response =*/ chan_no_request_response,
.free = pfd_chan_free,
.open_confirmation = pfd_open_confirmation,
.open_failed = pfd_open_failure,
.send = pfd_send,
.send_eof = pfd_send_eof,
.set_input_wanted = pfd_set_input_wanted,
.log_close_msg = pfd_log_close_msg,
.want_close = chan_default_want_close,
.rcvd_exit_status = chan_no_exit_status,
.rcvd_exit_signal = chan_no_exit_signal,
.rcvd_exit_signal_numeric = chan_no_exit_signal_numeric,
.run_shell = chan_no_run_shell,
.run_command = chan_no_run_command,
.run_subsystem = chan_no_run_subsystem,
.enable_x11_forwarding = chan_no_enable_x11_forwarding,
.enable_agent_forwarding = chan_no_enable_agent_forwarding,
.allocate_pty = chan_no_allocate_pty,
.set_env = chan_no_set_env,
.send_break = chan_no_send_break,
.send_signal = chan_no_send_signal,
.change_window_size = chan_no_change_window_size,
.request_response = chan_no_request_response,
};
Channel *portfwd_raw_new(ConnectionLayer *cl, Plug **plug, bool start_ready)
@@ -548,12 +542,9 @@ static int pfl_accepting(Plug *p, accept_fn_t constructor, accept_ctx_t ctx)
}
static const PlugVtable PortListener_plugvt = {
// WINSCP
/*.log =*/ nullplug_log,
/*.closing =*/ pfl_closing,
NULL,
NULL,
/*.accepting =*/ pfl_accepting,
.log = nullplug_log,
.closing = pfl_closing,
.accepting = pfl_accepting,
};
/*
@@ -627,7 +618,7 @@ static void pfl_terminate(struct PortListener *pl)
static void pfd_set_input_wanted(Channel *chan, bool wanted)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
pf->input_wanted = wanted;
sk_set_frozen(pf->s, !pf->input_wanted);
@@ -635,7 +626,7 @@ static void pfd_set_input_wanted(Channel *chan, bool wanted)
static void pfd_chan_free(Channel *chan)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
pfd_close(pf);
}
@@ -646,21 +637,21 @@ static void pfd_chan_free(Channel *chan)
static size_t pfd_send(
Channel *chan, bool is_stderr, const void *data, size_t len)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
return sk_write(pf->s, data, len);
}
static void pfd_send_eof(Channel *chan)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
sk_write_eof(pf->s);
}
static void pfd_open_confirmation(Channel *chan)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
pf->ready = true;
@@ -676,7 +667,7 @@ static void pfd_open_confirmation(Channel *chan)
static void pfd_open_failure(Channel *chan, const char *errtext)
{
pinitassert(chan->vt == &PortForwarding_channelvt);
assert(chan->vt == &PortForwarding_channelvt);
PortForwarding *pf = container_of(chan, PortForwarding, chan);
logeventf(pf->cl->logctx,
@@ -890,7 +881,6 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf)
address_family == '6' ? ADDRTYPE_IPV6 :
ADDRTYPE_UNSPEC);
{ // WINSCP
PortFwdRecord *existing = add234(mgr->forwardings, pfr);
if (existing != pfr) {
if (existing->status == DESTROY) {
@@ -910,7 +900,6 @@ void portfwdmgr_config(PortFwdManager *mgr, Conf *conf)
} else {
pfr->status = CREATE;
}
} // WINSCP
} else {
sfree(saddr);
sfree(host);
@@ -1070,7 +1059,6 @@ bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
pfr->remote = NULL;
pfr->addressfamily = ADDRTYPE_UNSPEC;
{ // WINSCP
PortFwdRecord *existing = add234(mgr->forwardings, pfr);
if (existing != pfr) {
/*
@@ -1079,9 +1067,7 @@ bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
pfr_free(pfr);
return false;
}
} // WINSCP
{ // WINSCP
char *err = pfl_listen(keyhost, keyport, host, port,
mgr->cl, conf, &pfr->local, pfr->addressfamily);
logeventf(mgr->cl->logctx,
@@ -1094,7 +1080,6 @@ bool portfwdmgr_listen(PortFwdManager *mgr, const char *host, int port,
pfr_free(pfr);
return false;
}
} // WINSCP
return true;
}
@@ -1113,7 +1098,6 @@ bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
pfr_key.remote = NULL;
pfr_key.addressfamily = ADDRTYPE_UNSPEC;
{ // WINSCP
PortFwdRecord *pfr = del234(mgr->forwardings, &pfr_key);
if (!pfr)
@@ -1122,7 +1106,6 @@ bool portfwdmgr_unlisten(PortFwdManager *mgr, const char *host, int port)
logeventf(mgr->cl->logctx, "Closing listening port %s:%d", host, port);
pfr_free(pfr);
} // WINSCP
return true;
}

View File

@@ -1795,11 +1795,9 @@ static void share_receive(Plug *plug, int urgent, const char *data, size_t len)
}
if (cs->recvlen > 0 && cs->recvbuf[cs->recvlen-1] == '\015')
cs->recvlen--; /* trim off \r before \n */
{ // WINSCP
ptrlen verstring = make_ptrlen(cs->recvbuf, cs->recvlen);
log_downstream(cs, "Downstream version string: %.*s",
PTRLEN_PRINTF(verstring));
} // WINSCP
cs->got_verstring = true;
/*
@@ -1904,12 +1902,10 @@ void share_activate(ssh_sharing_state *sharestate,
}
static const PlugVtable ssh_sharing_conn_plugvt = {
// WINSCP
/*.log =*/ nullplug_log,
/*.closing =*/ share_closing,
/*.receive =*/ share_receive,
/*.sent =*/ share_sent,
NULL, // WINSCP
.closing = share_closing,
.receive = share_receive,
.sent = share_sent,
.log = nullplug_log,
};
static int share_listen_accepting(Plug *plug,
@@ -2049,11 +2045,9 @@ bool ssh_share_test_for_upstream(const char *host, int port, Conf *conf)
}
static const PlugVtable ssh_sharing_listen_plugvt = {
// WINSCP
/*.log =*/ nullplug_log,
/*.closing =*/ share_listen_closing,
NULL, NULL, // WINSCP
/*.accepting =*/ share_listen_accepting,
.closing = share_listen_closing,
.accepting = share_listen_accepting,
.log = nullplug_log,
};
void ssh_connshare_provide_connlayer(ssh_sharing_state *sharestate,

View File

@@ -338,7 +338,6 @@ void ssh_check_frozen(Ssh *ssh)
if (!ssh->s)
return;
{ // WINSCP
bool prev_frozen = ssh->socket_frozen;
ssh->socket_frozen = (ssh->logically_frozen ||
bufchain_size(&ssh->in_raw) > SSH_MAX_BACKLOG);
@@ -350,7 +349,6 @@ void ssh_check_frozen(Ssh *ssh)
*/
queue_idempotent_callback(&ssh->bpp->ic_in_raw);
}
} // WINSCP
}
void ssh_conn_processed_data(Ssh *ssh)
@@ -717,25 +715,19 @@ static char *ssh_close_warn_text(Backend *be)
Ssh *ssh = container_of(be, Ssh, backend);
if (!ssh->connshare)
return NULL;
{ // WINSCP
int ndowns = share_ndownstreams(ssh->connshare);
if (ndowns == 0)
return NULL;
{ // WINSCP
char *msg = dupprintf("This will also close %d downstream connection%s.",
ndowns, ndowns==1 ? "" : "s");
return msg;
} // WINSCP
} // WINSCP
}
static const PlugVtable Ssh_plugvt = {
// WINSCP
/*.log =*/ ssh_socket_log,
/*.closing =*/ ssh_closing,
/*.receive =*/ ssh_receive,
/*.sent =*/ ssh_sent,
// NULL
.log = ssh_socket_log,
.closing = ssh_closing,
.receive = ssh_receive,
.sent = ssh_sent,
};
static char *ssh_description(Interactor *itr)
@@ -763,11 +755,10 @@ static void ssh_set_seat(Interactor *itr, Seat *seat)
}
static const InteractorVtable Ssh_interactorvt = {
// WINSCP
/*.description =*/ ssh_description,
/*.logpolicy =*/ ssh_logpolicy,
/*.get_seat =*/ ssh_get_seat,
/*.set_seat =*/ ssh_set_seat,
.description = ssh_description,
.logpolicy = ssh_logpolicy,
.get_seat = ssh_get_seat,
.set_seat = ssh_set_seat,
};
/*
@@ -938,10 +929,7 @@ bool ssh_is_bare(Ssh *ssh)
* because it might be called early due to plink -shareexists */
static void dummy_sharing_no_more_downstreams(ConnectionLayer *cl) {}
static const ConnectionLayerVtable dummy_connlayer_vtable = {
// WINSCP
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/*.sharing_no_more_downstreams =*/ dummy_sharing_no_more_downstreams,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
.sharing_no_more_downstreams = dummy_sharing_no_more_downstreams,
};
/*
@@ -987,7 +975,6 @@ static char *ssh_init(const BackendVtable *vt, Seat *seat,
ssh->cl_dummy.vt = &dummy_connlayer_vtable;
ssh->cl_dummy.logctx = ssh->logctx = logctx;
{ // WINSCP
char *loghost;
ssh_hostport_setup(host, port, ssh->conf,
@@ -997,7 +984,6 @@ static char *ssh_init(const BackendVtable *vt, Seat *seat,
random_ref(); /* do this now - may be needed by sharing setup code */
ssh->need_random_unref = true;
{ // WINSCP
char *conn_err = connect_to_host(
ssh, host, port, loghost, realhost, nodelay, keepalive);
if (conn_err) {
@@ -1011,8 +997,6 @@ static char *ssh_init(const BackendVtable *vt, Seat *seat,
}
return NULL;
} // WINSCP
} // WINSCP
}
static void ssh_free(Backend *be)
@@ -1300,59 +1284,54 @@ void ssh_got_fallback_cmd(Ssh *ssh)
}
const BackendVtable ssh_backend = {
// WINSCP
/*.init =*/ ssh_init,
/*.free =*/ ssh_free,
/*.reconfig =*/ ssh_reconfig,
/*.send =*/ ssh_send,
/*.sendbuffer =*/ ssh_sendbuffer,
/*.size =*/ ssh_size,
/*.special =*/ ssh_special,
/*.get_specials =*/ ssh_get_specials,
/*.connected =*/ ssh_connected,
/*.exitcode =*/ ssh_return_exitcode,
/*.sendok =*/ ssh_sendok,
/*.ldisc_option_state =*/ ssh_ldisc,
/*.provide_ldisc =*/ ssh_provide_ldisc,
/*.unthrottle =*/ ssh_unthrottle,
/*.cfg_info =*/ ssh_cfg_info,
/*.test_for_upstream =*/ ssh_test_for_upstream,
/*.close_warn_text =*/ ssh_close_warn_text,
/*.id =*/ "ssh",
/*.displayname_tc =*/ "SSH",
/*.displayname_lc =*/ "SSH", /* proper name, so capitalise it anyway */
/*.protocol =*/ PROT_SSH,
/*.default_port =*/ 22,
/*.flags =*/ BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
0, 0, // WINSCP
.init = ssh_init,
.free = ssh_free,
.reconfig = ssh_reconfig,
.send = ssh_send,
.sendbuffer = ssh_sendbuffer,
.size = ssh_size,
.special = ssh_special,
.get_specials = ssh_get_specials,
.connected = ssh_connected,
.exitcode = ssh_return_exitcode,
.sendok = ssh_sendok,
.ldisc_option_state = ssh_ldisc,
.provide_ldisc = ssh_provide_ldisc,
.unthrottle = ssh_unthrottle,
.cfg_info = ssh_cfg_info,
.test_for_upstream = ssh_test_for_upstream,
.close_warn_text = ssh_close_warn_text,
.id = "ssh",
.displayname_tc = "SSH",
.displayname_lc = "SSH", /* proper name, so capitalise it anyway */
.protocol = PROT_SSH,
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
.default_port = 22,
};
const BackendVtable sshconn_backend = {
// WINSCP
/*.init =*/ ssh_init,
/*.free =*/ ssh_free,
/*.reconfig =*/ ssh_reconfig,
/*.send =*/ ssh_send,
/*.sendbuffer =*/ ssh_sendbuffer,
/*.size =*/ ssh_size,
/*.special =*/ ssh_special,
/*.get_specials =*/ ssh_get_specials,
/*.connected =*/ ssh_connected,
/*.exitcode =*/ ssh_return_exitcode,
/*.sendok =*/ ssh_sendok,
/*.ldisc_option_state =*/ ssh_ldisc,
/*.provide_ldisc =*/ ssh_provide_ldisc,
/*.unthrottle =*/ ssh_unthrottle,
/*.cfg_info =*/ ssh_cfg_info,
/*.test_for_upstream =*/ ssh_test_for_upstream,
/*.close_warn_text =*/ ssh_close_warn_text,
/*.id =*/ "ssh-connection",
/*.displayname_tc =*/ "Bare ssh-connection",
/*.displayname_lc =*/ "bare ssh-connection",
/*.protocol =*/ PROT_SSHCONN,
0, // WINSCP
/*.flags =*/ BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
0, 0, // WINSCP
.init = ssh_init,
.free = ssh_free,
.reconfig = ssh_reconfig,
.send = ssh_send,
.sendbuffer = ssh_sendbuffer,
.size = ssh_size,
.special = ssh_special,
.get_specials = ssh_get_specials,
.connected = ssh_connected,
.exitcode = ssh_return_exitcode,
.sendok = ssh_sendok,
.ldisc_option_state = ssh_ldisc,
.provide_ldisc = ssh_provide_ldisc,
.unthrottle = ssh_unthrottle,
.cfg_info = ssh_cfg_info,
.test_for_upstream = ssh_test_for_upstream,
.close_warn_text = ssh_close_warn_text,
.id = "ssh-connection",
.displayname_tc = "Bare ssh-connection",
.displayname_lc = "bare ssh-connection",
.protocol = PROT_SSHCONN,
.flags = BACKEND_SUPPORTS_NC_HOST | BACKEND_NOTIFIES_SESSION_START,
};
#ifdef MPEXT

View File

@@ -68,16 +68,15 @@ static bool ssh_decomp_none_block(ssh_decompressor *handle,
return false;
}
static const ssh_compression_alg ssh_comp_none = {
// WINSCP
/*.name =*/ "none",
/*.delayed_name =*/ NULL,
/*.compress_new =*/ ssh_comp_none_init,
/*.compress_free =*/ ssh_comp_none_cleanup,
/*.compress =*/ ssh_comp_none_block,
/*.decompress_new =*/ ssh_decomp_none_init,
/*.decompress_free =*/ ssh_decomp_none_cleanup,
/*.decompress =*/ ssh_decomp_none_block,
/*.text_name =*/ NULL,
.name = "none",
.delayed_name = NULL,
.compress_new = ssh_comp_none_init,
.compress_free = ssh_comp_none_cleanup,
.compress = ssh_comp_none_block,
.decompress_new = ssh_decomp_none_init,
.decompress_free = ssh_decomp_none_cleanup,
.decompress = ssh_decomp_none_block,
.text_name = NULL,
};
const static ssh_compression_alg *const compressions[] = {
&ssh_zlib, &ssh_comp_none
@@ -102,16 +101,15 @@ static bool try_to_avoid_terrapin(const struct ssh2_transport_state *s);
static unsigned int ssh2_transport_winscp_query(PacketProtocolLayer *ppl, int query);
static const PacketProtocolLayerVtable ssh2_transport_vtable = {
// WINSCP
/*.free =*/ ssh2_transport_free,
/*.process_queue =*/ ssh2_transport_process_queue,
/*.get_specials =*/ ssh2_transport_get_specials,
/*.special_cmd =*/ ssh2_transport_special_cmd,
/*.reconfigure =*/ ssh2_transport_reconfigure,
/*.queued_data_size =*/ ssh2_transport_queued_data_size,
/*.final_output =*/ ssh2_transport_final_output,
/*.name =*/ NULL, /* no protocol name for this layer */
ssh2_transport_winscp_query,
.free = ssh2_transport_free,
.process_queue = ssh2_transport_process_queue,
.get_specials = ssh2_transport_get_specials,
.special_cmd = ssh2_transport_special_cmd,
.reconfigure = ssh2_transport_reconfigure,
.queued_data_size = ssh2_transport_queued_data_size,
.final_output = ssh2_transport_final_output,
.name = NULL, /* no protocol name for this layer */
.winscp_query = ssh2_transport_winscp_query,
};
#ifndef NO_GSSAPI
@@ -248,9 +246,7 @@ static void ssh2_transport_free(PacketProtocolLayer *ppl)
ssh_key_free(s->hkey);
s->hkey = NULL;
}
{ // WINSCP
size_t i;
for (i = 0; i < NKEXLIST; i++)
for (size_t i = 0; i < NKEXLIST; i++)
sfree(s->kexlists[i].algs);
if (s->f) mp_free(s->f);
if (s->p) mp_free(s->p);
@@ -276,7 +272,6 @@ static void ssh2_transport_free(PacketProtocolLayer *ppl)
expire_timer_context(s);
sfree(s);
} // WINSCP
}
/*
@@ -348,17 +343,14 @@ static void ssh2_mkkey(
static struct kexinit_algorithm *ssh2_kexinit_addalg_pl(
struct kexinit_algorithm_list *list, ptrlen name)
{
size_t i; // WINSCP
for (i = 0; i < list->nalgs; i++)
for (size_t i = 0; i < list->nalgs; i++)
if (ptrlen_eq_ptrlen(list->algs[i].name, name))
return &list->algs[i];
sgrowarray(list->algs, list->algsize, list->nalgs);
{ // WINSCP
struct kexinit_algorithm *entry = &list->algs[list->nalgs++];
entry->name = name;
return entry;
} // WINSCP
}
static struct kexinit_algorithm *ssh2_kexinit_addalg(
@@ -443,8 +435,7 @@ bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)
* the session before the BPP aborts it anyway.
*/
uint32_t nexts = get_uint32(pktin);
uint32_t i; // WINSCP
for (i = 0; i < nexts && !get_err(pktin); i++) {
for (uint32_t i = 0; i < nexts && !get_err(pktin); i++) {
ptrlen extname = get_string(pktin);
ptrlen extvalue = get_string(pktin);
if (ptrlen_eq_string(extname, "server-sig-algs")) {
@@ -736,15 +727,12 @@ static void ssh2_write_kexinit_lists(
alg->u.hk.hkflags = 0;
alg->u.hk.warn = false;
{ // WINSCP
uint32_t supported_flags = ssh_keyalg_supported_flags(keyalg);
static const uint32_t try_flags[] = {
SSH_AGENT_RSA_SHA2_256,
SSH_AGENT_RSA_SHA2_512,
};
{ // WINSCP
size_t i;
for (i = 0; i < lenof(try_flags); i++) {
for (size_t i = 0; i < lenof(try_flags); i++) {
if (try_flags[i] & ~supported_flags)
continue; /* these flags not supported */
@@ -756,8 +744,6 @@ static void ssh2_write_kexinit_lists(
alg->u.hk.hkflags = try_flags[i];
alg->u.hk.warn = false;
}
} // WINSCP
} // WINSCP
}
} else if (first_time) {
/*
@@ -1031,8 +1017,7 @@ struct server_hostkeys {
static bool kexinit_keyword_found(ptrlen list, ptrlen keyword)
{
ptrlen word; // WINSCP
for (; get_commasep_word(&list, &word) ;)
for (ptrlen word; get_commasep_word(&list, &word) ;)
if (ptrlen_eq_ptrlen(word, keyword))
return true;
return false;
@@ -1088,7 +1073,7 @@ static ScanKexinitsResult ssh2_scan_kexinits(
slists[i] = get_string(server);
if (get_err(client) || get_err(server)) {
ScanKexinitsResult skr = {
/*.success =*/ false, /*.error =*/ SKR_INCOMPLETE,
.success = false, .error = SKR_INCOMPLETE,
};
return skr;
}
@@ -1138,9 +1123,10 @@ static ScanKexinitsResult ssh2_scan_kexinits(
* produce a reasonably useful message instead of an
* assertion failure.
*/
ScanKexinitsResult skr;
skr.success = false, skr.error = SKR_UNKNOWN_ID,
skr.kind = kexlist_descr[i], skr.desc = found;
ScanKexinitsResult skr = {
.success = false, .error = SKR_UNKNOWN_ID,
.kind = kexlist_descr[i], .desc = found,
};
return skr;
}
@@ -1196,9 +1182,10 @@ static ScanKexinitsResult ssh2_scan_kexinits(
/*
* Otherwise, any match failure _is_ a fatal error.
*/
ScanKexinitsResult skr;
skr.success = false, skr.error = SKR_NO_AGREEMENT,
skr.kind = kexlist_descr[i], skr.desc = slists[i];
ScanKexinitsResult skr = {
.success = false, .error = SKR_NO_AGREEMENT,
.kind = kexlist_descr[i], .desc = slists[i],
};
return skr;
}
@@ -1283,10 +1270,8 @@ static ScanKexinitsResult ssh2_scan_kexinits(
* one or not. We return these as a list of indices into the
* constant ssh2_hostkey_algs[] array.
*/
{ // WINSCP
ptrlen list = slists[KEXLIST_HOSTKEY];
ptrlen word; // WINSCP
for (; get_commasep_word(&list, &word) ;) {
for (ptrlen word; get_commasep_word(&list, &word) ;) {
for (i = 0; i < lenof(ssh2_hostkey_algs); i++)
if (ptrlen_eq_string(word, ssh2_hostkey_algs[i].alg->ssh_id)) {
sgrowarray(server_hostkeys->indices, server_hostkeys->size,
@@ -1295,13 +1280,10 @@ static ScanKexinitsResult ssh2_scan_kexinits(
break;
}
}
} // WINSCP
}
{ // WINSCP
ScanKexinitsResult skr = { /*.success =*/ true };
ScanKexinitsResult skr = { .success = true };
return skr;
} // WINSCP
}
static void ssh2_report_scan_kexinits_error(Ssh *ssh, ScanKexinitsResult skr)
@@ -1364,15 +1346,11 @@ static void filter_outgoing_kexinit(struct ssh2_transport_state *s)
* lists the same as the rest. In the rest of this code base we
* ignore those.
*/
{ // WINSCP
strbuf *out = strbuf_new();
size_t i; // WINSCP
for (i = 0; i < NKEXLIST+2; i++) {
for (size_t i = 0; i < NKEXLIST+2; i++) {
strbuf_clear(out);
{ // WINSCP
ptrlen olist = get_string(osrc), ilist = get_string(isrc);
ptrlen oword; // WINSCP
for (; get_commasep_word(&olist, &oword) ;) {
for (ptrlen oword; get_commasep_word(&olist, &oword) ;) {
ptrlen searchword = oword;
ptrlen ilist_copy = ilist;
@@ -1390,10 +1368,8 @@ static void filter_outgoing_kexinit(struct ssh2_transport_state *s)
searchword = kex_strict_c;
}
{ // WINSCP
bool add = false;
ptrlen iword; // WINSCP
for (; get_commasep_word(&ilist_copy, &iword) ;) {
for (ptrlen iword; get_commasep_word(&ilist_copy, &iword) ;) {
if (ptrlen_eq_ptrlen(searchword, iword)) {
/* Found this word in the incoming list. */
add = true;
@@ -1415,10 +1391,8 @@ static void filter_outgoing_kexinit(struct ssh2_transport_state *s)
if (add)
add_to_commasep_pl(out, oword);
} // WINSCP
}
put_stringpl(pktout, ptrlen_from_strbuf(out));
} // WINSCP
}
strbuf_free(out);
@@ -1437,7 +1411,6 @@ static void filter_outgoing_kexinit(struct ssh2_transport_state *s)
strbuf_shrink_to(s->outgoing_kexinit, 1); /* keep the type byte */
put_datapl(s->outgoing_kexinit, ptrlen_from_strbuf(pktout));
strbuf_free(pktout);
} // WINSCP
}
void ssh2transport_finalise_exhash(struct ssh2_transport_state *s)
@@ -1656,9 +1629,7 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
*/
s->n_uncert_hostkeys = 0;
{ // WINSCP
int i;
for (i = 0; i < hks.n; i++) {
for (int i = 0; i < hks.n; i++) {
int j = hks.indices[i];
if (ssh2_hostkey_algs[j].alg != s->hostkey_alg &&
ssh2_hostkey_algs[j].alg->cache_id &&
@@ -1669,7 +1640,6 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
}
sfree(hks.indices);
} // WINSCP
}
if (s->warn_kex) {
@@ -1904,13 +1874,10 @@ static void ssh2_transport_process_queue(PacketProtocolLayer *ppl)
* key algorithms. */
n_exts++;
put_stringz(extinfo, "server-sig-algs");
{ // WINSCP
strbuf *list = strbuf_new();
size_t i; // WINSCP
for (i = 0; i < n_keyalgs; i++)
for (size_t i = 0; i < n_keyalgs; i++)
add_to_commasep(list, all_keyalgs[i]->ssh_id);
put_stringsb(extinfo, list);
} // WINSCP
} else {
/* Client->server EXT_INFO is currently not sent, but here's
* where we should put things in it if we ever want to. */
@@ -2708,10 +2675,8 @@ static bool try_to_avoid_terrapin(const struct ssh2_transport_state *s)
* previously above it. If not, don't do anything - we don't want
* to _promote_ it.
*/
{ // WINSCP
int ccp_pos_now = -1, ccp_pos_wanted = -1;
int i; // WINSCP
for (i = 0; i < CIPHER_MAX; i++) {
for (int i = 0; i < CIPHER_MAX; i++) {
switch (conf_get_int_int(alt_conf, CONF_ssh_cipherlist,
i)) {
case CIPHER_CHACHA20:
@@ -2735,7 +2700,6 @@ static bool try_to_avoid_terrapin(const struct ssh2_transport_state *s)
}
conf_set_int_int(alt_conf, CONF_ssh_cipherlist,
ccp_pos_now + 1, CIPHER_CHACHA20);
} // WINSCP
/*
* Make the outgoing KEXINIT we would have made using this
@@ -2756,7 +2720,6 @@ static bool try_to_avoid_terrapin(const struct ssh2_transport_state *s)
* Re-analyse the incoming KEXINIT with respect to this one, to
* see what we'd have decided on.
*/
{ // WINSCP
transport_direction cstrans, sctrans;
bool warn_kex, warn_hk, warn_cscipher, warn_sccipher;
bool can_send_ext_info = false, strict_kex = false;
@@ -2800,16 +2763,12 @@ static bool try_to_avoid_terrapin(const struct ssh2_transport_state *s)
out:
{ // WINSCP
size_t i;
for (i = 0; i < NKEXLIST; i++)
for (size_t i = 0; i < NKEXLIST; i++)
sfree(alt_kexlists[i].algs);
strbuf_free(alt_client_kexinit);
conf_free(alt_conf);
return avoidable;
} // WINSCP
} // WINSCP
}
#include "puttyexp.h"

View File

@@ -59,7 +59,6 @@ struct kexinit_algorithm_list {
X(HK_RSA, ssh_rsa_sha512) \
X(HK_RSA, ssh_rsa_sha256) \
X(HK_RSA, ssh_rsa) \
/* WINSCP */ \
X(HK_ED25519, opensshcert_ssh_ecdsa_ed25519) \
/* OpenSSH defines no certified version of Ed448 */ \
X(HK_ECDSA, opensshcert_ssh_ecdsa_nistp256) \

View File

@@ -143,16 +143,14 @@ static ptrlen workaround_rsa_sha2_cert_userauth(
struct ssh2_userauth_state *s, ptrlen id);
static const PacketProtocolLayerVtable ssh2_userauth_vtable = {
// WINSCP
/*.free =*/ ssh2_userauth_free,
/*.process_queue =*/ ssh2_userauth_process_queue,
/*.get_specials =*/ ssh2_userauth_get_specials,
/*.special_cmd =*/ ssh2_userauth_special_cmd,
/*.reconfigure =*/ ssh2_userauth_reconfigure,
/*.queued_data_size =*/ ssh_ppl_default_queued_data_size,
/*.final_output =*/ ssh2_userauth_final_output,
/*.name =*/ "ssh-userauth",
NULL, // WINSCP
.free = ssh2_userauth_free,
.process_queue = ssh2_userauth_process_queue,
.get_specials = ssh2_userauth_get_specials,
.special_cmd = ssh2_userauth_special_cmd,
.reconfigure = ssh2_userauth_reconfigure,
.queued_data_size = ssh_ppl_default_queued_data_size,
.final_output = ssh2_userauth_final_output,
.name = "ssh-userauth",
};
PacketProtocolLayer *ssh2_userauth_new(
@@ -217,8 +215,7 @@ static void ssh2_userauth_free(PacketProtocolLayer *ppl)
ssh_ppl_free(s->successor_layer);
if (s->agent_keys) {
size_t i; // WINSCP
for (i = 0; i < s->agent_keys_len; i++) {
for (size_t i = 0; i < s->agent_keys_len; i++) {
strbuf_free(s->agent_keys[i].blob);
strbuf_free(s->agent_keys[i].comment);
}
@@ -264,7 +261,6 @@ static void ssh2_userauth_handle_banner_packet(struct ssh2_userauth_state *s,
if (!s->show_banner)
return;
{ // WINSCP
ptrlen string = get_string(pktin);
if (string.len > BANNER_LIMIT - bufchain_size(&s->banner))
string.len = BANNER_LIMIT - bufchain_size(&s->banner);
@@ -281,7 +277,6 @@ static void ssh2_userauth_handle_banner_packet(struct ssh2_userauth_state *s,
put_datapl(s->banner_scc, string);
else
put_datapl(&s->banner_bs, string);
} // WINSCP
}
static void ssh2_userauth_filter_queue(struct ssh2_userauth_state *s)
@@ -312,12 +307,10 @@ static bool ssh2_userauth_signflags(struct ssh2_userauth_state *s,
{
*signflags = 0; /* default */
{ // WINSCP
const ssh_keyalg *alg = find_pubkey_alg(*algname);
if (!alg)
return false; /* we don't know how to upgrade this */
{ // WINSCP
unsigned supported_flags = ssh_keyalg_supported_flags(alg);
if (s->ppl.bpp->ext_info_rsa_sha512_ok &&
@@ -332,8 +325,6 @@ static bool ssh2_userauth_signflags(struct ssh2_userauth_state *s,
*algname = ssh_keyalg_alternate_ssh_id(alg, *signflags);
return true;
} // WINSCP
} // WINSCP
}
static void authplugin_plug_log(Plug *plug, Socket *sock, PlugLogType type,
@@ -375,11 +366,10 @@ static void authplugin_plug_sent(Plug *plug, size_t bufsize)
}
static const PlugVtable authplugin_plugvt = {
/*.log =*/ authplugin_plug_log,
/*.closing =*/ authplugin_plug_closing,
/*.receive =*/ authplugin_plug_receive,
/*.sent =*/ authplugin_plug_sent,
NULL, // WINSCP
.log = authplugin_plug_log,
.closing = authplugin_plug_closing,
.receive = authplugin_plug_receive,
.sent = authplugin_plug_sent,
};
static strbuf *authplugin_newmsg(uint8_t type)
@@ -405,11 +395,9 @@ static bool authplugin_expect_msg(struct ssh2_userauth_state *s,
*type = PLUGIN_EOF;
return true;
}
{ // WINSCP
uint8_t len[4];
if (!bufchain_try_fetch(&s->authplugin_bc, len, 4))
return false;
{ // WINSCP
size_t size = GET_32BIT_MSB_FIRST(len);
if (bufchain_size(&s->authplugin_bc) - 4 < size)
return false;
@@ -428,8 +416,6 @@ static bool authplugin_expect_msg(struct ssh2_userauth_state *s,
if (get_err(src))
*type = PLUGIN_NOTYPE;
return true;
} // WINSCP
} // WINSCP
}
static void authplugin_bad_packet(struct ssh2_userauth_state *s,
@@ -459,13 +445,11 @@ static void authplugin_bad_packet(struct ssh2_userauth_state *s,
}
if (fmt) {
put_dataz(msg, " (");
{ // WINSCP
va_list ap;
va_start(ap, fmt);
put_fmt(msg, fmt, ap);
va_end(ap);
put_dataz(msg, ")");
} // WINSCP
}
ssh_sw_abort(s->ppl.ssh, "%s", msg->s);
strbuf_free(msg);
@@ -541,7 +525,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
ppl_logevent(WINSCP_BOM "Reading certificate file \"%s\"",
filename_to_str(s->detached_cert_file));
{ // WINSCP
int keytype = key_type(s->detached_cert_file);
if (!(keytype == SSH_KEYTYPE_SSH2_PUBLIC_RFC4716 ||
keytype == SSH_KEYTYPE_SSH2_PUBLIC_OPENSSH)) {
@@ -549,7 +532,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
goto cert_load_done;
}
{ // WINSCP
const char *error;
bool success = ppk_loadpub_f(
s->detached_cert_file, &algname,
@@ -560,7 +542,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
goto cert_load_done;
}
{ // WINSCP
const ssh_keyalg *certalg = find_pubkey_alg(algname);
if (!certalg) {
cert_error = dupprintf(
@@ -595,9 +576,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
strbuf_free(cert_blob);
sfree(algname);
sfree(comment);
} // WINSCP
} // WINSCP
} // WINSCP
}
/*
@@ -625,9 +603,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
/*
* Check that the agent response is well formed.
*/
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < nkeys; i++) {
for (size_t i = 0; i < nkeys; i++) {
get_string(s->asrc); /* blob */
get_string(s->asrc); /* comment */
if (get_err(s->asrc)) {
@@ -635,7 +611,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
goto done_agent_query;
}
}
} // WINSCP
/*
* Copy the list of public-key blobs out of the Pageant
@@ -644,20 +619,15 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
BinarySource_REWIND_TO(s->asrc, origpos);
s->agent_keys_len = nkeys;
s->agent_keys = snewn(s->agent_keys_len, agent_key);
{ // WINSCP
size_t i; // WINSCP
for (i = 0; i < nkeys; i++) {
for (size_t i = 0; i < nkeys; i++) {
s->agent_keys[i].blob = strbuf_dup(get_string(s->asrc));
s->agent_keys[i].comment = strbuf_dup(get_string(s->asrc));
{ // WINSCP
/* Also, extract the algorithm string from the start
* of the public-key blob. */
s->agent_keys[i].algorithm = pubkey_blob_to_alg_name(
ptrlen_from_strbuf(s->agent_keys[i].blob));
} // WINSCP
}
} // WINSCP
ppl_logevent("Pageant has %"SIZEu" SSH-2 keys", nkeys);
@@ -716,14 +686,12 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
put_stringz(amsg, s->username ? s->username : "");
authplugin_send_free(s, amsg);
{ // WINSCP
BinarySource src[1];
unsigned type;
crMaybeWaitUntilV(authplugin_expect_msg(s, &type, src));
switch (type) {
case PLUGIN_INIT_RESPONSE: {
s->authplugin_version = get_uint32(src);
{ // WINSCP
ptrlen username = get_string(src);
if (get_err(src)) {
ssh_sw_abort(s->ppl.ssh, "Received malformed "
@@ -742,7 +710,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
ppl_logevent("Authentication plugin set username '%s'",
s->default_username);
}
} // WINSCP
break;
}
case PLUGIN_INIT_FAILURE: {
@@ -768,7 +735,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
"PLUGIN_INIT_FAILURE");
return;
}
} // WINSCP
}
/*
@@ -888,8 +854,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
* anti-spoofing header lines.
*/
ssh2_userauth_print_banner(s);
{ // WINSCP
} // WINSCP
if (pktin && pktin->type == SSH2_MSG_USERAUTH_SUCCESS) {
ppl_logevent("Access granted");
@@ -995,15 +959,13 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
/*
* Scan it for method identifiers we know about.
*/
{ // WINSCP
bool srv_pubkey = false, srv_passwd = false;
bool srv_keyb_inter = false;
#ifndef NO_GSSAPI
bool srv_gssapi = false, srv_gssapi_keyex_auth = false;
#endif
ptrlen method; // WINSCP
for (; get_commasep_word(&methods, &method) ;) {
for (ptrlen method; get_commasep_word(&methods, &method) ;) {
if (ptrlen_eq_string(method, "publickey"))
srv_pubkey = true;
else if (ptrlen_eq_string(method, "password"))
@@ -1032,7 +994,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
srv_gssapi_keyex_auth &&
s->shgss->libs->nlibraries > 0 && s->shgss->ctx;
#endif
} // WINSCP
}
s->ppl.bpp->pls->actx = SSH2_PKTCTX_NOAUTH;
@@ -1066,7 +1027,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
* Attempt public-key authentication using a key from Pageant.
*/
s->agent_keyalg = s->agent_keys[s->agent_key_index].algorithm;
{ // WINSCP
char *alg_tmp = mkstr(s->agent_keyalg);
const char *newalg = alg_tmp;
if (ssh2_userauth_signflags(s, &s->signflags, &newalg))
@@ -1177,7 +1137,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
/* Do we have any keys left to try? */
if (++s->agent_key_index >= s->agent_key_limit)
s->done_agent = true;
} // WINSCP
} else if (s->can_pubkey && s->publickey_blob &&
s->privatekey_available && !s->tried_pubkey_config) {
@@ -1194,7 +1153,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
*
* First, try to upgrade its algorithm.
*/
{ // WINSCP
const char *newalg = s->publickey_algorithm;
if (ssh2_userauth_signflags(s, &s->signflags, &newalg)) {
sfree(s->publickey_algorithm);
@@ -1368,7 +1326,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
sfree(key);
s->is_trivial_auth = false;
}
} // WINSCP
#ifndef NO_GSSAPI
} else if (s->can_gssapi && !s->tried_gssapi) {
@@ -1606,7 +1563,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
put_stringz(amsg, "keyboard-interactive");
authplugin_send_free(s, amsg);
{ // WINSCP
BinarySource src[1];
unsigned type;
crMaybeWaitUntilV(authplugin_expect_msg(s, &type, src));
@@ -1656,7 +1612,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
"PLUGIN_PROTOCOL_REJECT");
return;
}
} // WINSCP
} else {
s->authplugin_ki_active = false;
}
@@ -1744,7 +1699,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
put_datapl(amsg, get_data(pktin, get_avail(pktin)));
authplugin_send_free(s, amsg);
{ // WINSCP
BinarySource src[1];
unsigned type;
while (true) {
@@ -1775,13 +1729,11 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
/*
* Send the responses on to the plugin.
*/
{ // WINSCP
strbuf *amsg = authplugin_newmsg(
PLUGIN_KI_USER_RESPONSE);
ssh2_userauth_ki_write_responses(
s, BinarySink_UPCAST(amsg));
authplugin_send_free(s, amsg);
} // WINSCP
}
if (type != PLUGIN_KI_SERVER_RESPONSE) {
@@ -1803,7 +1755,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
*/
crMaybeWaitUntilV(
(pktin = ssh2_userauth_pop(s)) != NULL);
} // WINSCP
}
}
@@ -1841,13 +1792,11 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
BinarySource_BARE_INIT(
src, get_ptr(pktin), get_avail(pktin));
get_string(pktin); /* skip methods */
{ // WINSCP
bool partial_success = get_bool(pktin);
if (!get_err(src)) {
plugin_msg = partial_success ?
PLUGIN_AUTH_SUCCESS : PLUGIN_AUTH_FAILURE;
}
} // WINSCP
}
if (plugin_msg >= 0) {
@@ -1863,7 +1812,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
}
} else if (s->can_passwd) {
s->is_trivial_auth = false;
{ // WINSCP
/*
* Plain old password authentication.
*/
@@ -2108,7 +2056,6 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
*/
smemclr(s->password, strlen(s->password));
sfree(s->password);
} // WINSCP
} else {
ssh_bpp_queue_disconnect(
@@ -2166,7 +2113,6 @@ static void ssh2_userauth_print_banner(struct ssh2_userauth_state *s)
seat_set_trust_status(s->ppl.seat, false);
}
{ // WINSCP
bool mid_line = false;
while (bufchain_size(&s->banner) > 0) {
// WINSCP: consume banner buffer before calling seat_banner_pl.
@@ -2193,7 +2139,6 @@ static void ssh2_userauth_print_banner(struct ssh2_userauth_state *s)
seat_antispoof_msg(ppl_get_iseat(&s->ppl),
"End of banner message from server");
}
} // WINSCP
}
}
@@ -2219,11 +2164,8 @@ static bool ssh2_userauth_ki_setup_prompts(
* Get any prompt(s) from the packet.
*/
s->num_prompts = get_uint32(src);
{ // WINSCP
uint32_t i; // WINSCP
for (i = 0; i < s->num_prompts; i++) {
for (uint32_t i = 0; i < s->num_prompts; i++) {
s->is_trivial_auth = false;
{ // WINSCP
ptrlen prompt = get_string(src);
bool echo = get_bool(src);
@@ -2247,9 +2189,7 @@ static bool ssh2_userauth_ki_setup_prompts(
put_datapl(sb, prompt);
}
add_prompt(s->cur_prompt, strbuf_to_str(sb), echo);
} // WINSCP
}
} // WINSCP
/*
* Make the header strings. This includes the 'name' (optional
@@ -2330,11 +2270,8 @@ static void ssh2_userauth_ki_write_responses(
struct ssh2_userauth_state *s, BinarySink *bs)
{
put_uint32(bs, s->num_prompts);
{ // WINSCP
uint32_t i;
for (i = 0; i < s->num_prompts; i++)
for (uint32_t i = 0; i < s->num_prompts; i++)
put_stringz(bs, prompt_get_result_ref(s->cur_prompt->prompts[i]));
} // WINSCP
/*
* Free the prompts structure from this iteration. If there's
@@ -2424,7 +2361,6 @@ static void ssh2_userauth_add_alg_and_publickey(
* base public key.
*/
{ // WINSCP
const ssh_keyalg *certalg = pubkey_blob_to_alg(detached_cert_pl);
assert(certalg); /* we checked this before setting s->detached_blob */
assert(certalg->is_certificate); /* and this too */
@@ -2551,7 +2487,6 @@ static void ssh2_userauth_add_alg_and_publickey(
/* And if we did, don't fall through to the alternative below */
if (done)
return;
} // WINSCP
}
/* In all other cases, basically just put in what we were given -
@@ -2717,8 +2652,7 @@ static void ssh2_userauth_final_output(PacketProtocolLayer *ppl)
* in our queue just before the server closed the connection, and
* add them to our banner buffer.
*/
PktIn *pktin; // WINSCP
for (pktin = pq_first(s->ppl.in_pq); pktin != NULL;
for (PktIn *pktin = pq_first(s->ppl.in_pq); pktin != NULL;
pktin = pq_next(s->ppl.in_pq, pktin)) {
if (pktin->type == SSH2_MSG_USERAUTH_BANNER)
ssh2_userauth_handle_banner_packet(s, pktin);

View File

@@ -46,13 +46,12 @@ static void ssh_verstring_queue_disconnect(BinaryPacketProtocol *bpp,
const char *msg, int category);
static const BinaryPacketProtocolVtable ssh_verstring_vtable = {
// WINSCP
/*.free =*/ ssh_verstring_free,
/*.handle_input =*/ ssh_verstring_handle_input,
/*.handle_output =*/ ssh_verstring_handle_output,
/*.new_pktout =*/ ssh_verstring_new_pktout,
/*.queue_disconnect =*/ ssh_verstring_queue_disconnect,
/*.packet_size_limit =*/ 0xFFFFFFFF, /* no special limit for this bpp */
.free = ssh_verstring_free,
.handle_input = ssh_verstring_handle_input,
.handle_output = ssh_verstring_handle_output,
.new_pktout = ssh_verstring_new_pktout,
.queue_disconnect = ssh_verstring_queue_disconnect,
.packet_size_limit = 0xFFFFFFFF, /* no special limit for this bpp */
};
static void ssh_detect_bugs(struct ssh_verstring_state *s);

View File

@@ -1240,14 +1240,13 @@ static bool zlib_decompress_block(
}
const ssh_compression_alg ssh_zlib = {
// WINSCP
/*.name =*/ "zlib",
/*.delayed_name =*/ "zlib@openssh.com", /* delayed version */
/*.compress_new =*/ zlib_compress_init,
/*.compress_free =*/ zlib_compress_cleanup,
/*.compress =*/ zlib_compress_block,
/*.decompress_new =*/ zlib_decompress_init,
/*.decompress_free =*/ zlib_decompress_cleanup,
/*.decompress =*/ zlib_decompress_block,
/*.text_name =*/ "zlib (RFC1950)",
.name = "zlib",
.delayed_name = "zlib@openssh.com", /* delayed version */
.compress_new = zlib_compress_init,
.compress_free = zlib_compress_cleanup,
.compress = zlib_compress_block,
.decompress_new = zlib_decompress_init,
.decompress_free = zlib_decompress_cleanup,
.decompress = zlib_decompress_block,
.text_name = "zlib (RFC1950)",
};

View File

@@ -75,7 +75,6 @@ LoadFileStatus lf_load_fp(LoadedFile *lf, FILE *fp)
lf->len += retd;
}
{ // WINSCP
LoadFileStatus status = LF_OK;
if (lf->len == lf->max_size) {
@@ -88,7 +87,6 @@ LoadFileStatus lf_load_fp(LoadedFile *lf, FILE *fp)
BinarySource_INIT(lf, lf->data, lf->len);
return status;
} // WINSCP
}
LoadFileStatus lf_load(LoadedFile *lf, const Filename *filename)
@@ -118,17 +116,13 @@ LoadFileStatus lf_load(LoadedFile *lf, const Filename *filename)
return status;
}
#endif
{ // WINSCP
FILE *fp = f_open(filename, "rb", false);
if (!fp)
return LF_ERROR;
{ // WINSCP
LoadFileStatus status = lf_load_fp(lf, fp);
fclose(fp);
return status;
} // WINSCP
} // WINSCP
}
static inline bool lf_load_keyfile_helper(LoadFileStatus status,
@@ -237,14 +231,12 @@ static int rsa1_load_s_internal(BinarySource *src, RSAKey *key, bool pub_only,
buf = strbuf_dup_nm(get_data(src, enclen));
{ // WINSCP
unsigned char keybuf[16];
hash_simple(&ssh_md5, ptrlen_from_asciz(passphrase), keybuf);
des3_decrypt_pubkey(keybuf, buf->u, enclen);
smemclr(keybuf, sizeof(keybuf)); /* burn the evidence */
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(buf));
} // WINSCP
}
/*
@@ -301,11 +293,9 @@ int rsa1_load_f(const Filename *filename, RSAKey *key,
if (!lf)
return false;
{ // WINSCP
int toret = rsa1_load_s(BinarySource_UPCAST(lf), key, passphrase, errstr);
lf_free(lf);
return toret;
} // WINSCP
}
/*
@@ -324,11 +314,9 @@ bool rsa1_encrypted_f(const Filename *filename, char **comment)
if (!lf)
return false; /* couldn't even open the file */
{ // WINSCP
bool toret = rsa1_encrypted_s(BinarySource_UPCAST(lf), comment);
lf_free(lf);
return toret;
} // WINSCP
}
/*
@@ -345,7 +333,6 @@ int rsa1_loadpub_s(BinarySource *src, BinarySink *bs,
/* Default return if we fail. */
ret = 0;
{ // WINSCP
bool is_privkey_file = expect_signature(src, rsa1_signature);
BinarySource_REWIND(src);
@@ -417,7 +404,6 @@ int rsa1_loadpub_s(BinarySource *src, BinarySink *bs,
if ((ret != 1) && errorstr)
*errorstr = error;
return ret;
} // WINSCP
}
int rsa1_loadpub_f(const Filename *filename, BinarySink *bs,
@@ -427,12 +413,10 @@ int rsa1_loadpub_f(const Filename *filename, BinarySink *bs,
if (!lf)
return 0;
{ // WINSCP
int toret = rsa1_loadpub_s(BinarySource_UPCAST(lf), bs,
commentptr, errorstr);
lf_free(lf);
return toret;
} // WINSCP
}
strbuf *rsa1_save_sb(RSAKey *key, const char *passphrase)
@@ -503,14 +487,12 @@ bool rsa1_save_f(const Filename *filename, RSAKey *key, const char *passphrase)
if (!fp)
return false;
{ // WINSCP
strbuf *buf = rsa1_save_sb(key, passphrase);
bool toret = fwrite(buf->s, 1, buf->len, fp) == buf->len;
if (fclose(fp))
toret = false;
strbuf_free(buf);
return toret;
} // WINSCP
}
#endif
@@ -623,8 +605,7 @@ const size_t n_keyalgs = lenof(all_keyalgs);
const ssh_keyalg *find_pubkey_alg_len(ptrlen name)
{
size_t i; // WINSCP
for (i = 0; i < n_keyalgs; i++)
for (size_t i = 0; i < n_keyalgs; i++)
if (ptrlen_eq_string(name, all_keyalgs[i]->ssh_id))
return all_keyalgs[i];
@@ -668,12 +649,10 @@ static void ssh2_ppk_derive_keys(
mac_keylen = 0;
break;
}
{ // WINSCP
ptrlen empty = PTRLEN_LITERAL("");
mac_keylen = 32;
{ // WINSCP
uint32_t taglen = ciphertype->keylen + ciphertype->ivlen + mac_keylen;
if (params->argon2_passes_auto) {
@@ -692,8 +671,6 @@ static void ssh2_ppk_derive_keys(
params->argon2_passes, params->argon2_parallelism, taglen,
passphrase, passphrase_salt, empty, empty, storage);
}
} // WINSCP
} // WINSCP
break;
}
@@ -701,9 +678,7 @@ static void ssh2_ppk_derive_keys(
case 2:
case 1: {
/* Counter-mode iteration to generate cipher key data. */
{ // WINSCP
unsigned ctr; // WINSCP
for (ctr = 0; ctr * 20 < ciphertype->keylen; ctr++) {
for (unsigned ctr = 0; ctr * 20 < ciphertype->keylen; ctr++) {
ssh_hash *h = ssh_hash_new(&ssh_sha1);
put_uint32(h, ctr);
put_datapl(h, passphrase);
@@ -715,14 +690,11 @@ static void ssh2_ppk_derive_keys(
put_padding(storage, ciphertype->ivlen, 0);
/* Completely separate hash for the MAC key. */
{ // WINSCP
ssh_hash *h = ssh_hash_new(&ssh_sha1);
mac_keylen = ssh_hash_alg(h)->hlen;
put_datapl(h, PTRLEN_LITERAL("putty-private-key-file-mac-key"));
put_datapl(h, passphrase);
ssh_hash_final(h, strbuf_append(storage, mac_keylen));
} // WINSCP
} // WINSCP
break;
}
@@ -731,13 +703,11 @@ static void ssh2_ppk_derive_keys(
unreachable("bad format version in ssh2_ppk_derive_keys");
}
{ // WINSCP
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(storage));
*cipherkey = get_data(src, ciphertype->keylen);
*cipheriv = get_data(src, ciphertype->ivlen);
*mackey = get_data(src, mac_keylen);
} // WINSCP
}
static int userkey_parse_line_counter(const char *text)
@@ -903,9 +873,7 @@ ssh2_userkey *ppk_load_s(BinarySource *src, const char *passphrase,
goto error;
if ((b = read_body(src)) == NULL)
goto error;
{ // WINSCP
size_t i; // WINSCP
for (i = 0; b[i]; i += 2) {
for (size_t i = 0; b[i]; i += 2) {
if (isxdigit((unsigned char)b[i]) && b[i+1] &&
isxdigit((unsigned char)b[i+1])) {
char s[3];
@@ -918,7 +886,6 @@ ssh2_userkey *ppk_load_s(BinarySource *src, const char *passphrase,
goto error;
}
}
} // WINSCP
sfree(b);
}
@@ -1383,12 +1350,10 @@ bool ppk_loadpub_f(const Filename *filename, char **algorithm, BinarySink *bs,
if (!lf)
return false;
{ // WINSCP
bool toret = ppk_loadpub_s(BinarySource_UPCAST(lf), algorithm, bs,
commentptr, errorstr);
lf_free(lf);
return toret;
} // WINSCP
}
bool ppk_encrypted_s(BinarySource *src, char **commentptr)
@@ -1449,11 +1414,9 @@ bool ppk_encrypted_f(const Filename *filename, char **commentptr)
return false;
}
{ // WINSCP
bool toret = ppk_encrypted_s(BinarySource_UPCAST(lf), commentptr);
lf_free(lf);
return toret;
} // WINSCP
}
int base64_lines(int datalen)
@@ -1463,15 +1426,14 @@ int base64_lines(int datalen)
}
const ppk_save_parameters ppk_save_default_parameters = {
// WINSCP
/*.fmt_version =*/ 3,
.fmt_version = 3,
/*
* The Argon2 spec recommends the hybrid variant Argon2id, where
* you don't have a good reason to go with the pure Argon2d or
* Argon2i.
*/
/*.argon2_flavour =*/ Argon2id,
.argon2_flavour = Argon2id,
/*
* Memory requirement for hashing a password: I don't want to set
@@ -1486,7 +1448,7 @@ const ppk_save_parameters ppk_save_default_parameters = {
* (which was plain SHA-1), so it still imposes a limit on
* parallel attacks on someone's key file.
*/
/*.argon2_mem =*/ 8192, /* require 8 Mb memory */
.argon2_mem = 8192, /* require 8 Mb memory */
/*
* Automatically scale the number of Argon2 passes so that the
@@ -1495,8 +1457,8 @@ const ppk_save_parameters ppk_save_default_parameters = {
* but for the moment, I'm trying to err on the side of not
* stopping anyone from using the tools at all.)
*/
/*.argon2_passes_auto =*/ true,
/*.argon2_milliseconds =*/ 100,
.argon2_passes_auto = true,
.argon2_milliseconds = 100,
/*
* PuTTY's own Argon2 implementation is single-threaded. So we
@@ -1508,8 +1470,7 @@ const ppk_save_parameters ppk_save_default_parameters = {
* least they don't get a speed advantage over us in computing
* even one hash.)
*/
/*.argon2_parallelism =*/ 1,
NULL, 0, // WINSCP
.argon2_parallelism = 1,
};
strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
@@ -1560,7 +1521,6 @@ strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
/* Copy the save parameters, so that when derive_keys chooses the
* number of Argon2 passes, it can write the result back to our
* copy for us to retrieve. */
{ // WINSCP
ppk_save_parameters params = *params_orig;
strbuf *passphrase_salt = strbuf_new();
@@ -1579,7 +1539,6 @@ strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
cipher_mac_keys_blob, &cipherkey, &cipheriv, &mackey,
ptrlen_from_strbuf(passphrase_salt), &params);
{ // WINSCP
const ssh2_macalg *macalg = (params.fmt_version == 2 ?
&ssh_hmac_sha1 : &ssh_hmac_sha256);
@@ -1604,7 +1563,6 @@ strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
priv_blob_encrypted, priv_encrypted_len);
}
{ // WINSCP
strbuf *out = strbuf_new_nm();
put_fmt(out, "PuTTY-User-Key-File-%u: %s\n",
params.fmt_version, ssh_key_ssh_id(key->key));
@@ -1622,12 +1580,9 @@ strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
put_fmt(out, "Argon2-Parallelism: %"PRIu32"\n",
params.argon2_parallelism);
put_fmt(out, "Argon2-Salt: ");
{ // WINSCP
size_t i;
for (i = 0; i < passphrase_salt->len; i++)
for (size_t i = 0; i < passphrase_salt->len; i++)
put_fmt(out, "%02x", passphrase_salt->u[i]);
put_fmt(out, "\n");
} // WINSCP
}
put_fmt(out, "Private-Lines: %d\n", base64_lines(priv_encrypted_len));
base64_encode_bs(BinarySink_UPCAST(out),
@@ -1644,9 +1599,6 @@ strbuf *ppk_save_sb(ssh2_userkey *key, const char *passphrase,
smemclr(priv_blob_encrypted, priv_encrypted_len);
sfree(priv_blob_encrypted);
return out;
} // WINSCP
} // WINSCP
} // WINSCP
}
bool ppk_save_f(const Filename *filename, ssh2_userkey *key,
@@ -1656,14 +1608,12 @@ bool ppk_save_f(const Filename *filename, ssh2_userkey *key,
if (!fp)
return false;
{ // WINSCP
strbuf *buf = ppk_save_sb(key, passphrase, params);
bool toret = fwrite(buf->s, 1, buf->len, fp) == buf->len;
if (fclose(fp))
toret = false;
strbuf_free(buf);
return toret;
} // WINSCP
}
/* ----------------------------------------------------------------------
@@ -1802,9 +1752,8 @@ static void ssh2_fingerprint_blob_md5(ptrlen blob, strbuf *sb)
{
unsigned char digest[16];
unsigned i; // WINSCP
hash_simple(&ssh_md5, blob, digest);
for (i = 0; i < 16; i++)
for (unsigned i = 0; i < 16; i++)
put_fmt(sb, "%02x%s", digest[i], i==15 ? "" : ":");
}
@@ -1815,9 +1764,7 @@ static void ssh2_fingerprint_blob_sha256(ptrlen blob, strbuf *sb)
put_datapl(sb, PTRLEN_LITERAL("SHA256:"));
{ // WINSCP
unsigned i;
for (i = 0; i < 32; i += 3) {
for (unsigned i = 0; i < 32; i += 3) {
char buf[5];
unsigned len = 32-i;
if (len > 3)
@@ -1826,7 +1773,6 @@ static void ssh2_fingerprint_blob_sha256(ptrlen blob, strbuf *sb)
put_data(sb, buf, 4);
}
strbuf_chomp(sb, '=');
} // WINSCP
}
char *ssh2_fingerprint_blob(ptrlen blob, FingerprintType fptype)
@@ -1842,7 +1788,6 @@ char *ssh2_fingerprint_blob(ptrlen blob, FingerprintType fptype)
*/
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, blob);
{ // WINSCP
ptrlen algname = get_string(src);
if (!get_err(src)) {
const ssh_keyalg *alg = find_pubkey_alg_len(algname);
@@ -1864,7 +1809,6 @@ char *ssh2_fingerprint_blob(ptrlen blob, FingerprintType fptype)
put_fmt(sb, "%.*s ", PTRLEN_PRINTF(algname));
}
}
} // WINSCP
switch (ssh_fptype_from_cert(fptype)) {
case SSH_FPTYPE_MD5:
@@ -1888,7 +1832,6 @@ char *ssh2_double_fingerprint_blob(ptrlen blob, FingerprintType fptype)
if (ssh_fptype_is_cert(fptype))
fptype = ssh_fptype_from_cert(fptype);
{ // WINSCP
char *fp = ssh2_fingerprint_blob(blob, fptype);
char *p = strrchr(fp, ' ');
char *hash = p ? p + 1 : fp;
@@ -1905,14 +1848,12 @@ char *ssh2_double_fingerprint_blob(ptrlen blob, FingerprintType fptype)
sfree(fpc);
return fp;
} // WINSCP
}
char **ssh2_all_fingerprints_for_blob(ptrlen blob)
{
char **fps = snewn(SSH_N_FPTYPES, char *);
unsigned i; // WINSCP
for (i = 0; i < SSH_N_FPTYPES; i++)
for (unsigned i = 0; i < SSH_N_FPTYPES; i++)
fps[i] = ssh2_fingerprint_blob(blob, i);
return fps;
}
@@ -1920,9 +1861,8 @@ char **ssh2_all_fingerprints_for_blob(ptrlen blob)
char *ssh2_fingerprint(ssh_key *data, FingerprintType fptype)
{
strbuf *blob = strbuf_new();
char *ret; //MPEXT
ssh_key_public_blob(data, BinarySink_UPCAST(blob));
ret = ssh2_fingerprint_blob(ptrlen_from_strbuf(blob), fptype);
char *ret = ssh2_fingerprint_blob(ptrlen_from_strbuf(blob), fptype);
strbuf_free(blob);
return ret;
}
@@ -1931,28 +1871,23 @@ char *ssh2_double_fingerprint(ssh_key *data, FingerprintType fptype)
{
strbuf *blob = strbuf_new();
ssh_key_public_blob(data, BinarySink_UPCAST(blob));
{ // WINSCP
char *ret = ssh2_double_fingerprint_blob(ptrlen_from_strbuf(blob), fptype);
strbuf_free(blob);
return ret;
} // WINSCP
}
char **ssh2_all_fingerprints(ssh_key *data)
{
strbuf *blob = strbuf_new();
ssh_key_public_blob(data, BinarySink_UPCAST(blob));
{ // WINSCP
char **ret = ssh2_all_fingerprints_for_blob(ptrlen_from_strbuf(blob));
strbuf_free(blob);
return ret;
} // WINSCP
}
void ssh2_free_all_fingerprints(char **fps)
{
unsigned i; // WINSCP
for (i = 0; i < SSH_N_FPTYPES; i++)
for (unsigned i = 0; i < SSH_N_FPTYPES; i++)
sfree(fps[i]);
sfree(fps);
}
@@ -2019,11 +1954,9 @@ int key_type(const Filename *filename)
return SSH_KEYTYPE_UNOPENABLE;
}
{ // WINSCP
int toret = key_type_s(BinarySource_UPCAST(lf));
lf_free(lf);
return toret;
} // WINSCP
}
/*

View File

@@ -162,12 +162,10 @@ void random_read(void *buf, size_t size)
void random_get_savedata(void **data, int *len)
{
WINSCP_PUTTY_SECTION_ENTER; // though called from our finalizer, when the app is single threaded only
{ // WINSCP
void *buf = snewn(global_prng->savesize, char);
random_read(buf, global_prng->savesize);
*len = global_prng->savesize;
*data = buf;
} // WINSCP
WINSCP_PUTTY_SECTION_LEAVE;
}

View File

@@ -9,10 +9,10 @@
static void null_opener_free(DeferredSocketOpener *opener) {}
static const DeferredSocketOpenerVtable NullOpener_vt = {
/*.free =*/ null_opener_free,
.free = null_opener_free,
};
static DeferredSocketOpener null_opener = { /*.vt =*/ &NullOpener_vt };
static DeferredSocketOpener null_opener = { .vt = &NullOpener_vt };
DeferredSocketOpener *null_deferred_socket_opener(void)
{

View File

@@ -25,12 +25,10 @@ void nullplug_sent(Plug *plug, size_t bufsize)
}
static const PlugVtable nullplug_plugvt = {
// WINSCP
/*.log =*/ nullplug_log,
/*.closing =*/ nullplug_closing,
/*.receive =*/ nullplug_receive,
/*.sent =*/ nullplug_sent,
NULL, // WINSCP
.log = nullplug_log,
.closing = nullplug_closing,
.receive = nullplug_receive,
.sent = nullplug_sent,
};
static Plug nullplug_plug = { &nullplug_plugvt };

View File

@@ -59,12 +59,12 @@ bool nullseat_get_cursor_position(Seat *seat, int *x, int *y) { return false; }
const SeatDialogPromptDescriptions *nullseat_prompt_descriptions(Seat *seat)
{
static const SeatDialogPromptDescriptions descs = {
/*.hk_accept_action =*/ "",
/*.hk_connect_once_action =*/ "",
/*.hk_cancel_action =*/ "",
/*.hk_cancel_action_Participle =*/ "",
/*.weak_accept_action =*/ "",
/*.weak_cancel_action =*/ "",
.hk_accept_action = "",
.hk_connect_once_action = "",
.hk_cancel_action = "",
.hk_cancel_action_Participle = "",
.weak_accept_action = "",
.weak_cancel_action = "",
};
return &descs;
}

View File

@@ -9,9 +9,7 @@ void base64_decode_bs(BinarySink *bs, ptrlen input)
char b64atom[4];
unsigned char binatom[3];
{ // WINSCP
size_t i;
for (i = 0; i < 4 ;) {
for (size_t i = 0; i < 4 ;) {
char c = get_byte(src);
if (get_err(src))
c = '=';
@@ -19,7 +17,6 @@ void base64_decode_bs(BinarySink *bs, ptrlen input)
continue;
b64atom[i++] = c;
}
} // WINSCP
put_data(bs, binatom, base64_decode_atom(b64atom, binatom));
}

View File

@@ -4,7 +4,6 @@ void base64_encode_bs(BinarySink *bs, ptrlen input, int cpl)
{
BinarySource src[1];
BinarySource_BARE_INIT_PL(src, input);
{ // WINSCP
int linelen = 0;
while (get_avail(src)) {
@@ -13,9 +12,7 @@ void base64_encode_bs(BinarySink *bs, ptrlen input, int cpl)
char b64atom[4];
base64_encode_atom(binatom.ptr, binatom.len, b64atom);
{ // WINSCP
size_t i;
for (i = 0; i < 4; i++) {
for (size_t i = 0; i < 4; i++) {
if (cpl > 0 && linelen >= cpl) {
linelen = 0;
put_byte(bs, '\n');
@@ -23,11 +20,9 @@ void base64_encode_bs(BinarySink *bs, ptrlen input, int cpl)
put_byte(bs, b64atom[i]);
linelen++;
}
} // WINSCP
}
if (cpl > 0)
put_byte(bs, '\n');
} // WINSCP
}
void base64_encode_fp(FILE *fp, ptrlen input, int cpl)

View File

@@ -16,8 +16,7 @@ bool base64_valid(ptrlen data)
{
size_t blocklen = 0, nequals = 0;
size_t i; // WINSCP
for (i = 0; i < data.len; i++) {
for (size_t i = 0; i < data.len; i++) {
char c = ((const char *)data.ptr)[i];
if (c == '\n' || c == '\r')

View File

@@ -201,7 +201,6 @@ static Token lex(ptrlen *text, ptrlen *token, char **err)
while (p < e && is_space(*p))
p++;
{ // WINSCP
const char *start = p;
if (!(p < e)) {
@@ -222,9 +221,7 @@ static Token lex(ptrlen *text, ptrlen *token, char **err)
{PTRLEN_DECL_LITERAL("!"), TOK_NOT},
};
{ // WINSCP
size_t i;
for (i = 0; i < lenof(operators); i++) {
for (size_t i = 0; i < lenof(operators); i++) {
const struct operator *op = &operators[i];
if (e - p >= op->text.len &&
ptrlen_eq_ptrlen(op->text, make_ptrlen(p, op->text.len))) {
@@ -233,7 +230,6 @@ static Token lex(ptrlen *text, ptrlen *token, char **err)
goto out;
}
}
} // WINSCP
/*
* Report an error if one of the operator characters is used
@@ -272,7 +268,6 @@ static Token lex(ptrlen *text, ptrlen *token, char **err)
text->ptr = p;
text->len = e - p;
return type;
} // WINSCP
}
typedef enum Operator {
@@ -319,11 +314,8 @@ static void exprnode_free(ExprNode *en)
switch (en->op) {
case OP_AND:
case OP_OR:
{ // WINSCP
size_t i;
for (i = 0; i < en->nsubexprs; i++)
for (size_t i = 0; i < en->nsubexprs; i++)
exprnode_free(en->subexprs[i]);
} // WINSCP
sfree(en->subexprs);
break;
case OP_NOT:
@@ -344,8 +336,7 @@ static void exprnode_free(ExprNode *en)
static unsigned ptrlen_to_port_number(ptrlen input)
{
unsigned val = 0;
const char *p, *end; // WINSCP
for (p = input.ptr, end = p + input.len; p < end; p++) {
for (const char *p = input.ptr, *end = p + input.len; p < end; p++) {
assert('0' <= *p && *p <= '9'); /* expect parser to have checked */
val = 10 * val + (*p - '0');
if (val >= 65536)
@@ -395,7 +386,6 @@ static ExprNode *parse_atom(ParserState *ps)
ptrlen openpar = ps->toktext;
advance(ps); /* eat the ( */
{ // WINSCP
ExprNode *subexpr = parse_expr(ps);
if (!subexpr)
return NULL;
@@ -407,7 +397,6 @@ static ExprNode *parse_atom(ParserState *ps)
return NULL;
}
{ // WINSCP
ptrlen closepar = ps->toktext;
advance(ps); /* eat the ) */
@@ -417,27 +406,21 @@ static ExprNode *parse_atom(ParserState *ps)
subexpr->text = make_ptrlen_startend(
openpar.ptr, ptrlen_end(closepar));
return subexpr;
} // WINSCP
} // WINSCP
}
if (ps->tok == TOK_NOT) {
ptrlen notloc = ps->toktext;
advance(ps); /* eat the ! */
{ // WINSCP
ExprNode *subexpr = parse_atom(ps);
if (!subexpr)
return NULL;
{ // WINSCP
ExprNode *en = exprnode_new(
OP_NOT, make_ptrlen_startend(
notloc.ptr, ptrlen_end(subexpr->text)));
en->subexpr = subexpr;
return en;
} // WINSCP
} // WINSCP
}
if (ps->tok == TOK_ATOM) {
@@ -449,7 +432,6 @@ static ExprNode *parse_atom(ParserState *ps)
return en;
}
{ // WINSCP
ptrlen tail;
if (ptrlen_startswith(ps->toktext, PTRLEN_LITERAL("port:"), &tail)) {
/* Port number (single or range). */
@@ -502,15 +484,12 @@ static ExprNode *parse_atom(ParserState *ps)
}
{ // WINSCP
ExprNode *en = exprnode_new(OP_PORT_RANGE, ps->toktext);
en->lo = lo;
en->hi = hi;
advance(ps);
return en;
} // WINSCP
}
} // WINSCP
}
error(ps, dupstr("expected a predicate or a parenthesised subexpression"),
@@ -527,7 +506,6 @@ static ExprNode *parse_expr(ParserState *ps)
if (ps->tok != TOK_AND && ps->tok != TOK_OR)
return subexpr;
{ // WINSCP
Token operator = ps->tok;
ExprNode *en = exprnode_new(ps->tok == TOK_AND ? OP_AND : OP_OR,
subexpr->text);
@@ -559,7 +537,6 @@ static ExprNode *parse_expr(ParserState *ps)
return NULL;
}
}
} // WINSCP
}
static ExprNode *parse(ptrlen expr, char **error_msg, ptrlen *error_loc)
@@ -569,7 +546,6 @@ static ExprNode *parse(ptrlen expr, char **error_msg, ptrlen *error_loc)
ps->err = NULL;
advance(ps);
{ // WINSCP
ExprNode *en = parse_expr(ps);
if (en && ps->tok != TOK_END) {
error(ps, dupstr("unexpected text at end of expression"),
@@ -589,29 +565,22 @@ static ExprNode *parse(ptrlen expr, char **error_msg, ptrlen *error_loc)
}
return en;
} // WINSCP
}
static bool eval(ExprNode *en, const char *hostname, unsigned port)
{
switch (en->op) {
case OP_AND:
{ // WINSCP
size_t i;
for (i = 0; i < en->nsubexprs; i++)
for (size_t i = 0; i < en->nsubexprs; i++)
if (!eval(en->subexprs[i], hostname, port))
return false;
return true;
} // WINSCP
case OP_OR:
{ // WINSCP
size_t i;
for (i = 0; i < en->nsubexprs; i++)
for (size_t i = 0; i < en->nsubexprs; i++)
if (eval(en->subexprs[i], hostname, port))
return true;
return false;
} // WINSCP
case OP_NOT:
return !eval(en->subexpr, hostname, port);
@@ -634,11 +603,9 @@ bool cert_expr_match_str(const char *expression,
if (!en)
return false;
{ // WINSCP
bool matched = eval(en, hostname, port);
exprnode_free(en);
return matched;
} // WINSCP
}
bool cert_expr_valid(const char *expression,
@@ -668,8 +635,7 @@ CertExprBuilder *cert_expr_builder_new(void)
void cert_expr_builder_free(CertExprBuilder *eb)
{
size_t i; // WINSCP
for (i = 0; i < eb->nwcs; i++)
for (size_t i = 0; i < eb->nwcs; i++)
sfree(eb->wcs[i]);
sfree(eb->wcs);
sfree(eb);
@@ -698,8 +664,7 @@ void cert_expr_builder_add(CertExprBuilder *eb, const char *wildcard)
char *cert_expr_expression(CertExprBuilder *eb)
{
strbuf *sb = strbuf_new();
size_t i; // WINSCP
for (i = 0; i < eb->nwcs; i++) {
for (size_t i = 0; i < eb->nwcs; i++) {
if (i)
put_dataz(sb, " || ");
put_dataz(sb, eb->wcs[i]);

View File

@@ -475,14 +475,12 @@ bool conf_try_set_str(Conf *conf, int primary, const char *value)
assert(conf_key_info[primary].value_type == CONF_TYPE_STR ||
conf_key_info[primary].value_type == CONF_TYPE_STR_AMBI);
{ // WINSCP
struct conf_entry *entry = snew(struct conf_entry);
entry->key.primary = primary;
entry->value.u.stringval.str = dupstr(value);
entry->value.u.stringval.utf8 = false;
conf_insert(conf, entry);
return true;
} // WINSCP
}
void conf_set_str(Conf *conf, int primary, const char *value)
@@ -499,14 +497,12 @@ bool conf_try_set_utf8(Conf *conf, int primary, const char *value)
assert(conf_key_info[primary].value_type == CONF_TYPE_UTF8 ||
conf_key_info[primary].value_type == CONF_TYPE_STR_AMBI);
{ // WINSCP
struct conf_entry *entry = snew(struct conf_entry);
entry->key.primary = primary;
entry->value.u.stringval.str = dupstr(value);
entry->value.u.stringval.utf8 = true;
conf_insert(conf, entry);
return true;
} // WINSCP
}
void conf_set_utf8(Conf *conf, int primary, const char *value)

View File

@@ -4,8 +4,8 @@
static const ConfSaveEnumValue conf_enum_values_##name[] = { \
__VA_ARGS__ \
}; const ConfSaveEnumType conf_enum_##name = { \
/*.values =*/ conf_enum_values_##name, \
/*.nvalues =*/ lenof(conf_enum_values_##name), \
.values = conf_enum_values_##name, \
.nvalues = lenof(conf_enum_values_##name), \
};
#define VALUE(eval, sval) { eval, sval, false }
@@ -21,8 +21,7 @@
bool conf_enum_map_to_storage(const ConfSaveEnumType *etype,
int confval, int *storageval_out)
{
size_t i; // WINSCP
for (i = 0; i < etype->nvalues; i++)
for (size_t i = 0; i < etype->nvalues; i++)
if (!etype->values[i].obsolete &&
etype->values[i].confval == confval) {
*storageval_out = etype->values[i].storageval;
@@ -34,8 +33,7 @@ bool conf_enum_map_to_storage(const ConfSaveEnumType *etype,
bool conf_enum_map_from_storage(const ConfSaveEnumType *etype,
int storageval, int *confval_out)
{
size_t i; // WINSCP
for (i = 0; i < etype->nvalues; i++)
for (size_t i = 0; i < etype->nvalues; i++)
if (etype->values[i].storageval == storageval) {
*confval_out = etype->values[i].confval;
return true;
@@ -43,9 +41,18 @@ bool conf_enum_map_from_storage(const ConfSaveEnumType *etype,
return false;
}
#define CONF_OPTION(id, subkey_type, value_type, ...) \
{ CONF_TYPE_ ## subkey_type, CONF_TYPE_ ## value_type, __VA_ARGS__ },
#define CONF_OPTION(id, ...) { __VA_ARGS__ },
#define VALUE_TYPE(x) .value_type = CONF_TYPE_ ## x
#define SUBKEY_TYPE(x) .subkey_type = CONF_TYPE_ ## x
#define DEFAULT_INT(x) .default_value.ival = x
#define DEFAULT_STR(x) .default_value.sval = x
#define DEFAULT_BOOL(x) .default_value.bval = x
#define SAVE_KEYWORD(x) .save_keyword = x
#define STORAGE_ENUM(x) .storage_enum = &conf_enum_ ## x
#define SAVE_CUSTOM .save_custom = true
#define LOAD_CUSTOM .load_custom = true
#define NOT_SAVED .not_saved = true
const ConfKeyInfo conf_key_info[] = {
#include "conf.winscp.h"
#include "conf.h"
};

View File

@@ -13,7 +13,6 @@ unsigned decode_utf8(BinarySource *src, DecodeUTF8Failure *err)
/* If the source has no byte available, this will return 0, which
* we'll return immediately and is a reasonable error return anyway */
{ // WINSCP
unsigned char c = get_byte(src);
/* One-byte cases. */
@@ -25,7 +24,6 @@ unsigned decode_utf8(BinarySource *src, DecodeUTF8Failure *err)
return 0xFFFD;
}
{ // WINSCP
unsigned long wc, min;
size_t ncont;
if (c < 0xE0) {
@@ -48,7 +46,6 @@ unsigned decode_utf8(BinarySource *src, DecodeUTF8Failure *err)
*err = DUTF8_E_OUT_OF_DATA;
return 0xFFFD;
}
{ // WINSCP
unsigned char cont = get_byte(src);
if (!(0x80 <= cont && cont < 0xC0)) {
BinarySource_REWIND_TO(src, src->pos - 1);
@@ -57,7 +54,6 @@ unsigned decode_utf8(BinarySource *src, DecodeUTF8Failure *err)
}
wc = (wc << 6) | (cont & 0x3F);
} // WINSCP
}
if (wc < min) {
@@ -74,8 +70,6 @@ unsigned decode_utf8(BinarySource *src, DecodeUTF8Failure *err)
}
*err = DUTF8_SUCCESS;
return wc;
} // WINSCP
} // WINSCP
}
const char *const decode_utf8_error_strings[DUTF8_N_FAILURE_CODES] = {

View File

@@ -23,10 +23,8 @@ wchar_t *decode_utf8_to_wide_string(const char *s)
/* We ignore 'err': if it is set, then the character decode
* function will have emitted U+FFFD REPLACEMENT CHARACTER,
* which is what we'd have done in response anyway. */
{ // WINSCP
DecodeUTF8Failure err;
wlen += decode_utf8_to_wchar(src, ws + wlen, &err);
} // WINSCP
}
/* Reallocate to the final size and append the trailing NUL */

View File

@@ -41,7 +41,7 @@
#include "utils/utils.h"
/* Work around lack of va_copy in old MSC */
#if (defined _MSC_VER || defined WINSCP) && !defined va_copy
#if defined _MSC_VER && !defined va_copy
#define va_copy(a, b) TYPECHECK( \
(va_list *)0 == &(a) && (va_list *)0 == &(b), \
memcpy(&a, &b, sizeof(va_list)))
@@ -60,18 +60,10 @@ char *dupvprintf_inner(char *buf, size_t oldlen, size_t *sizeptr,
{
size_t size = *sizeptr;
sgrowarrayn_nm(buf, size, oldlen, 512);
#if defined _DEBUG && defined IDE
// WORKAROUND
// CodeGuard breaks execution when vsnprintf function returns -1.
// Prevent that by making the buffer large enough not to ever return -1.
// (particularly when called from verify_ssh_host_key for keydisp)
sgrowarrayn_nm(buf, size, oldlen, 4096);
#endif
while (1) {
va_list aq;
va_copy(aq, ap);
{ // WINSCP
int len = vsnprintf(buf + oldlen, size - oldlen, fmt, aq);
va_end(aq);
@@ -89,7 +81,6 @@ char *dupvprintf_inner(char *buf, size_t oldlen, size_t *sizeptr,
* buffer wasn't big enough, so we enlarge it a bit and hope. */
sgrowarray_nm(buf, size, size);
}
} // WINSCP
}
}

View File

@@ -14,12 +14,10 @@ static void key_components_add_str(key_components *kc, const char *name,
KeyComponentType type, ptrlen data)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
{ // WINSCP
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].type = type;
kc->components[n].str = strbuf_dup_nm(data);
} // WINSCP
}
void key_components_add_text(key_components *kc,
@@ -44,12 +42,10 @@ void key_components_add_mp(key_components *kc,
const char *name, mp_int *value)
{
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
{ // WINSCP
size_t n = kc->ncomponents++;
kc->components[n].name = dupstr(name);
kc->components[n].type = KCT_MPINT;
kc->components[n].mp = mp_copy(value);
} // WINSCP
}
void key_components_add_uint(key_components *kc,
@@ -77,8 +73,7 @@ void key_components_add_copy(key_components *kc,
void key_components_free(key_components *kc)
{
size_t i; // WINSCP
for (i = 0; i < kc->ncomponents; i++) {
for (size_t i = 0; i < kc->ncomponents; i++) {
key_component *comp = &kc->components[i];
sfree(comp->name);
switch (comp->type) {

View File

@@ -38,7 +38,7 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
/*
* Copy as much data into psb->buf as will fit.
*/
pinitassert(psb->size < lenof(psb->buf));
assert(psb->size < lenof(psb->buf));
size_t to_consume = lenof(psb->buf) - psb->size;
if (to_consume > len)
to_consume = len;
@@ -50,7 +50,6 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
/*
* Output any full lines in psb->buf.
*/
{ // WINSCP
size_t pos = 0;
while (pos < psb->size) {
char *nlpos = memchr(psb->buf + pos, '\n', psb->size - pos);
@@ -60,12 +59,10 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
/*
* Found a newline in the buffer, so we can output a line.
*/
{ // WINSCP
size_t endpos = nlpos - psb->buf;
while (endpos > pos && (psb->buf[endpos-1] == '\n' ||
psb->buf[endpos-1] == '\r'))
endpos--;
{ // WINSCP
char *msg = dupprintf(
"%s: %.*s", psb->prefix, (int)(endpos - pos), psb->buf + pos);
plug_log(plug, sock, PLUGLOG_PROXY_MSG, NULL, 0, msg, 0);
@@ -73,8 +70,6 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
pos = nlpos - psb->buf + 1;
assert(pos <= psb->size);
} // WINSCP
} // WINSCP
}
/*
@@ -95,7 +90,6 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
/*
* Now move any remaining data up to the front of the buffer.
*/
{ // WINSCP
size_t newsize = psb->size - pos;
if (newsize)
memmove(psb->buf, psb->buf + pos, newsize);
@@ -105,7 +99,5 @@ void log_proxy_stderr(Plug *plug, Socket *sock, ProxyStderrBuf *psb,
* And loop round again if there's more data to be read from
* our input.
*/
} // WINSCP
} // WINSCP
}
}

View File

@@ -248,10 +248,8 @@ static ptrlen BinarySource_get_chars_internal(
break;
(void) consume(1);
}
{ // WINSCP
const char *end = here;
return make_ptrlen(start, end - start);
} // WINSCP
}
ptrlen BinarySource_get_chars(BinarySource *src, const char *include_set)

View File

@@ -20,20 +20,17 @@ void *safemalloc(size_t factor1, size_t factor2, size_t addend)
{
if (factor1 > SIZE_MAX / factor2)
goto fail;
{ // WINSCP
size_t product = factor1 * factor2;
if (addend > SIZE_MAX)
goto fail;
if (product > SIZE_MAX - addend)
goto fail;
{ // WINSCP
size_t size = product + addend;
if (size == 0)
size = 1;
{ // WINSCP
void *p;
#ifdef MINEFIELD
p = minefield_c_malloc(size);
@@ -53,9 +50,6 @@ void *safemalloc(size_t factor1, size_t factor2, size_t addend)
fail:
out_of_memory();
} // WINSCP
} // WINSCP
} // WINSCP
}
void *saferealloc(void *ptr, size_t n, size_t size)
@@ -104,7 +98,7 @@ void *safegrowarray(void *ptr, size_t *allocated, size_t eltsize,
size_t oldlen, size_t extralen, bool secret)
{
/* The largest value we can safely multiply by eltsize */
pinitassert(eltsize > 0);
assert(eltsize > 0);
size_t maxsize = (~(size_t)0) / eltsize;
size_t oldsize = *allocated;
@@ -119,7 +113,6 @@ void *safegrowarray(void *ptr, size_t *allocated, size_t eltsize,
return ptr;
/* Find out how much we need to grow the array by. */
{ // WINSCP
size_t increment = (oldlen + extralen) - oldsize;
/* Invent a new size. We want to grow the array by at least
@@ -133,12 +126,10 @@ void *safegrowarray(void *ptr, size_t *allocated, size_t eltsize,
increment = oldsize / 16;
/* But we also can't grow beyond maxsize. */
{ // WINSCP
size_t maxincr = maxsize - oldsize;
if (increment > maxincr)
increment = maxincr;
{ // WINSCP
size_t newsize = oldsize + increment;
void *toret;
if (secret) {
@@ -153,7 +144,4 @@ void *safegrowarray(void *ptr, size_t *allocated, size_t eltsize,
}
*allocated = newsize;
return toret;
} // WINSCP
} // WINSCP
} // WINSCP
}

View File

@@ -56,8 +56,7 @@ bool ptrlen_endswith(ptrlen whole, ptrlen suffix, ptrlen *tail)
bool ptrlen_contains(ptrlen input, const char *characters)
{
const char *p, *end; // WINSCP
for (p = input.ptr, end = p + input.len; p < end; p++)
for (const char *p = input.ptr, *end = p + input.len; p < end; p++)
if (strchr(characters, *p))
return true;
return false;
@@ -65,8 +64,7 @@ bool ptrlen_contains(ptrlen input, const char *characters)
bool ptrlen_contains_only(ptrlen input, const char *characters)
{
const char *p, *end; // WINSCP
for (p = input.ptr, end = p + input.len; p < end; p++)
for (const char *p = input.ptr, *end = p + input.len; p < end; p++)
if (!strchr(characters, *p))
return false;
return true;
@@ -84,14 +82,12 @@ ptrlen ptrlen_get_word(ptrlen *input, const char *separators)
p++;
toret.len = p - (const char *)toret.ptr;
{ // WINSCP
size_t to_consume = p - (const char *)input->ptr;
assert(to_consume <= input->len);
input->ptr = (const char *)input->ptr + to_consume;
input->len -= to_consume;
return toret;
} // WINSCP
}
char *mkstr(ptrlen pl)

View File

@@ -16,8 +16,7 @@ SeatDialogText *seat_dialog_text_new(void)
void seat_dialog_text_free(SeatDialogText *sdt)
{
size_t i; // WINSCP
for (i = 0; i < sdt->nitems; i++)
for (size_t i = 0; i < sdt->nitems; i++)
sfree(sdt->items[i].text);
sfree(sdt->items);
sfree(sdt);
@@ -27,11 +26,9 @@ static void seat_dialog_text_append_v(
SeatDialogText *sdt, SeatDialogTextType type, const char *fmt, va_list ap)
{
sgrowarray(sdt->items, sdt->itemsize, sdt->nitems);
{ // WINSCP
SeatDialogTextItem *item = &sdt->items[sdt->nitems++];
item->type = type;
item->text = dupvprintf(fmt, ap);
} // WINSCP
}
void seat_dialog_text_append(SeatDialogText *sdt, SeatDialogTextType type,

View File

@@ -320,7 +320,6 @@ static void stripctrl_locale_BinarySink_write(
to_copy = len;
memcpy(scc->buf + scc->buflen, p, to_copy);
{ // WINSCP
size_t consumed = stripctrl_locale_try_consume(
scc, scc->buf, scc->buflen + to_copy);
@@ -370,7 +369,6 @@ static void stripctrl_locale_BinarySink_write(
*/
scc->buflen -= consumed;
memmove(scc->buf, scc->buf + consumed, scc->buflen);
} // WINSCP
}
/*

View File

@@ -331,36 +331,35 @@ static bool tempseat_eof(Seat *seat)
*/
static const struct SeatVtable tempseat_vt = {
// WINSCP
/*.output =*/ tempseat_output,
/*.eof =*/ tempseat_eof,
/*.sent =*/ nullseat_sent,
/*.banner =*/ tempseat_banner,
/*.get_userpass_input =*/ tempseat_get_userpass_input,
/*.notify_session_started =*/ tempseat_notify_session_started,
/*.notify_remote_exit =*/ tempseat_notify_remote_exit,
/*.notify_remote_disconnect =*/ tempseat_notify_remote_disconnect,
/*.connection_fatal =*/ tempseat_connection_fatal,
/*.nonfatal =*/ tempseat_nonfatal,
/*.update_specials_menu =*/ tempseat_update_specials_menu,
/*.get_ttymode =*/ tempseat_get_ttymode,
/*.set_busy_status =*/ tempseat_set_busy_status,
/*.confirm_ssh_host_key =*/ tempseat_confirm_ssh_host_key,
/*.confirm_weak_crypto_primitive =*/ tempseat_confirm_weak_crypto_primitive,
/*.confirm_weak_cached_hostkey =*/ tempseat_confirm_weak_cached_hostkey,
/*.prompt_descriptions =*/ tempseat_prompt_descriptions,
/*.is_utf8 =*/ tempseat_is_utf8,
/*.echoedit_update =*/ tempseat_echoedit_update,
/*.get_x_display =*/ tempseat_get_x_display,
/*.get_windowid =*/ tempseat_get_windowid,
/*.get_window_pixel_size =*/ tempseat_get_window_pixel_size,
/*.stripctrl_new =*/ tempseat_stripctrl_new,
/*.set_trust_status =*/ tempseat_set_trust_status,
/*.can_set_trust_status =*/ tempseat_can_set_trust_status,
/*.has_mixed_input_stream =*/ tempseat_has_mixed_input_stream,
/*.verbose =*/ tempseat_verbose,
/*.interactive =*/ tempseat_interactive,
/*.get_cursor_position =*/ tempseat_get_cursor_position,
.output = tempseat_output,
.eof = tempseat_eof,
.sent = nullseat_sent,
.banner = tempseat_banner,
.get_userpass_input = tempseat_get_userpass_input,
.notify_session_started = tempseat_notify_session_started,
.notify_remote_exit = tempseat_notify_remote_exit,
.notify_remote_disconnect = tempseat_notify_remote_disconnect,
.connection_fatal = tempseat_connection_fatal,
.nonfatal = tempseat_nonfatal,
.update_specials_menu = tempseat_update_specials_menu,
.get_ttymode = tempseat_get_ttymode,
.set_busy_status = tempseat_set_busy_status,
.confirm_ssh_host_key = tempseat_confirm_ssh_host_key,
.confirm_weak_crypto_primitive = tempseat_confirm_weak_crypto_primitive,
.confirm_weak_cached_hostkey = tempseat_confirm_weak_cached_hostkey,
.prompt_descriptions = tempseat_prompt_descriptions,
.is_utf8 = tempseat_is_utf8,
.echoedit_update = tempseat_echoedit_update,
.get_x_display = tempseat_get_x_display,
.get_windowid = tempseat_get_windowid,
.get_window_pixel_size = tempseat_get_window_pixel_size,
.stripctrl_new = tempseat_stripctrl_new,
.set_trust_status = tempseat_set_trust_status,
.can_set_trust_status = tempseat_can_set_trust_status,
.has_mixed_input_stream = tempseat_has_mixed_input_stream,
.verbose = tempseat_verbose,
.interactive = tempseat_interactive,
.get_cursor_position = tempseat_get_cursor_position,
};
Seat *tempseat_new(Seat *realseat)
@@ -383,14 +382,14 @@ bool is_tempseat(Seat *seat)
Seat *tempseat_get_real(Seat *seat)
{
pinitassert(seat->vt == &tempseat_vt);
assert(seat->vt == &tempseat_vt);
TempSeat *ts = container_of(seat, TempSeat, seat);
return ts->realseat;
}
void tempseat_free(Seat *seat)
{
pinitassert(seat->vt == &tempseat_vt);
assert(seat->vt == &tempseat_vt);
TempSeat *ts = container_of(seat, TempSeat, seat);
bufchain_clear(&ts->output);
while (ts->outchunk_head) {
@@ -403,7 +402,7 @@ void tempseat_free(Seat *seat)
void tempseat_flush(Seat *seat)
{
pinitassert(seat->vt == &tempseat_vt);
assert(seat->vt == &tempseat_vt);
TempSeat *ts = container_of(seat, TempSeat, seat);
/* Empty the output bufchains into the real seat, taking care to
@@ -411,7 +410,7 @@ void tempseat_flush(Seat *seat)
while (bufchain_size(&ts->output)) {
ptrlen pl = bufchain_prefix(&ts->output);
pinitassert(ts->outchunk_head);
assert(ts->outchunk_head);
struct output_chunk *chunk = ts->outchunk_head;
if (pl.len > chunk->size)

View File

@@ -9,8 +9,7 @@
void BinarySink_put_c_string_literal(BinarySink *bs, ptrlen str)
{
const char *p; // WINSCP
for (p = str.ptr; p < (const char *)str.ptr + str.len; p++) {
for (const char *p = str.ptr; p < (const char *)str.ptr + str.len; p++) {
char c = *p;
if (c == '\n')

View File

@@ -165,11 +165,9 @@ static int named_pipe_agent_accumulate_response(
if (length_field > AGENT_MAX_MSGLEN)
return -1; /* badly formatted message */
{ // WINSCP
int overall_length = length_field + 4;
if (sb->len >= overall_length)
return overall_length;
} // WINSCP
}
return 0; /* not done yet */
@@ -186,7 +184,6 @@ static size_t named_pipe_agent_gotdata(
return 0;
}
{ // WINSCP
int status = named_pipe_agent_accumulate_response(pq->response, data, len);
if (status == -1) {
pq->callback(pq->callback_ctx, NULL, 0);
@@ -198,7 +195,6 @@ static size_t named_pipe_agent_gotdata(
agent_cancel_query(pq);
}
return 0;
} // WINSCP
}
static agent_pending_query *named_pipe_agent_query(
@@ -217,9 +213,7 @@ static agent_pending_query *named_pipe_agent_query(
strbuf_finalise_agent_query(query);
{ // WINSCP
DWORD done; // WINSCP
for (done = 0; done < query->len ;) {
for (DWORD done = 0; done < query->len ;) {
DWORD nwritten;
bool ret = WriteFile(pipehandle, query->s + done, query->len - done,
&nwritten, NULL);
@@ -274,7 +268,6 @@ static agent_pending_query *named_pipe_agent_query(
if (sb)
strbuf_free(sb);
return pq;
} // WINSCP
}
void agent_cancel_query(agent_pending_query *pq)

View File

@@ -141,7 +141,6 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
/* MIT Kerberos GSSAPI implementation */
module = NULL;
putty_registry_pass(true);
{ // WINSCP
HKEY regkey = open_regkey_ro(HKEY_LOCAL_MACHINE,
"SOFTWARE\\MIT\\Kerberos");
if (regkey) {
@@ -156,7 +155,6 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
sfree(dllPath);
}
{ // WINSCP
char *dllfile = dupcat(bindir, "\\gssapi"MIT_KERB_SUFFIX".dll");
module = LoadLibraryEx(dllfile, NULL,
LOAD_LIBRARY_SEARCH_SYSTEM32 |
@@ -182,7 +180,6 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
sfree(dllfile);
sfree(bindir);
sfree(installdir);
} // WINSCP
}
close_regkey(regkey);
}
@@ -242,7 +239,6 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
* Custom GSSAPI DLL.
*/
module = NULL;
{ // WINSCP
Filename *customlib = conf_get_filename(conf, CONF_ssh_gss_custom);
if (!filename_is_null(customlib)) {
const wchar_t *path = customlib->wpath;
@@ -311,8 +307,6 @@ struct ssh_gss_liblist *ssh_gss_setup(Conf *conf, LogContext *logctx) // MPEXT
return list;
} // WINSCP
} // WINSCP
}
void ssh_gss_cleanup(struct ssh_gss_liblist *list)
@@ -406,39 +400,6 @@ static Ssh_gss_stat ssh_sspi_acquire_cred(struct ssh_gss_library *lib,
return SSH_GSS_OK;
}
#ifdef MPEXT
static SecBuffer ssh_gss_init_sec_buffer(unsigned long buffersize,
unsigned long buffertype, void * buffer)
{
SecBuffer result;
result.cbBuffer = buffersize;
result.BufferType = buffertype;
result.pvBuffer = buffer;
return result;
}
static SecBufferDesc ssh_gss_init_sec_buffer_desc(unsigned long version,
unsigned long bufferscount, PSecBuffer buffers)
{
SecBufferDesc result;
result.ulVersion = version;
result.cBuffers = bufferscount;
result.pBuffers = buffers;
return result;
}
#define MPEXT_INIT_SEC_BUFFER(BUFFERSIZE, BUFFERTYPE, BUFFER) \
ssh_gss_init_sec_buffer(BUFFERSIZE, BUFFERTYPE, BUFFER)
#define MPEXT_INIT_SEC_BUFFERDESC(VERSION, BUFFERSCOUNT, BUFFERS) \
ssh_gss_init_sec_buffer_desc(VERSION, BUFFERSCOUNT, BUFFERS)
#else
#define MPEXT_INIT_SEC_BUFFER(BUFFERSIZE, BUFFERTYPE, BUFFER) \
{BUFFERSIZE, BUFFERTYPE, BUFFER}
#define MPEXT_INIT_SEC_BUFFERDESC(VERSION, BUFFERSCOUNT, BUFFERS) \
{VERSION, BUFFERSCOUNT, BUFFERS}
#endif
static void localexp_to_exp_lifetime(TimeStamp *localexp,
time_t *expiry, unsigned long *lifetime)
{
@@ -502,10 +463,10 @@ static Ssh_gss_stat ssh_sspi_init_sec_context(struct ssh_gss_library *lib,
unsigned long *lifetime)
{
winSsh_gss_ctx *winctx = (winSsh_gss_ctx *) *ctx;
SecBuffer wsend_tok = MPEXT_INIT_SEC_BUFFER(send_tok->length,SECBUFFER_TOKEN,send_tok->value);
SecBuffer wrecv_tok = MPEXT_INIT_SEC_BUFFER(recv_tok->length,SECBUFFER_TOKEN,recv_tok->value);
SecBufferDesc output_desc = MPEXT_INIT_SEC_BUFFERDESC(SECBUFFER_VERSION,1,&wsend_tok);
SecBufferDesc input_desc = MPEXT_INIT_SEC_BUFFERDESC(SECBUFFER_VERSION,1,&wrecv_tok);
SecBuffer wsend_tok = {send_tok->length,SECBUFFER_TOKEN,send_tok->value};
SecBuffer wrecv_tok = {recv_tok->length,SECBUFFER_TOKEN,recv_tok->value};
SecBufferDesc output_desc = {SECBUFFER_VERSION,1,&wsend_tok};
SecBufferDesc input_desc = {SECBUFFER_VERSION,1,&wrecv_tok};
unsigned long flags=ISC_REQ_MUTUAL_AUTH|ISC_REQ_REPLAY_DETECT|
ISC_REQ_CONFIDENTIALITY|ISC_REQ_ALLOCATE_MEMORY;
ULONG ret_flags=0;

View File

@@ -504,7 +504,6 @@ struct handle *handle_input_new(struct callback_set * callback_set, HANDLE handl
h->u.i.callback_set = callback_set; // WINSCP
ensure_ready_event_setup(callback_set);
{ // WINSCP
HANDLE hThread = CreateThread(NULL, 0, handle_input_threadfunc,
&h->u.i, 0, &in_threadid);
if (hThread)
@@ -512,7 +511,6 @@ struct handle *handle_input_new(struct callback_set * callback_set, HANDLE handl
h->u.i.busy = true;
return h;
} // WINSCP
}
struct handle *handle_output_new(struct callback_set * callback_set, HANDLE handle, handle_outputfn_t sentdata, // WINSCP
@@ -537,14 +535,12 @@ struct handle *handle_output_new(struct callback_set * callback_set, HANDLE hand
h->u.o.callback_set = callback_set; // WINSCP
ensure_ready_event_setup(callback_set);
{ // WINSCP
HANDLE hThread = CreateThread(NULL, 0, handle_output_threadfunc,
&h->u.o, 0, &out_threadid);
if (hThread)
CloseHandle(hThread); /* we don't need the thread handle */
return h;
} // WINSCP
}
size_t handle_write(struct handle *h, const void *data, size_t len)
@@ -602,7 +598,7 @@ void handle_free(struct handle *h)
* There isn't even a subthread; we can go straight to
* handle_destroy.
*/
handle_destroy(h); // WINSCP
handle_destroy(h);
} else {
/*
* The subthread is alive but not busy, so we now signal it
@@ -629,7 +625,7 @@ static bool handle_ready(struct handle *h) // WINSCP
* we haven't yet done so, or destroy the handle if not.
*/
if (h->u.g.done) {
handle_destroy(h); // WINSCP
handle_destroy(h);
} else {
h->u.g.done = true;
h->u.g.busy = true;

Some files were not shown because too many files have changed in this diff Show More