├── .clang-format ├── .gitignore ├── CHANGELOG.md ├── LICENCE.md ├── Makefile ├── README.md ├── _crypto-test_dh_x25519.inc ├── _crypto-test_hash_sha256.inc ├── _crypto-test_hash_sha512.inc ├── _crypto-test_kem_sntrup761.inc ├── _crypto-test_onetimeauth_poly1305.inc ├── _crypto-test_sign_ed25519.inc ├── _crypto-test_sort_uint32.inc ├── _crypto-test_verify_16.inc ├── _crypto-test_verify_32.inc ├── _tinysshd-printkex.c ├── _tinysshd-speed.c ├── _tinysshd-test-hello1.c ├── _tinysshd-test-hello2.c ├── _tinysshd-test-kex1.c ├── _tinysshd-test-kex2.c ├── _tinysshd-unauthenticated.c ├── blocking.c ├── blocking.h ├── buf.c ├── buf.h ├── bug.h ├── byte.c ├── byte.h ├── channel.c ├── channel.h ├── channel_drop.c ├── channel_fork.c ├── channel_forkpty.c ├── channel_subsystem.c ├── cleanup.c ├── cleanup.h ├── coe.c ├── coe.h ├── connectioninfo.c ├── connectioninfo.h ├── crypto.h ├── crypto_declassify.h ├── crypto_dh_x25519.c ├── crypto_dh_x25519.h ├── crypto_hash_sha256.c ├── crypto_hash_sha256.h ├── crypto_hash_sha512.h ├── crypto_hash_sha512_lib25519.c ├── crypto_hash_sha512_tinyssh.c ├── crypto_kem_sntrup761.h ├── crypto_kem_sntrup761_libntruprime.c ├── crypto_kem_sntrup761_tinyssh.c ├── crypto_kem_sntrup761x25519.c ├── crypto_kem_sntrup761x25519.h ├── crypto_onetimeauth_poly1305.h ├── crypto_onetimeauth_poly1305_lib1305.c ├── crypto_onetimeauth_poly1305_tinyssh.c ├── crypto_scalarmult_curve25519.c ├── crypto_scalarmult_curve25519.h ├── crypto_sign_ed25519.h ├── crypto_sign_ed25519_lib25519.c ├── crypto_sign_ed25519_tinyssh.c ├── crypto_sort_uint32.c ├── crypto_sort_uint32.h ├── crypto_stream_chacha20.c ├── crypto_stream_chacha20.h ├── crypto_verify_16.c ├── crypto_verify_16.h ├── crypto_verify_32.c ├── crypto_verify_32.h ├── cryptoint ├── LICENSE ├── README ├── autogen ├── create.py ├── crypto_int16.h ├── crypto_int32.h ├── crypto_int64.h ├── crypto_int8.h ├── crypto_intN.h ├── crypto_uint16.h ├── crypto_uint32.h ├── crypto_uint64.h ├── crypto_uint8.h ├── crypto_uintN.h ├── functions ├── int16_optblocker.c ├── int32_optblocker.c ├── int64_optblocker.c ├── int8_optblocker.c ├── intN_optblocker.c ├── namespace ├── readasm.py ├── specialize.py ├── uint16_optblocker.c ├── uint32_optblocker.c ├── uint64_optblocker.c ├── uint8_optblocker.c ├── uintN_optblocker.c └── version ├── die.c ├── die.h ├── dropuidgid.c ├── dropuidgid.h ├── e.c ├── e.h ├── env.c ├── env.h ├── fe.c ├── fe.h ├── fe25519.c ├── fe25519.h ├── ge25519.c ├── ge25519.h ├── getln.c ├── getln.h ├── global.c ├── global.h ├── haslib1305.c ├── haslib25519.c ├── haslibntruprime.c ├── haslibrandombytes.c ├── haslibutilh.c ├── haslimits.c ├── haslogintty.c ├── hasmlock.c ├── hasopenpty.c ├── hasutilh.c ├── hasutmp.c ├── hasutmpaddrv6.c ├── hasutmphost.c ├── hasutmploginlogout.c ├── hasutmplogwtmp.c ├── hasutmpname.c ├── hasutmppid.c ├── hasutmptime.c ├── hasutmptv.c ├── hasutmptype.c ├── hasutmpuser.c ├── hasutmpx.c ├── hasutmpxaddrv6.c ├── hasutmpxsyslen.c ├── hasutmpxupdwtmpx.c ├── hasvalgrind.c ├── int16_optblocker.c ├── int32_optblocker.c ├── int64_optblocker.c ├── int8_optblocker.c ├── iptostr.c ├── iptostr.h ├── limit.h ├── load.c ├── load.h ├── log.c ├── log.h ├── loginshell.c ├── loginshell.h ├── logsys.c ├── logsys.h ├── main.h ├── main_tinysshd.c ├── main_tinysshd_makekey.c ├── main_tinysshd_printkey.c ├── makefilegen.sh ├── man ├── tinysshd-makekey.8 ├── tinysshd-printkey.8 ├── tinysshd.8 └── tinysshnoneauthd.8 ├── newenv.c ├── newenv.h ├── numtostr.c ├── numtostr.h ├── old ├── INSTALL ├── LICENCE ├── Makefile ├── README.md ├── _tinyssh │ ├── _TARGETS │ ├── _tinysshd-printkex.c │ ├── _tinysshd-speed.c │ ├── _tinysshd-test-hello1.c │ ├── _tinysshd-test-hello2.c │ ├── _tinysshd-test-kex1.c │ ├── _tinysshd-test-kex2.c │ └── _tinysshd-unauthenticated.c ├── conf-ar ├── conf-bin ├── conf-cc ├── conf-cflags ├── conf-libs ├── conf-man ├── crypto-tests │ ├── crypto_dh_x25519test.c │ ├── crypto_hash_sha256test.c │ ├── crypto_hash_sha512test.c │ ├── crypto_kem_sntrup761test.c │ ├── crypto_kem_sntrup761test.data │ ├── crypto_kem_sntrup761x25519test.c │ ├── crypto_kem_sntrup761x25519test.data │ ├── crypto_onetimeauth_poly1305test.c │ ├── crypto_scalarmult_curve25519test.c │ ├── crypto_sign_ed25519test.c │ ├── crypto_sort_uint32test.c │ ├── crypto_stream_chacha20test.c │ ├── crypto_verify_16test.c │ ├── crypto_verify_32test.c │ ├── misc.h │ ├── precomp.data │ ├── precomp.data.py │ ├── precomp.txt │ ├── precomp_curve25519.data │ ├── precomp_curve25519.data.py │ ├── precomp_ed25519.data │ ├── precomp_ed25519.data.py │ └── randombytestest.c ├── crypto │ ├── CRYPTOLIBS │ ├── CRYPTOPRIMITIVES │ ├── CRYPTOSOURCES │ ├── cleanup.c │ ├── cleanup.h │ ├── crypto_declassify.h │ ├── crypto_dh_x25519.c │ ├── crypto_dh_x25519.h │ ├── crypto_hash_sha256.c │ ├── crypto_hash_sha256.h │ ├── crypto_hash_sha512.c │ ├── crypto_hash_sha512.h │ ├── crypto_int16.h │ ├── crypto_int32.h │ ├── crypto_int64.h │ ├── crypto_int8.h │ ├── crypto_kem_sntrup761.c │ ├── crypto_kem_sntrup761.h │ ├── crypto_kem_sntrup761x25519.c │ ├── crypto_kem_sntrup761x25519.h │ ├── crypto_onetimeauth_poly1305.c │ ├── crypto_onetimeauth_poly1305.h │ ├── crypto_scalarmult_curve25519.c │ ├── crypto_scalarmult_curve25519.h │ ├── crypto_sign_ed25519.c │ ├── crypto_sign_ed25519.h │ ├── crypto_sort_uint32.c │ ├── crypto_sort_uint32.h │ ├── crypto_stream_chacha20.c │ ├── crypto_stream_chacha20.h │ ├── crypto_uint16.h │ ├── crypto_uint32.h │ ├── crypto_uint64.h │ ├── crypto_uint8.h │ ├── crypto_verify_16.c │ ├── crypto_verify_16.h │ ├── crypto_verify_32.c │ ├── crypto_verify_32.h │ ├── fe.c │ ├── fe.h │ ├── fe25519.c │ ├── fe25519.h │ ├── ge25519.c │ ├── ge25519.h │ ├── randombytes.c │ ├── randombytes.h │ ├── sc25519.c │ ├── sc25519.h │ ├── uint16_optblocker.c │ ├── uint32_optblocker.c │ ├── uint64_optblocker.c │ └── uint8_optblocker.c ├── make-install.sh ├── make-tinyssh.sh ├── make-tinysshcc.sh ├── man ├── sysdep │ ├── default.h-no.c │ ├── default.h-no.out │ ├── haslibutilh.h-yes.c │ ├── haslibutilh.h-yes.out │ ├── haslimits.h-yes.c │ ├── haslimits.h-yes.out │ ├── haslogintty.h-yes.c │ ├── haslogintty.h-yes.out │ ├── hasmlock.h-yes.c │ ├── hasmlock.h-yes.out │ ├── hasopenpty.h-yes.c │ ├── hasopenpty.h-yes.out │ ├── hasutilh.h-yes.c │ ├── hasutilh.h-yes.out │ ├── hasutmp.h-yes.c │ ├── hasutmp.h-yes.out │ ├── hasutmpaddrv6.h-yes.c │ ├── hasutmpaddrv6.h-yes.out │ ├── hasutmphost.h-yes.c │ ├── hasutmphost.h-yes.out │ ├── hasutmploginlogout.h-yes.c │ ├── hasutmploginlogout.h-yes.out │ ├── hasutmplogwtmp.h-yes.c │ ├── hasutmplogwtmp.h-yes.out │ ├── hasutmpname.h-yes.c │ ├── hasutmpname.h-yes.out │ ├── hasutmppid.h-yes.c │ ├── hasutmppid.h-yes.out │ ├── hasutmptime.h-yes.c │ ├── hasutmptime.h-yes.out │ ├── hasutmptv.h-yes.c │ ├── hasutmptv.h-yes.out │ ├── hasutmptype.h-yes.c │ ├── hasutmptype.h-yes.out │ ├── hasutmpuser.h-yes.c │ ├── hasutmpuser.h-yes.out │ ├── hasutmpx.h-yes.c │ ├── hasutmpx.h-yes.out │ ├── hasutmpxaddrv6.h-yes.c │ ├── hasutmpxaddrv6.h-yes.out │ ├── hasutmpxsyslen.h-yes.c │ ├── hasutmpxsyslen.h-yes.out │ ├── hasutmpxupdwtmpx.h-yes.c │ ├── hasutmpxupdwtmpx.h-yes.out │ ├── hasvalgrind.h-yes.c │ └── list ├── tinyssh-tests │ ├── blockingtest.c │ ├── buftest.c │ ├── bytetest.c │ ├── channel_droptest.c │ ├── channel_forkptytest.c │ ├── channel_forktest.c │ ├── channel_subsystemtest.c │ ├── channeltest.c │ ├── coetest.c │ ├── connectioninfotest.c │ ├── dietest.c │ ├── dropuidgidtest.c │ ├── emptytest.c │ ├── envtest.c │ ├── etest.c │ ├── fail.h │ ├── forkptytest.c │ ├── getlntest.c │ ├── globaltest.c │ ├── iptostrtest.c │ ├── loadtest.c │ ├── loginshelltest.c │ ├── logsystest.c │ ├── logtest.c │ ├── main_tinysshd_makekeytest.c │ ├── main_tinysshd_printkeytest.c │ ├── main_tinysshdtest.c │ ├── newenvtest.c │ ├── numtostrtest.c │ ├── opentest.c │ ├── packet_authtest.c │ ├── packet_channel_opentest.c │ ├── packet_channel_recvtest.c │ ├── packet_channel_requesttest.c │ ├── packet_channel_sendtest.c │ ├── packet_gettest.c │ ├── packet_hellotest.c │ ├── packet_kexdhtest.c │ ├── packet_kextest.c │ ├── packet_puttest.c │ ├── packet_recvtest.c │ ├── packet_sendtest.c │ ├── packet_unimplementedtest.c │ ├── packetparsertest.c │ ├── packettest.c │ ├── porttostrtest.c │ ├── randommodtest.c │ ├── readalltest.c │ ├── run.h │ ├── savesynctest.c │ ├── sshcrypto_cipher_chachapolytest.c │ ├── sshcrypto_ciphertest.c │ ├── sshcrypto_kex_curve25519test.c │ ├── sshcrypto_kex_sntrup761x25519test.c │ ├── sshcrypto_kextest.c │ ├── sshcrypto_key_ed25519test.c │ ├── sshcrypto_keytest.c │ ├── sshcryptotest.c │ ├── sshtest.c │ ├── stringparsertest.c │ ├── strtest.c │ ├── subprocess_authtest.c │ ├── subprocess_signtest.c │ ├── trymlocktest.c │ └── writealltest.c ├── tinyssh │ ├── LIBS │ ├── LINKS │ ├── SOURCES │ ├── TARGETS │ ├── blocking.c │ ├── blocking.h │ ├── buf.c │ ├── buf.h │ ├── bug.h │ ├── byte.c │ ├── byte.h │ ├── channel.c │ ├── channel.h │ ├── channel_drop.c │ ├── channel_fork.c │ ├── channel_forkpty.c │ ├── channel_subsystem.c │ ├── coe.c │ ├── coe.h │ ├── connectioninfo.c │ ├── connectioninfo.h │ ├── die.c │ ├── die.h │ ├── dropuidgid.c │ ├── dropuidgid.h │ ├── e.c │ ├── e.h │ ├── env.c │ ├── env.h │ ├── getln.c │ ├── getln.h │ ├── global.c │ ├── global.h │ ├── iptostr.c │ ├── iptostr.h │ ├── limit.h │ ├── load.c │ ├── load.h │ ├── log.c │ ├── log.h │ ├── loginshell.c │ ├── loginshell.h │ ├── logsys.c │ ├── logsys.h │ ├── main.h │ ├── main_tinysshd.c │ ├── main_tinysshd_makekey.c │ ├── main_tinysshd_printkey.c │ ├── newenv.c │ ├── newenv.h │ ├── numtostr.c │ ├── numtostr.h │ ├── open.c │ ├── open.h │ ├── packet.c │ ├── packet.h │ ├── packet_auth.c │ ├── packet_channel_open.c │ ├── packet_channel_recv.c │ ├── packet_channel_request.c │ ├── packet_channel_send.c │ ├── packet_get.c │ ├── packet_hello.c │ ├── packet_kex.c │ ├── packet_kexdh.c │ ├── packet_put.c │ ├── packet_recv.c │ ├── packet_send.c │ ├── packet_unimplemented.c │ ├── packetparser.c │ ├── packetparser.h │ ├── porttostr.c │ ├── porttostr.h │ ├── purge.h │ ├── randommod.c │ ├── randommod.h │ ├── readall.c │ ├── readall.h │ ├── savesync.c │ ├── savesync.h │ ├── ssh.c │ ├── ssh.h │ ├── sshcrypto.c │ ├── sshcrypto.h │ ├── sshcrypto_cipher.c │ ├── sshcrypto_cipher_chachapoly.c │ ├── sshcrypto_kex.c │ ├── sshcrypto_kex_curve25519.c │ ├── sshcrypto_kex_sntrup761x25519.c │ ├── sshcrypto_key.c │ ├── sshcrypto_key_ed25519.c │ ├── str.c │ ├── str.h │ ├── stringparser.c │ ├── stringparser.h │ ├── subprocess.h │ ├── subprocess_auth.c │ ├── subprocess_sign.c │ ├── tinysshd-makekey.c │ ├── tinysshd-makekey.exp │ ├── tinysshd-makekey.rts │ ├── tinysshd-printkey.c │ ├── tinysshd-printkey.exp │ ├── tinysshd-printkey.rts │ ├── tinysshd.c │ ├── tinysshd.exp │ ├── tinysshd.rts │ ├── tinysshnoneauthd.c │ ├── tinysshnoneauthd.exp │ ├── tinysshnoneauthd.rts │ ├── trymlock.c │ ├── trymlock.h │ ├── writeall.c │ └── writeall.h └── tools ├── open.c ├── open.h ├── packet.c ├── packet.h ├── packet_auth.c ├── packet_channel_open.c ├── packet_channel_recv.c ├── packet_channel_request.c ├── packet_channel_send.c ├── packet_get.c ├── packet_hello.c ├── packet_kex.c ├── packet_kexdh.c ├── packet_put.c ├── packet_recv.c ├── packet_send.c ├── packet_unimplemented.c ├── packetparser.c ├── packetparser.h ├── porttostr.c ├── porttostr.h ├── purge.h ├── randombytes.c ├── randombytes.h ├── randommod.c ├── randommod.h ├── readall.c ├── readall.h ├── runtest.sh ├── savesync.c ├── savesync.h ├── sc25519.c ├── sc25519.h ├── ssh.c ├── ssh.h ├── sshcrypto.c ├── sshcrypto.h ├── sshcrypto_cipher.c ├── sshcrypto_cipher_chachapoly.c ├── sshcrypto_kex.c ├── sshcrypto_kex_curve25519.c ├── sshcrypto_kex_sntrup761x25519.c ├── sshcrypto_key.c ├── sshcrypto_key_ed25519.c ├── str.c ├── str.h ├── stringparser.c ├── stringparser.h ├── subprocess.h ├── subprocess_auth.c ├── subprocess_sign.c ├── test-crypto-dh.exp ├── test-crypto-dh.sh ├── test-crypto-hash.exp ├── test-crypto-hash.sh ├── test-crypto-kem.exp ├── test-crypto-kem.sh ├── test-crypto-onetimeauth.exp ├── test-crypto-onetimeauth.sh ├── test-crypto-sign.exp ├── test-crypto-sign.sh ├── test-crypto-sort.exp ├── test-crypto-sort.sh ├── test-crypto-verify.exp ├── test-crypto-verify.sh ├── test-crypto.c ├── test-tinysshd-makekey.exp ├── test-tinysshd-makekey.sh ├── test-tinysshd-printkey.exp ├── test-tinysshd-printkey.sh ├── test-tinysshd.exp ├── test-tinysshd.sh ├── test-tinysshnoneauthd.exp ├── test-tinysshnoneauthd.sh ├── tinysshd.c ├── tools └── tinyssh-convert ├── tryfeature.sh ├── trylibs.sh ├── trymlock.c ├── trymlock.h ├── uint16_optblocker.c ├── uint32_optblocker.c ├── uint64_optblocker.c ├── uint8_optblocker.c ├── writeall.c └── writeall.h /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | TinySSH is hereby placed into the public domain. 2 | 3 | SPDX-License-Identifier: CC0-1.0 OR 0BSD OR MIT-0 OR MIT 4 | 5 | - [CC0-1.0](https://spdx.org/licenses/CC0-1.0.html) 6 | - [0BSD](https://spdx.org/licenses/0BSD.html) 7 | - [MIT-0](https://spdx.org/licenses/MIT-0.html) 8 | - [MIT](https://spdx.org/licenses/MIT.html) 9 | 10 | Comment: 11 | "Public domain" works differently depending on the country, therefore LICENCE updated to CC0-1.0 OR 0BSD OR MIT-0 OR MIT. 12 | 13 | History: 14 | - initial release - public domain 15 | - 20230101 - CC0 16 | - 20250201 - CC0-1.0 OR 0BSD OR MIT-0 OR MIT. 17 | 18 | Other: 19 | _crypto-test_*.inc: derived from djb work from supercop/lib25519/libntruprime/lib1305, license: LicenseRef-PD-hp OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT 20 | cryptoint/*: copy of cryptoint library from D. J. Bernstein, see cryptoint/README.md, license: LicenseRef-PD-hp OR CC0-1.0 OR 0BSD OR MIT-0 OR MIT 21 | -------------------------------------------------------------------------------- /_crypto-test_verify_16.inc: -------------------------------------------------------------------------------- 1 | /* ----- verify, derived from supercop/crypto_verify/try.c */ 2 | 3 | /* 4 | derived from djb work from lib25519/libntruprime 5 | mj modifications: 6 | - rename files to test-crypto.c and _crypto_<>.<>.inc 7 | - fix compiler warnings 8 | - include crypto.h 9 | - use less rounds for valgrind test 10 | - reformat using clang-format 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "crypto.h" 18 | 19 | static unsigned char *test_verify_16_x; 20 | static unsigned char *test_verify_16_y; 21 | 22 | static void test_verify_16_check(void) { 23 | unsigned char *x = test_verify_16_x; 24 | unsigned char *y = test_verify_16_y; 25 | int r; 26 | 27 | secret(x, 16); 28 | secret(y, 16); 29 | r = crypto_verify_16(x, y); 30 | public(x, 16); 31 | public(y, 16); 32 | public(&r, sizeof r); 33 | 34 | if (r == 0) { 35 | if (memcmp(x, y, 16)) fail("failure: different strings pass verify\n"); 36 | } 37 | else if (r == -1) { 38 | if (!memcmp(x, y, 16)) fail("failure: equal strings fail verify\n"); 39 | } 40 | else { fail("failure: weird return value\n"); } 41 | } 42 | 43 | void test_verify_16_impl(long long impl) { 44 | unsigned char *x = test_verify_16_x; 45 | unsigned char *y = test_verify_16_y; 46 | 47 | if (targetn && atol(targetn) != impl) return; 48 | 49 | randombytes(x, 16); 50 | randombytes(y, 16); 51 | test_verify_16_check(); 52 | memcpy(y, x, 16); 53 | test_verify_16_check(); 54 | y[myrandom() % 16] = myrandom(); 55 | test_verify_16_check(); 56 | y[myrandom() % 16] = myrandom(); 57 | test_verify_16_check(); 58 | y[myrandom() % 16] = myrandom(); 59 | test_verify_16_check(); 60 | } 61 | 62 | static void test_verify_16(void) { 63 | if (targeto && strcmp(targeto, "verify")) return; 64 | if (targetp && strcmp(targetp, "16")) return; 65 | 66 | test_verify_16_x = callocplus(16); 67 | test_verify_16_y = callocplus(16); 68 | 69 | for (long long offset = 0; offset < 2; ++offset) { 70 | if (targetoffset && atol(targetoffset) != offset) continue; 71 | if (offset && valgrind) break; 72 | printf("verify_16 offset %lld\n", offset); 73 | forked(test_verify_16_impl, -1); 74 | ++test_verify_16_x; 75 | ++test_verify_16_y; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /_crypto-test_verify_32.inc: -------------------------------------------------------------------------------- 1 | /* ----- verify, derived from supercop/crypto_verify/try.c */ 2 | 3 | /* 4 | derived from djb work from lib25519/libntruprime 5 | mj modifications: 6 | - rename files to test-crypto.c and _crypto_<>.<>.inc 7 | - fix compiler warnings 8 | - include crypto.h 9 | - use less rounds for valgrind test 10 | - reformat using clang-format 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "crypto.h" 18 | 19 | static unsigned char *test_verify_32_x; 20 | static unsigned char *test_verify_32_y; 21 | 22 | static void test_verify_32_check(void) { 23 | unsigned char *x = test_verify_32_x; 24 | unsigned char *y = test_verify_32_y; 25 | int r; 26 | 27 | secret(x, 32); 28 | secret(y, 32); 29 | r = crypto_verify_32(x, y); 30 | public(x, 32); 31 | public(y, 32); 32 | public(&r, sizeof r); 33 | 34 | if (r == 0) { 35 | if (memcmp(x, y, 32)) fail("failure: different strings pass verify\n"); 36 | } 37 | else if (r == -1) { 38 | if (!memcmp(x, y, 32)) fail("failure: equal strings fail verify\n"); 39 | } 40 | else { fail("failure: weird return value\n"); } 41 | } 42 | 43 | void test_verify_32_impl(long long impl) { 44 | unsigned char *x = test_verify_32_x; 45 | unsigned char *y = test_verify_32_y; 46 | 47 | if (targetn && atol(targetn) != impl) return; 48 | 49 | randombytes(x, 32); 50 | randombytes(y, 32); 51 | test_verify_32_check(); 52 | memcpy(y, x, 32); 53 | test_verify_32_check(); 54 | y[myrandom() % 32] = myrandom(); 55 | test_verify_32_check(); 56 | y[myrandom() % 32] = myrandom(); 57 | test_verify_32_check(); 58 | y[myrandom() % 32] = myrandom(); 59 | test_verify_32_check(); 60 | } 61 | 62 | static void test_verify_32(void) { 63 | if (targeto && strcmp(targeto, "verify")) return; 64 | if (targetp && strcmp(targetp, "32")) return; 65 | 66 | test_verify_32_x = callocplus(32); 67 | test_verify_32_y = callocplus(32); 68 | 69 | for (long long offset = 0; offset < 2; ++offset) { 70 | if (targetoffset && atol(targetoffset) != offset) continue; 71 | if (offset && valgrind) break; 72 | printf("verify_32 offset %lld\n", offset); 73 | forked(test_verify_32_impl, -1); 74 | ++test_verify_32_x; 75 | ++test_verify_32_y; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /_tinysshd-test-hello1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20160225 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int main(int argc, char **argv) { 12 | 13 | pid_t pid; 14 | int tochild[2] = {-1, -1}; 15 | int fromchild[2] = {-1, -1}; 16 | 17 | if (argc < 2) _exit(111); 18 | if (!argv[0]) _exit(111); 19 | if (!argv[1]) _exit(111); 20 | ++argv; 21 | 22 | if (pipe(tochild) == -1) _exit(111); 23 | if (pipe(fromchild) == -1) _exit(111); 24 | pid = fork(); 25 | if (pid == -1) _exit(111); 26 | 27 | if (pid == 0) { 28 | close(tochild[1]); 29 | close(fromchild[0]); 30 | close(1); /* simulate closed connection */ 31 | if (dup2(tochild[0], 0) == -1) _exit(111); 32 | if (dup2(fromchild[1], 1) == -1) _exit(111); 33 | execvp(*argv, argv); 34 | _exit(111); 35 | } 36 | close(tochild[0]); 37 | close(fromchild[1]); 38 | 39 | close(0); 40 | if (dup2(fromchild[0], 0) == -1) _exit(111); 41 | close(1); 42 | if (dup2(tochild[1], 1) == -1) _exit(111); 43 | 44 | signal(SIGPIPE, SIG_IGN); 45 | 46 | _exit(111); 47 | } 48 | -------------------------------------------------------------------------------- /_tinysshd-test-hello2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20160225 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "log.h" 11 | #include "packet.h" 12 | #include "global.h" 13 | #include "str.h" 14 | #include "writeall.h" 15 | 16 | static void cleanup(void) { global_purge(); } 17 | 18 | __attribute__((noreturn)) static void die_fatal(const char *trouble, 19 | const char *d, const char *fn) { 20 | 21 | cleanup(); 22 | 23 | if (d) { 24 | if (fn) 25 | log_f5(trouble, " ", d, "/", fn); 26 | else 27 | log_f3(trouble, " ", d); 28 | } 29 | else { log_f1(trouble); } 30 | _exit(111); 31 | } 32 | 33 | int main(int argc, char **argv) { 34 | 35 | pid_t pid; 36 | int tochild[2] = {-1, -1}; 37 | int fromchild[2] = {-1, -1}; 38 | const char *message; 39 | long long messagelen; 40 | 41 | if (argc < 2) _exit(111); 42 | if (!argv[0]) _exit(111); 43 | if (!argv[1]) _exit(111); 44 | if (!argv[2]) _exit(111); 45 | ++argv; 46 | message = *argv; 47 | messagelen = str_len(message); 48 | ++argv; 49 | 50 | if (pipe(tochild) == -1) _exit(111); 51 | if (pipe(fromchild) == -1) _exit(111); 52 | pid = fork(); 53 | if (pid == -1) _exit(111); 54 | 55 | if (pid == 0) { 56 | close(tochild[1]); 57 | close(fromchild[0]); 58 | if (dup2(tochild[0], 0) == -1) _exit(111); 59 | if (dup2(fromchild[1], 1) == -1) _exit(111); 60 | execvp(*argv, argv); 61 | _exit(111); 62 | } 63 | close(tochild[0]); 64 | close(fromchild[1]); 65 | 66 | close(0); 67 | if (dup2(fromchild[0], 0) == -1) _exit(111); 68 | close(1); 69 | if (dup2(tochild[1], 1) == -1) _exit(111); 70 | 71 | signal(SIGPIPE, SIG_IGN); 72 | 73 | global_init(); 74 | 75 | if (!packet_hello_receive()) 76 | die_fatal("unable to receive hello-string", 0, 0); 77 | if (messagelen) { 78 | if (writeall(1, message, messagelen) == -1) 79 | die_fatal("unable to write hello-string", 0, 0); 80 | if (writeall(1, "\r\n", 2) == -1) 81 | die_fatal("unable to write hello-string", 0, 0); 82 | } 83 | 84 | _exit(111); 85 | } 86 | -------------------------------------------------------------------------------- /_tinysshd-test-kex1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20160226 3 | 20241215 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include 10 | #include 11 | #include "log.h" 12 | #include "packet.h" 13 | #include "ssh.h" 14 | #include "bug.h" 15 | #include "packetparser.h" 16 | #include "global.h" 17 | 18 | static void cleanup(void) { global_purge(); } 19 | 20 | __attribute__((noreturn)) static void die_fatal(const char *trouble, 21 | const char *d, const char *fn) { 22 | 23 | cleanup(); 24 | 25 | if (d) { 26 | if (fn) 27 | log_f5(trouble, " ", d, "/", fn); 28 | else 29 | log_f3(trouble, " ", d); 30 | } 31 | else { log_f1(trouble); } 32 | _exit(111); 33 | } 34 | 35 | int main(int argc, char **argv) { 36 | 37 | pid_t pid; 38 | int tochild[2] = {-1, -1}; 39 | int fromchild[2] = {-1, -1}; 40 | 41 | if (argc < 2) _exit(111); 42 | if (!argv[0]) _exit(111); 43 | if (!argv[1]) _exit(111); 44 | ++argv; 45 | 46 | if (pipe(tochild) == -1) _exit(111); 47 | if (pipe(fromchild) == -1) _exit(111); 48 | pid = fork(); 49 | if (pid == -1) _exit(111); 50 | 51 | if (pid == 0) { 52 | close(tochild[1]); 53 | close(fromchild[0]); 54 | if (dup2(tochild[0], 0) == -1) _exit(111); 55 | if (dup2(fromchild[1], 1) == -1) _exit(111); 56 | execvp(*argv, argv); 57 | _exit(111); 58 | } 59 | close(tochild[0]); 60 | close(fromchild[1]); 61 | 62 | close(0); 63 | if (dup2(fromchild[0], 0) == -1) _exit(111); 64 | close(1); 65 | if (dup2(tochild[1], 1) == -1) _exit(111); 66 | 67 | signal(SIGPIPE, SIG_IGN); 68 | 69 | global_init(); 70 | 71 | log_init(2, "_tinysshd-test-kex1", 0, 0); 72 | 73 | if (!packet_hello_receive()) 74 | die_fatal("unable to receive hello-string", 0, 0); 75 | if (!packet_hello_send()) die_fatal("unable to send hello-string", 0, 0); 76 | 77 | _exit(111); 78 | } 79 | -------------------------------------------------------------------------------- /blocking.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from from curvecp/blocking.c 3 | - reformated using clang-format 4 | */ 5 | 6 | #include 7 | #include "blocking.h" 8 | 9 | void blocking_enable(int fd) { 10 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK); 11 | } 12 | 13 | void blocking_disable(int fd) { 14 | fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); 15 | } 16 | -------------------------------------------------------------------------------- /blocking.h: -------------------------------------------------------------------------------- 1 | #ifndef BLOCKING_H____ 2 | #define BLOCKING_H____ 3 | 4 | extern void blocking_enable(int); 5 | extern void blocking_disable(int); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /byte.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20241205 3 | */ 4 | 5 | #include "crypto_int16.h" 6 | #include "byte.h" 7 | 8 | void byte_copy(void *yv, long long ylen, const void *xv) { 9 | 10 | long long i; 11 | const char *x = xv; 12 | char *y = yv; 13 | 14 | for (i = 0; i < ylen; ++i) y[i] = x[i]; 15 | } 16 | 17 | int byte_isequal(const void *yv, long long ylen, const void *xv) { 18 | 19 | long long i; 20 | const unsigned char *y = yv; 21 | const unsigned char *x = xv; 22 | unsigned char diff = 0; 23 | 24 | for (i = 0; i < ylen; ++i) diff |= x[i] ^ y[i]; 25 | return crypto_int16_zero_01(diff); 26 | } 27 | 28 | void byte_zero(void *yv, long long ylen) { 29 | 30 | long long i; 31 | volatile char *y = yv; 32 | 33 | for (i = 0; i < ylen; ++i) y[i] = 0; 34 | #ifdef __GNUC__ 35 | __asm__ __volatile__("" : : "r"(yv) : "memory"); 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /byte.h: -------------------------------------------------------------------------------- 1 | #ifndef BYTE_H____ 2 | #define BYTE_H____ 3 | 4 | extern void byte_zero(void *, long long); 5 | extern void byte_copy(void *, long long, const void *); 6 | extern int byte_isequal(const void *, long long, const void *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /channel_drop.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140129 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "dropuidgid.h" 11 | #include "newenv.h" 12 | #include "channel.h" 13 | 14 | int channel_droppriv(char *user, char **shell) { 15 | 16 | struct passwd *pw; 17 | char *name; 18 | 19 | pw = getpwnam(user); 20 | if (!pw) return 0; 21 | 22 | if (isatty(0)) { 23 | name = ttyname(0); 24 | if (!name) return 0; 25 | if (!newenv_env("SSH_TTY", name)) return 0; 26 | /* setowner */ 27 | if (chown(name, pw->pw_uid, pw->pw_gid) == -1) return 0; 28 | if (chmod(name, 0600) == -1) return 0; 29 | } 30 | 31 | /* drop privileges */ 32 | if (!dropuidgid(pw->pw_name, pw->pw_uid, pw->pw_gid)) return 0; 33 | 34 | if (chdir(pw->pw_dir) == -1) return 0; 35 | if (!newenv_env("HOME", pw->pw_dir)) return 0; 36 | if (!newenv_env("USER", pw->pw_name)) return 0; 37 | if (!newenv_env("LOGNAME", pw->pw_name)) return 0; 38 | if (!newenv_env("LOGIN", pw->pw_name)) return 0; 39 | if (!newenv_env("SHELL", pw->pw_shell)) return 0; 40 | 41 | *shell = pw->pw_shell; 42 | return 1; 43 | } 44 | -------------------------------------------------------------------------------- /channel_fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140129 3 | 20241209 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include "blocking.h" 10 | #include "open.h" 11 | #include "channel.h" 12 | 13 | /* 14 | The 'channel_fork' function is used to create a new process. 15 | Function creates 3 pipes from/to child: 16 | fd[0] is pipe to childs standard input 17 | fd[1] is pipe from childs standard output 18 | fd[2] is pipe from childs error output 19 | Function returns also childs PID. 20 | */ 21 | long long channel_fork(int fd[3]) { 22 | 23 | int pi[2], pa[3], ch[3]; 24 | long long i, pid; 25 | 26 | for (i = 0; i < 3; ++i) pa[i] = ch[i] = fd[i] = -1; 27 | for (i = 0; i < 3; ++i) { 28 | if (open_pipe(pi) == -1) goto cleanup; 29 | pa[i] = pi[i ? 0 : 1]; 30 | ch[i] = pi[i ? 1 : 0]; 31 | } 32 | 33 | pid = fork(); 34 | if (pid == -1) goto cleanup; 35 | if (pid == 0) { 36 | for (i = 0; i < 3; ++i) { 37 | close(pa[i]); 38 | close(i); 39 | blocking_enable(ch[i]); 40 | if (dup(ch[i]) != i) _exit(111); 41 | } 42 | return 0; 43 | } 44 | for (i = 0; i < 3; ++i) { 45 | close(ch[i]); 46 | fd[i] = pa[i]; 47 | } 48 | 49 | return pid; 50 | 51 | cleanup: 52 | for (i = 0; i < 3; ++i) { 53 | close(pa[i]); 54 | close(ch[i]); 55 | } 56 | return -1; 57 | } 58 | -------------------------------------------------------------------------------- /channel_subsystem.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20150114 3 | 20241209 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "str.h" 9 | #include "log.h" 10 | #include "e.h" 11 | #include "channel.h" 12 | 13 | static long long channel_subsystem_pos = 0; 14 | static const char *channel_subsystem[CHANNEL_SUBSYSTEM_MAX] = {0}; 15 | 16 | int channel_subsystem_add(const char *x) { 17 | 18 | if (channel_subsystem_pos >= CHANNEL_SUBSYSTEM_MAX) return 0; 19 | channel_subsystem[channel_subsystem_pos++] = x; 20 | return 1; 21 | } 22 | 23 | const char *channel_subsystem_get(const char *x) { 24 | 25 | long long len, i; 26 | 27 | if (!x) return 0; 28 | 29 | len = str_len(x); 30 | for (i = 0; i < CHANNEL_SUBSYSTEM_MAX; ++i) { 31 | if (!channel_subsystem[i]) break; 32 | if (str_start(channel_subsystem[i], x)) { 33 | if (channel_subsystem[i][len] == '=') { 34 | return channel_subsystem[i] + len + 1; 35 | } 36 | } 37 | } 38 | return 0; 39 | } 40 | 41 | void channel_subsystem_log(void) { 42 | 43 | long long i; 44 | 45 | for (i = 0; i < CHANNEL_SUBSYSTEM_MAX; ++i) { 46 | if (!channel_subsystem[i]) break; 47 | log_d3("subsystem: ", channel_subsystem[i], " registered"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /cleanup.c: -------------------------------------------------------------------------------- 1 | #include "cleanup.h" 2 | 3 | void cleanup_(void *yv, long long ylen) { 4 | volatile char *y = (volatile char *) yv; 5 | while (ylen > 0) { 6 | *y++ = 0; 7 | --ylen; 8 | } 9 | #ifdef __GNUC__ 10 | __asm__ __volatile__("" : : "r"(yv) : "memory"); 11 | #endif 12 | } 13 | -------------------------------------------------------------------------------- /cleanup.h: -------------------------------------------------------------------------------- 1 | #ifndef CLEANUP_H____ 2 | #define CLEANUP_H____ 3 | 4 | extern void cleanup_(void *, long long); 5 | #define cleanup(x) cleanup_((x), sizeof(x)) 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /coe.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20241112 3 | */ 4 | 5 | #include 6 | #include "coe.h" 7 | 8 | /* 9 | The 'coe_enable(fd)' function enables 10 | the close-on-exec flag on a file-descriptor 'fd'. 11 | */ 12 | void coe_enable(int fd) { fcntl(fd, F_SETFD, 1); } 13 | 14 | /* 15 | The 'coe_disable(fd)' function disables 16 | the close-on-exec flag on a file-descriptor 'fd'. 17 | */ 18 | void coe_disable(int fd) { fcntl(fd, F_SETFD, 0); } 19 | -------------------------------------------------------------------------------- /coe.h: -------------------------------------------------------------------------------- 1 | #ifndef COE_H____ 2 | #define COE_H____ 3 | 4 | extern void coe_enable(int); 5 | extern void coe_disable(int); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /connectioninfo.h: -------------------------------------------------------------------------------- 1 | #ifndef CONNECTIONINFO_H____ 2 | #define CONNECTIONINFO_H____ 3 | 4 | extern void connectioninfo(char *, char *, char *, char *); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /crypto.h: -------------------------------------------------------------------------------- 1 | /* allways include local versions */ 2 | #include "crypto_int16.h" 3 | #include "crypto_int32.h" 4 | #include "crypto_int64.h" 5 | #include "crypto_int8.h" 6 | #include "crypto_uint16.h" 7 | #include "crypto_uint32.h" 8 | #include "crypto_uint64.h" 9 | #include "crypto_uint8.h" 10 | #include "crypto_verify_16.h" 11 | #include "crypto_verify_32.h" 12 | 13 | /* include randombytes from librandombytes */ 14 | #include "haslibrandombytes.h" 15 | #ifdef HASLIBRANDOMBYTES 16 | #include 17 | #else 18 | #include "randombytes.h" 19 | #endif 20 | 21 | /* TODO */ 22 | #include "crypto_hash_sha256.h" 23 | #include "crypto_hash_sha512.h" 24 | #include "crypto_kem_sntrup761.h" 25 | #include "crypto_kem_sntrup761x25519.h" 26 | #include "crypto_onetimeauth_poly1305.h" 27 | #include "crypto_scalarmult_curve25519.h" 28 | #include "crypto_dh_x25519.h" 29 | #include "crypto_sign_ed25519.h" 30 | #include "crypto_sort_uint32.h" 31 | #include "crypto_stream_chacha20.h" 32 | -------------------------------------------------------------------------------- /crypto_declassify.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_declassify_h 2 | #define crypto_declassify_h 3 | 4 | #include "hasvalgrind.h" 5 | #ifdef HASVALGRIND 6 | 7 | #include 8 | 9 | #define crypto_declassify_uses_valgrind 1 10 | 11 | static void crypto_declassify(void *xv, long long xlen) { 12 | VALGRIND_MAKE_MEM_DEFINED(xv, xlen); 13 | } 14 | 15 | #else 16 | 17 | #define crypto_declassify_uses_valgrind 0 18 | 19 | static void crypto_declassify(void *xv, long long xlen) { 20 | (void) xv; 21 | (void) xlen; 22 | } 23 | 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /crypto_dh_x25519.c: -------------------------------------------------------------------------------- 1 | #include "crypto_dh_x25519.h" 2 | 3 | #include "haslib25519.h" 4 | #ifdef HASLIB25519 5 | 6 | #include 7 | 8 | int crypto_dh_x25519_lib25519(unsigned char *k, const unsigned char *pk, 9 | const unsigned char *sk) { 10 | lib25519_dh_x25519(k, pk, sk); 11 | return 0; 12 | } 13 | 14 | int crypto_dh_x25519_lib25519_keypair(unsigned char *pk, unsigned char *sk) { 15 | lib25519_dh_x25519_keypair(pk, sk); 16 | return 0; 17 | } 18 | 19 | #else 20 | 21 | #include "randombytes.h" 22 | #include "crypto_scalarmult_curve25519.h" 23 | 24 | int crypto_dh_x25519_tinyssh(unsigned char *k, const unsigned char *pk, 25 | const unsigned char *sk) { 26 | return crypto_scalarmult_curve25519(k, sk, pk); 27 | } 28 | 29 | static const unsigned char basepoint[32] = {9}; 30 | 31 | int crypto_dh_x25519_tinyssh_keypair(unsigned char *q, unsigned char *n) { 32 | randombytes(n, 32); 33 | return crypto_dh_x25519(q, basepoint, n); 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /crypto_dh_x25519.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_dh_x25519_H 2 | #define crypto_dh_x25519_H 3 | 4 | #include "haslib25519.h" 5 | #ifdef HASLIB25519 6 | 7 | #include 8 | 9 | #define crypto_dh_x25519_lib25519_BYTES lib25519_dh_x25519_BYTES 10 | #define crypto_dh_x25519_lib25519_PUBLICKEYBYTES \ 11 | lib25519_dh_x25519_PUBLICKEYBYTES 12 | #define crypto_dh_x25519_lib25519_SECRETKEYBYTES \ 13 | lib25519_dh_x25519_SECRETKEYBYTES 14 | extern int crypto_dh_x25519_lib25519(unsigned char *, const unsigned char *, 15 | const unsigned char *); 16 | extern int crypto_dh_x25519_lib25519_keypair(unsigned char *, unsigned char *); 17 | 18 | #define crypto_dh_x25519 crypto_dh_x25519_lib25519 19 | #define crypto_dh_x25519_keypair crypto_dh_x25519_lib25519_keypair 20 | #define crypto_dh_x25519_BYTES crypto_dh_x25519_lib25519_BYTES 21 | #define crypto_dh_x25519_PUBLICKEYBYTES crypto_dh_x25519_lib25519_PUBLICKEYBYTES 22 | #define crypto_dh_x25519_SECRETKEYBYTES crypto_dh_x25519_lib25519_SECRETKEYBYTES 23 | #define crypto_dh_x25519_IMPLEMENTATION "lib25519" 24 | #define crypto_dh_x25519_VERSION lib25519_version 25 | 26 | #else 27 | 28 | #define crypto_dh_x25519_tinyssh_BYTES 32 29 | #define crypto_dh_x25519_tinyssh_PUBLICKEYBYTES 32 30 | #define crypto_dh_x25519_tinyssh_SECRETKEYBYTES 32 31 | extern int crypto_dh_x25519_tinyssh(unsigned char *, const unsigned char *, 32 | const unsigned char *); 33 | extern int crypto_dh_x25519_tinyssh_keypair(unsigned char *, unsigned char *); 34 | 35 | #define crypto_dh_x25519 crypto_dh_x25519_tinyssh 36 | #define crypto_dh_x25519_keypair crypto_dh_x25519_tinyssh_keypair 37 | #define crypto_dh_x25519_BYTES crypto_dh_x25519_tinyssh_BYTES 38 | #define crypto_dh_x25519_PUBLICKEYBYTES crypto_dh_x25519_tinyssh_PUBLICKEYBYTES 39 | #define crypto_dh_x25519_SECRETKEYBYTES crypto_dh_x25519_tinyssh_SECRETKEYBYTES 40 | #define crypto_dh_x25519_IMPLEMENTATION "tinyssh" 41 | #define crypto_dh_x25519_VERSION "-" 42 | 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /crypto_hash_sha256.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha256_H 2 | #define crypto_hash_sha256_H 3 | 4 | #define crypto_hash_sha256_tinyssh_BYTES 32 5 | extern int crypto_hash_sha256_tinyssh(unsigned char *, const unsigned char *, 6 | unsigned long long); 7 | 8 | #define crypto_hash_sha256 crypto_hash_sha256_tinyssh 9 | #define crypto_hash_sha256_BYTES crypto_hash_sha256_tinyssh_BYTES 10 | #define crypto_hash_sha256_IMPLEMENTATION "tinyssh" 11 | #define crypto_hash_sha256_VERSION "-" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /crypto_hash_sha512.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_hash_sha512_H 2 | #define crypto_hash_sha512_H 3 | 4 | #include "haslib25519.h" 5 | #ifndef HASLIB25519 6 | 7 | #define crypto_hash_sha512_tinyssh_BYTES 64 8 | extern int crypto_hash_sha512_tinyssh(unsigned char *, const unsigned char *, 9 | unsigned long long); 10 | 11 | #define crypto_hash_sha512 crypto_hash_sha512_tinyssh 12 | #define crypto_hash_sha512_BYTES crypto_hash_sha512_tinyssh_BYTES 13 | #define crypto_hash_sha512_IMPLEMENTATION "tinyssh" 14 | #define crypto_hash_sha512_VERSION "-" 15 | 16 | #else 17 | 18 | #include 19 | #define crypto_hash_sha512_lib25519_BYTES lib25519_hash_sha512_BYTES 20 | extern int crypto_hash_sha512_lib25519(unsigned char *, const unsigned char *, 21 | unsigned long long); 22 | 23 | #define crypto_hash_sha512 crypto_hash_sha512_lib25519 24 | #define crypto_hash_sha512_BYTES crypto_hash_sha512_lib25519_BYTES 25 | #define crypto_hash_sha512_IMPLEMENTATION "lib25519" 26 | #define crypto_hash_sha512_VERSION lib25519_version 27 | 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /crypto_hash_sha512_lib25519.c: -------------------------------------------------------------------------------- 1 | #include "haslib25519.h" 2 | #ifdef HASLIB25519 3 | 4 | #include 5 | #include "crypto_hash_sha512.h" 6 | 7 | int crypto_hash_sha512_lib25519(unsigned char *o, const unsigned char *m, 8 | unsigned long long n) { 9 | lib25519_hash_sha512(o, m, n); 10 | return 0; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /crypto_kem_sntrup761_libntruprime.c: -------------------------------------------------------------------------------- 1 | #include "haslibntruprime.h" 2 | #ifdef HASLIBNTRUPRIME 3 | 4 | #include 5 | #include "crypto_kem_sntrup761.h" 6 | 7 | int crypto_kem_sntrup761_libntruprime_keypair(unsigned char *pk, 8 | unsigned char *sk) { 9 | sntrup761_keypair(pk, sk); 10 | return 0; 11 | } 12 | 13 | int crypto_kem_sntrup761_libntruprime_enc(unsigned char *c, unsigned char *k, 14 | const unsigned char *pk) { 15 | sntrup761_enc(c, k, pk); 16 | return 0; 17 | } 18 | 19 | int crypto_kem_sntrup761_libntruprime_dec(unsigned char *k, 20 | const unsigned char *c, 21 | const unsigned char *sk) { 22 | sntrup761_dec(k, c, sk); 23 | return 0; 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /crypto_kem_sntrup761x25519.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_kem_sntrup761x25519_H 2 | #define crypto_kem_sntrup761x25519_H 3 | 4 | #define crypto_kem_sntrup761x25519_tinyssh_SECRETKEYBYTES 1795 5 | #define crypto_kem_sntrup761x25519_tinyssh_PUBLICKEYBYTES 1190 6 | #define crypto_kem_sntrup761x25519_tinyssh_CIPHERTEXTBYTES 1071 7 | #define crypto_kem_sntrup761x25519_tinyssh_BYTES 64 8 | extern int crypto_kem_sntrup761x25519_tinyssh_keypair(unsigned char *, 9 | unsigned char *); 10 | extern int crypto_kem_sntrup761x25519_tinyssh_enc(unsigned char *, 11 | unsigned char *, 12 | const unsigned char *); 13 | extern int crypto_kem_sntrup761x25519_tinyssh_dec(unsigned char *, 14 | const unsigned char *, 15 | const unsigned char *); 16 | 17 | #define crypto_kem_sntrup761x25519_keypair \ 18 | crypto_kem_sntrup761x25519_tinyssh_keypair 19 | #define crypto_kem_sntrup761x25519_enc crypto_kem_sntrup761x25519_tinyssh_enc 20 | #define crypto_kem_sntrup761x25519_dec crypto_kem_sntrup761x25519_tinyssh_dec 21 | #define crypto_kem_sntrup761x25519_SECRETKEYBYTES \ 22 | crypto_kem_sntrup761x25519_tinyssh_SECRETKEYBYTES 23 | #define crypto_kem_sntrup761x25519_PUBLICKEYBYTES \ 24 | crypto_kem_sntrup761x25519_tinyssh_PUBLICKEYBYTES 25 | #define crypto_kem_sntrup761x25519_CIPHERTEXTBYTES \ 26 | crypto_kem_sntrup761x25519_tinyssh_CIPHERTEXTBYTES 27 | #define crypto_kem_sntrup761x25519_BYTES \ 28 | crypto_kem_sntrup761x25519_tinyssh_BYTES 29 | #define crypto_kem_sntrup761x25519_IMPLEMENTATION "tinyssh" 30 | #define crypto_kem_sntrup761x25519_VERSION "-" 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /crypto_onetimeauth_poly1305_lib1305.c: -------------------------------------------------------------------------------- 1 | #include "haslib1305.h" 2 | #ifdef HASLIB1305 3 | 4 | #include 5 | #include "crypto_onetimeauth_poly1305.h" 6 | 7 | int crypto_onetimeauth_poly1305_lib1305(unsigned char *a, 8 | const unsigned char *m, 9 | unsigned long long n, 10 | const unsigned char *k) { 11 | poly1305(a, m, (unsigned long long) n, k); 12 | return 0; 13 | } 14 | 15 | int crypto_onetimeauth_poly1305_lib1305_verify(const unsigned char *a, 16 | const unsigned char *m, 17 | unsigned long long n, 18 | const unsigned char *k) { 19 | return poly1305_verify(a, m, (unsigned long long) n, k); 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /crypto_scalarmult_curve25519.c: -------------------------------------------------------------------------------- 1 | #include "cleanup.h" 2 | #include "fe25519.h" 3 | #include "crypto_uint8.h" 4 | #include "crypto_scalarmult_curve25519.h" 5 | 6 | int crypto_scalarmult_curve25519_tinyssh(unsigned char *q, 7 | const unsigned char *n, 8 | const unsigned char *p) { 9 | 10 | unsigned char e[32]; 11 | fe x1, x2, z2, x3, z3, tmp0, tmp1; 12 | long long i; 13 | int pos; 14 | crypto_uint32 swap, b; 15 | 16 | for (i = 0; i < 32; ++i) e[i] = n[i]; 17 | e[0] &= 248; 18 | e[31] &= 127; 19 | e[31] |= 64; 20 | fe25519_frombytes(x1, p); 21 | fe_1(x2); 22 | fe_0(z2); 23 | fe_copy(x3, x1); 24 | fe_1(z3); 25 | 26 | swap = 0; 27 | for (pos = 254; pos >= 0; --pos) { 28 | b = crypto_uint8_bitmod_01(e[pos / 8], pos); 29 | swap ^= b; 30 | fe_cswap(x2, x3, swap); 31 | fe_cswap(z2, z3, swap); 32 | swap = b; 33 | 34 | fe25519_sub(tmp0, x3, z3); 35 | fe25519_sub(tmp1, x2, z2); 36 | fe25519_add(x2, x2, z2); 37 | fe25519_add(z2, x3, z3); 38 | fe25519_mul(z3, tmp0, x2); 39 | fe25519_mul(z2, z2, tmp1); 40 | fe25519_sq(tmp0, tmp1); 41 | fe25519_sq(tmp1, x2); 42 | fe25519_add(x3, z3, z2); 43 | fe25519_sub(z2, z3, z2); 44 | fe25519_mul(x2, tmp1, tmp0); 45 | fe25519_sub(tmp1, tmp1, tmp0); 46 | fe25519_sq(z2, z2); 47 | fe25519_mul121666(z3, tmp1); 48 | fe25519_sq(x3, x3); 49 | fe25519_add(tmp0, tmp0, z3); 50 | fe25519_mul(z3, x1, z2); 51 | fe25519_mul(z2, tmp1, tmp0); 52 | } 53 | 54 | fe_cswap(x2, x3, swap); 55 | fe_cswap(z2, z3, swap); 56 | 57 | fe25519_inv(z2, z2); 58 | fe25519_mul(x2, x2, z2); 59 | fe25519_tobytes(q, x2); 60 | 61 | cleanup(e); 62 | cleanup(tmp0); 63 | cleanup(tmp1); 64 | cleanup(x1); 65 | cleanup(x2); 66 | cleanup(x3); 67 | cleanup(z2); 68 | cleanup(z3); 69 | 70 | return 0; 71 | } 72 | 73 | static const unsigned char basepoint[32] = {9}; 74 | 75 | int crypto_scalarmult_curve25519_tinyssh_base(unsigned char *q, 76 | const unsigned char *n) { 77 | return crypto_scalarmult_curve25519_tinyssh(q, n, basepoint); 78 | } 79 | -------------------------------------------------------------------------------- /crypto_scalarmult_curve25519.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_scalarmult_curve25519_H 2 | #define crypto_scalarmult_curve25519_H 3 | 4 | #define crypto_scalarmult_curve25519_tinyssh_BYTES 32 5 | #define crypto_scalarmult_curve25519_tinyssh_SCALARBYTES 32 6 | extern int crypto_scalarmult_curve25519_tinyssh(unsigned char *, 7 | const unsigned char *, 8 | const unsigned char *); 9 | extern int crypto_scalarmult_curve25519_tinyssh_base(unsigned char *, 10 | const unsigned char *); 11 | 12 | #define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_tinyssh 13 | #define crypto_scalarmult_curve25519_base \ 14 | crypto_scalarmult_curve25519_tinyssh_base 15 | #define crypto_scalarmult_curve25519_BYTES \ 16 | crypto_scalarmult_curve25519_tinyssh_BYTES 17 | #define crypto_scalarmult_curve25519_SCALARBYTES \ 18 | crypto_scalarmult_curve25519_tinyssh_SCALARBYTES 19 | #define crypto_scalarmult_curve25519_IMPLEMENTATION "tinyssh" 20 | #define crypto_scalarmult_curve25519_VERSION "-" 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /crypto_sign_ed25519_lib25519.c: -------------------------------------------------------------------------------- 1 | #include "haslib25519.h" 2 | #ifdef HASLIB25519 3 | 4 | #include 5 | #include "crypto_sign_ed25519.h" 6 | 7 | int crypto_sign_ed25519_lib25519(unsigned char *sm, unsigned long long *smlen, 8 | const unsigned char *m, unsigned long long n, 9 | const unsigned char *skorig) { 10 | long long llsmlen; 11 | lib25519_sign_ed25519(sm, &llsmlen, m, n, skorig); 12 | *smlen = (unsigned long long) llsmlen; 13 | return 0; 14 | } 15 | 16 | int crypto_sign_ed25519_lib25519_open(unsigned char *m, 17 | unsigned long long *mlen, 18 | const unsigned char *sm, 19 | unsigned long long n, 20 | const unsigned char *pk) { 21 | long long llmlen; 22 | int ret; 23 | ret = lib25519_sign_ed25519_open(m, &llmlen, sm, n, pk); 24 | *mlen = (unsigned long long) llmlen; 25 | return ret; 26 | } 27 | 28 | int crypto_sign_ed25519_lib25519_keypair(unsigned char *pk, unsigned char *sk) { 29 | lib25519_sign_ed25519_keypair(pk, sk); 30 | return 0; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /crypto_sort_uint32.c: -------------------------------------------------------------------------------- 1 | #include "crypto_uint32.h" 2 | #include "crypto_sort_uint32.h" 3 | 4 | static void minmax(crypto_uint32 *x, crypto_uint32 *y) { 5 | 6 | crypto_uint32 xi = *x; 7 | crypto_uint32 yi = *y; 8 | crypto_uint32 xy = xi ^ yi; 9 | crypto_uint32 c = yi - xi; 10 | 11 | c ^= xy & (c ^ yi ^ 0x80000000); 12 | c >>= 31; 13 | c &= 1; 14 | c = -c; 15 | c &= xy; 16 | *x = xi ^ c; 17 | *y = yi ^ c; 18 | } 19 | 20 | void crypto_sort_uint32_tinyssh(void *xv, long long n) { 21 | 22 | long long top, p, q, i; 23 | crypto_uint32 *x = xv; 24 | 25 | if (n < 2) return; 26 | top = 1; 27 | while (top < n - top) top += top; 28 | 29 | for (p = top; p > 0; p >>= 1) { 30 | for (i = 0; i < n - p; ++i) 31 | if (!(i & p)) minmax(x + i, x + i + p); 32 | for (q = top; q > p; q >>= 1) 33 | for (i = 0; i < n - q; ++i) 34 | if (!(i & p)) minmax(x + i + p, x + i + q); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /crypto_sort_uint32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_sort_uint32_H 2 | #define crypto_sort_uint32_H 3 | 4 | #define crypto_sort_uint32_tinyssh_BYTES 4 5 | extern void crypto_sort_uint32_tinyssh(void *, long long); 6 | 7 | #define crypto_sort_uint32 crypto_sort_uint32_tinyssh 8 | #define crypto_sort_uint32_BYTES crypto_sort_uint32_tinyssh_BYTES 9 | #define crypto_sort_uint32_IMPLEMENTATION "tinyssh" 10 | #define crypto_sort_uint32_VERSION "-" 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /crypto_stream_chacha20.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_stream_chacha20_H 2 | #define crypto_stream_chacha20_H 3 | 4 | #define crypto_stream_chacha20_tinyssh_KEYBYTES 32 5 | #define crypto_stream_chacha20_tinyssh_NONCEBYTES 8 6 | extern int crypto_stream_chacha20_tinyssh(unsigned char *, unsigned long long, 7 | const unsigned char *, 8 | const unsigned char *); 9 | extern int crypto_stream_chacha20_tinyssh_xor(unsigned char *, 10 | const unsigned char *, 11 | unsigned long long, 12 | const unsigned char *, 13 | const unsigned char *); 14 | 15 | #define crypto_stream_chacha20 crypto_stream_chacha20_tinyssh 16 | #define crypto_stream_chacha20_xor crypto_stream_chacha20_tinyssh_xor 17 | #define crypto_stream_chacha20_KEYBYTES crypto_stream_chacha20_tinyssh_KEYBYTES 18 | #define crypto_stream_chacha20_NONCEBYTES \ 19 | crypto_stream_chacha20_tinyssh_NONCEBYTES 20 | #define crypto_stream_chacha20_IMPLEMENTATION "tinyssh" 21 | #define crypto_stream_chacha20_VERSION "-" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /crypto_verify_16.c: -------------------------------------------------------------------------------- 1 | #include "crypto_int16.h" 2 | #include "crypto_verify_16.h" 3 | 4 | int crypto_verify_16_tinyssh(const unsigned char *x, const unsigned char *y) { 5 | 6 | crypto_int16 d = 0; 7 | long long i; 8 | 9 | for (i = 0; i < crypto_verify_16_BYTES; ++i) { d |= x[i] ^ y[i]; } 10 | 11 | return crypto_int16_nonzero_mask(d); 12 | } 13 | -------------------------------------------------------------------------------- /crypto_verify_16.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_16_H 2 | #define crypto_verify_16_H 3 | 4 | #define crypto_verify_16_tinyssh_BYTES 16 5 | extern int crypto_verify_16_tinyssh(const unsigned char *, 6 | const unsigned char *); 7 | 8 | #define crypto_verify_16 crypto_verify_16_tinyssh 9 | #define crypto_verify_16_BYTES crypto_verify_16_tinyssh_BYTES 10 | #define crypto_verify_16_IMPLEMENTATION "tinyssh" 11 | #define crypto_verify_16_VERSION "-" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /crypto_verify_32.c: -------------------------------------------------------------------------------- 1 | #include "crypto_int16.h" 2 | #include "crypto_verify_32.h" 3 | 4 | int crypto_verify_32_tinyssh(const unsigned char *x, const unsigned char *y) { 5 | 6 | crypto_int16 d = 0; 7 | long long i; 8 | 9 | for (i = 0; i < crypto_verify_32_BYTES; ++i) { d |= x[i] ^ y[i]; } 10 | 11 | return crypto_int16_nonzero_mask(d); 12 | } 13 | -------------------------------------------------------------------------------- /crypto_verify_32.h: -------------------------------------------------------------------------------- 1 | #ifndef crypto_verify_32_H 2 | #define crypto_verify_32_H 3 | 4 | #define crypto_verify_32_tinyssh_BYTES 32 5 | extern int crypto_verify_32_tinyssh(const unsigned char *, 6 | const unsigned char *); 7 | 8 | #define crypto_verify_32 crypto_verify_32_tinyssh 9 | #define crypto_verify_32_BYTES crypto_verify_32_tinyssh_BYTES 10 | #define crypto_verify_32_IMPLEMENTATION "tinyssh" 11 | #define crypto_verify_32_VERSION "-" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /cryptoint/LICENSE: -------------------------------------------------------------------------------- 1 | The files in this directory are hereby placed into the public domain. 2 | 3 | [SPDX-License-Identifier](https://spdx.dev/ids/): 4 | [LicenseRef-PD-hp](https://cr.yp.to/spdx.html) 5 | OR 6 | [CC0-1.0](https://spdx.org/licenses/CC0-1.0.html) 7 | OR 8 | [0BSD](https://spdx.org/licenses/0BSD.html) 9 | OR 10 | [MIT-0](https://spdx.org/licenses/MIT-0.html) 11 | OR 12 | [MIT](https://spdx.org/licenses/MIT.html) 13 | -------------------------------------------------------------------------------- /cryptoint/autogen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./create.py 4 | ./specialize.py 5 | rm -rf __pycache__ 6 | -------------------------------------------------------------------------------- /cryptoint/int16_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_int16.h" 4 | 5 | volatile crypto_int16 crypto_int16_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/int32_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_int32.h" 4 | 5 | volatile crypto_int32 crypto_int32_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/int64_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_int64.h" 4 | 5 | volatile crypto_int64 crypto_int64_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/int8_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_int8.h" 4 | 5 | volatile crypto_int8 crypto_int8_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/intN_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_intN.h" 4 | 5 | volatile crypto_intN crypto_intN_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/namespace: -------------------------------------------------------------------------------- 1 | tinyssh 2 | -------------------------------------------------------------------------------- /cryptoint/uint16_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_uint16.h" 4 | 5 | volatile crypto_uint16_signed crypto_uint16_signed_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/uint32_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_uint32.h" 4 | 5 | volatile crypto_uint32_signed crypto_uint32_signed_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/uint64_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_uint64.h" 4 | 5 | volatile crypto_uint64_signed crypto_uint64_signed_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/uint8_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_uint8.h" 4 | 5 | volatile crypto_uint8_signed crypto_uint8_signed_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/uintN_optblocker.c: -------------------------------------------------------------------------------- 1 | /* auto-generated: cd cryptoint; ./autogen */ 2 | /* cryptoint 20250414 */ 3 | #include "crypto_uintN.h" 4 | 5 | volatile crypto_uintN_signed crypto_uintN_signed_optblocker = 0; 6 | -------------------------------------------------------------------------------- /cryptoint/version: -------------------------------------------------------------------------------- 1 | cryptoint 20250414 2 | -------------------------------------------------------------------------------- /die.c: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | #include "log.h" 3 | #include "die.h" 4 | 5 | void die_usage(const char *x) { 6 | 7 | log_u1(x); 8 | global_die(100); 9 | } 10 | 11 | void die_fatal_(const char *fn, unsigned long long line, const char *trouble, 12 | const char *d, const char *f) { 13 | 14 | if (d) { 15 | if (f) 16 | log_9_(1, 0, fn, line, trouble, " ", d, "/", f, 0, 0, 0, 0); 17 | else 18 | log_9_(1, 0, fn, line, trouble, " ", d, 0, 0, 0, 0, 0, 0); 19 | } 20 | else { log_9_(1, 0, fn, line, trouble, 0, 0, 0, 0, 0, 0, 0, 0); } 21 | global_die(111); 22 | } 23 | -------------------------------------------------------------------------------- /die.h: -------------------------------------------------------------------------------- 1 | #ifndef DIE_H____ 2 | #define DIE_H____ 3 | 4 | extern void die_usage(const char *); 5 | extern void die_fatal_(const char *, unsigned long long, const char *, 6 | const char *, const char *); 7 | #define die_fatal(a, b, cc) die_fatal_(__FILE__, __LINE__, (a), (b), (cc)) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /dropuidgid.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140420 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "e.h" 11 | #include "dropuidgid.h" 12 | 13 | /* 14 | The 'dropuidgid' function is used to drop root privileges. If the process has 15 | appropriate permittions, the 'dropuidgid' function sets user ID and group ID 16 | of calling process to uid and gid. The 'dropuidgid' function also initialize 17 | supplementary group IDs. 18 | */ 19 | int dropuidgid(const char *name, uid_t uid, gid_t gid) { 20 | 21 | /* we can change group only as the root */ 22 | if (geteuid() == 0) { 23 | if (setgid(gid) == -1) return 0; 24 | if (getgid() != gid) { 25 | errno = EPERM; 26 | return 0; 27 | } 28 | if (name) { 29 | if (initgroups(name, gid) == -1) return 0; 30 | } 31 | } 32 | 33 | if (geteuid() != uid) { 34 | if (setuid(uid) == -1) return 0; 35 | if (getuid() != uid) { 36 | errno = EPERM; 37 | return 0; 38 | } 39 | } 40 | return 1; 41 | } 42 | -------------------------------------------------------------------------------- /dropuidgid.h: -------------------------------------------------------------------------------- 1 | #ifndef DROPUIDGID_H____ 2 | #define DROPUIDGID_H____ 3 | 4 | #include 5 | extern int dropuidgid(const char *, uid_t, gid_t); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /env.c: -------------------------------------------------------------------------------- 1 | #include "str.h" 2 | #include "env.h" 3 | 4 | /* 5 | The 'env_get(name)' function returns the value of the first environment 6 | variable whose name is 'name', or 0 if there is no such variable. 7 | */ 8 | char *env_get(const char *name) { 9 | 10 | long long len, i; 11 | 12 | if (!name) return 0; 13 | len = str_len(name); 14 | for (i = 0; environ[i]; ++i) 15 | if (str_start(environ[i], name) && (environ[i][len] == '=')) 16 | return environ[i] + len + 1; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /env.h: -------------------------------------------------------------------------------- 1 | #ifndef ENV_H____ 2 | #define ENV_H____ 3 | 4 | /* 5 | The environment 'environ', is a 0-terminated array 6 | of 0-terminated strings, called environment variables. 7 | Each environment variable is of the form name=value. 8 | */ 9 | extern char **environ; 10 | 11 | extern char *env_get(const char *); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /fe.h: -------------------------------------------------------------------------------- 1 | #ifndef FE_H____ 2 | #define FE_H____ 3 | 4 | #include "crypto_uint32.h" 5 | #include "crypto_uint64.h" 6 | 7 | typedef crypto_uint32 fe[8]; 8 | typedef crypto_uint64 fel[16]; 9 | 10 | extern void fe_0(fe); 11 | extern void fe_1(fe); 12 | extern void fe_copy(fe, const fe); 13 | extern void fe_cswap(fe, fe, crypto_uint32); 14 | extern void fe_cmov(fe, const fe, crypto_uint32); 15 | 16 | extern void fe_mul_(fel, const fe, const fe); 17 | extern void fe_sq_(fel, const fe); 18 | 19 | extern void fe_reducesmall(fe, const fe, const crypto_uint64); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /fe25519.h: -------------------------------------------------------------------------------- 1 | #ifndef FE25519_H____ 2 | #define FE25519_H____ 3 | 4 | #include "fe.h" 5 | 6 | extern void fe25519_mul(fe, const fe, const fe); 7 | extern void fe25519_sq(fe, const fe); 8 | extern void fe25519_add(fe, const fe, const fe); 9 | extern void fe25519_mul121666(fe, const fe); 10 | extern void fe25519_sub(fe, const fe, const fe); 11 | extern void fe25519_neg(fe, const fe); 12 | extern void fe25519_inv(fe, const fe); 13 | extern void fe25519_pow22523(fe, const fe); 14 | 15 | extern void fe25519_tobytes(unsigned char *, const fe); 16 | extern void fe25519_frombytes(fe, const unsigned char *); 17 | 18 | extern int fe25519_isnonzero(const fe); 19 | extern int fe25519_isnegative(const fe); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /ge25519.h: -------------------------------------------------------------------------------- 1 | #ifndef GE25519_H____ 2 | #define GE25519_H____ 3 | 4 | #include "fe.h" 5 | 6 | typedef fe ge25519[4]; /* X, Y, Z, T */ 7 | 8 | extern void ge25519_tobytes(unsigned char *, ge25519); 9 | extern int ge25519_frombytes_negate_vartime(ge25519, const unsigned char *); 10 | extern void ge25519_add(ge25519, ge25519, ge25519); 11 | extern void ge25519_scalarmult(ge25519, ge25519, const unsigned char *); 12 | extern void ge25519_scalarmult_base(ge25519, const unsigned char *); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /getln.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140323 3 | 20241207 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include 10 | #include "e.h" 11 | #include "getln.h" 12 | 13 | static int getch(int fd, char *x) { 14 | 15 | int r; 16 | struct pollfd p; 17 | 18 | for (;;) { 19 | r = read(fd, x, 1); 20 | if (r == -1) { 21 | if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { 22 | p.fd = fd; 23 | p.events = POLLIN | POLLERR; 24 | poll(&p, 1, -1); 25 | continue; 26 | } 27 | } 28 | break; 29 | } 30 | return r; 31 | } 32 | 33 | /* 34 | The function 'getln' reads line from filedescriptor 'fd' into 35 | buffer 'xv' of length 'xmax'. 36 | */ 37 | int getln(int fd, void *xv, long long xmax) { 38 | 39 | long long xlen; 40 | int r; 41 | char ch; 42 | char *x = (char *) xv; 43 | 44 | if (xmax < 1) { 45 | errno = EINVAL; 46 | return -1; 47 | } 48 | x[0] = 0; 49 | if (fd < 0) { 50 | errno = EBADF; 51 | return -1; 52 | } 53 | 54 | xlen = 0; 55 | for (;;) { 56 | if (xlen >= xmax - 1) { 57 | x[xmax - 1] = 0; 58 | errno = ENOMEM; 59 | return -1; 60 | } 61 | r = getch(fd, &ch); 62 | if (r != 1) break; 63 | if (ch == 0) ch = '\n'; 64 | x[xlen++] = ch; 65 | if (ch == '\n') break; 66 | } 67 | x[xlen] = 0; 68 | return r; 69 | } 70 | -------------------------------------------------------------------------------- /getln.h: -------------------------------------------------------------------------------- 1 | #ifndef GETLN_H____ 2 | #define GETLN_H____ 3 | 4 | extern int getln(int, void *, long long); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /global.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140214 3 | 20241207 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | 7 | The 'global' library is used for global memory 8 | initializition and global memory cleanup. 9 | The 'global' library also has space 10 | for 2 versatile buffers. 11 | */ 12 | 13 | #include 14 | #include "newenv.h" 15 | #include "channel.h" 16 | #include "packet.h" 17 | #include "sshcrypto.h" 18 | #include "purge.h" 19 | #include "trymlock.h" 20 | #include "global.h" 21 | 22 | unsigned char global_bspace1[GLOBAL_BSIZE]; 23 | unsigned char global_bspace2[GLOBAL_BSIZE]; 24 | 25 | /* 26 | Initialize memory space. 27 | */ 28 | void global_init(void) { 29 | 30 | packet_init(); 31 | channel_init(); 32 | newenv_init(); 33 | 34 | sshcrypto_init(); 35 | 36 | trymlock(global_bspace1, sizeof global_bspace1); 37 | trymlock(global_bspace2, sizeof global_bspace2); 38 | purge(global_bspace1, sizeof global_bspace1); 39 | purge(global_bspace2, sizeof global_bspace2); 40 | } 41 | 42 | /* 43 | Remove sentitive data from allocated memory. 44 | */ 45 | void global_purge(void) { 46 | 47 | unsigned char stack[4096]; 48 | 49 | purge(stack, sizeof stack); 50 | 51 | packet_purge(); 52 | channel_purge(); 53 | newenv_purge(); 54 | 55 | sshcrypto_purge(); 56 | 57 | purge(global_bspace1, sizeof global_bspace1); 58 | purge(global_bspace2, sizeof global_bspace2); 59 | trymunlock(global_bspace1, sizeof global_bspace1); 60 | trymunlock(global_bspace2, sizeof global_bspace2); 61 | } 62 | 63 | /* 64 | Remove sentitive data from allocated memory 65 | and exit with status 'x'. 66 | */ 67 | __attribute__((noreturn)) void global_die(int x) { 68 | global_purge(); 69 | _exit(x); 70 | } 71 | -------------------------------------------------------------------------------- /global.h: -------------------------------------------------------------------------------- 1 | #ifndef GLOBAL_H____ 2 | #define GLOBAL_H____ 3 | 4 | #define GLOBAL_BSIZE 65536 5 | extern unsigned char global_bspace1[GLOBAL_BSIZE]; 6 | extern unsigned char global_bspace2[GLOBAL_BSIZE]; 7 | 8 | extern void global_init(void); 9 | extern void global_purge(void); 10 | extern void global_die(int); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /haslib1305.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) { 4 | int ret = 0; 5 | long long i; 6 | unsigned char k[poly1305_KEYBYTES] = {2}; 7 | unsigned char m[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 8 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 9 | unsigned char a[poly1305_BYTES]; 10 | unsigned char o[poly1305_BYTES] = {3}; 11 | 12 | (void) argc; 13 | (void) argv; 14 | 15 | ret |= -poly1305_verify(0, m, sizeof m, k); 16 | poly1305(a, m, sizeof m, k); 17 | for (i = 0; i < poly1305_BYTES; ++i) ret |= (o[i] ^ a[i]); 18 | return ret; 19 | } 20 | -------------------------------------------------------------------------------- /haslibntruprime.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* return zero for all inputs */ 4 | static unsigned char z(unsigned char x) { 5 | 6 | unsigned long long z = (unsigned long long) x + 1ULL; 7 | unsigned long long t = z; 8 | long long i; 9 | 10 | for (i = 6; i >= 0; --i) { 11 | t = (t * t) % 257; 12 | t = (t * z) % 257; 13 | } 14 | t = (t * z) % 257; 15 | return t - 1; 16 | } 17 | 18 | static unsigned char pk[sntrup761_PUBLICKEYBYTES]; 19 | static unsigned char sk[sntrup761_SECRETKEYBYTES]; 20 | static unsigned char c[sntrup761_CIPHERTEXTBYTES]; 21 | static unsigned char k1[sntrup761_BYTES]; 22 | static unsigned char k2[sntrup761_BYTES]; 23 | 24 | int main(int argc, char **argv) { 25 | unsigned char ret = 0; 26 | unsigned long long i; 27 | 28 | (void) argc; 29 | (void) argv; 30 | 31 | sntrup761_keypair(pk, sk); 32 | sntrup761_enc(c, k1, pk); 33 | sntrup761_dec(k2, c, sk); 34 | for (i = 0; i < sntrup761_BYTES; ++i) ret |= k1[i] ^ k2[i]; 35 | for (i = 0; i < sizeof k1; ++i) ret |= z(k1[i]); 36 | return ret; 37 | } 38 | -------------------------------------------------------------------------------- /haslibrandombytes.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* return zero for all inputs */ 4 | static unsigned char z(unsigned char x) { 5 | 6 | unsigned long long z = (unsigned long long) x + 1ULL; 7 | unsigned long long t = z; 8 | long long i; 9 | 10 | for (i = 6; i >= 0; --i) { 11 | t = (t * t) % 257; 12 | t = (t * z) % 257; 13 | } 14 | t = (t * z) % 257; 15 | return (unsigned char) t - 1; 16 | } 17 | 18 | int main(int argc, char **argv) { 19 | unsigned char buf[32], ret = 0; 20 | const char *source; 21 | unsigned long long i; 22 | 23 | (void) argc; 24 | (void) argv; 25 | 26 | randombytes(buf, sizeof buf); 27 | for (i = 0; i < sizeof buf; ++i) ret |= z(buf[i]); 28 | source = randombytes_source(); 29 | for (i = 0; source[i]; ++i) ret |= z((unsigned char) source[i]); 30 | return z(ret); 31 | } 32 | -------------------------------------------------------------------------------- /haslibutilh.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | int main(void) { return 0; } 5 | -------------------------------------------------------------------------------- /haslimits.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | int main(void) { return 0; } 5 | -------------------------------------------------------------------------------- /haslogintty.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | extern int login_tty(int); 3 | 4 | static void foo(void) { login_tty(0); } 5 | 6 | int main(int argc, char **argv) { 7 | if (!argc) foo(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /hasmlock.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | int main(void) { 5 | char x[16] = {0}; 6 | mlock(x, sizeof x); 7 | munlock(x, sizeof x); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /hasopenpty.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | extern int openpty(int *, int *, char *, struct termios *, struct winsize *); 7 | 8 | static void foo(void) { 9 | int master, slave; 10 | openpty(&master, &slave, 0, 0, 0); 11 | } 12 | 13 | int main(int argc, char **argv) { 14 | if (!argc) foo(); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /hasutilh.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | int main(void) { return 0; } 5 | -------------------------------------------------------------------------------- /hasutmp.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut = {0}; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /hasutmpaddrv6.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut; 9 | int x[sizeof(ut.ut_addr_v6) < 16 ? -1 : 1] = {0}; 10 | return x[0]; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmphost.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut; 9 | if (sizeof ut.ut_host < 8) return 111; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmploginlogout.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | extern void login(const struct utmp *); 7 | extern int logout(const char *); 8 | 9 | static void foo(void) { 10 | struct utmp ut = {0}; 11 | login(&ut); 12 | logout(ut.ut_line); 13 | } 14 | 15 | int main(int argc, char **argv) { 16 | if (!argc) foo(); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /hasutmplogwtmp.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | 3 | extern void logwtmp(const char *, const char *, const char *); 4 | 5 | static void foo(void) { logwtmp("", "", ""); } 6 | 7 | int main(int argc, char **argv) { 8 | if (!argc) foo(); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /hasutmpname.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut; 9 | if (sizeof ut.ut_name < 8) return 111; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmppid.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut = {0}; 9 | return ut.ut_pid; 10 | } 11 | -------------------------------------------------------------------------------- /hasutmptime.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | struct utmp ut = {0}; 8 | return ut.ut_time; 9 | } 10 | -------------------------------------------------------------------------------- /hasutmptv.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut = {0}; 9 | return ut.ut_tv.tv_sec + ut.ut_tv.tv_usec; 10 | } 11 | -------------------------------------------------------------------------------- /hasutmptype.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut; 9 | ut.ut_type = USER_PROCESS | DEAD_PROCESS; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmpuser.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmp ut; 9 | if (sizeof ut.ut_user < 8) return 111; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmpx.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | static void foo(void) { 5 | 6 | struct utmpx ut; 7 | 8 | ut.ut_type = DEAD_PROCESS; 9 | ut.ut_type = USER_PROCESS; 10 | ut.ut_type = 0; 11 | 12 | setutxent(); 13 | pututxline(&ut); 14 | endutxent(); 15 | } 16 | 17 | int main(int argc, char **argv) { 18 | if (!argc) foo(); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /hasutmpxaddrv6.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | #include 4 | #include 5 | 6 | int main(void) { 7 | 8 | struct utmpx utx; 9 | int x[sizeof(utx.ut_addr_v6) < 16 ? -1 : 1] = {0}; 10 | return x[0]; 11 | } 12 | -------------------------------------------------------------------------------- /hasutmpxsyslen.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | int main(void) { 5 | 6 | struct utmpx ut = {0}; 7 | return ut.ut_syslen; 8 | } 9 | -------------------------------------------------------------------------------- /hasutmpxupdwtmpx.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | #include 3 | 4 | static void foo(void) { 5 | struct utmpx ut = {0}; 6 | updwtmpx("/nonexistent", &ut); 7 | } 8 | 9 | int main(int argc, char **argv) { 10 | (void) argv; 11 | if (!argc) foo(); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /hasvalgrind.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* return zero for all inputs */ 4 | static unsigned char z(unsigned char x) { 5 | 6 | unsigned long long z = (unsigned long long) x + 1ULL; 7 | unsigned long long t = z; 8 | long long i; 9 | 10 | for (i = 6; i >= 0; --i) { 11 | t = (t * t) % 257; 12 | t = (t * z) % 257; 13 | } 14 | t = (t * z) % 257; 15 | return (unsigned char) t - 1; 16 | } 17 | 18 | static void secret(void *xv, long long xlen) { 19 | VALGRIND_MAKE_MEM_UNDEFINED(xv, xlen); 20 | } 21 | 22 | static void public(void *xv, long long xlen) { 23 | VALGRIND_MAKE_MEM_DEFINED(xv, xlen); 24 | } 25 | 26 | int main(int argc, char **argv) { 27 | 28 | unsigned char buf[32] = {1}; 29 | unsigned char ret = 0; 30 | unsigned long long i; 31 | 32 | (void) argc; 33 | (void) argv; 34 | 35 | secret(buf, sizeof buf); 36 | for (i = 0; i < sizeof buf; ++i) ret |= z(buf[i]); 37 | public(buf, sizeof buf); 38 | for (i = 0; i < sizeof buf; ++i) ret |= z(buf[i]); 39 | return ret; 40 | } 41 | -------------------------------------------------------------------------------- /int16_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/int16_optblocker.c -------------------------------------------------------------------------------- /int32_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/int32_optblocker.c -------------------------------------------------------------------------------- /int64_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/int64_optblocker.c -------------------------------------------------------------------------------- /int8_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/int8_optblocker.c -------------------------------------------------------------------------------- /iptostr.h: -------------------------------------------------------------------------------- 1 | #ifndef IPTOSTR_H____ 2 | #define IPTOSTR_H____ 3 | 4 | #define IPTOSTR_LEN 46 5 | 6 | extern char *iptostr(char *, const unsigned char *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /limit.h: -------------------------------------------------------------------------------- 1 | #ifndef LIMIT_H____ 2 | #define LIMIT_H____ 3 | 4 | #include "haslimits.h" 5 | #ifdef HASLIMITS 6 | #include 7 | #endif 8 | 9 | #ifndef LOGIN_NAME_MAX 10 | #define LOGIN_NAME_MAX 256 11 | #endif 12 | 13 | #ifndef NAME_MAX 14 | #define NAME_MAX 255 15 | #endif 16 | 17 | #ifndef TTY_NAME_MAX 18 | #define TTY_NAME_MAX 32 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /load.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from curvecp/load.c 3 | - reformated using clang-format 4 | */ 5 | #include 6 | #include "readall.h" 7 | #include "open.h" 8 | #include "e.h" 9 | #include "load.h" 10 | 11 | int load(const char *fn, void *x, long long xlen) { 12 | int fd; 13 | int r; 14 | fd = open_read(fn); 15 | if (fd == -1) return -1; 16 | r = readall(fd, x, xlen); 17 | close(fd); 18 | return r; 19 | } 20 | -------------------------------------------------------------------------------- /load.h: -------------------------------------------------------------------------------- 1 | #ifndef LOAD_H____ 2 | #define LOAD_H____ 3 | 4 | extern int load(const char *, void *, long long); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /loginshell.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140429 3 | 20241208 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "e.h" 9 | #include "loginshell.h" 10 | 11 | /* 12 | The 'loginshell()' function converts shell path 13 | into -shell name. For example: 14 | '/bin/sh' -> '-sh' 15 | '/usr/pkg/bin/bash' -> '-bash' 16 | */ 17 | 18 | int loginshell(char *out, long long outlen, const char *in) { 19 | 20 | long long len, pos = -1; 21 | 22 | if (!out || !in || outlen < 2) { 23 | errno = EINVAL; 24 | return 0; 25 | } 26 | 27 | for (len = 0; in[len]; ++len) 28 | if (in[len] == '/') pos = len; 29 | in += pos + 1; 30 | len -= pos + 1; 31 | if (len > outlen - 2) len = outlen - 2; /* truncate name */ 32 | 33 | *out++ = '-'; 34 | while (len > 0) { 35 | *out++ = *in++; 36 | --len; 37 | } 38 | *out = 0; 39 | 40 | return 1; 41 | } 42 | -------------------------------------------------------------------------------- /loginshell.h: -------------------------------------------------------------------------------- 1 | #ifndef LOGINSHELL_H____ 2 | #define LOGINSHELL_H____ 3 | 4 | extern int loginshell(char *, long long, const char *); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /logsys.h: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | 3 | #ifndef LOGSYS_H____ 4 | #define LOGSYS_H____ 5 | 6 | void logsys_login(const char *, const char *, const char *, long long); 7 | void logsys_logout(const char *, const char *, const char *, long long); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H____ 2 | #define MAIN_H____ 3 | 4 | extern int main_tinysshd(int, char **, const char *); 5 | extern int main_tinysshd_printkey(int, char **); 6 | extern int main_tinysshd_makekey(int, char **); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /main_tinysshd_printkey.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20150124 3 | 20241212 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include "e.h" 10 | #include "load.h" 11 | #include "sshcrypto.h" 12 | #include "crypto.h" 13 | #include "global.h" 14 | #include "buf.h" 15 | #include "log.h" 16 | #include "writeall.h" 17 | #include "die.h" 18 | #include "main.h" 19 | 20 | static struct buf b1 = {global_bspace1, 0, 21 | sizeof global_bspace1}; /* reusing global buffer */ 22 | static struct buf b2 = {global_bspace2, 0, 23 | sizeof global_bspace2}; /* reusing global buffer */ 24 | static unsigned char pk[sshcrypto_sign_PUBLICKEYMAX]; 25 | 26 | #define USAGE "usage: tinysshd-printkey keydir" 27 | 28 | int main_tinysshd_printkey(int argc, char **argv) { 29 | 30 | char *x; 31 | long long i; 32 | 33 | log_init(3, "tinysshd-printkey", 0, 0); 34 | 35 | if (argc < 2) die_usage(USAGE); 36 | if (!argv[0]) die_usage(USAGE); 37 | for (;;) { 38 | if (!argv[1]) break; 39 | if (argv[1][0] != '-') break; 40 | x = *++argv; 41 | if (x[0] == '-' && x[1] == 0) break; 42 | if (x[0] == '-' && x[1] == '-' && x[2] == 0) break; 43 | while (*++x) { die_usage(USAGE); } 44 | } 45 | x = *++argv; 46 | if (!x) die_usage(USAGE); 47 | 48 | if (chdir(x) == -1) die_fatal("unable to chdir to directory", x, 0); 49 | 50 | /* read public keys */ 51 | for (i = 0; sshcrypto_keys[i].name; ++i) { 52 | if (load(sshcrypto_keys[i].sign_publickeyfilename, pk, 53 | sshcrypto_keys[i].sign_publickeybytes) == -1) { 54 | if (errno == ENOENT) continue; 55 | die_fatal("unable to read public key from file", x, 56 | sshcrypto_keys[i].sign_publickeyfilename); 57 | } 58 | 59 | buf_purge(&b1); 60 | sshcrypto_keys[i].buf_putsignpk(&b1, pk); 61 | if (b1.len < 4) die_fatal("unable to get publickey", 0, 0); 62 | 63 | /* base64 */ 64 | buf_purge(&b2); 65 | buf_puts(&b2, sshcrypto_keys[i].name); 66 | buf_puts(&b2, " "); 67 | buf_putbase64(&b2, b1.buf + 4, b1.len - 4); 68 | buf_puts(&b2, "\n"); 69 | if (writeall(1, b2.buf, b2.len) == -1) 70 | die_fatal("unable to write output", 0, 0); 71 | } 72 | global_die(0); 73 | return 111; 74 | } 75 | -------------------------------------------------------------------------------- /man/tinysshd-makekey.8: -------------------------------------------------------------------------------- 1 | .TH tinysshd\-makekey 8 2 | .SH NAME 3 | tinysshd\-makekey \- create TinySSH key\-directory 4 | .SH SYNOPSIS 5 | .B tinysshd\-makekey 6 | [ options ] 7 | .I keydir 8 | .SH DESCRIPTION 9 | .B tinysshd\-makekey 10 | safely creates secret\-keys and appropriate public\-keys in directory 11 | .I keydir 12 | .SH OPTIONS 13 | .TP 14 | .B \-q 15 | no error messages 16 | .TP 17 | .B \-Q 18 | print error messages (default) 19 | .TP 20 | .TP 21 | .I keydir 22 | directory for TinySSH keys, typically /etc/tinyssh/sshkeydir 23 | .SH EXAMPLE 24 | tinysshd\-makekey /etc/tinyssh/sshkeydir 25 | .SH SEE ALSO 26 | .BR tinysshd (8), 27 | .BR tinysshd\-printkey (8) 28 | .sp 29 | .nf 30 | https://tinyssh.org/ 31 | .fi 32 | -------------------------------------------------------------------------------- /man/tinysshd-printkey.8: -------------------------------------------------------------------------------- 1 | .TH tinysshd\-printkey 8 2 | .SH NAME 3 | tinysshd\-printkey \- print TinySSH public\-keys 4 | .SH SYNOPSIS 5 | .B tinysshd\-printkey 6 | .I keydir 7 | .SH DESCRIPTION 8 | .B tinysshd\-printkey 9 | prints TinySSH public\-keys in base64 format 10 | .SH OPTIONS 11 | .TP 12 | .I keydir 13 | directory containing TinySSH keys, typically /etc/tinyssh/sshkeydir 14 | .SH EXAMPLE 15 | tinysshd\-printkey /etc/tinyssh/sshkeydir 16 | .SH SEE ALSO 17 | .BR tinysshd (8), 18 | .BR tinysshd\-makekey (8) 19 | .sp 20 | .nf 21 | https://tinyssh.org/ 22 | .fi 23 | -------------------------------------------------------------------------------- /man/tinysshnoneauthd.8: -------------------------------------------------------------------------------- 1 | .TH tinysshnoneauthd 8 2 | .SH NAME 3 | tinysshnoneauthd \- Tiny SSH daemon with 'none' auth. enabled 4 | .SH SYNOPSIS 5 | .B tinysshnoneauthd 6 | [ options ] 7 | .I keydir 8 | .SH DESCRIPTION 9 | .B tinysshnoneauthd 10 | creates encrypted (but not auhenticated) SSH connection. 11 | It's used to protect older protocols which uses e.g. telnet etc. 12 | .SH OPTIONS 13 | .TP 14 | .B \-q 15 | no error messages 16 | .TP 17 | .B \-Q 18 | print error messages (default) 19 | .TP 20 | .B \-v 21 | print extra information 22 | .TP 23 | .B \-l 24 | use syslog instead of standard error output (useful for running from inetd) 25 | .TP 26 | .B \-L 27 | don't use syslog, use standard error output (default) 28 | .TP 29 | .B \-e \fIcommand 30 | execute the given command instead of spawning the shell (disables \fIexec\fR/\fIsubsystem\fR channel requests) 31 | .TP 32 | .I keydir 33 | directory containing TinySSH keys, typically /etc/tinyssh/sshkeydir 34 | .SH EXAMPLES 35 | .TP 36 | .B TCPSERVER 37 | .nf 38 | useradd tinysshnoneauth 39 | mkdir -p /home/tinysshnoneauth/ 40 | tinysshd-makekey /home/tinysshnoneauth/sshkeydir 41 | chown -R tinysshnoneauth /home/tinysshnoneauth/sshkeydir 42 | envuidgid tinysshnoneauth tcpserver -UHRDl0 0 2222 /usr/sbin/tinysshnoneauthd -vv -e 'cat /etc/motd' /home/tinysshnoneauth/sshkeydir 43 | .fi 44 | .SH SEE ALSO 45 | .BR tinysshd (8), 46 | .BR tinysshd\-makekey (8), 47 | .BR tinysshd\-printkey (8) 48 | .sp 49 | .nf 50 | https://tinyssh.org/ 51 | .fi 52 | -------------------------------------------------------------------------------- /newenv.h: -------------------------------------------------------------------------------- 1 | #ifndef NEWENV_H____ 2 | #define NEWENV_H____ 3 | 4 | extern int newenv_env_(int, const char *, const char *); 5 | 6 | #define newenv_env(x, y) newenv_env_(1, (x), (y)) 7 | #define newenv_lowenv(x, y) newenv_env_(2, (x), (y)) 8 | extern int newenv_copyenv(const char *); 9 | extern void newenv_exec(char *, char **); 10 | extern void newenv_init(void); 11 | extern void newenv_purge(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /numtostr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20130604 3 | 20241208 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "numtostr.h" 9 | 10 | /* 11 | The 'numtostr(strbuf,n)' converts number 'n' into the 0-terminated string. 12 | The caller must allocate at least NUMTOSTR_LEN bytes for 'strbuf'. 13 | The 'numtostr' function is ready for 128-bit integer. 14 | */ 15 | char *numtostr(char *strbuf, long long n) { 16 | 17 | long long len = 0; 18 | unsigned long long n1, n2; 19 | static char staticbuf[NUMTOSTR_LEN]; 20 | int flagsign = 0; 21 | 22 | if (!strbuf) strbuf = staticbuf; /* not thread-safe */ 23 | 24 | if (n < 0) { 25 | n1 = n2 = -(unsigned long long) n; 26 | flagsign = 1; 27 | } 28 | else { n1 = n2 = (unsigned long long) n; } 29 | 30 | do { 31 | n1 /= 10; 32 | ++len; 33 | } while (n1); 34 | if (flagsign) ++len; 35 | strbuf += len; 36 | 37 | do { 38 | *--strbuf = '0' + (n2 % 10); 39 | n2 /= 10; 40 | } while (n2); 41 | if (flagsign) *--strbuf = '-'; 42 | 43 | while (len < NUMTOSTR_LEN) strbuf[len++] = 0; 44 | return strbuf; 45 | } 46 | -------------------------------------------------------------------------------- /numtostr.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMTOSTR_H____ 2 | #define NUMTOSTR_H____ 3 | 4 | #define NUMTOSTR_LEN 41 5 | 6 | extern char *numtostr(char *, long long); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /old/INSTALL: -------------------------------------------------------------------------------- 1 | See https://tinyssh.org/install.html 2 | -------------------------------------------------------------------------------- /old/LICENCE: -------------------------------------------------------------------------------- 1 | ../LICENCE -------------------------------------------------------------------------------- /old/Makefile: -------------------------------------------------------------------------------- 1 | compile: make-tinyssh.sh 2 | sh -e make-tinyssh.sh 3 | cross-compile: make-tinysshcc.sh 4 | sh -e make-tinysshcc.sh 5 | clean: 6 | rm -rf build 7 | install: 8 | sh -e make-install.sh $(DESTDIR) 9 | deb: 10 | dpkg-buildpackage -b -rfakeroot -us -uc 11 | -------------------------------------------------------------------------------- /old/README.md: -------------------------------------------------------------------------------- 1 | ../README.md -------------------------------------------------------------------------------- /old/_tinyssh/_TARGETS: -------------------------------------------------------------------------------- 1 | _tinysshd-printkex 2 | _tinysshd-unauthenticated 3 | _tinysshd-test-hello1 4 | _tinysshd-test-hello2 5 | _tinysshd-test-kex1 6 | _tinysshd-test-kex2 7 | _tinysshd-speed 8 | -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-printkex.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-printkex.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-speed.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-speed.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-test-hello1.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-test-hello1.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-test-hello2.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-test-hello2.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-test-kex1.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-test-kex1.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-test-kex2.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-test-kex2.c -------------------------------------------------------------------------------- /old/_tinyssh/_tinysshd-unauthenticated.c: -------------------------------------------------------------------------------- 1 | ../../_tinysshd-unauthenticated.c -------------------------------------------------------------------------------- /old/conf-ar: -------------------------------------------------------------------------------- 1 | ar 2 | -------------------------------------------------------------------------------- /old/conf-bin: -------------------------------------------------------------------------------- 1 | /usr/sbin 2 | -------------------------------------------------------------------------------- /old/conf-cc: -------------------------------------------------------------------------------- 1 | cc 2 | gcc 3 | clang 4 | -------------------------------------------------------------------------------- /old/conf-cflags: -------------------------------------------------------------------------------- 1 | -pedantic 2 | -Wall 3 | -Wno-long-long 4 | -Wno-overlength-strings 5 | -Wno-unused-function 6 | -Wshadow 7 | -Wdeclaration-after-statement 8 | -Wwrite-strings 9 | -Wmissing-declarations 10 | -Wmissing-prototypes 11 | -Wstrict-prototypes 12 | -Wunused-value 13 | -Wunused-parameter 14 | -Wundef 15 | -fstack-protector-strong 16 | -fwrapv 17 | -fno-strict-overflow 18 | -Os 19 | -fomit-frame-pointer 20 | -funroll-loops 21 | -------------------------------------------------------------------------------- /old/conf-libs: -------------------------------------------------------------------------------- 1 | -lutil 2 | -lsocket -lnsl 3 | -------------------------------------------------------------------------------- /old/conf-man: -------------------------------------------------------------------------------- 1 | /usr/share/man 2 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_dh_x25519test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | 5 | _exit(0); 6 | } 7 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_hash_sha256test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20141018 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "misc.h" 8 | #include "crypto_hash_sha256.h" 9 | 10 | #define SPACESIZE 5232 11 | 12 | static unsigned char space[SPACESIZE + 16]; 13 | static unsigned char buf[crypto_hash_sha256_BYTES + 16]; 14 | 15 | static unsigned char test_pseudorandom_checksum[32] = { 16 | 0xbd, 0x62, 0xb1, 0x24, 0x12, 0xce, 0xc2, 0xd6, 17 | 0xc9, 0x81, 0x29, 0x7f, 0x83, 0x8a, 0xe5, 0x19, 18 | 0xfd, 0xd7, 0x26, 0x4f, 0x13, 0x7e, 0xd5, 0x18, 19 | 0x40, 0x53, 0x76, 0x16, 0xe4, 0x22, 0x48, 0x50 20 | }; 21 | 22 | static void test_pseudorandom(void) { 23 | 24 | long long i, j; 25 | 26 | checksum_zero(); 27 | i = 0; 28 | for (j = 0; j < SPACESIZE; j += 1 + j / 16) { 29 | pseudorandombytes(space + i, j); 30 | crypto_hash_sha256(buf + i, space + i, j); 31 | checksum(buf + i, crypto_hash_sha256_BYTES); 32 | ++i; 33 | i %= 16; 34 | } 35 | fail_whenbadchecksum(test_pseudorandom_checksum); 36 | } 37 | 38 | int main(void) { 39 | 40 | test_pseudorandom(); 41 | _exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_hash_sha512test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20141018 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "misc.h" 8 | #include "crypto_hash_sha512.h" 9 | 10 | #define SPACESIZE 5232 11 | 12 | static unsigned char space[SPACESIZE + 16]; 13 | static unsigned char buf[crypto_hash_sha512_BYTES + 16]; 14 | 15 | static unsigned char test_pseudorandom_checksum[32] = { 16 | 0xa1, 0x57, 0x2f, 0x67, 0x19, 0xa6, 0x88, 0x2f, 17 | 0x54, 0xa5, 0xa4, 0x7d, 0xe2, 0xd3, 0xa3, 0xfd, 18 | 0xd1, 0x1a, 0x73, 0x58, 0x84, 0xc7, 0xb9, 0xfd, 19 | 0x7f, 0xa2, 0x33, 0xbf, 0x86, 0xf7, 0x15, 0xee 20 | }; 21 | 22 | static void test_pseudorandom(void) { 23 | 24 | long long i, j; 25 | 26 | checksum_zero(); 27 | i = 0; 28 | for (j = 0; j < SPACESIZE; j += 1 + j / 16) { 29 | pseudorandombytes(space + i, j); 30 | crypto_hash_sha512(buf + i, space + i, j); 31 | checksum(buf + i, crypto_hash_sha512_BYTES); 32 | ++i; 33 | i %= 16; 34 | } 35 | fail_whenbadchecksum(test_pseudorandom_checksum); 36 | } 37 | 38 | int main(void) { 39 | 40 | test_pseudorandom(); 41 | _exit(0); 42 | } 43 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_onetimeauth_poly1305test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20141017 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "misc.h" 8 | #include "crypto_onetimeauth_poly1305.h" 9 | 10 | #define SPACESIZE 5232 11 | 12 | static unsigned char space[SPACESIZE + 16]; 13 | static unsigned char key[crypto_onetimeauth_poly1305_KEYBYTES + 16]; 14 | static unsigned char buf[crypto_onetimeauth_poly1305_BYTES + 16]; 15 | 16 | static unsigned char test_pseudorandom_checksum[32] = { 17 | 0xaf, 0xe7, 0xbb, 0x79, 0x2a, 0xe5, 0x81, 0xee, 18 | 0xbc, 0x1f, 0x5b, 0x79, 0x96, 0xb7, 0x27, 0x1a, 19 | 0xc2, 0x74, 0x65, 0x0e, 0x1d, 0xb5, 0xb7, 0x06, 20 | 0x10, 0x42, 0x6a, 0x50, 0x57, 0x8b, 0xf1, 0xb0 21 | }; 22 | 23 | 24 | static void test_pseudorandom(void) { 25 | 26 | long long i, j; 27 | 28 | checksum_zero(); 29 | i = 0; 30 | for (j = 0; j < SPACESIZE; j += 1 + j / 16) { 31 | 32 | pseudorandombytes(space + i, j); 33 | pseudorandombytes(key + i, crypto_onetimeauth_poly1305_KEYBYTES); 34 | 35 | crypto_onetimeauth_poly1305(buf + i, space + i, j, key + i); 36 | checksum(buf + i, crypto_onetimeauth_poly1305_BYTES); 37 | 38 | if (crypto_onetimeauth_poly1305_verify(buf + i, space + i, j, key + i) != 0) { 39 | fail_printdata("m", space + i, j); 40 | fail_printdata("key", key + i, crypto_onetimeauth_poly1305_KEYBYTES); 41 | fail_printdata("a", buf + i, crypto_onetimeauth_poly1305_BYTES); 42 | fail("crypto_onetimeauth_poly1305_verify() failure"); 43 | } 44 | ++i; 45 | i %= 16; 46 | } 47 | fail_whenbadchecksum(test_pseudorandom_checksum); 48 | } 49 | 50 | static void test_1(void) { 51 | 52 | unsigned char k[32] = {2}; 53 | unsigned char m[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 54 | unsigned char o[16] = {3}; 55 | if (crypto_onetimeauth_poly1305_verify(o, m, sizeof m, k) != 0) { 56 | fail("crypto_onetimeauth_poly1305_verify() failure"); 57 | } 58 | } 59 | 60 | 61 | int main(void) { 62 | 63 | test_pseudorandom(); 64 | test_1(); 65 | 66 | _exit(0); 67 | } 68 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_sort_uint32test.c: -------------------------------------------------------------------------------- 1 | #include "misc.h" 2 | #include "crypto_uint32.h" 3 | #include "crypto_sort_uint32.h" 4 | 5 | static void test_321(void) { 6 | 7 | crypto_uint32 x[3] = {3, 2, 1}; 8 | 9 | crypto_sort_uint32(x, 3); 10 | 11 | if (x[0] != 1) fail("crypto_sort_uint32() failure"); 12 | if (x[1] != 2) fail("crypto_sort_uint32() failure"); 13 | if (x[2] != 3) fail("crypto_sort_uint32() failure"); 14 | } 15 | 16 | static void test_i(void) { 17 | 18 | crypto_uint32 x[5] = { (crypto_uint32) -1, (crypto_uint32) -2, 2, 1, 0}; 19 | 20 | crypto_sort_uint32(x, 5); 21 | 22 | if (x[0] != 0) fail("crypto_sort_uint32() failure"); 23 | if (x[1] != 1) fail("crypto_sort_uint32() failure"); 24 | if (x[2] != 2) fail("crypto_sort_uint32() failure"); 25 | if (x[3] != (crypto_uint32) -2) fail("crypto_sort_uint32() failure"); 26 | if (x[4] != (crypto_uint32) -1) fail("crypto_sort_uint32() failure"); 27 | } 28 | 29 | int main(void) { 30 | 31 | test_321(); 32 | test_i(); 33 | _exit(0); 34 | } 35 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_stream_chacha20test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140709 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "misc.h" 9 | #include "crypto_stream_chacha20.h" 10 | 11 | static unsigned char space[5232]; 12 | static unsigned char k[crypto_stream_chacha20_KEYBYTES + 16]; 13 | static unsigned char n[crypto_stream_chacha20_NONCEBYTES + 16]; 14 | 15 | static unsigned char o[32] = { 16 | 0x98, 0x43, 0x28, 0xe2, 0x76, 0xc2, 0xc3, 0xa1, 17 | 0xe8, 0xf3, 0x50, 0x98, 0x15, 0xc4, 0xea, 0xa6, 18 | 0x2c, 0x54, 0x87, 0x1b, 0x02, 0x4c, 0x61, 0xd1, 19 | 0x01, 0xd9, 0xf0, 0xb1, 0xd5, 0x21, 0xc4, 0x7a 20 | }; 21 | 22 | static void test_alignment(void) { 23 | 24 | long long i; 25 | 26 | for (i = 0; i < 16; ++i) { 27 | crypto_stream_chacha20_xor(space + i, space + i, sizeof space - i, n + i, k + i); 28 | } 29 | } 30 | 31 | static void test_rand(void) { 32 | 33 | long long i, j; 34 | unsigned int u; 35 | 36 | pseudorandombytes(space, sizeof space); 37 | pseudorandombytes(k, sizeof k); 38 | pseudorandombytes(n, sizeof n); 39 | 40 | for (i = 0; i < sizeof space; i += 1 + i / 16) { 41 | u = 1; 42 | for (j = 0; j < 8; ++j) { 43 | u += (unsigned int) n[j]; 44 | n[j] = u; 45 | u >>= 8; 46 | } 47 | crypto_stream_chacha20_xor(space, space, i, n, k); 48 | } 49 | checksum(space, sizeof space); 50 | fail_whenbadchecksum(o); 51 | } 52 | 53 | 54 | int main(void) { 55 | 56 | test_alignment(); 57 | test_rand(); 58 | _exit(0); 59 | } 60 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_verify_16test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140167 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "misc.h" 8 | #include "crypto_verify_16.h" 9 | 10 | static unsigned char b1[crypto_verify_16_BYTES + 16]; 11 | static unsigned char b2[crypto_verify_16_BYTES + 16]; 12 | 13 | 14 | static void test_alignment(void) { 15 | 16 | long long i; 17 | 18 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 19 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff; 20 | 21 | for (i = 0; i < 16; ++i) { 22 | if (crypto_verify_16(b1 + i, b2 + i) != 0) fail("crypto_verify_16 failure"); 23 | } 24 | } 25 | 26 | static void test_verify(void) { 27 | 28 | long long i; 29 | 30 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 31 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff; 32 | 33 | if (crypto_verify_16(b1, b2) != 0) fail("crypto_verify_16 failure"); 34 | 35 | for (i = 0; i < crypto_verify_16_BYTES; ++i) { 36 | b1[i] = 0; 37 | if (crypto_verify_16(b1, b2) == 0) fail("crypto_verify_16 failure"); 38 | b1[i] = 0xff; 39 | } 40 | } 41 | 42 | int main(void) { 43 | 44 | test_alignment(); 45 | test_verify(); 46 | 47 | _exit(0); 48 | } 49 | -------------------------------------------------------------------------------- /old/crypto-tests/crypto_verify_32test.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140167 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "misc.h" 8 | #include "crypto_verify_32.h" 9 | 10 | static unsigned char b1[crypto_verify_32_BYTES + 16]; 11 | static unsigned char b2[crypto_verify_32_BYTES + 16]; 12 | 13 | 14 | static void test_alignment(void) { 15 | 16 | long long i; 17 | 18 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 19 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff; 20 | 21 | for (i = 0; i < 16; ++i) { 22 | if (crypto_verify_32(b1 + i, b2 + i) != 0) fail("crypto_verify_32 failure"); 23 | } 24 | } 25 | 26 | static void test_verify(void) { 27 | 28 | long long i; 29 | 30 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 31 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff; 32 | 33 | if (crypto_verify_32(b1, b2) != 0) fail("crypto_verify_32 failure"); 34 | 35 | for (i = 0; i < crypto_verify_32_BYTES; ++i) { 36 | b1[i] = 0; 37 | if (crypto_verify_32(b1, b2) == 0) fail("crypto_verify_32 failure"); 38 | b1[i] = 0xff; 39 | } 40 | } 41 | 42 | int main(void) { 43 | 44 | test_alignment(); 45 | test_verify(); 46 | 47 | _exit(0); 48 | } 49 | -------------------------------------------------------------------------------- /old/crypto-tests/precomp.data.py: -------------------------------------------------------------------------------- 1 | import binascii 2 | 3 | f = open("precomp.txt") 4 | 5 | def l(line): 6 | 7 | l = "" 8 | for i in range(32): 9 | if i == 31: 10 | l += "0x%s%s" % (line[2*i], line[2*i+1]) 11 | else: 12 | l += "0x%s%s," % (line[2*i], line[2*i+1]) 13 | return l 14 | 15 | 16 | while True: 17 | line=f.readline() 18 | if len(line) == 0: 19 | f.close() 20 | break 21 | print "{", l(line), "}," 22 | -------------------------------------------------------------------------------- /old/crypto-tests/precomp_curve25519.data.py: -------------------------------------------------------------------------------- 1 | import binascii 2 | 3 | P = 2 ** 255 - 19 4 | A = 486662 5 | 6 | def expmod(b, e, m): 7 | if e == 0: return 1 8 | t = expmod(b, e / 2, m) ** 2 % m 9 | if e & 1: t = (t * b) % m 10 | return t 11 | 12 | def inv(x): 13 | return expmod(x, P - 2, P) 14 | 15 | # Addition and doubling formulas taken from Appendix D of "Curve25519: 16 | # new Diffie-Hellman speed records". 17 | 18 | def add((xn,zn), (xm,zm), (xd,zd)): 19 | x = 4 * (xm * xn - zm * zn) ** 2 * zd 20 | z = 4 * (xm * zn - zm * xn) ** 2 * xd 21 | return (x % P, z % P) 22 | 23 | def double((xn,zn)): 24 | x = (xn ** 2 - zn ** 2) ** 2 25 | z = 4 * xn * zn * (xn ** 2 + A * xn * zn + zn ** 2) 26 | return (x % P, z % P) 27 | 28 | def curve25519(n, base): 29 | one = (base,1) 30 | two = double(one) 31 | # f(m) evaluates to a tuple containing the mth multiple and the 32 | # (m+1)th multiple of base. 33 | def f(m): 34 | if m == 1: return (one, two) 35 | (pm, pm1) = f(m / 2) 36 | if (m & 1): 37 | return (add(pm, pm1, one), double(pm1)) 38 | return (double(pm), add(pm, pm1, one)) 39 | ((x,z), _) = f(n) 40 | return (x * inv(z)) % P 41 | 42 | def unpack(s): 43 | if len(s) != 32: raise ValueError('Invalid Curve25519 argument') 44 | return sum(ord(s[i]) << (8 * i) for i in range(32)) 45 | 46 | def pack(n): 47 | return ''.join([chr((n >> (8 * i)) & 255) for i in range(32)]) 48 | 49 | def clamp(n): 50 | n &= ~7 51 | n &= ~(128 << 8 * 31) 52 | n |= 64 << 8 * 31 53 | return n 54 | 55 | def crypto_scalarmult_curve25519(n, p): 56 | n = clamp(unpack(n)) 57 | p = unpack(p) 58 | return pack(curve25519(n, p)) 59 | 60 | def crypto_scalarmult_curve25519_base(n): 61 | n = clamp(unpack(n)) 62 | return pack(curve25519(n, 9)) 63 | 64 | 65 | f = open("precomp.txt") 66 | 67 | def l(line): 68 | 69 | l = "" 70 | for i in range(32): 71 | if i == 31: 72 | l += "0x%s%s" % (line[2*i], line[2*i+1]) 73 | else: 74 | l += "0x%s%s," % (line[2*i], line[2*i+1]) 75 | return l 76 | 77 | 78 | while True: 79 | line=f.readline() 80 | if len(line) == 0: 81 | f.close() 82 | break 83 | print "{", l(binascii.hexlify(crypto_scalarmult_curve25519_base(binascii.unhexlify(line[0:-1])))), "}," 84 | 85 | -------------------------------------------------------------------------------- /old/crypto/CRYPTOLIBS: -------------------------------------------------------------------------------- 1 | crypto_onetimeauth_poly1305.o 2 | randombytes.o 3 | crypto_stream_chacha20.o 4 | crypto_verify_16.o 5 | crypto_verify_32.o 6 | crypto_hash_sha512.o 7 | crypto_hash_sha256.o 8 | fe.o 9 | fe25519.o 10 | ge25519.o 11 | sc25519.o 12 | crypto_scalarmult_curve25519.o 13 | crypto_dh_x25519.o 14 | crypto_sign_ed25519.o 15 | cleanup.o 16 | crypto_sort_uint32.o 17 | crypto_kem_sntrup761.o 18 | crypto_kem_sntrup761x25519.o 19 | uint8_optblocker.o 20 | uint16_optblocker.o 21 | uint32_optblocker.o 22 | uint64_optblocker.o 23 | -------------------------------------------------------------------------------- /old/crypto/CRYPTOPRIMITIVES: -------------------------------------------------------------------------------- 1 | crypto_int16 0 2 | crypto_int64 0 3 | crypto_uint16 0 4 | crypto_uint32 0 5 | crypto_uint64 0 6 | crypto_uint8 0 7 | crypto_stream_chacha20 1 8 | crypto_onetimeauth_poly1305 1 9 | crypto_hash_sha512 1 10 | crypto_hash_sha256 1 11 | crypto_verify_16 1 12 | crypto_verify_32 1 13 | crypto_scalarmult_curve25519 1 14 | crypto_dh_x25519 1 15 | crypto_sign_ed25519 1 16 | randombytes 1 17 | cleanup 0 18 | crypto_sort_uint32 1 19 | crypto_kem_sntrup761 1 20 | crypto_kem_sntrup761x25519 1 21 | -------------------------------------------------------------------------------- /old/crypto/CRYPTOSOURCES: -------------------------------------------------------------------------------- 1 | crypto_onetimeauth_poly1305 2 | randombytes 3 | crypto_stream_chacha20 4 | crypto_verify_16 5 | crypto_verify_32 6 | crypto_hash_sha256 7 | crypto_hash_sha512 8 | fe 9 | fe25519 10 | ge25519 11 | sc25519 12 | crypto_scalarmult_curve25519 13 | crypto_dh_x25519 14 | crypto_sign_ed25519 15 | cleanup 16 | crypto_sort_uint32 17 | crypto_kem_sntrup761 18 | crypto_kem_sntrup761x25519 19 | uint8_optblocker 20 | uint16_optblocker 21 | uint32_optblocker 22 | uint64_optblocker 23 | -------------------------------------------------------------------------------- /old/crypto/cleanup.c: -------------------------------------------------------------------------------- 1 | ../../cleanup.c -------------------------------------------------------------------------------- /old/crypto/cleanup.h: -------------------------------------------------------------------------------- 1 | ../../cleanup.h -------------------------------------------------------------------------------- /old/crypto/crypto_declassify.h: -------------------------------------------------------------------------------- 1 | ../../crypto_declassify.h -------------------------------------------------------------------------------- /old/crypto/crypto_dh_x25519.c: -------------------------------------------------------------------------------- 1 | ../../crypto_dh_x25519.c -------------------------------------------------------------------------------- /old/crypto/crypto_dh_x25519.h: -------------------------------------------------------------------------------- 1 | ../../crypto_dh_x25519.h -------------------------------------------------------------------------------- /old/crypto/crypto_hash_sha256.c: -------------------------------------------------------------------------------- 1 | ../../crypto_hash_sha256.c -------------------------------------------------------------------------------- /old/crypto/crypto_hash_sha256.h: -------------------------------------------------------------------------------- 1 | ../../crypto_hash_sha256.h -------------------------------------------------------------------------------- /old/crypto/crypto_hash_sha512.c: -------------------------------------------------------------------------------- 1 | ../../crypto_hash_sha512_tinyssh.c -------------------------------------------------------------------------------- /old/crypto/crypto_hash_sha512.h: -------------------------------------------------------------------------------- 1 | ../../crypto_hash_sha512.h -------------------------------------------------------------------------------- /old/crypto/crypto_int16.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_int16.h -------------------------------------------------------------------------------- /old/crypto/crypto_int32.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_int32.h -------------------------------------------------------------------------------- /old/crypto/crypto_int64.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_int64.h -------------------------------------------------------------------------------- /old/crypto/crypto_int8.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_int8.h -------------------------------------------------------------------------------- /old/crypto/crypto_kem_sntrup761.c: -------------------------------------------------------------------------------- 1 | ../../crypto_kem_sntrup761_tinyssh.c -------------------------------------------------------------------------------- /old/crypto/crypto_kem_sntrup761.h: -------------------------------------------------------------------------------- 1 | ../../crypto_kem_sntrup761.h -------------------------------------------------------------------------------- /old/crypto/crypto_kem_sntrup761x25519.c: -------------------------------------------------------------------------------- 1 | ../../crypto_kem_sntrup761x25519.c -------------------------------------------------------------------------------- /old/crypto/crypto_kem_sntrup761x25519.h: -------------------------------------------------------------------------------- 1 | ../../crypto_kem_sntrup761x25519.h -------------------------------------------------------------------------------- /old/crypto/crypto_onetimeauth_poly1305.c: -------------------------------------------------------------------------------- 1 | ../../crypto_onetimeauth_poly1305_tinyssh.c -------------------------------------------------------------------------------- /old/crypto/crypto_onetimeauth_poly1305.h: -------------------------------------------------------------------------------- 1 | ../../crypto_onetimeauth_poly1305.h -------------------------------------------------------------------------------- /old/crypto/crypto_scalarmult_curve25519.c: -------------------------------------------------------------------------------- 1 | ../../crypto_scalarmult_curve25519.c -------------------------------------------------------------------------------- /old/crypto/crypto_scalarmult_curve25519.h: -------------------------------------------------------------------------------- 1 | ../../crypto_scalarmult_curve25519.h -------------------------------------------------------------------------------- /old/crypto/crypto_sign_ed25519.c: -------------------------------------------------------------------------------- 1 | ../../crypto_sign_ed25519_tinyssh.c -------------------------------------------------------------------------------- /old/crypto/crypto_sign_ed25519.h: -------------------------------------------------------------------------------- 1 | ../../crypto_sign_ed25519.h -------------------------------------------------------------------------------- /old/crypto/crypto_sort_uint32.c: -------------------------------------------------------------------------------- 1 | ../../crypto_sort_uint32.c -------------------------------------------------------------------------------- /old/crypto/crypto_sort_uint32.h: -------------------------------------------------------------------------------- 1 | ../../crypto_sort_uint32.h -------------------------------------------------------------------------------- /old/crypto/crypto_stream_chacha20.c: -------------------------------------------------------------------------------- 1 | ../../crypto_stream_chacha20.c -------------------------------------------------------------------------------- /old/crypto/crypto_stream_chacha20.h: -------------------------------------------------------------------------------- 1 | ../../crypto_stream_chacha20.h -------------------------------------------------------------------------------- /old/crypto/crypto_uint16.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_uint16.h -------------------------------------------------------------------------------- /old/crypto/crypto_uint32.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_uint32.h -------------------------------------------------------------------------------- /old/crypto/crypto_uint64.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_uint64.h -------------------------------------------------------------------------------- /old/crypto/crypto_uint8.h: -------------------------------------------------------------------------------- 1 | ../../cryptoint/crypto_uint8.h -------------------------------------------------------------------------------- /old/crypto/crypto_verify_16.c: -------------------------------------------------------------------------------- 1 | ../../crypto_verify_16.c -------------------------------------------------------------------------------- /old/crypto/crypto_verify_16.h: -------------------------------------------------------------------------------- 1 | ../../crypto_verify_16.h -------------------------------------------------------------------------------- /old/crypto/crypto_verify_32.c: -------------------------------------------------------------------------------- 1 | ../../crypto_verify_32.c -------------------------------------------------------------------------------- /old/crypto/crypto_verify_32.h: -------------------------------------------------------------------------------- 1 | ../../crypto_verify_32.h -------------------------------------------------------------------------------- /old/crypto/fe.c: -------------------------------------------------------------------------------- 1 | ../../fe.c -------------------------------------------------------------------------------- /old/crypto/fe.h: -------------------------------------------------------------------------------- 1 | ../../fe.h -------------------------------------------------------------------------------- /old/crypto/fe25519.c: -------------------------------------------------------------------------------- 1 | ../../fe25519.c -------------------------------------------------------------------------------- /old/crypto/fe25519.h: -------------------------------------------------------------------------------- 1 | ../../fe25519.h -------------------------------------------------------------------------------- /old/crypto/ge25519.c: -------------------------------------------------------------------------------- 1 | ../../ge25519.c -------------------------------------------------------------------------------- /old/crypto/ge25519.h: -------------------------------------------------------------------------------- 1 | ../../ge25519.h -------------------------------------------------------------------------------- /old/crypto/randombytes.c: -------------------------------------------------------------------------------- 1 | ../../randombytes.c -------------------------------------------------------------------------------- /old/crypto/randombytes.h: -------------------------------------------------------------------------------- 1 | ../../randombytes.h -------------------------------------------------------------------------------- /old/crypto/sc25519.c: -------------------------------------------------------------------------------- 1 | ../../sc25519.c -------------------------------------------------------------------------------- /old/crypto/sc25519.h: -------------------------------------------------------------------------------- 1 | ../../sc25519.h -------------------------------------------------------------------------------- /old/crypto/uint16_optblocker.c: -------------------------------------------------------------------------------- 1 | ../../cryptoint/uint16_optblocker.c -------------------------------------------------------------------------------- /old/crypto/uint32_optblocker.c: -------------------------------------------------------------------------------- 1 | ../../cryptoint/uint32_optblocker.c -------------------------------------------------------------------------------- /old/crypto/uint64_optblocker.c: -------------------------------------------------------------------------------- 1 | ../../cryptoint/uint64_optblocker.c -------------------------------------------------------------------------------- /old/crypto/uint8_optblocker.c: -------------------------------------------------------------------------------- 1 | ../../cryptoint/uint8_optblocker.c -------------------------------------------------------------------------------- /old/make-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | build="`pwd`/build" 5 | source="`pwd`" 6 | bin="${build}/bin" 7 | man="${build}/man" 8 | 9 | cat "${source}/tinyssh/TARGETS" |\ 10 | while read x 11 | do 12 | [ -x "${bin}/${x}" ] || \ 13 | ( 14 | echo "=== `date` === $x not compiled, compile first!" 15 | exit 111; 16 | ) || exit 111 17 | done || exit 111 18 | 19 | #bin 20 | confbin="`head -1 conf-bin`" 21 | bindir=`echo "$1/${confbin}" | sed 's,//,/,g'` 22 | echo "=== `date` === installing bin directory ${bindir}" 23 | mkdir -p "${bindir}" || exit 111 24 | cat "${source}/tinyssh/LINKS" |\ 25 | while read x y 26 | do 27 | rm -f "${x}.tmp" 28 | if [ "_${y}" = "_" ]; then 29 | cp "${bin}/${x}" "${bindir}/${x}.tmp" 30 | ( 31 | cd "${bindir}" 32 | chmod 755 "${x}.tmp" 33 | mv -f "${x}.tmp" "${x}" 34 | ) 35 | else 36 | ( 37 | cd "${bindir}" 38 | ln -s "${y}" "${x}.tmp" 39 | mv -f "${x}.tmp" "${x}" 40 | ) 41 | fi 42 | echo "=== `date` === installing ${bin}/${x} -> ${bindir}/${x}" 43 | done || exit 111 44 | echo "=== `date` === finishing" 45 | 46 | #man 47 | confman="`head -1 conf-man`" 48 | mandir=`echo "$1/${confman}" | sed 's,//,/,g'` 49 | echo "=== `date` === installing man directory ${mandir}" 50 | mkdir -p "${mandir}" || exit 111 51 | ls "${man}" | sort |\ 52 | while read x 53 | do 54 | n=`echo "${x}" | cut -d'.' -f2` 55 | mkdir -p "${mandir}/man${n}" || exit 111 56 | cp "${man}/${x}" "${mandir}/man${n}/${x}.tmp" 57 | ( 58 | cd "${mandir}/man${n}" 59 | chmod 644 "${x}.tmp" 60 | mv -f "${x}.tmp" "${x}" 61 | ) 62 | echo "=== `date` === installing ${man}/${x} -> ${mandir}/man${n}/${x}" 63 | done || exit 111 64 | echo "=== `date` === finishing" 65 | 66 | exit 0 67 | -------------------------------------------------------------------------------- /old/man: -------------------------------------------------------------------------------- 1 | ../man -------------------------------------------------------------------------------- /old/sysdep/default.h-no.c: -------------------------------------------------------------------------------- 1 | /* Public domain. */ 2 | int main(void) { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /old/sysdep/default.h-no.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/janmojzis/tinyssh/5e679c9823a6e10c206356b97a2b31996d20e69a/old/sysdep/default.h-no.out -------------------------------------------------------------------------------- /old/sysdep/haslibutilh.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../haslibutilh.c -------------------------------------------------------------------------------- /old/sysdep/haslibutilh.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASLIBUTILH 1 2 | -------------------------------------------------------------------------------- /old/sysdep/haslimits.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../haslimits.c -------------------------------------------------------------------------------- /old/sysdep/haslimits.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASLIMITS 1 2 | -------------------------------------------------------------------------------- /old/sysdep/haslogintty.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../haslogintty.c -------------------------------------------------------------------------------- /old/sysdep/haslogintty.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASLOGINTTY 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasmlock.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasmlock.c -------------------------------------------------------------------------------- /old/sysdep/hasmlock.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASMLOCK 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasopenpty.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasopenpty.c -------------------------------------------------------------------------------- /old/sysdep/hasopenpty.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASOPENPTY 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutilh.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutilh.c -------------------------------------------------------------------------------- /old/sysdep/hasutilh.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTILH 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmp.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmp.c -------------------------------------------------------------------------------- /old/sysdep/hasutmp.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMP 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpaddrv6.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpaddrv6.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpaddrv6.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPADDRV6 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmphost.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmphost.c -------------------------------------------------------------------------------- /old/sysdep/hasutmphost.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPHOST 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmploginlogout.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmploginlogout.c -------------------------------------------------------------------------------- /old/sysdep/hasutmploginlogout.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPLOGINLOGOUT 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmplogwtmp.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmplogwtmp.c -------------------------------------------------------------------------------- /old/sysdep/hasutmplogwtmp.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPLOGWTMP 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpname.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpname.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpname.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPNAME 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmppid.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmppid.c -------------------------------------------------------------------------------- /old/sysdep/hasutmppid.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPPID 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmptime.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmptime.c -------------------------------------------------------------------------------- /old/sysdep/hasutmptime.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPTIME 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmptv.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmptv.c -------------------------------------------------------------------------------- /old/sysdep/hasutmptv.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPTV 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmptype.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmptype.c -------------------------------------------------------------------------------- /old/sysdep/hasutmptype.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPTYPE 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpuser.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpuser.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpuser.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPUSER 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpx.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpx.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpx.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPX 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpxaddrv6.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpxaddrv6.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpxaddrv6.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPXADDRV6 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpxsyslen.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpxsyslen.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpxsyslen.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPXSYSLEN 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasutmpxupdwtmpx.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasutmpxupdwtmpx.c -------------------------------------------------------------------------------- /old/sysdep/hasutmpxupdwtmpx.h-yes.out: -------------------------------------------------------------------------------- 1 | #define HASUTMPXUPDWTMPX 1 2 | -------------------------------------------------------------------------------- /old/sysdep/hasvalgrind.h-yes.c: -------------------------------------------------------------------------------- 1 | ../../hasvalgrind.c -------------------------------------------------------------------------------- /old/sysdep/list: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | #mlock 4 | echo 'hasmlock.h hasmlock.h-yes' 5 | echo 'hasmlock.h default.h-no' 6 | 7 | #util/libutil 8 | echo 'haslibutilh.h haslibutilh.h-yes' 9 | echo 'haslibutilh.h default.h-no' 10 | echo 'hasutilh.h hasutilh.h-yes' 11 | echo 'hasutilh.h default.h-no' 12 | 13 | #openpty/login_tty 14 | echo 'hasopenpty.h hasopenpty.h-yes' 15 | echo 'hasopenpty.h default.h-no' 16 | echo 'haslogintty.h haslogintty.h-yes' 17 | echo 'haslogintty.h default.h-no' 18 | 19 | #utmpx 20 | echo 'hasutmpx.h hasutmpx.h-yes' 21 | echo 'hasutmpx.h default.h-no' 22 | echo 'hasutmpxupdwtmpx.h hasutmpxupdwtmpx.h-yes' 23 | echo 'hasutmpxupdwtmpx.h default.h-no' 24 | echo 'hasutmpxsyslen.h hasutmpxsyslen.h-yes' 25 | echo 'hasutmpxsyslen.h default.h-no' 26 | echo 'hasutmpxaddrv6.h hasutmpxaddrv6.h-yes' 27 | echo 'hasutmpxaddrv6.h default.h-no' 28 | 29 | #utmp 30 | echo 'hasutmp.h hasutmp.h-yes' 31 | echo 'hasutmp.h default.h-no' 32 | echo 'hasutmpname.h hasutmpname.h-yes' 33 | echo 'hasutmpname.h default.h-no' 34 | echo 'hasutmpuser.h hasutmpuser.h-yes' 35 | echo 'hasutmpuser.h default.h-no' 36 | echo 'hasutmphost.h hasutmphost.h-yes' 37 | echo 'hasutmphost.h default.h-no' 38 | echo 'hasutmptime.h hasutmptime.h-yes' 39 | echo 'hasutmptime.h default.h-no' 40 | echo 'hasutmptv.h hasutmptv.h-yes' 41 | echo 'hasutmptv.h default.h-no' 42 | echo 'hasutmppid.h hasutmppid.h-yes' 43 | echo 'hasutmppid.h default.h-no' 44 | echo 'hasutmptype.h hasutmptype.h-yes' 45 | echo 'hasutmptype.h default.h-no' 46 | echo 'hasutmplogwtmp.h hasutmplogwtmp.h-yes' 47 | echo 'hasutmplogwtmp.h default.h-no' 48 | echo 'hasutmploginlogout.h hasutmploginlogout.h-yes' 49 | echo 'hasutmploginlogout.h default.h-no' 50 | echo 'hasutmpaddrv6.h hasutmpaddrv6.h-yes' 51 | echo 'hasutmpaddrv6.h default.h-no' 52 | 53 | #limits 54 | echo 'haslimits.h haslimits.h-yes' 55 | echo 'haslimits.h default.h-no' 56 | 57 | #valgrind 58 | echo 'hasvalgrind.h hasvalgrind.h-yes' 59 | echo 'hasvalgrind.h default.h-no' 60 | 61 | # librandombytes + lib25519 + libntruprime + lib1305 62 | echo 'haslibrandombytes.h default.h-no' 63 | echo 'haslib25519.h default.h-no' 64 | echo 'haslibntruprime.h default.h-no' 65 | echo 'haslib1305.h default.h-no' 66 | 67 | -------------------------------------------------------------------------------- /old/tinyssh-tests/blockingtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140302 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "fail.h" 11 | #include "blocking.h" 12 | 13 | int main(void) { 14 | 15 | int pi[2]; 16 | long long i; 17 | 18 | if (pipe(pi) == -1) fail("failure"); 19 | for (i = 0; i < 2; ++i) { 20 | if ((fcntl(pi[i], F_GETFL) & O_NONBLOCK) != 0) fail("failure"); 21 | blocking_disable(pi[i]); 22 | if ((fcntl(pi[i], F_GETFL) & O_NONBLOCK) == 0) fail("failure"); 23 | blocking_enable(pi[i]); 24 | if ((fcntl(pi[i], F_GETFL) & O_NONBLOCK) != 0) fail("failure"); 25 | } 26 | _exit(0); 27 | } 28 | -------------------------------------------------------------------------------- /old/tinyssh-tests/bytetest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140302 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | /* 8 | XXX TODO 9 | - check if byte_isequal is constant-time 10 | */ 11 | 12 | #include 13 | #include "fail.h" 14 | #include "byte.h" 15 | 16 | int main(void) { 17 | 18 | unsigned char b1[32]; 19 | unsigned char b2[32]; 20 | long long i, j; 21 | const char *x = "abcdefgh"; 22 | char y[8]; 23 | 24 | /* byte_zero test */ 25 | for (i = 0; i < 32; ++i) { 26 | for (j = 0; j < sizeof b1; ++j) b1[j] = 0; 27 | for (j = 0; j < sizeof b2; ++j) b2[j] = 0; 28 | b1[i] = 0xff; b2[i] = 0xff; 29 | byte_zero(b1, sizeof b1); 30 | 31 | if (byte_isequal(b1, 32, b2) != 0) fail("byte_zero failure"); 32 | } 33 | 34 | /* byte_isequal test */ 35 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 36 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0xff; 37 | 38 | if (byte_isequal(b1, 32, b2) == 0) fail("byte_isequal failure"); 39 | 40 | for (i = 0; i < 32; ++i) { 41 | b1[i] = 0; 42 | if (byte_isequal(b1, 32, b2) != 0) fail("byte_isequal failure"); 43 | b1[i] = 0xff; 44 | } 45 | 46 | /* byte_copy test */ 47 | for (i = 0; i < sizeof b1; ++i) b1[i] = 0xff; 48 | for (i = 0; i < sizeof b2; ++i) b2[i] = 0x00; 49 | 50 | byte_copy(b1, 32, b2); 51 | if (byte_isequal(b1, 32, b2) == 0) fail("byte_copy failure"); 52 | 53 | for (i = 0; i < 32; ++i) { 54 | b1[i] = 0; 55 | byte_copy(b1, 32, b2); 56 | if (byte_isequal(b1, 32, b2) == 0) fail("byte_copy failure"); 57 | b1[i] = 0xff; 58 | } 59 | 60 | byte_zero(y, 8); 61 | if (!byte_isequal(y, 8, "\0\0\0\0\0\0\0\0")) fail("byte_zero/byte_isequal failure"); 62 | 63 | byte_copy(y, 8, x); 64 | if (!byte_isequal(y, 8, x)) fail("byte_copy/byte_isequal failure"); 65 | 66 | byte_copy(y, 7, y + 1); 67 | if (!byte_isequal(y, 8, "bcdefghh")) fail("byte_copy/byte_isequal failure"); 68 | 69 | byte_zero(y, 8); 70 | if (!byte_isequal(y, 8, "\0\0\0\0\0\0\0\0")) fail("byte_zero/byte_isequal failure"); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /old/tinyssh-tests/channel_droptest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/channel_forkptytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/coetest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140302 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "fail.h" 11 | #include "coe.h" 12 | 13 | int main(void) { 14 | 15 | int pi[2]; 16 | long long i; 17 | 18 | if (pipe(pi) == -1) fail("failure"); 19 | for (i = 0; i < 2; ++i) { 20 | if (fcntl(pi[i], F_GETFD) != 0) fail("failure"); 21 | coe_enable(pi[i]); 22 | if (fcntl(pi[i], F_GETFD) == 0) fail("failure"); 23 | coe_disable(pi[i]); 24 | if (fcntl(pi[i], F_GETFD) != 0) fail("failure"); 25 | } 26 | _exit(0); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /old/tinyssh-tests/dietest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/dropuidgidtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140320 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "run.h" 9 | #include "fail.h" 10 | #include "dropuidgid.h" 11 | 12 | static void droproot(void) { 13 | 14 | if (geteuid() == 0) { 15 | if (!dropuidgid(0, 1230, 1230)) _exit(111); 16 | } 17 | if (geteuid() == 0) _exit(111); 18 | } 19 | 20 | 21 | static void test1(void) { 22 | droproot(); 23 | if (dropuidgid(0, 1231, getegid())) _exit(111); 24 | _exit(0); 25 | } 26 | 27 | static void test2(void) { 28 | droproot(); 29 | if (!dropuidgid(0, geteuid(), getegid())) _exit(111); 30 | if (!dropuidgid(0, geteuid(), getegid())) _exit(111); 31 | _exit(0); 32 | } 33 | 34 | static void test3(void) { 35 | droproot(); 36 | if (!dropuidgid(0, 0, 0)) _exit(111); 37 | _exit(0); 38 | } 39 | 40 | 41 | int main(void) { 42 | 43 | run_mustpass(test1); 44 | run_mustpass(test2); 45 | run_mustfail(test3); 46 | _exit(0); 47 | } 48 | -------------------------------------------------------------------------------- /old/tinyssh-tests/emptytest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140319 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | 9 | int main(void) { 10 | 11 | _exit(0); 12 | } 13 | -------------------------------------------------------------------------------- /old/tinyssh-tests/envtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20130606 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "fail.h" 12 | #include "env.h" 13 | 14 | static void test_zero(void) { 15 | 16 | if (env_get(0)) fail("env_get accepts zero input"); 17 | } 18 | 19 | static void doit(const char *d0, const char *d) { 20 | 21 | char *s; 22 | 23 | s = env_get(d0); 24 | 25 | if (!s) { 26 | if (d) fail("env_get failure"); 27 | return; 28 | } 29 | 30 | if (!s) fail("env_get failure"); 31 | if (strcmp(s, d)) fail("env_get failure"); 32 | return; 33 | } 34 | 35 | static void test_setunset(void) { 36 | 37 | setenv("x","x",1); 38 | doit("x", "x"); 39 | 40 | setenv("x","y",1); 41 | doit("x", "y"); 42 | 43 | unsetenv("x"); 44 | doit("x", 0); 45 | } 46 | 47 | 48 | static void test_env(void) { 49 | 50 | const char *env[10]; 51 | 52 | env[0] = "a=1"; 53 | env[1] = "a=2"; 54 | env[2] = "b=b=1"; 55 | env[3] = "c="; 56 | env[4] = "d"; 57 | env[5] = "=null"; 58 | env[6] = "e=="; 59 | env[7] = 0; 60 | 61 | environ = (char **)env; 62 | 63 | doit("a", "1"); 64 | doit("b", "b=1"); 65 | doit("b=b", "1"); 66 | doit("c", ""); 67 | doit("d", 0); 68 | doit("e", "="); 69 | doit("", "null"); 70 | } 71 | 72 | int main(void) { 73 | 74 | test_zero(); 75 | test_setunset(); 76 | test_env(); 77 | _exit(0); 78 | } 79 | -------------------------------------------------------------------------------- /old/tinyssh-tests/etest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "e.h" 9 | 10 | #ifndef EPROTO 11 | error! 12 | #endif 13 | 14 | int main(void) { 15 | 16 | _exit(0); 17 | } 18 | -------------------------------------------------------------------------------- /old/tinyssh-tests/fail.h: -------------------------------------------------------------------------------- 1 | #ifndef _FAIL_H____ 2 | #define _FAIL_H____ 3 | 4 | #include 5 | #include 6 | #include "fail.h" 7 | 8 | #define fail_(a, b, x) do { fprintf(stderr, "%s:%llu: %s\n", (a), (unsigned long long)(b), (x)); fflush(stderr); _exit(111); } while (0); 9 | #define fail(x) fail_(__FILE__, __LINE__, (x)) 10 | 11 | 12 | static void fail_printdata(char *text, unsigned char *data, long long len) { 13 | 14 | long long i; 15 | 16 | fprintf(stderr, "%s = {\n ", text); 17 | for (i = 0; i < len; ++i) { 18 | if (i == len - 1) { 19 | fprintf(stderr, "0x%02x", data[i]); 20 | } 21 | else { 22 | fprintf(stderr, "0x%02x, ", data[i]); 23 | if (i % 8 == 7) fprintf(stderr, "\n "); 24 | } 25 | } 26 | fprintf(stderr, "\n};\n"); 27 | fflush(stderr); 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /old/tinyssh-tests/forkptytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/getlntest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140323 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "fail.h" 10 | #include "savesync.h" 11 | #include "str.h" 12 | #include "byte.h" 13 | #include "open.h" 14 | #include "getln.h" 15 | 16 | int main(void) { 17 | 18 | char buf[6]; 19 | int fd; 20 | int r; 21 | 22 | /* create test file */ 23 | if (savesync("getlntest.txt", "ab\ncd", 5) == -1) fail("savesync() failure"); 24 | 25 | /* ok test */ 26 | fd = open_read("getlntest.txt"); 27 | if (fd == -1) fail("open_read() failure"); 28 | r = getln(fd, buf, sizeof buf); 29 | if (r != 1) fail("getln() failure"); 30 | if (str_len(buf) != 3) fail("getln() failure"); 31 | if (!byte_isequal(buf, 3, "ab\n")) fail("getln() failure"); 32 | r = getln(fd, buf, sizeof buf); 33 | if (r != 0) fail("getln() failure"); 34 | if (str_len(buf) != 2) fail("getln() failure"); 35 | if (!byte_isequal(buf, 2, "cd")) fail("getln() failure"); 36 | close(fd); 37 | 38 | /* overflow test */ 39 | fd = open_read("getlntest.txt"); 40 | if (fd == -1) fail("open_read() failure"); 41 | r = getln(fd, buf, 3); 42 | if (r != -1) fail("getln() failure"); 43 | close(fd); 44 | if (unlink("getlntest.txt") == -1) fail("unlink() failure"); 45 | 46 | /* empty test */ 47 | if (savesync("getlntest.txt", "", 0) == -1) fail("savesync() failure"); 48 | fd = open_read("getlntest.txt"); 49 | if (fd == -1) fail("open_read() failure"); 50 | r = getln(fd, buf, sizeof buf); 51 | if (r != 0) fail("getln() failure"); 52 | if (str_len(buf) != 0) fail("getln() failure"); 53 | close(fd); 54 | if (unlink("getlntest.txt") == -1) fail("unlink() failure"); 55 | 56 | /* empty line test */ 57 | if (savesync("getlntest.txt", "\n", 1) == -1) fail("savesync() failure"); 58 | fd = open_read("getlntest.txt"); 59 | if (fd == -1) fail("open_read() failure"); 60 | r = getln(fd, buf, sizeof buf); 61 | if (r != 1) fail("getln() failure"); 62 | if (str_len(buf) != 1) fail("getln() failure"); 63 | r = getln(fd, buf, sizeof buf); 64 | if (r != 0) fail("getln() failure"); 65 | if (str_len(buf) != 0) fail("getln() failure"); 66 | close(fd); 67 | if (unlink("getlntest.txt") == -1) fail("unlink() failure"); 68 | 69 | _exit(0); 70 | } 71 | 72 | -------------------------------------------------------------------------------- /old/tinyssh-tests/globaltest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140304 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "global.h" 9 | 10 | #ifndef GLOBAL_BSIZE 11 | error! 12 | #endif 13 | 14 | int main(void) { 15 | global_init(); 16 | global_init(); 17 | global_purge(); 18 | global_purge(); 19 | global_init(); 20 | global_init(); 21 | _exit(0); 22 | } 23 | -------------------------------------------------------------------------------- /old/tinyssh-tests/loadtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "fail.h" 12 | #include "open.h" 13 | #include "randombytes.h" 14 | #include "byte.h" 15 | #include "load.h" 16 | #include "writeall.h" 17 | 18 | #define SPACELEN 1048577 19 | 20 | unsigned char space1[SPACELEN]; 21 | unsigned char space2[SPACELEN]; 22 | 23 | static void test1(void) { 24 | 25 | int fd; 26 | 27 | 28 | fd = open_write("loadtest.data"); 29 | if (fd == -1) fail("failure"); 30 | randombytes(space1, sizeof space1); 31 | if (writeall(fd, space1, sizeof space1) == -1) fail("failure"); 32 | close(fd); 33 | 34 | if (load("loadtest.data", space2, sizeof space2) == -1) fail("failure"); 35 | 36 | if (!byte_isequal(space1, SPACELEN, space2)) fail("failure"); 37 | 38 | } 39 | 40 | int main(void) { 41 | test1(); 42 | _exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /old/tinyssh-tests/loginshelltest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140429 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "str.h" 8 | #include "byte.h" 9 | #include "fail.h" 10 | #include "loginshell.h" 11 | 12 | static char buf[10]; 13 | 14 | static struct vector { 15 | const char *in; 16 | const char *out; 17 | } vectors[] = { 18 | { "", "-" }, 19 | { "/", "-" }, 20 | { "//", "-" }, 21 | { "///", "-" }, 22 | { "////", "-" }, 23 | { "/////", "-" }, 24 | { "/a/b/c/d/", "-" }, 25 | { "/a///d/", "-" }, 26 | { "//b/c//", "-" }, 27 | { "x/", "-" }, 28 | { "x/x/xx/xxx/", "-" }, 29 | { "sh", "-sh" }, 30 | { "/bin/bash", "-bash" }, 31 | { "///////dash", "-dash" }, 32 | { "///////-ksh", "--ksh" }, 33 | /* truncation */ 34 | { "longlongsh", "-longlong" }, 35 | { 0, 0 } 36 | }; 37 | 38 | static void testok(void) { 39 | 40 | long long i, len; 41 | 42 | for (i = 0; vectors[i].in; ++i) { 43 | if (!loginshell(buf, sizeof buf, vectors[i].in)) fail("loginshell failure"); 44 | len = str_len(vectors[i].out); 45 | if (str_len(buf) != len) fail("loginshell failure"); 46 | if (!byte_isequal(buf, len, vectors[i].out)) fail("loginshell failure"); 47 | } 48 | } 49 | 50 | static void testbad(void) { 51 | 52 | if (loginshell(buf, -1, "")) fail("loginshell failure"); 53 | if (loginshell(buf, 0, "")) fail("loginshell failure"); 54 | if (loginshell(buf, 1, "")) fail("loginshell failure"); 55 | if (loginshell(buf, 1, "//")) fail("loginshell failure"); 56 | } 57 | 58 | 59 | int main(void) { 60 | 61 | testok(); 62 | testbad(); 63 | _exit(0); 64 | } 65 | -------------------------------------------------------------------------------- /old/tinyssh-tests/logsystest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/main_tinysshd_makekeytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/main_tinysshd_printkeytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/main_tinysshdtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/opentest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140410 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "run.h" 10 | #include "fail.h" 11 | #include "open.h" 12 | 13 | static void cat(void) { 14 | char *catcmd[2] = { (char *)"cat", 0 }; 15 | execvp(*catcmd, catcmd); 16 | } 17 | 18 | /* test if close-on-exec works for open_read() */ 19 | static void test1(void) { 20 | 21 | int fd; 22 | 23 | close(0); 24 | fd = open_read("opentest.c"); 25 | if (fd != 0) fail("unable to open opentest.c for reading"); 26 | cat(); 27 | } 28 | 29 | /* test if close-on-exec works for open_write() */ 30 | static void test2(void) { 31 | 32 | int fd; 33 | 34 | close(1); 35 | fd = open_write("opentest.data"); 36 | if (fd != 1) fail("unable to open opentest.data for writing"); 37 | cat(); 38 | } 39 | 40 | /* test if close-on-exec works for open_pipe() */ 41 | static void test3(void) { 42 | 43 | int fd, pi[2]; 44 | 45 | close(0); 46 | close(1); 47 | fd = open_pipe(pi); 48 | if (fd == -1) fail("unable to open pipe"); 49 | if (pi[0] != 0) fail("unable to open pipe"); 50 | if (pi[1] != 1) fail("unable to open pipe"); 51 | cat(); 52 | } 53 | 54 | /* dummy test */ 55 | static void testdummy(void) { 56 | _exit(0); 57 | } 58 | 59 | int main(void) { 60 | alarm(10); 61 | run_mustfail(test1); 62 | run_mustfail(test2); 63 | run_mustfail(test3); 64 | run_mustpass(testdummy); 65 | _exit(0); 66 | } 67 | -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_authtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_channel_opentest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_channel_recvtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_channel_requesttest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_channel_sendtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_gettest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_hellotest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_kexdhtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_kextest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_puttest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_recvtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_sendtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packet_unimplementedtest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/packettest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/randommodtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140416 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include "fail.h" 10 | #include "randommod.h" 11 | 12 | int main(void) { 13 | 14 | long long i, r; 15 | 16 | if (randommod(-1) != 0) fail("failure"); 17 | if (randommod(0) != 0) fail("failure"); 18 | if (randommod(1) != 0) fail("failure"); 19 | for (i = 2; i < 10; ++i) { 20 | r = randommod(i); 21 | if (r > i - 1 || r < 0) fail("failure"); 22 | } 23 | for (i = 18014398509481984ULL; i < 18014398509481994ULL; ++i) { 24 | if (randommod(i) == randommod(i)) fail("failure"); 25 | } 26 | _exit(0); 27 | } 28 | -------------------------------------------------------------------------------- /old/tinyssh-tests/readalltest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "fail.h" 12 | #include "open.h" 13 | #include "randombytes.h" 14 | #include "byte.h" 15 | #include "readall.h" 16 | #include "writeall.h" 17 | 18 | #define SPACELEN 1048577 19 | 20 | unsigned char space1[SPACELEN]; 21 | unsigned char space2[SPACELEN]; 22 | 23 | static void test1(void) { 24 | 25 | int fd; 26 | 27 | 28 | fd = open_write("readall.data"); 29 | if (fd == -1) fail("failure"); 30 | randombytes(space1, sizeof space1); 31 | if (writeall(fd, space1, sizeof space1) == -1) fail("failure"); 32 | close(fd); 33 | 34 | fd = open_read("readall.data"); 35 | if (readall(fd, space2, sizeof space2) == -1) fail("failure"); 36 | close(fd); 37 | 38 | if (!byte_isequal(space1, SPACELEN, space2)) fail("failure"); 39 | 40 | } 41 | 42 | int main(void) { 43 | test1(); 44 | _exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /old/tinyssh-tests/savesynctest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "fail.h" 12 | #include "randombytes.h" 13 | #include "byte.h" 14 | #include "load.h" 15 | #include "savesync.h" 16 | #include "writeall.h" 17 | 18 | #define SPACELEN 1048577 19 | 20 | unsigned char space1[SPACELEN]; 21 | unsigned char space2[SPACELEN]; 22 | 23 | static void test1(void) { 24 | 25 | 26 | randombytes(space1, sizeof space1); 27 | 28 | if (savesync("savesynctest.data", space1, sizeof space1) == -1) fail("savesync() failure"); 29 | if (load("savesynctest.data", space2, sizeof space2) == -1) fail("load() failure"); 30 | if (!byte_isequal(space1, SPACELEN, space2)) fail("load()/savesync() failure"); 31 | 32 | } 33 | 34 | int main(void) { 35 | test1(); 36 | _exit(0); 37 | } 38 | -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_cipher_chachapolytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_ciphertest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_kex_curve25519test.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_kex_sntrup761x25519test.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_kextest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_key_ed25519test.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcrypto_keytest.c: -------------------------------------------------------------------------------- 1 | emptytest.c -------------------------------------------------------------------------------- /old/tinyssh-tests/sshcryptotest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "sshcrypto.h" 9 | 10 | /* grep "define sshcrypto_" source/tinyssh/sshcrypto.h | cut -d ' ' -f2 | while read x; do echo \#ifndef $x; echo error! ;echo \#endif; done */ 11 | 12 | #ifndef sshcrypto_kem_PUBLICKEYMAX 13 | error! 14 | #endif 15 | #ifndef sshcrypto_kem_CIPHERTEXTMAX 16 | error! 17 | #endif 18 | #ifndef sshcrypto_kem_MAX 19 | error! 20 | #endif 21 | #ifndef sshcrypto_hash_MAX 22 | error! 23 | #endif 24 | #ifndef sshcrypto_sign_PUBLICKEYMAX 25 | error! 26 | #endif 27 | #ifndef sshcrypto_sign_SECRETKEYMAX 28 | error! 29 | #endif 30 | #ifndef sshcrypto_sign_MAX 31 | error! 32 | #endif 33 | #ifndef sshcrypto_sign_BASE64PUBLICKEYMAX 34 | error! 35 | #endif 36 | #ifndef sshcrypto_sign_BASE64PUBLICKEYMIN 37 | error! 38 | #endif 39 | #ifndef sshcrypto_cipher_KEYMAX 40 | error! 41 | #endif 42 | 43 | int main(void) { 44 | 45 | /* check sshcrypto_init() called called more than once */ 46 | sshcrypto_init(); 47 | sshcrypto_init(); 48 | /* check sshcrypto_purge() called called more than once */ 49 | sshcrypto_purge(); 50 | sshcrypto_purge(); 51 | /* check sshcrypto_init() called called more than once after sshcrypto_purge() */ 52 | sshcrypto_init(); 53 | sshcrypto_init(); 54 | _exit(0); 55 | } 56 | -------------------------------------------------------------------------------- /old/tinyssh-tests/sshtest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140319 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include "fail.h" 11 | #include "ssh.h" 12 | 13 | /* 14 | grep SSH_ * | sed 's/.*SSH_/SSH_/g' | cut -d ',' -f1 | cut -d ' ' -f1 | cut -d ')' -f1 | cut -d ':' -f1 | cut -d '"' -f1 | cut -d ';' -f1 | sort -u | grep -v 'SSH_TTY\|SSH_CONNECTION'| while read x; do echo \#ifndef $x; echo error! ;echo \#endif; done 15 | */ 16 | 17 | #ifndef SSH_MSG_CHANNEL_CLOSE 18 | error! 19 | #endif 20 | #ifndef SSH_MSG_CHANNEL_DATA 21 | error! 22 | #endif 23 | #ifndef SSH_MSG_CHANNEL_EOF 24 | error! 25 | #endif 26 | #ifndef SSH_MSG_CHANNEL_EXTENDED_DATA 27 | error! 28 | #endif 29 | #ifndef SSH_MSG_CHANNEL_OPEN 30 | error! 31 | #endif 32 | #ifndef SSH_MSG_CHANNEL_OPEN_CONFIRMATION 33 | error! 34 | #endif 35 | #ifndef SSH_MSG_CHANNEL_OPEN_FAILURE 36 | error! 37 | #endif 38 | #ifndef SSH_MSG_CHANNEL_REQUEST 39 | error! 40 | #endif 41 | #ifndef SSH_MSG_CHANNEL_SUCCESS 42 | error! 43 | #endif 44 | #ifndef SSH_MSG_CHANNEL_WINDOW_ADJUST 45 | error! 46 | #endif 47 | #ifndef SSH_MSG_DEBUG 48 | error! 49 | #endif 50 | #ifndef SSH_MSG_DISCONNECT 51 | error! 52 | #endif 53 | #ifndef SSH_MSG_IGNORE 54 | error! 55 | #endif 56 | #ifndef SSH_MSG_KEXDH_INIT 57 | error! 58 | #endif 59 | #ifndef SSH_MSG_KEXDH_REPLY 60 | error! 61 | #endif 62 | #ifndef SSH_MSG_KEXINIT 63 | error! 64 | #endif 65 | #ifndef SSH_MSG_NEWKEYS 66 | error! 67 | #endif 68 | #ifndef SSH_MSG_SERVICE_ACCEPT 69 | error! 70 | #endif 71 | #ifndef SSH_MSG_SERVICE_REQUEST 72 | error! 73 | #endif 74 | #ifndef SSH_MSG_UNIMPLEMENTED 75 | error! 76 | #endif 77 | #ifndef SSH_MSG_USERAUTH_FAILURE 78 | error! 79 | #endif 80 | #ifndef SSH_MSG_USERAUTH_PK_OK 81 | error! 82 | #endif 83 | #ifndef SSH_MSG_USERAUTH_REQUEST 84 | error! 85 | #endif 86 | #ifndef SSH_MSG_USERAUTH_SUCCESS 87 | error! 88 | #endif 89 | #ifndef SSH_OPEN_ADMINISTRATIVELY_PROHIBITED 90 | error! 91 | #endif 92 | 93 | int main(void) { 94 | 95 | if (strcmp(ssh_sigstr(SIGTERM), "TERM")) fail("failure") 96 | if (strcmp(ssh_sigstrlong(SIGTERM), "SIGTERM (termination)")) fail("failure") 97 | if (strcmp(ssh_sigstr(-1), "UNKNOWN")) fail("failure") 98 | if (strcmp(ssh_sigstrlong(-1), "UNKNOWN SIGNAL")) fail("failure") 99 | _exit(0); 100 | } 101 | -------------------------------------------------------------------------------- /old/tinyssh-tests/trymlocktest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140303 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include "trymlock.h" 9 | 10 | unsigned char buf[100]; 11 | 12 | int main(void) { 13 | 14 | long long i; 15 | 16 | for (i = 81; i < 100; ++i) trymlock(buf, i); 17 | _exit(0); 18 | } 19 | -------------------------------------------------------------------------------- /old/tinyssh-tests/writealltest.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140417 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "fail.h" 12 | #include "open.h" 13 | #include "randombytes.h" 14 | #include "byte.h" 15 | #include "load.h" 16 | #include "writeall.h" 17 | 18 | #define SPACELEN 1048577 19 | 20 | unsigned char space1[SPACELEN]; 21 | unsigned char space2[SPACELEN]; 22 | 23 | static void test1(void) { 24 | 25 | int fd; 26 | 27 | 28 | fd = open_write("writealltest.data"); 29 | if (fd == -1) fail("failure"); 30 | randombytes(space1, sizeof space1); 31 | if (writeall(fd, space1, sizeof space1) == -1) fail("failure"); 32 | close(fd); 33 | 34 | if (load("writealltest.data", space2, sizeof space2) == -1) fail("failure"); 35 | 36 | if (!byte_isequal(space1, SPACELEN, space2)) fail("failure"); 37 | 38 | } 39 | 40 | int main(void) { 41 | test1(); 42 | _exit(0); 43 | } 44 | -------------------------------------------------------------------------------- /old/tinyssh/LIBS: -------------------------------------------------------------------------------- 1 | blocking.o 2 | buf.o 3 | byte.o 4 | channel.o 5 | channel_drop.o 6 | channel_fork.o 7 | channel_forkpty.o 8 | channel_subsystem.o 9 | coe.o 10 | connectioninfo.o 11 | die.o 12 | dropuidgid.o 13 | e.o 14 | env.o 15 | getln.o 16 | global.o 17 | iptostr.o 18 | load.o 19 | log.o 20 | loginshell.o 21 | logsys.o 22 | main_tinysshd.o 23 | main_tinysshd_makekey.o 24 | main_tinysshd_printkey.o 25 | newenv.o 26 | numtostr.o 27 | open.o 28 | packet.o 29 | packet_auth.o 30 | packet_channel_open.o 31 | packet_channel_recv.o 32 | packet_channel_request.o 33 | packet_channel_send.o 34 | packet_get.o 35 | packet_hello.o 36 | packet_kex.o 37 | packet_kexdh.o 38 | packet_put.o 39 | packet_recv.o 40 | packet_send.o 41 | packet_unimplemented.o 42 | packetparser.o 43 | porttostr.o 44 | randommod.o 45 | readall.o 46 | savesync.o 47 | ssh.o 48 | sshcrypto.o 49 | sshcrypto_cipher.o 50 | sshcrypto_cipher_chachapoly.o 51 | sshcrypto_kex.o 52 | sshcrypto_kex_curve25519.o 53 | sshcrypto_kex_sntrup761x25519.o 54 | sshcrypto_key.o 55 | sshcrypto_key_ed25519.o 56 | str.o 57 | stringparser.o 58 | subprocess_auth.o 59 | subprocess_sign.o 60 | trymlock.o 61 | writeall.o 62 | -------------------------------------------------------------------------------- /old/tinyssh/LINKS: -------------------------------------------------------------------------------- 1 | tinysshd 2 | tinysshd-makekey tinysshd 3 | tinysshd-printkey tinysshd 4 | -------------------------------------------------------------------------------- /old/tinyssh/SOURCES: -------------------------------------------------------------------------------- 1 | blocking 2 | buf 3 | byte 4 | channel 5 | channel_drop 6 | channel_fork 7 | channel_forkpty 8 | channel_subsystem 9 | coe 10 | connectioninfo 11 | die 12 | dropuidgid 13 | e 14 | env 15 | getln 16 | global 17 | iptostr 18 | load 19 | log 20 | loginshell 21 | logsys 22 | main_tinysshd 23 | main_tinysshd_makekey 24 | main_tinysshd_printkey 25 | newenv 26 | numtostr 27 | open 28 | packet 29 | packet_auth 30 | packet_channel_open 31 | packet_channel_recv 32 | packet_channel_request 33 | packet_channel_send 34 | packet_get 35 | packet_hello 36 | packet_kex 37 | packet_kexdh 38 | packet_put 39 | packet_recv 40 | packet_send 41 | packet_unimplemented 42 | packetparser 43 | porttostr 44 | randommod 45 | readall 46 | savesync 47 | ssh 48 | sshcrypto 49 | sshcrypto_cipher 50 | sshcrypto_cipher_chachapoly 51 | sshcrypto_kex 52 | sshcrypto_kex_curve25519 53 | sshcrypto_kex_sntrup761x25519 54 | sshcrypto_key 55 | sshcrypto_key_ed25519 56 | str 57 | stringparser 58 | subprocess_auth 59 | subprocess_sign 60 | tinysshd 61 | tinysshd-makekey 62 | tinysshd-printkey 63 | trymlock 64 | writeall 65 | -------------------------------------------------------------------------------- /old/tinyssh/TARGETS: -------------------------------------------------------------------------------- 1 | tinysshd 2 | tinysshnoneauthd 3 | tinysshd-makekey 4 | tinysshd-printkey 5 | -------------------------------------------------------------------------------- /old/tinyssh/blocking.c: -------------------------------------------------------------------------------- 1 | ../../blocking.c -------------------------------------------------------------------------------- /old/tinyssh/blocking.h: -------------------------------------------------------------------------------- 1 | ../../blocking.h -------------------------------------------------------------------------------- /old/tinyssh/buf.c: -------------------------------------------------------------------------------- 1 | ../../buf.c -------------------------------------------------------------------------------- /old/tinyssh/buf.h: -------------------------------------------------------------------------------- 1 | ../../buf.h -------------------------------------------------------------------------------- /old/tinyssh/bug.h: -------------------------------------------------------------------------------- 1 | ../../bug.h -------------------------------------------------------------------------------- /old/tinyssh/byte.c: -------------------------------------------------------------------------------- 1 | ../../byte.c -------------------------------------------------------------------------------- /old/tinyssh/byte.h: -------------------------------------------------------------------------------- 1 | ../../byte.h -------------------------------------------------------------------------------- /old/tinyssh/channel.c: -------------------------------------------------------------------------------- 1 | ../../channel.c -------------------------------------------------------------------------------- /old/tinyssh/channel.h: -------------------------------------------------------------------------------- 1 | ../../channel.h -------------------------------------------------------------------------------- /old/tinyssh/channel_drop.c: -------------------------------------------------------------------------------- 1 | ../../channel_drop.c -------------------------------------------------------------------------------- /old/tinyssh/channel_fork.c: -------------------------------------------------------------------------------- 1 | ../../channel_fork.c -------------------------------------------------------------------------------- /old/tinyssh/channel_forkpty.c: -------------------------------------------------------------------------------- 1 | ../../channel_forkpty.c -------------------------------------------------------------------------------- /old/tinyssh/channel_subsystem.c: -------------------------------------------------------------------------------- 1 | ../../channel_subsystem.c -------------------------------------------------------------------------------- /old/tinyssh/coe.c: -------------------------------------------------------------------------------- 1 | ../../coe.c -------------------------------------------------------------------------------- /old/tinyssh/coe.h: -------------------------------------------------------------------------------- 1 | ../../coe.h -------------------------------------------------------------------------------- /old/tinyssh/connectioninfo.c: -------------------------------------------------------------------------------- 1 | ../../connectioninfo.c -------------------------------------------------------------------------------- /old/tinyssh/connectioninfo.h: -------------------------------------------------------------------------------- 1 | ../../connectioninfo.h -------------------------------------------------------------------------------- /old/tinyssh/die.c: -------------------------------------------------------------------------------- 1 | ../../die.c -------------------------------------------------------------------------------- /old/tinyssh/die.h: -------------------------------------------------------------------------------- 1 | ../../die.h -------------------------------------------------------------------------------- /old/tinyssh/dropuidgid.c: -------------------------------------------------------------------------------- 1 | ../../dropuidgid.c -------------------------------------------------------------------------------- /old/tinyssh/dropuidgid.h: -------------------------------------------------------------------------------- 1 | ../../dropuidgid.h -------------------------------------------------------------------------------- /old/tinyssh/e.c: -------------------------------------------------------------------------------- 1 | ../../e.c -------------------------------------------------------------------------------- /old/tinyssh/e.h: -------------------------------------------------------------------------------- 1 | ../../e.h -------------------------------------------------------------------------------- /old/tinyssh/env.c: -------------------------------------------------------------------------------- 1 | ../../env.c -------------------------------------------------------------------------------- /old/tinyssh/env.h: -------------------------------------------------------------------------------- 1 | ../../env.h -------------------------------------------------------------------------------- /old/tinyssh/getln.c: -------------------------------------------------------------------------------- 1 | ../../getln.c -------------------------------------------------------------------------------- /old/tinyssh/getln.h: -------------------------------------------------------------------------------- 1 | ../../getln.h -------------------------------------------------------------------------------- /old/tinyssh/global.c: -------------------------------------------------------------------------------- 1 | ../../global.c -------------------------------------------------------------------------------- /old/tinyssh/global.h: -------------------------------------------------------------------------------- 1 | ../../global.h -------------------------------------------------------------------------------- /old/tinyssh/iptostr.c: -------------------------------------------------------------------------------- 1 | ../../iptostr.c -------------------------------------------------------------------------------- /old/tinyssh/iptostr.h: -------------------------------------------------------------------------------- 1 | ../../iptostr.h -------------------------------------------------------------------------------- /old/tinyssh/limit.h: -------------------------------------------------------------------------------- 1 | ../../limit.h -------------------------------------------------------------------------------- /old/tinyssh/load.c: -------------------------------------------------------------------------------- 1 | ../../load.c -------------------------------------------------------------------------------- /old/tinyssh/load.h: -------------------------------------------------------------------------------- 1 | ../../load.h -------------------------------------------------------------------------------- /old/tinyssh/log.c: -------------------------------------------------------------------------------- 1 | ../../log.c -------------------------------------------------------------------------------- /old/tinyssh/log.h: -------------------------------------------------------------------------------- 1 | ../../log.h -------------------------------------------------------------------------------- /old/tinyssh/loginshell.c: -------------------------------------------------------------------------------- 1 | ../../loginshell.c -------------------------------------------------------------------------------- /old/tinyssh/loginshell.h: -------------------------------------------------------------------------------- 1 | ../../loginshell.h -------------------------------------------------------------------------------- /old/tinyssh/logsys.c: -------------------------------------------------------------------------------- 1 | ../../logsys.c -------------------------------------------------------------------------------- /old/tinyssh/logsys.h: -------------------------------------------------------------------------------- 1 | ../../logsys.h -------------------------------------------------------------------------------- /old/tinyssh/main.h: -------------------------------------------------------------------------------- 1 | ../../main.h -------------------------------------------------------------------------------- /old/tinyssh/main_tinysshd.c: -------------------------------------------------------------------------------- 1 | ../../main_tinysshd.c -------------------------------------------------------------------------------- /old/tinyssh/main_tinysshd_makekey.c: -------------------------------------------------------------------------------- 1 | ../../main_tinysshd_makekey.c -------------------------------------------------------------------------------- /old/tinyssh/main_tinysshd_printkey.c: -------------------------------------------------------------------------------- 1 | ../../main_tinysshd_printkey.c -------------------------------------------------------------------------------- /old/tinyssh/newenv.c: -------------------------------------------------------------------------------- 1 | ../../newenv.c -------------------------------------------------------------------------------- /old/tinyssh/newenv.h: -------------------------------------------------------------------------------- 1 | ../../newenv.h -------------------------------------------------------------------------------- /old/tinyssh/numtostr.c: -------------------------------------------------------------------------------- 1 | ../../numtostr.c -------------------------------------------------------------------------------- /old/tinyssh/numtostr.h: -------------------------------------------------------------------------------- 1 | ../../numtostr.h -------------------------------------------------------------------------------- /old/tinyssh/open.c: -------------------------------------------------------------------------------- 1 | ../../open.c -------------------------------------------------------------------------------- /old/tinyssh/open.h: -------------------------------------------------------------------------------- 1 | ../../open.h -------------------------------------------------------------------------------- /old/tinyssh/packet.c: -------------------------------------------------------------------------------- 1 | ../../packet.c -------------------------------------------------------------------------------- /old/tinyssh/packet.h: -------------------------------------------------------------------------------- 1 | ../../packet.h -------------------------------------------------------------------------------- /old/tinyssh/packet_auth.c: -------------------------------------------------------------------------------- 1 | ../../packet_auth.c -------------------------------------------------------------------------------- /old/tinyssh/packet_channel_open.c: -------------------------------------------------------------------------------- 1 | ../../packet_channel_open.c -------------------------------------------------------------------------------- /old/tinyssh/packet_channel_recv.c: -------------------------------------------------------------------------------- 1 | ../../packet_channel_recv.c -------------------------------------------------------------------------------- /old/tinyssh/packet_channel_request.c: -------------------------------------------------------------------------------- 1 | ../../packet_channel_request.c -------------------------------------------------------------------------------- /old/tinyssh/packet_channel_send.c: -------------------------------------------------------------------------------- 1 | ../../packet_channel_send.c -------------------------------------------------------------------------------- /old/tinyssh/packet_get.c: -------------------------------------------------------------------------------- 1 | ../../packet_get.c -------------------------------------------------------------------------------- /old/tinyssh/packet_hello.c: -------------------------------------------------------------------------------- 1 | ../../packet_hello.c -------------------------------------------------------------------------------- /old/tinyssh/packet_kex.c: -------------------------------------------------------------------------------- 1 | ../../packet_kex.c -------------------------------------------------------------------------------- /old/tinyssh/packet_kexdh.c: -------------------------------------------------------------------------------- 1 | ../../packet_kexdh.c -------------------------------------------------------------------------------- /old/tinyssh/packet_put.c: -------------------------------------------------------------------------------- 1 | ../../packet_put.c -------------------------------------------------------------------------------- /old/tinyssh/packet_recv.c: -------------------------------------------------------------------------------- 1 | ../../packet_recv.c -------------------------------------------------------------------------------- /old/tinyssh/packet_send.c: -------------------------------------------------------------------------------- 1 | ../../packet_send.c -------------------------------------------------------------------------------- /old/tinyssh/packet_unimplemented.c: -------------------------------------------------------------------------------- 1 | ../../packet_unimplemented.c -------------------------------------------------------------------------------- /old/tinyssh/packetparser.c: -------------------------------------------------------------------------------- 1 | ../../packetparser.c -------------------------------------------------------------------------------- /old/tinyssh/packetparser.h: -------------------------------------------------------------------------------- 1 | ../../packetparser.h -------------------------------------------------------------------------------- /old/tinyssh/porttostr.c: -------------------------------------------------------------------------------- 1 | ../../porttostr.c -------------------------------------------------------------------------------- /old/tinyssh/porttostr.h: -------------------------------------------------------------------------------- 1 | ../../porttostr.h -------------------------------------------------------------------------------- /old/tinyssh/purge.h: -------------------------------------------------------------------------------- 1 | ../../purge.h -------------------------------------------------------------------------------- /old/tinyssh/randommod.c: -------------------------------------------------------------------------------- 1 | ../../randommod.c -------------------------------------------------------------------------------- /old/tinyssh/randommod.h: -------------------------------------------------------------------------------- 1 | ../../randommod.h -------------------------------------------------------------------------------- /old/tinyssh/readall.c: -------------------------------------------------------------------------------- 1 | ../../readall.c -------------------------------------------------------------------------------- /old/tinyssh/readall.h: -------------------------------------------------------------------------------- 1 | ../../readall.h -------------------------------------------------------------------------------- /old/tinyssh/savesync.c: -------------------------------------------------------------------------------- 1 | ../../savesync.c -------------------------------------------------------------------------------- /old/tinyssh/savesync.h: -------------------------------------------------------------------------------- 1 | ../../savesync.h -------------------------------------------------------------------------------- /old/tinyssh/ssh.c: -------------------------------------------------------------------------------- 1 | ../../ssh.c -------------------------------------------------------------------------------- /old/tinyssh/ssh.h: -------------------------------------------------------------------------------- 1 | ../../ssh.h -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto.h: -------------------------------------------------------------------------------- 1 | ../../sshcrypto.h -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_cipher.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_cipher.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_cipher_chachapoly.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_cipher_chachapoly.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_kex.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_kex.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_kex_curve25519.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_kex_curve25519.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_kex_sntrup761x25519.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_kex_sntrup761x25519.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_key.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_key.c -------------------------------------------------------------------------------- /old/tinyssh/sshcrypto_key_ed25519.c: -------------------------------------------------------------------------------- 1 | ../../sshcrypto_key_ed25519.c -------------------------------------------------------------------------------- /old/tinyssh/str.c: -------------------------------------------------------------------------------- 1 | ../../str.c -------------------------------------------------------------------------------- /old/tinyssh/str.h: -------------------------------------------------------------------------------- 1 | ../../str.h -------------------------------------------------------------------------------- /old/tinyssh/stringparser.c: -------------------------------------------------------------------------------- 1 | ../../stringparser.c -------------------------------------------------------------------------------- /old/tinyssh/stringparser.h: -------------------------------------------------------------------------------- 1 | ../../stringparser.h -------------------------------------------------------------------------------- /old/tinyssh/subprocess.h: -------------------------------------------------------------------------------- 1 | ../../subprocess.h -------------------------------------------------------------------------------- /old/tinyssh/subprocess_auth.c: -------------------------------------------------------------------------------- 1 | ../../subprocess_auth.c -------------------------------------------------------------------------------- /old/tinyssh/subprocess_sign.c: -------------------------------------------------------------------------------- 1 | ../../subprocess_sign.c -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-makekey.c: -------------------------------------------------------------------------------- 1 | ../../tinysshd.c -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-makekey.exp: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd-makekey.exp -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-makekey.rts: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd-makekey.sh -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-printkey.c: -------------------------------------------------------------------------------- 1 | ../../tinysshd.c -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-printkey.exp: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd-printkey.exp -------------------------------------------------------------------------------- /old/tinyssh/tinysshd-printkey.rts: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd-printkey.sh -------------------------------------------------------------------------------- /old/tinyssh/tinysshd.c: -------------------------------------------------------------------------------- 1 | ../../tinysshd.c -------------------------------------------------------------------------------- /old/tinyssh/tinysshd.exp: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd.exp -------------------------------------------------------------------------------- /old/tinyssh/tinysshd.rts: -------------------------------------------------------------------------------- 1 | ../../test-tinysshd.sh -------------------------------------------------------------------------------- /old/tinyssh/tinysshnoneauthd.c: -------------------------------------------------------------------------------- 1 | ../../tinysshd.c -------------------------------------------------------------------------------- /old/tinyssh/tinysshnoneauthd.exp: -------------------------------------------------------------------------------- 1 | ../../test-tinysshnoneauthd.exp -------------------------------------------------------------------------------- /old/tinyssh/tinysshnoneauthd.rts: -------------------------------------------------------------------------------- 1 | ../../test-tinysshnoneauthd.sh -------------------------------------------------------------------------------- /old/tinyssh/trymlock.c: -------------------------------------------------------------------------------- 1 | ../../trymlock.c -------------------------------------------------------------------------------- /old/tinyssh/trymlock.h: -------------------------------------------------------------------------------- 1 | ../../trymlock.h -------------------------------------------------------------------------------- /old/tinyssh/writeall.c: -------------------------------------------------------------------------------- 1 | ../../writeall.c -------------------------------------------------------------------------------- /old/tinyssh/writeall.h: -------------------------------------------------------------------------------- 1 | ../../writeall.h -------------------------------------------------------------------------------- /old/tools: -------------------------------------------------------------------------------- 1 | ../tools -------------------------------------------------------------------------------- /open.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from curvecp/open_cwd.c curvecp/open_pipe.c 3 | curvecp/open_read.c curvecp/open_write.c 4 | - reformated using clang-format 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "blocking.h" 11 | #include "open.h" 12 | 13 | int open_cwd(void) { return open_read("."); } 14 | 15 | int open_pipe(int *fd) { 16 | int i; 17 | if (pipe(fd) == -1) return -1; 18 | for (i = 0; i < 2; ++i) { 19 | fcntl(fd[i], F_SETFD, 1); 20 | blocking_disable(fd[i]); 21 | } 22 | return 0; 23 | } 24 | 25 | int open_read(const char *fn) { 26 | #ifdef O_CLOEXEC 27 | return open(fn, O_RDONLY | O_NONBLOCK | O_CLOEXEC); 28 | #else 29 | int fd = open(fn, O_RDONLY | O_NONBLOCK); 30 | if (fd == -1) return -1; 31 | fcntl(fd, F_SETFD, 1); 32 | return fd; 33 | #endif 34 | } 35 | 36 | int open_write(const char *fn) { 37 | #ifdef O_CLOEXEC 38 | return open(fn, O_CREAT | O_WRONLY | O_NONBLOCK | O_CLOEXEC, 0644); 39 | #else 40 | int fd = open(fn, O_CREAT | O_WRONLY | O_NONBLOCK, 0644); 41 | if (fd == -1) return -1; 42 | fcntl(fd, F_SETFD, 1); 43 | return fd; 44 | #endif 45 | } 46 | -------------------------------------------------------------------------------- /open.h: -------------------------------------------------------------------------------- 1 | #ifndef OPEN_H____ 2 | #define OPEN_H____ 3 | 4 | extern int open_read(const char *); 5 | extern int open_write(const char *); 6 | extern int open_lock(const char *); 7 | extern int open_cwd(void); 8 | extern int open_pipe(int *); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /packet.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140222 3 | 20241210 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "purge.h" 9 | #include "trymlock.h" 10 | #include "packet.h" 11 | 12 | struct packet packet = {0}; 13 | 14 | void packet_purge(void) { 15 | purge(&packet, sizeof packet); 16 | trymunlock(&packet, sizeof packet); 17 | } 18 | 19 | void packet_init(void) { 20 | 21 | trymlock(&packet, sizeof packet); 22 | purge(&packet, sizeof packet); 23 | 24 | packet.flagkeys = 0; 25 | packet.flagauthorized = 0; 26 | packet.flagrekeying = 0; 27 | packet.flagclosesent = 0; 28 | packet.flageofsent = 0; 29 | packet.flagchanneleofreceived = 0; 30 | packet.sendpacketid = 0; 31 | packet.receivepacketid = 0; 32 | packet.packet_length = 0; 33 | 34 | buf_init(&packet.hellosend, packet.hellosendspace, 35 | sizeof packet.hellosendspace); 36 | buf_init(&packet.helloreceive, packet.helloreceivespace, 37 | sizeof packet.helloreceivespace); 38 | buf_init(&packet.kexsend, packet.kexsendspace, sizeof packet.kexsendspace); 39 | buf_init(&packet.kexrecv, packet.kexrecvspace, sizeof packet.kexrecvspace); 40 | buf_init(&packet.hashbuf, packet.hashbufspace, sizeof packet.hashbufspace); 41 | buf_init(&packet.sendbuf, packet.sendbufspace, sizeof packet.sendbufspace); 42 | buf_init(&packet.recvbuf, packet.recvbufspace, sizeof packet.recvbufspace); 43 | } 44 | -------------------------------------------------------------------------------- /packet_hello.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140125 3 | 20241210 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "buf.h" 9 | #include "byte.h" 10 | #include "writeall.h" 11 | #include "purge.h" 12 | #include "log.h" 13 | #include "str.h" 14 | #include "getln.h" 15 | #include "e.h" 16 | #include "packet.h" 17 | 18 | /* 19 | The 'packet_hello_send()' function sends SSH hello string to the client. 20 | See RFC 4253 4.2. Protocol Version Exchange. 21 | Example: SSH-2.0-tinyssh_20160201 iX512l8j 22 | */ 23 | int packet_hello_send(void) { 24 | 25 | struct buf *b = &packet.hellosend; 26 | 27 | buf_purge(b); 28 | buf_puts(b, "SSH-2.0-tinyssh"); 29 | #ifdef VERSION 30 | buf_puts(b, "_"); 31 | buf_puts(b, VERSION); 32 | #endif 33 | buf_puts(b, " "); 34 | buf_puts(b, log_string()); 35 | buf_puts(b, "\r\n"); 36 | if (writeall(1, b->buf, b->len) == -1) return 0; 37 | b->len -= 2; /* remove "\r\n" */ 38 | b->buf[b->len] = 0; 39 | log_d2("hello: server: ", (char *) (b->buf)); 40 | purge(b->buf + b->len, b->alloc - b->len); 41 | return 1; 42 | } 43 | 44 | /* 45 | The 'packet_hello_receive()' function receives SSH hello string from the client. 46 | See RFC 4253 4.2. Protocol Version Exchange. 47 | Example: SSH-2.0-OpenSSH_6.6.1p1 Debian-4~bpo70+1 48 | */ 49 | int packet_hello_receive(void) { 50 | 51 | int r; 52 | struct buf *b = &packet.helloreceive; 53 | 54 | r = getln(0, b->buf, b->alloc); 55 | if (r == 0) { 56 | errno = ECONNRESET; 57 | return 0; 58 | } 59 | if (r != 1) return 0; 60 | b->len = str_len((char *) b->buf); 61 | if (b->len < 6) { 62 | errno = EPROTO; 63 | return 0; 64 | } 65 | if (b->buf[b->len - 1] == '\n') --(b->len); /* remove '\n' */ 66 | if (b->buf[b->len - 1] == '\r') --(b->len); /* remove '\r' */ 67 | b->buf[b->len] = 0; 68 | if (!byte_isequal(b->buf, 4, "SSH-")) { 69 | errno = EPROTO; 70 | return 0; 71 | } 72 | log_d2("hello: client: ", (char *) b->buf); 73 | purge(b->buf + b->len, b->alloc - b->len); 74 | return 1; 75 | } 76 | -------------------------------------------------------------------------------- /packet_put.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140207 3 | 20241211 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "crypto_uint32.h" 9 | #include "buf.h" 10 | #include "bug.h" 11 | #include "sshcrypto.h" 12 | #include "ssh.h" 13 | #include "log.h" 14 | #include "packet.h" 15 | 16 | static void packet_put_plain_(struct buf *b) { 17 | 18 | long long pos; 19 | crypto_uint8 paddinglen; 20 | struct buf *sendbuf = &packet.sendbuf; 21 | 22 | pos = sendbuf->len; /* get position */ 23 | buf_putnum32(sendbuf, 0); /* length */ 24 | buf_putnum8(sendbuf, 0); /* padding length */ 25 | buf_put(sendbuf, b->buf, b->len); /* add data */ 26 | packet.sendpacketid++; /* increment id */ 27 | 28 | /* padding */ 29 | paddinglen = 2 * 8 - ((sendbuf->len - pos) % 8); 30 | buf_putzerobytes(sendbuf, paddinglen); 31 | sendbuf->buf[pos + 4] = paddinglen; 32 | 33 | /* add packet length */ 34 | crypto_uint32_store_bigendian(sendbuf->buf + pos, sendbuf->len - pos - 4); 35 | } 36 | 37 | int packet_putisready(void) { 38 | 39 | return buf_ready(&packet.sendbuf, PACKET_FULLLIMIT); 40 | } 41 | 42 | void packet_put(struct buf *b) { 43 | 44 | if (packet.flagkeys) { sshcrypto_packet_put(b); } 45 | else { packet_put_plain_(b); } 46 | 47 | /* overflow check */ 48 | if (!packet.sendpacketid) { 49 | log_f1("sendpacketid overflow"); 50 | global_die(111); 51 | } 52 | 53 | /* strict kex - reset sendpacketid */ 54 | if (b->buf[0] == SSH_MSG_NEWKEYS && 55 | sshcrypto_kex_flags & sshcrypto_FLAGSTRICTKEX) { 56 | packet.sendpacketid = 0; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /packet_recv.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140120 3 | 20241211 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include "e.h" 10 | #include "buf.h" 11 | #include "purge.h" 12 | #include "packet.h" 13 | 14 | int packet_recvisready(void) { 15 | 16 | return buf_ready(&packet.recvbuf, PACKET_FULLLIMIT); 17 | } 18 | 19 | int packet_recv(void) { 20 | 21 | long long r; 22 | struct buf *b = &packet.recvbuf; 23 | 24 | if (b->len < PACKET_ZEROBYTES) { 25 | b->len = PACKET_ZEROBYTES; 26 | purge(b->buf, PACKET_ZEROBYTES); 27 | } 28 | if (!packet_recvisready()) return 1; 29 | 30 | r = read(0, b->buf + b->len, PACKET_FULLLIMIT); 31 | if (r == 0) { 32 | errno = ECONNRESET; 33 | return 0; 34 | } 35 | if (r == -1) { 36 | if (errno == EINTR) return 1; 37 | if (errno == EAGAIN) return 1; 38 | if (errno == EWOULDBLOCK) return 1; 39 | return 0; 40 | } 41 | b->len += r; 42 | return 1; 43 | } 44 | -------------------------------------------------------------------------------- /packet_send.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140120 3 | 20241211 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include 9 | #include "writeall.h" 10 | #include "e.h" 11 | #include "byte.h" 12 | #include "purge.h" 13 | #include "packet.h" 14 | 15 | int packet_sendisready(void) { return (packet.sendbuf.len > 0); } 16 | 17 | int packet_send(void) { 18 | 19 | struct buf *sendbuf = &packet.sendbuf; 20 | long long w; 21 | 22 | if (sendbuf->len <= 0) return 1; 23 | w = write(1, sendbuf->buf, sendbuf->len); 24 | if (w == -1) { 25 | if (errno == EINTR) return 1; 26 | if (errno == EAGAIN) return 1; 27 | if (errno == EWOULDBLOCK) return 1; 28 | return 0; 29 | } 30 | byte_copy(sendbuf->buf, sendbuf->len - w, sendbuf->buf + w); 31 | sendbuf->len -= w; 32 | purge(sendbuf->buf + sendbuf->len, w); 33 | return 1; 34 | } 35 | 36 | int packet_sendall(void) { 37 | 38 | if (writeall(1, packet.sendbuf.buf, packet.sendbuf.len) == -1) return 0; 39 | purge(packet.sendbuf.buf, packet.sendbuf.len); 40 | packet.sendbuf.len = 0; 41 | return 1; 42 | } 43 | -------------------------------------------------------------------------------- /packet_unimplemented.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20150719 3 | 20241211 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "buf.h" 9 | #include "ssh.h" 10 | #include "log.h" 11 | #include "numtostr.h" 12 | #include "packet.h" 13 | 14 | int packet_unimplemented(struct buf *b) { 15 | 16 | char strnum[NUMTOSTR_LEN]; 17 | 18 | /* note that b->buf[0] contains packetid */ 19 | log_d3("packet=", numtostr(strnum, b->buf[0]), 20 | ", sending SSH_MSG_UNIMPLEMENTED message"); 21 | 22 | buf_purge(b); 23 | buf_putnum8(b, SSH_MSG_UNIMPLEMENTED); /* SSH_MSG_UNIMPLEMENTED */ 24 | buf_putnum32(b, packet.receivepacketid); /* packeid */ 25 | packet_put(b); 26 | return packet_sendall(); 27 | } 28 | -------------------------------------------------------------------------------- /packetparser.h: -------------------------------------------------------------------------------- 1 | #ifndef PACKETPARSER_H____ 2 | #define PACKETPARSER_H____ 3 | 4 | #include "crypto_uint32.h" 5 | #include "crypto_uint8.h" 6 | 7 | extern long long packetparser_uint8_(const char *, unsigned long long, 8 | const unsigned char *, long long, 9 | long long, crypto_uint8 *); 10 | extern long long packetparser_uint32_(const char *, unsigned long long, 11 | const unsigned char *, long long, 12 | long long, crypto_uint32 *); 13 | extern long long packetparser_copy_(const char *, unsigned long long, 14 | const unsigned char *, long long, long long, 15 | unsigned char *, long long); 16 | extern long long packetparser_skip_(const char *, unsigned long long, 17 | const unsigned char *, long long, long long, 18 | long long); 19 | extern long long packetparser_end_(const char *, unsigned long long, 20 | const unsigned char *, long long, long long); 21 | 22 | #define packetparser_uint8(a, b, cc, d) \ 23 | packetparser_uint8_(__FILE__, __LINE__, (a), (b), (cc), (d)) 24 | #define packetparser_uint32(a, b, cc, d) \ 25 | packetparser_uint32_(__FILE__, __LINE__, (a), (b), (cc), (d)) 26 | #define packetparser_copy(a, b, cc, d, e) \ 27 | packetparser_copy_(__FILE__, __LINE__, (a), (b), (cc), (d), (e)) 28 | #define packetparser_skip(a, b, cc, d) \ 29 | packetparser_skip_(__FILE__, __LINE__, (a), (b), (cc), (d)) 30 | #define packetparser_end(a, b, cc) \ 31 | packetparser_end_(__FILE__, __LINE__, (a), (b), (cc)) 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /porttostr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20130604 3 | 20241207 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "crypto_uint16.h" 9 | #include "porttostr.h" 10 | 11 | /* 12 | The 'porttostr(strbuf,port)' converts 'port' from network byte order 13 | into the 0-terminated string. The 'port' length is always 2 bytes. 14 | The caller must allocate at least PORTTOSTR_LEN bytes for 'strbuf'. 15 | */ 16 | char *porttostr(char *strbuf, const unsigned char *port) { 17 | 18 | long long len = 0; 19 | crypto_uint16 num; 20 | static char staticbuf[PORTTOSTR_LEN]; 21 | 22 | if (!strbuf) strbuf = staticbuf; /* not thread-safe */ 23 | 24 | num = port[0]; 25 | num <<= 8; 26 | num |= port[1]; 27 | do { 28 | num /= 10; 29 | ++len; 30 | } while (num); 31 | strbuf += len; 32 | 33 | num = port[0]; 34 | num <<= 8; 35 | num |= port[1]; 36 | do { 37 | *--strbuf = '0' + (num % 10); 38 | num /= 10; 39 | } while (num); 40 | 41 | while (len < PORTTOSTR_LEN) strbuf[len++] = 0; 42 | return strbuf; 43 | } 44 | -------------------------------------------------------------------------------- /porttostr.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTTOSTR_H____ 2 | #define PORTTOSTR_H____ 3 | 4 | #define PORTTOSTR_LEN 6 5 | 6 | extern char *porttostr(char *, const unsigned char *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /purge.h: -------------------------------------------------------------------------------- 1 | #ifndef PURGE_H____ 2 | #define PURGE_H____ 3 | 4 | #include "cleanup.h" 5 | #define purge cleanup_ 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /randombytes.c: -------------------------------------------------------------------------------- 1 | #include "randombytes.h" 2 | 3 | #include "haslibrandombytes.h" 4 | #ifndef HASLIBRANDOMBYTES 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static int fd = -1; 11 | 12 | __attribute__((constructor)) static void init(void) { 13 | if (fd == -1) { 14 | for (;;) { 15 | #ifdef O_CLOEXEC 16 | fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); 17 | #else 18 | fd = open("/dev/urandom", O_RDONLY); 19 | fcntl(fd, F_SETFD, 1); 20 | #endif 21 | if (fd != -1) break; 22 | sleep(1); 23 | } 24 | } 25 | } 26 | 27 | void randombytes(void *xv, long long xlen) { 28 | 29 | long long i; 30 | unsigned char *x = xv; 31 | 32 | if (fd == -1) init(); 33 | 34 | while (xlen > 0) { 35 | if (xlen < 1048576) 36 | i = xlen; 37 | else 38 | i = 1048576; 39 | 40 | i = read(fd, x, i); 41 | if (i < 1) { 42 | sleep(1); 43 | continue; 44 | } 45 | 46 | x += i; 47 | xlen -= i; 48 | } 49 | #ifdef __GNUC__ 50 | __asm__ __volatile__("" : : "r"(xv) : "memory"); 51 | #endif 52 | } 53 | 54 | const char *randombytes_source(void) { return "kernel-devurandom"; } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /randombytes.h: -------------------------------------------------------------------------------- 1 | #ifndef RANDOMBYTES_H____ 2 | #define RANDOMBYTES_H____ 3 | 4 | #include "haslibrandombytes.h" 5 | #ifdef HASLIBRANDOMBYTES 6 | #include 7 | #else 8 | #define randombytes randombytes_internal_void_voidstar_longlong 9 | #define randombytes_source randombytes_internal_source 10 | extern void randombytes(void *, long long); 11 | extern const char *randombytes_source(void); 12 | #endif 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /randommod.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from curvecp/randommod.c 3 | - reformated using clang-format 4 | */ 5 | #include "randombytes.h" 6 | #include "randommod.h" 7 | 8 | /* XXX: current implementation is limited to n<2^55 */ 9 | 10 | long long randommod(long long n) { 11 | long long result = 0; 12 | long long j; 13 | unsigned char r[32]; 14 | if (n <= 1) return 0; 15 | randombytes(r, 32); 16 | for (j = 0; j < 32; ++j) 17 | result = (result * 256 + (unsigned long long) r[j]) % n; 18 | return result; 19 | } 20 | -------------------------------------------------------------------------------- /randommod.h: -------------------------------------------------------------------------------- 1 | #ifndef RANDOMMOD_H____ 2 | #define RANDOMMOD_H____ 3 | 4 | extern long long randommod(long long); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /readall.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from curvecp/load.c 3 | - reformated using clang-format 4 | */ 5 | #include 6 | #include "e.h" 7 | #include "readall.h" 8 | 9 | int readall(int fd, void *xv, long long xlen) { 10 | 11 | long long r; 12 | unsigned char *x = (unsigned char *) xv; 13 | 14 | while (xlen > 0) { 15 | r = xlen; 16 | if (r > 1048576) r = 1048576; 17 | r = read(fd, x, r); 18 | if (r == 0) errno = EPROTO; 19 | if (r <= 0) { 20 | if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) 21 | continue; 22 | return -1; 23 | } 24 | x += r; 25 | xlen -= r; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /readall.h: -------------------------------------------------------------------------------- 1 | #ifndef READALL_H____ 2 | #define READALL_H____ 3 | 4 | extern int readall(int, void *, long long); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /runtest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LANG=C 4 | export LANG 5 | 6 | [ x"$1" = x ] && exit 100 7 | script="$1" 8 | [ x"$2" = x ] && exit 100 9 | outfile="$2" 10 | [ x"$3" = x ] && exit 100 11 | expfile="$3" 12 | 13 | # run test 14 | sh "${script}" > "${outfile}" 15 | 16 | # compare 17 | if ! cmp "${expfile}" "${outfile}"; then 18 | echo "${script} FAILED" 19 | if [ x"`which diff`" != x ]; then 20 | # print diff 21 | diff -u "${expfile}" "${outfile}" 22 | else 23 | # print output file 24 | cat "${outfile}" 25 | fi 26 | exit 1 27 | fi 28 | 29 | echo "${script} OK" 30 | exit 0 31 | -------------------------------------------------------------------------------- /savesync.c: -------------------------------------------------------------------------------- 1 | /* 2 | taken from nacl-20110221, from curvecp/savesync.c 3 | - reformated using clang-format 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "open.h" 10 | #include "savesync.h" 11 | #include "writeall.h" 12 | 13 | static int writesync(int fd, const void *x, long long xlen) { 14 | if (writeall(fd, x, xlen) == -1) return -1; 15 | return fsync(fd); 16 | } 17 | 18 | int savesync(const char *fn, const void *x, long long xlen) { 19 | int fd; 20 | int r; 21 | fd = open_write(fn); 22 | if (fd == -1) return -1; 23 | r = writesync(fd, x, xlen); 24 | close(fd); 25 | return r; 26 | } 27 | -------------------------------------------------------------------------------- /savesync.h: -------------------------------------------------------------------------------- 1 | #ifndef SAVESYNC_H____ 2 | #define SAVESYNC_H____ 3 | 4 | extern int savesync(const char *, const void *, long long); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /sc25519.c: -------------------------------------------------------------------------------- 1 | /* 2 | - based on tweetnacl 20140427 (http://tweetnacl.cr.yp.to/software.html) 3 | - reformated using clang-format 4 | */ 5 | 6 | #include "crypto_int64.h" 7 | #include "crypto_uint32.h" 8 | #include "crypto_uint64.h" 9 | #include "cleanup.h" 10 | #include "sc25519.h" 11 | 12 | #define FOR(i, n) for (i = 0; i < n; ++i) 13 | 14 | static const crypto_uint64 L[32] = { 15 | 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7, 16 | 0xa2, 0xde, 0xf9, 0xde, 0x14, 0, 0, 0, 0, 0, 0, 17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x10}; 18 | 19 | static void modL(unsigned char *r, crypto_int64 x[64]) { 20 | crypto_int64 carry, i, j; 21 | for (i = 63; i >= 32; --i) { 22 | carry = 0; 23 | for (j = i - 32; j < i - 12; ++j) { 24 | x[j] += carry - 16 * x[i] * L[j - (i - 32)]; 25 | carry = (x[j] + 128) >> 8; 26 | x[j] -= carry << 8; 27 | } 28 | x[j] += carry; 29 | x[i] = 0; 30 | } 31 | carry = 0; 32 | FOR(j, 32) { 33 | x[j] += carry - (x[31] >> 4) * L[j]; 34 | carry = x[j] >> 8; 35 | x[j] &= 255; 36 | } 37 | FOR(j, 32) x[j] -= carry * L[j]; 38 | FOR(i, 32) { 39 | x[i + 1] += x[i] >> 8; 40 | r[i] = x[i] & 255; 41 | } 42 | } 43 | 44 | void sc25519_reduce(unsigned char *s) { 45 | 46 | crypto_int64 t[64], i; 47 | 48 | for (i = 0; i < 64; ++i) t[i] = s[i]; 49 | for (i = 0; i < 64; ++i) s[i] = 0; 50 | modL(s, t); 51 | 52 | cleanup(t); 53 | } 54 | 55 | void sc25519_muladd(unsigned char *s, const unsigned char *a, 56 | const unsigned char *b, const unsigned char *c) { 57 | 58 | crypto_int64 t[64], i, j; 59 | 60 | for (i = 0; i < 64; ++i) t[i] = 0; 61 | 62 | for (i = 0; i < 32; ++i) 63 | for (j = 0; j < 32; ++j) { 64 | t[i + j] += (crypto_int64) a[i] * (crypto_int64) b[j]; 65 | } 66 | 67 | for (i = 0; i < 32; ++i) t[i] += c[i]; 68 | modL(s, t); 69 | 70 | cleanup(t); 71 | } 72 | -------------------------------------------------------------------------------- /sc25519.h: -------------------------------------------------------------------------------- 1 | #ifndef SC25519_H____ 2 | #define SC25519_H____ 3 | 4 | extern void sc25519_reduce(unsigned char *); 5 | extern void sc25519_muladd(unsigned char *, const unsigned char *, 6 | const unsigned char *, const unsigned char *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /ssh.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ssh.h" 3 | 4 | #define X(e, s) \ 5 | if (i == e) return s 6 | 7 | /* 8 | Return short name of signal. 9 | */ 10 | const char *ssh_sigstr(int i) { 11 | 12 | #ifdef SIGABRT 13 | X(SIGABRT, "ABRT"); 14 | #endif 15 | #ifdef SIGALRM 16 | X(SIGALRM, "ALRM"); 17 | #endif 18 | #ifdef SIGFPE 19 | X(SIGFPE, "FPE"); 20 | #endif 21 | #ifdef SIGHUP 22 | X(SIGHUP, "HUP"); 23 | #endif 24 | #ifdef SIGILL 25 | X(SIGILL, "ILL"); 26 | #endif 27 | #ifdef SIGINT 28 | X(SIGINT, "INT"); 29 | #endif 30 | #ifdef SIGKILL 31 | X(SIGKILL, "KILL"); 32 | #endif 33 | #ifdef SIGPIPE 34 | X(SIGPIPE, "PIPE"); 35 | #endif 36 | #ifdef SIGQUIT 37 | X(SIGQUIT, "QUIT"); 38 | #endif 39 | #ifdef SIGSEGV 40 | X(SIGSEGV, "SEGV"); 41 | #endif 42 | #ifdef SIGTERM 43 | X(SIGTERM, "TERM"); 44 | #endif 45 | #ifdef SIGUSR1 46 | X(SIGUSR1, "USR1"); 47 | #endif 48 | #ifdef SIGUSR2 49 | X(SIGUSR2, "USR2"); 50 | #endif 51 | 52 | return "UNKNOWN"; 53 | } 54 | 55 | /* 56 | Return long name of signal. 57 | */ 58 | const char *ssh_sigstrlong(int i) { 59 | 60 | #ifdef SIGABRT 61 | X(SIGABRT, "SIGABRT (abort)"); 62 | #endif 63 | #ifdef SIGALRM 64 | X(SIGALRM, "SIGALRM (alarm clock)"); 65 | #endif 66 | #ifdef SIGFPE 67 | X(SIGFPE, "SIGFPE (floating-point exception)"); 68 | #endif 69 | #ifdef SIGILL 70 | X(SIGILL, "SIGILL (illegal instruction)"); 71 | #endif 72 | #ifdef SIGINT 73 | X(SIGINT, "SIGINT (interrupt)"); 74 | #endif 75 | #ifdef SIGKILL 76 | X(SIGKILL, "SIGKILL (kill, unblockable)"); 77 | #endif 78 | #ifdef SIGPIPE 79 | X(SIGPIPE, "SIGPIPE (broken pipe)"); 80 | #endif 81 | #ifdef SIGQUIT 82 | X(SIGQUIT, "SIGQUIT (quit)"); 83 | #endif 84 | #ifdef SIGSEGV 85 | X(SIGSEGV, "SIGSEGV (segment violation)"); 86 | #endif 87 | #ifdef SIGTERM 88 | X(SIGTERM, "SIGTERM (termination)"); 89 | #endif 90 | #ifdef SIGUSR1 91 | X(SIGUSR1, "SIGUSR1 (user defined signal 1)"); 92 | #endif 93 | #ifdef SIGUSR2 94 | X(SIGUSR2, "SIGUSR2 (user defined signal 2)"); 95 | #endif 96 | 97 | return "UNKNOWN SIGNAL"; 98 | } 99 | -------------------------------------------------------------------------------- /sshcrypto.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140225 3 | 20241210 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "purge.h" 9 | #include "bug.h" 10 | #include "str.h" 11 | #include "sshcrypto.h" 12 | 13 | /* 14 | Initialize and check *MAX constants 15 | */ 16 | void sshcrypto_init(void) { 17 | 18 | long long i; 19 | 20 | /* kex */ 21 | for (i = 0; sshcrypto_kexs[i].name; ++i) { 22 | if (sshcrypto_kexs[i].kem_publickeybytes > sshcrypto_kem_PUBLICKEYMAX) 23 | bug_inval(); 24 | if (sshcrypto_kexs[i].kem_ciphertextbytes > sshcrypto_kem_CIPHERTEXTMAX) 25 | bug_inval(); 26 | if (sshcrypto_kexs[i].kem_bytes > sshcrypto_kem_MAX) bug_inval(); 27 | if (sshcrypto_kexs[i].hash_bytes > sshcrypto_hash_MAX) bug_inval(); 28 | } 29 | 30 | /* key */ 31 | for (i = 0; sshcrypto_keys[i].name; ++i) { 32 | if (sshcrypto_keys[i].sign_publickeybytes > sshcrypto_sign_PUBLICKEYMAX) 33 | bug_inval(); 34 | if (sshcrypto_keys[i].sign_secretkeybytes > sshcrypto_sign_SECRETKEYMAX) 35 | bug_inval(); 36 | if (sshcrypto_keys[i].sign_bytes > sshcrypto_sign_MAX) bug_inval(); 37 | if (str_len(sshcrypto_keys[i].name) + 1 > sshcrypto_sign_NAMEMAX) 38 | bug_inval(); 39 | } 40 | 41 | /* cipher */ 42 | for (i = 0; sshcrypto_ciphers[i].name; ++i) { 43 | if (sshcrypto_ciphers[i].stream_keybytes > sshcrypto_cipher_KEYMAX) 44 | bug_inval(); 45 | } 46 | } 47 | 48 | /* 49 | Remove sentitive data from allocated memory. 50 | */ 51 | void sshcrypto_purge(void) { 52 | 53 | long long i; 54 | 55 | /* kex */ 56 | for (i = 0; sshcrypto_kexs[i].name; ++i) { 57 | purge(&sshcrypto_kexs[i], sizeof(struct sshcrypto_kex)); 58 | } 59 | 60 | /* key */ 61 | for (i = 0; sshcrypto_keys[i].name; ++i) { 62 | purge(&sshcrypto_keys[i], sizeof(struct sshcrypto_key)); 63 | } 64 | 65 | /* cipher */ 66 | for (i = 0; sshcrypto_ciphers[i].name; ++i) { 67 | purge(&sshcrypto_ciphers[i], sizeof(struct sshcrypto_cipher)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /sshcrypto_kex_curve25519.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20241114 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "buf.h" 8 | #include "crypto.h" 9 | #include "purge.h" 10 | #include "crypto_int16.h" 11 | #include "sshcrypto.h" 12 | 13 | int curve25519_enc(unsigned char *c, unsigned char *k, 14 | const unsigned char *pk) { 15 | 16 | unsigned char onetimesk[crypto_dh_x25519_SECRETKEYBYTES]; 17 | long long i; 18 | unsigned int d = 0; 19 | 20 | crypto_dh_x25519_keypair(/*onetimepk*/ c, onetimesk); 21 | crypto_dh_x25519(k, pk, onetimesk); 22 | purge(onetimesk, sizeof onetimesk); 23 | 24 | for (i = 0; i < crypto_dh_x25519_BYTES; ++i) d |= k[i]; 25 | return crypto_int16_zero_mask(d); 26 | } 27 | 28 | void curve25519_putkemkey(struct buf *b, const unsigned char *x) { 29 | buf_putsharedsecret(b, x, crypto_dh_x25519_BYTES); 30 | } 31 | -------------------------------------------------------------------------------- /sshcrypto_kex_sntrup761x25519.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20210314 3 | 20241210 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "buf.h" 9 | #include "crypto.h" 10 | #include "sshcrypto.h" 11 | 12 | void sntrup761x25519_putkemkey(struct buf *b, const unsigned char *x) { 13 | buf_putstringlen(b, x, crypto_kem_sntrup761x25519_BYTES); 14 | } 15 | -------------------------------------------------------------------------------- /str.c: -------------------------------------------------------------------------------- 1 | #include "str.h" 2 | 3 | /* 4 | The 'str_len(s)' function calculates the length of the string 's'. 5 | */ 6 | long long str_len(const char *s) { 7 | 8 | long long i; 9 | 10 | for (i = 0; s[i]; ++i); 11 | return i; 12 | } 13 | 14 | /* 15 | The 'str_start(s,t)' function returns 1 if t is a prefix of s, 0 otherwise. 16 | */ 17 | int str_start(const char *s, const char *t) { 18 | 19 | char x; 20 | 21 | for (;;) { 22 | x = *t++; 23 | if (!x) return 1; 24 | if (x != *s++) return 0; 25 | } 26 | } 27 | 28 | /* 29 | The 'str_equaln(y,ylen,x)' function returns 1 if the length of string 'x' is 30 | ylen and if y and x match up to, 0 otherwise. 31 | */ 32 | int str_equaln(const char *y, long long ylen, const char *x) { 33 | 34 | long long i; 35 | 36 | if (str_len(x) != ylen) return 0; 37 | for (i = 0; i < ylen; ++i) 38 | if (y[i] != x[i]) return 0; 39 | return 1; 40 | } 41 | 42 | /* 43 | The 'str_copyn(y,ylen,x)' function copies the string pointed to by 'x' 44 | (including \0) to the buffer pointed to by 'y'. If the length of string x is 45 | smaller than ylen or equal, then function returns 1. If the length of string x 46 | is biger than ylen, then only ylen - 1 bytes of 'x' are copied and function 47 | returns 0. The 'y' string is always \0 terminated. 48 | */ 49 | int str_copyn(char *y, long long ylen, const char *x) { 50 | 51 | long long len = str_len(x); 52 | int ret = 1; 53 | 54 | if (ylen <= 0) return 0; 55 | if (ylen - 1 < len) { 56 | len = ylen - 1; 57 | ret = 0; 58 | } 59 | y[len] = 0; 60 | while (len > 0) { 61 | *y++ = *x++; 62 | --len; 63 | } 64 | return ret; 65 | } 66 | -------------------------------------------------------------------------------- /str.h: -------------------------------------------------------------------------------- 1 | #ifndef STR_H____ 2 | #define STR_H____ 3 | 4 | extern long long str_len(const char *); 5 | extern int str_start(const char *, const char *); 6 | extern int str_equaln(const char *, long long, const char *); 7 | extern int str_copyn(char *, long long, const char *); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /stringparser.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20140203 3 | 20241208 - reformated using clang-format 4 | Jan Mojzis 5 | Public domain. 6 | */ 7 | 8 | #include "byte.h" 9 | #include "e.h" 10 | #include "bug.h" 11 | #include "stringparser.h" 12 | 13 | /* 14 | The 'stringparser' function parses items from 15 | comma-separated list. Empty strings are ignored. 16 | */ 17 | long long stringparser(const unsigned char *buf, long long len, long long pos, 18 | const unsigned char **x, long long *xlen) { 19 | 20 | long long i; 21 | 22 | if (!buf || len < 0 || len > 1073741824 || pos < 0 || pos > 1073741824 || 23 | !x || !xlen) 24 | bug_inval(); 25 | 26 | for (;;) { 27 | if (pos >= len) return 0; 28 | 29 | for (i = pos; i < len; ++i) { 30 | if (buf[i] == ',') break; 31 | } 32 | *x = buf + pos; 33 | *xlen = i - pos; 34 | pos = i + 1; 35 | if (*xlen != 0) return pos; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /stringparser.h: -------------------------------------------------------------------------------- 1 | #ifndef STRINGPARSER_H____ 2 | #define STRINGPARSER_H____ 3 | 4 | extern long long stringparser(const unsigned char *, long long, long long, 5 | const unsigned char **, long long *); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /subprocess.h: -------------------------------------------------------------------------------- 1 | #ifndef SUBPROCESS_H____ 2 | #define SUBPROCESS_H____ 3 | 4 | #include 5 | 6 | extern int subprocess_sign(unsigned char *, long long, const char *, 7 | unsigned char *, long long); 8 | extern int subprocess_auth(const char *, const char *, const char *); 9 | 10 | extern int subprocess_auth_checkpath_(char *, long long, uid_t); 11 | extern int subprocess_auth_authorizedkeys_(const char *, const char *, 12 | const char *, char *, long long); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /test-crypto-dh.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto dh 2 | dh_x25519 offset 0 3 | dh_x25519 offset 1 4 | all tests succeeded 5 | 0 6 | 7 | -------------------------------------------------------------------------------- /test-crypto-dh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto dh' 4 | ./test-crypto dh 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-hash.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto hash 2 | hash_sha256 offset 0 3 | hash_sha256 offset 1 4 | hash_sha512 offset 0 5 | hash_sha512 offset 1 6 | all tests succeeded 7 | 0 8 | 9 | -------------------------------------------------------------------------------- /test-crypto-hash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto hash' 4 | ./test-crypto hash 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-kem.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto kem 2 | kem_sntrup761 offset 0 3 | kem_sntrup761 offset 1 4 | all tests succeeded 5 | 0 6 | 7 | -------------------------------------------------------------------------------- /test-crypto-kem.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto kem' 4 | ./test-crypto kem 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-onetimeauth.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto onetimeauth 2 | onetimeauth_poly1305 offset 0 3 | onetimeauth_poly1305 offset 1 4 | all tests succeeded 5 | 0 6 | 7 | -------------------------------------------------------------------------------- /test-crypto-onetimeauth.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto onetimeauth' 4 | ./test-crypto onetimeauth 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-sign.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto sign 2 | sign_ed25519 offset 0 3 | sign_ed25519 offset 1 4 | all tests succeeded 5 | 0 6 | 7 | -------------------------------------------------------------------------------- /test-crypto-sign.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto sign' 4 | ./test-crypto sign 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-sort.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto sort 2 | sort_uint32 offset 0 3 | all tests succeeded 4 | 0 5 | 6 | -------------------------------------------------------------------------------- /test-crypto-sort.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto sort' 4 | ./test-crypto sort 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-crypto-verify.exp: -------------------------------------------------------------------------------- 1 | --- test-crypto verify 2 | verify_16 offset 0 3 | verify_16 offset 1 4 | verify_32 offset 0 5 | verify_32 offset 1 6 | all tests succeeded 7 | 0 8 | 9 | -------------------------------------------------------------------------------- /test-crypto-verify.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo '--- test-crypto verify' 4 | ./test-crypto verify 5 | echo $? 6 | echo 7 | exit 0 8 | -------------------------------------------------------------------------------- /test-tinysshd-makekey.exp: -------------------------------------------------------------------------------- 1 | --- tinysshd-makekey prints help 2 | 3 | 100 4 | 5 | --- tinysshd-makekey creates key-directory 6 | 7 | keydirm/ed25519.pk 8 | 0 9 | 10 | --- tinysshd-makekey fails when directory exists 11 | 12 | tinysshd-makekey: fatal: unable to create directory keydirm (file already exists) 13 | 111 14 | --- tinysshd-makekey handles '-m' parameter (prints help) 15 | 16 | 100 17 | 18 | --- tinysshd-makekey creates '-m' key-directory 19 | 20 | 0 21 | 22 | -------------------------------------------------------------------------------- /test-tinysshd-makekey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | LANG=C 4 | export LANG 5 | 6 | LC_ALL=C 7 | export LC_ALL 8 | 9 | cleanup() { 10 | ex=$? 11 | rm -rf -- keydirm -m 12 | exit "${ex}" 13 | } 14 | trap "cleanup" EXIT TERM INT 15 | 16 | echo '--- tinysshd-makekey prints help' 17 | echo 18 | ./tinysshd-makekey 2>/dev/null 19 | echo $? 20 | echo 21 | 22 | echo '--- tinysshd-makekey creates key-directory' 23 | echo 24 | rm -rf keydirm 25 | ./tinysshd-makekey keydirm 2>&1 26 | ls keydirm/*.pk | sort 27 | echo $? 28 | echo 29 | 30 | echo '--- tinysshd-makekey fails when directory exists' 31 | echo 32 | rm -rf keydirm 33 | mkdir keydirm 34 | ./tinysshd-makekey keydirm 2>&1 35 | echo $? 36 | 37 | echo "--- tinysshd-makekey handles '-m' parameter (prints help)" 38 | echo 39 | ./tinysshd-makekey -m 2>/dev/null 40 | echo $? 41 | echo 42 | 43 | echo "--- tinysshd-makekey creates '-m' key-directory" 44 | echo 45 | ./tinysshd-makekey -- -m 2>&1 46 | echo $? 47 | echo 48 | -------------------------------------------------------------------------------- /test-tinysshd-printkey.exp: -------------------------------------------------------------------------------- 1 | --- tinysshd-printkey prints help 2 | 3 | 100 4 | 5 | --- tinysshd-printkey prints keys 6 | 7 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHgK 8 | 0 9 | 10 | --- tinysshd-printkey prints only ssh-ed25519 key 11 | 12 | ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHgK 13 | 0 14 | 15 | --- tinysshd-printkey prints only ecdsa-sha2-nistp256 key 16 | 17 | 0 18 | 19 | --- tinysshd-printkey handles '-r' parameter (prints help) 20 | 21 | 100 22 | 23 | --- tinysshd-printkey prints keys from '-r' key-directory 24 | 25 | 0 26 | 27 | -------------------------------------------------------------------------------- /test-tinysshd-printkey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cleanup() { 4 | ex=$? 5 | rm -rf -- keydirp -r 6 | exit "${ex}" 7 | } 8 | trap "cleanup" EXIT TERM INT 9 | 10 | mkdir keydirp 11 | 12 | echo '--- tinysshd-printkey prints help' 13 | echo 14 | ./tinysshd-printkey 2>/dev/null 15 | echo $? 16 | echo 17 | 18 | ( 19 | echo 'ed25519.pk xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 20 | echo 'nistp256ecdsa.pk xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' 21 | ) | ( 22 | while read name key 23 | do 24 | echo ${key} > "keydirp/${name}" 25 | done 26 | ) 27 | 28 | echo '--- tinysshd-printkey prints keys' 29 | echo 30 | ./tinysshd-printkey keydirp 31 | echo $? 32 | echo 33 | 34 | mv keydirp/nistp256ecdsa.pk keydirp/nistp256ecdsa.pk.bk 35 | 36 | echo '--- tinysshd-printkey prints only ssh-ed25519 key' 37 | echo 38 | ./tinysshd-printkey keydirp 39 | echo $? 40 | echo 41 | 42 | mv keydirp/nistp256ecdsa.pk.bk keydirp/nistp256ecdsa.pk 43 | mv keydirp/ed25519.pk keydirp/ed25519.pk.bk 44 | 45 | echo '--- tinysshd-printkey prints only ecdsa-sha2-nistp256 key' 46 | echo 47 | ./tinysshd-printkey keydirp 48 | echo $? 49 | echo 50 | 51 | 52 | echo "--- tinysshd-printkey handles '-r' parameter (prints help)" 53 | echo 54 | ./tinysshd-printkey -r 2>/dev/null 55 | echo $? 56 | echo 57 | 58 | ./tinysshd-makekey -- -r 2>/dev/null || : 59 | 60 | echo "--- tinysshd-printkey prints keys from '-r' key-directory" 61 | echo 62 | ./tinysshd-printkey -- -r 1>/dev/null 63 | echo $? 64 | echo 65 | 66 | exit 0 67 | -------------------------------------------------------------------------------- /test-tinysshnoneauthd.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/janmojzis/tinyssh/5e679c9823a6e10c206356b97a2b31996d20e69a/test-tinysshnoneauthd.exp -------------------------------------------------------------------------------- /test-tinysshnoneauthd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exit 0 3 | -------------------------------------------------------------------------------- /tinysshd.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20181206 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | /* 8 | Multi-call binary wrapper 9 | */ 10 | 11 | #include 12 | #include "str.h" 13 | #include "main.h" 14 | 15 | static char *basename(char *str) { 16 | 17 | char *s; 18 | char *ret = str; 19 | 20 | for (s = str; *s; ++s) { 21 | if (*s == '/') ret = s + 1; 22 | } 23 | return ret; 24 | } 25 | 26 | static char *x; 27 | static long long xlen; 28 | 29 | int main(int argc, char **argv) { 30 | 31 | if (argc < 1) _exit(100); 32 | if (!argv[0]) _exit(100); 33 | 34 | x = basename(argv[0]); 35 | if (!x) _exit(100); 36 | xlen = str_len(x); 37 | 38 | if (str_equaln(x, xlen, "tinysshd-printkey")) { 39 | return main_tinysshd_printkey(argc, argv); 40 | } 41 | if (str_equaln(x, xlen, "tinysshd-makekey")) { 42 | return main_tinysshd_makekey(argc, argv); 43 | } 44 | if (str_equaln(x, xlen, "tinysshnoneauthd")) { 45 | return main_tinysshd(argc, argv, "tinysshnoneauthd"); 46 | } 47 | return main_tinysshd(argc, argv, "tinysshd"); 48 | } 49 | -------------------------------------------------------------------------------- /tryfeature.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # version 20241107 4 | 5 | scriptname="`basename $0`" 6 | 7 | if [ x"${CC}" = x ]; then 8 | echo "usage: env CC= ${scriptname} feature.c" 9 | echo '$CC not set' 10 | exit 1 11 | fi 12 | 13 | if [ x"$1" = x ]; then 14 | echo "usage: env CC= ${scriptname} feature.c" 15 | echo 'missing feature.c argument' 16 | exit 1 17 | fi 18 | 19 | # input 20 | tryname="$1" 21 | 22 | # output 23 | headermacro=`echo ${tryname} | sed 's/\.c//' | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'` 24 | 25 | # temporary 26 | binname="${tryname}.tmp.bin" 27 | logname="${tryname}.tmp.log" 28 | 29 | cleanup() { 30 | ex=$? 31 | rm -f "${binname}" "${logname}" 32 | exit "${ex}" 33 | } 34 | trap "cleanup" EXIT TERM INT 35 | 36 | "${CC}" ${CFLAGS} -O0 -o "${binname}" "${tryname}" ${LDFLAGS} 1>"${logname}" 2>&1 37 | if [ $? -eq 0 ]; then 38 | echo "#define ${headermacro} 1" 39 | else 40 | echo "#undef ${headermacro}" 41 | cat "${logname}" >&2 42 | fi 43 | exit 0 44 | -------------------------------------------------------------------------------- /trylibs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # version 20241109 4 | 5 | scriptname="`basename $0`" 6 | 7 | if [ x"${CC}" = x ]; then 8 | echo "usage: env CC= ${scriptname} -l -l ..." 9 | echo '$CC not set' 10 | exit 1 11 | fi 12 | 13 | if [ x"$1" = x ]; then 14 | echo "usage: env CC= ${scriptname} -l -l ..." 15 | echo 'missing -l argument' 16 | exit 1 17 | fi 18 | 19 | # temporary 20 | name="${scriptname}" 21 | tryname="${name}.tmp.C" 22 | binname="${tryname}.tmp.bin" 23 | logname="${tryname}.tmp.log" 24 | 25 | cleanup() { 26 | ex=$? 27 | rm -f "${binname}" "${tryname}" "${logname}" 28 | exit "${ex}" 29 | } 30 | trap "cleanup" EXIT TERM INT 31 | 32 | cat < "${tryname}" 33 | int main(int argc, char **argv) { 34 | (void) argc; 35 | (void) argv; 36 | return 0; 37 | } 38 | EOF 39 | 40 | while true; do 41 | [ x"$1" = x ] && break 42 | "${CC}" -O0 -o "${binname}" "${tryname}" "$1" 1>"${logname}" 2>&1 43 | if [ $? -eq 0 ]; then 44 | echo "${scriptname}: '$1' detected" >&2 45 | echo "$1" 46 | else 47 | echo "${scriptname}: '$1' not detected" >&2 48 | cat "${logname}" >&2 49 | fi 50 | shift 51 | done 52 | exit 0 53 | -------------------------------------------------------------------------------- /trymlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | 20120923 3 | Jan Mojzis 4 | Public domain. 5 | */ 6 | 7 | #include "hasmlock.h" 8 | #ifdef HASMLOCK 9 | #include 10 | #endif 11 | #include "trymlock.h" 12 | 13 | /* 14 | The 'trymlock' function tries to 15 | lock the memory to make it unswappable. 16 | */ 17 | void trymlock(void *x, long long len) { 18 | #ifdef HASMLOCK 19 | mlock(x, len); 20 | #else 21 | (void) x; 22 | (void) len; 23 | #endif 24 | } 25 | 26 | /* 27 | The 'trymunlock' function tries to 28 | unlock the memory. 29 | */ 30 | void trymunlock(void *x, long long len) { 31 | #ifdef HASMLOCK 32 | munlock(x, len); 33 | #else 34 | (void) x; 35 | (void) len; 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /trymlock.h: -------------------------------------------------------------------------------- 1 | #ifndef TRYMLOCK_H____ 2 | #define TRYMLOCK_H____ 3 | 4 | extern void trymlock(void *, long long); 5 | extern void trymunlock(void *, long long); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /uint16_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/uint16_optblocker.c -------------------------------------------------------------------------------- /uint32_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/uint32_optblocker.c -------------------------------------------------------------------------------- /uint64_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/uint64_optblocker.c -------------------------------------------------------------------------------- /uint8_optblocker.c: -------------------------------------------------------------------------------- 1 | cryptoint/uint8_optblocker.c -------------------------------------------------------------------------------- /writeall.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "e.h" 4 | #include "writeall.h" 5 | 6 | int writeall(int fd, const void *xv, long long xlen) { 7 | 8 | const unsigned char *x = xv; 9 | long long w; 10 | while (xlen > 0) { 11 | w = xlen; 12 | if (w > 1048576) w = 1048576; 13 | w = write(fd, x, (unsigned long long) w); 14 | if (w < 0) { 15 | if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK) { 16 | struct pollfd p; 17 | p.fd = fd; 18 | p.events = POLLOUT | POLLERR; 19 | poll(&p, 1, -1); 20 | continue; 21 | } 22 | return -1; 23 | } 24 | x += w; 25 | xlen -= w; 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /writeall.h: -------------------------------------------------------------------------------- 1 | #ifndef WRITEALL_H____ 2 | #define WRITEALL_H____ 3 | 4 | extern int writeall(int, const void *, long long); 5 | 6 | #endif 7 | --------------------------------------------------------------------------------