pax_global_header 0000666 0000000 0000000 00000000064 14747360755 0014534 g ustar 00root root 0000000 0000000 52 comment=372ce83253588dd1d87da85feb8bf1200061bd16
tinyssh-20250201/ 0000775 0000000 0000000 00000000000 14747360755 0013472 5 ustar 00root root 0000000 0000000 tinyssh-20250201/.clang-format 0000664 0000000 0000000 00000011032 14747360755 0016042 0 ustar 00root root 0000000 0000000 # 20211227
# based on LLVM
# AllowShortBlocksOnASingleLine: Always
# AllowShortLoopsOnASingleLine: true
# AllowShortIfStatementsOnASingleLine: WithoutElse
# IndentWidth: 4
# TabWidth: 4
# SortIncludes: false
# BreakBeforeBraces: Custom
# BeforeElse: true
# ColumnLimit: 80
# SpaceAfterCStyleCast: true
# IndentCaseLabels: true
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveBitFields: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortEnumsOnASingleLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: true
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
- Regex: '.*'
Priority: 1
SortPriority: 0
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: true
IndentCaseBlocks: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentExternBlock: AfterExternBlock
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
# XXX - should be false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Never
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
...
tinyssh-20250201/.gitignore 0000664 0000000 0000000 00000000007 14747360755 0015457 0 ustar 00root root 0000000 0000000 /build
tinyssh-20250201/CHANGELOG.md 0000664 0000000 0000000 00000004253 14747360755 0015307 0 ustar 00root root 0000000 0000000 ### 20250201
- Relicensed under CC0-1.0 OR 0BSD OR MIT-0 OR MIT
- Final reformatting using clang-format
### 20250126 (pre-relase)
- Fixed more compiler warnings
- More used cryptoint
### 20241201 (pre-relase)
- Switched to [cryptoint](https://libntruprime.cr.yp.to/libntruprime-20241021/cryptoint.html) 20241003
- Switched to tests from [SUPERCOP](https://bench.cr.yp.to/supercop.html) for crypto primitives
- Fixed various compiler warnings
### 20241111 (pre-relase)
- Fixed implicit-function-declaration warning packet_put.c (tnx @lanodan)
- Modification of the build system to a simple Makefile (old build system still in directory 'old')
- Added support for external librandombytes, lib25519, libntruprime library
- Dropped support for other NaCl-compatible external libraries
- Temporary disabled unit tests.
### 20240101
- fixed channel_forkpty() race condition between close(slave) in parent process and login_tty(slave) in child process
- fixed behavior when using terminal mode and stdin redirected to /dev/null 'ssh -tt -n'
- added an 'strict-key' key exchange kex-strict-s-v00@openssh.com (Mitigates CVE-2023-48795 "Terrapin attack")
### 20230101
- LICENCE update from public-domain to CC0, public domain works differently depending on the country, to avoid it, set explicitly CC0
- fixed sysdep tests, tnx Johannes Nixdorf
### 20220801
- tinyssh/getln.c don't close fd in case of error
- use null fields in utmpx calls for logout
- do not reverse the argument order in LIBS
- fill utmp(x)'s ut_addr_v6 field when it exists
- updated crypto/crypto_onetimeauth_poly1305.c
### 20220311
- fixed build on big-endian platforms
### 20220305 (workaround release)
- use PACKET_LIMIT/2 as incoming maximum packet size, it's workaround for packets with miscalculated packet_length
### 20220222
- add tinysshnoneauthd
### 20220101
- add tinysshnoneauthd
- fixed return error message when second channel is requested
- man/tinysshd-{make,print}key.1 -> man/tinysshd-{make,print}key.8
### 20210601
- add tools/tinyssh-convert
- fix log error messages
- honor "max packet size" requested from the client
### 20210319
- removed sntrup4591761x25519-sha512@tinyssh.org
- added sntrup761x25519-sha512@openssh.com
tinyssh-20250201/LICENCE.md 0000664 0000000 0000000 00000001032 14747360755 0015052 0 ustar 00root root 0000000 0000000 TinySSH is hereby placed into the public domain.
SPDX-License-Identifier: CC0-1.0 OR 0BSD OR MIT-0 OR MIT
- [CC0-1.0](https://spdx.org/licenses/CC0-1.0.html)
- [0BSD](https://spdx.org/licenses/0BSD.html)
- [MIT-0](https://spdx.org/licenses/MIT-0.html)
- [MIT](https://spdx.org/licenses/MIT.html)
Comment:
"Public domain" works differently depending on the country, therefore LICENCE updated to CC0-1.0 OR 0BSD OR MIT-0 OR MIT.
History:
- initial release - public domain
- 20230101 - CC0
- 20250201 - CC0-1.0 OR 0BSD OR MIT-0 OR MIT.
tinyssh-20250201/Makefile 0000664 0000000 0000000 00000144200 14747360755 0015133 0 ustar 00root root 0000000 0000000 CC?=cc
CFLAGS+=-W -Wall -Os -fPIC -fwrapv -Werror=deprecated-declarations -Icryptoint
LDFLAGS?=
CPPFLAGS?=
DESTDIR?=
PREFIX?=/usr/local
INSTALL?=install
LINKS=tinysshd-makekey tinysshd-printkey tinysshnoneauthd
BINARIES=tinysshd _tinysshd-printkex _tinysshd-speed _tinysshd-test-hello1 \
_tinysshd-test-hello2 _tinysshd-test-kex1 _tinysshd-test-kex2 \
_tinysshd-unauthenticated
TESTCRYPTOBINARIES=test-crypto
OBJLIB=blocking.o buf.o byte.o channel.o channel_drop.o channel_fork.o \
channel_forkpty.o channel_subsystem.o cleanup.o coe.o connectioninfo.o \
crypto_dh_x25519.o crypto_hash_sha256.o crypto_hash_sha512_lib25519.o \
crypto_hash_sha512_tinyssh.o crypto_kem_sntrup761_libntruprime.o \
crypto_kem_sntrup761_tinyssh.o crypto_kem_sntrup761x25519.o \
crypto_onetimeauth_poly1305.o crypto_scalarmult_curve25519.o \
crypto_sign_ed25519_lib25519.o crypto_sign_ed25519_tinyssh.o \
crypto_sort_uint32.o crypto_stream_chacha20.o crypto_verify_16.o \
crypto_verify_32.o die.o dropuidgid.o e.o env.o fe25519.o fe.o ge25519.o \
getln.o global.o int16_optblocker.o int32_optblocker.o int64_optblocker.o \
int8_optblocker.o iptostr.o load.o log.o loginshell.o logsys.o main_tinysshd.o \
main_tinysshd_makekey.o main_tinysshd_printkey.o newenv.o numtostr.o open.o \
packet_auth.o packet.o packet_channel_open.o packet_channel_recv.o \
packet_channel_request.o packet_channel_send.o packet_get.o packet_hello.o \
packet_kex.o packet_kexdh.o packetparser.o packet_put.o packet_recv.o \
packet_send.o packet_unimplemented.o porttostr.o randommod.o readall.o \
savesync.o sc25519.o ssh.o sshcrypto.o sshcrypto_cipher.o \
sshcrypto_cipher_chachapoly.o sshcrypto_kex.o sshcrypto_kex_curve25519.o \
sshcrypto_kex_sntrup761x25519.o sshcrypto_key.o sshcrypto_key_ed25519.o str.o \
stringparser.o subprocess_auth.o subprocess_sign.o trymlock.o \
uint16_optblocker.o uint32_optblocker.o uint64_optblocker.o uint8_optblocker.o \
writeall.o
OBJALL=blocking.o buf.o byte.o channel.o channel_drop.o channel_fork.o \
channel_forkpty.o channel_subsystem.o cleanup.o coe.o connectioninfo.o \
crypto_dh_x25519.o crypto_hash_sha256.o crypto_hash_sha512_lib25519.o \
crypto_hash_sha512_tinyssh.o crypto_kem_sntrup761_libntruprime.o \
crypto_kem_sntrup761_tinyssh.o crypto_kem_sntrup761x25519.o \
crypto_onetimeauth_poly1305.o crypto_scalarmult_curve25519.o \
crypto_sign_ed25519_lib25519.o crypto_sign_ed25519_tinyssh.o \
crypto_sort_uint32.o crypto_stream_chacha20.o crypto_verify_16.o \
crypto_verify_32.o die.o dropuidgid.o e.o env.o fe25519.o fe.o ge25519.o \
getln.o global.o int16_optblocker.o int32_optblocker.o int64_optblocker.o \
int8_optblocker.o iptostr.o load.o log.o loginshell.o logsys.o main_tinysshd.o \
main_tinysshd_makekey.o main_tinysshd_printkey.o newenv.o numtostr.o open.o \
packet_auth.o packet.o packet_channel_open.o packet_channel_recv.o \
packet_channel_request.o packet_channel_send.o packet_get.o packet_hello.o \
packet_kex.o packet_kexdh.o packetparser.o packet_put.o packet_recv.o \
packet_send.o packet_unimplemented.o porttostr.o randombytes.o randommod.o \
readall.o savesync.o sc25519.o ssh.o sshcrypto.o sshcrypto_cipher.o \
sshcrypto_cipher_chachapoly.o sshcrypto_kex.o sshcrypto_kex_curve25519.o \
sshcrypto_kex_sntrup761x25519.o sshcrypto_key.o sshcrypto_key_ed25519.o str.o \
stringparser.o subprocess_auth.o subprocess_sign.o test-crypto.o tinysshd.o \
_tinysshd-printkex.o _tinysshd-speed.o _tinysshd-test-hello1.o \
_tinysshd-test-hello2.o _tinysshd-test-kex1.o _tinysshd-test-kex2.o \
_tinysshd-unauthenticated.o trymlock.o uint16_optblocker.o uint32_optblocker.o \
uint64_optblocker.o uint8_optblocker.o writeall.o
AUTOHEADERS=haslib25519.h haslibntruprime.h haslibrandombytes.h haslibutilh.h \
haslimits.h haslogintty.h hasmlock.h hasopenpty.h hasutilh.h hasutmpaddrv6.h \
hasutmp.h hasutmphost.h hasutmploginlogout.h hasutmplogwtmp.h hasutmpname.h \
hasutmppid.h hasutmptime.h hasutmptv.h hasutmptype.h hasutmpuser.h \
hasutmpxaddrv6.h hasutmpx.h hasutmpxsyslen.h hasutmpxupdwtmpx.h hasvalgrind.h
TESTOUT=test-crypto-dh.out test-crypto-hash.out test-crypto-kem.out \
test-crypto-sign.out test-crypto-sort.out test-crypto-verify.out \
test-tinysshd-makekey.out test-tinysshd-printkey.out test-tinysshd.out \
test-tinysshnoneauthd.out
all: $(AUTOHEADERS) $(BINARIES) $(LINKS)
blocking.o: blocking.c blocking.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c blocking.c
buf.o: buf.c byte.h str.h purge.h cleanup.h randombytes.h \
haslibrandombytes.h cryptoint/crypto_uint32.h bug.h global.h e.h log.h \
buf.h cryptoint/crypto_uint8.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c buf.c
byte.o: byte.c cryptoint/crypto_int16.h byte.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c byte.c
channel.o: channel.c byte.h bug.h global.h e.h log.h newenv.h purge.h \
cleanup.h connectioninfo.h iptostr.h porttostr.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h str.h logsys.h \
loginshell.h trymlock.h limit.h haslimits.h channel.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c channel.c
channel_drop.o: channel_drop.c dropuidgid.h newenv.h channel.h \
cryptoint/crypto_uint32.h iptostr.h porttostr.h limit.h haslimits.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c channel_drop.c
channel_fork.o: channel_fork.c blocking.h open.h channel.h \
cryptoint/crypto_uint32.h iptostr.h porttostr.h limit.h haslimits.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c channel_fork.c
channel_forkpty.o: channel_forkpty.c hasopenpty.h haslogintty.h e.h coe.h \
blocking.h global.h channel.h cryptoint/crypto_uint32.h iptostr.h \
porttostr.h limit.h haslimits.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c channel_forkpty.c
channel_subsystem.o: channel_subsystem.c str.h log.h e.h channel.h \
cryptoint/crypto_uint32.h iptostr.h porttostr.h limit.h haslimits.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c channel_subsystem.c
cleanup.o: cleanup.c cleanup.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c cleanup.c
coe.o: coe.c coe.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c coe.c
connectioninfo.o: connectioninfo.c e.h byte.h iptostr.h porttostr.h env.h \
str.h connectioninfo.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c connectioninfo.c
crypto_dh_x25519.o: crypto_dh_x25519.c crypto_dh_x25519.h haslib25519.h \
randombytes.h haslibrandombytes.h crypto_scalarmult_curve25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_dh_x25519.c
crypto_hash_sha256.o: crypto_hash_sha256.c cryptoint/crypto_uint32.h \
cryptoint/crypto_uint64.h crypto_hash_sha256.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_hash_sha256.c
crypto_hash_sha512_lib25519.o: crypto_hash_sha512_lib25519.c \
haslib25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_hash_sha512_lib25519.c
crypto_hash_sha512_tinyssh.o: crypto_hash_sha512_tinyssh.c \
crypto_hash_sha512.h haslib25519.h cryptoint/crypto_uint64.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_hash_sha512_tinyssh.c
crypto_kem_sntrup761_libntruprime.o: crypto_kem_sntrup761_libntruprime.c \
haslibntruprime.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_kem_sntrup761_libntruprime.c
crypto_kem_sntrup761_tinyssh.o: crypto_kem_sntrup761_tinyssh.c \
crypto_kem_sntrup761.h haslibntruprime.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int16.h \
cryptoint/crypto_int8.h randombytes.h haslibrandombytes.h \
crypto_verify_32.h crypto_sort_uint32.h crypto_hash_sha512.h \
haslib25519.h crypto_declassify.h hasvalgrind.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_kem_sntrup761_tinyssh.c
crypto_kem_sntrup761x25519.o: crypto_kem_sntrup761x25519.c cleanup.h \
crypto_hash_sha512.h haslib25519.h crypto_dh_x25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_kem_sntrup761x25519.c
crypto_onetimeauth_poly1305.o: crypto_onetimeauth_poly1305.c \
cryptoint/crypto_int16.h cryptoint/crypto_uint32.h \
cryptoint/crypto_uint64.h crypto_onetimeauth_poly1305.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_onetimeauth_poly1305.c
crypto_scalarmult_curve25519.o: crypto_scalarmult_curve25519.c cleanup.h \
fe25519.h fe.h cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint8.h crypto_scalarmult_curve25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_scalarmult_curve25519.c
crypto_sign_ed25519_lib25519.o: crypto_sign_ed25519_lib25519.c \
haslib25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_sign_ed25519_lib25519.c
crypto_sign_ed25519_tinyssh.o: crypto_sign_ed25519_tinyssh.c \
crypto_sign_ed25519.h haslib25519.h randombytes.h haslibrandombytes.h \
cleanup.h crypto_hash_sha512.h crypto_verify_32.h ge25519.h fe.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h sc25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_sign_ed25519_tinyssh.c
crypto_sort_uint32.o: crypto_sort_uint32.c cryptoint/crypto_uint32.h \
crypto_sort_uint32.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_sort_uint32.c
crypto_stream_chacha20.o: crypto_stream_chacha20.c \
crypto_stream_chacha20.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_stream_chacha20.c
crypto_verify_16.o: crypto_verify_16.c cryptoint/crypto_int16.h \
crypto_verify_16.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_verify_16.c
crypto_verify_32.o: crypto_verify_32.c cryptoint/crypto_int16.h \
crypto_verify_32.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c crypto_verify_32.c
die.o: die.c global.h log.h die.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c die.c
dropuidgid.o: dropuidgid.c e.h dropuidgid.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c dropuidgid.c
e.o: e.c e.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c e.c
env.o: env.c str.h env.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c env.c
fe25519.o: fe25519.c crypto_verify_32.h cleanup.h fe.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h fe25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c fe25519.c
fe.o: fe.c fe.h cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c fe.c
ge25519.o: ge25519.c fe25519.h fe.h cryptoint/crypto_uint32.h \
cryptoint/crypto_uint64.h cleanup.h ge25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c ge25519.c
getln.o: getln.c e.h getln.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c getln.c
global.o: global.c newenv.h channel.h cryptoint/crypto_uint32.h iptostr.h \
porttostr.h limit.h haslimits.h packet.h buf.h cryptoint/crypto_uint8.h \
sshcrypto.h crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h purge.h cleanup.h trymlock.h global.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c global.c
int16_optblocker.o: int16_optblocker.c cryptoint/crypto_int16.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c int16_optblocker.c
int32_optblocker.o: int32_optblocker.c cryptoint/crypto_int32.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c int32_optblocker.c
int64_optblocker.o: int64_optblocker.c cryptoint/crypto_int64.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c int64_optblocker.c
int8_optblocker.o: int8_optblocker.c cryptoint/crypto_int8.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c int8_optblocker.c
iptostr.o: iptostr.c byte.h iptostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c iptostr.c
load.o: load.c readall.h open.h e.h load.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c load.c
log.o: log.c writeall.h randommod.h purge.h cleanup.h numtostr.h e.h \
log.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c log.c
loginshell.o: loginshell.c e.h loginshell.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c loginshell.c
logsys.o: logsys.c hasutilh.h hasutmpx.h hasutmpxupdwtmpx.h \
hasutmpxsyslen.h hasutmpxaddrv6.h hasutmp.h hasutmpname.h hasutmppid.h \
hasutmptime.h hasutmptv.h hasutmptype.h hasutmphost.h hasutmpuser.h \
hasutmplogwtmp.h hasutmploginlogout.h hasutmpaddrv6.h str.h byte.h \
logsys.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c logsys.c
main_tinysshd.o: main_tinysshd.c blocking.h ssh.h purge.h cleanup.h \
open.h load.h e.h byte.h buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h packet.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h log.h subprocess.h global.h connectioninfo.h die.h str.h \
main.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c main_tinysshd.c
main_tinysshd_makekey.o: main_tinysshd_makekey.c savesync.h log.h \
sshcrypto.h buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h \
crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h global.h die.h main.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c main_tinysshd_makekey.c
main_tinysshd_printkey.o: main_tinysshd_printkey.c e.h load.h sshcrypto.h \
buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h global.h log.h writeall.h die.h main.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c main_tinysshd_printkey.c
newenv.o: newenv.c e.h byte.h str.h purge.h cleanup.h bug.h global.h \
log.h env.h trymlock.h newenv.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c newenv.c
numtostr.o: numtostr.c numtostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c numtostr.c
open.o: open.c blocking.h open.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c open.c
packet_auth.o: packet_auth.c buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h ssh.h e.h str.h packetparser.h subprocess.h \
sshcrypto.h crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h bug.h global.h log.h purge.h cleanup.h packet.h \
limit.h haslimits.h channel.h iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_auth.c
packet.o: packet.c purge.h cleanup.h trymlock.h packet.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet.c
packet_channel_open.o: packet_channel_open.c buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h ssh.h e.h bug.h \
global.h log.h packetparser.h str.h packet.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_channel_open.c
packet_channel_recv.o: packet_channel_recv.c bug.h global.h e.h log.h \
buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h channel.h \
iptostr.h porttostr.h limit.h haslimits.h ssh.h packetparser.h packet.h \
sshcrypto.h crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_channel_recv.c
packet_channel_request.o: packet_channel_request.c buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h ssh.h e.h bug.h \
global.h log.h str.h packetparser.h packet.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_channel_request.c
packet_channel_send.o: packet_channel_send.c bug.h global.h e.h log.h \
buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h channel.h \
iptostr.h porttostr.h limit.h haslimits.h ssh.h packet.h sshcrypto.h \
crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_channel_send.c
packet_get.o: packet_get.c byte.h e.h bug.h global.h log.h \
cryptoint/crypto_uint32.h purge.h cleanup.h ssh.h sshcrypto.h buf.h \
cryptoint/crypto_uint8.h crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint64.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h numtostr.h packet.h limit.h haslimits.h \
channel.h iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_get.c
packet_hello.o: packet_hello.c buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h byte.h writeall.h purge.h cleanup.h log.h \
str.h getln.h e.h packet.h sshcrypto.h crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint64.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_hello.c
packet_kex.o: packet_kex.c buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h ssh.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h packetparser.h bug.h global.h e.h log.h \
packet.h limit.h haslimits.h channel.h iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_kex.c
packet_kexdh.o: packet_kexdh.c buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h ssh.h e.h byte.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h packetparser.h bug.h global.h log.h purge.h \
cleanup.h subprocess.h packet.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_kexdh.c
packetparser.o: packetparser.c e.h cryptoint/crypto_uint32.h bug.h \
global.h log.h byte.h packetparser.h cryptoint/crypto_uint8.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packetparser.c
packet_put.o: packet_put.c cryptoint/crypto_uint32.h buf.h \
cryptoint/crypto_uint8.h bug.h global.h e.h log.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h ssh.h packet.h limit.h haslimits.h channel.h \
iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_put.c
packet_recv.o: packet_recv.c e.h buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h purge.h cleanup.h packet.h sshcrypto.h \
crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_recv.c
packet_send.o: packet_send.c writeall.h e.h byte.h purge.h cleanup.h \
packet.h buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h \
sshcrypto.h crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_send.c
packet_unimplemented.o: packet_unimplemented.c buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h ssh.h log.h \
numtostr.h packet.h sshcrypto.h crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint64.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c packet_unimplemented.c
porttostr.o: porttostr.c cryptoint/crypto_uint16.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c porttostr.c
randombytes.o: randombytes.c randombytes.h haslibrandombytes.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c randombytes.c
randommod.o: randommod.c randombytes.h haslibrandombytes.h randommod.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c randommod.c
readall.o: readall.c e.h readall.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c readall.c
savesync.o: savesync.c open.h savesync.h writeall.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c savesync.c
sc25519.o: sc25519.c cryptoint/crypto_int64.h cryptoint/crypto_uint32.h \
cryptoint/crypto_uint64.h cleanup.h sc25519.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sc25519.c
ssh.o: ssh.c ssh.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c ssh.c
sshcrypto.o: sshcrypto.c purge.h cleanup.h bug.h global.h e.h log.h str.h \
sshcrypto.h buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h \
crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto.c
sshcrypto_cipher.o: sshcrypto_cipher.c crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint8.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h stringparser.h e.h log.h bug.h global.h str.h \
byte.h packet.h buf.h sshcrypto.h limit.h haslimits.h channel.h \
iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_cipher.c
sshcrypto_cipher_chachapoly.o: sshcrypto_cipher_chachapoly.c \
cryptoint/crypto_uint32.h crypto_verify_16.h randommod.h e.h byte.h \
purge.h cleanup.h sshcrypto.h buf.h cryptoint/crypto_uint8.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h bug.h global.h log.h packet.h limit.h \
haslimits.h channel.h iptostr.h porttostr.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_cipher_chachapoly.c
sshcrypto_kex.o: sshcrypto_kex.c crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint8.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h stringparser.h str.h byte.h e.h log.h bug.h \
global.h sshcrypto.h buf.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_kex.c
sshcrypto_kex_curve25519.o: sshcrypto_kex_curve25519.c buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h purge.h cleanup.h sshcrypto.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_kex_curve25519.c
sshcrypto_kex_sntrup761x25519.o: sshcrypto_kex_sntrup761x25519.c buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h sshcrypto.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_kex_sntrup761x25519.c
sshcrypto_key.o: sshcrypto_key.c crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint8.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h packetparser.h stringparser.h str.h byte.h e.h \
log.h bug.h global.h purge.h cleanup.h sshcrypto.h buf.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_key.c
sshcrypto_key_ed25519.o: sshcrypto_key_ed25519.c crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint32.h \
cryptoint/crypto_uint64.h cryptoint/crypto_uint8.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h packetparser.h buf.h byte.h str.h purge.h \
cleanup.h sshcrypto.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c sshcrypto_key_ed25519.c
str.o: str.c str.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c str.c
stringparser.o: stringparser.c byte.h e.h bug.h global.h log.h \
stringparser.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c stringparser.c
subprocess_auth.o: subprocess_auth.c str.h open.h dropuidgid.h global.h \
e.h log.h sshcrypto.h buf.h cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint64.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h getln.h bug.h limit.h haslimits.h subprocess.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c subprocess_auth.c
subprocess_sign.o: subprocess_sign.c load.h log.h open.h writeall.h \
purge.h cleanup.h global.h bug.h e.h readall.h blocking.h sshcrypto.h \
buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h subprocess.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c subprocess_sign.c
test-crypto.o: test-crypto.c cryptoint/crypto_uint8.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h crypto_declassify.h \
hasvalgrind.h crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h _crypto-test_verify_16.inc \
_crypto-test_verify_32.inc _crypto-test_sort_uint32.inc \
_crypto-test_hash_sha256.inc _crypto-test_hash_sha512.inc \
_crypto-test_sign_ed25519.inc _crypto-test_kem_sntrup761.inc \
_crypto-test_dh_x25519.inc
$(CC) $(CFLAGS) $(CPPFLAGS) -c test-crypto.c
tinysshd.o: tinysshd.c str.h main.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c tinysshd.c
_tinysshd-printkex.o: _tinysshd-printkex.c log.h packet.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h ssh.h bug.h global.h e.h packetparser.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-printkex.c
_tinysshd-speed.o: _tinysshd-speed.c crypto.h cryptoint/crypto_int16.h \
cryptoint/crypto_int32.h cryptoint/crypto_int64.h \
cryptoint/crypto_int8.h cryptoint/crypto_uint16.h \
cryptoint/crypto_uint32.h cryptoint/crypto_uint64.h \
cryptoint/crypto_uint8.h crypto_verify_16.h crypto_verify_32.h \
haslibrandombytes.h randombytes.h crypto_hash_sha256.h \
crypto_hash_sha512.h haslib25519.h crypto_kem_sntrup761.h \
haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-speed.c
_tinysshd-test-hello1.o: _tinysshd-test-hello1.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-test-hello1.c
_tinysshd-test-hello2.o: _tinysshd-test-hello2.c log.h packet.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h global.h str.h writeall.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-test-hello2.c
_tinysshd-test-kex1.o: _tinysshd-test-kex1.c log.h packet.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h ssh.h bug.h global.h e.h packetparser.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-test-kex1.c
_tinysshd-test-kex2.o: _tinysshd-test-kex2.c log.h packet.h buf.h \
cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h crypto.h \
cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h ssh.h bug.h global.h e.h packetparser.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-test-kex2.c
_tinysshd-unauthenticated.o: _tinysshd-unauthenticated.c log.h packet.h \
buf.h cryptoint/crypto_uint8.h cryptoint/crypto_uint32.h sshcrypto.h \
crypto.h cryptoint/crypto_int16.h cryptoint/crypto_int32.h \
cryptoint/crypto_int64.h cryptoint/crypto_int8.h \
cryptoint/crypto_uint16.h cryptoint/crypto_uint64.h crypto_verify_16.h \
crypto_verify_32.h haslibrandombytes.h randombytes.h \
crypto_hash_sha256.h crypto_hash_sha512.h haslib25519.h \
crypto_kem_sntrup761.h haslibntruprime.h crypto_kem_sntrup761x25519.h \
crypto_onetimeauth_poly1305.h crypto_scalarmult_curve25519.h \
crypto_dh_x25519.h crypto_sign_ed25519.h crypto_sort_uint32.h \
crypto_stream_chacha20.h limit.h haslimits.h channel.h iptostr.h \
porttostr.h ssh.h bug.h global.h e.h packetparser.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c _tinysshd-unauthenticated.c
trymlock.o: trymlock.c hasmlock.h trymlock.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c trymlock.c
uint16_optblocker.o: uint16_optblocker.c cryptoint/crypto_uint16.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c uint16_optblocker.c
uint32_optblocker.o: uint32_optblocker.c cryptoint/crypto_uint32.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c uint32_optblocker.c
uint64_optblocker.o: uint64_optblocker.c cryptoint/crypto_uint64.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c uint64_optblocker.c
uint8_optblocker.o: uint8_optblocker.c cryptoint/crypto_uint8.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c uint8_optblocker.c
writeall.o: writeall.c e.h writeall.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c writeall.c
tinysshd: tinysshd.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o tinysshd tinysshd.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-printkex: _tinysshd-printkex.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-printkex _tinysshd-printkex.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-speed: _tinysshd-speed.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-speed _tinysshd-speed.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-test-hello1: _tinysshd-test-hello1.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-test-hello1 _tinysshd-test-hello1.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-test-hello2: _tinysshd-test-hello2.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-test-hello2 _tinysshd-test-hello2.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-test-kex1: _tinysshd-test-kex1.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-test-kex1 _tinysshd-test-kex1.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-test-kex2: _tinysshd-test-kex2.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-test-kex2 _tinysshd-test-kex2.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
_tinysshd-unauthenticated: _tinysshd-unauthenticated.o $(OBJLIB) randombytes.o libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o _tinysshd-unauthenticated _tinysshd-unauthenticated.o \
$(OBJLIB) $(LDFLAGS) `cat libs` randombytes.o
test-crypto: test-crypto.o $(OBJLIB) libs
$(CC) $(CFLAGS) $(CPPFLAGS) -o test-crypto test-crypto.o \
$(OBJLIB) $(LDFLAGS) `cat libs`
haslib25519.h: tryfeature.sh haslib25519.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslib25519.c >haslib25519.h 2>haslib25519.log
cat haslib25519.h
haslibntruprime.h: tryfeature.sh haslibntruprime.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslibntruprime.c >haslibntruprime.h 2>haslibntruprime.log
cat haslibntruprime.h
haslibrandombytes.h: tryfeature.sh haslibrandombytes.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslibrandombytes.c >haslibrandombytes.h 2>haslibrandombytes.log
cat haslibrandombytes.h
haslibutilh.h: tryfeature.sh haslibutilh.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslibutilh.c >haslibutilh.h 2>haslibutilh.log
cat haslibutilh.h
haslimits.h: tryfeature.sh haslimits.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslimits.c >haslimits.h 2>haslimits.log
cat haslimits.h
haslogintty.h: tryfeature.sh haslogintty.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh haslogintty.c >haslogintty.h 2>haslogintty.log
cat haslogintty.h
hasmlock.h: tryfeature.sh hasmlock.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasmlock.c >hasmlock.h 2>hasmlock.log
cat hasmlock.h
hasopenpty.h: tryfeature.sh hasopenpty.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasopenpty.c >hasopenpty.h 2>hasopenpty.log
cat hasopenpty.h
hasutilh.h: tryfeature.sh hasutilh.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutilh.c >hasutilh.h 2>hasutilh.log
cat hasutilh.h
hasutmpaddrv6.h: tryfeature.sh hasutmpaddrv6.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpaddrv6.c >hasutmpaddrv6.h 2>hasutmpaddrv6.log
cat hasutmpaddrv6.h
hasutmp.h: tryfeature.sh hasutmp.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmp.c >hasutmp.h 2>hasutmp.log
cat hasutmp.h
hasutmphost.h: tryfeature.sh hasutmphost.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmphost.c >hasutmphost.h 2>hasutmphost.log
cat hasutmphost.h
hasutmploginlogout.h: tryfeature.sh hasutmploginlogout.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmploginlogout.c >hasutmploginlogout.h 2>hasutmploginlogout.log
cat hasutmploginlogout.h
hasutmplogwtmp.h: tryfeature.sh hasutmplogwtmp.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmplogwtmp.c >hasutmplogwtmp.h 2>hasutmplogwtmp.log
cat hasutmplogwtmp.h
hasutmpname.h: tryfeature.sh hasutmpname.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpname.c >hasutmpname.h 2>hasutmpname.log
cat hasutmpname.h
hasutmppid.h: tryfeature.sh hasutmppid.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmppid.c >hasutmppid.h 2>hasutmppid.log
cat hasutmppid.h
hasutmptime.h: tryfeature.sh hasutmptime.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmptime.c >hasutmptime.h 2>hasutmptime.log
cat hasutmptime.h
hasutmptv.h: tryfeature.sh hasutmptv.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmptv.c >hasutmptv.h 2>hasutmptv.log
cat hasutmptv.h
hasutmptype.h: tryfeature.sh hasutmptype.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmptype.c >hasutmptype.h 2>hasutmptype.log
cat hasutmptype.h
hasutmpuser.h: tryfeature.sh hasutmpuser.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpuser.c >hasutmpuser.h 2>hasutmpuser.log
cat hasutmpuser.h
hasutmpxaddrv6.h: tryfeature.sh hasutmpxaddrv6.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpxaddrv6.c >hasutmpxaddrv6.h 2>hasutmpxaddrv6.log
cat hasutmpxaddrv6.h
hasutmpx.h: tryfeature.sh hasutmpx.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpx.c >hasutmpx.h 2>hasutmpx.log
cat hasutmpx.h
hasutmpxsyslen.h: tryfeature.sh hasutmpxsyslen.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpxsyslen.c >hasutmpxsyslen.h 2>hasutmpxsyslen.log
cat hasutmpxsyslen.h
hasutmpxupdwtmpx.h: tryfeature.sh hasutmpxupdwtmpx.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasutmpxupdwtmpx.c >hasutmpxupdwtmpx.h 2>hasutmpxupdwtmpx.log
cat hasutmpxupdwtmpx.h
hasvalgrind.h: tryfeature.sh hasvalgrind.c libs
env CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS) `cat libs`" \
./tryfeature.sh hasvalgrind.c >hasvalgrind.h 2>hasvalgrind.log
cat hasvalgrind.h
test-crypto-dh.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-dh.sh test-crypto-dh.exp
sh runtest.sh test-crypto-dh.sh test-crypto-dh.out test-crypto-dh.exp
test-crypto-hash.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-hash.sh test-crypto-hash.exp
sh runtest.sh test-crypto-hash.sh test-crypto-hash.out test-crypto-hash.exp
test-crypto-kem.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-kem.sh test-crypto-kem.exp
sh runtest.sh test-crypto-kem.sh test-crypto-kem.out test-crypto-kem.exp
test-crypto-sign.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-sign.sh test-crypto-sign.exp
sh runtest.sh test-crypto-sign.sh test-crypto-sign.out test-crypto-sign.exp
test-crypto-sort.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-sort.sh test-crypto-sort.exp
sh runtest.sh test-crypto-sort.sh test-crypto-sort.out test-crypto-sort.exp
test-crypto-verify.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-crypto-verify.sh test-crypto-verify.exp
sh runtest.sh test-crypto-verify.sh test-crypto-verify.out test-crypto-verify.exp
test-tinysshd-makekey.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-tinysshd-makekey.sh test-tinysshd-makekey.exp
sh runtest.sh test-tinysshd-makekey.sh test-tinysshd-makekey.out test-tinysshd-makekey.exp
test-tinysshd-printkey.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-tinysshd-printkey.sh test-tinysshd-printkey.exp
sh runtest.sh test-tinysshd-printkey.sh test-tinysshd-printkey.out test-tinysshd-printkey.exp
test-tinysshd.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-tinysshd.sh test-tinysshd.exp
sh runtest.sh test-tinysshd.sh test-tinysshd.out test-tinysshd.exp
test-tinysshnoneauthd.out: $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) runtest.sh test-tinysshnoneauthd.sh test-tinysshnoneauthd.exp
sh runtest.sh test-tinysshnoneauthd.sh test-tinysshnoneauthd.out test-tinysshnoneauthd.exp
test: $(TESTOUT)
libs: trylibs.sh
env CC="$(CC)" ./trylibs.sh -lsocket -lnsl -lutil -lrandombytes -l25519 -lntruprime >libs 2>libs.log
cat libs
tinysshd-makekey: tinysshd
rm -f tinysshd-makekey
ln -s tinysshd tinysshd-makekey
tinysshd-printkey: tinysshd
rm -f tinysshd-printkey
ln -s tinysshd tinysshd-printkey
tinysshnoneauthd: tinysshd
rm -f tinysshnoneauthd
ln -s tinysshd tinysshnoneauthd
install: $(BINARIES) $(LINKS)
mkdir -p $(DESTDIR)$(PREFIX)/sbin
mkdir -p $(DESTDIR)$(PREFIX)/share/man/man8
$(INSTALL) -m 0755 tinysshd $(DESTDIR)$(PREFIX)/sbin/tinysshd
$(INSTALL) -m 0755 tinysshd-makekey $(DESTDIR)$(PREFIX)/sbin/tinysshd-makekey
$(INSTALL) -m 0755 tinysshd-printkey $(DESTDIR)$(PREFIX)/sbin/tinysshd-printkey
$(INSTALL) -m 0755 tinysshnoneauthd $(DESTDIR)$(PREFIX)/sbin/tinysshnoneauthd
$(INSTALL) -m 0644 man/tinysshd.8 $(DESTDIR)$(PREFIX)/share/man/man8/tinysshd.8
$(INSTALL) -m 0644 man/tinysshd-makekey.8 $(DESTDIR)$(PREFIX)/share/man/man8/tinysshd-makekey.8
$(INSTALL) -m 0644 man/tinysshd-printkey.8 $(DESTDIR)$(PREFIX)/share/man/man8/tinysshd-printkey.8
$(INSTALL) -m 0644 man/tinysshnoneauthd.8 $(DESTDIR)$(PREFIX)/share/man/man8/tinysshnoneauthd.8
clean:
rm -f *.log libs $(OBJLIB) $(OBJALL) $(BINARIES) $(TESTCRYPTOBINARIES) $(LINKS) $(AUTOHEADERS) $(TESTOUT)
tinyssh-20250201/README.cryptoint.md 0000664 0000000 0000000 00000000517 14747360755 0017006 0 ustar 00root root 0000000 0000000 Cryptoint is a library created by Daniel J. Bernstein.
It's public-domain code used in SUPERCOP/libntruprime/libmceliece/...
To TinySSH is imported from https://libntruprime.cr.yp.to/libntruprime-20241021/cryptoint.html.
Description from the author e.g. here:
- https://cr.yp.to/talks/2024.07.22/slides-djb-20240722-snippets-4x3.pdf
tinyssh-20250201/README.md 0000664 0000000 0000000 00000005430 14747360755 0014753 0 ustar 00root root 0000000 0000000 ### Introduction ###
* tinysshd is a minimalistic SSH server which implements only a subset of SSHv2 features.
* tinysshd supports only secure cryptography (minimum 128-bit security, protected against cache-timing attacks)
* tinysshd doesn't implement older crypto (such as RSA, DSA, HMAC-MD5, HMAC-SHA1, 3DES, RC4, ...)
* tinysshd doesn't implement unsafe features (such as password or hostbased authentication)
* tinysshd doesn't have features such: SSH1 protocol, compression, port forwarding, agent forwarding, X11 forwarding ...
* tinysshd doesn't use dynamic memory allocation (no allocation failures, etc.)
### Crypto primitives ###
* State-of-the-art crypto: ssh-ed25519, curve25519-sha256, chacha20-poly1305@openssh.com
* Older standard: ecdsa-sha2-nistp256, ecdh-sha2-nistp256, aes256-ctr, hmac-sha2-256 removed in version 20190101
* Postquantum crypto: sntrup761x25519-sha512@openssh.com, chacha20-poly1305@openssh.com
### Project timelime ###
* experimental: 2014.01.01 - 2014.12.31 (experimentation)
* alpha(updated): 2015.01.01 - 2017.12.31 (not ready for production use, ready for testing)
* beta(updated): 2018.01.01 - ????.??.?? (ready for production use)
* stable: expected ????.??.?? - (ready for production use - including post-quantum crypto)
### Current release (20250201) ###
* has 74260 words of code
* beta release
### How-to compile and install ###
~~~
make
sudo make install
~~~
### How-to run ###
~~~
mkdir -p /etc/tinyssh
tinysshd-makekey /etc/tinyssh/sshkeydir
~~~
~~~
TCPSERVER
tcpserver -HRDl0 0.0.0.0 22 /usr/sbin/tinysshd -v /etc/tinyssh/sshkeydir &
BUSYBOX
busybox tcpsvd 0 22 tinysshd -v /etc/tinyssh/sshkeydir &
INETD
/etc/inetd.conf:
ssh stream tcp nowait root /usr/sbin/tinysshd tinysshd -l -v /etc/tinyssh/sshkeydir
SYSTEMD
tinysshd.socket:
[Unit]
Description=TinySSH server socket
ConditionPathExists=!/etc/tinyssh/disable_tinysshd
[Socket]
ListenStream=22
Accept=yes
[Install]
WantedBy=sockets.target
tinysshd@.service:
[Unit]
Description=Tiny SSH server
After=network.target auditd.service
[Service]
ExecStartPre=-/usr/sbin/tinysshd-makekey -q /etc/tinyssh/sshkeydir
EnvironmentFile=-/etc/default/tinysshd
ExecStart=/usr/sbin/tinysshd ${TINYSSHDOPTS} -- /etc/tinyssh/sshkeydir
KillMode=process
SuccessExitStatus=111
StandardInput=socket
StandardError=journal
[Install]
WantedBy=multi-user.target
~~~
tinyssh-20250201/_crypto-test_dh_x25519.inc 0000664 0000000 0000000 00000031557 14747360755 0020244 0 ustar 00root root 0000000 0000000 /* ----- dh/x25519, derived from supercop/crypto_dh/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto_dh_x25519.h"
#define fail ((ok = 0), printf)
static const char *dh_x25519_checksums[] = {
"2c8a73ec86d5d4c4bc838f49cfd78c87b60b534ae6fff59ce3bea0c32cdc1450",
"b09016b3a1371786b46a183085133338159e623c5eb9cbc5eaa4f8b62d6c5aea",
};
static int (*crypto_dh_keypair)(unsigned char *, unsigned char *);
static int (*crypto_dh)(unsigned char *, const unsigned char *,
const unsigned char *);
#define crypto_dh_SECRETKEYBYTES crypto_dh_x25519_SECRETKEYBYTES
#define crypto_dh_PUBLICKEYBYTES crypto_dh_x25519_PUBLICKEYBYTES
#define crypto_dh_BYTES crypto_dh_x25519_BYTES
static void *storage_dh_x25519_a;
static unsigned char *test_dh_x25519_a;
static void *storage_dh_x25519_b;
static unsigned char *test_dh_x25519_b;
static void *storage_dh_x25519_c;
static unsigned char *test_dh_x25519_c;
static void *storage_dh_x25519_d;
static unsigned char *test_dh_x25519_d;
static void *storage_dh_x25519_e;
static unsigned char *test_dh_x25519_e;
static void *storage_dh_x25519_f;
static unsigned char *test_dh_x25519_f;
static void *storage_dh_x25519_a2;
static unsigned char *test_dh_x25519_a2;
static void *storage_dh_x25519_b2;
static unsigned char *test_dh_x25519_b2;
static void *storage_dh_x25519_c2;
static unsigned char *test_dh_x25519_c2;
static void *storage_dh_x25519_d2;
static unsigned char *test_dh_x25519_d2;
static void *storage_dh_x25519_e2;
static unsigned char *test_dh_x25519_e2;
static void *storage_dh_x25519_f2;
static unsigned char *test_dh_x25519_f2;
static void test_dh_x25519_impl(long long impl) {
unsigned char *a = test_dh_x25519_a;
unsigned char *b = test_dh_x25519_b;
unsigned char *c = test_dh_x25519_c;
unsigned char *d = test_dh_x25519_d;
unsigned char *e = test_dh_x25519_e;
unsigned char *f = test_dh_x25519_f;
unsigned char *a2 = test_dh_x25519_a2;
unsigned char *b2 = test_dh_x25519_b2;
unsigned char *c2 = test_dh_x25519_c2;
unsigned char *d2 = test_dh_x25519_d2;
unsigned char *e2 = test_dh_x25519_e2;
unsigned char *f2 = test_dh_x25519_f2;
long long alen = crypto_dh_SECRETKEYBYTES;
long long blen = crypto_dh_SECRETKEYBYTES;
long long clen = crypto_dh_PUBLICKEYBYTES;
long long dlen = crypto_dh_PUBLICKEYBYTES;
long long elen = crypto_dh_BYTES;
long long flen = crypto_dh_BYTES;
if (targetn && atol(targetn) != impl) return;
crypto_dh_keypair = crypto_dh_x25519_keypair;
crypto_dh = crypto_dh_x25519;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 512 : 64;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
output_prepare(c2, c, clen);
output_prepare(a2, a, alen);
crypto_dh_keypair(c, a);
public(c, clen);
public(a, alen);
checksum(c, clen);
checksum(a, alen);
output_compare(c2, c, clen, "crypto_dh_keypair");
output_compare(a2, a, alen, "crypto_dh_keypair");
output_prepare(d2, d, dlen);
output_prepare(b2, b, blen);
crypto_dh_keypair(d, b);
public(d, dlen);
public(b, blen);
checksum(d, dlen);
checksum(b, blen);
output_compare(d2, d, dlen, "crypto_dh_keypair");
output_compare(b2, b, blen, "crypto_dh_keypair");
output_prepare(e2, e, elen);
memcpy(d2, d, dlen);
double_canary(d2, d, dlen);
memcpy(a2, a, alen);
double_canary(a2, a, alen);
secret(d, dlen);
secret(a, alen);
crypto_dh(e, d, a);
public(d, dlen);
public(a, alen);
public(e, elen);
checksum(e, elen);
output_compare(e2, e, elen, "crypto_dh");
input_compare(d2, d, dlen, "crypto_dh");
input_compare(a2, a, alen, "crypto_dh");
double_canary(e2, e, elen);
double_canary(d2, d, dlen);
double_canary(a2, a, alen);
secret(d2, dlen);
secret(a2, alen);
crypto_dh(e2, d2, a2);
public(d2, dlen);
public(a2, alen);
public(e2, elen);
if (memcmp(e2, e, elen) != 0)
fail("failure: crypto_dh is nondeterministic\n");
double_canary(e2, e, elen);
double_canary(d2, d, dlen);
double_canary(a2, a, alen);
secret(d2, dlen);
secret(a, alen);
crypto_dh(d2, d2, a);
public(d2, elen);
public(a, alen);
if (memcmp(d2, e, elen) != 0)
fail("failure: crypto_dh does not handle d=e overlap\n");
memcpy(d2, d, dlen);
secret(d, dlen);
secret(a2, alen);
crypto_dh(a2, d, a2);
public(a2, elen);
public(d, dlen);
if (memcmp(a2, e, elen) != 0)
fail("failure: crypto_dh does not handle a=e overlap\n");
memcpy(a2, a, alen);
output_prepare(f2, f, flen);
memcpy(c2, c, clen);
double_canary(c2, c, clen);
memcpy(b2, b, blen);
double_canary(b2, b, blen);
secret(c, clen);
secret(b, blen);
crypto_dh(f, c, b);
public(c, clen);
public(b, blen);
public(f, flen);
checksum(f, flen);
output_compare(f2, f, flen, "crypto_dh");
input_compare(c2, c, clen, "crypto_dh");
input_compare(b2, b, blen, "crypto_dh");
double_canary(f2, f, flen);
double_canary(c2, c, clen);
double_canary(b2, b, blen);
secret(c2, clen);
secret(b2, blen);
crypto_dh(f2, c2, b2);
public(c2, clen);
public(b2, blen);
public(f2, flen);
if (memcmp(f2, f, flen) != 0)
fail("failure: crypto_dh is nondeterministic\n");
double_canary(f2, f, flen);
double_canary(c2, c, clen);
double_canary(b2, b, blen);
secret(c2, clen);
secret(b, blen);
crypto_dh(c2, c2, b);
public(c2, flen);
public(b, blen);
if (memcmp(c2, f, flen) != 0)
fail("failure: crypto_dh does not handle c=f overlap\n");
memcpy(c2, c, clen);
secret(c, clen);
secret(b2, blen);
crypto_dh(b2, c, b2);
public(b2, flen);
public(c, clen);
if (memcmp(b2, f, flen) != 0)
fail("failure: crypto_dh does not handle b=f overlap\n");
memcpy(b2, b, blen);
if (memcmp(f, e, elen) != 0)
fail("failure: crypto_dh not associative\n");
}
checksum_expected(dh_x25519_checksums[checksumbig]);
}
}
void test_dh_x25519(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "dh")) return;
if (targetp && strcmp(targetp, "x25519")) return;
storage_dh_x25519_a = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_a = aligned(storage_dh_x25519_a,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_b = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_b = aligned(storage_dh_x25519_b,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_c = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_c = aligned(storage_dh_x25519_c,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_d = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_d = aligned(storage_dh_x25519_d,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_e = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_e = aligned(storage_dh_x25519_e,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_f = callocplus(
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES);
test_dh_x25519_f = aligned(storage_dh_x25519_f,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
if (crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES + crypto_dh_SECRETKEYBYTES >
maxalloc)
maxalloc = crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES;
storage_dh_x25519_a2 = callocplus(maxalloc);
test_dh_x25519_a2 = aligned(storage_dh_x25519_a2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
storage_dh_x25519_b2 = callocplus(maxalloc);
test_dh_x25519_b2 = aligned(storage_dh_x25519_b2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
storage_dh_x25519_c2 = callocplus(maxalloc);
test_dh_x25519_c2 = aligned(storage_dh_x25519_c2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
storage_dh_x25519_d2 = callocplus(maxalloc);
test_dh_x25519_d2 = aligned(storage_dh_x25519_d2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
storage_dh_x25519_e2 = callocplus(maxalloc);
test_dh_x25519_e2 = aligned(storage_dh_x25519_e2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
storage_dh_x25519_f2 = callocplus(maxalloc);
test_dh_x25519_f2 = aligned(storage_dh_x25519_f2,
crypto_dh_BYTES + crypto_dh_PUBLICKEYBYTES +
crypto_dh_SECRETKEYBYTES);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("dh_x25519 offset %lld\n", offset);
forked(test_dh_x25519_impl, -1);
++test_dh_x25519_a;
++test_dh_x25519_b;
++test_dh_x25519_c;
++test_dh_x25519_d;
++test_dh_x25519_e;
++test_dh_x25519_f;
++test_dh_x25519_a2;
++test_dh_x25519_b2;
++test_dh_x25519_c2;
++test_dh_x25519_d2;
++test_dh_x25519_e2;
++test_dh_x25519_f2;
}
free(storage_dh_x25519_f2);
free(storage_dh_x25519_e2);
free(storage_dh_x25519_d2);
free(storage_dh_x25519_c2);
free(storage_dh_x25519_b2);
free(storage_dh_x25519_a2);
free(storage_dh_x25519_f);
free(storage_dh_x25519_e);
free(storage_dh_x25519_d);
free(storage_dh_x25519_c);
free(storage_dh_x25519_b);
free(storage_dh_x25519_a);
}
#undef crypto_dh_SECRETKEYBYTES
#undef crypto_dh_PUBLICKEYBYTES
#undef crypto_dh_BYTES
tinyssh-20250201/_crypto-test_hash_sha256.inc 0000664 0000000 0000000 00000010404 14747360755 0020713 0 ustar 00root root 0000000 0000000 /* ----- hash/sha256, derived from supercop/crypto_hash/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
#define fail ((ok = 0), printf)
static const char *hash_sha256_checksums[] = {
"0fb5122d471d9310c4ff212c64a73cc985f0826484c24f34b56cb1d39534ba24",
"55ff5e29282c4d7d192a20b427c000ec121fcda33dd96d53aa8857e3f2dd1469",
};
static int (*crypto_hash)(unsigned char *, const unsigned char *,
unsigned long long);
#define crypto_hash_BYTES crypto_hash_sha256_BYTES
static void *storage_hash_sha256_h;
static unsigned char *test_hash_sha256_h;
static void *storage_hash_sha256_m;
static unsigned char *test_hash_sha256_m;
static void *storage_hash_sha256_h2;
static unsigned char *test_hash_sha256_h2;
static void *storage_hash_sha256_m2;
static unsigned char *test_hash_sha256_m2;
static void test_hash_sha256_impl(long long impl) {
unsigned char *h = test_hash_sha256_h;
unsigned char *m = test_hash_sha256_m;
unsigned char *h2 = test_hash_sha256_h2;
unsigned char *m2 = test_hash_sha256_m2;
long long hlen = crypto_hash_BYTES;
long long mlen;
if (targetn && atol(targetn) != impl) return;
crypto_hash = crypto_hash_sha256;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 512 : 64;
long long maxtest = checksumbig ? 4096 : 128;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
mlen = myrandom() % (maxtest + 1);
output_prepare(h2, h, hlen);
input_prepare(m2, m, mlen);
secret(m, mlen);
crypto_hash(h, m, mlen);
public(m, mlen);
public(h, hlen);
checksum(h, hlen);
output_compare(h2, h, hlen, "crypto_hash");
input_compare(m2, m, mlen, "crypto_hash");
double_canary(h2, h, hlen);
double_canary(m2, m, mlen);
secret(m2, mlen);
crypto_hash(h2, m2, mlen);
public(m2, mlen);
public(h2, hlen);
if (memcmp(h2, h, hlen) != 0)
fail("failure: crypto_hash is nondeterministic\n");
double_canary(h2, h, hlen);
double_canary(m2, m, mlen);
secret(m2, mlen);
crypto_hash(m2, m2, mlen);
public(m2, hlen);
if (memcmp(m2, h, hlen) != 0)
fail("failure: crypto_hash does not handle m=h overlap\n");
memcpy(m2, m, mlen);
}
checksum_expected(hash_sha256_checksums[checksumbig]);
}
}
void test_hash_sha256(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "hash")) return;
if (targetp && strcmp(targetp, "sha256")) return;
storage_hash_sha256_h = callocplus(crypto_hash_BYTES);
test_hash_sha256_h = aligned(storage_hash_sha256_h, crypto_hash_BYTES);
if (crypto_hash_BYTES > maxalloc) maxalloc = crypto_hash_BYTES;
storage_hash_sha256_m = callocplus(4096 + crypto_hash_BYTES);
test_hash_sha256_m =
aligned(storage_hash_sha256_m, 4096 + crypto_hash_BYTES);
if (4096 + crypto_hash_BYTES > maxalloc)
maxalloc = 4096 + crypto_hash_BYTES;
storage_hash_sha256_h2 = callocplus(maxalloc);
test_hash_sha256_h2 = aligned(storage_hash_sha256_h2, crypto_hash_BYTES);
storage_hash_sha256_m2 = callocplus(maxalloc);
test_hash_sha256_m2 =
aligned(storage_hash_sha256_m2, 4096 + crypto_hash_BYTES);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("hash_sha256 offset %lld\n", offset);
forked(test_hash_sha256_impl, -1);
++test_hash_sha256_h;
++test_hash_sha256_m;
++test_hash_sha256_h2;
++test_hash_sha256_m2;
}
free(storage_hash_sha256_m2);
free(storage_hash_sha256_h2);
free(storage_hash_sha256_m);
free(storage_hash_sha256_h);
}
#undef crypto_hash_BYTES
tinyssh-20250201/_crypto-test_hash_sha512.inc 0000664 0000000 0000000 00000010404 14747360755 0020706 0 ustar 00root root 0000000 0000000 /* ----- hash/sha512, derived from supercop/crypto_hash/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
#define fail ((ok = 0), printf)
static const char *hash_sha512_checksums[] = {
"8220572f58bd4730be165c9739d8d4b0fd2e0229dbe01e25b4aed23f00f23b70",
"c1e322b7cbfc941260c5508967ba05bce22eeee94d425e708b7c3301ea1d5e2e",
};
static int (*crypto_hash)(unsigned char *, const unsigned char *,
unsigned long long);
#define crypto_hash_BYTES crypto_hash_sha512_BYTES
static void *storage_hash_sha512_h;
static unsigned char *test_hash_sha512_h;
static void *storage_hash_sha512_m;
static unsigned char *test_hash_sha512_m;
static void *storage_hash_sha512_h2;
static unsigned char *test_hash_sha512_h2;
static void *storage_hash_sha512_m2;
static unsigned char *test_hash_sha512_m2;
static void test_hash_sha512_impl(long long impl) {
unsigned char *h = test_hash_sha512_h;
unsigned char *m = test_hash_sha512_m;
unsigned char *h2 = test_hash_sha512_h2;
unsigned char *m2 = test_hash_sha512_m2;
long long hlen = crypto_hash_BYTES;
long long mlen;
if (targetn && atol(targetn) != impl) return;
crypto_hash = crypto_hash_sha512;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 512 : 64;
long long maxtest = checksumbig ? 4096 : 128;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
mlen = myrandom() % (maxtest + 1);
output_prepare(h2, h, hlen);
input_prepare(m2, m, mlen);
secret(m, mlen);
crypto_hash(h, m, mlen);
public(m, mlen);
public(h, hlen);
checksum(h, hlen);
output_compare(h2, h, hlen, "crypto_hash");
input_compare(m2, m, mlen, "crypto_hash");
double_canary(h2, h, hlen);
double_canary(m2, m, mlen);
secret(m2, mlen);
crypto_hash(h2, m2, mlen);
public(m2, mlen);
public(h2, hlen);
if (memcmp(h2, h, hlen) != 0)
fail("failure: crypto_hash is nondeterministic\n");
double_canary(h2, h, hlen);
double_canary(m2, m, mlen);
secret(m2, mlen);
crypto_hash(m2, m2, mlen);
public(m2, hlen);
if (memcmp(m2, h, hlen) != 0)
fail("failure: crypto_hash does not handle m=h overlap\n");
memcpy(m2, m, mlen);
}
checksum_expected(hash_sha512_checksums[checksumbig]);
}
}
void test_hash_sha512(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "hash")) return;
if (targetp && strcmp(targetp, "sha512")) return;
storage_hash_sha512_h = callocplus(crypto_hash_BYTES);
test_hash_sha512_h = aligned(storage_hash_sha512_h, crypto_hash_BYTES);
if (crypto_hash_BYTES > maxalloc) maxalloc = crypto_hash_BYTES;
storage_hash_sha512_m = callocplus(4096 + crypto_hash_BYTES);
test_hash_sha512_m =
aligned(storage_hash_sha512_m, 4096 + crypto_hash_BYTES);
if (4096 + crypto_hash_BYTES > maxalloc)
maxalloc = 4096 + crypto_hash_BYTES;
storage_hash_sha512_h2 = callocplus(maxalloc);
test_hash_sha512_h2 = aligned(storage_hash_sha512_h2, crypto_hash_BYTES);
storage_hash_sha512_m2 = callocplus(maxalloc);
test_hash_sha512_m2 =
aligned(storage_hash_sha512_m2, 4096 + crypto_hash_BYTES);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("hash_sha512 offset %lld\n", offset);
forked(test_hash_sha512_impl, -1);
++test_hash_sha512_h;
++test_hash_sha512_m;
++test_hash_sha512_h2;
++test_hash_sha512_m2;
}
free(storage_hash_sha512_m2);
free(storage_hash_sha512_h2);
free(storage_hash_sha512_m);
free(storage_hash_sha512_h);
}
#undef crypto_hash_BYTES
tinyssh-20250201/_crypto-test_kem_sntrup761.inc 0000664 0000000 0000000 00000022602 14747360755 0021330 0 ustar 00root root 0000000 0000000 /* ----- kem/sntrup761, derived from supercop/crypto_kem/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
#define fail ((ok = 0), printf)
static const char *kem_sntrup761_checksums[] = {
"4081ab3f61bac9aae91bff7f9b212855177591ec4427dff2a501be124c5bb97d",
"730a572b64fa05a42bce7b1573edc04b70ef75909db309c012aa27f53f1f2f41",
};
static int (*crypto_kem_keypair)(unsigned char *, unsigned char *);
static int (*crypto_kem_enc)(unsigned char *, unsigned char *,
const unsigned char *);
static int (*crypto_kem_dec)(unsigned char *, const unsigned char *,
const unsigned char *);
#define crypto_kem_SECRETKEYBYTES crypto_kem_sntrup761_SECRETKEYBYTES
#define crypto_kem_PUBLICKEYBYTES crypto_kem_sntrup761_PUBLICKEYBYTES
#define crypto_kem_CIPHERTEXTBYTES crypto_kem_sntrup761_CIPHERTEXTBYTES
#define crypto_kem_BYTES crypto_kem_sntrup761_BYTES
static void *storage_kem_sntrup761_p;
static unsigned char *test_kem_sntrup761_p;
static void *storage_kem_sntrup761_s;
static unsigned char *test_kem_sntrup761_s;
static void *storage_kem_sntrup761_k;
static unsigned char *test_kem_sntrup761_k;
static void *storage_kem_sntrup761_c;
static unsigned char *test_kem_sntrup761_c;
static void *storage_kem_sntrup761_t;
static unsigned char *test_kem_sntrup761_t;
static void *storage_kem_sntrup761_p2;
static unsigned char *test_kem_sntrup761_p2;
static void *storage_kem_sntrup761_s2;
static unsigned char *test_kem_sntrup761_s2;
static void *storage_kem_sntrup761_k2;
static unsigned char *test_kem_sntrup761_k2;
static void *storage_kem_sntrup761_c2;
static unsigned char *test_kem_sntrup761_c2;
static void *storage_kem_sntrup761_t2;
static unsigned char *test_kem_sntrup761_t2;
static void test_kem_sntrup761_impl(long long impl) {
unsigned char *p = test_kem_sntrup761_p;
unsigned char *s = test_kem_sntrup761_s;
unsigned char *k = test_kem_sntrup761_k;
unsigned char *c = test_kem_sntrup761_c;
unsigned char *t = test_kem_sntrup761_t;
unsigned char *p2 = test_kem_sntrup761_p2;
unsigned char *s2 = test_kem_sntrup761_s2;
unsigned char *k2 = test_kem_sntrup761_k2;
unsigned char *c2 = test_kem_sntrup761_c2;
unsigned char *t2 = test_kem_sntrup761_t2;
long long plen = crypto_kem_PUBLICKEYBYTES;
long long slen = crypto_kem_SECRETKEYBYTES;
long long klen = crypto_kem_BYTES;
long long clen = crypto_kem_CIPHERTEXTBYTES;
long long tlen = crypto_kem_BYTES;
if (targetn && atol(targetn) != impl) return;
crypto_kem_keypair = crypto_kem_sntrup761_keypair;
crypto_kem_enc = crypto_kem_sntrup761_enc;
crypto_kem_dec = crypto_kem_sntrup761_dec;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 64 : 8;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
output_prepare(p2, p, plen);
output_prepare(s2, s, slen);
crypto_kem_keypair(p, s);
public(p, plen);
public(s, slen);
checksum(p, plen);
checksum(s, slen);
output_compare(p2, p, plen, "crypto_kem_keypair");
output_compare(s2, s, slen, "crypto_kem_keypair");
output_prepare(c2, c, clen);
output_prepare(k2, k, klen);
memcpy(p2, p, plen);
double_canary(p2, p, plen);
secret(p, plen);
crypto_kem_enc(c, k, p);
public(p, plen);
public(c, clen);
public(k, klen);
checksum(c, clen);
checksum(k, klen);
output_compare(c2, c, clen, "crypto_kem_enc");
output_compare(k2, k, klen, "crypto_kem_enc");
input_compare(p2, p, plen, "crypto_kem_enc");
output_prepare(t2, t, tlen);
memcpy(c2, c, clen);
double_canary(c2, c, clen);
memcpy(s2, s, slen);
double_canary(s2, s, slen);
secret(c, clen);
secret(s, slen);
crypto_kem_dec(t, c, s);
public(c, clen);
public(s, slen);
public(t, tlen);
if (memcmp(t, k, klen) != 0)
fail("failure: crypto_kem_dec does not match k\n");
checksum(t, tlen);
output_compare(t2, t, tlen, "crypto_kem_dec");
input_compare(c2, c, clen, "crypto_kem_dec");
input_compare(s2, s, slen, "crypto_kem_dec");
double_canary(t2, t, tlen);
double_canary(c2, c, clen);
double_canary(s2, s, slen);
secret(c2, clen);
secret(s2, slen);
crypto_kem_dec(t2, c2, s2);
public(c2, clen);
public(s2, slen);
public(t2, tlen);
if (memcmp(t2, t, tlen) != 0)
fail("failure: crypto_kem_dec is nondeterministic\n");
double_canary(t2, t, tlen);
double_canary(c2, c, clen);
double_canary(s2, s, slen);
secret(c2, clen);
secret(s, slen);
crypto_kem_dec(c2, c2, s);
public(c2, tlen);
public(s, slen);
if (memcmp(c2, t, tlen) != 0)
fail("failure: crypto_kem_dec does not handle c=t overlap\n");
memcpy(c2, c, clen);
secret(c, clen);
secret(s2, slen);
crypto_kem_dec(s2, c, s2);
public(s2, tlen);
public(c, clen);
if (memcmp(s2, t, tlen) != 0)
fail("failure: crypto_kem_dec does not handle s=t overlap\n");
memcpy(s2, s, slen);
c[myrandom() % clen] += 1 + (myrandom() % 255);
crypto_kem_dec(t, c, s);
checksum(t, tlen);
c[myrandom() % clen] += 1 + (myrandom() % 255);
crypto_kem_dec(t, c, s);
checksum(t, tlen);
c[myrandom() % clen] += 1 + (myrandom() % 255);
crypto_kem_dec(t, c, s);
checksum(t, tlen);
}
checksum_expected(kem_sntrup761_checksums[checksumbig]);
}
}
void test_kem_sntrup761(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "kem")) return;
if (targetp && strcmp(targetp, "sntrup761")) return;
storage_kem_sntrup761_p = callocplus(crypto_kem_PUBLICKEYBYTES);
test_kem_sntrup761_p =
aligned(storage_kem_sntrup761_p, crypto_kem_PUBLICKEYBYTES);
if (crypto_kem_PUBLICKEYBYTES > maxalloc)
maxalloc = crypto_kem_PUBLICKEYBYTES;
storage_kem_sntrup761_s = callocplus(crypto_kem_SECRETKEYBYTES);
test_kem_sntrup761_s =
aligned(storage_kem_sntrup761_s, crypto_kem_SECRETKEYBYTES);
if (crypto_kem_SECRETKEYBYTES > maxalloc)
maxalloc = crypto_kem_SECRETKEYBYTES;
storage_kem_sntrup761_k = callocplus(crypto_kem_BYTES);
test_kem_sntrup761_k = aligned(storage_kem_sntrup761_k, crypto_kem_BYTES);
if (crypto_kem_BYTES > maxalloc) maxalloc = crypto_kem_BYTES;
storage_kem_sntrup761_c = callocplus(crypto_kem_CIPHERTEXTBYTES);
test_kem_sntrup761_c =
aligned(storage_kem_sntrup761_c, crypto_kem_CIPHERTEXTBYTES);
if (crypto_kem_CIPHERTEXTBYTES > maxalloc)
maxalloc = crypto_kem_CIPHERTEXTBYTES;
storage_kem_sntrup761_t = callocplus(crypto_kem_BYTES);
test_kem_sntrup761_t = aligned(storage_kem_sntrup761_t, crypto_kem_BYTES);
if (crypto_kem_BYTES > maxalloc) maxalloc = crypto_kem_BYTES;
storage_kem_sntrup761_p2 = callocplus(maxalloc);
test_kem_sntrup761_p2 =
aligned(storage_kem_sntrup761_p2, crypto_kem_PUBLICKEYBYTES);
storage_kem_sntrup761_s2 = callocplus(maxalloc);
test_kem_sntrup761_s2 =
aligned(storage_kem_sntrup761_s2, crypto_kem_SECRETKEYBYTES);
storage_kem_sntrup761_k2 = callocplus(maxalloc);
test_kem_sntrup761_k2 = aligned(storage_kem_sntrup761_k2, crypto_kem_BYTES);
storage_kem_sntrup761_c2 = callocplus(maxalloc);
test_kem_sntrup761_c2 =
aligned(storage_kem_sntrup761_c2, crypto_kem_CIPHERTEXTBYTES);
storage_kem_sntrup761_t2 = callocplus(maxalloc);
test_kem_sntrup761_t2 = aligned(storage_kem_sntrup761_t2, crypto_kem_BYTES);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("kem_sntrup761 offset %lld\n", offset);
forked(test_kem_sntrup761_impl, -1);
++test_kem_sntrup761_p;
++test_kem_sntrup761_s;
++test_kem_sntrup761_k;
++test_kem_sntrup761_c;
++test_kem_sntrup761_t;
++test_kem_sntrup761_p2;
++test_kem_sntrup761_s2;
++test_kem_sntrup761_k2;
++test_kem_sntrup761_c2;
++test_kem_sntrup761_t2;
}
free(storage_kem_sntrup761_t2);
free(storage_kem_sntrup761_c2);
free(storage_kem_sntrup761_k2);
free(storage_kem_sntrup761_s2);
free(storage_kem_sntrup761_p2);
free(storage_kem_sntrup761_t);
free(storage_kem_sntrup761_c);
free(storage_kem_sntrup761_k);
free(storage_kem_sntrup761_s);
free(storage_kem_sntrup761_p);
}
#undef crypto_kem_SECRETKEYBYTES
#undef crypto_kem_PUBLICKEYBYTES
#undef crypto_kem_CIPHERTEXTBYTES
#undef crypto_kem_BYTES
tinyssh-20250201/_crypto-test_sign_ed25519.inc 0000664 0000000 0000000 00000033524 14747360755 0020726 0 ustar 00root root 0000000 0000000 /* ----- sign/ed25519, derived from supercop/crypto_sign/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
#define fail ((ok = 0), printf)
static const char *sign_ed25519_checksums[] = {
"ce11fd7c1eac4dd0bc5eec49b26ad1e91aef696fae50ce377dbd806dc394da01",
"2ed857f17c917a8185e6c296303a11772ae45683a5e7cb5b095489bad65fffde",
};
static int (*crypto_sign_keypair)(unsigned char *, unsigned char *);
static int (*crypto_sign)(unsigned char *, unsigned long long *,
const unsigned char *, unsigned long long,
const unsigned char *);
static int (*crypto_sign_open)(unsigned char *, unsigned long long *,
const unsigned char *, unsigned long long,
const unsigned char *);
#define crypto_sign_SECRETKEYBYTES crypto_sign_ed25519_SECRETKEYBYTES
#define crypto_sign_PUBLICKEYBYTES crypto_sign_ed25519_PUBLICKEYBYTES
#define crypto_sign_BYTES crypto_sign_ed25519_BYTES
static void *storage_sign_ed25519_p;
static unsigned char *test_sign_ed25519_p;
static void *storage_sign_ed25519_s;
static unsigned char *test_sign_ed25519_s;
static void *storage_sign_ed25519_m;
static unsigned char *test_sign_ed25519_m;
static void *storage_sign_ed25519_c;
static unsigned char *test_sign_ed25519_c;
static void *storage_sign_ed25519_t;
static unsigned char *test_sign_ed25519_t;
static void *storage_sign_ed25519_p2;
static unsigned char *test_sign_ed25519_p2;
static void *storage_sign_ed25519_s2;
static unsigned char *test_sign_ed25519_s2;
static void *storage_sign_ed25519_m2;
static unsigned char *test_sign_ed25519_m2;
static void *storage_sign_ed25519_c2;
static unsigned char *test_sign_ed25519_c2;
static void *storage_sign_ed25519_t2;
static unsigned char *test_sign_ed25519_t2;
static void test_sign_ed25519_impl(long long impl) {
unsigned char *p = test_sign_ed25519_p;
unsigned char *s = test_sign_ed25519_s;
unsigned char *m = test_sign_ed25519_m;
unsigned char *c = test_sign_ed25519_c;
unsigned char *t = test_sign_ed25519_t;
unsigned char *p2 = test_sign_ed25519_p2;
unsigned char *s2 = test_sign_ed25519_s2;
unsigned char *m2 = test_sign_ed25519_m2;
unsigned char *c2 = test_sign_ed25519_c2;
unsigned char *t2 = test_sign_ed25519_t2;
unsigned long long plen = crypto_sign_PUBLICKEYBYTES;
unsigned long long slen = crypto_sign_SECRETKEYBYTES;
unsigned long long mlen;
unsigned long long clen;
unsigned long long tlen;
if (targetn && atol(targetn) != impl) return;
crypto_sign_keypair = crypto_sign_ed25519_keypair;
crypto_sign = crypto_sign_ed25519;
crypto_sign_open = crypto_sign_ed25519_open;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 64 : 8;
long long maxtest = checksumbig ? 4096 : 128;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
int result;
mlen = myrandom() % (maxtest + 1);
output_prepare(p2, p, plen);
output_prepare(s2, s, slen);
crypto_sign_keypair(p, s);
public(p, plen);
public(s, slen);
checksum(p, plen);
checksum(s, slen);
output_compare(p2, p, plen, "crypto_sign_keypair");
output_compare(s2, s, slen, "crypto_sign_keypair");
clen = mlen + crypto_sign_BYTES;
output_prepare(c2, c, clen);
input_prepare(m2, m, mlen);
memcpy(s2, s, slen);
double_canary(s2, s, slen);
secret(m, mlen);
secret(s, slen);
crypto_sign(c, &clen, m, mlen, s);
public(m, mlen);
public(s, slen);
public(c, clen);
if (clen < mlen)
fail(
"failure: crypto_sign returns smaller output than input\n");
if (clen > mlen + crypto_sign_BYTES)
fail("failure: crypto_sign returns more than crypto_sign_BYTES "
"extra bytes\n");
checksum(c, clen);
output_compare(c2, c, clen, "crypto_sign");
input_compare(m2, m, mlen, "crypto_sign");
input_compare(s2, s, slen, "crypto_sign");
tlen = clen;
output_prepare(t2, t, tlen);
memcpy(c2, c, clen);
double_canary(c2, c, clen);
memcpy(p2, p, plen);
double_canary(p2, p, plen);
public(c, clen);
public(p, plen);
result = crypto_sign_open(t, &tlen, c, clen, p);
public(&result, sizeof result);
if (result != 0)
fail("failure: crypto_sign_open returns nonzero\n");
public(c, clen);
public(p, plen);
public(t, tlen);
if (tlen != mlen)
fail("failure: crypto_sign_open does not match mlen\n");
if (memcmp(t, m, mlen) != 0)
fail("failure: crypto_sign_open does not match m\n");
checksum(t, tlen);
output_compare(t2, t, clen, "crypto_sign_open");
input_compare(c2, c, clen, "crypto_sign_open");
input_compare(p2, p, plen, "crypto_sign_open");
double_canary(t2, t, tlen);
double_canary(c2, c, clen);
double_canary(p2, p, plen);
public(c2, clen);
public(p2, plen);
result = crypto_sign_open(t2, &tlen, c2, clen, p2);
public(&result, sizeof result);
if (result != 0)
fail("failure: crypto_sign_open returns nonzero\n");
public(c2, clen);
public(p2, plen);
public(t2, tlen);
if (memcmp(t2, t, tlen) != 0)
fail("failure: crypto_sign_open is nondeterministic\n");
double_canary(t2, t, tlen);
double_canary(c2, c, clen);
double_canary(p2, p, plen);
public(c2, clen);
public(p, plen);
result = crypto_sign_open(c2, &tlen, c2, clen, p);
public(&result, sizeof result);
if (result != 0)
fail("failure: crypto_sign_open with c=t overlap returns "
"nonzero\n");
public(c2, tlen);
public(p, plen);
if (memcmp(c2, t, tlen) != 0)
fail("failure: crypto_sign_open does not handle c=t overlap\n");
memcpy(c2, c, clen);
public(c, clen);
public(p2, plen);
result = crypto_sign_open(p2, &tlen, c, clen, p2);
public(&result, sizeof result);
if (result != 0)
fail("failure: crypto_sign_open with p=t overlap returns "
"nonzero\n");
public(p2, tlen);
public(c, clen);
if (memcmp(p2, t, tlen) != 0)
fail("failure: crypto_sign_open does not handle p=t overlap\n");
memcpy(p2, p, plen);
c[myrandom() % clen] += 1 + (myrandom() % 255);
if (crypto_sign_open(t, &tlen, c, clen, p) == 0)
if ((tlen != mlen) || (memcmp(t, m, mlen) != 0))
fail(
"failure: crypto_sign_open allows trivial forgeries\n");
c[myrandom() % clen] += 1 + (myrandom() % 255);
if (crypto_sign_open(t, &tlen, c, clen, p) == 0)
if ((tlen != mlen) || (memcmp(t, m, mlen) != 0))
fail(
"failure: crypto_sign_open allows trivial forgeries\n");
c[myrandom() % clen] += 1 + (myrandom() % 255);
if (crypto_sign_open(t, &tlen, c, clen, p) == 0)
if ((tlen != mlen) || (memcmp(t, m, mlen) != 0))
fail(
"failure: crypto_sign_open allows trivial forgeries\n");
}
checksum_expected(sign_ed25519_checksums[checksumbig]);
}
}
void test_sign_ed25519(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "sign")) return;
if (targetp && strcmp(targetp, "ed25519")) return;
storage_sign_ed25519_p =
callocplus(4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
test_sign_ed25519_p =
aligned(storage_sign_ed25519_p, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
if (4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES >
maxalloc)
maxalloc = 4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES;
storage_sign_ed25519_s =
callocplus(4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
test_sign_ed25519_s =
aligned(storage_sign_ed25519_s, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
if (4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES >
maxalloc)
maxalloc = 4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES;
storage_sign_ed25519_m =
callocplus(4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
test_sign_ed25519_m =
aligned(storage_sign_ed25519_m, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
if (4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES >
maxalloc)
maxalloc = 4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES;
storage_sign_ed25519_c =
callocplus(4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
test_sign_ed25519_c =
aligned(storage_sign_ed25519_c, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
if (4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES >
maxalloc)
maxalloc = 4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES;
storage_sign_ed25519_t =
callocplus(4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
test_sign_ed25519_t =
aligned(storage_sign_ed25519_t, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
if (4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES >
maxalloc)
maxalloc = 4096 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES;
storage_sign_ed25519_p2 = callocplus(maxalloc);
test_sign_ed25519_p2 =
aligned(storage_sign_ed25519_p2, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
storage_sign_ed25519_s2 = callocplus(maxalloc);
test_sign_ed25519_s2 =
aligned(storage_sign_ed25519_s2, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
storage_sign_ed25519_m2 = callocplus(maxalloc);
test_sign_ed25519_m2 =
aligned(storage_sign_ed25519_m2, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
storage_sign_ed25519_c2 = callocplus(maxalloc);
test_sign_ed25519_c2 =
aligned(storage_sign_ed25519_c2, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
storage_sign_ed25519_t2 = callocplus(maxalloc);
test_sign_ed25519_t2 =
aligned(storage_sign_ed25519_t2, 4096 + crypto_sign_BYTES +
crypto_sign_PUBLICKEYBYTES +
crypto_sign_SECRETKEYBYTES);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("sign_ed25519 offset %lld\n", offset);
forked(test_sign_ed25519_impl, -1);
++test_sign_ed25519_p;
++test_sign_ed25519_s;
++test_sign_ed25519_m;
++test_sign_ed25519_c;
++test_sign_ed25519_t;
++test_sign_ed25519_p2;
++test_sign_ed25519_s2;
++test_sign_ed25519_m2;
++test_sign_ed25519_c2;
++test_sign_ed25519_t2;
}
free(storage_sign_ed25519_t2);
free(storage_sign_ed25519_c2);
free(storage_sign_ed25519_m2);
free(storage_sign_ed25519_s2);
free(storage_sign_ed25519_p2);
free(storage_sign_ed25519_t);
free(storage_sign_ed25519_c);
free(storage_sign_ed25519_m);
free(storage_sign_ed25519_s);
free(storage_sign_ed25519_p);
}
#undef crypto_sign_SECRETKEYBYTES
#undef crypto_sign_PUBLICKEYBYTES
#undef crypto_sign_BYTES
tinyssh-20250201/_crypto-test_sort_uint32.inc 0000664 0000000 0000000 00000006415 14747360755 0021102 0 ustar 00root root 0000000 0000000 /* ----- sort/uint32, derived from supercop/crypto_sort/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
#define fail ((ok = 0), printf)
static const char *sort_uint32_checksums[] = {
"83fc714d7acc0375aa6657bd36d3324a6cbc503f68019345651be8a88534c3e2",
"30921a0be2d73a185181f0ec842fa0fa73cd6e958fc03411d435f14a3fc64c89",
};
static void (*crypto_sort)(void *, long long);
#define crypto_sort_BYTES crypto_sort_uint32_BYTES
static void *storage_sort_uint32_x;
static unsigned char *test_sort_uint32_x;
static void *storage_sort_uint32_x2;
static unsigned char *test_sort_uint32_x2;
static void test_sort_uint32_impl(long long impl) {
unsigned char *x = test_sort_uint32_x;
unsigned char *x2 = test_sort_uint32_x2;
long long xlen;
long long xwords;
if (targetn && atol(targetn) != impl) return;
crypto_sort = crypto_sort_uint32;
for (long long checksumbig = 0; checksumbig < 2; ++checksumbig) {
long long loops = checksumbig ? 4096 : 1024;
long long maxtest = checksumbig ? 4096 : 128;
if (checksumbig && valgrind) break;
checksum_clear();
for (long long loop = 0; loop < loops; ++loop) {
xwords = myrandom() % (maxtest + 1);
xlen = xwords * crypto_sort_BYTES;
input_prepare(x2, x, xlen);
endianness(x, xwords, crypto_sort_BYTES);
secret(x, xlen);
crypto_sort(x, xwords);
public(x, xlen);
endianness(x, xwords, crypto_sort_BYTES);
checksum(x, xlen);
output_compare(x2, x, xlen, "crypto_sort");
double_canary(x2, x, xlen);
endianness(x2, xwords, crypto_sort_BYTES);
secret(x2, xlen);
crypto_sort(x2, xwords);
public(x2, xlen);
endianness(x2, xwords, crypto_sort_BYTES);
if (memcmp(x2, x, xlen) != 0)
fail("failure: crypto_sort is nondeterministic\n");
}
checksum_expected(sort_uint32_checksums[checksumbig]);
}
}
void test_sort_uint32(void) {
long long maxalloc = 0;
if (targeto && strcmp(targeto, "sort")) return;
if (targetp && strcmp(targetp, "uint32")) return;
storage_sort_uint32_x = callocplus(crypto_sort_uint32_BYTES * 4096);
test_sort_uint32_x =
aligned(storage_sort_uint32_x, crypto_sort_uint32_BYTES * 4096);
if (crypto_sort_uint32_BYTES * 4096 > maxalloc)
maxalloc = crypto_sort_uint32_BYTES * 4096;
storage_sort_uint32_x2 = callocplus(maxalloc);
test_sort_uint32_x2 =
aligned(storage_sort_uint32_x2, crypto_sort_uint32_BYTES * 4096);
for (long long offset = 0; offset < 1; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("sort_uint32 offset %lld\n", offset);
forked(test_sort_uint32_impl, -1);
++test_sort_uint32_x;
++test_sort_uint32_x2;
}
free(storage_sort_uint32_x2);
free(storage_sort_uint32_x);
}
#undef crypto_sort_BYTES
tinyssh-20250201/_crypto-test_verify_16.inc 0000664 0000000 0000000 00000004007 14747360755 0020514 0 ustar 00root root 0000000 0000000 /* ----- verify, derived from supercop/crypto_verify/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
static unsigned char *test_verify_16_x;
static unsigned char *test_verify_16_y;
static void test_verify_16_check(void) {
unsigned char *x = test_verify_16_x;
unsigned char *y = test_verify_16_y;
int r;
secret(x, 16);
secret(y, 16);
r = crypto_verify_16(x, y);
public(x, 16);
public(y, 16);
public(&r, sizeof r);
if (r == 0) {
if (memcmp(x, y, 16)) fail("failure: different strings pass verify\n");
}
else if (r == -1) {
if (!memcmp(x, y, 16)) fail("failure: equal strings fail verify\n");
}
else { fail("failure: weird return value\n"); }
}
void test_verify_16_impl(long long impl) {
unsigned char *x = test_verify_16_x;
unsigned char *y = test_verify_16_y;
if (targetn && atol(targetn) != impl) return;
randombytes(x, 16);
randombytes(y, 16);
test_verify_16_check();
memcpy(y, x, 16);
test_verify_16_check();
y[myrandom() % 16] = myrandom();
test_verify_16_check();
y[myrandom() % 16] = myrandom();
test_verify_16_check();
y[myrandom() % 16] = myrandom();
test_verify_16_check();
}
static void test_verify_16(void) {
if (targeto && strcmp(targeto, "verify")) return;
if (targetp && strcmp(targetp, "16")) return;
test_verify_16_x = callocplus(16);
test_verify_16_y = callocplus(16);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("verify_16 offset %lld\n", offset);
forked(test_verify_16_impl, -1);
++test_verify_16_x;
++test_verify_16_y;
}
}
tinyssh-20250201/_crypto-test_verify_32.inc 0000664 0000000 0000000 00000004007 14747360755 0020512 0 ustar 00root root 0000000 0000000 /* ----- verify, derived from supercop/crypto_verify/try.c */
/*
derived from djb work from lib25519/libntruprime
mj modifications:
- rename files to test-crypto.c and _crypto_<>.<>.inc
- fix compiler warnings
- include crypto.h
- use less rounds for valgrind test
- reformat using clang-format
*/
#include
#include
#include
#include
#include "crypto.h"
static unsigned char *test_verify_32_x;
static unsigned char *test_verify_32_y;
static void test_verify_32_check(void) {
unsigned char *x = test_verify_32_x;
unsigned char *y = test_verify_32_y;
int r;
secret(x, 32);
secret(y, 32);
r = crypto_verify_32(x, y);
public(x, 32);
public(y, 32);
public(&r, sizeof r);
if (r == 0) {
if (memcmp(x, y, 32)) fail("failure: different strings pass verify\n");
}
else if (r == -1) {
if (!memcmp(x, y, 32)) fail("failure: equal strings fail verify\n");
}
else { fail("failure: weird return value\n"); }
}
void test_verify_32_impl(long long impl) {
unsigned char *x = test_verify_32_x;
unsigned char *y = test_verify_32_y;
if (targetn && atol(targetn) != impl) return;
randombytes(x, 32);
randombytes(y, 32);
test_verify_32_check();
memcpy(y, x, 32);
test_verify_32_check();
y[myrandom() % 32] = myrandom();
test_verify_32_check();
y[myrandom() % 32] = myrandom();
test_verify_32_check();
y[myrandom() % 32] = myrandom();
test_verify_32_check();
}
static void test_verify_32(void) {
if (targeto && strcmp(targeto, "verify")) return;
if (targetp && strcmp(targetp, "32")) return;
test_verify_32_x = callocplus(32);
test_verify_32_y = callocplus(32);
for (long long offset = 0; offset < 2; ++offset) {
if (targetoffset && atol(targetoffset) != offset) continue;
if (offset && valgrind) break;
printf("verify_32 offset %lld\n", offset);
forked(test_verify_32_impl, -1);
++test_verify_32_x;
++test_verify_32_y;
}
}
tinyssh-20250201/_tinysshd-printkex.c 0000664 0000000 0000000 00000011010 14747360755 0017475 0 ustar 00root root 0000000 0000000 /*
20141210
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "log.h"
#include "packet.h"
#include "ssh.h"
#include "bug.h"
#include "packetparser.h"
#include "global.h"
static void cleanup(void) { global_purge(); }
__attribute__((noreturn)) static void die_fatal(const char *trouble,
const char *d, const char *fn) {
cleanup();
if (d) {
if (fn)
log_f5(trouble, " ", d, "/", fn);
else
log_f3(trouble, " ", d);
}
else { log_f1(trouble); }
_exit(111);
}
static int packet_kex_receive_(void) {
struct buf *b = &packet.kexrecv;
long long pos = 0;
crypto_uint8 ch;
crypto_uint32 len;
if (!packet_getall(b, SSH_MSG_KEXINIT)) return 0;
/* parse packet */
pos = packetparser_uint8(b->buf, b->len, pos, &ch); /* SSH_MSG_KEXINIT */
if (ch != SSH_MSG_KEXINIT) bug_proto();
pos = packetparser_skip(b->buf, b->len, pos, 16); /* cookie */
pos = packetparser_uint32(b->buf, b->len, pos, &len); /* kex algorithms */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("kex algorithms: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* server host key algorithms */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("server host key algorithms: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(
b->buf, b->len, pos, &len); /* encryption algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("encryption algorithms client to server: ",
(char *) b->buf + pos - len);
pos = packetparser_uint32(
b->buf, b->len, pos, &len); /* encryption algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("encryption algorithms server to client: ",
(char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* mac algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("mac algorithms client to server: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* mac algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("mac algorithms server to client: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* compress algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* compress algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* languages client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* languages server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* kex first packet follows */
pos = packetparser_uint32(b->buf, b->len, pos, &len); /* reserved */
return 1;
}
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
++argv;
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
close(2);
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
global_init();
log_init(2, "_tinysshd-printkex", 0, 0);
if (!packet_hello_receive())
die_fatal("unable to receive hello-string", 0, 0);
if (!packet_hello_send()) die_fatal("unable to send hello-string", 0, 0);
if (!packet_kex_receive_())
die_fatal("unable to receive kex-message", 0, 0);
_exit(111);
}
tinyssh-20250201/_tinysshd-speed.c 0000664 0000000 0000000 00000016042 14747360755 0016743 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include "crypto.h"
static unsigned char sk[2560];
static unsigned char pk[2560];
static unsigned char a[16];
static unsigned char n[8];
static unsigned char k[64];
static unsigned char h[64];
static unsigned char space[10240];
static unsigned char m[51200];
static unsigned char sm[51200];
static unsigned long long smlen;
static unsigned long long mlen;
static const char *implementation, *version;
static int flagtimeout;
static void timeout(int x) {
flagtimeout = x = 1;
signal(SIGALRM, timeout);
}
int main(void) {
long long count;
signal(SIGALRM, timeout);
/* randombytes test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
randombytes(space, sizeof space);
++count;
}
printf("randombytes: %lld MB/s (%s)\n", count / 100, randombytes_source());
#ifdef crypto_hash_sha512_IMPLEMENTATION
implementation = crypto_hash_sha512_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_hash_sha512_VERSION
version = crypto_hash_sha512_VERSION;
#else
version = "unknown";
#endif
/* sha512 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_hash_sha512(h, space, sizeof space) != 0) return 111;
++count;
}
printf("crypto_hash_sha512: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_hash_sha256_IMPLEMENTATION
implementation = crypto_hash_sha256_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_hash_sha256_VERSION
version = crypto_hash_sha256_VERSION;
#else
version = "unknown";
#endif
/* sha256 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_hash_sha256(h, space, sizeof space) != 0) return 111;
++count;
}
printf("crypto_hash_sha256: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_stream_chacha20_IMPLEMENTATION
implementation = crypto_stream_chacha20_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_stream_chacha20_VERSION
version = crypto_stream_chacha20_VERSION;
#else
version = "unknown";
#endif
/* chacha20 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_stream_chacha20_xor(space, space, sizeof space, n, k) != 0)
return 111;
++count;
}
printf("crypto_stream_chacha20_xor: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_onetimeauth_poly1305_IMPLEMENTATION
implementation = crypto_onetimeauth_poly1305_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_onetimeauth_poly1305_VERSION
version = crypto_onetimeauth_poly1305_VERSION;
#else
version = "unknown";
#endif
/* onetimeauth test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_onetimeauth_poly1305(a, space, sizeof space, k) != 0)
return 111;
++count;
}
printf("crypto_onetimeauth_poly1305: %lld MB/s (%s, %s)\n", count / 100,
implementation, version);
#ifdef crypto_scalarmult_curve25519_IMPLEMENTATION
implementation = crypto_scalarmult_curve25519_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_scalarmult_curve25519_VERSION
version = crypto_scalarmult_curve25519_VERSION;
#else
version = "unknown";
#endif
/* x25519 test */
randombytes(sk, crypto_scalarmult_curve25519_SCALARBYTES);
crypto_scalarmult_curve25519_base(pk, sk);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_scalarmult_curve25519(k, sk, pk) != 0) return 111;
++count;
}
printf("crypto_scalarmult_curve25519: %lld dh/s (%s, %s)\n", count,
implementation, version);
#ifdef crypto_sign_ed25519_IMPLEMENTATION
implementation = crypto_sign_ed25519_IMPLEMENTATION;
#else
implementation = "unknown";
#endif
#ifdef crypto_sign_ed25519_VERSION
version = crypto_sign_ed25519_VERSION;
#else
version = "unknown";
#endif
/* ed25519 test */
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_sign_ed25519_keypair: %lld keypairs/s (%s, %s)\n", count,
implementation, version);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519(sm, &smlen, m + crypto_sign_ed25519_BYTES,
sizeof(m) - crypto_sign_ed25519_BYTES, sk) != 0)
return 111;
++count;
}
printf("crypto_sign_ed25519: %lld sigs/s (%s, %s)\n", count, implementation,
version);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_sign_ed25519_open(m, &mlen, sm, sizeof sm, pk) != 0)
return 111;
++count;
}
printf("crypto_sign_ed25519_open: %lld sigs/s (%s, %s)\n", count,
implementation, version);
#ifdef crypto_kem_sntrup4591761_IMPLEMENTATION
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_keypair: %lld keypairs/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_enc(c, k, pk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_enc: %lld encryptions/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761_dec(k, c, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761_dec: %lld decryptions/s (%s)\n", count,
crypto_kem_sntrup4591761_IMPLEMENTATION);
#endif
#ifdef crypto_kem_sntrup4591761x25519_IMPLEMENTATION
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_keypair(pk, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_keypair: %lld keypairs/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_enc(c, k, pk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_enc: %lld encryptions/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
alarm(1);
flagtimeout = 0;
count = 0;
while (!flagtimeout) {
if (crypto_kem_sntrup4591761x25519_dec(k, c, sk) != 0) return 111;
++count;
}
printf("crypto_kem_sntrup4591761x25519_dec: %lld decryptions/s (%s)\n",
count, crypto_kem_sntrup4591761x25519_IMPLEMENTATION);
#endif
return 0;
}
tinyssh-20250201/_tinysshd-test-hello1.c 0000664 0000000 0000000 00000001710 14747360755 0020000 0 ustar 00root root 0000000 0000000 /*
20160225
Jan Mojzis
Public domain.
*/
#include
#include
#include
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
++argv;
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
close(1); /* simulate closed connection */
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
_exit(111);
}
tinyssh-20250201/_tinysshd-test-hello2.c 0000664 0000000 0000000 00000003570 14747360755 0020007 0 ustar 00root root 0000000 0000000 /*
20160225
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "log.h"
#include "packet.h"
#include "global.h"
#include "str.h"
#include "writeall.h"
static void cleanup(void) { global_purge(); }
__attribute__((noreturn)) static void die_fatal(const char *trouble,
const char *d, const char *fn) {
cleanup();
if (d) {
if (fn)
log_f5(trouble, " ", d, "/", fn);
else
log_f3(trouble, " ", d);
}
else { log_f1(trouble); }
_exit(111);
}
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
const char *message;
long long messagelen;
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
if (!argv[2]) _exit(111);
++argv;
message = *argv;
messagelen = str_len(message);
++argv;
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
global_init();
if (!packet_hello_receive())
die_fatal("unable to receive hello-string", 0, 0);
if (messagelen) {
if (writeall(1, message, messagelen) == -1)
die_fatal("unable to write hello-string", 0, 0);
if (writeall(1, "\r\n", 2) == -1)
die_fatal("unable to write hello-string", 0, 0);
}
_exit(111);
}
tinyssh-20250201/_tinysshd-test-kex1.c 0000664 0000000 0000000 00000003252 14747360755 0017467 0 ustar 00root root 0000000 0000000 /*
20160226
20241215 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "log.h"
#include "packet.h"
#include "ssh.h"
#include "bug.h"
#include "packetparser.h"
#include "global.h"
static void cleanup(void) { global_purge(); }
__attribute__((noreturn)) static void die_fatal(const char *trouble,
const char *d, const char *fn) {
cleanup();
if (d) {
if (fn)
log_f5(trouble, " ", d, "/", fn);
else
log_f3(trouble, " ", d);
}
else { log_f1(trouble); }
_exit(111);
}
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
++argv;
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
global_init();
log_init(2, "_tinysshd-test-kex1", 0, 0);
if (!packet_hello_receive())
die_fatal("unable to receive hello-string", 0, 0);
if (!packet_hello_send()) die_fatal("unable to send hello-string", 0, 0);
_exit(111);
}
tinyssh-20250201/_tinysshd-test-kex2.c 0000664 0000000 0000000 00000013066 14747360755 0017474 0 ustar 00root root 0000000 0000000 /*
20160226
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "log.h"
#include "packet.h"
#include "ssh.h"
#include "bug.h"
#include "packetparser.h"
#include "global.h"
static void cleanup(void) { global_purge(); }
__attribute__((noreturn)) static void die_fatal(const char *trouble,
const char *d, const char *fn) {
cleanup();
if (d) {
if (fn)
log_f5(trouble, " ", d, "/", fn);
else
log_f3(trouble, " ", d);
}
else { log_f1(trouble); }
_exit(111);
}
static int packet_disconnect_(struct buf *b) {
buf_purge(b);
buf_putnum8(b, SSH_MSG_DISCONNECT); /* byte SSH_MSG_DISCONNECT */
buf_putnum32(b, 0); /* uint32 reason code */
buf_putstring(b, "bye"); /* string description in ISO-10646 UTF-8
encoding [RFC3629] */
buf_putstring(b, ""); /* string language tag [RFC3066] */
packet_put(b);
return packet_sendall();
}
#if 0
static int _packet_debug(struct buf *b) {
buf_purge(b);
buf_putnum8(b, SSH_MSG_DEBUG); /* SSH_MSG_DEBUG */
buf_putnum8(b, 1); /* always_display */
buf_putstring(b, "test message"); /* message in ISO-10646 UTF-8 encoding [RFC3629] */
buf_putstring(b, ""); /* language tag [RFC3066] */
packet_put(b);
return packet_sendall();
}
#endif
static int packet_kex_receive_(void) {
struct buf *b = &packet.kexrecv;
long long pos = 0;
crypto_uint8 ch;
crypto_uint32 len;
if (!packet_getall(b, SSH_MSG_KEXINIT)) return 0;
/* parse packet */
pos = packetparser_uint8(b->buf, b->len, pos, &ch); /* SSH_MSG_KEXINIT */
if (ch != SSH_MSG_KEXINIT) bug_proto();
pos = packetparser_skip(b->buf, b->len, pos, 16); /* cookie */
pos = packetparser_uint32(b->buf, b->len, pos, &len); /* kex algorithms */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("kex algorithms: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* server host key algorithms */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("server host key algorithms: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(
b->buf, b->len, pos, &len); /* encryption algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("encryption algorithms client to server: ",
(char *) b->buf + pos - len);
pos = packetparser_uint32(
b->buf, b->len, pos, &len); /* encryption algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("encryption algorithms server to client: ",
(char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* mac algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("mac algorithms client to server: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* mac algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
log_i2("mac algorithms server to client: ", (char *) b->buf + pos - len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* compress algorithms client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* compress algorithms server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* languages client to server */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint32(b->buf, b->len, pos,
&len); /* languages server to client */
pos = packetparser_skip(b->buf, b->len, pos, len);
pos = packetparser_uint8(b->buf, b->len, pos,
&ch); /* kex first packet follows */
pos = packetparser_uint32(b->buf, b->len, pos, &len); /* reserved */
return 1;
}
static unsigned char bspace[1024];
static struct buf b;
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
++argv;
buf_init(&b, bspace, sizeof bspace);
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
global_init();
log_init(0, "_tinysshd-test-kex1", 0, 0);
if (!packet_hello_receive())
die_fatal("unable to receive hello-string", 0, 0);
if (!packet_hello_send()) die_fatal("unable to send hello-string", 0, 0);
if (!packet_kex_receive_())
die_fatal("unable to receive kex-message", 0, 0);
if (!packet_disconnect_(&b))
die_fatal("unable to send disconnect-message", 0, 0);
_exit(111);
}
tinyssh-20250201/_tinysshd-unauthenticated.c 0000664 0000000 0000000 00000005130 14747360755 0021024 0 ustar 00root root 0000000 0000000 /*
20141210
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "log.h"
#include "packet.h"
#include "ssh.h"
#include "bug.h"
#include "packetparser.h"
#include "global.h"
static void cleanup(void) { global_purge(); }
__attribute__((noreturn)) static void die_fatal(const char *trouble,
const char *d, const char *fn) {
cleanup();
if (d) {
if (fn)
log_f5(trouble, " ", d, "/", fn);
else
log_f3(trouble, " ", d);
}
else { log_f1(trouble); }
_exit(111);
}
static int packet_debug_(struct buf *b) {
buf_purge(b);
buf_putnum8(b, SSH_MSG_DEBUG); /* SSH_MSG_DEBUG */
buf_putnum8(b, 1); /* always_display */
buf_putstring(
b, "test message"); /* message in ISO-10646 UTF-8 encoding [RFC3629] */
buf_putstring(b, ""); /* language tag [RFC3066] */
packet_put(b);
return packet_sendall();
}
static unsigned char bspace[1024];
static struct buf b;
int main(int argc, char **argv) {
pid_t pid;
int tochild[2] = {-1, -1};
int fromchild[2] = {-1, -1};
long long i;
if (argc < 2) _exit(111);
if (!argv[0]) _exit(111);
if (!argv[1]) _exit(111);
++argv;
buf_init(&b, bspace, sizeof bspace);
if (pipe(tochild) == -1) _exit(111);
if (pipe(fromchild) == -1) _exit(111);
pid = fork();
if (pid == -1) _exit(111);
if (pid == 0) {
close(tochild[1]);
close(fromchild[0]);
close(2);
if (dup2(tochild[0], 0) == -1) _exit(111);
if (dup2(fromchild[1], 1) == -1) _exit(111);
execvp(*argv, argv);
_exit(111);
}
close(tochild[0]);
close(fromchild[1]);
close(0);
if (dup2(fromchild[0], 0) == -1) _exit(111);
close(1);
if (dup2(tochild[1], 1) == -1) _exit(111);
signal(SIGPIPE, SIG_IGN);
global_init();
log_init(1, "_tinysshd-unauthenticated", 0, 0);
if (!packet_hello_receive())
die_fatal("unable to receive hello-string", 0, 0);
if (!packet_hello_send()) die_fatal("unable to send hello-string", 0, 0);
for (i = 1; i < 100 * PACKET_UNAUTHENTICATED_MESSAGES; ++i) {
if (!packet_debug_(&b)) {
if (i < PACKET_UNAUTHENTICATED_MESSAGES)
die_fatal(
"unable to send debug message - parent died too early", 0,
0);
_exit(0); /* limitation works */
}
if (i > PACKET_UNAUTHENTICATED_MESSAGES) usleep(1000); /* XXX */
}
die_fatal("limitation is not working !!!!!!!!!!", 0, 0);
}
tinyssh-20250201/blocking.c 0000664 0000000 0000000 00000000505 14747360755 0015426 0 ustar 00root root 0000000 0000000 /*
taken from nacl-20110221, from from curvecp/blocking.c
- reformated using clang-format
*/
#include
#include "blocking.h"
void blocking_enable(int fd) {
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK);
}
void blocking_disable(int fd) {
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
}
tinyssh-20250201/blocking.h 0000664 0000000 0000000 00000000174 14747360755 0015435 0 ustar 00root root 0000000 0000000 #ifndef BLOCKING_H____
#define BLOCKING_H____
extern void blocking_enable(int);
extern void blocking_disable(int);
#endif
tinyssh-20250201/buf.c 0000664 0000000 0000000 00000013716 14747360755 0014422 0 ustar 00root root 0000000 0000000 /*
20140108
20241208 - reformated using clang-format
Jan Mojzis
Public domain.
The 'buf' library holds a string in allocated space.
The string length is limited by allocated memory.
All 'buf_put*' functions checks the limit and if
the string exceeds the limit, 'buf_put*' function
immediately exits with 111 status code.
*/
#include "byte.h"
#include "str.h"
#include "purge.h"
#include "randombytes.h"
#include "crypto_uint32.h"
#include "bug.h"
#include "buf.h"
/*
Initialize 'b' structure.
*/
void buf_init_(const char *fn, unsigned long long line, struct buf *b,
unsigned char *buf, long long alloc) {
if (!b || !buf || alloc <= 0 || alloc > 1073741824) bug_inval_(fn, line);
b->buf = buf;
b->len = 0;
b->alloc = alloc;
purge(b->buf, b->alloc);
}
/*
Remove content of 'b'.
*/
void buf_purge_(const char *fn, unsigned long long line, struct buf *b) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf)
bug_inval_(fn, line);
purge(b->buf, b->len);
b->len = 0;
}
/*
Retun if 'b' has available space for string of length 'len'.
*/
int buf_ready_(const char *fn, unsigned long long line, struct buf *b,
long long len) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf || len < 0 || len > 1073741824)
bug_inval_(fn, line);
return (b->len + len < b->alloc);
}
/*
Put string 'x' of length 'len'.
*/
int buf_put_(const char *fn, unsigned long long line, struct buf *b,
const unsigned char *x, long long len) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf || !x || len < 0 || len > 1073741824)
bug_inval_(fn, line);
if (b->len + len >= b->alloc) bug_nomem_(fn, line);
byte_copy(b->buf + b->len, len, x);
b->len += len;
return 1;
}
/*
Put 0-terminated string 'x'.
*/
int buf_puts_(const char *fn, unsigned long long line, struct buf *b,
const char *x) {
return buf_put_(fn, line, b, (const unsigned char *) x, str_len(x));
}
/*
Put zero bytes of length 'len'.
*/
int buf_putzerobytes_(const char *fn, unsigned long long line, struct buf *b,
long long len) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf || len < 0 || len > 1073741824)
bug_inval_(fn, line);
if (b->len + len >= b->alloc) bug_nomem_(fn, line);
byte_zero(b->buf + b->len, len);
b->len += len;
return 1;
}
/*
Put random bytes of length 'len'.
*/
int buf_putrandombytes_(const char *fn, unsigned long long line, struct buf *b,
long long len) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf || len < 0 || len > 1073741824)
bug_inval_(fn, line);
if (b->len + len >= b->alloc) bug_nomem_(fn, line);
randombytes(b->buf + b->len, len);
b->len += len;
return 1;
}
/*
Put padding of length 'len'.
*/
int buf_putpadding_(const char *fn, unsigned long long line, struct buf *b,
long long len) {
if (!b || b->len < 0 || b->len > 1073741824 || b->alloc <= 0 ||
b->alloc > 1073741824 || !b->buf || len < 0 || len > 1073741824)
bug_inval_(fn, line);
if (b->len + len >= b->alloc) bug_nomem_(fn, line);
purge(b->buf + b->len, len);
b->len += len;
return 1;
}
/*
Put 32-bit unsigned integer in big-endian format.
*/
int buf_putnum32_(const char *fn, unsigned long long line, struct buf *b,
crypto_uint32 x) {
unsigned char s[4];
crypto_uint32_store_bigendian(s, x);
return buf_put_(fn, line, b, s, sizeof s);
}
/*
Put 8-bit unsigned integer.
*/
int buf_putnum8_(const char *fn, unsigned long long line, struct buf *b,
crypto_uint8 u) {
return buf_put_(fn, line, b, &u, 1);
}
/*
Put string 'x' of length 'len' and format it as a SSH-string.
*/
int buf_putstringlen_(const char *fn, unsigned long long line, struct buf *b,
const unsigned char *x, long long len) {
if (!buf_putnum32_(fn, line, b, len)) return 0;
return buf_put_(fn, line, b, x, len);
}
/*
Put 0-terminated string 'x' and format it as a SSH-string.
*/
int buf_putstring_(const char *fn, unsigned long long line, struct buf *b,
const char *x) {
return buf_putstringlen_(fn, line, b, (const unsigned char *) x,
str_len(x));
}
/*
Put SSH shared secret (bignum formated into wire format)
*/
int buf_putsharedsecret_(const char *fn, unsigned long long line, struct buf *b,
const unsigned char *x, long long len) {
long long pos;
if (len < 0 || len > 1073741824 || !b || !x) bug_inval_(fn, line);
for (pos = 0; pos < len; ++pos)
if (x[pos]) break;
if (x[pos] & 0x80) {
buf_putnum32_(fn, line, b, len - pos + 1);
buf_putnum8_(fn, line, b, 0);
}
else { buf_putnum32_(fn, line, b, len - pos + 0); }
return buf_put_(fn, line, b, x + pos, len - pos);
}
/*
Put string 'x' of length 'len' and encode it into base64.
*/
static const unsigned char b64chars[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int buf_putbase64_(const char *fn, unsigned long long line, struct buf *b,
const unsigned char *x, long long len) {
long long i;
unsigned long long bits = 0, v = 0;
unsigned char ch;
if (len < 0 || len > 1073741824 || !b || !x) bug_inval_(fn, line);
for (i = 0; i < len; ++i) {
v <<= 8;
v += x[i];
bits += 8;
while (bits > 6) {
ch = b64chars[((v >> (bits - 6)) & 63)];
buf_putnum8_(fn, line, b, ch);
bits -= 6;
}
}
if (bits) {
v <<= (6 - bits);
ch = b64chars[v & 63];
buf_putnum8_(fn, line, b, ch);
}
while (b->len & 3) { buf_putnum8_(fn, line, b, '='); }
return 1;
}
tinyssh-20250201/buf.h 0000664 0000000 0000000 00000006124 14747360755 0014422 0 ustar 00root root 0000000 0000000 /*
20140108
20241208 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#ifndef BUF_H____
#define BUF_H____
#include "crypto_uint8.h"
#include "crypto_uint32.h"
struct buf {
unsigned char *buf;
long long len;
long long alloc;
};
extern void buf_init_(const char *, unsigned long long, struct buf *,
unsigned char *, long long);
extern void buf_purge_(const char *, unsigned long long, struct buf *);
extern int buf_ready_(const char *, unsigned long long, struct buf *,
long long);
extern int buf_put_(const char *, unsigned long long, struct buf *,
const unsigned char *, long long);
extern int buf_puts_(const char *, unsigned long long, struct buf *,
const char *);
extern int buf_putzerobytes_(const char *, unsigned long long, struct buf *,
long long);
extern int buf_putrandombytes_(const char *, unsigned long long, struct buf *,
long long);
extern int buf_putpadding_(const char *, unsigned long long, struct buf *,
long long);
extern int buf_putnum32_(const char *, unsigned long long, struct buf *,
crypto_uint32);
extern int buf_putnum8_(const char *, unsigned long long, struct buf *,
crypto_uint8);
extern int buf_putstringlen_(const char *, unsigned long long, struct buf *,
const unsigned char *, long long);
extern int buf_putstring_(const char *, unsigned long long, struct buf *,
const char *);
extern int buf_putsharedsecret_(const char *, unsigned long long, struct buf *,
const unsigned char *, long long);
extern int buf_putbase64_(const char *, unsigned long long, struct buf *,
const unsigned char *, long long);
#define buf_init(a, b, cc) buf_init_(__FILE__, __LINE__, (a), (b), (cc))
#define buf_purge(a) buf_purge_(__FILE__, __LINE__, (a))
#define buf_ready(a, b) buf_ready_(__FILE__, __LINE__, (a), (b))
#define buf_put(a, b, cc) buf_put_(__FILE__, __LINE__, (a), (b), (cc))
#define buf_puts(a, b) buf_puts_(__FILE__, __LINE__, (a), (b))
#define buf_putzerobytes(a, b) buf_putzerobytes_(__FILE__, __LINE__, (a), (b))
#define buf_putrandombytes(a, b) \
buf_putrandombytes_(__FILE__, __LINE__, (a), (b))
#define buf_putpadding(a, b) buf_putpadding_(__FILE__, __LINE__, (a), (b))
#define buf_putnum32(a, b) buf_putnum32_(__FILE__, __LINE__, (a), (b))
#define buf_putnum8(a, b) buf_putnum8_(__FILE__, __LINE__, (a), (b))
#define buf_putstringlen(a, b, cc) \
buf_putstringlen_(__FILE__, __LINE__, (a), (b), (cc))
#define buf_putstring(a, b) buf_putstring_(__FILE__, __LINE__, (a), (b))
#define buf_putsharedsecret(a, b, cc) \
buf_putsharedsecret_(__FILE__, __LINE__, (a), (b), (cc))
#define buf_putbase64(a, b, cc) \
buf_putbase64_(__FILE__, __LINE__, (a), (b), (cc))
#endif
tinyssh-20250201/bug.h 0000664 0000000 0000000 00000004753 14747360755 0014431 0 ustar 00root root 0000000 0000000 #ifndef BUG_H____
#define BUG_H____
#include
#include "global.h"
#include "e.h"
#include "log.h"
#define bug_(a, b) \
do { \
log_9_(-1, 0, a, b, 0, 0, 0, 0, 0, 0, 0, 0, 0); \
global_die(111); \
} while (0)
#define bug() bug_(__FILE__, __LINE__)
#define bug_nomem() \
do { \
errno = ENOMEM; \
bug(); \
} while (0)
#define bug_proto() \
do { \
errno = EPROTO; \
bug(); \
} while (0)
#define bug_inval() \
do { \
errno = EINVAL; \
bug(); \
} while (0)
#define bug_nomem_(a, b) \
do { \
errno = ENOMEM; \
bug_(a, b); \
} while (0)
#define bug_proto_(a, b) \
do { \
errno = EPROTO; \
bug_(a, b); \
} while (0)
#define bug_inval_(a, b) \
do { \
errno = EINVAL; \
bug_(a, b); \
} while (0)
#endif
tinyssh-20250201/byte.c 0000664 0000000 0000000 00000001306 14747360755 0014601 0 ustar 00root root 0000000 0000000 /*
20241205
*/
#include "crypto_int16.h"
#include "byte.h"
void byte_copy(void *yv, long long ylen, const void *xv) {
long long i;
const char *x = xv;
char *y = yv;
for (i = 0; i < ylen; ++i) y[i] = x[i];
}
int byte_isequal(const void *yv, long long ylen, const void *xv) {
long long i;
const unsigned char *y = yv;
const unsigned char *x = xv;
unsigned char diff = 0;
for (i = 0; i < ylen; ++i) diff |= x[i] ^ y[i];
return crypto_int16_zero_01(diff);
}
void byte_zero(void *yv, long long ylen) {
long long i;
volatile char *y = yv;
for (i = 0; i < ylen; ++i) y[i] = 0;
#ifdef __GNUC__
__asm__ __volatile__("" : : "r"(yv) : "memory");
#endif
}
tinyssh-20250201/byte.h 0000664 0000000 0000000 00000000321 14747360755 0014602 0 ustar 00root root 0000000 0000000 #ifndef BYTE_H____
#define BYTE_H____
extern void byte_zero(void *, long long);
extern void byte_copy(void *, long long, const void *);
extern int byte_isequal(const void *, long long, const void *);
#endif
tinyssh-20250201/channel.c 0000664 0000000 0000000 00000027616 14747360755 0015262 0 ustar 00root root 0000000 0000000 /*
20140124
20241209 - reformated using clang-format
Jan Mojzis
Public domain.
The 'channel' library is used to handle data from/to SSH channel (rfc4254).
*/
#include
#include
#include
#include
#include
#include
#include
extern char *ptsname(int);
#include "byte.h"
#include "bug.h"
#include "newenv.h"
#include "e.h"
#include "purge.h"
#include "connectioninfo.h"
#include "iptostr.h"
#include "porttostr.h"
#include "buf.h"
#include "str.h"
#include "logsys.h"
#include "loginshell.h"
#include "trymlock.h"
#include "limit.h"
#include "channel.h"
/*
1. channel not open: maxpacket == 0, pid == 0
2. channel open: maxpacket != 0, pid == 0
3. child executed: maxpacket != 0, pid > 0, fd[01] != -1
4. child eof: maxpacket != 0, pid > 0, fd[12] == -1
5. child died: maxpacket != 0, pid == -1
*/
struct channel channel = {0};
/*
The 'channel_open' function opens the channel.
It sets 'localwindow' and maxpacket, values obtained from
from SSH_MSG_CHANNEL_OPEN message.
Function also obtaines connection information and sets
environment variables PATH, SSH_CONNECTION and MAIL.
*/
int channel_open(const char *user, crypto_uint32 id, crypto_uint32 remotewindow,
crypto_uint32 maxpacket, crypto_uint32 *localwindow) {
struct buf b = {channel.buf0, 0, CHANNEL_BUFSIZE};
if (!localwindow) bug_inval();
if (!maxpacket) bug_inval();
if (!remotewindow) bug_inval();
if (channel.maxpacket != 0) return 0;
if (channel.pid != 0) return 0;
/* copy user-name */
if (!str_copyn(channel.user, sizeof channel.user, user)) bug_nomem();
/* set id, maxpacket, remotewindow, localwindow */
channel.id = id;
channel.maxpacket = maxpacket;
channel.remotewindow = remotewindow;
channel.localwindow = *localwindow = CHANNEL_BUFSIZE;
/* copy PATH */
if (!newenv_copyenv("PATH")) {
if (!newenv_env("PATH", "/bin:/usr/bin")) return 0;
}
/* create env. SSH_CONNECTION */
connectioninfo(channel.localip, channel.localport, channel.remoteip,
channel.remoteport);
buf_purge(&b);
buf_puts(&b, channel.remoteip);
buf_puts(&b, " ");
buf_puts(&b, channel.remoteport);
buf_puts(&b, " ");
buf_puts(&b, channel.localip);
buf_puts(&b, " ");
buf_puts(&b, channel.localport);
buf_putnum8(&b, 0);
if (!newenv_env("SSH_CONNECTION", (char *) b.buf)) return 0;
#ifdef _PATH_MAILDIR
/* create env. MAIL */
buf_purge(&b);
buf_puts(&b, _PATH_MAILDIR);
buf_puts(&b, "/");
buf_puts(&b, user);
buf_putnum8(&b, 0);
if (!newenv_env("MAIL", (char *) b.buf)) return 0;
#endif
purge(channel.buf0, sizeof channel.buf0);
return 1;
}
/*
The 'channel_openterminal' function opens terminal,
sets environment variable TERM and initial terminal windowsize.
*/
int channel_openterminal(const char *name, crypto_uint32 a, crypto_uint32 b,
crypto_uint32 x, crypto_uint32 y) {
if (channel.maxpacket == 0) bug_proto();
if (channel.pid != 0) bug_proto();
if (channel.flagterminal == 1) bug_proto();
if (!channel_openpty(&channel.master, &channel.slave)) return 0;
if (!newenv_env("TERM", name)) return 0;
channel.flagterminal = 1;
channel.a = a;
channel.b = b;
channel.x = x;
channel.y = y;
return 1;
}
/*
The 'channel_ptyresize' function sets new
terminal windowsize.
*/
void channel_ptyresize(crypto_uint32 a, crypto_uint32 b, crypto_uint32 x,
crypto_uint32 y) {
struct winsize w;
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) bug_proto();
if (!a && !b && !x && !y) return;
w.ws_col = a;
w.ws_row = b;
w.ws_xpixel = x;
w.ws_ypixel = y;
ioctl(channel.fd0, TIOCSWINSZ, &w);
}
/*
The 'channel_env' adds new environment variable
sent from client.
*/
int channel_env(const char *x, const char *y) {
if (channel.maxpacket == 0) bug_proto();
if (channel.pid != 0) bug_proto();
if (!x || !y) bug_inval();
return newenv_lowenv(x, y);
}
/*
The 'channel_exec' function executes new process.
If terminal is requsted, than users shell is executed,
if exec is requested, than command 'cmd' is executed.
Process is executed under appropriate users UID.
*/
int channel_exec(const char *cmd) {
char *run[4];
char *shell;
char *name;
int fd[3];
char ln[NAME_MAX + 2];
if (channel.maxpacket == 0) bug_proto();
if (channel.pid != 0) bug_proto();
if (channel.flagterminal) {
channel.pid = channel_forkpty(fd, channel.master, channel.slave);
if (channel.pid > 0) {
name = ptsname(fd[0]);
if (!name) bug();
if (!str_copyn(channel.termname, sizeof channel.termname, name))
bug_nomem();
}
}
else { channel.pid = channel_fork(fd); }
if (channel.pid == -1) return 0;
if (channel.pid == 0) {
logsys_login(channel.user, channel.remoteip, 0, 0);
if (!channel_droppriv(channel.user, &shell)) _exit(111);
if (cmd) {
run[0] = shell;
run[1] = (char *) "-c";
run[2] = (char *) cmd;
run[3] = 0;
}
else {
if (!loginshell(ln, sizeof ln, shell)) bug();
run[0] = ln;
run[1] = 0;
}
signal(SIGPIPE, SIG_DFL);
newenv_exec(shell, run);
_exit(111);
}
channel.fd0 = fd[0];
channel.fd1 = fd[1];
channel.fd2 = fd[2];
channel.len0 = 0;
newenv_purge();
if (channel.flagterminal && channel.pid > 0) {
channel_ptyresize(channel.a, channel.b, channel.x, channel.y);
}
return 1;
}
/*
The 'channel_put' function adds data from
client to childs buffer.
*/
void channel_put(unsigned char *buf, long long len) {
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) bug_proto();
if (channel.fd0 == -1) bug_proto();
if (!buf || len < 0) bug_inval();
if (channel.len0 + len > CHANNEL_BUFSIZE) bug_nomem();
byte_copy(channel.buf0 + channel.len0, len, buf);
channel.len0 += len;
channel.localwindow -= len;
}
/*
The 'channel_puteof' function adds information
that remote side closed standard output.
*/
void channel_puteof(void) {
if (channel.maxpacket == 0) bug_proto();
if (channel.pid == 0) bug_proto();
if (channel.fd0 == -1) bug_proto();
channel.remoteeof = 1;
if (channel.len0 == 0 && !channel.flagterminal) {
close(channel.fd0);
channel.fd0 = -1;
}
}
/*
The 'channel_putisready' function returns
if child is ready accept data.
*/
int channel_putisready(void) {
if (channel.maxpacket == 0) return 0;
if (channel.pid <= 0) return 0;
if (channel.fd0 == -1) return 0;
return (CHANNEL_BUFSIZE > channel.len0);
}
/*
The 'channel_read' function reads
data from childs standard output.
*/
long long channel_read(unsigned char *buf, long long len) {
long long r;
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) bug_proto();
if (channel.fd1 == -1) bug_proto();
if (!buf || len < 0) bug_inval();
if (channel.remotewindow <= 0) return 0;
r = len;
if (r > 1048576) r = 1048576;
if (r > channel.remotewindow) r = channel.remotewindow;
r = read(channel.fd1, buf, r);
if (r == -1) {
if (errno == EINTR) return 0;
if (errno == EAGAIN) return 0;
if (errno == EWOULDBLOCK) return 0;
}
if (r <= 0) {
channel.fd1 = -1;
return 0;
}
channel.remotewindow -= r;
return r;
}
/*
The 'channel_extendedread' function reads
data from childs error output.
*/
long long channel_extendedread(unsigned char *buf, long long len) {
long long r;
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) bug_proto();
if (channel.fd2 == -1) bug_proto();
if (!buf || len < 0) bug_inval();
if (channel.remotewindow <= 0) return 0;
r = len;
if (r > 1048576) r = 1048576;
if (r > channel.remotewindow) r = channel.remotewindow;
r = read(channel.fd2, buf, r);
if (r == -1) {
if (errno == EINTR) return 0;
if (errno == EAGAIN) return 0;
if (errno == EWOULDBLOCK) return 0;
}
if (r <= 0) {
channel.fd2 = -1;
return 0;
}
channel.remotewindow -= r;
return r;
}
/*
The 'channel_readisready' function returns
if we can read data from childs standard output.
*/
int channel_readisready(void) {
if (channel.maxpacket == 0 || channel.pid == 0) return 0;
if (channel.fd1 == -1) return 0;
return (channel.remotewindow > 0);
}
/*
The 'channel_extendedreadisready' function returns
if we can read data from childs error output.
*/
int channel_extendedreadisready(void) {
if (channel.maxpacket == 0 || channel.pid == 0) return 0;
if (channel.fd2 == -1) return 0;
return (channel.remotewindow > 0);
}
/*
The 'channel_write' function writes
data to childs standard input.
*/
int channel_write(void) {
long long w;
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) bug_proto();
if (channel.fd0 == -1) bug_proto();
if (channel.len0 <= 0) return 1;
w = write(channel.fd0, channel.buf0, channel.len0);
if (w == -1) {
if (errno == EINTR) return 1;
if (errno == EAGAIN) return 1;
if (errno == EWOULDBLOCK) return 1;
}
if (w <= 0) {
channel.fd0 = -1;
return 0;
}
byte_copy(channel.buf0, channel.len0 - w, channel.buf0 + w);
purge(channel.buf0 + channel.len0 - w, w);
channel.len0 -= w;
if (channel.remoteeof && channel.len0 == 0 && !channel.flagterminal) {
close(channel.fd0);
channel.fd0 = -1;
}
return 1;
}
/*
The 'channel_writeisready' function returns
if we can write data to childs standard input.
*/
int channel_writeisready(void) {
if (channel.maxpacket == 0) return 0;
if (channel.pid <= 0) return 0;
if (channel.fd0 == -1) return 0;
return (channel.len0 > 0);
}
/*
The 'channel_iseof' function returns
if child closed standard and error output.
*/
int channel_iseof(void) {
if (channel.maxpacket == 0) return 0;
if (channel.pid == 0) return 0;
if (channel.pid == -1) return 1;
return (channel.fd1 == -1 && channel.fd2 == -1);
}
/*
The 'channel_waitnohang' function returns
if child exited or was killed.
*/
int channel_waitnohang(int *s, int *e) {
int r, status;
if (!s || !e) bug_inval();
if (channel.maxpacket == 0) bug_proto();
if (channel.pid <= 0) return 0;
do {
r = waitpid(channel.pid, &status, WNOHANG);
} while (r == -1 && errno == EINTR);
if (r <= 0) return 0;
if (channel.flagterminal) {
logsys_logout(channel.user, channel.remoteip, channel.termname,
channel.pid);
}
if (WIFEXITED(status)) {
*e = WEXITSTATUS(status);
*s = 0;
}
else if (WIFSIGNALED(status)) {
*e = 0;
*s = WTERMSIG(status);
}
else { *e = *s = -1; }
channel.pid = -1;
return 1;
}
/*
Remove sentitive data from allocated memory.
*/
void channel_purge(void) {
purge(&channel, sizeof channel);
trymunlock(&channel, sizeof channel);
}
/*
Initialize channel structure.
*/
void channel_init(void) {
trymlock(&channel, sizeof channel);
purge(&channel, sizeof channel);
channel.maxpacket = 0;
channel.remoteeof = 0;
channel.len0 = 0;
channel.pid = 0;
channel.flagterminal = 0;
channel.master = -1;
channel.slave = -1;
}
int channel_getfd0(void) { return channel.fd0; }
int channel_getfd1(void) { return channel.fd1; }
int channel_getfd2(void) { return channel.fd2; }
long long channel_getlen0(void) { return channel.len0; }
crypto_uint32 channel_getid(void) { return channel.id; }
crypto_uint32 channel_getlocalwindow(void) { return channel.localwindow; }
void channel_incrementremotewindow(crypto_uint32 x) {
channel.remotewindow += x;
}
void channel_incrementlocalwindow(crypto_uint32 x) { channel.localwindow += x; }
tinyssh-20250201/channel.h 0000664 0000000 0000000 00000005310 14747360755 0015252 0 ustar 00root root 0000000 0000000 #ifndef CHANNEL_H____
#define CHANNEL_H____
#include "crypto_uint32.h"
#include "iptostr.h"
#include "porttostr.h"
#include "limit.h"
#define CHANNEL_BUFSIZE 131072
struct channel {
/* channel */
crypto_uint32 maxpacket;
crypto_uint32 id;
crypto_uint32 localwindow;
crypto_uint32 remotewindow;
/* child */
unsigned char buf0[CHANNEL_BUFSIZE];
long long len0;
long long pid;
int fd0;
int fd1;
int fd2;
int status;
/* ip */
char localip[IPTOSTR_LEN];
char localport[PORTTOSTR_LEN];
char remoteip[IPTOSTR_LEN];
char remoteport[PORTTOSTR_LEN];
/* terminal */
char user[LOGIN_NAME_MAX + 1];
char termname[TTY_NAME_MAX + 1];
int flagterminal;
int master;
int slave;
int a;
int b;
int x;
int y;
/* channel */
int remoteeof;
};
extern struct channel channel;
/* channel_drop.c */
extern int channel_droppriv(char *, char **);
/* channel_fork.c */
extern long long channel_fork(int[3]);
/* channel_forkpty.c */
extern long long channel_forkpty(int[3], int, int);
extern int channel_openpty(int *, int *);
/* channel.c */
extern void channel_purge(void);
extern int channel_open(const char *, crypto_uint32, crypto_uint32,
crypto_uint32, crypto_uint32 *);
extern int channel_openterminal(const char *, crypto_uint32, crypto_uint32,
crypto_uint32, crypto_uint32);
extern void channel_ptyresize(crypto_uint32, crypto_uint32, crypto_uint32,
crypto_uint32);
extern int channel_env(const char *, const char *);
extern int channel_exec(const char *);
extern void channel_put(unsigned char *, long long);
extern void channel_puteof(void);
extern int channel_putisready(void);
extern long long channel_read(unsigned char *, long long);
extern long long channel_extendedread(unsigned char *, long long);
extern int channel_readisready(void);
extern int channel_extendedreadisready(void);
extern int channel_write(void);
extern int channel_writeisready(void);
extern int channel_iseof(void);
extern int channel_waitnohang(int *, int *);
extern void channel_purge(void);
extern void channel_init(void);
extern int channel_getfd0(void);
extern int channel_getfd1(void);
extern int channel_getfd2(void);
extern long long channel_getlen0(void);
extern crypto_uint32 channel_getid(void);
extern crypto_uint32 channel_getlocalwindow(void);
extern void channel_incrementremotewindow(crypto_uint32);
extern void channel_incrementlocalwindow(crypto_uint32);
/* channel subsystem.c */
#define CHANNEL_SUBSYSTEM_MAX 64
extern int channel_subsystem_add(const char *);
extern const char *channel_subsystem_get(const char *);
extern void channel_subsystem_log(void);
#endif
tinyssh-20250201/channel_drop.c 0000664 0000000 0000000 00000002000 14747360755 0016262 0 ustar 00root root 0000000 0000000 /*
20140129
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include "dropuidgid.h"
#include "newenv.h"
#include "channel.h"
int channel_droppriv(char *user, char **shell) {
struct passwd *pw;
char *name;
pw = getpwnam(user);
if (!pw) return 0;
if (isatty(0)) {
name = ttyname(0);
if (!name) return 0;
if (!newenv_env("SSH_TTY", name)) return 0;
/* setowner */
if (chown(name, pw->pw_uid, pw->pw_gid) == -1) return 0;
if (chmod(name, 0600) == -1) return 0;
}
/* drop privileges */
if (!dropuidgid(pw->pw_name, pw->pw_uid, pw->pw_gid)) return 0;
if (chdir(pw->pw_dir) == -1) return 0;
if (!newenv_env("HOME", pw->pw_dir)) return 0;
if (!newenv_env("USER", pw->pw_name)) return 0;
if (!newenv_env("LOGNAME", pw->pw_name)) return 0;
if (!newenv_env("LOGIN", pw->pw_name)) return 0;
if (!newenv_env("SHELL", pw->pw_shell)) return 0;
*shell = pw->pw_shell;
return 1;
}
tinyssh-20250201/channel_fork.c 0000664 0000000 0000000 00000002246 14747360755 0016273 0 ustar 00root root 0000000 0000000 /*
20140129
20241209 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include
#include "blocking.h"
#include "open.h"
#include "channel.h"
/*
The 'channel_fork' function is used to create a new process.
Function creates 3 pipes from/to child:
fd[0] is pipe to childs standard input
fd[1] is pipe from childs standard output
fd[2] is pipe from childs error output
Function returns also childs PID.
*/
long long channel_fork(int fd[3]) {
int pi[2], pa[3], ch[3];
long long i, pid;
for (i = 0; i < 3; ++i) pa[i] = ch[i] = fd[i] = -1;
for (i = 0; i < 3; ++i) {
if (open_pipe(pi) == -1) goto cleanup;
pa[i] = pi[i ? 0 : 1];
ch[i] = pi[i ? 1 : 0];
}
pid = fork();
if (pid == -1) goto cleanup;
if (pid == 0) {
for (i = 0; i < 3; ++i) {
close(pa[i]);
close(i);
blocking_enable(ch[i]);
if (dup(ch[i]) != i) _exit(111);
}
return 0;
}
for (i = 0; i < 3; ++i) {
close(ch[i]);
fd[i] = pa[i];
}
return pid;
cleanup:
for (i = 0; i < 3; ++i) {
close(pa[i]);
close(ch[i]);
}
return -1;
}
tinyssh-20250201/channel_forkpty.c 0000664 0000000 0000000 00000007753 14747360755 0017040 0 ustar 00root root 0000000 0000000 /*
20150212
20241209 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include
#if defined(sun) || defined(__hpux)
#include
#endif
#include
#include
#include
#include
#include
extern char *ptsname(int);
extern int grantpt(int);
extern int unlockpt(int);
#include "hasopenpty.h"
#ifdef HASOPENPTY
extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
#endif
#include "haslogintty.h"
#ifdef HASLOGINTTY
extern int login_tty(int);
#endif
#include "e.h"
#include "coe.h"
#include "blocking.h"
#include "global.h"
#include "channel.h"
#ifndef HASLOGINTTY
static int login_tty_(int fd) {
char *name;
setsid();
#ifdef TIOCSCTTY
if (ioctl(fd, TIOCSCTTY, (char *) 0) == -1) return -1;
#endif
name = ttyname(fd);
if (!name) return -1;
#ifndef TIOCSCTTY
if (fd != 0) close(0);
if (fd != 1) close(1);
if (fd != 2) close(2);
close(open(name, O_RDWR));
#endif
if (dup2(fd, 0) == -1) return -1;
if (dup2(fd, 1) == -1) return -1;
if (dup2(fd, 2) == -1) return -1;
if (fd > 2) close(fd);
return 0;
}
#endif
#ifndef HASOPENPTY
static int openpty_(int *amaster, int *aslave) {
int master = -1, slave = -1;
char *slave_name;
static const char *fn[] = {"/dev/ptmx", "/dev/ptc", 0};
long long i;
for (i = 0; fn[i]; ++i) {
master = open(fn[i], O_RDWR | O_NOCTTY);
if (master != -1) break;
}
if (master == -1) return -1;
if (grantpt(master) == -1) {
close(master);
return -1;
}
if (unlockpt(master) == -1) {
close(master);
return -1;
}
slave_name = ptsname(master);
if (!slave_name) {
close(master);
return -1;
}
slave = open(slave_name, O_RDWR | O_NOCTTY);
if (slave == -1) {
close(master);
return -1;
}
#if defined(sun) || defined(__hpux)
ioctl(slave, I_PUSH, "ptem");
ioctl(slave, I_PUSH, "ldterm");
#endif
#if defined(sun)
ioctl(slave, I_PUSH, "ttcompat");
#endif
if (amaster) *amaster = master;
if (aslave) *aslave = slave;
return 0;
}
#endif
int channel_openpty(int *amaster, int *aslave) {
#ifdef HASOPENPTY
if (openpty(amaster, aslave, 0, 0, 0) == -1) return 0;
#else
if (openpty_(amaster, aslave) == -1) return 0;
#endif
if (!ttyname(*aslave)) {
close(*amaster);
close(*aslave);
return 0;
}
return 1;
}
/*
The 'channel_forkpty' function is used to create a new process
operating in a pseudoterminal. Function sets 3 integers in 'fd[3]':
fd[0] and fd[1] is pseudoterminal fd
fd[2] is always -1
*/
long long channel_forkpty(int fd[3], int master, int slave) {
long long pid, r;
char ch;
int pi[2];
if (!ttyname(slave)) return -1;
if (pipe(pi) == -1) return -1;
fd[0] = fd[1] = master;
fd[2] = -1;
pid = fork();
switch (pid) {
case -1:
close(pi[0]);
close(pi[1]);
close(slave);
close(master);
return -1;
case 0:
close(master);
close(pi[0]);
#ifdef HASLOGINTTY
if (login_tty(slave) == -1) global_die(111);
#else
if (login_tty_(slave) == -1) global_die(111);
#endif
/* Trigger a read event on the other side of the pipe. */
do { r = write(pi[1], "", 1); } while (r == -1 && errno == EINTR);
close(pi[1]);
return 0;
default:
close(pi[1]);
coe_enable(master);
blocking_disable(master);
/*
Wait until child calls login_tty(slave), so that we can safely
close(slave). Fixes race condition between close(slave) in parent
and login_tty(slave) in child process.
*/
do {
r = read(pi[0], &ch, sizeof ch);
} while (r == -1 && errno == EINTR);
close(pi[0]);
close(slave);
return pid;
}
}
tinyssh-20250201/channel_subsystem.c 0000664 0000000 0000000 00000002073 14747360755 0017366 0 ustar 00root root 0000000 0000000 /*
20150114
20241209 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include "str.h"
#include "log.h"
#include "e.h"
#include "channel.h"
static long long channel_subsystem_pos = 0;
static const char *channel_subsystem[CHANNEL_SUBSYSTEM_MAX] = {0};
int channel_subsystem_add(const char *x) {
if (channel_subsystem_pos >= CHANNEL_SUBSYSTEM_MAX) return 0;
channel_subsystem[channel_subsystem_pos++] = x;
return 1;
}
const char *channel_subsystem_get(const char *x) {
long long len, i;
if (!x) return 0;
len = str_len(x);
for (i = 0; i < CHANNEL_SUBSYSTEM_MAX; ++i) {
if (!channel_subsystem[i]) break;
if (str_start(channel_subsystem[i], x)) {
if (channel_subsystem[i][len] == '=') {
return channel_subsystem[i] + len + 1;
}
}
}
return 0;
}
void channel_subsystem_log(void) {
long long i;
for (i = 0; i < CHANNEL_SUBSYSTEM_MAX; ++i) {
if (!channel_subsystem[i]) break;
log_d3("subsystem: ", channel_subsystem[i], " registered");
}
}
tinyssh-20250201/cleanup.c 0000664 0000000 0000000 00000000372 14747360755 0015267 0 ustar 00root root 0000000 0000000 #include "cleanup.h"
void cleanup_(void *yv, long long ylen) {
volatile char *y = (volatile char *) yv;
while (ylen > 0) {
*y++ = 0;
--ylen;
}
#ifdef __GNUC__
__asm__ __volatile__("" : : "r"(yv) : "memory");
#endif
}
tinyssh-20250201/cleanup.h 0000664 0000000 0000000 00000000212 14747360755 0015265 0 ustar 00root root 0000000 0000000 #ifndef CLEANUP_H____
#define CLEANUP_H____
extern void cleanup_(void *, long long);
#define cleanup(x) cleanup_((x), sizeof(x))
#endif
tinyssh-20250201/coe.c 0000664 0000000 0000000 00000000533 14747360755 0014405 0 ustar 00root root 0000000 0000000 /*
20241112
*/
#include
#include "coe.h"
/*
The 'coe_enable(fd)' function enables
the close-on-exec flag on a file-descriptor 'fd'.
*/
void coe_enable(int fd) { fcntl(fd, F_SETFD, 1); }
/*
The 'coe_disable(fd)' function disables
the close-on-exec flag on a file-descriptor 'fd'.
*/
void coe_disable(int fd) { fcntl(fd, F_SETFD, 0); }
tinyssh-20250201/coe.h 0000664 0000000 0000000 00000000150 14747360755 0014405 0 ustar 00root root 0000000 0000000 #ifndef COE_H____
#define COE_H____
extern void coe_enable(int);
extern void coe_disable(int);
#endif
tinyssh-20250201/connectioninfo.c 0000664 0000000 0000000 00000007635 14747360755 0016664 0 ustar 00root root 0000000 0000000 /*
20140131
20241215 - reformated using clang-format
Jan Mojzis
Public domain.
*/
#include
#include
#include
#include
#include
#include "e.h"
#include "byte.h"
#include "iptostr.h"
#include "porttostr.h"
#include "env.h"
#include "str.h"
#include "connectioninfo.h"
/*
The connectioninfo_fromfd function gets
informations about TCP connection from
getsockname(), getpeername() libc functions.
*/
static int connectioninfo_fromfd(char *localip, char *localport, char *remoteip,
char *remoteport) {
long long i;
struct sockaddr_storage sa;
socklen_t salen;
int fd = 0;
unsigned char ip[16];
unsigned char port[2];
char *ipstr[2];
char *portstr[2];
int (*op[2])(int, struct sockaddr *, socklen_t *) = {getsockname,
getpeername};
ipstr[0] = localip;
portstr[0] = localport;
ipstr[1] = remoteip;
portstr[1] = remoteport;
for (i = 0; i < 2; ++i) {
salen = sizeof sa;
if (op[i](fd, (struct sockaddr *) &sa, &salen) == -1) return 0;
if (sa.ss_family == PF_INET) {
struct sockaddr_in *sin = (struct sockaddr_in *) &sa;
byte_copy(ip, 12, "\0\0\0\0\0\0\0\0\0\0\377\377");
byte_copy(ip + 12, 4, &sin->sin_addr);
byte_copy(port, 2, &sin->sin_port);
}
#ifdef PF_INET6
else if (sa.ss_family == PF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) &sa;
byte_copy(ip, 16, &sin6->sin6_addr);
byte_copy(port, 2, &sin6->sin6_port);
}
#endif
else {
errno = EPROTONOSUPPORT;
return 0;
}
iptostr(ipstr[i], ip);
porttostr(portstr[i], port);
}
return 1;
}
static int env(char *y, long long ylen, const char *e) {
char *x;
x = env_get(e);
if (!x) return 0;
if (!str_copyn(y, ylen, x)) return 0;
return 1;
}
/*
The connectioninfo_fromtcpserverenv function gets
informations about TCP connection from environment.
*/
static int connectioninfo_fromtcpserverenv(char *localip, char *localport,
char *remoteip, char *remoteport) {
if (!env(localip, IPTOSTR_LEN, "TCPLOCALIP")) return 0;
if (!env(localport, PORTTOSTR_LEN, "TCPLOCALPORT")) return 0;
if (!env(remoteip, IPTOSTR_LEN, "TCPREMOTEIP")) return 0;
if (!env(remoteport, PORTTOSTR_LEN, "TCPREMOTEPORT")) return 0;
return 1;
}
/*
The connectioninfo_fromcurvecpserverenv function gets
informations about CurveCP connection from environment.
*/
static int connectioninfo_fromcurvecpserverenv(char *localip, char *localport,
char *remoteip,
char *remoteport) {
if (!env(localip, IPTOSTR_LEN, "CURVECPLOCALIP")) return 0;
if (!env(localport, PORTTOSTR_LEN, "CURVECPLOCALPORT")) return 0;
if (!env(remoteip, IPTOSTR_LEN, "CURVECPREMOTEIP")) return 0;
if (!env(remoteport, PORTTOSTR_LEN, "CURVECPREMOTEPORT")) return 0;
return 1;
}
#define unknown "unknown"
#define port0 "0"
/*
The connectioninfo function gets informations about TCP/CurveCP connection.
*/
void connectioninfo(char *localip, char *localport, char *remoteip,
char *remoteport) {
if (connectioninfo_fromtcpserverenv(localip, localport, remoteip,
remoteport))
return;
if (connectioninfo_fromcurvecpserverenv(localip, localport, remoteip,
remoteport))
return;
if (connectioninfo_fromfd(localip, localport, remoteip, remoteport)) return;
byte_copy(localip, sizeof unknown, unknown);
byte_copy(remoteip, sizeof unknown, unknown);
byte_copy(localport, sizeof port0, port0);
byte_copy(remoteport, sizeof port0, port0);
return;
}
tinyssh-20250201/connectioninfo.h 0000664 0000000 0000000 00000000177 14747360755 0016663 0 ustar 00root root 0000000 0000000 #ifndef CONNECTIONINFO_H____
#define CONNECTIONINFO_H____
extern void connectioninfo(char *, char *, char *, char *);
#endif
tinyssh-20250201/crypto.h 0000664 0000000 0000000 00000001505 14747360755 0015164 0 ustar 00root root 0000000 0000000 /* allways include local versions */
#include "crypto_int16.h"
#include "crypto_int32.h"
#include "crypto_int64.h"
#include "crypto_int8.h"
#include "crypto_uint16.h"
#include "crypto_uint32.h"
#include "crypto_uint64.h"
#include "crypto_uint8.h"
#include "crypto_verify_16.h"
#include "crypto_verify_32.h"
/* include randombytes from librandombytes */
#include "haslibrandombytes.h"
#ifdef HASLIBRANDOMBYTES
#include
#else
#include "randombytes.h"
#endif
/* TODO */
#include "crypto_hash_sha256.h"
#include "crypto_hash_sha512.h"
#include "crypto_kem_sntrup761.h"
#include "crypto_kem_sntrup761x25519.h"
#include "crypto_onetimeauth_poly1305.h"
#include "crypto_scalarmult_curve25519.h"
#include "crypto_dh_x25519.h"
#include "crypto_sign_ed25519.h"
#include "crypto_sort_uint32.h"
#include "crypto_stream_chacha20.h"
tinyssh-20250201/crypto_declassify.h 0000664 0000000 0000000 00000000664 14747360755 0017377 0 ustar 00root root 0000000 0000000 #ifndef crypto_declassify_h
#define crypto_declassify_h
#include "hasvalgrind.h"
#ifdef HASVALGRIND
#include
#define crypto_declassify_uses_valgrind 1
static void crypto_declassify(void *xv, long long xlen) {
VALGRIND_MAKE_MEM_DEFINED(xv, xlen);
}
#else
#define crypto_declassify_uses_valgrind 0
static void crypto_declassify(void *xv, long long xlen) {
(void) xv;
(void) xlen;
}
#endif
#endif
tinyssh-20250201/crypto_dh_x25519.c 0000664 0000000 0000000 00000001556 14747360755 0016575 0 ustar 00root root 0000000 0000000 #include "crypto_dh_x25519.h"
#include "haslib25519.h"
#ifdef HASLIB25519
#include
int crypto_dh_x25519_lib25519(unsigned char *k, const unsigned char *pk,
const unsigned char *sk) {
lib25519_dh_x25519(k, pk, sk);
return 0;
}
int crypto_dh_x25519_lib25519_keypair(unsigned char *pk, unsigned char *sk) {
lib25519_dh_x25519_keypair(pk, sk);
return 0;
}
#else
#include "randombytes.h"
#include "crypto_scalarmult_curve25519.h"
int crypto_dh_x25519_tinyssh(unsigned char *k, const unsigned char *pk,
const unsigned char *sk) {
return crypto_scalarmult_curve25519(k, sk, pk);
}
static const unsigned char basepoint[32] = {9};
int crypto_dh_x25519_tinyssh_keypair(unsigned char *q, unsigned char *n) {
randombytes(n, 32);
return crypto_dh_x25519(q, basepoint, n);
}
#endif
tinyssh-20250201/crypto_dh_x25519.h 0000664 0000000 0000000 00000003551 14747360755 0016577 0 ustar 00root root 0000000 0000000 #ifndef crypto_dh_x25519_H
#define crypto_dh_x25519_H
#include "haslib25519.h"
#ifdef HASLIB25519
#include
#define crypto_dh_x25519_lib25519_BYTES lib25519_dh_x25519_BYTES
#define crypto_dh_x25519_lib25519_PUBLICKEYBYTES \
lib25519_dh_x25519_PUBLICKEYBYTES
#define crypto_dh_x25519_lib25519_SECRETKEYBYTES \
lib25519_dh_x25519_SECRETKEYBYTES
extern int crypto_dh_x25519_lib25519(unsigned char *, const unsigned char *,
const unsigned char *);
extern int crypto_dh_x25519_lib25519_keypair(unsigned char *, unsigned char *);
#define crypto_dh_x25519 crypto_dh_x25519_lib25519
#define crypto_dh_x25519_keypair crypto_dh_x25519_lib25519_keypair
#define crypto_dh_x25519_BYTES crypto_dh_x25519_lib25519_BYTES
#define crypto_dh_x25519_PUBLICKEYBYTES crypto_dh_x25519_lib25519_PUBLICKEYBYTES
#define crypto_dh_x25519_SECRETKEYBYTES crypto_dh_x25519_lib25519_SECRETKEYBYTES
#define crypto_dh_x25519_IMPLEMENTATION "lib25519"
#define crypto_dh_x25519_VERSION lib25519_version
#else
#define crypto_dh_x25519_tinyssh_BYTES 32
#define crypto_dh_x25519_tinyssh_PUBLICKEYBYTES 32
#define crypto_dh_x25519_tinyssh_SECRETKEYBYTES 32
extern int crypto_dh_x25519_tinyssh(unsigned char *, const unsigned char *,
const unsigned char *);
extern int crypto_dh_x25519_tinyssh_keypair(unsigned char *, unsigned char *);
#define crypto_dh_x25519 crypto_dh_x25519_tinyssh
#define crypto_dh_x25519_keypair crypto_dh_x25519_tinyssh_keypair
#define crypto_dh_x25519_BYTES crypto_dh_x25519_tinyssh_BYTES
#define crypto_dh_x25519_PUBLICKEYBYTES crypto_dh_x25519_tinyssh_PUBLICKEYBYTES
#define crypto_dh_x25519_SECRETKEYBYTES crypto_dh_x25519_tinyssh_SECRETKEYBYTES
#define crypto_dh_x25519_IMPLEMENTATION "tinyssh"
#define crypto_dh_x25519_VERSION "-"
#endif
#endif
tinyssh-20250201/crypto_hash_sha256.c 0000664 0000000 0000000 00000005622 14747360755 0017256 0 ustar 00root root 0000000 0000000 /*
20241208
*/
#include "crypto_uint32.h"
#include "crypto_uint64.h"
#include "crypto_hash_sha256.h"
#define R(x, c) (((x) >> (c)) | ((x) << (32 - (c))))
#define Ch(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define Sigma0(x) (R((x), 2) ^ R((x), 13) ^ R((x), 22))
#define Sigma1(x) (R((x), 6) ^ R((x), 11) ^ R((x), 25))
#define sigma0(x) (R((x), 7) ^ R((x), 18) ^ ((x) >> 3))
#define sigma1(x) (R((x), 17) ^ R((x), 19) ^ ((x) >> 10))
static const crypto_uint32 K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
static void blocks(crypto_uint32 *z, const unsigned char *m,
unsigned long long n) {
crypto_uint32 b[8], a[8], w[64], t;
long long i, j;
for (i = 0; i < 8; ++i) a[i] = z[i];
while (n >= 64) {
for (i = 0; i < 16; ++i) w[i] = crypto_uint32_load_bigendian(m + 4 * i);
for (i = 16; i < 64; ++i)
w[i] =
(sigma1(w[i - 2]) + w[i - 7] + sigma0(w[i - 15]) + w[i - 16]);
for (i = 0; i < 64; ++i) {
for (j = 0; j < 8; ++j) b[j] = a[j];
t = a[7] + Sigma1(a[4]) + Ch(a[4], a[5], a[6]) + K[i] + w[i];
b[7] = t + Sigma0(a[0]) + Maj(a[0], a[1], a[2]);
b[3] += t;
for (j = 0; j < 8; ++j) a[(j + 1) % 8] = b[j];
}
for (i = 0; i < 8; ++i) {
a[i] += z[i];
z[i] = a[i];
}
m += 64;
n -= 64;
}
}
int crypto_hash_sha256_tinyssh(unsigned char *o, const unsigned char *m,
unsigned long long n) {
unsigned long long i;
unsigned char x[128];
unsigned long long b = n;
crypto_uint32 h[8] = {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
blocks(h, m, n);
m += n;
n &= 63;
m -= n;
for (i = 0; i < sizeof x; ++i) x[i] = 0;
for (i = 0; i < n; ++i) x[i] = m[i];
x[n] = 128;
n = 128 - 64 * (n < 56);
crypto_uint64_store_bigendian(x + n - 8, b << 3);
blocks(h, x, n);
for (i = 0; i < 8; ++i) crypto_uint32_store_bigendian(o + 4 * i, h[i]);
return 0;
}
tinyssh-20250201/crypto_hash_sha256.h 0000664 0000000 0000000 00000000714 14747360755 0017260 0 ustar 00root root 0000000 0000000 #ifndef crypto_hash_sha256_H
#define crypto_hash_sha256_H
#define crypto_hash_sha256_tinyssh_BYTES 32
extern int crypto_hash_sha256_tinyssh(unsigned char *, const unsigned char *,
unsigned long long);
#define crypto_hash_sha256 crypto_hash_sha256_tinyssh
#define crypto_hash_sha256_BYTES crypto_hash_sha256_tinyssh_BYTES
#define crypto_hash_sha256_IMPLEMENTATION "tinyssh"
#define crypto_hash_sha256_VERSION "-"
#endif
tinyssh-20250201/crypto_hash_sha512.h 0000664 0000000 0000000 00000001724 14747360755 0017255 0 ustar 00root root 0000000 0000000 #ifndef crypto_hash_sha512_H
#define crypto_hash_sha512_H
#include "haslib25519.h"
#ifndef HASLIB25519
#define crypto_hash_sha512_tinyssh_BYTES 64
extern int crypto_hash_sha512_tinyssh(unsigned char *, const unsigned char *,
unsigned long long);
#define crypto_hash_sha512 crypto_hash_sha512_tinyssh
#define crypto_hash_sha512_BYTES crypto_hash_sha512_tinyssh_BYTES
#define crypto_hash_sha512_IMPLEMENTATION "tinyssh"
#define crypto_hash_sha512_VERSION "-"
#else
#include
#define crypto_hash_sha512_lib25519_BYTES lib25519_hash_sha512_BYTES
extern int crypto_hash_sha512_lib25519(unsigned char *, const unsigned char *,
unsigned long long);
#define crypto_hash_sha512 crypto_hash_sha512_lib25519
#define crypto_hash_sha512_BYTES crypto_hash_sha512_lib25519_BYTES
#define crypto_hash_sha512_IMPLEMENTATION "lib25519"
#define crypto_hash_sha512_VERSION lib25519_version
#endif
#endif
tinyssh-20250201/crypto_hash_sha512_lib25519.c 0000664 0000000 0000000 00000000441 14747360755 0020477 0 ustar 00root root 0000000 0000000 #include "haslib25519.h"
#ifdef HASLIB25519
#include
#include "crypto_hash_sha512.h"
int crypto_hash_sha512_lib25519(unsigned char *o, const unsigned char *m,
unsigned long long n) {
lib25519_hash_sha512(o, m, n);
return 0;
}
#endif
tinyssh-20250201/crypto_hash_sha512_tinyssh.c 0000664 0000000 0000000 00000010361 14747360755 0021026 0 ustar 00root root 0000000 0000000 /*
20241210
- based on tweetnacl 20140427 (http://tweetnacl.cr.yp.to/software.html)
*/
#include "crypto_hash_sha512.h"
#include "haslib25519.h"
#ifndef HASLIB25519
#include "crypto_uint64.h"
#define R(x, c) (((x) >> (c)) ^ ((x) << (64 - (c))))
#define Ch(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
#define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
#define Sigma0(x) (R((x), 28) ^ R((x), 34) ^ R((x), 39))
#define Sigma1(x) (R((x), 14) ^ R((x), 18) ^ R((x), 41))
#define sigma0(x) (R((x), 1) ^ R((x), 8) ^ ((x) >> 7))
#define sigma1(x) (R((x), 19) ^ R((x), 61) ^ ((x) >> 6))
static const crypto_uint64 K[80] = {
0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL,
0xe9b5dba58189dbbcULL, 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, 0xd807aa98a3030242ULL,
0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL,
0xc19bf174cf692694ULL, 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, 0x2de92c6f592b0275ULL,
0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL,
0xbf597fc7beef0ee4ULL, 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, 0x27b70a8546d22ffcULL,
0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL,
0x92722c851482353bULL, 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, 0xd192e819d6ef5218ULL,
0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL,
0x34b0bcb5e19b48a8ULL, 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, 0x748f82ee5defb2fcULL,
0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL,
0xc67178f2e372532bULL, 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, 0x06f067aa72176fbaULL,
0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL,
0x431d67c49c100d4cULL, 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL};
static void blocks(crypto_uint64 *z, const unsigned char *m, crypto_uint64 n) {
crypto_uint64 b[8], a[8], w[80], t;
long long i, j;
for (i = 0; i < 8; ++i) a[i] = z[i];
while (n >= 128) {
for (i = 0; i < 16; ++i) w[i] = crypto_uint64_load_bigendian(m + 8 * i);
for (i = 16; i < 80; ++i)
w[i] =
(sigma1(w[i - 2]) + w[i - 7] + sigma0(w[i - 15]) + w[i - 16]);
for (i = 0; i < 80; ++i) {
for (j = 0; j < 8; ++j) b[j] = a[j];
t = a[7] + Sigma1(a[4]) + Ch(a[4], a[5], a[6]) + K[i] + w[i];
b[7] = t + Sigma0(a[0]) + Maj(a[0], a[1], a[2]);
b[3] += t;
for (j = 0; j < 8; ++j) a[(j + 1) % 8] = b[j];
}
for (i = 0; i < 8; ++i) {
a[i] += z[i];
z[i] = a[i];
}
m += 128;
n -= 128;
}
}
int crypto_hash_sha512_tinyssh(unsigned char *o, const unsigned char *m,
unsigned long long n) {
unsigned long long i;
unsigned char x[256];
crypto_uint64 b = n;
crypto_uint64 h[8] = {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL};
blocks(h, m, n);
m += n;
n &= 127;
m -= n;
for (i = 0; i < sizeof x; ++i) x[i] = 0;
for (i = 0; i < n; ++i) x[i] = m[i];
x[n] = 128;
n = 256 - 128 * (n < 112);
x[n - 9] = b >> 61;
crypto_uint64_store_bigendian(x + n - 8, b << 3);
blocks(h, x, n);
for (i = 0; i < 8; ++i) crypto_uint64_store_bigendian(o + 8 * i, h[i]);
return 0;
}
#endif
tinyssh-20250201/crypto_kem_sntrup761.h 0000664 0000000 0000000 00000006447 14747360755 0017703 0 ustar 00root root 0000000 0000000 #ifndef crypto_kem_sntrup761_H
#define crypto_kem_sntrup761_H
#include "haslibntruprime.h"
#ifndef HASLIBNTRUPRIME
#define crypto_kem_sntrup761_tinyssh_SECRETKEYBYTES 1763
#define crypto_kem_sntrup761_tinyssh_PUBLICKEYBYTES 1158
#define crypto_kem_sntrup761_tinyssh_CIPHERTEXTBYTES 1039
#define crypto_kem_sntrup761_tinyssh_BYTES 32
extern int crypto_kem_sntrup761_tinyssh_keypair(unsigned char *,
unsigned char *);
extern int crypto_kem_sntrup761_tinyssh_enc(unsigned char *, unsigned char *,
const unsigned char *);
extern int crypto_kem_sntrup761_tinyssh_dec(unsigned char *,
const unsigned char *,
const unsigned char *);
#define crypto_kem_sntrup761_keypair crypto_kem_sntrup761_tinyssh_keypair
#define crypto_kem_sntrup761_enc crypto_kem_sntrup761_tinyssh_enc
#define crypto_kem_sntrup761_dec crypto_kem_sntrup761_tinyssh_dec
#define crypto_kem_sntrup761_SECRETKEYBYTES \
crypto_kem_sntrup761_tinyssh_SECRETKEYBYTES
#define crypto_kem_sntrup761_PUBLICKEYBYTES \
crypto_kem_sntrup761_tinyssh_PUBLICKEYBYTES
#define crypto_kem_sntrup761_CIPHERTEXTBYTES \
crypto_kem_sntrup761_tinyssh_CIPHERTEXTBYTES
#define crypto_kem_sntrup761_BYTES crypto_kem_sntrup761_tinyssh_BYTES
#define crypto_kem_sntrup761_IMPLEMENTATION "tinyssh"
#define crypto_kem_sntrup761_VERSION "-"
#else
#include
#define crypto_kem_sntrup761_libntruprime_SECRETKEYBYTES \
sntrup761_SECRETKEYBYTES
#define crypto_kem_sntrup761_libntruprime_PUBLICKEYBYTES \
sntrup761_PUBLICKEYBYTES
#define crypto_kem_sntrup761_libntruprime_CIPHERTEXTBYTES \
sntrup761_CIPHERTEXTBYTES
#define crypto_kem_sntrup761_libntruprime_BYTES sntrup761_BYTES
extern int crypto_kem_sntrup761_libntruprime_keypair(unsigned char *,
unsigned char *);
extern int crypto_kem_sntrup761_libntruprime_enc(unsigned char *,
unsigned char *,
const unsigned char *);
extern int crypto_kem_sntrup761_libntruprime_dec(unsigned char *,
const unsigned char *,
const unsigned char *);
#define crypto_kem_sntrup761_keypair crypto_kem_sntrup761_libntruprime_keypair
#define crypto_kem_sntrup761_enc crypto_kem_sntrup761_libntruprime_enc
#define crypto_kem_sntrup761_dec crypto_kem_sntrup761_libntruprime_dec
#define crypto_kem_sntrup761_SECRETKEYBYTES \
crypto_kem_sntrup761_libntruprime_SECRETKEYBYTES
#define crypto_kem_sntrup761_PUBLICKEYBYTES \
crypto_kem_sntrup761_libntruprime_PUBLICKEYBYTES
#define crypto_kem_sntrup761_CIPHERTEXTBYTES \
crypto_kem_sntrup761_libntruprime_CIPHERTEXTBYTES
#define crypto_kem_sntrup761_BYTES crypto_kem_sntrup761_libntruprime_BYTES
#define crypto_kem_sntrup761_IMPLEMENTATION "libntruprime"
#define crypto_kem_sntrup761_VERSION "-"
#endif
#endif
tinyssh-20250201/crypto_kem_sntrup761_libntruprime.c 0000664 0000000 0000000 00000001334 14747360755 0022460 0 ustar 00root root 0000000 0000000 #include "haslibntruprime.h"
#ifdef HASLIBNTRUPRIME
#include
#include "crypto_kem_sntrup761.h"
int crypto_kem_sntrup761_libntruprime_keypair(unsigned char *pk,
unsigned char *sk) {
sntrup761_keypair(pk, sk);
return 0;
}
int crypto_kem_sntrup761_libntruprime_enc(unsigned char *c, unsigned char *k,
const unsigned char *pk) {
sntrup761_enc(c, k, pk);
return 0;
}
int crypto_kem_sntrup761_libntruprime_dec(unsigned char *k,
const unsigned char *c,
const unsigned char *sk) {
sntrup761_dec(k, c, sk);
return 0;
}
#endif
tinyssh-20250201/crypto_kem_sntrup761_tinyssh.c 0000664 0000000 0000000 00000070233 14747360755 0021451 0 ustar 00root root 0000000 0000000 #include "crypto_kem_sntrup761.h"
#include "haslibntruprime.h"
#ifndef HASLIBNTRUPRIME
/*
Original code: supercop-20210125/crypto_kem/sntrup761/ref
Modifications (Jan Mojzis):
- source code merged into single file
- crypto_kem renamed to crypto_kem_sntrup761_tinyssh
- crypto_declassify added
*/
/* See https://ntruprime.cr.yp.to/software.html for detailed documentation. */
#include
#include "crypto_uint64.h"
#include "crypto_uint32.h"
#include "crypto_uint16.h"
#include "crypto_int32.h"
#include "crypto_int16.h"
#include "crypto_int8.h"
#include "randombytes.h"
#include "crypto_verify_32.h"
#include "crypto_sort_uint32.h"
#include "crypto_hash_sha512.h"
#include "crypto_declassify.h"
#define uint64 crypto_uint64
#define uint32 crypto_uint32
#define uint16 crypto_uint16
#define int32 crypto_int32
#define int16 crypto_int16
#define int8 crypto_int8
/* uint32.c */
/*
CPU division instruction typically takes time depending on x.
This software is designed to take time independent of x.
Time still varies depending on m; user must ensure that m is constant.
Time also varies on CPUs where multiplication is variable-time.
There could be more CPU issues.
There could also be compiler issues.
*/
static void uint32_divmod_uint14(uint32 *q, uint16 *r, uint32 x, uint16 m) {
uint32 v = 0x80000000;
uint32 qpart;
uint32 mask;
v /= m;
/* caller guarantees m > 0 */
/* caller guarantees m < 16384 */
/* vm <= 2^31 <= vm+m-1 */
/* xvm <= 2^31 x <= xvm+x(m-1) */
*q = 0;
qpart = (x * (uint64) v) >> 31;
/* 2^31 qpart <= xv <= 2^31 qpart + 2^31-1 */
/* 2^31 qpart m <= xvm <= 2^31 qpart m + (2^31-1)m */
/* 2^31 qpart m <= 2^31 x <= 2^31 qpart m + (2^31-1)m + x(m-1) */
/* 0 <= 2^31 newx <= (2^31-1)m + x(m-1) */
/* 0 <= newx <= (1-1/2^31)m + x(m-1)/2^31 */
/* 0 <= newx <= (1-1/2^31)(2^14-1) + (2^32-1)((2^14-1)-1)/2^31 */
x -= qpart * m;
*q += qpart;
/* x <= 49146 */
qpart = (x * (uint64) v) >> 31;
/* 0 <= newx <= (1-1/2^31)m + x(m-1)/2^31 */
/* 0 <= newx <= m + 49146(2^14-1)/2^31 */
/* 0 <= newx <= m + 0.4 */
/* 0 <= newx <= m */
x -= qpart * m;
*q += qpart;
/* x <= m */
x -= m;
*q += 1;
mask = -(x >> 31);
x += mask & (uint32) m;
*q += mask;
/* x < m */
*r = x;
}
uint32 uint32_div_uint14(uint32 x, uint16 m) {
uint32 q;
uint16 r;
uint32_divmod_uint14(&q, &r, x, m);
return q;
}
uint16 uint32_mod_uint14(uint32 x, uint16 m) {
uint32 q;
uint16 r;
uint32_divmod_uint14(&q, &r, x, m);
return r;
}
/* int32.c */
static void int32_divmod_uint14(int32 *q, uint16 *r, int32 x, uint16 m) {
uint32 uq, uq2;
uint16 ur, ur2;
uint32 mask;
uint32_divmod_uint14(&uq, &ur, 0x80000000 + (uint32) x, m);
uint32_divmod_uint14(&uq2, &ur2, 0x80000000, m);
ur -= ur2;
uq -= uq2;
mask = -(uint32) (ur >> 15);
ur += mask & m;
uq += mask;
*r = ur;
*q = uq;
}
int32 int32_div_uint14(int32 x, uint16 m) {
int32 q;
uint16 r;
int32_divmod_uint14(&q, &r, x, m);
return q;
}
uint16 int32_mod_uint14(int32 x, uint16 m) {
int32 q;
uint16 r;
int32_divmod_uint14(&q, &r, x, m);
return r;
}
/* paramsmenu.h */
/* pick one of these three: */
#define SIZE761
#undef SIZE653
#undef SIZE857
/* pick one of these two: */
#define SNTRUP /* Streamlined NTRU Prime */
#undef LPR /* NTRU LPRime */
/* params.h */
#ifndef params_H
#define params_H
/* menu of parameter choices: */
/* what the menu means: */
#if defined(SIZE761)
#define p 761
#define q 4591
#define Rounded_bytes 1007
#ifndef LPR
#define Rq_bytes 1158
#define w 286
#else
#define w 250
#define tau0 2156
#define tau1 114
#define tau2 2007
#define tau3 287
#endif
#elif defined(SIZE653)
#define p 653
#define q 4621
#define Rounded_bytes 865
#ifndef LPR
#define Rq_bytes 994
#define w 288
#else
#define w 252
#define tau0 2175
#define tau1 113
#define tau2 2031
#define tau3 290
#endif
#elif defined(SIZE857)
#define p 857
#define q 5167
#define Rounded_bytes 1152
#ifndef LPR
#define Rq_bytes 1322
#define w 322
#else
#define w 281
#define tau0 2433
#define tau1 101
#define tau2 2265
#define tau3 324
#endif
#else
#error "no parameter set defined"
#endif
#ifdef LPR
#define I 256
#endif
#endif
/* Decode.c */
static void Decode(uint16 *out, const unsigned char *S, const uint16 *M,
long long len) {
if (len == 1) {
if (M[0] == 1)
*out = 0;
else if (M[0] <= 256)
*out = uint32_mod_uint14(S[0], M[0]);
else
*out = uint32_mod_uint14(S[0] + (((uint16) S[1]) << 8), M[0]);
}
if (len > 1) {
uint16 R2[(len + 1) / 2];
uint16 M2[(len + 1) / 2];
uint16 bottomr[len / 2];
uint32 bottomt[len / 2];
long long i;
for (i = 0; i < len - 1; i += 2) {
uint32 m = M[i] * (uint32) M[i + 1];
if (m > 256 * 16383) {
bottomt[i / 2] = 256 * 256;
bottomr[i / 2] = S[0] + 256 * S[1];
S += 2;
M2[i / 2] = (((m + 255) >> 8) + 255) >> 8;
}
else if (m >= 16384) {
bottomt[i / 2] = 256;
bottomr[i / 2] = S[0];
S += 1;
M2[i / 2] = (m + 255) >> 8;
}
else {
bottomt[i / 2] = 1;
bottomr[i / 2] = 0;
M2[i / 2] = m;
}
}
if (i < len) M2[i / 2] = M[i];
Decode(R2, S, M2, (len + 1) / 2);
for (i = 0; i < len - 1; i += 2) {
uint32 r = bottomr[i / 2];
uint32 r1;
uint16 r0;
r += bottomt[i / 2] * R2[i / 2];
uint32_divmod_uint14(&r1, &r0, r, M[i]);
r1 = uint32_mod_uint14(
r1, M[i + 1]); /* only needed for invalid inputs */
*out++ = r0;
*out++ = r1;
}
if (i < len) *out++ = R2[i / 2];
}
}
/* Encode.c */
/* 0 <= R[i] < M[i] < 16384 */
static void Encode(unsigned char *out, const uint16 *R, const uint16 *M,
long long len) {
if (len == 1) {
uint16 r = R[0];
uint16 m = M[0];
while (m > 1) {
*out++ = r;
r >>= 8;
m = (m + 255) >> 8;
}
}
if (len > 1) {
uint16 R2[(len + 1) / 2];
uint16 M2[(len + 1) / 2];
long long i;
for (i = 0; i < len - 1; i += 2) {
uint32 m0 = M[i];
uint32 r = R[i] + R[i + 1] * m0;
uint32 m = M[i + 1] * m0;
while (m >= 16384) {
*out++ = r;
r >>= 8;
m = (m + 255) >> 8;
}
R2[i / 2] = r;
M2[i / 2] = m;
}
if (i < len) {
R2[i / 2] = R[i];
M2[i / 2] = M[i];
}
Encode(out, R2, M2, (len + 1) / 2);
}
}
/* kem.c */
#ifdef LPR
#endif
/* ----- masks */
#ifndef LPR
/* return -1 if x!=0; else return 0 */
static int int16_nonzero_mask(int16 x) {
uint16 u = x; /* 0, else 1...65535 */
uint32 v = u; /* 0, else 1...65535 */
v = -v; /* 0, else 2^32-65535...2^32-1 */
v >>= 31; /* 0, else 1 */
return -v; /* 0, else -1 */
}
#endif
/* return -1 if x<0; otherwise return 0 */
static int int16_negative_mask(int16 x) {
uint16 u = x;
u >>= 15;
return -(int) u;
/* alternative with gcc -fwrapv: */
/* x>>15 compiles to CPU's arithmetic right shift */
}
/* ----- arithmetic mod 3 */
typedef int8 small;
/* F3 is always represented as -1,0,1 */
/* so ZZ_fromF3 is a no-op */
/* x must not be close to top int16 */
static small F3_freeze(int16 x) { return int32_mod_uint14(x + 1, 3) - 1; }
/* ----- arithmetic mod q */
#define q12 ((q - 1) / 2)
typedef int16 Fq;
/* always represented as -q12...q12 */
/* so ZZ_fromFq is a no-op */
/* x must not be close to top int32 */
static Fq Fq_freeze(int32 x) { return int32_mod_uint14(x + q12, q) - q12; }
#ifndef LPR
static Fq Fq_recip(Fq a1) {
int i = 1;
Fq ai = a1;
while (i < q - 2) {
ai = Fq_freeze(a1 * (int32) ai);
i += 1;
}
return ai;
}
#endif
/* ----- Top and Right */
#ifdef LPR
#define tau 16
static int8 Top(Fq C) { return (tau1 * (int32) (C + tau0) + 16384) >> 15; }
static Fq Right(int8 T) { return Fq_freeze(tau3 * (int32) T - tau2); }
#endif
/* ----- small polynomials */
#ifndef LPR
/* 0 if Weightw_is(r), else -1 */
static int Weightw_mask(small *r) {
int weight = 0;
int i;
for (i = 0; i < p; ++i) weight += r[i] & 1;
return int16_nonzero_mask(weight - w);
}
/* R3_fromR(R_fromRq(r)) */
static void R3_fromRq(small *out, const Fq *r) {
int i;
for (i = 0; i < p; ++i) out[i] = F3_freeze(r[i]);
}
/* h = f*g in the ring R3 */
static void R3_mult(small *h, const small *f, const small *g) {
small fg[p + p - 1];
small result;
int i, j;
for (i = 0; i < p; ++i) {
result = 0;
for (j = 0; j <= i; ++j) result = F3_freeze(result + f[j] * g[i - j]);
fg[i] = result;
}
for (i = p; i < p + p - 1; ++i) {
result = 0;
for (j = i - p + 1; j < p; ++j)
result = F3_freeze(result + f[j] * g[i - j]);
fg[i] = result;
}
for (i = p + p - 2; i >= p; --i) {
fg[i - p] = F3_freeze(fg[i - p] + fg[i]);
fg[i - p + 1] = F3_freeze(fg[i - p + 1] + fg[i]);
}
for (i = 0; i < p; ++i) h[i] = fg[i];
}
/* returns 0 if recip succeeded; else -1 */
static int R3_recip(small *out, const small *in) {
small f[p + 1], g[p + 1], v[p + 1], r[p + 1];
int i, loop, delta;
int sign, swap, t;
for (i = 0; i < p + 1; ++i) v[i] = 0;
for (i = 0; i < p + 1; ++i) r[i] = 0;
r[0] = 1;
for (i = 0; i < p; ++i) f[i] = 0;
f[0] = 1;
f[p - 1] = f[p] = -1;
for (i = 0; i < p; ++i) g[p - 1 - i] = in[i];
g[p] = 0;
delta = 1;
for (loop = 0; loop < 2 * p - 1; ++loop) {
for (i = p; i > 0; --i) v[i] = v[i - 1];
v[0] = 0;
sign = -g[0] * f[0];
swap = int16_negative_mask(-delta) & int16_nonzero_mask(g[0]);
delta ^= swap & (delta ^ -delta);
delta += 1;
for (i = 0; i < p + 1; ++i) {
t = swap & (f[i] ^ g[i]);
f[i] ^= t;
g[i] ^= t;
t = swap & (v[i] ^ r[i]);
v[i] ^= t;
r[i] ^= t;
}
for (i = 0; i < p + 1; ++i) g[i] = F3_freeze(g[i] + sign * f[i]);
for (i = 0; i < p + 1; ++i) r[i] = F3_freeze(r[i] + sign * v[i]);
for (i = 0; i < p; ++i) g[i] = g[i + 1];
g[p] = 0;
}
sign = f[0];
for (i = 0; i < p; ++i) out[i] = sign * v[p - 1 - i];
return int16_nonzero_mask(delta);
}
#endif
/* ----- polynomials mod q */
/* h = f*g in the ring Rq */
static void Rq_mult_small(Fq *h, const Fq *f, const small *g) {
Fq fg[p + p - 1];
Fq result;
int i, j;
for (i = 0; i < p; ++i) {
result = 0;
for (j = 0; j <= i; ++j)
result = Fq_freeze(result + f[j] * (int32) g[i - j]);
fg[i] = result;
}
for (i = p; i < p + p - 1; ++i) {
result = 0;
for (j = i - p + 1; j < p; ++j)
result = Fq_freeze(result + f[j] * (int32) g[i - j]);
fg[i] = result;
}
for (i = p + p - 2; i >= p; --i) {
fg[i - p] = Fq_freeze(fg[i - p] + fg[i]);
fg[i - p + 1] = Fq_freeze(fg[i - p + 1] + fg[i]);
}
for (i = 0; i < p; ++i) h[i] = fg[i];
}
#ifndef LPR
/* h = 3f in Rq */
static void Rq_mult3(Fq *h, const Fq *f) {
int i;
for (i = 0; i < p; ++i) h[i] = Fq_freeze(3 * f[i]);
}
/* out = 1/(3*in) in Rq */
/* returns 0 if recip succeeded; else -1 */
static int Rq_recip3(Fq *out, const small *in) {
Fq f[p + 1], g[p + 1], v[p + 1], r[p + 1];
int i, loop, delta;
int swap, t;
int32 f0, g0;
Fq scale;
for (i = 0; i < p + 1; ++i) v[i] = 0;
for (i = 0; i < p + 1; ++i) r[i] = 0;
r[0] = Fq_recip(3);
for (i = 0; i < p; ++i) f[i] = 0;
f[0] = 1;
f[p - 1] = f[p] = -1;
for (i = 0; i < p; ++i) g[p - 1 - i] = in[i];
g[p] = 0;
delta = 1;
for (loop = 0; loop < 2 * p - 1; ++loop) {
for (i = p; i > 0; --i) v[i] = v[i - 1];
v[0] = 0;
swap = int16_negative_mask(-delta) & int16_nonzero_mask(g[0]);
delta ^= swap & (delta ^ -delta);
delta += 1;
for (i = 0; i < p + 1; ++i) {
t = swap & (f[i] ^ g[i]);
f[i] ^= t;
g[i] ^= t;
t = swap & (v[i] ^ r[i]);
v[i] ^= t;
r[i] ^= t;
}
f0 = f[0];
g0 = g[0];
for (i = 0; i < p + 1; ++i) g[i] = Fq_freeze(f0 * g[i] - g0 * f[i]);
for (i = 0; i < p + 1; ++i) r[i] = Fq_freeze(f0 * r[i] - g0 * v[i]);
for (i = 0; i < p; ++i) g[i] = g[i + 1];
g[p] = 0;
}
scale = Fq_recip(f[0]);
for (i = 0; i < p; ++i) out[i] = Fq_freeze(scale * (int32) v[p - 1 - i]);
return int16_nonzero_mask(delta);
}
#endif
/* ----- rounded polynomials mod q */
static void Round(Fq *out, const Fq *a) {
int i;
for (i = 0; i < p; ++i) out[i] = a[i] - F3_freeze(a[i]);
}
/* ----- sorting to generate short polynomial */
static void Short_fromlist(small *out, const uint32 *in) {
uint32 L[p];
int i;
for (i = 0; i < w; ++i) L[i] = in[i] & (uint32) -2;
for (i = w; i < p; ++i) L[i] = (in[i] & (uint32) -3) | 1;
crypto_sort_uint32(L, p);
for (i = 0; i < p; ++i) out[i] = (L[i] & 3) - 1;
}
/* ----- underlying hash function */
#define Hash_bytes 32
/* e.g., b = 0 means out = Hash0(in) */
static void Hash_prefix(unsigned char *out, int b, const unsigned char *in,
int inlen) {
unsigned char x[inlen + 1];
unsigned char h[64];
int i;
x[0] = b;
for (i = 0; i < inlen; ++i) x[i + 1] = in[i];
crypto_hash_sha512(h, x, inlen + 1);
for (i = 0; i < 32; ++i) out[i] = h[i];
}
/* ----- higher-level randomness */
static uint32 urandom32(void) {
unsigned char c[4];
uint32 out[4];
randombytes(c, 4);
out[0] = (uint32) c[0];
out[1] = ((uint32) c[1]) << 8;
out[2] = ((uint32) c[2]) << 16;
out[3] = ((uint32) c[3]) << 24;
return out[0] + out[1] + out[2] + out[3];
}
static void Short_random(small *out) {
uint32 L[p];
int i;
for (i = 0; i < p; ++i) L[i] = urandom32();
Short_fromlist(out, L);
}
#ifndef LPR
static void Small_random(small *out) {
int i;
for (i = 0; i < p; ++i)
out[i] = (((urandom32() & 0x3fffffff) * 3) >> 30) - 1;
}
#endif
/* ----- Streamlined NTRU Prime Core */
#ifndef LPR
/* h,(f,ginv) = KeyGen() */
static void KeyGen(Fq *h, small *f, small *ginv) {
small g[p];
Fq finv[p];
for (;;) {
int result;
Small_random(g);
result = R3_recip(ginv, g);
crypto_declassify(&result, sizeof result);
if (result == 0) break;
}
Short_random(f);
Rq_recip3(finv, f); /* always works */
Rq_mult_small(h, finv, g);
}
/* c = Encrypt(r,h) */
static void Encrypt(Fq *c, const small *r, const Fq *h) {
Fq hr[p];
Rq_mult_small(hr, h, r);
Round(c, hr);
}
/* r = Decrypt(c,(f,ginv)) */
static void Decrypt(small *r, const Fq *c, const small *f, const small *ginv) {
Fq cf[p];
Fq cf3[p];
small e[p];
small ev[p];
int mask;
int i;
Rq_mult_small(cf, c, f);
Rq_mult3(cf3, cf);
R3_fromRq(e, cf3);
R3_mult(ev, e, ginv);
mask = Weightw_mask(ev); /* 0 if weight w, else -1 */
for (i = 0; i < w; ++i) r[i] = ((ev[i] ^ 1) & ~mask) ^ 1;
for (i = w; i < p; ++i) r[i] = ev[i] & ~mask;
}
#endif
/* ----- NTRU LPRime Core */
#ifdef LPR
/* (G,A),a = KeyGen(G); leaves G unchanged */
static void KeyGen(Fq *A, small *a, const Fq *G) {
Fq aG[p];
Short_random(a);
Rq_mult_small(aG, G, a);
Round(A, aG);
}
/* B,T = Encrypt(r,(G,A),b) */
static void Encrypt(Fq *B, int8 *T, const int8 *r, const Fq *G, const Fq *A,
const small *b) {
Fq bG[p];
Fq bA[p];
int i;
Rq_mult_small(bG, G, b);
Round(B, bG);
Rq_mult_small(bA, A, b);
for (i = 0; i < I; ++i) T[i] = Top(Fq_freeze(bA[i] + r[i] * q12));
}
/* r = Decrypt((B,T),a) */
static void Decrypt(int8 *r, const Fq *B, const int8 *T, const small *a) {
Fq aB[p];
int i;
Rq_mult_small(aB, B, a);
for (i = 0; i < I; ++i)
r[i] = -int16_negative_mask(Fq_freeze(Right(T[i]) - aB[i] + 4 * w + 1));
}
#endif
/* ----- encoding I-bit inputs */
#ifdef LPR
#define Inputs_bytes (I / 8)
typedef int8 Inputs[I]; /* passed by reference */
static void Inputs_encode(unsigned char *s, const Inputs r) {
int i;
for (i = 0; i < Inputs_bytes; ++i) s[i] = 0;
for (i = 0; i < I; ++i) s[i >> 3] |= r[i] << (i & 7);
}
#endif
/* ----- Expand */
#ifdef LPR
static const unsigned char aes_nonce[16] = {0};
static void Expand(uint32 *L, const unsigned char *k) {
int i;
crypto_stream_aes256ctr((unsigned char *) L, 4 * p, aes_nonce, k);
for (i = 0; i < p; ++i) {
uint32 L0 = ((unsigned char *) L)[4 * i];
uint32 L1 = ((unsigned char *) L)[4 * i + 1];
uint32 L2 = ((unsigned char *) L)[4 * i + 2];
uint32 L3 = ((unsigned char *) L)[4 * i + 3];
L[i] = L0 + (L1 << 8) + (L2 << 16) + (L3 << 24);
}
}
#endif
/* ----- Seeds */
#ifdef LPR
#define Seeds_bytes 32
static void Seeds_random(unsigned char *s) { randombytes(s, Seeds_bytes); }
#endif
/* ----- Generator, HashShort */
#ifdef LPR
/* G = Generator(k) */
static void Generator(Fq *G, const unsigned char *k) {
uint32 L[p];
int i;
Expand(L, k);
for (i = 0; i < p; ++i) G[i] = uint32_mod_uint14(L[i], q) - q12;
}
/* out = HashShort(r) */
static void HashShort(small *out, const Inputs r) {
unsigned char s[Inputs_bytes];
unsigned char h[Hash_bytes];
uint32 L[p];
Inputs_encode(s, r);
Hash_prefix(h, 5, s, sizeof s);
Expand(L, h);
Short_fromlist(out, L);
}
#endif
/* ----- NTRU LPRime Expand */
#ifdef LPR
/* (S,A),a = XKeyGen() */
static void XKeyGen(unsigned char *S, Fq *A, small *a) {
Fq G[p];
Seeds_random(S);
Generator(G, S);
KeyGen(A, a, G);
}
/* B,T = XEncrypt(r,(S,A)) */
static void XEncrypt(Fq *B, int8 *T, const int8 *r, const unsigned char *S,
const Fq *A) {
Fq G[p];
small b[p];
Generator(G, S);
HashShort(b, r);
Encrypt(B, T, r, G, A, b);
}
#define XDecrypt Decrypt
#endif
/* ----- encoding small polynomials (including short polynomials) */
#define Small_bytes ((p + 3) / 4)
/* these are the only functions that rely on p mod 4 = 1 */
static void Small_encode(unsigned char *s, const small *f) {
small x;
int i;
for (i = 0; i < p / 4; ++i) {
x = *f++ + 1;
x += (*f++ + 1) << 2;
x += (*f++ + 1) << 4;
x += (*f++ + 1) << 6;
*s++ = x;
}
x = *f++ + 1;
*s++ = x;
}
static void Small_decode(small *f, const unsigned char *s) {
unsigned char x;
int i;
for (i = 0; i < p / 4; ++i) {
x = *s++;
*f++ = ((small) (x & 3)) - 1;
x >>= 2;
*f++ = ((small) (x & 3)) - 1;
x >>= 2;
*f++ = ((small) (x & 3)) - 1;
x >>= 2;
*f++ = ((small) (x & 3)) - 1;
}
x = *s++;
*f++ = ((small) (x & 3)) - 1;
}
/* ----- encoding general polynomials */
#ifndef LPR
static void Rq_encode(unsigned char *s, const Fq *r) {
uint16 R[p], M[p];
int i;
for (i = 0; i < p; ++i) R[i] = r[i] + q12;
for (i = 0; i < p; ++i) M[i] = q;
Encode(s, R, M, p);
}
static void Rq_decode(Fq *r, const unsigned char *s) {
uint16 R[p], M[p];
int i;
for (i = 0; i < p; ++i) M[i] = q;
Decode(R, s, M, p);
for (i = 0; i < p; ++i) r[i] = ((Fq) R[i]) - q12;
}
#endif
/* ----- encoding rounded polynomials */
static void Rounded_encode(unsigned char *s, const Fq *r) {
uint16 R[p], M[p];
int i;
for (i = 0; i < p; ++i) R[i] = ((r[i] + q12) * 10923) >> 15;
for (i = 0; i < p; ++i) M[i] = (q + 2) / 3;
Encode(s, R, M, p);
}
static void Rounded_decode(Fq *r, const unsigned char *s) {
uint16 R[p], M[p];
int i;
for (i = 0; i < p; ++i) M[i] = (q + 2) / 3;
Decode(R, s, M, p);
for (i = 0; i < p; ++i) r[i] = R[i] * 3 - q12;
}
/* ----- encoding top polynomials */
#ifdef LPR
#define Top_bytes (I / 2)
static void Top_encode(unsigned char *s, const int8 *T) {
int i;
for (i = 0; i < Top_bytes; ++i) s[i] = T[2 * i] + (T[2 * i + 1] << 4);
}
static void Top_decode(int8 *T, const unsigned char *s) {
int i;
for (i = 0; i < Top_bytes; ++i) {
T[2 * i] = s[i] & 15;
T[2 * i + 1] = s[i] >> 4;
}
}
#endif
/* ----- Streamlined NTRU Prime Core plus encoding */
#ifndef LPR
typedef small Inputs[p]; /* passed by reference */
#define Inputs_random Short_random
#define Inputs_encode Small_encode
#define Inputs_bytes Small_bytes
#define Ciphertexts_bytes Rounded_bytes
#define SecretKeys_bytes (2 * Small_bytes)
#define PublicKeys_bytes Rq_bytes
/* pk,sk = ZKeyGen() */
static void ZKeyGen(unsigned char *pk, unsigned char *sk) {
Fq h[p];
small f[p], v[p];
KeyGen(h, f, v);
Rq_encode(pk, h);
Small_encode(sk, f);
sk += Small_bytes;
Small_encode(sk, v);
}
/* C = ZEncrypt(r,pk) */
static void ZEncrypt(unsigned char *C, const Inputs r,
const unsigned char *pk) {
Fq h[p];
Fq c[p];
Rq_decode(h, pk);
Encrypt(c, r, h);
Rounded_encode(C, c);
}
/* r = ZDecrypt(C,sk) */
static void ZDecrypt(Inputs r, const unsigned char *C,
const unsigned char *sk) {
small f[p], v[p];
Fq c[p];
Small_decode(f, sk);
sk += Small_bytes;
Small_decode(v, sk);
Rounded_decode(c, C);
Decrypt(r, c, f, v);
}
#endif
/* ----- NTRU LPRime Expand plus encoding */
#ifdef LPR
#define Ciphertexts_bytes (Rounded_bytes + Top_bytes)
#define SecretKeys_bytes Small_bytes
#define PublicKeys_bytes (Seeds_bytes + Rounded_bytes)
static void Inputs_random(Inputs r) {
unsigned char s[Inputs_bytes];
int i;
randombytes(s, sizeof s);
for (i = 0; i < I; ++i) r[i] = 1 & (s[i >> 3] >> (i & 7));
}
/* pk,sk = ZKeyGen() */
static void ZKeyGen(unsigned char *pk, unsigned char *sk) {
Fq A[p];
small a[p];
XKeyGen(pk, A, a);
pk += Seeds_bytes;
Rounded_encode(pk, A);
Small_encode(sk, a);
}
/* c = ZEncrypt(r,pk) */
static void ZEncrypt(unsigned char *c, const Inputs r,
const unsigned char *pk) {
Fq A[p];
Fq B[p];
int8 T[I];
Rounded_decode(A, pk + Seeds_bytes);
XEncrypt(B, T, r, pk, A);
Rounded_encode(c, B);
c += Rounded_bytes;
Top_encode(c, T);
}
/* r = ZDecrypt(C,sk) */
static void ZDecrypt(Inputs r, const unsigned char *c,
const unsigned char *sk) {
small a[p];
Fq B[p];
int8 T[I];
Small_decode(a, sk);
Rounded_decode(B, c);
Top_decode(T, c + Rounded_bytes);
XDecrypt(r, B, T, a);
}
#endif
/* ----- confirmation hash */
#define Confirm_bytes 32
/* h = HashConfirm(r,pk,cache); cache is Hash4(pk) */
static void HashConfirm(unsigned char *h, const unsigned char *r,
const unsigned char *pk, const unsigned char *cache) {
(void) pk;
#ifndef LPR
unsigned char x[Hash_bytes * 2];
int i;
Hash_prefix(x, 3, r, Inputs_bytes);
for (i = 0; i < Hash_bytes; ++i) x[Hash_bytes + i] = cache[i];
#else
unsigned char x[Inputs_bytes + Hash_bytes];
int i;
for (i = 0; i < Inputs_bytes; ++i) x[i] = r[i];
for (i = 0; i < Hash_bytes; ++i) x[Inputs_bytes + i] = cache[i];
#endif
Hash_prefix(h, 2, x, sizeof x);
}
/* ----- session-key hash */
/* k = HashSession(b,y,z) */
static void HashSession(unsigned char *k, int b, const unsigned char *y,
const unsigned char *z) {
#ifndef LPR
unsigned char x[Hash_bytes + Ciphertexts_bytes + Confirm_bytes];
int i;
Hash_prefix(x, 3, y, Inputs_bytes);
for (i = 0; i < Ciphertexts_bytes + Confirm_bytes; ++i)
x[Hash_bytes + i] = z[i];
#else
unsigned char x[Inputs_bytes + Ciphertexts_bytes + Confirm_bytes];
int i;
for (i = 0; i < Inputs_bytes; ++i) x[i] = y[i];
for (i = 0; i < Ciphertexts_bytes + Confirm_bytes; ++i)
x[Inputs_bytes + i] = z[i];
#endif
Hash_prefix(k, b, x, sizeof x);
}
/* ----- Streamlined NTRU Prime and NTRU LPRime */
/* pk,sk = KEM_KeyGen() */
static void KEM_KeyGen(unsigned char *pk, unsigned char *sk) {
int i;
ZKeyGen(pk, sk);
sk += SecretKeys_bytes;
for (i = 0; i < PublicKeys_bytes; ++i) *sk++ = pk[i];
randombytes(sk, Inputs_bytes);
sk += Inputs_bytes;
Hash_prefix(sk, 4, pk, PublicKeys_bytes);
}
/* c,r_enc = Hide(r,pk,cache); cache is Hash4(pk) */
static void Hide(unsigned char *c, unsigned char *r_enc, const Inputs r,
const unsigned char *pk, const unsigned char *cache) {
Inputs_encode(r_enc, r);
ZEncrypt(c, r, pk);
c += Ciphertexts_bytes;
HashConfirm(c, r_enc, pk, cache);
}
/* c,k = Encap(pk) */
static void Encap(unsigned char *c, unsigned char *k, const unsigned char *pk) {
Inputs r;
unsigned char r_enc[Inputs_bytes];
unsigned char cache[Hash_bytes];
Hash_prefix(cache, 4, pk, PublicKeys_bytes);
Inputs_random(r);
Hide(c, r_enc, r, pk, cache);
HashSession(k, 1, r_enc, c);
}
/* 0 if matching ciphertext+confirm, else -1 */
static int Ciphertexts_diff_mask(const unsigned char *c,
const unsigned char *c2) {
uint16 differentbits = 0;
int len = Ciphertexts_bytes + Confirm_bytes;
while (len-- > 0) differentbits |= (*c++) ^ (*c2++);
return crypto_int16_nonzero_mask(differentbits);
}
/* k = Decap(c,sk) */
static void Decap(unsigned char *k, const unsigned char *c,
const unsigned char *sk) {
const unsigned char *pk = sk + SecretKeys_bytes;
const unsigned char *rho = pk + PublicKeys_bytes;
const unsigned char *cache = rho + Inputs_bytes;
Inputs r;
unsigned char r_enc[Inputs_bytes];
unsigned char cnew[Ciphertexts_bytes + Confirm_bytes];
int mask;
int i;
ZDecrypt(r, c, sk);
Hide(cnew, r_enc, r, pk, cache);
mask = Ciphertexts_diff_mask(c, cnew);
for (i = 0; i < Inputs_bytes; ++i) r_enc[i] ^= mask & (r_enc[i] ^ rho[i]);
HashSession(k, 1 + mask, r_enc, c);
}
/* ----- crypto_kem_sntrup761_tinyssh API */
int crypto_kem_sntrup761_tinyssh_keypair(unsigned char *pk, unsigned char *sk) {
KEM_KeyGen(pk, sk);
return 0;
}
int crypto_kem_sntrup761_tinyssh_enc(unsigned char *c, unsigned char *k,
const unsigned char *pk) {
Encap(c, k, pk);
return 0;
}
int crypto_kem_sntrup761_tinyssh_dec(unsigned char *k, const unsigned char *c,
const unsigned char *sk) {
Decap(k, c, sk);
return 0;
}
#if 0
Script used to merge into single the file:
#!/ bin / sh
rm crypto_kem_sntrup761.c || :
(
cd "$1"
echo '/*'
echo 'Original code: supercop-20210125/crypto_kem/sntrup761/ref'
echo 'Modifications (Jan Mojzis):'
echo '- source code merged into single file'
echo '- crypto_kem renamed to crypto_kem_sntrup761_tinyssh'
echo '*/'
echo
echo '/* See https://ntruprime.cr.yp.to/software.html for detailed documentation. */'
echo
echo '#include '
echo '#include "crypto_uint64.h"'
echo '#include "crypto_uint32.h"'
echo '#include "crypto_uint16.h"'
echo '#include "crypto_int32.h"'
echo '#include "crypto_int16.h"'
echo '#include "crypto_int8.h"'
echo '#include "randombytes.h"'
echo '#include "crypto_verify_32.h"'
echo '#include "crypto_sort_uint32.h"'
echo '#include "crypto_hash_sha512.h"'
echo '#include "crypto_kem_sntrup761.h"'
echo ''
echo '#define uint64 crypto_uint64'
echo '#define uint32 crypto_uint32'
echo '#define uint16 crypto_uint16'
echo '#define int32 crypto_int32'
echo '#define int16 crypto_int16'
echo '#define int8 crypto_int8'
echo
(
for f in uint32.c int32.c paramsmenu.h params.h Decode.c Encode.c; do
echo "/* ${f} */"
cat "${f}" | sed 's/^void /static void /' | sed 's/^int16 /static int16 /'
echo
done | grep -v '#include'
)
(
echo '/* kem.c */'
cat kem.c
echo
) | grep -v '#include' | sed 's/crypto_kem/crypto_kem_sntrup761_tinyssh/g'
echo
echo '#if 0'
echo 'Script used to merge into single the file:'
echo
cat $0
echo
echo '#endif'
) > crypto_kem_sntrup761.c.tmp
mv -f crypto_kem_sntrup761.c.tmp crypto_kem_sntrup761.c
#endif
#endif
tinyssh-20250201/crypto_kem_sntrup761x25519.c 0000664 0000000 0000000 00000004123 14747360755 0020461 0 ustar 00root root 0000000 0000000 /*
20210314
20241211 - reformated using clang-format
20241215 - scalarmult_curve25519 -> dh_x25519
Jan Mojzis
Public domain.
*/
#include "cleanup.h"
#include "crypto_hash_sha512.h"
#include "crypto_dh_x25519.h"
#include "crypto_kem_sntrup761.h"
#include "crypto_kem_sntrup761x25519.h"
int crypto_kem_sntrup761x25519_tinyssh_enc(unsigned char *c, unsigned char *k,
const unsigned char *pk) {
unsigned char onetimesk[crypto_dh_x25519_SECRETKEYBYTES];
unsigned char buf[crypto_kem_sntrup761_BYTES + crypto_dh_x25519_BYTES];
/* sntrup761 */
crypto_kem_sntrup761_enc(c, buf, pk);
pk += crypto_kem_sntrup761_PUBLICKEYBYTES;
c += crypto_kem_sntrup761_CIPHERTEXTBYTES;
/* x25519 */
crypto_dh_x25519_keypair(/*onetimepk*/ c, onetimesk);
crypto_dh_x25519(buf + crypto_kem_sntrup761_BYTES, pk, onetimesk);
/* hash together sntrup459176 KEM-key and x25519 shared secret */
crypto_hash_sha512(k, buf, sizeof buf);
/* cleanup */
cleanup(buf);
cleanup(onetimesk);
return 0;
}
int crypto_kem_sntrup761x25519_tinyssh_dec(unsigned char *k,
const unsigned char *c,
const unsigned char *sk) {
unsigned char buf[crypto_kem_sntrup761_BYTES + crypto_dh_x25519_BYTES];
/* sntrup761 */
crypto_kem_sntrup761_dec(buf, c, sk);
sk += crypto_kem_sntrup761_SECRETKEYBYTES;
c += crypto_kem_sntrup761_CIPHERTEXTBYTES;
/* x25519 */
crypto_dh_x25519(buf + crypto_kem_sntrup761_BYTES, c, sk);
/* hash together sntrup459176 KEM-key and x25519 shared secret */
crypto_hash_sha512(k, buf, sizeof buf);
/* cleanup */
cleanup(buf);
return 0;
}
int crypto_kem_sntrup761x25519_tinyssh_keypair(unsigned char *pk,
unsigned char *sk) {
/* sntrup761 */
crypto_kem_sntrup761_keypair(pk, sk);
/* x25519 */
crypto_dh_x25519_keypair(pk + crypto_kem_sntrup761_PUBLICKEYBYTES,
sk + crypto_kem_sntrup761_SECRETKEYBYTES);
return 0;
}
tinyssh-20250201/crypto_kem_sntrup761x25519.h 0000664 0000000 0000000 00000003426 14747360755 0020473 0 ustar 00root root 0000000 0000000 #ifndef crypto_kem_sntrup761x25519_H
#define crypto_kem_sntrup761x25519_H
#define crypto_kem_sntrup761x25519_tinyssh_SECRETKEYBYTES 1795
#define crypto_kem_sntrup761x25519_tinyssh_PUBLICKEYBYTES 1190
#define crypto_kem_sntrup761x25519_tinyssh_CIPHERTEXTBYTES 1071
#define crypto_kem_sntrup761x25519_tinyssh_BYTES 64
extern int crypto_kem_sntrup761x25519_tinyssh_keypair(unsigned char *,
unsigned char *);
extern int crypto_kem_sntrup761x25519_tinyssh_enc(unsigned char *,
unsigned char *,
const unsigned char *);
extern int crypto_kem_sntrup761x25519_tinyssh_dec(unsigned char *,
const unsigned char *,
const unsigned char *);
#define crypto_kem_sntrup761x25519_keypair \
crypto_kem_sntrup761x25519_tinyssh_keypair
#define crypto_kem_sntrup761x25519_enc crypto_kem_sntrup761x25519_tinyssh_enc
#define crypto_kem_sntrup761x25519_dec crypto_kem_sntrup761x25519_tinyssh_dec
#define crypto_kem_sntrup761x25519_SECRETKEYBYTES \
crypto_kem_sntrup761x25519_tinyssh_SECRETKEYBYTES
#define crypto_kem_sntrup761x25519_PUBLICKEYBYTES \
crypto_kem_sntrup761x25519_tinyssh_PUBLICKEYBYTES
#define crypto_kem_sntrup761x25519_CIPHERTEXTBYTES \
crypto_kem_sntrup761x25519_tinyssh_CIPHERTEXTBYTES
#define crypto_kem_sntrup761x25519_BYTES \
crypto_kem_sntrup761x25519_tinyssh_BYTES
#define crypto_kem_sntrup761x25519_IMPLEMENTATION "tinyssh"
#define crypto_kem_sntrup761x25519_VERSION "-"
#endif
tinyssh-20250201/crypto_onetimeauth_poly1305.c 0000664 0000000 0000000 00000013043 14747360755 0021135 0 ustar 00root root 0000000 0000000 /*
20250126
*/
/*
Based on poly1305-donna (https://github.com/floodyberry/poly1305-donna)
- modified for NaCl API
- switched to cryptoint
*/
#include "crypto_int16.h"
#include "crypto_uint32.h"
#include "crypto_uint64.h"
#include "crypto_onetimeauth_poly1305.h"
/* clang-format off */
int crypto_onetimeauth_poly1305_tinyssh(unsigned char *o,
const unsigned char *m,
unsigned long long n,
const unsigned char *k) {
crypto_uint32 h0, h1, h2, h3, h4;
crypto_uint32 r0, r1, r2, r3, r4;
crypto_uint32 s1, s2, s3, s4;
crypto_uint64 d0, d1, d2, d3, d4;
crypto_uint32 c, mask;
crypto_uint64 f;
crypto_uint64 i;
/* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
r0 = (crypto_uint32_load(k + 0) ) & 0x3ffffff;
r1 = (crypto_uint32_load(k + 3) >> 2) & 0x3ffff03;
r2 = (crypto_uint32_load(k + 6) >> 4) & 0x3ffc0ff;
r3 = (crypto_uint32_load(k + 9) >> 6) & 0x3f03fff;
r4 = (crypto_uint32_load(k + 12) >> 8) & 0x00fffff;
s1 = r1 * 5;
s2 = r2 * 5;
s3 = r3 * 5;
s4 = r4 * 5;
/* h = 0 */
h0 = h1 = h2 = h3 = h4 = 0;
while (n > 0) {
/* h += m[i] */
if (n >= 16) {
h0 += (crypto_uint32_load(m ) ) & 0x3ffffff;
h1 += (crypto_uint32_load(m + 3) >> 2) & 0x3ffffff;
h2 += (crypto_uint32_load(m + 6) >> 4) & 0x3ffffff;
h3 += (crypto_uint32_load(m + 9) >> 6) & 0x3ffffff;
h4 += (crypto_uint32_load(m + 12) >> 8) | 16777216;
m += 16;
n -= 16;
}
else {
unsigned char mm[16];
for (i = 0; i < 16; ++i) mm[i] = 0;
for (i = 0; i < n; ++i) mm[i] = m[i];
mm[i] = 1;
h0 += (crypto_uint32_load(mm ) ) & 0x3ffffff;
h1 += (crypto_uint32_load(mm + 3) >> 2) & 0x3ffffff;
h2 += (crypto_uint32_load(mm + 6) >> 4) & 0x3ffffff;
h3 += (crypto_uint32_load(mm + 9) >> 6) & 0x3ffffff;
h4 += (crypto_uint32_load(mm + 12) >> 8);
n = 0;
}
/* h *= r */
d0 = ((crypto_uint64)h0 * r0) + ((crypto_uint64)h1 * s4) + ((crypto_uint64)h2 * s3) + ((crypto_uint64)h3 * s2) + ((crypto_uint64)h4 * s1);
d1 = ((crypto_uint64)h0 * r1) + ((crypto_uint64)h1 * r0) + ((crypto_uint64)h2 * s4) + ((crypto_uint64)h3 * s3) + ((crypto_uint64)h4 * s2);
d2 = ((crypto_uint64)h0 * r2) + ((crypto_uint64)h1 * r1) + ((crypto_uint64)h2 * r0) + ((crypto_uint64)h3 * s4) + ((crypto_uint64)h4 * s3);
d3 = ((crypto_uint64)h0 * r3) + ((crypto_uint64)h1 * r2) + ((crypto_uint64)h2 * r1) + ((crypto_uint64)h3 * r0) + ((crypto_uint64)h4 * s4);
d4 = ((crypto_uint64)h0 * r4) + ((crypto_uint64)h1 * r3) + ((crypto_uint64)h2 * r2) + ((crypto_uint64)h3 * r1) + ((crypto_uint64)h4 * r0);
/* (partial) h %= p */
c = (crypto_uint32)(d0 >> 26); h0 = (crypto_uint32)d0 & 0x3ffffff;
d1 += c; c = (crypto_uint32)(d1 >> 26); h1 = (crypto_uint32)d1 & 0x3ffffff;
d2 += c; c = (crypto_uint32)(d2 >> 26); h2 = (crypto_uint32)d2 & 0x3ffffff;
d3 += c; c = (crypto_uint32)(d3 >> 26); h3 = (crypto_uint32)d3 & 0x3ffffff;
d4 += c; c = (crypto_uint32)(d4 >> 26); h4 = (crypto_uint32)d4 & 0x3ffffff;
h0 += c * 5; c = (h0 >> 26); h0 = h0 & 0x3ffffff;
h1 += c;
}
/* fully carry h */
c = h1 >> 26; h1 = h1 & 0x3ffffff;
h2 += c; c = h2 >> 26; h2 = h2 & 0x3ffffff;
h3 += c; c = h3 >> 26; h3 = h3 & 0x3ffffff;
h4 += c; c = h4 >> 26; h4 = h4 & 0x3ffffff;
h0 += c * 5; c = h0 >> 26; h0 = h0 & 0x3ffffff;
h1 += c;
/* compute h + -p */
r0 = h0 + 5; c = r0 >> 26; r0 &= 0x3ffffff;
r1 = h1 + c; c = r1 >> 26; r1 &= 0x3ffffff;
r2 = h2 + c; c = r2 >> 26; r2 &= 0x3ffffff;
r3 = h3 + c; c = r3 >> 26; r3 &= 0x3ffffff;
r4 = h4 + c - (1 << 26);
/* select h if h < p, or h + -p if h >= p */
mask = crypto_uint32_topbit_01(r4);
mask -= 1;
r0 ^= h0;
r1 ^= h1;
r2 ^= h2;
r3 ^= h3;
r4 ^= h4;
h0 ^= mask & r0;
h1 ^= mask & r1;
h2 ^= mask & r2;
h3 ^= mask & r3;
h4 ^= mask & r4;
/* h = h % (2^128) */
h0 = ((h0 ) | (h1 << 26)) & 0xffffffff;
h1 = ((h1 >> 6) | (h2 << 20)) & 0xffffffff;
h2 = ((h2 >> 12) | (h3 << 14)) & 0xffffffff;
h3 = ((h3 >> 18) | (h4 << 8)) & 0xffffffff;
/* mac = (h + pad) % (2^128) */
f = (crypto_uint64)h0 + crypto_uint32_load(k + 16) ; h0 = (crypto_uint32)f;
f = (crypto_uint64)h1 + crypto_uint32_load(k + 20) + (f >> 32); h1 = (crypto_uint32)f;
f = (crypto_uint64)h2 + crypto_uint32_load(k + 24) + (f >> 32); h2 = (crypto_uint32)f;
f = (crypto_uint64)h3 + crypto_uint32_load(k + 28) + (f >> 32); h3 = (crypto_uint32)f;
crypto_uint32_store(o + 0, h0);
crypto_uint32_store(o + 4, h1);
crypto_uint32_store(o + 8, h2);
crypto_uint32_store(o + 12, h3);
return 0;
}
int crypto_onetimeauth_poly1305_tinyssh_verify(const unsigned char *h,
const unsigned char *in,
unsigned long long l,
const unsigned char *k) {
unsigned char correct[16];
crypto_int16 d = 0;
long long i;
crypto_onetimeauth_poly1305(correct, in, l, k);
for (i = 0; i < 16; ++i) d |= correct[i] ^ h[i];
return crypto_int16_nonzero_mask(d);
}
/* clang-format on */
tinyssh-20250201/crypto_onetimeauth_poly1305.h 0000664 0000000 0000000 00000002473 14747360755 0021147 0 ustar 00root root 0000000 0000000 #ifndef crypto_onetimeauth_poly1305_H
#define crypto_onetimeauth_poly1305_H
#define crypto_onetimeauth_poly1305_tinyssh_BYTES 16
#define crypto_onetimeauth_poly1305_tinyssh_KEYBYTES 32
extern int crypto_onetimeauth_poly1305_tinyssh(unsigned char *,
const unsigned char *,
unsigned long long,
const unsigned char *);
extern int crypto_onetimeauth_poly1305_tinyssh_verify(const unsigned char *,
const unsigned char *,
unsigned long long,
const unsigned char *);
#define crypto_onetimeauth_poly1305 crypto_onetimeauth_poly1305_tinyssh
#define crypto_onetimeauth_poly1305_verify \
crypto_onetimeauth_poly1305_tinyssh_verify
#define crypto_onetimeauth_poly1305_BYTES \
crypto_onetimeauth_poly1305_tinyssh_BYTES
#define crypto_onetimeauth_poly1305_KEYBYTES \
crypto_onetimeauth_poly1305_tinyssh_KEYBYTES
#define crypto_onetimeauth_poly1305_IMPLEMENTATION "tinyssh"
#define crypto_onetimeauth_poly1305_VERSION "-"
#endif
tinyssh-20250201/crypto_scalarmult_curve25519.c 0000664 0000000 0000000 00000003704 14747360755 0021223 0 ustar 00root root 0000000 0000000 #include "cleanup.h"
#include "fe25519.h"
#include "crypto_uint8.h"
#include "crypto_scalarmult_curve25519.h"
int crypto_scalarmult_curve25519_tinyssh(unsigned char *q,
const unsigned char *n,
const unsigned char *p) {
unsigned char e[32];
fe x1, x2, z2, x3, z3, tmp0, tmp1;
long long i;
int pos;
crypto_uint32 swap, b;
for (i = 0; i < 32; ++i) e[i] = n[i];
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
fe25519_frombytes(x1, p);
fe_1(x2);
fe_0(z2);
fe_copy(x3, x1);
fe_1(z3);
swap = 0;
for (pos = 254; pos >= 0; --pos) {
b = crypto_uint8_bitmod_01(e[pos / 8], pos);
swap ^= b;
fe_cswap(x2, x3, swap);
fe_cswap(z2, z3, swap);
swap = b;
fe25519_sub(tmp0, x3, z3);
fe25519_sub(tmp1, x2, z2);
fe25519_add(x2, x2, z2);
fe25519_add(z2, x3, z3);
fe25519_mul(z3, tmp0, x2);
fe25519_mul(z2, z2, tmp1);
fe25519_sq(tmp0, tmp1);
fe25519_sq(tmp1, x2);
fe25519_add(x3, z3, z2);
fe25519_sub(z2, z3, z2);
fe25519_mul(x2, tmp1, tmp0);
fe25519_sub(tmp1, tmp1, tmp0);
fe25519_sq(z2, z2);
fe25519_mul121666(z3, tmp1);
fe25519_sq(x3, x3);
fe25519_add(tmp0, tmp0, z3);
fe25519_mul(z3, x1, z2);
fe25519_mul(z2, tmp1, tmp0);
}
fe_cswap(x2, x3, swap);
fe_cswap(z2, z3, swap);
fe25519_inv(z2, z2);
fe25519_mul(x2, x2, z2);
fe25519_tobytes(q, x2);
cleanup(e);
cleanup(tmp0);
cleanup(tmp1);
cleanup(x1);
cleanup(x2);
cleanup(x3);
cleanup(z2);
cleanup(z3);
return 0;
}
static const unsigned char basepoint[32] = {9};
int crypto_scalarmult_curve25519_tinyssh_base(unsigned char *q,
const unsigned char *n) {
return crypto_scalarmult_curve25519_tinyssh(q, n, basepoint);
}
tinyssh-20250201/crypto_scalarmult_curve25519.h 0000664 0000000 0000000 00000002153 14747360755 0021225 0 ustar 00root root 0000000 0000000 #ifndef crypto_scalarmult_curve25519_H
#define crypto_scalarmult_curve25519_H
#define crypto_scalarmult_curve25519_tinyssh_BYTES 32
#define crypto_scalarmult_curve25519_tinyssh_SCALARBYTES 32
extern int crypto_scalarmult_curve25519_tinyssh(unsigned char *,
const unsigned char *,
const unsigned char *);
extern int crypto_scalarmult_curve25519_tinyssh_base(unsigned char *,
const unsigned char *);
#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_tinyssh
#define crypto_scalarmult_curve25519_base \
crypto_scalarmult_curve25519_tinyssh_base
#define crypto_scalarmult_curve25519_BYTES \
crypto_scalarmult_curve25519_tinyssh_BYTES
#define crypto_scalarmult_curve25519_SCALARBYTES \
crypto_scalarmult_curve25519_tinyssh_SCALARBYTES
#define crypto_scalarmult_curve25519_IMPLEMENTATION "tinyssh"
#define crypto_scalarmult_curve25519_VERSION "-"
#endif
tinyssh-20250201/crypto_sign_ed25519.h 0000664 0000000 0000000 00000006357 14747360755 0017274 0 ustar 00root root 0000000 0000000 #ifndef crypto_sign_ed25519_H
#define crypto_sign_ed25519_H
#include "haslib25519.h"
#ifndef HASLIB25519
#define crypto_sign_ed25519_tinyssh_SECRETKEYBYTES 64
#define crypto_sign_ed25519_tinyssh_PUBLICKEYBYTES 32
#define crypto_sign_ed25519_tinyssh_BYTES 64
extern int crypto_sign_ed25519_tinyssh(unsigned char *, unsigned long long *,
const unsigned char *,
unsigned long long,
const unsigned char *);
extern int crypto_sign_ed25519_tinyssh_open(unsigned char *,
unsigned long long *,
const unsigned char *,
unsigned long long,
const unsigned char *);
extern int crypto_sign_ed25519_tinyssh_keypair(unsigned char *,
unsigned char *);
#define crypto_sign_ed25519 crypto_sign_ed25519_tinyssh
#define crypto_sign_ed25519_open crypto_sign_ed25519_tinyssh_open
#define crypto_sign_ed25519_keypair crypto_sign_ed25519_tinyssh_keypair
#define crypto_sign_ed25519_BYTES crypto_sign_ed25519_tinyssh_BYTES
#define crypto_sign_ed25519_PUBLICKEYBYTES \
crypto_sign_ed25519_tinyssh_PUBLICKEYBYTES
#define crypto_sign_ed25519_SECRETKEYBYTES \
crypto_sign_ed25519_tinyssh_SECRETKEYBYTES
#define crypto_sign_ed25519_IMPLEMENTATION "tinyssh"
#define crypto_sign_ed25519_VERSION "-"
#else
#include
#define crypto_sign_ed25519_lib25519_SECRETKEYBYTES \
lib25519_sign_ed25519_SECRETKEYBYTES
#define crypto_sign_ed25519_lib25519_PUBLICKEYBYTES \
lib25519_sign_ed25519_PUBLICKEYBYTES
#define crypto_sign_ed25519_lib25519_BYTES lib25519_sign_ed25519_BYTES
extern int crypto_sign_ed25519_lib25519(unsigned char *, unsigned long long *,
const unsigned char *,
unsigned long long,
const unsigned char *);
extern int crypto_sign_ed25519_lib25519_open(unsigned char *,
unsigned long long *,
const unsigned char *,
unsigned long long,
const unsigned char *);
extern int crypto_sign_ed25519_lib25519_keypair(unsigned char *,
unsigned char *);
#define crypto_sign_ed25519 crypto_sign_ed25519_lib25519
#define crypto_sign_ed25519_open crypto_sign_ed25519_lib25519_open
#define crypto_sign_ed25519_keypair crypto_sign_ed25519_lib25519_keypair
#define crypto_sign_ed25519_BYTES crypto_sign_ed25519_lib25519_BYTES
#define crypto_sign_ed25519_PUBLICKEYBYTES \
crypto_sign_ed25519_lib25519_PUBLICKEYBYTES
#define crypto_sign_ed25519_SECRETKEYBYTES \
crypto_sign_ed25519_lib25519_SECRETKEYBYTES
#define crypto_sign_ed25519_IMPLEMENTATION "lib25519"
#define crypto_sign_ed25519_VERSION lib25519_version
#endif
#endif
tinyssh-20250201/crypto_sign_ed25519_lib25519.c 0000664 0000000 0000000 00000002061 14747360755 0020507 0 ustar 00root root 0000000 0000000 #include "haslib25519.h"
#ifdef HASLIB25519
#include
#include "crypto_sign_ed25519.h"
int crypto_sign_ed25519_lib25519(unsigned char *sm, unsigned long long *smlen,
const unsigned char *m, unsigned long long n,
const unsigned char *skorig) {
long long llsmlen;
lib25519_sign_ed25519(sm, &llsmlen, m, n, skorig);
*smlen = (unsigned long long) llsmlen;
return 0;
}
int crypto_sign_ed25519_lib25519_open(unsigned char *m,
unsigned long long *mlen,
const unsigned char *sm,
unsigned long long n,
const unsigned char *pk) {
long long llmlen;
int ret;
ret = lib25519_sign_ed25519_open(m, &llmlen, sm, n, pk);
*mlen = (unsigned long long) llmlen;
return ret;
}
int crypto_sign_ed25519_lib25519_keypair(unsigned char *pk, unsigned char *sk) {
lib25519_sign_ed25519_keypair(pk, sk);
return 0;
}
#endif
tinyssh-20250201/crypto_sign_ed25519_tinyssh.c 0000664 0000000 0000000 00000007111 14747360755 0021035 0 ustar 00root root 0000000 0000000 #include "crypto_sign_ed25519.h"
#include "haslib25519.h"
#ifndef HASLIB25519
#include "randombytes.h"
#include "cleanup.h"
#include "crypto_hash_sha512.h"
#include "crypto_verify_32.h"
#include "ge25519.h"
#include "sc25519.h"
int crypto_sign_ed25519_tinyssh(unsigned char *sm, unsigned long long *smlen,
const unsigned char *m, unsigned long long n,
const unsigned char *skorig) {
long long i;
unsigned char nonce[64], hram[64], sk[96], pk[32];
ge25519 R;
/* copy public key*/
for (i = 31; i >= 0; --i) pk[i] = skorig[i + 32];
/* compute secret key from seed sk = H(skorig), H = sha512 */
crypto_hash_sha512(sk, skorig, 32);
sk[0] &= 248;
sk[31] &= 63;
sk[31] |= 64;
randombytes(sk + 64, 32);
crypto_hash_sha512(sk + 32, sk + 32, 64);
/* copy m to sm, copy secret key */
*smlen = n + 64;
for (i = n - 1; i >= 0; --i) sm[i + 64] = m[i];
for (i = 31; i >= 0; --i) sm[i + 32] = sk[i + 32];
/* get pseudorandom nonce = H(sk2, m) */
crypto_hash_sha512(nonce, sm + 32, n + 32);
sc25519_reduce(nonce);
/* copy pk to sm */
for (i = 31; i >= 0; --i) sm[i + 32] = pk[i];
/* compute R */
ge25519_scalarmult_base(R, nonce);
ge25519_tobytes(sm, R);
/* calculate hram = H(r, a, m) */
crypto_hash_sha512(hram, sm, n + 64);
sc25519_reduce(hram);
/* compute S */
sc25519_muladd(sm + 32, hram, sk, nonce);
/* cleanup */
cleanup(nonce);
cleanup(hram);
cleanup(sk);
cleanup(pk);
cleanup(R);
return 0;
}
int crypto_sign_ed25519_tinyssh_open(unsigned char *m, unsigned long long *mlen,
const unsigned char *sm,
unsigned long long n,
const unsigned char *pk) {
unsigned long long i;
long long j;
unsigned char pkcopy[32], rcopy[32], scopy[32], hram[64], rcheck[32];
ge25519 R, S, A;
int ret = -1;
/* check input */
if (n < 64) goto fail;
if (sm[63] & 224) goto fail;
/* unpack pk */
if (ge25519_frombytes_negate_vartime(A, pk) != 0) goto fail;
/* copy pk, r, s */
for (i = 0; i < 32; ++i) pkcopy[i] = pk[i];
for (i = 0; i < 32; ++i) rcopy[i] = sm[i];
for (i = 0; i < 32; ++i) scopy[i] = sm[i + 32];
/* copy sm to m and copy pk to m */
for (j = n - 1; j >= 0; --j) m[j] = sm[j];
for (i = 0; i < 32; ++i) m[i + 32] = pkcopy[i];
/* calculate hram = H(r, a, m) */
crypto_hash_sha512(hram, m, n);
sc25519_reduce(hram);
/* compute R */
ge25519_scalarmult(A, A, hram);
ge25519_scalarmult_base(S, scopy);
ge25519_add(R, S, A);
/* check R */
ge25519_tobytes(rcheck, R);
if (crypto_verify_32(rcheck, rcopy) != 0) goto fail;
/* copy message */
n -= 64;
*mlen = n;
for (i = 0; i < n; ++i) m[i] = m[i + 64];
for (i = 0; i < 64; ++i) m[i + n] = 0;
ret = 0;
goto cleanup;
fail:
for (i = 0; i < n; ++i) m[i] = 0;
cleanup:
cleanup(pkcopy);
cleanup(rcopy);
cleanup(scopy);
cleanup(hram);
cleanup(rcheck);
cleanup(R);
cleanup(S);
cleanup(A);
return ret;
}
int crypto_sign_ed25519_tinyssh_keypair(unsigned char *pk, unsigned char *sk) {
unsigned char h[64];
ge25519 A;
long long i;
randombytes(sk, 32);
crypto_hash_sha512(h, sk, 32);
h[0] &= 248;
h[31] &= 63;
h[31] |= 64;
ge25519_scalarmult_base(A, h);
ge25519_tobytes(pk, A);
for (i = 31; i >= 0; --i) sk[i + 32] = pk[i];
cleanup(h);
cleanup(A);
return 0;
}
#endif
tinyssh-20250201/crypto_sort_uint32.c 0000664 0000000 0000000 00000001464 14747360755 0017436 0 ustar 00root root 0000000 0000000 #include "crypto_uint32.h"
#include "crypto_sort_uint32.h"
static void minmax(crypto_uint32 *x, crypto_uint32 *y) {
crypto_uint32 xi = *x;
crypto_uint32 yi = *y;
crypto_uint32 xy = xi ^ yi;
crypto_uint32 c = yi - xi;
c ^= xy & (c ^ yi ^ 0x80000000);
c >>= 31;
c &= 1;
c = -c;
c &= xy;
*x = xi ^ c;
*y = yi ^ c;
}
void crypto_sort_uint32_tinyssh(void *xv, long long n) {
long long top, p, q, i;
crypto_uint32 *x = xv;
if (n < 2) return;
top = 1;
while (top < n - top) top += top;
for (p = top; p > 0; p >>= 1) {
for (i = 0; i < n - p; ++i)
if (!(i & p)) minmax(x + i, x + i + p);
for (q = top; q > p; q >>= 1)
for (i = 0; i < n - q; ++i)
if (!(i & p)) minmax(x + i + p, x + i + q);
}
}
tinyssh-20250201/crypto_sort_uint32.h 0000664 0000000 0000000 00000000575 14747360755 0017445 0 ustar 00root root 0000000 0000000 #ifndef crypto_sort_uint32_H
#define crypto_sort_uint32_H
#define crypto_sort_uint32_tinyssh_BYTES 4
extern void crypto_sort_uint32_tinyssh(void *, long long);
#define crypto_sort_uint32 crypto_sort_uint32_tinyssh
#define crypto_sort_uint32_BYTES crypto_sort_uint32_tinyssh_BYTES
#define crypto_sort_uint32_IMPLEMENTATION "tinyssh"
#define crypto_sort_uint32_VERSION "-"
#endif
tinyssh-20250201/crypto_stream_chacha20.c 0000664 0000000 0000000 00000016252 14747360755 0020170 0 ustar 00root root 0000000 0000000 /*
20241112
*/
#include
#include "crypto_stream_chacha20.h"
static inline uint32_t unpack32(const unsigned char *x) {
uint32_t u0 = ((uint32_t) x[0]);
uint32_t u1 = ((uint32_t) x[1]) << 8;
uint32_t u2 = ((uint32_t) x[2]) << 16;
uint32_t u3 = ((uint32_t) x[3]) << 24;
return u0 ^ u1 ^ u2 ^ u3;
}
static inline void pack32(unsigned char *x, uint32_t u) {
x[0] = (unsigned char) (u);
x[1] = (unsigned char) (u >> 8);
x[2] = (unsigned char) (u >> 16);
x[3] = (unsigned char) (u >> 24);
}
#define ROTATE(x, c) ((x) << (c)) ^ ((x) >> (32 - (c)))
#define QUARTERROUND(a, b, c, d) \
a += b; \
d = ROTATE(d ^ a, 16); \
c += d; \
b = ROTATE(b ^ c, 12); \
a += b; \
d = ROTATE(d ^ a, 8); \
c += d; \
b = ROTATE(b ^ c, 7);
#define TWOROUNDS() \
QUARTERROUND(x0, x4, x8, x12) \
QUARTERROUND(x1, x5, x9, x13) \
QUARTERROUND(x2, x6, x10, x14) \
QUARTERROUND(x3, x7, x11, x15) \
QUARTERROUND(x0, x5, x10, x15) \
QUARTERROUND(x1, x6, x11, x12) \
QUARTERROUND(x2, x7, x8, x13) \
QUARTERROUND(x3, x4, x9, x14)
#define XORBLOCK(o, i) \
x0 = s0; \
x1 = s1; \
x2 = s2; \
x3 = s3; \
x4 = k0; \
x5 = k1; \
x6 = k2; \
x7 = k3; \
x8 = k4; \
x9 = k5; \
x10 = k6; \
x11 = k7; \
x12 = n0; \
x13 = n1; \
x14 = n2; \
x15 = n3; \
\
TWOROUNDS() /* round 1, 2 */ \
TWOROUNDS() /* round 3, 4 */ \
TWOROUNDS() /* round 5, 6 */ \
TWOROUNDS() /* round 7, 8 */ \
TWOROUNDS() /* round 9, 10 */ \
TWOROUNDS() /* round 11, 12 */ \
TWOROUNDS() /* round 13, 14 */ \
TWOROUNDS() /* round 15, 16 */ \
TWOROUNDS() /* round 17, 18 */ \
TWOROUNDS() /* round 19, 20 */ \
\
pack32(o, (x0 + s0) ^ unpack32(i)); \
pack32(o + 4, (x1 + s1) ^ unpack32(i + 4)); \
pack32(o + 8, (x2 + s2) ^ unpack32(i + 8)); \
pack32(o + 12, (x3 + s3) ^ unpack32(i + 12)); \
pack32(o + 16, (x4 + k0) ^ unpack32(i + 16)); \
pack32(o + 20, (x5 + k1) ^ unpack32(i + 20)); \
pack32(o + 24, (x6 + k2) ^ unpack32(i + 24)); \
pack32(o + 28, (x7 + k3) ^ unpack32(i + 28)); \
pack32(o + 32, (x8 + k4) ^ unpack32(i + 32)); \
pack32(o + 36, (x9 + k5) ^ unpack32(i + 36)); \
pack32(o + 40, (x10 + k6) ^ unpack32(i + 40)); \
pack32(o + 44, (x11 + k7) ^ unpack32(i + 44)); \
pack32(o + 48, (x12 + n0) ^ unpack32(i + 48)); \
pack32(o + 52, (x13 + n1) ^ unpack32(i + 52)); \
pack32(o + 56, (x14 + n2) ^ unpack32(i + 56)); \
pack32(o + 60, (x15 + n3) ^ unpack32(i + 60))
int crypto_stream_chacha20_tinyssh_xor(unsigned char *c, const unsigned char *m,
unsigned long long l,
const unsigned char *n,
const unsigned char *k) {
register uint32_t x0, x1, x2, x3, x4, x5, x6, x7;
register uint32_t x8, x9, x10, x11, x12, x13, x14, x15;
uint32_t k0 = unpack32(k);
uint32_t k1 = unpack32(k + 4);
uint32_t k2 = unpack32(k + 8);
uint32_t k3 = unpack32(k + 12);
uint32_t k4 = unpack32(k + 16);
uint32_t k5 = unpack32(k + 20);
uint32_t k6 = unpack32(k + 24);
uint32_t k7 = unpack32(k + 28);
uint32_t n0 = 0;
uint32_t n1 = 0;
uint32_t n2 = unpack32(n);
uint32_t n3 = unpack32(n + 4);
uint32_t s0 = 0x61707865;
uint32_t s1 = 0x3320646E;
uint32_t s2 = 0x79622D32;
uint32_t s3 = 0x6B206574;
uint64_t u = 0;
if (!l) return 0;
while (l >= 64) {
XORBLOCK(c, m);
n0 = (uint32_t) ++u;
n1 = u >> 32;
l -= 64;
c += 64;
m += 64;
}
if (l) {
unsigned char b[64] = {0};
unsigned long long j;
for (j = 0; j < l; ++j) b[j] = m[j];
XORBLOCK(b, b);
for (j = 0; j < l; ++j) c[j] = b[j];
}
return 0;
}
int crypto_stream_chacha20_tinyssh(unsigned char *c, unsigned long long l,
const unsigned char *n,
const unsigned char *k) {
unsigned long long j;
unsigned char ncopy[8], kcopy[32];
for (j = 0; j < 32; ++j) kcopy[j] = k[j];
for (j = 0; j < 8; ++j) ncopy[j] = n[j];
for (j = 0; j < l; ++j) c[j] = 0;
return crypto_stream_chacha20_tinyssh_xor(c, c, l, ncopy, kcopy);
}
tinyssh-20250201/crypto_stream_chacha20.h 0000664 0000000 0000000 00000002214 14747360755 0020166 0 ustar 00root root 0000000 0000000 #ifndef crypto_stream_chacha20_H
#define crypto_stream_chacha20_H
#define crypto_stream_chacha20_tinyssh_KEYBYTES 32
#define crypto_stream_chacha20_tinyssh_NONCEBYTES 8
extern int crypto_stream_chacha20_tinyssh(unsigned char *, unsigned long long,
const unsigned char *,
const unsigned char *);
extern int crypto_stream_chacha20_tinyssh_xor(unsigned char *,
const unsigned char *,
unsigned long long,
const unsigned char *,
const unsigned char *);
#define crypto_stream_chacha20 crypto_stream_chacha20_tinyssh
#define crypto_stream_chacha20_xor crypto_stream_chacha20_tinyssh_xor
#define crypto_stream_chacha20_KEYBYTES crypto_stream_chacha20_tinyssh_KEYBYTES
#define crypto_stream_chacha20_NONCEBYTES \
crypto_stream_chacha20_tinyssh_NONCEBYTES
#define crypto_stream_chacha20_IMPLEMENTATION "tinyssh"
#define crypto_stream_chacha20_VERSION "-"
#endif
tinyssh-20250201/crypto_verify_16.c 0000664 0000000 0000000 00000000446 14747360755 0017054 0 ustar 00root root 0000000 0000000 #include "crypto_int16.h"
#include "crypto_verify_16.h"
int crypto_verify_16_tinyssh(const unsigned char *x, const unsigned char *y) {
crypto_int16 d = 0;
long long i;
for (i = 0; i < crypto_verify_16_BYTES; ++i) { d |= x[i] ^ y[i]; }
return crypto_int16_nonzero_mask(d);
}
tinyssh-20250201/crypto_verify_16.h 0000664 0000000 0000000 00000000650 14747360755 0017056 0 ustar 00root root 0000000 0000000 #ifndef crypto_verify_16_H
#define crypto_verify_16_H
#define crypto_verify_16_tinyssh_BYTES 16
extern int crypto_verify_16_tinyssh(const unsigned char *,
const unsigned char *);
#define crypto_verify_16 crypto_verify_16_tinyssh
#define crypto_verify_16_BYTES crypto_verify_16_tinyssh_BYTES
#define crypto_verify_16_IMPLEMENTATION "tinyssh"
#define crypto_verify_16_VERSION "-"
#endif
tinyssh-20250201/crypto_verify_32.c 0000664 0000000 0000000 00000000446 14747360755 0017052 0 ustar 00root root 0000000 0000000 #include "crypto_int16.h"
#include "crypto_verify_32.h"
int crypto_verify_32_tinyssh(const unsigned char *x, const unsigned char *y) {
crypto_int16 d = 0;
long long i;
for (i = 0; i < crypto_verify_32_BYTES; ++i) { d |= x[i] ^ y[i]; }
return crypto_int16_nonzero_mask(d);
}
tinyssh-20250201/crypto_verify_32.h 0000664 0000000 0000000 00000000650 14747360755 0017054 0 ustar 00root root 0000000 0000000 #ifndef crypto_verify_32_H
#define crypto_verify_32_H
#define crypto_verify_32_tinyssh_BYTES 32
extern int crypto_verify_32_tinyssh(const unsigned char *,
const unsigned char *);
#define crypto_verify_32 crypto_verify_32_tinyssh
#define crypto_verify_32_BYTES crypto_verify_32_tinyssh_BYTES
#define crypto_verify_32_IMPLEMENTATION "tinyssh"
#define crypto_verify_32_VERSION "-"
#endif
tinyssh-20250201/cryptoint/ 0000775 0000000 0000000 00000000000 14747360755 0015525 5 ustar 00root root 0000000 0000000 tinyssh-20250201/cryptoint/autogen 0000775 0000000 0000000 00000000072 14747360755 0017114 0 ustar 00root root 0000000 0000000 #!/bin/sh
./create.py
./specialize.py
rm -rf __pycache__
tinyssh-20250201/cryptoint/create.py 0000775 0000000 0000000 00000005167 14747360755 0017356 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
vars = 'k','l','p','q','r','s','x','y','z'
with open('version') as f:
version = f.read().strip()
# ===== top
csh = f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#ifndef crypto_intN_h
#define crypto_intN_h
#include
#define crypto_intN intN_t
#define crypto_intN_unsigned uintN_t
#define crypto_intN_optblocker namespace_intN_optblocker
extern volatile crypto_intN crypto_intN_optblocker;
'''
cuh = f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#ifndef crypto_uintN_h
#define crypto_uintN_h
#include
#define crypto_uintN uintN_t
#define crypto_uintN_signed intN_t
#define crypto_uintN_signed_optblocker namespace_uintN_signed_optblocker
extern volatile crypto_uintN_signed crypto_uintN_signed_optblocker;
'''
# ===== functions
functions = []
with open('functions') as f:
which,fun = 'both',None
for line in f:
if fun is None:
if line.startswith('#'): continue
if line.strip() == '': continue
if line.strip() == 'SIGNED:':
which = 'signed'
continue
if line.strip() == 'UNSIGNED:':
which = 'unsigned'
continue
fun = ''
fun += line
if line.strip() == '}':
functions += [(which,fun)]
which,fun = 'both',None
for which,fun in functions:
if which in ('both','signed'):
data = fun
data = data.replace('TYPE','crypto_intN')
data = data.replace('UNSIGNED','crypto_intN_unsigned')
data = data.replace('SIGNED','crypto_intN')
for v in vars:
data = data.replace(v.upper(),'crypto_intN_'+v)
csh += '__attribute__((unused))\n'
csh += 'static inline\n'
csh += data
csh += '\n'
if which in ('both','unsigned'):
data = fun
data = data.replace('TYPE','crypto_uintN')
data = data.replace('UNSIGNED','crypto_uintN')
data = data.replace('SIGNED','crypto_uintN_signed')
for v in vars:
data = data.replace(v.upper(),'crypto_uintN_'+v)
cuh += '__attribute__((unused))\n'
cuh += 'static inline\n'
cuh += data
cuh += '\n'
# ===== bottom
csh += '''#endif
'''
cuh += '''#endif
'''
# ===== ship it
with open('crypto_intN.h','w') as f:
f.write(csh)
with open('crypto_uintN.h','w') as f:
f.write(cuh)
with open('intN_optblocker.c','w') as f:
f.write(f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#include "crypto_intN.h"
volatile crypto_intN crypto_intN_optblocker = 0;
''')
with open('uintN_optblocker.c','w') as f:
f.write(f'''/* auto-generated: cd cryptoint; ./autogen */
/* {version} */
#include "crypto_uintN.h"
volatile crypto_uintN_signed crypto_uintN_signed_optblocker = 0;
''')
tinyssh-20250201/cryptoint/crypto_int16.h 0000664 0000000 0000000 00000052665 14747360755 0020255 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_int16_h
#define crypto_int16_h
#include
#define crypto_int16 int16_t
#define crypto_int16_unsigned uint16_t
#define crypto_int16_optblocker tinyssh_int16_optblocker
extern volatile crypto_int16 crypto_int16_optblocker;
__attribute__((unused))
static inline
crypto_int16 crypto_int16_load(const unsigned char *crypto_int16_s) {
crypto_int16 crypto_int16_z = 0;
crypto_int16_z |= ((crypto_int16) (*crypto_int16_s++)) << 0;
crypto_int16_z |= ((crypto_int16) (*crypto_int16_s++)) << 8;
return crypto_int16_z;
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_load_bigendian(const unsigned char *crypto_int16_s) {
crypto_int16 crypto_int16_z = 0;
crypto_int16_z |= ((crypto_int16) (*crypto_int16_s++)) << 8;
crypto_int16_z |= ((crypto_int16) (*crypto_int16_s++)) << 0;
return crypto_int16_z;
}
__attribute__((unused))
static inline
void crypto_int16_store(unsigned char *crypto_int16_s,crypto_int16 crypto_int16_x) {
*crypto_int16_s++ = crypto_int16_x >> 0;
*crypto_int16_s++ = crypto_int16_x >> 8;
}
__attribute__((unused))
static inline
void crypto_int16_store_bigendian(unsigned char *crypto_int16_s,crypto_int16 crypto_int16_x) {
*crypto_int16_s++ = crypto_int16_x >> 8;
*crypto_int16_s++ = crypto_int16_x >> 0;
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_negative_mask(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarw $15,%0" : "+r"(crypto_int16_x) : : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_y;
__asm__ ("sbfx %w0,%w1,15,1" : "=r"(crypto_int16_y) : "r"(crypto_int16_x) : );
return crypto_int16_y;
#else
crypto_int16_x >>= 16-6;
crypto_int16_x += crypto_int16_optblocker;
crypto_int16_x >>= 5;
return crypto_int16_x;
#endif
}
__attribute__((unused))
static inline
crypto_int16_unsigned crypto_int16_unsigned_topbit_01(crypto_int16_unsigned crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrw $15,%0" : "+r"(crypto_int16_x) : : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_y;
__asm__ ("ubfx %w0,%w1,15,1" : "=r"(crypto_int16_y) : "r"(crypto_int16_x) : );
return crypto_int16_y;
#else
crypto_int16_x >>= 16-6;
crypto_int16_x += crypto_int16_optblocker;
crypto_int16_x >>= 5;
return crypto_int16_x;
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_negative_01(crypto_int16 crypto_int16_x) {
return crypto_int16_unsigned_topbit_01(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_topbit_mask(crypto_int16 crypto_int16_x) {
return crypto_int16_negative_mask(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_topbit_01(crypto_int16 crypto_int16_x) {
return crypto_int16_unsigned_topbit_01(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bottombit_mask(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andw $1,%0" : "+r"(crypto_int16_x) : : "cc");
return -crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_int16_y) : "r"(crypto_int16_x) : );
return crypto_int16_y;
#else
crypto_int16_x &= 1 + crypto_int16_optblocker;
return -crypto_int16_x;
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bottombit_01(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andw $1,%0" : "+r"(crypto_int16_x) : : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_int16_y) : "r"(crypto_int16_x) : );
return crypto_int16_y;
#else
crypto_int16_x &= 1 + crypto_int16_optblocker;
return crypto_int16_x;
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bitinrangepublicpos_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarw %%cl,%0" : "+r"(crypto_int16_x) : "c"(crypto_int16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxth %w0,%w0\n asr %w0,%w0,%w1" : "+&r"(crypto_int16_x) : "r"(crypto_int16_s) : );
#else
crypto_int16_x >>= crypto_int16_s ^ crypto_int16_optblocker;
#endif
return crypto_int16_bottombit_mask(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bitinrangepublicpos_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarw %%cl,%0" : "+r"(crypto_int16_x) : "c"(crypto_int16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxth %w0,%w0\n asr %w0,%w0,%w1" : "+&r"(crypto_int16_x) : "r"(crypto_int16_s) : );
#else
crypto_int16_x >>= crypto_int16_s ^ crypto_int16_optblocker;
#endif
return crypto_int16_bottombit_01(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_shlmod(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16_s &= 15;
__asm__ ("shlw %%cl,%0" : "+r"(crypto_int16_x) : "c"(crypto_int16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,15\n and %w1,%w1,65535\n lsl %w1,%w1,%w0" : "+&r"(crypto_int16_s), "+r"(crypto_int16_x) : : );
#else
int crypto_int16_k, crypto_int16_l;
for (crypto_int16_l = 0,crypto_int16_k = 1;crypto_int16_k < 16;++crypto_int16_l,crypto_int16_k *= 2)
crypto_int16_x ^= (crypto_int16_x ^ (crypto_int16_x << crypto_int16_k)) & crypto_int16_bitinrangepublicpos_mask(crypto_int16_s,crypto_int16_l);
#endif
return crypto_int16_x;
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_shrmod(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16_s &= 15;
__asm__ ("sarw %%cl,%0" : "+r"(crypto_int16_x) : "c"(crypto_int16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,15\n sxth %w1,%w1\n asr %w1,%w1,%w0" : "+&r"(crypto_int16_s), "+r"(crypto_int16_x) : : );
#else
int crypto_int16_k, crypto_int16_l;
for (crypto_int16_l = 0,crypto_int16_k = 1;crypto_int16_k < 16;++crypto_int16_l,crypto_int16_k *= 2)
crypto_int16_x ^= (crypto_int16_x ^ (crypto_int16_x >> crypto_int16_k)) & crypto_int16_bitinrangepublicpos_mask(crypto_int16_s,crypto_int16_l);
#endif
return crypto_int16_x;
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bitmod_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
crypto_int16_x = crypto_int16_shrmod(crypto_int16_x,crypto_int16_s);
return crypto_int16_bottombit_mask(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_bitmod_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_s) {
crypto_int16_x = crypto_int16_shrmod(crypto_int16_x,crypto_int16_s);
return crypto_int16_bottombit_01(crypto_int16_x);
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_nonzero_mask(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n testw %2,%2\n cmovnew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("tst %w1,65535\n csetm %w0,ne" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
crypto_int16_x |= -crypto_int16_x;
return crypto_int16_negative_mask(crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_nonzero_01(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n testw %2,%2\n cmovnew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("tst %w1,65535\n cset %w0,ne" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
crypto_int16_x |= -crypto_int16_x;
return crypto_int16_unsigned_topbit_01(crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_positive_mask(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n testw %2,%2\n cmovgw %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,0\n csetm %w0,gt" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
crypto_int16 crypto_int16_z = -crypto_int16_x;
crypto_int16_z ^= crypto_int16_x & crypto_int16_z;
return crypto_int16_negative_mask(crypto_int16_z);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_positive_01(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n testw %2,%2\n cmovgw %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,0\n cset %w0,gt" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
crypto_int16 crypto_int16_z = -crypto_int16_x;
crypto_int16_z ^= crypto_int16_x & crypto_int16_z;
return crypto_int16_unsigned_topbit_01(crypto_int16_z);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_zero_mask(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n testw %2,%2\n cmovew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("tst %w1,65535\n csetm %w0,eq" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
return ~crypto_int16_nonzero_mask(crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_zero_01(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n testw %2,%2\n cmovew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("tst %w1,65535\n cset %w0,eq" : "=r"(crypto_int16_z) : "r"(crypto_int16_x) : "cc");
return crypto_int16_z;
#else
return 1-crypto_int16_nonzero_01(crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_unequal_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovnew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,ne" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return crypto_int16_nonzero_mask(crypto_int16_x ^ crypto_int16_y);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_unequal_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovnew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,ne" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return crypto_int16_nonzero_01(crypto_int16_x ^ crypto_int16_y);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_equal_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,eq" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return ~crypto_int16_unequal_mask(crypto_int16_x,crypto_int16_y);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_equal_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,eq" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return 1-crypto_int16_unequal_01(crypto_int16_x,crypto_int16_y);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_min(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpw %1,%0\n cmovgw %1,%0" : "+r"(crypto_int16_x) : "r"(crypto_int16_y) : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxth %w0,%w0\n cmp %w0,%w1,sxth\n csel %w0,%w0,%w1,lt" : "+&r"(crypto_int16_x) : "r"(crypto_int16_y) : "cc");
return crypto_int16_x;
#else
crypto_int16 crypto_int16_r = crypto_int16_y ^ crypto_int16_x;
crypto_int16 crypto_int16_z = crypto_int16_y - crypto_int16_x;
crypto_int16_z ^= crypto_int16_r & (crypto_int16_z ^ crypto_int16_y);
crypto_int16_z = crypto_int16_negative_mask(crypto_int16_z);
crypto_int16_z &= crypto_int16_r;
return crypto_int16_x ^ crypto_int16_z;
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_max(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpw %1,%0\n cmovlw %1,%0" : "+r"(crypto_int16_x) : "r"(crypto_int16_y) : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxth %w0,%w0\n cmp %w0,%w1,sxth\n csel %w0,%w1,%w0,lt" : "+&r"(crypto_int16_x) : "r"(crypto_int16_y) : "cc");
return crypto_int16_x;
#else
crypto_int16 crypto_int16_r = crypto_int16_y ^ crypto_int16_x;
crypto_int16 crypto_int16_z = crypto_int16_y - crypto_int16_x;
crypto_int16_z ^= crypto_int16_r & (crypto_int16_z ^ crypto_int16_y);
crypto_int16_z = crypto_int16_negative_mask(crypto_int16_z);
crypto_int16_z &= crypto_int16_r;
return crypto_int16_y ^ crypto_int16_z;
#endif
}
__attribute__((unused))
static inline
void crypto_int16_minmax(crypto_int16 *crypto_int16_p,crypto_int16 *crypto_int16_q) {
crypto_int16 crypto_int16_x = *crypto_int16_p;
crypto_int16 crypto_int16_y = *crypto_int16_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_z;
__asm__ ("cmpw %2,%1\n movw %1,%0\n cmovgw %2,%1\n cmovgw %0,%2" : "=&r"(crypto_int16_z), "+&r"(crypto_int16_x), "+r"(crypto_int16_y) : : "cc");
*crypto_int16_p = crypto_int16_x;
*crypto_int16_q = crypto_int16_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_r, crypto_int16_s;
__asm__ ("sxth %w0,%w0\n cmp %w0,%w3,sxth\n csel %w1,%w0,%w3,lt\n csel %w2,%w3,%w0,lt" : "+&r"(crypto_int16_x), "=&r"(crypto_int16_r), "=r"(crypto_int16_s) : "r"(crypto_int16_y) : "cc");
*crypto_int16_p = crypto_int16_r;
*crypto_int16_q = crypto_int16_s;
#else
crypto_int16 crypto_int16_r = crypto_int16_y ^ crypto_int16_x;
crypto_int16 crypto_int16_z = crypto_int16_y - crypto_int16_x;
crypto_int16_z ^= crypto_int16_r & (crypto_int16_z ^ crypto_int16_y);
crypto_int16_z = crypto_int16_negative_mask(crypto_int16_z);
crypto_int16_z &= crypto_int16_r;
crypto_int16_x ^= crypto_int16_z;
crypto_int16_y ^= crypto_int16_z;
*crypto_int16_p = crypto_int16_x;
*crypto_int16_q = crypto_int16_y;
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_smaller_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovlw %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,%w2,sxth\n csetm %w0,lt" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
crypto_int16 crypto_int16_r = crypto_int16_x ^ crypto_int16_y;
crypto_int16 crypto_int16_z = crypto_int16_x - crypto_int16_y;
crypto_int16_z ^= crypto_int16_r & (crypto_int16_z ^ crypto_int16_x);
return crypto_int16_negative_mask(crypto_int16_z);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_smaller_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovlw %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,%w2,sxth\n cset %w0,lt" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
crypto_int16 crypto_int16_r = crypto_int16_x ^ crypto_int16_y;
crypto_int16 crypto_int16_z = crypto_int16_x - crypto_int16_y;
crypto_int16_z ^= crypto_int16_r & (crypto_int16_z ^ crypto_int16_x);
return crypto_int16_unsigned_topbit_01(crypto_int16_z);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_leq_mask(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovlew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,%w2,sxth\n csetm %w0,le" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return ~crypto_int16_smaller_mask(crypto_int16_y,crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
crypto_int16 crypto_int16_leq_01(crypto_int16 crypto_int16_x,crypto_int16 crypto_int16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 crypto_int16_q,crypto_int16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovlew %1,%0" : "=&r"(crypto_int16_z), "=&r"(crypto_int16_q) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int16 crypto_int16_z;
__asm__ ("sxth %w0,%w1\n cmp %w0,%w2,sxth\n cset %w0,le" : "=&r"(crypto_int16_z) : "r"(crypto_int16_x), "r"(crypto_int16_y) : "cc");
return crypto_int16_z;
#else
return 1-crypto_int16_smaller_01(crypto_int16_y,crypto_int16_x);
#endif
}
__attribute__((unused))
static inline
int crypto_int16_ones_num(crypto_int16 crypto_int16_x) {
crypto_int16_unsigned crypto_int16_y = crypto_int16_x;
const crypto_int16 C0 = 0x5555;
const crypto_int16 C1 = 0x3333;
const crypto_int16 C2 = 0x0f0f;
crypto_int16_y -= ((crypto_int16_y >> 1) & C0);
crypto_int16_y = (crypto_int16_y & C1) + ((crypto_int16_y >> 2) & C1);
crypto_int16_y = (crypto_int16_y + (crypto_int16_y >> 4)) & C2;
crypto_int16_y = (crypto_int16_y + (crypto_int16_y >> 8)) & 0xff;
return crypto_int16_y;
}
__attribute__((unused))
static inline
int crypto_int16_bottomzeros_num(crypto_int16 crypto_int16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int16 fallback = 16;
__asm__ ("bsfw %0,%0\n cmovew %1,%0" : "+&r"(crypto_int16_x) : "r"(fallback) : "cc");
return crypto_int16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_int16_y;
__asm__ ("orr %w0,%w1,-65536\n rbit %w0,%w0\n clz %w0,%w0" : "=r"(crypto_int16_y) : "r"(crypto_int16_x) : );
return crypto_int16_y;
#else
crypto_int16 crypto_int16_y = crypto_int16_x ^ (crypto_int16_x-1);
crypto_int16_y = ((crypto_int16) crypto_int16_y) >> 1;
crypto_int16_y &= ~(crypto_int16_x & (((crypto_int16) 1) << (16-1)));
return crypto_int16_ones_num(crypto_int16_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_int32.h 0000664 0000000 0000000 00000052673 14747360755 0020252 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_int32_h
#define crypto_int32_h
#include
#define crypto_int32 int32_t
#define crypto_int32_unsigned uint32_t
#define crypto_int32_optblocker tinyssh_int32_optblocker
extern volatile crypto_int32 crypto_int32_optblocker;
__attribute__((unused))
static inline
crypto_int32 crypto_int32_load(const unsigned char *crypto_int32_s) {
crypto_int32 crypto_int32_z = 0;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 0;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 8;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 16;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 24;
return crypto_int32_z;
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_load_bigendian(const unsigned char *crypto_int32_s) {
crypto_int32 crypto_int32_z = 0;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 24;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 16;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 8;
crypto_int32_z |= ((crypto_int32) (*crypto_int32_s++)) << 0;
return crypto_int32_z;
}
__attribute__((unused))
static inline
void crypto_int32_store(unsigned char *crypto_int32_s,crypto_int32 crypto_int32_x) {
*crypto_int32_s++ = crypto_int32_x >> 0;
*crypto_int32_s++ = crypto_int32_x >> 8;
*crypto_int32_s++ = crypto_int32_x >> 16;
*crypto_int32_s++ = crypto_int32_x >> 24;
}
__attribute__((unused))
static inline
void crypto_int32_store_bigendian(unsigned char *crypto_int32_s,crypto_int32 crypto_int32_x) {
*crypto_int32_s++ = crypto_int32_x >> 24;
*crypto_int32_s++ = crypto_int32_x >> 16;
*crypto_int32_s++ = crypto_int32_x >> 8;
*crypto_int32_s++ = crypto_int32_x >> 0;
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_negative_mask(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarl $31,%0" : "+r"(crypto_int32_x) : : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_y;
__asm__ ("asr %w0,%w1,31" : "=r"(crypto_int32_y) : "r"(crypto_int32_x) : );
return crypto_int32_y;
#else
crypto_int32_x >>= 32-6;
crypto_int32_x += crypto_int32_optblocker;
crypto_int32_x >>= 5;
return crypto_int32_x;
#endif
}
__attribute__((unused))
static inline
crypto_int32_unsigned crypto_int32_unsigned_topbit_01(crypto_int32_unsigned crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrl $31,%0" : "+r"(crypto_int32_x) : : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_y;
__asm__ ("lsr %w0,%w1,31" : "=r"(crypto_int32_y) : "r"(crypto_int32_x) : );
return crypto_int32_y;
#else
crypto_int32_x >>= 32-6;
crypto_int32_x += crypto_int32_optblocker;
crypto_int32_x >>= 5;
return crypto_int32_x;
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_negative_01(crypto_int32 crypto_int32_x) {
return crypto_int32_unsigned_topbit_01(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_topbit_mask(crypto_int32 crypto_int32_x) {
return crypto_int32_negative_mask(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_topbit_01(crypto_int32 crypto_int32_x) {
return crypto_int32_unsigned_topbit_01(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bottombit_mask(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andl $1,%0" : "+r"(crypto_int32_x) : : "cc");
return -crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_int32_y) : "r"(crypto_int32_x) : );
return crypto_int32_y;
#else
crypto_int32_x &= 1 + crypto_int32_optblocker;
return -crypto_int32_x;
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bottombit_01(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andl $1,%0" : "+r"(crypto_int32_x) : : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_int32_y) : "r"(crypto_int32_x) : );
return crypto_int32_y;
#else
crypto_int32_x &= 1 + crypto_int32_optblocker;
return crypto_int32_x;
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bitinrangepublicpos_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarl %%cl,%0" : "+r"(crypto_int32_x) : "c"(crypto_int32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %w0,%w0,%w1" : "+r"(crypto_int32_x) : "r"(crypto_int32_s) : );
#else
crypto_int32_x >>= crypto_int32_s ^ crypto_int32_optblocker;
#endif
return crypto_int32_bottombit_mask(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bitinrangepublicpos_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarl %%cl,%0" : "+r"(crypto_int32_x) : "c"(crypto_int32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %w0,%w0,%w1" : "+r"(crypto_int32_x) : "r"(crypto_int32_s) : );
#else
crypto_int32_x >>= crypto_int32_s ^ crypto_int32_optblocker;
#endif
return crypto_int32_bottombit_01(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_shlmod(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shll %%cl,%0" : "+r"(crypto_int32_x) : "c"(crypto_int32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsl %w0,%w0,%w1" : "+r"(crypto_int32_x) : "r"(crypto_int32_s) : );
#else
int crypto_int32_k, crypto_int32_l;
for (crypto_int32_l = 0,crypto_int32_k = 1;crypto_int32_k < 32;++crypto_int32_l,crypto_int32_k *= 2)
crypto_int32_x ^= (crypto_int32_x ^ (crypto_int32_x << crypto_int32_k)) & crypto_int32_bitinrangepublicpos_mask(crypto_int32_s,crypto_int32_l);
#endif
return crypto_int32_x;
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_shrmod(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarl %%cl,%0" : "+r"(crypto_int32_x) : "c"(crypto_int32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %w0,%w0,%w1" : "+r"(crypto_int32_x) : "r"(crypto_int32_s) : );
#else
int crypto_int32_k, crypto_int32_l;
for (crypto_int32_l = 0,crypto_int32_k = 1;crypto_int32_k < 32;++crypto_int32_l,crypto_int32_k *= 2)
crypto_int32_x ^= (crypto_int32_x ^ (crypto_int32_x >> crypto_int32_k)) & crypto_int32_bitinrangepublicpos_mask(crypto_int32_s,crypto_int32_l);
#endif
return crypto_int32_x;
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bitmod_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
crypto_int32_x = crypto_int32_shrmod(crypto_int32_x,crypto_int32_s);
return crypto_int32_bottombit_mask(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_bitmod_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_s) {
crypto_int32_x = crypto_int32_shrmod(crypto_int32_x,crypto_int32_s);
return crypto_int32_bottombit_01(crypto_int32_x);
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_nonzero_mask(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testl %2,%2\n cmovnel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n csetm %w0,ne" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
crypto_int32_x |= -crypto_int32_x;
return crypto_int32_negative_mask(crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_nonzero_01(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n testl %2,%2\n cmovnel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n cset %w0,ne" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
crypto_int32_x |= -crypto_int32_x;
return crypto_int32_unsigned_topbit_01(crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_positive_mask(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testl %2,%2\n cmovgl %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n csetm %w0,gt" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
crypto_int32 crypto_int32_z = -crypto_int32_x;
crypto_int32_z ^= crypto_int32_x & crypto_int32_z;
return crypto_int32_negative_mask(crypto_int32_z);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_positive_01(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n testl %2,%2\n cmovgl %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n cset %w0,gt" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
crypto_int32 crypto_int32_z = -crypto_int32_x;
crypto_int32_z ^= crypto_int32_x & crypto_int32_z;
return crypto_int32_unsigned_topbit_01(crypto_int32_z);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_zero_mask(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testl %2,%2\n cmovel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n csetm %w0,eq" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
return ~crypto_int32_nonzero_mask(crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_zero_01(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n testl %2,%2\n cmovel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,0\n cset %w0,eq" : "=r"(crypto_int32_z) : "r"(crypto_int32_x) : "cc");
return crypto_int32_z;
#else
return 1-crypto_int32_nonzero_01(crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_unequal_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovnel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,ne" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return crypto_int32_nonzero_mask(crypto_int32_x ^ crypto_int32_y);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_unequal_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovnel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,ne" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return crypto_int32_nonzero_01(crypto_int32_x ^ crypto_int32_y);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_equal_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,eq" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return ~crypto_int32_unequal_mask(crypto_int32_x,crypto_int32_y);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_equal_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,eq" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return 1-crypto_int32_unequal_01(crypto_int32_x,crypto_int32_y);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_min(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpl %1,%0\n cmovgl %1,%0" : "+r"(crypto_int32_x) : "r"(crypto_int32_y) : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %w0,%w1\n csel %w0,%w0,%w1,lt" : "+r"(crypto_int32_x) : "r"(crypto_int32_y) : "cc");
return crypto_int32_x;
#else
crypto_int32 crypto_int32_r = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_r & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_r;
return crypto_int32_x ^ crypto_int32_z;
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_max(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpl %1,%0\n cmovll %1,%0" : "+r"(crypto_int32_x) : "r"(crypto_int32_y) : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %w0,%w1\n csel %w0,%w1,%w0,lt" : "+r"(crypto_int32_x) : "r"(crypto_int32_y) : "cc");
return crypto_int32_x;
#else
crypto_int32 crypto_int32_r = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_r & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_r;
return crypto_int32_y ^ crypto_int32_z;
#endif
}
__attribute__((unused))
static inline
void crypto_int32_minmax(crypto_int32 *crypto_int32_p,crypto_int32 *crypto_int32_q) {
crypto_int32 crypto_int32_x = *crypto_int32_p;
crypto_int32 crypto_int32_y = *crypto_int32_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmpl %2,%1\n movl %1,%0\n cmovgl %2,%1\n cmovgl %0,%2" : "=&r"(crypto_int32_z), "+&r"(crypto_int32_x), "+r"(crypto_int32_y) : : "cc");
*crypto_int32_p = crypto_int32_x;
*crypto_int32_q = crypto_int32_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_r, crypto_int32_s;
__asm__ ("cmp %w2,%w3\n csel %w0,%w2,%w3,lt\n csel %w1,%w3,%w2,lt" : "=&r"(crypto_int32_r), "=r"(crypto_int32_s) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
*crypto_int32_p = crypto_int32_r;
*crypto_int32_q = crypto_int32_s;
#else
crypto_int32 crypto_int32_r = crypto_int32_y ^ crypto_int32_x;
crypto_int32 crypto_int32_z = crypto_int32_y - crypto_int32_x;
crypto_int32_z ^= crypto_int32_r & (crypto_int32_z ^ crypto_int32_y);
crypto_int32_z = crypto_int32_negative_mask(crypto_int32_z);
crypto_int32_z &= crypto_int32_r;
crypto_int32_x ^= crypto_int32_z;
crypto_int32_y ^= crypto_int32_z;
*crypto_int32_p = crypto_int32_x;
*crypto_int32_q = crypto_int32_y;
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_smaller_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovll %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,lt" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
crypto_int32 crypto_int32_r = crypto_int32_x ^ crypto_int32_y;
crypto_int32 crypto_int32_z = crypto_int32_x - crypto_int32_y;
crypto_int32_z ^= crypto_int32_r & (crypto_int32_z ^ crypto_int32_x);
return crypto_int32_negative_mask(crypto_int32_z);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_smaller_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovll %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,lt" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
crypto_int32 crypto_int32_r = crypto_int32_x ^ crypto_int32_y;
crypto_int32 crypto_int32_z = crypto_int32_x - crypto_int32_y;
crypto_int32_z ^= crypto_int32_r & (crypto_int32_z ^ crypto_int32_x);
return crypto_int32_unsigned_topbit_01(crypto_int32_z);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_leq_mask(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovlel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,le" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return ~crypto_int32_smaller_mask(crypto_int32_y,crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
crypto_int32 crypto_int32_leq_01(crypto_int32 crypto_int32_x,crypto_int32 crypto_int32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 crypto_int32_q,crypto_int32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovlel %1,%0" : "=&r"(crypto_int32_z), "=&r"(crypto_int32_q) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int32 crypto_int32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,le" : "=r"(crypto_int32_z) : "r"(crypto_int32_x), "r"(crypto_int32_y) : "cc");
return crypto_int32_z;
#else
return 1-crypto_int32_smaller_01(crypto_int32_y,crypto_int32_x);
#endif
}
__attribute__((unused))
static inline
int crypto_int32_ones_num(crypto_int32 crypto_int32_x) {
crypto_int32_unsigned crypto_int32_y = crypto_int32_x;
const crypto_int32 C0 = 0x55555555;
const crypto_int32 C1 = 0x33333333;
const crypto_int32 C2 = 0x0f0f0f0f;
crypto_int32_y -= ((crypto_int32_y >> 1) & C0);
crypto_int32_y = (crypto_int32_y & C1) + ((crypto_int32_y >> 2) & C1);
crypto_int32_y = (crypto_int32_y + (crypto_int32_y >> 4)) & C2;
crypto_int32_y += crypto_int32_y >> 8;
crypto_int32_y = (crypto_int32_y + (crypto_int32_y >> 16)) & 0xff;
return crypto_int32_y;
}
__attribute__((unused))
static inline
int crypto_int32_bottomzeros_num(crypto_int32 crypto_int32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int32 fallback = 32;
__asm__ ("bsfl %0,%0\n cmovel %1,%0" : "+&r"(crypto_int32_x) : "r"(fallback) : "cc");
return crypto_int32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_int32_y;
__asm__ ("rbit %w0,%w1\n clz %w0,%w0" : "=r"(crypto_int32_y) : "r"(crypto_int32_x) : );
return crypto_int32_y;
#else
crypto_int32 crypto_int32_y = crypto_int32_x ^ (crypto_int32_x-1);
crypto_int32_y = ((crypto_int32) crypto_int32_y) >> 1;
crypto_int32_y &= ~(crypto_int32_x & (((crypto_int32) 1) << (32-1)));
return crypto_int32_ones_num(crypto_int32_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_int64.h 0000664 0000000 0000000 00000054417 14747360755 0020255 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_int64_h
#define crypto_int64_h
#include
#define crypto_int64 int64_t
#define crypto_int64_unsigned uint64_t
#define crypto_int64_optblocker tinyssh_int64_optblocker
extern volatile crypto_int64 crypto_int64_optblocker;
__attribute__((unused))
static inline
crypto_int64 crypto_int64_load(const unsigned char *crypto_int64_s) {
crypto_int64 crypto_int64_z = 0;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 0;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 8;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 16;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 24;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 32;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 40;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 48;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 56;
return crypto_int64_z;
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_load_bigendian(const unsigned char *crypto_int64_s) {
crypto_int64 crypto_int64_z = 0;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 56;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 48;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 40;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 32;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 24;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 16;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 8;
crypto_int64_z |= ((crypto_int64) (*crypto_int64_s++)) << 0;
return crypto_int64_z;
}
__attribute__((unused))
static inline
void crypto_int64_store(unsigned char *crypto_int64_s,crypto_int64 crypto_int64_x) {
*crypto_int64_s++ = crypto_int64_x >> 0;
*crypto_int64_s++ = crypto_int64_x >> 8;
*crypto_int64_s++ = crypto_int64_x >> 16;
*crypto_int64_s++ = crypto_int64_x >> 24;
*crypto_int64_s++ = crypto_int64_x >> 32;
*crypto_int64_s++ = crypto_int64_x >> 40;
*crypto_int64_s++ = crypto_int64_x >> 48;
*crypto_int64_s++ = crypto_int64_x >> 56;
}
__attribute__((unused))
static inline
void crypto_int64_store_bigendian(unsigned char *crypto_int64_s,crypto_int64 crypto_int64_x) {
*crypto_int64_s++ = crypto_int64_x >> 56;
*crypto_int64_s++ = crypto_int64_x >> 48;
*crypto_int64_s++ = crypto_int64_x >> 40;
*crypto_int64_s++ = crypto_int64_x >> 32;
*crypto_int64_s++ = crypto_int64_x >> 24;
*crypto_int64_s++ = crypto_int64_x >> 16;
*crypto_int64_s++ = crypto_int64_x >> 8;
*crypto_int64_s++ = crypto_int64_x >> 0;
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_negative_mask(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarq $63,%0" : "+r"(crypto_int64_x) : : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_y;
__asm__ ("asr %0,%1,63" : "=r"(crypto_int64_y) : "r"(crypto_int64_x) : );
return crypto_int64_y;
#else
crypto_int64_x >>= 64-6;
crypto_int64_x += crypto_int64_optblocker;
crypto_int64_x >>= 5;
return crypto_int64_x;
#endif
}
__attribute__((unused))
static inline
crypto_int64_unsigned crypto_int64_unsigned_topbit_01(crypto_int64_unsigned crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrq $63,%0" : "+r"(crypto_int64_x) : : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_y;
__asm__ ("lsr %0,%1,63" : "=r"(crypto_int64_y) : "r"(crypto_int64_x) : );
return crypto_int64_y;
#else
crypto_int64_x >>= 64-6;
crypto_int64_x += crypto_int64_optblocker;
crypto_int64_x >>= 5;
return crypto_int64_x;
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_negative_01(crypto_int64 crypto_int64_x) {
return crypto_int64_unsigned_topbit_01(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_topbit_mask(crypto_int64 crypto_int64_x) {
return crypto_int64_negative_mask(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_topbit_01(crypto_int64 crypto_int64_x) {
return crypto_int64_unsigned_topbit_01(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bottombit_mask(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andq $1,%0" : "+r"(crypto_int64_x) : : "cc");
return -crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_y;
__asm__ ("sbfx %0,%1,0,1" : "=r"(crypto_int64_y) : "r"(crypto_int64_x) : );
return crypto_int64_y;
#else
crypto_int64_x &= 1 + crypto_int64_optblocker;
return -crypto_int64_x;
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bottombit_01(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andq $1,%0" : "+r"(crypto_int64_x) : : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_y;
__asm__ ("ubfx %0,%1,0,1" : "=r"(crypto_int64_y) : "r"(crypto_int64_x) : );
return crypto_int64_y;
#else
crypto_int64_x &= 1 + crypto_int64_optblocker;
return crypto_int64_x;
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bitinrangepublicpos_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarq %%cl,%0" : "+r"(crypto_int64_x) : "c"(crypto_int64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %0,%0,%1" : "+r"(crypto_int64_x) : "r"(crypto_int64_s) : );
#else
crypto_int64_x >>= crypto_int64_s ^ crypto_int64_optblocker;
#endif
return crypto_int64_bottombit_mask(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bitinrangepublicpos_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarq %%cl,%0" : "+r"(crypto_int64_x) : "c"(crypto_int64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %0,%0,%1" : "+r"(crypto_int64_x) : "r"(crypto_int64_s) : );
#else
crypto_int64_x >>= crypto_int64_s ^ crypto_int64_optblocker;
#endif
return crypto_int64_bottombit_01(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_shlmod(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shlq %%cl,%0" : "+r"(crypto_int64_x) : "c"(crypto_int64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsl %0,%0,%1" : "+r"(crypto_int64_x) : "r"(crypto_int64_s) : );
#else
int crypto_int64_k, crypto_int64_l;
for (crypto_int64_l = 0,crypto_int64_k = 1;crypto_int64_k < 64;++crypto_int64_l,crypto_int64_k *= 2)
crypto_int64_x ^= (crypto_int64_x ^ (crypto_int64_x << crypto_int64_k)) & crypto_int64_bitinrangepublicpos_mask(crypto_int64_s,crypto_int64_l);
#endif
return crypto_int64_x;
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_shrmod(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarq %%cl,%0" : "+r"(crypto_int64_x) : "c"(crypto_int64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("asr %0,%0,%1" : "+r"(crypto_int64_x) : "r"(crypto_int64_s) : );
#else
int crypto_int64_k, crypto_int64_l;
for (crypto_int64_l = 0,crypto_int64_k = 1;crypto_int64_k < 64;++crypto_int64_l,crypto_int64_k *= 2)
crypto_int64_x ^= (crypto_int64_x ^ (crypto_int64_x >> crypto_int64_k)) & crypto_int64_bitinrangepublicpos_mask(crypto_int64_s,crypto_int64_l);
#endif
return crypto_int64_x;
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bitmod_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
crypto_int64_x = crypto_int64_shrmod(crypto_int64_x,crypto_int64_s);
return crypto_int64_bottombit_mask(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_bitmod_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_s) {
crypto_int64_x = crypto_int64_shrmod(crypto_int64_x,crypto_int64_s);
return crypto_int64_bottombit_01(crypto_int64_x);
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_nonzero_mask(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n testq %2,%2\n cmovneq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n csetm %0,ne" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
crypto_int64_x |= -crypto_int64_x;
return crypto_int64_negative_mask(crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_nonzero_01(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n testq %2,%2\n cmovneq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n cset %0,ne" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
crypto_int64_x |= -crypto_int64_x;
return crypto_int64_unsigned_topbit_01(crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_positive_mask(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n testq %2,%2\n cmovgq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n csetm %0,gt" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
crypto_int64 crypto_int64_z = -crypto_int64_x;
crypto_int64_z ^= crypto_int64_x & crypto_int64_z;
return crypto_int64_negative_mask(crypto_int64_z);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_positive_01(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n testq %2,%2\n cmovgq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n cset %0,gt" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
crypto_int64 crypto_int64_z = -crypto_int64_x;
crypto_int64_z ^= crypto_int64_x & crypto_int64_z;
return crypto_int64_unsigned_topbit_01(crypto_int64_z);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_zero_mask(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n testq %2,%2\n cmoveq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n csetm %0,eq" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
return ~crypto_int64_nonzero_mask(crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_zero_01(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n testq %2,%2\n cmoveq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,0\n cset %0,eq" : "=r"(crypto_int64_z) : "r"(crypto_int64_x) : "cc");
return crypto_int64_z;
#else
return 1-crypto_int64_nonzero_01(crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_unequal_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovneq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n csetm %0,ne" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return crypto_int64_nonzero_mask(crypto_int64_x ^ crypto_int64_y);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_unequal_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovneq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n cset %0,ne" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return crypto_int64_nonzero_01(crypto_int64_x ^ crypto_int64_y);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_equal_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmoveq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n csetm %0,eq" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return ~crypto_int64_unequal_mask(crypto_int64_x,crypto_int64_y);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_equal_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmoveq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n cset %0,eq" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return 1-crypto_int64_unequal_01(crypto_int64_x,crypto_int64_y);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_min(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpq %1,%0\n cmovgq %1,%0" : "+r"(crypto_int64_x) : "r"(crypto_int64_y) : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %0,%1\n csel %0,%0,%1,lt" : "+r"(crypto_int64_x) : "r"(crypto_int64_y) : "cc");
return crypto_int64_x;
#else
crypto_int64 crypto_int64_r = crypto_int64_y ^ crypto_int64_x;
crypto_int64 crypto_int64_z = crypto_int64_y - crypto_int64_x;
crypto_int64_z ^= crypto_int64_r & (crypto_int64_z ^ crypto_int64_y);
crypto_int64_z = crypto_int64_negative_mask(crypto_int64_z);
crypto_int64_z &= crypto_int64_r;
return crypto_int64_x ^ crypto_int64_z;
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_max(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpq %1,%0\n cmovlq %1,%0" : "+r"(crypto_int64_x) : "r"(crypto_int64_y) : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %0,%1\n csel %0,%1,%0,lt" : "+r"(crypto_int64_x) : "r"(crypto_int64_y) : "cc");
return crypto_int64_x;
#else
crypto_int64 crypto_int64_r = crypto_int64_y ^ crypto_int64_x;
crypto_int64 crypto_int64_z = crypto_int64_y - crypto_int64_x;
crypto_int64_z ^= crypto_int64_r & (crypto_int64_z ^ crypto_int64_y);
crypto_int64_z = crypto_int64_negative_mask(crypto_int64_z);
crypto_int64_z &= crypto_int64_r;
return crypto_int64_y ^ crypto_int64_z;
#endif
}
__attribute__((unused))
static inline
void crypto_int64_minmax(crypto_int64 *crypto_int64_p,crypto_int64 *crypto_int64_q) {
crypto_int64 crypto_int64_x = *crypto_int64_p;
crypto_int64 crypto_int64_y = *crypto_int64_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmpq %2,%1\n movq %1,%0\n cmovgq %2,%1\n cmovgq %0,%2" : "=&r"(crypto_int64_z), "+&r"(crypto_int64_x), "+r"(crypto_int64_y) : : "cc");
*crypto_int64_p = crypto_int64_x;
*crypto_int64_q = crypto_int64_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_r, crypto_int64_s;
__asm__ ("cmp %2,%3\n csel %0,%2,%3,lt\n csel %1,%3,%2,lt" : "=&r"(crypto_int64_r), "=r"(crypto_int64_s) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
*crypto_int64_p = crypto_int64_r;
*crypto_int64_q = crypto_int64_s;
#else
crypto_int64 crypto_int64_r = crypto_int64_y ^ crypto_int64_x;
crypto_int64 crypto_int64_z = crypto_int64_y - crypto_int64_x;
crypto_int64_z ^= crypto_int64_r & (crypto_int64_z ^ crypto_int64_y);
crypto_int64_z = crypto_int64_negative_mask(crypto_int64_z);
crypto_int64_z &= crypto_int64_r;
crypto_int64_x ^= crypto_int64_z;
crypto_int64_y ^= crypto_int64_z;
*crypto_int64_p = crypto_int64_x;
*crypto_int64_q = crypto_int64_y;
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_smaller_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovlq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n csetm %0,lt" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
crypto_int64 crypto_int64_r = crypto_int64_x ^ crypto_int64_y;
crypto_int64 crypto_int64_z = crypto_int64_x - crypto_int64_y;
crypto_int64_z ^= crypto_int64_r & (crypto_int64_z ^ crypto_int64_x);
return crypto_int64_negative_mask(crypto_int64_z);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_smaller_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovlq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n cset %0,lt" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
crypto_int64 crypto_int64_r = crypto_int64_x ^ crypto_int64_y;
crypto_int64 crypto_int64_z = crypto_int64_x - crypto_int64_y;
crypto_int64_z ^= crypto_int64_r & (crypto_int64_z ^ crypto_int64_x);
return crypto_int64_unsigned_topbit_01(crypto_int64_z);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_leq_mask(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovleq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n csetm %0,le" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return ~crypto_int64_smaller_mask(crypto_int64_y,crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
crypto_int64 crypto_int64_leq_01(crypto_int64 crypto_int64_x,crypto_int64 crypto_int64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 crypto_int64_q,crypto_int64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovleq %1,%0" : "=&r"(crypto_int64_z), "=&r"(crypto_int64_q) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int64 crypto_int64_z;
__asm__ ("cmp %1,%2\n cset %0,le" : "=r"(crypto_int64_z) : "r"(crypto_int64_x), "r"(crypto_int64_y) : "cc");
return crypto_int64_z;
#else
return 1-crypto_int64_smaller_01(crypto_int64_y,crypto_int64_x);
#endif
}
__attribute__((unused))
static inline
int crypto_int64_ones_num(crypto_int64 crypto_int64_x) {
crypto_int64_unsigned crypto_int64_y = crypto_int64_x;
const crypto_int64 C0 = 0x5555555555555555;
const crypto_int64 C1 = 0x3333333333333333;
const crypto_int64 C2 = 0x0f0f0f0f0f0f0f0f;
crypto_int64_y -= ((crypto_int64_y >> 1) & C0);
crypto_int64_y = (crypto_int64_y & C1) + ((crypto_int64_y >> 2) & C1);
crypto_int64_y = (crypto_int64_y + (crypto_int64_y >> 4)) & C2;
crypto_int64_y += crypto_int64_y >> 8;
crypto_int64_y += crypto_int64_y >> 16;
crypto_int64_y = (crypto_int64_y + (crypto_int64_y >> 32)) & 0xff;
return crypto_int64_y;
}
__attribute__((unused))
static inline
int crypto_int64_bottomzeros_num(crypto_int64 crypto_int64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int64 fallback = 64;
__asm__ ("bsfq %0,%0\n cmoveq %1,%0" : "+&r"(crypto_int64_x) : "r"(fallback) : "cc");
return crypto_int64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_int64_y;
__asm__ ("rbit %0,%1\n clz %0,%0" : "=r"(crypto_int64_y) : "r"(crypto_int64_x) : );
return crypto_int64_y;
#else
crypto_int64 crypto_int64_y = crypto_int64_x ^ (crypto_int64_x-1);
crypto_int64_y = ((crypto_int64) crypto_int64_y) >> 1;
crypto_int64_y &= ~(crypto_int64_x & (((crypto_int64) 1) << (64-1)));
return crypto_int64_ones_num(crypto_int64_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_int8.h 0000664 0000000 0000000 00000055053 14747360755 0020170 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_int8_h
#define crypto_int8_h
#include
#define crypto_int8 int8_t
#define crypto_int8_unsigned uint8_t
#define crypto_int8_optblocker tinyssh_int8_optblocker
extern volatile crypto_int8 crypto_int8_optblocker;
__attribute__((unused))
static inline
crypto_int8 crypto_int8_load(const unsigned char *crypto_int8_s) {
crypto_int8 crypto_int8_z = 0;
crypto_int8_z |= ((crypto_int8) (*crypto_int8_s++)) << 0;
return crypto_int8_z;
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_load_bigendian(const unsigned char *crypto_int8_s) {
crypto_int8 crypto_int8_z = 0;
crypto_int8_z |= ((crypto_int8) (*crypto_int8_s++)) << 0;
return crypto_int8_z;
}
__attribute__((unused))
static inline
void crypto_int8_store(unsigned char *crypto_int8_s,crypto_int8 crypto_int8_x) {
*crypto_int8_s++ = crypto_int8_x >> 0;
}
__attribute__((unused))
static inline
void crypto_int8_store_bigendian(unsigned char *crypto_int8_s,crypto_int8 crypto_int8_x) {
*crypto_int8_s++ = crypto_int8_x >> 0;
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_negative_mask(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarb $7,%0" : "+r"(crypto_int8_x) : : "cc");
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_y;
__asm__ ("sbfx %w0,%w1,7,1" : "=r"(crypto_int8_y) : "r"(crypto_int8_x) : );
return crypto_int8_y;
#else
crypto_int8_x >>= 8-6;
crypto_int8_x += crypto_int8_optblocker;
crypto_int8_x >>= 5;
return crypto_int8_x;
#endif
}
__attribute__((unused))
static inline
crypto_int8_unsigned crypto_int8_unsigned_topbit_01(crypto_int8_unsigned crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrb $7,%0" : "+r"(crypto_int8_x) : : "cc");
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_y;
__asm__ ("ubfx %w0,%w1,7,1" : "=r"(crypto_int8_y) : "r"(crypto_int8_x) : );
return crypto_int8_y;
#else
crypto_int8_x >>= 8-6;
crypto_int8_x += crypto_int8_optblocker;
crypto_int8_x >>= 5;
return crypto_int8_x;
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_negative_01(crypto_int8 crypto_int8_x) {
return crypto_int8_unsigned_topbit_01(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_topbit_mask(crypto_int8 crypto_int8_x) {
return crypto_int8_negative_mask(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_topbit_01(crypto_int8 crypto_int8_x) {
return crypto_int8_unsigned_topbit_01(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bottombit_mask(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andb $1,%0" : "+r"(crypto_int8_x) : : "cc");
return -crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_int8_y) : "r"(crypto_int8_x) : );
return crypto_int8_y;
#else
crypto_int8_x &= 1 + crypto_int8_optblocker;
return -crypto_int8_x;
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bottombit_01(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andb $1,%0" : "+r"(crypto_int8_x) : : "cc");
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_int8_y) : "r"(crypto_int8_x) : );
return crypto_int8_y;
#else
crypto_int8_x &= 1 + crypto_int8_optblocker;
return crypto_int8_x;
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bitinrangepublicpos_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarb %%cl,%0" : "+r"(crypto_int8_x) : "c"(crypto_int8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxtb %w0,%w0\n asr %w0,%w0,%w1" : "+&r"(crypto_int8_x) : "r"(crypto_int8_s) : );
#else
crypto_int8_x >>= crypto_int8_s ^ crypto_int8_optblocker;
#endif
return crypto_int8_bottombit_mask(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bitinrangepublicpos_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarb %%cl,%0" : "+r"(crypto_int8_x) : "c"(crypto_int8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxtb %w0,%w0\n asr %w0,%w0,%w1" : "+&r"(crypto_int8_x) : "r"(crypto_int8_s) : );
#else
crypto_int8_x >>= crypto_int8_s ^ crypto_int8_optblocker;
#endif
return crypto_int8_bottombit_01(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_shlmod(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8_s &= 7;
__asm__ ("shlb %%cl,%0" : "+r"(crypto_int8_x) : "c"(crypto_int8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,7\n and %w1,%w1,255\n lsl %w1,%w1,%w0" : "+&r"(crypto_int8_s), "+r"(crypto_int8_x) : : );
#else
int crypto_int8_k, crypto_int8_l;
for (crypto_int8_l = 0,crypto_int8_k = 1;crypto_int8_k < 8;++crypto_int8_l,crypto_int8_k *= 2)
crypto_int8_x ^= (crypto_int8_x ^ (crypto_int8_x << crypto_int8_k)) & crypto_int8_bitinrangepublicpos_mask(crypto_int8_s,crypto_int8_l);
#endif
return crypto_int8_x;
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_shrmod(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8_s &= 7;
__asm__ ("sarb %%cl,%0" : "+r"(crypto_int8_x) : "c"(crypto_int8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,7\n sxtb %w1,%w1\n asr %w1,%w1,%w0" : "+&r"(crypto_int8_s), "+r"(crypto_int8_x) : : );
#else
int crypto_int8_k, crypto_int8_l;
for (crypto_int8_l = 0,crypto_int8_k = 1;crypto_int8_k < 8;++crypto_int8_l,crypto_int8_k *= 2)
crypto_int8_x ^= (crypto_int8_x ^ (crypto_int8_x >> crypto_int8_k)) & crypto_int8_bitinrangepublicpos_mask(crypto_int8_s,crypto_int8_l);
#endif
return crypto_int8_x;
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bitmod_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
crypto_int8_x = crypto_int8_shrmod(crypto_int8_x,crypto_int8_s);
return crypto_int8_bottombit_mask(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_bitmod_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_s) {
crypto_int8_x = crypto_int8_shrmod(crypto_int8_x,crypto_int8_s);
return crypto_int8_bottombit_01(crypto_int8_x);
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_nonzero_mask(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testb %b2,%b2\n cmovnel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("tst %w1,255\n csetm %w0,ne" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
crypto_int8_x |= -crypto_int8_x;
return crypto_int8_negative_mask(crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_nonzero_01(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n testb %b2,%b2\n cmovnel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("tst %w1,255\n cset %w0,ne" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
crypto_int8_x |= -crypto_int8_x;
return crypto_int8_unsigned_topbit_01(crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_positive_mask(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testb %b2,%b2\n cmovgl %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,0\n csetm %w0,gt" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
crypto_int8 crypto_int8_z = -crypto_int8_x;
crypto_int8_z ^= crypto_int8_x & crypto_int8_z;
return crypto_int8_negative_mask(crypto_int8_z);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_positive_01(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n testb %b2,%b2\n cmovgl %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,0\n cset %w0,gt" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
crypto_int8 crypto_int8_z = -crypto_int8_x;
crypto_int8_z ^= crypto_int8_x & crypto_int8_z;
return crypto_int8_unsigned_topbit_01(crypto_int8_z);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_zero_mask(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testb %b2,%b2\n cmovel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("tst %w1,255\n csetm %w0,eq" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
return ~crypto_int8_nonzero_mask(crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_zero_01(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n testb %b2,%b2\n cmovel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("tst %w1,255\n cset %w0,eq" : "=r"(crypto_int8_z) : "r"(crypto_int8_x) : "cc");
return crypto_int8_z;
#else
return 1-crypto_int8_nonzero_01(crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_unequal_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovnel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,ne" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return crypto_int8_nonzero_mask(crypto_int8_x ^ crypto_int8_y);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_unequal_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovnel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,ne" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return crypto_int8_nonzero_01(crypto_int8_x ^ crypto_int8_y);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_equal_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,eq" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return ~crypto_int8_unequal_mask(crypto_int8_x,crypto_int8_y);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_equal_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,eq" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return 1-crypto_int8_unequal_01(crypto_int8_x,crypto_int8_y);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_min(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y;
__asm__ ("cmpb %b1,%b0\n cmovgl %1,%0" : "+q"(crypto_int8_x32) : "q"(crypto_int8_y32) : "cc");
crypto_int8_x = crypto_int8_x32;
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxtb %w0,%w0\n cmp %w0,%w1,sxtb\n csel %w0,%w0,%w1,lt" : "+&r"(crypto_int8_x) : "r"(crypto_int8_y) : "cc");
return crypto_int8_x;
#else
crypto_int8 crypto_int8_r = crypto_int8_y ^ crypto_int8_x;
crypto_int8 crypto_int8_z = crypto_int8_y - crypto_int8_x;
crypto_int8_z ^= crypto_int8_r & (crypto_int8_z ^ crypto_int8_y);
crypto_int8_z = crypto_int8_negative_mask(crypto_int8_z);
crypto_int8_z &= crypto_int8_r;
return crypto_int8_x ^ crypto_int8_z;
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_max(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y;
__asm__ ("cmpb %b1,%b0\n cmovll %1,%0" : "+q"(crypto_int8_x32) : "q"(crypto_int8_y32) : "cc");
crypto_int8_x = crypto_int8_x32;
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("sxtb %w0,%w0\n cmp %w0,%w1,sxtb\n csel %w0,%w1,%w0,lt" : "+&r"(crypto_int8_x) : "r"(crypto_int8_y) : "cc");
return crypto_int8_x;
#else
crypto_int8 crypto_int8_r = crypto_int8_y ^ crypto_int8_x;
crypto_int8 crypto_int8_z = crypto_int8_y - crypto_int8_x;
crypto_int8_z ^= crypto_int8_r & (crypto_int8_z ^ crypto_int8_y);
crypto_int8_z = crypto_int8_negative_mask(crypto_int8_z);
crypto_int8_z &= crypto_int8_r;
return crypto_int8_y ^ crypto_int8_z;
#endif
}
__attribute__((unused))
static inline
void crypto_int8_minmax(crypto_int8 *crypto_int8_p,crypto_int8 *crypto_int8_q) {
crypto_int8 crypto_int8_x = *crypto_int8_p;
crypto_int8 crypto_int8_y = *crypto_int8_q;
#if defined(__GNUC__) && defined(__x86_64__)
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_z32;
__asm__ ("cmpb %b2,%b1\n movl %1,%0\n cmovgl %2,%1\n cmovgl %0,%2" : "=&r"(crypto_int8_z32), "+&q"(crypto_int8_x32), "+q"(crypto_int8_y32) : : "cc");
crypto_int8_x = crypto_int8_x32; crypto_int8_y = crypto_int8_y32;
*crypto_int8_p = crypto_int8_x;
*crypto_int8_q = crypto_int8_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_r, crypto_int8_s;
__asm__ ("sxtb %w0,%w0\n cmp %w0,%w3,sxtb\n csel %w1,%w0,%w3,lt\n csel %w2,%w3,%w0,lt" : "+&r"(crypto_int8_x), "=&r"(crypto_int8_r), "=r"(crypto_int8_s) : "r"(crypto_int8_y) : "cc");
*crypto_int8_p = crypto_int8_r;
*crypto_int8_q = crypto_int8_s;
#else
crypto_int8 crypto_int8_r = crypto_int8_y ^ crypto_int8_x;
crypto_int8 crypto_int8_z = crypto_int8_y - crypto_int8_x;
crypto_int8_z ^= crypto_int8_r & (crypto_int8_z ^ crypto_int8_y);
crypto_int8_z = crypto_int8_negative_mask(crypto_int8_z);
crypto_int8_z &= crypto_int8_r;
crypto_int8_x ^= crypto_int8_z;
crypto_int8_y ^= crypto_int8_z;
*crypto_int8_p = crypto_int8_x;
*crypto_int8_q = crypto_int8_y;
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_smaller_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovll %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,%w2,sxtb\n csetm %w0,lt" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
crypto_int8 crypto_int8_r = crypto_int8_x ^ crypto_int8_y;
crypto_int8 crypto_int8_z = crypto_int8_x - crypto_int8_y;
crypto_int8_z ^= crypto_int8_r & (crypto_int8_z ^ crypto_int8_x);
return crypto_int8_negative_mask(crypto_int8_z);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_smaller_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovll %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,%w2,sxtb\n cset %w0,lt" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
crypto_int8 crypto_int8_r = crypto_int8_x ^ crypto_int8_y;
crypto_int8 crypto_int8_z = crypto_int8_x - crypto_int8_y;
crypto_int8_z ^= crypto_int8_r & (crypto_int8_z ^ crypto_int8_x);
return crypto_int8_unsigned_topbit_01(crypto_int8_z);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_leq_mask(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovlel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,%w2,sxtb\n csetm %w0,le" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return ~crypto_int8_smaller_mask(crypto_int8_y,crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
crypto_int8 crypto_int8_leq_01(crypto_int8 crypto_int8_x,crypto_int8 crypto_int8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_int8 crypto_int8_z;
int32_t crypto_int8_x32 = crypto_int8_x,crypto_int8_y32 = crypto_int8_y,crypto_int8_q32,crypto_int8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovlel %1,%0" : "=&r"(crypto_int8_z32), "=&r"(crypto_int8_q32) : "q"(crypto_int8_x32), "q"(crypto_int8_y32) : "cc");
crypto_int8_z = crypto_int8_z32;
return crypto_int8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_int8 crypto_int8_z;
__asm__ ("sxtb %w0,%w1\n cmp %w0,%w2,sxtb\n cset %w0,le" : "=&r"(crypto_int8_z) : "r"(crypto_int8_x), "r"(crypto_int8_y) : "cc");
return crypto_int8_z;
#else
return 1-crypto_int8_smaller_01(crypto_int8_y,crypto_int8_x);
#endif
}
__attribute__((unused))
static inline
int crypto_int8_ones_num(crypto_int8 crypto_int8_x) {
crypto_int8_unsigned crypto_int8_y = crypto_int8_x;
const crypto_int8 C0 = 0x55;
const crypto_int8 C1 = 0x33;
const crypto_int8 C2 = 0x0f;
crypto_int8_y -= ((crypto_int8_y >> 1) & C0);
crypto_int8_y = (crypto_int8_y & C1) + ((crypto_int8_y >> 2) & C1);
crypto_int8_y = (crypto_int8_y + (crypto_int8_y >> 4)) & C2;
return crypto_int8_y;
}
__attribute__((unused))
static inline
int crypto_int8_bottomzeros_num(crypto_int8 crypto_int8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
int32_t fallback = 8;
int32_t crypto_int8_x32 = crypto_int8_x;
__asm__ ("bsfl %0,%0\n cmovel %1,%0" : "+&r"(crypto_int8_x32) : "r"(fallback) : "cc");
crypto_int8_x = crypto_int8_x32;
return crypto_int8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_int8_y;
__asm__ ("orr %w0,%w1,-256\n rbit %w0,%w0\n clz %w0,%w0" : "=r"(crypto_int8_y) : "r"(crypto_int8_x) : );
return crypto_int8_y;
#else
crypto_int8 crypto_int8_y = crypto_int8_x ^ (crypto_int8_x-1);
crypto_int8_y = ((crypto_int8) crypto_int8_y) >> 1;
crypto_int8_y &= ~(crypto_int8_x & (((crypto_int8) 1) << (8-1)));
return crypto_int8_ones_num(crypto_int8_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_intN.h 0000664 0000000 0000000 00000140740 14747360755 0020214 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_intN_h
#define crypto_intN_h
#include
#define crypto_intN intN_t
#define crypto_intN_unsigned uintN_t
#define crypto_intN_optblocker namespace_intN_optblocker
extern volatile crypto_intN crypto_intN_optblocker;
__attribute__((unused))
static inline
crypto_intN crypto_intN_load(const unsigned char *crypto_intN_s) {
crypto_intN crypto_intN_z = 0;
int crypto_intN_k;
for (crypto_intN_k = 0;crypto_intN_k < N;crypto_intN_k += 8)
crypto_intN_z |= ((crypto_intN) (*crypto_intN_s++)) << crypto_intN_k;
return crypto_intN_z;
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_load_bigendian(const unsigned char *crypto_intN_s) {
crypto_intN crypto_intN_z = 0;
int crypto_intN_k;
for (crypto_intN_k = N - 8;crypto_intN_k >= 0;crypto_intN_k -= 8)
crypto_intN_z |= ((crypto_intN) (*crypto_intN_s++)) << crypto_intN_k;
return crypto_intN_z;
}
__attribute__((unused))
static inline
void crypto_intN_store(unsigned char *crypto_intN_s,crypto_intN crypto_intN_x) {
int crypto_intN_k;
for (crypto_intN_k = 0;crypto_intN_k < N;crypto_intN_k += 8)
*crypto_intN_s++ = crypto_intN_x >> crypto_intN_k;
}
__attribute__((unused))
static inline
void crypto_intN_store_bigendian(unsigned char *crypto_intN_s,crypto_intN crypto_intN_x) {
int crypto_intN_k;
for (crypto_intN_k = N - 8;crypto_intN_k >= 0;crypto_intN_k -= 8)
*crypto_intN_s++ = crypto_intN_x >> crypto_intN_k;
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_negative_mask(crypto_intN crypto_intN_x) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x; crypto_intN_x signed>>= 7");
16: readasm("amd64; int16 crypto_intN_x; crypto_intN_x signed>>= 15");
32: readasm("amd64; int32 crypto_intN_x; crypto_intN_x signed>>= 31");
64: readasm("amd64; int64 crypto_intN_x; crypto_intN_x signed>>= 63");
return crypto_intN_x;
#elif arm64
crypto_intN crypto_intN_y;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 7))");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 15))");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x signed>> 31");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x signed>> 63");
return crypto_intN_y;
#else
crypto_intN_x >>= N-6;
crypto_intN_x += crypto_intN_optblocker;
crypto_intN_x >>= 5;
return crypto_intN_x;
#endif
}
__attribute__((unused))
static inline
crypto_intN_unsigned crypto_intN_unsigned_topbit_01(crypto_intN_unsigned crypto_intN_x) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x; crypto_intN_x unsigned>>= 7");
16: readasm("amd64; int16 crypto_intN_x; crypto_intN_x unsigned>>= 15");
32: readasm("amd64; int32 crypto_intN_x; crypto_intN_x unsigned>>= 31");
64: readasm("amd64; int64 crypto_intN_x; crypto_intN_x unsigned>>= 63");
return crypto_intN_x;
#elif arm64
crypto_intN crypto_intN_y;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 7)");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 15)");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x unsigned>> 31");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x unsigned>> 63");
return crypto_intN_y;
#else
crypto_intN_x >>= N-6;
crypto_intN_x += crypto_intN_optblocker;
crypto_intN_x >>= 5;
return crypto_intN_x;
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_negative_01(crypto_intN crypto_intN_x) {
return crypto_intN_unsigned_topbit_01(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_topbit_mask(crypto_intN crypto_intN_x) {
return crypto_intN_negative_mask(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_topbit_01(crypto_intN crypto_intN_x) {
return crypto_intN_unsigned_topbit_01(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bottombit_mask(crypto_intN crypto_intN_x) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x; crypto_intN_x &= 1");
16: readasm("amd64; int16 crypto_intN_x; crypto_intN_x &= 1");
32: readasm("amd64; int32 crypto_intN_x; crypto_intN_x &= 1");
64: readasm("amd64; int64 crypto_intN_x; crypto_intN_x &= 1");
return -crypto_intN_x;
#elif arm64
crypto_intN crypto_intN_y;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 0))");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 0))");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 0))");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_y = -(1 & (crypto_intN_x unsigned>> 0))");
return crypto_intN_y;
#else
crypto_intN_x &= 1 + crypto_intN_optblocker;
return -crypto_intN_x;
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bottombit_01(crypto_intN crypto_intN_x) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x; crypto_intN_x &= 1");
16: readasm("amd64; int16 crypto_intN_x; crypto_intN_x &= 1");
32: readasm("amd64; int32 crypto_intN_x; crypto_intN_x &= 1");
64: readasm("amd64; int64 crypto_intN_x; crypto_intN_x &= 1");
return crypto_intN_x;
#elif arm64
crypto_intN crypto_intN_y;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 0)");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 0)");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 0)");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_y = 1 & (crypto_intN_x unsigned>> 0)");
return crypto_intN_y;
#else
crypto_intN_x &= 1 + crypto_intN_optblocker;
return crypto_intN_x;
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bitinrangepublicpos_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
16: readasm("amd64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
#else
crypto_intN_x >>= crypto_intN_s ^ crypto_intN_optblocker;
#endif
return crypto_intN_bottombit_mask(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bitinrangepublicpos_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
#if amd64
8: readasm("amd64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
16: readasm("amd64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
#else
crypto_intN_x >>= crypto_intN_s ^ crypto_intN_optblocker;
#endif
return crypto_intN_bottombit_01(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_shlmod(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
#if amd64
8: crypto_intN_s &= 7;
8: readasm("amd64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x <<= crypto_intN_s");
16: crypto_intN_s &= 15;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x <<= crypto_intN_s");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x <<= crypto_intN_s");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x <<= crypto_intN_s");
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_s; crypto_intN_s = crypto_intN_s & 7; crypto_intN_x = (uint8) crypto_intN_x; crypto_intN_x = crypto_intN_x << crypto_intN_s");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_s; crypto_intN_s = crypto_intN_s & 15; crypto_intN_x = (uint16) crypto_intN_x; crypto_intN_x = crypto_intN_x << crypto_intN_s");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x << crypto_intN_s");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x << crypto_intN_s");
#else
int crypto_intN_k, crypto_intN_l;
for (crypto_intN_l = 0,crypto_intN_k = 1;crypto_intN_k < N;++crypto_intN_l,crypto_intN_k *= 2)
crypto_intN_x ^= (crypto_intN_x ^ (crypto_intN_x << crypto_intN_k)) & crypto_intN_bitinrangepublicpos_mask(crypto_intN_s,crypto_intN_l);
#endif
return crypto_intN_x;
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_shrmod(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
#if amd64
8: crypto_intN_s &= 7;
8: readasm("amd64; int8 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
16: crypto_intN_s &= 15;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x signed>>= crypto_intN_s");
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_s; crypto_intN_s = crypto_intN_s & 7; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_s; crypto_intN_s = crypto_intN_s & 15; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_s; crypto_intN_x = crypto_intN_x signed>> crypto_intN_s");
#else
int crypto_intN_k, crypto_intN_l;
for (crypto_intN_l = 0,crypto_intN_k = 1;crypto_intN_k < N;++crypto_intN_l,crypto_intN_k *= 2)
crypto_intN_x ^= (crypto_intN_x ^ (crypto_intN_x >> crypto_intN_k)) & crypto_intN_bitinrangepublicpos_mask(crypto_intN_s,crypto_intN_l);
#endif
return crypto_intN_x;
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bitmod_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
crypto_intN_x = crypto_intN_shrmod(crypto_intN_x,crypto_intN_s);
return crypto_intN_bottombit_mask(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_bitmod_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_s) {
crypto_intN_x = crypto_intN_shrmod(crypto_intN_x,crypto_intN_s);
return crypto_intN_bottombit_01(crypto_intN_x);
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_nonzero_mask(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if !=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_x & 255; crypto_intN_z = -1 if != else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_x & 65535; crypto_intN_z = -1 if != else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if != else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if != else 0");
return crypto_intN_z;
#else
crypto_intN_x |= -crypto_intN_x;
return crypto_intN_negative_mask(crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_nonzero_01(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if !=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if !=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_x & 255; crypto_intN_z = 1 if != else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_x & 65535; crypto_intN_z = 1 if != else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if != else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if != else 0");
return crypto_intN_z;
#else
crypto_intN_x |= -crypto_intN_x;
return crypto_intN_unsigned_topbit_01(crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_positive_mask(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if signed>");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - 0; crypto_intN_z = -1 if signed> else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - 0; crypto_intN_z = -1 if signed> else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if signed> else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if signed> else 0");
return crypto_intN_z;
#else
crypto_intN crypto_intN_z = -crypto_intN_x;
crypto_intN_z ^= crypto_intN_x & crypto_intN_z;
return crypto_intN_negative_mask(crypto_intN_z);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_positive_01(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if signed>");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if signed>");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - 0; crypto_intN_z = 1 if signed> else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - 0; crypto_intN_z = 1 if signed> else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if signed> else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if signed> else 0");
return crypto_intN_z;
#else
crypto_intN crypto_intN_z = -crypto_intN_x;
crypto_intN_z ^= crypto_intN_x & crypto_intN_z;
return crypto_intN_unsigned_topbit_01(crypto_intN_z);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_zero_mask(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if =");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_x & 255; crypto_intN_z = -1 if = else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_x & 65535; crypto_intN_z = -1 if = else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if = else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = -1 if = else 0");
return crypto_intN_z;
#else
return ~crypto_intN_nonzero_mask(crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_zero_01(crypto_intN crypto_intN_x) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 & (int8) crypto_intN_x32; crypto_intN_z32 = crypto_intN_q32 if =");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x & crypto_intN_x; crypto_intN_z = crypto_intN_q if =");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_z; crypto_intN_x & 255; crypto_intN_z = 1 if = else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_z; crypto_intN_x & 65535; crypto_intN_z = 1 if = else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if = else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_z; crypto_intN_x - 0; crypto_intN_z = 1 if = else 0");
return crypto_intN_z;
#else
return 1-crypto_intN_nonzero_01(crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_unequal_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if !=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint8) crypto_intN_x; crypto_intN_z - (uint8) crypto_intN_y; crypto_intN_z = -1 if != else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint16) crypto_intN_x; crypto_intN_z - (uint16) crypto_intN_y; crypto_intN_z = -1 if != else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if != else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if != else 0");
return crypto_intN_z;
#else
return crypto_intN_nonzero_mask(crypto_intN_x ^ crypto_intN_y);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_unequal_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if !=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if !=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint8) crypto_intN_x; crypto_intN_z - (uint8) crypto_intN_y; crypto_intN_z = 1 if != else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint16) crypto_intN_x; crypto_intN_z - (uint16) crypto_intN_y; crypto_intN_z = 1 if != else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if != else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if != else 0");
return crypto_intN_z;
#else
return crypto_intN_nonzero_01(crypto_intN_x ^ crypto_intN_y);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_equal_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if =");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint8) crypto_intN_x; crypto_intN_z - (uint8) crypto_intN_y; crypto_intN_z = -1 if = else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint16) crypto_intN_x; crypto_intN_z - (uint16) crypto_intN_y; crypto_intN_z = -1 if = else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if = else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if = else 0");
return crypto_intN_z;
#else
return ~crypto_intN_unequal_mask(crypto_intN_x,crypto_intN_y);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_equal_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if =");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if =");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint8) crypto_intN_x; crypto_intN_z - (uint8) crypto_intN_y; crypto_intN_z = 1 if = else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (uint16) crypto_intN_x; crypto_intN_z - (uint16) crypto_intN_y; crypto_intN_z = 1 if = else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if = else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if = else 0");
return crypto_intN_z;
#else
return 1-crypto_intN_unequal_01(crypto_intN_x,crypto_intN_y);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_min(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_y32; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_x32 = crypto_intN_y32 if signed>");
8: crypto_intN_x = crypto_intN_x32;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed>");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed>");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed>");
return crypto_intN_x;
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x - (int8) crypto_intN_y; crypto_intN_x = crypto_intN_x if signed< else crypto_intN_y");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x - (int16) crypto_intN_y; crypto_intN_x = crypto_intN_x if signed< else crypto_intN_y");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_x if signed< else crypto_intN_y");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_x if signed< else crypto_intN_y");
return crypto_intN_x;
#else
crypto_intN crypto_intN_r = crypto_intN_y ^ crypto_intN_x;
crypto_intN crypto_intN_z = crypto_intN_y - crypto_intN_x;
crypto_intN_z ^= crypto_intN_r & (crypto_intN_z ^ crypto_intN_y);
crypto_intN_z = crypto_intN_negative_mask(crypto_intN_z);
crypto_intN_z &= crypto_intN_r;
return crypto_intN_x ^ crypto_intN_z;
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_max(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_y32; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_x32 = crypto_intN_y32 if signed<");
8: crypto_intN_x = crypto_intN_x32;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed<");
32: readasm("amd64; int32 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed<");
64: readasm("amd64; int64 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed<");
return crypto_intN_x;
#elif arm64
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x - (int8) crypto_intN_y; crypto_intN_x = crypto_intN_y if signed< else crypto_intN_x");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x - (int16) crypto_intN_y; crypto_intN_x = crypto_intN_y if signed< else crypto_intN_x");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed< else crypto_intN_x");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_x - crypto_intN_y; crypto_intN_x = crypto_intN_y if signed< else crypto_intN_x");
return crypto_intN_x;
#else
crypto_intN crypto_intN_r = crypto_intN_y ^ crypto_intN_x;
crypto_intN crypto_intN_z = crypto_intN_y - crypto_intN_x;
crypto_intN_z ^= crypto_intN_r & (crypto_intN_z ^ crypto_intN_y);
crypto_intN_z = crypto_intN_negative_mask(crypto_intN_z);
crypto_intN_z &= crypto_intN_r;
return crypto_intN_y ^ crypto_intN_z;
#endif
}
__attribute__((unused))
static inline
void crypto_intN_minmax(crypto_intN *crypto_intN_p,crypto_intN *crypto_intN_q) {
crypto_intN crypto_intN_x = *crypto_intN_p;
crypto_intN crypto_intN_y = *crypto_intN_q;
#if amd64
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_y32 crypto_intN_z32; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_x32; crypto_intN_x32 = crypto_intN_y32 if signed>; crypto_intN_y32 = crypto_intN_z32 if signed>");
8: crypto_intN_x = crypto_intN_x32; crypto_intN_y = crypto_intN_y32;
16: crypto_intN crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_x; crypto_intN_x = crypto_intN_y if signed>; crypto_intN_y = crypto_intN_z if signed>");
32: crypto_intN crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_x; crypto_intN_x = crypto_intN_y if signed>; crypto_intN_y = crypto_intN_z if signed>");
64: crypto_intN crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_x; crypto_intN_x = crypto_intN_y if signed>; crypto_intN_y = crypto_intN_z if signed>");
*crypto_intN_p = crypto_intN_x;
*crypto_intN_q = crypto_intN_y;
#elif arm64
crypto_intN crypto_intN_r, crypto_intN_s;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_r crypto_intN_s; crypto_intN_x = (int8) crypto_intN_x; crypto_intN_x - (int8) crypto_intN_y; crypto_intN_r = crypto_intN_x if signed< else crypto_intN_y; crypto_intN_s = crypto_intN_y if signed< else crypto_intN_x");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_r crypto_intN_s; crypto_intN_x = (int16) crypto_intN_x; crypto_intN_x - (int16) crypto_intN_y; crypto_intN_r = crypto_intN_x if signed< else crypto_intN_y; crypto_intN_s = crypto_intN_y if signed< else crypto_intN_x");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_r crypto_intN_s; crypto_intN_x - crypto_intN_y; crypto_intN_r = crypto_intN_x if signed< else crypto_intN_y; crypto_intN_s = crypto_intN_y if signed< else crypto_intN_x");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_r crypto_intN_s; crypto_intN_x - crypto_intN_y; crypto_intN_r = crypto_intN_x if signed< else crypto_intN_y; crypto_intN_s = crypto_intN_y if signed< else crypto_intN_x");
*crypto_intN_p = crypto_intN_r;
*crypto_intN_q = crypto_intN_s;
#else
crypto_intN crypto_intN_r = crypto_intN_y ^ crypto_intN_x;
crypto_intN crypto_intN_z = crypto_intN_y - crypto_intN_x;
crypto_intN_z ^= crypto_intN_r & (crypto_intN_z ^ crypto_intN_y);
crypto_intN_z = crypto_intN_negative_mask(crypto_intN_z);
crypto_intN_z &= crypto_intN_r;
crypto_intN_x ^= crypto_intN_z;
crypto_intN_y ^= crypto_intN_z;
*crypto_intN_p = crypto_intN_x;
*crypto_intN_q = crypto_intN_y;
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_smaller_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if signed<");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - (int8) crypto_intN_y; crypto_intN_z = -1 if signed< else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - (int16) crypto_intN_y; crypto_intN_z = -1 if signed< else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if signed< else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if signed< else 0");
return crypto_intN_z;
#else
crypto_intN crypto_intN_r = crypto_intN_x ^ crypto_intN_y;
crypto_intN crypto_intN_z = crypto_intN_x - crypto_intN_y;
crypto_intN_z ^= crypto_intN_r & (crypto_intN_z ^ crypto_intN_x);
return crypto_intN_negative_mask(crypto_intN_z);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_smaller_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if signed<");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - (int8) crypto_intN_y; crypto_intN_z = 1 if signed< else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - (int16) crypto_intN_y; crypto_intN_z = 1 if signed< else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if signed< else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if signed< else 0");
return crypto_intN_z;
#else
crypto_intN crypto_intN_r = crypto_intN_x ^ crypto_intN_y;
crypto_intN crypto_intN_z = crypto_intN_x - crypto_intN_y;
crypto_intN_z ^= crypto_intN_r & (crypto_intN_z ^ crypto_intN_x);
return crypto_intN_unsigned_topbit_01(crypto_intN_z);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_leq_mask(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = -1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if signed<=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = -1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - (int8) crypto_intN_y; crypto_intN_z = -1 if signed<= else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - (int16) crypto_intN_y; crypto_intN_z = -1 if signed<= else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if signed<= else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = -1 if signed<= else 0");
return crypto_intN_z;
#else
return ~crypto_intN_smaller_mask(crypto_intN_y,crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
crypto_intN crypto_intN_leq_01(crypto_intN crypto_intN_x,crypto_intN crypto_intN_y) {
#if amd64
8: crypto_intN crypto_intN_z;
8: int32_t crypto_intN_x32 = crypto_intN_x,crypto_intN_y32 = crypto_intN_y,crypto_intN_q32,crypto_intN_z32;
8: readasm("amd64; int32 crypto_intN_x32 crypto_intN_q32 crypto_intN_y32 crypto_intN_z32; crypto_intN_z32 = 0; crypto_intN_q32 = 1; crypto_intN_x32 - (int8) crypto_intN_y32; crypto_intN_z32 = crypto_intN_q32 if signed<=");
8: crypto_intN_z = crypto_intN_z32;
16: crypto_intN crypto_intN_q,crypto_intN_z;
16: readasm("amd64; int16 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
32: crypto_intN crypto_intN_q,crypto_intN_z;
32: readasm("amd64; int32 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
64: crypto_intN crypto_intN_q,crypto_intN_z;
64: readasm("amd64; int64 crypto_intN_x crypto_intN_q crypto_intN_y crypto_intN_z; crypto_intN_z = 0; crypto_intN_q = 1; crypto_intN_x - crypto_intN_y; crypto_intN_z = crypto_intN_q if signed<=");
return crypto_intN_z;
#elif arm64
crypto_intN crypto_intN_z;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int8) crypto_intN_x; crypto_intN_z - (int8) crypto_intN_y; crypto_intN_z = 1 if signed<= else 0");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_z = (int16) crypto_intN_x; crypto_intN_z - (int16) crypto_intN_y; crypto_intN_z = 1 if signed<= else 0");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if signed<= else 0");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y crypto_intN_z; crypto_intN_x - crypto_intN_y; crypto_intN_z = 1 if signed<= else 0");
return crypto_intN_z;
#else
return 1-crypto_intN_smaller_01(crypto_intN_y,crypto_intN_x);
#endif
}
__attribute__((unused))
static inline
int crypto_intN_ones_num(crypto_intN crypto_intN_x) {
crypto_intN_unsigned crypto_intN_y = crypto_intN_x;
8: const crypto_intN C0 = 0x55;
16: const crypto_intN C0 = 0x5555;
32: const crypto_intN C0 = 0x55555555;
64: const crypto_intN C0 = 0x5555555555555555;
8: const crypto_intN C1 = 0x33;
16: const crypto_intN C1 = 0x3333;
32: const crypto_intN C1 = 0x33333333;
64: const crypto_intN C1 = 0x3333333333333333;
8: const crypto_intN C2 = 0x0f;
16: const crypto_intN C2 = 0x0f0f;
32: const crypto_intN C2 = 0x0f0f0f0f;
64: const crypto_intN C2 = 0x0f0f0f0f0f0f0f0f;
crypto_intN_y -= ((crypto_intN_y >> 1) & C0);
crypto_intN_y = (crypto_intN_y & C1) + ((crypto_intN_y >> 2) & C1);
crypto_intN_y = (crypto_intN_y + (crypto_intN_y >> 4)) & C2;
16: crypto_intN_y = (crypto_intN_y + (crypto_intN_y >> 8)) & 0xff;
32: crypto_intN_y += crypto_intN_y >> 8;
32: crypto_intN_y = (crypto_intN_y + (crypto_intN_y >> 16)) & 0xff;
64: crypto_intN_y += crypto_intN_y >> 8;
64: crypto_intN_y += crypto_intN_y >> 16;
64: crypto_intN_y = (crypto_intN_y + (crypto_intN_y >> 32)) & 0xff;
return crypto_intN_y;
}
__attribute__((unused))
static inline
int crypto_intN_bottomzeros_num(crypto_intN crypto_intN_x) {
#if amd64
8: int32_t fallback = N;
8: int32_t crypto_intN_x32 = crypto_intN_x;
8: readasm("amd64; int32 crypto_intN_x32 fallback; crypto_intN_x32 = numbottomzeros_tricky crypto_intN_x32; crypto_intN_x32 = fallback if =");
8: crypto_intN_x = crypto_intN_x32;
16: crypto_intN fallback = N;
16: readasm("amd64; int16 crypto_intN_x fallback; crypto_intN_x = numbottomzeros_tricky crypto_intN_x; crypto_intN_x = fallback if =");
32: crypto_intN fallback = N;
32: readasm("amd64; int32 crypto_intN_x fallback; crypto_intN_x = numbottomzeros_tricky crypto_intN_x; crypto_intN_x = fallback if =");
64: crypto_intN fallback = N;
64: readasm("amd64; int64 crypto_intN_x fallback; crypto_intN_x = numbottomzeros_tricky crypto_intN_x; crypto_intN_x = fallback if =");
return crypto_intN_x;
#elif arm64
int64_t crypto_intN_y;
8: readasm("arm64; int8 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x | -256; crypto_intN_y = bitrev32 crypto_intN_y; crypto_intN_y = numbottomzeros crypto_intN_y");
16: readasm("arm64; int16 crypto_intN_x crypto_intN_y; crypto_intN_y = crypto_intN_x | -65536; crypto_intN_y = bitrev32 crypto_intN_y; crypto_intN_y = numbottomzeros crypto_intN_y");
32: readasm("arm64; int32 crypto_intN_x crypto_intN_y; crypto_intN_y = bitrev32 crypto_intN_x; crypto_intN_y = numbottomzeros crypto_intN_y");
64: readasm("arm64; int64 crypto_intN_x crypto_intN_y; crypto_intN_y = bitrev64 crypto_intN_x; crypto_intN_y = numbottomzeros crypto_intN_y");
return crypto_intN_y;
#else
crypto_intN crypto_intN_y = crypto_intN_x ^ (crypto_intN_x-1);
crypto_intN_y = ((crypto_intN) crypto_intN_y) >> 1;
crypto_intN_y &= ~(crypto_intN_x & (((crypto_intN) 1) << (N-1)));
return crypto_intN_ones_num(crypto_intN_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_uint16.h 0000664 0000000 0000000 00000051133 14747360755 0020427 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_uint16_h
#define crypto_uint16_h
#include
#define crypto_uint16 uint16_t
#define crypto_uint16_signed int16_t
#define crypto_uint16_signed_optblocker tinyssh_uint16_signed_optblocker
extern volatile crypto_uint16_signed crypto_uint16_signed_optblocker;
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_load(const unsigned char *crypto_uint16_s) {
crypto_uint16 crypto_uint16_z = 0;
crypto_uint16_z |= ((crypto_uint16) (*crypto_uint16_s++)) << 0;
crypto_uint16_z |= ((crypto_uint16) (*crypto_uint16_s++)) << 8;
return crypto_uint16_z;
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_load_bigendian(const unsigned char *crypto_uint16_s) {
crypto_uint16 crypto_uint16_z = 0;
crypto_uint16_z |= ((crypto_uint16) (*crypto_uint16_s++)) << 8;
crypto_uint16_z |= ((crypto_uint16) (*crypto_uint16_s++)) << 0;
return crypto_uint16_z;
}
__attribute__((unused))
static inline
void crypto_uint16_store(unsigned char *crypto_uint16_s,crypto_uint16 crypto_uint16_x) {
*crypto_uint16_s++ = crypto_uint16_x >> 0;
*crypto_uint16_s++ = crypto_uint16_x >> 8;
}
__attribute__((unused))
static inline
void crypto_uint16_store_bigendian(unsigned char *crypto_uint16_s,crypto_uint16 crypto_uint16_x) {
*crypto_uint16_s++ = crypto_uint16_x >> 8;
*crypto_uint16_s++ = crypto_uint16_x >> 0;
}
__attribute__((unused))
static inline
crypto_uint16_signed crypto_uint16_signed_negative_mask(crypto_uint16_signed crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarw $15,%0" : "+r"(crypto_uint16_x) : : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16_signed crypto_uint16_y;
__asm__ ("sbfx %w0,%w1,15,1" : "=r"(crypto_uint16_y) : "r"(crypto_uint16_x) : );
return crypto_uint16_y;
#else
crypto_uint16_x >>= 16-6;
crypto_uint16_x += crypto_uint16_signed_optblocker;
crypto_uint16_x >>= 5;
return crypto_uint16_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_topbit_01(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrw $15,%0" : "+r"(crypto_uint16_x) : : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16_signed crypto_uint16_y;
__asm__ ("ubfx %w0,%w1,15,1" : "=r"(crypto_uint16_y) : "r"(crypto_uint16_x) : );
return crypto_uint16_y;
#else
crypto_uint16_x >>= 16-6;
crypto_uint16_x += crypto_uint16_signed_optblocker;
crypto_uint16_x >>= 5;
return crypto_uint16_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_topbit_mask(crypto_uint16 crypto_uint16_x) {
return crypto_uint16_signed_negative_mask(crypto_uint16_x);
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bottombit_mask(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andw $1,%0" : "+r"(crypto_uint16_x) : : "cc");
return -crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_uint16_y) : "r"(crypto_uint16_x) : );
return crypto_uint16_y;
#else
crypto_uint16_x &= 1 + crypto_uint16_signed_optblocker;
return -crypto_uint16_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bottombit_01(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andw $1,%0" : "+r"(crypto_uint16_x) : : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_uint16_y) : "r"(crypto_uint16_x) : );
return crypto_uint16_y;
#else
crypto_uint16_x &= 1 + crypto_uint16_signed_optblocker;
return crypto_uint16_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bitinrangepublicpos_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrw %%cl,%0" : "+r"(crypto_uint16_x) : "c"(crypto_uint16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,65535\n lsr %w0,%w0,%w1" : "+&r"(crypto_uint16_x) : "r"(crypto_uint16_s) : );
#else
crypto_uint16_x >>= crypto_uint16_s ^ crypto_uint16_signed_optblocker;
#endif
return crypto_uint16_bottombit_mask(crypto_uint16_x);
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bitinrangepublicpos_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrw %%cl,%0" : "+r"(crypto_uint16_x) : "c"(crypto_uint16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,65535\n lsr %w0,%w0,%w1" : "+&r"(crypto_uint16_x) : "r"(crypto_uint16_s) : );
#else
crypto_uint16_x >>= crypto_uint16_s ^ crypto_uint16_signed_optblocker;
#endif
return crypto_uint16_bottombit_01(crypto_uint16_x);
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_shlmod(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16_s &= 15;
__asm__ ("shlw %%cl,%0" : "+r"(crypto_uint16_x) : "c"(crypto_uint16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,15\n and %w1,%w1,65535\n lsl %w1,%w1,%w0" : "+&r"(crypto_uint16_s), "+r"(crypto_uint16_x) : : );
#else
int crypto_uint16_k, crypto_uint16_l;
for (crypto_uint16_l = 0,crypto_uint16_k = 1;crypto_uint16_k < 16;++crypto_uint16_l,crypto_uint16_k *= 2)
crypto_uint16_x ^= (crypto_uint16_x ^ (crypto_uint16_x << crypto_uint16_k)) & crypto_uint16_bitinrangepublicpos_mask(crypto_uint16_s,crypto_uint16_l);
#endif
return crypto_uint16_x;
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_shrmod(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16_s &= 15;
__asm__ ("shrw %%cl,%0" : "+r"(crypto_uint16_x) : "c"(crypto_uint16_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,15\n and %w1,%w1,65535\n lsr %w1,%w1,%w0" : "+&r"(crypto_uint16_s), "+r"(crypto_uint16_x) : : );
#else
int crypto_uint16_k, crypto_uint16_l;
for (crypto_uint16_l = 0,crypto_uint16_k = 1;crypto_uint16_k < 16;++crypto_uint16_l,crypto_uint16_k *= 2)
crypto_uint16_x ^= (crypto_uint16_x ^ (crypto_uint16_x >> crypto_uint16_k)) & crypto_uint16_bitinrangepublicpos_mask(crypto_uint16_s,crypto_uint16_l);
#endif
return crypto_uint16_x;
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bitmod_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
crypto_uint16_x = crypto_uint16_shrmod(crypto_uint16_x,crypto_uint16_s);
return crypto_uint16_bottombit_mask(crypto_uint16_x);
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_bitmod_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_s) {
crypto_uint16_x = crypto_uint16_shrmod(crypto_uint16_x,crypto_uint16_s);
return crypto_uint16_bottombit_01(crypto_uint16_x);
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_nonzero_mask(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n testw %2,%2\n cmovnew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("tst %w1,65535\n csetm %w0,ne" : "=r"(crypto_uint16_z) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#else
crypto_uint16_x |= -crypto_uint16_x;
return crypto_uint16_signed_negative_mask(crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_nonzero_01(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n testw %2,%2\n cmovnew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("tst %w1,65535\n cset %w0,ne" : "=r"(crypto_uint16_z) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#else
crypto_uint16_x |= -crypto_uint16_x;
return crypto_uint16_topbit_01(crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_zero_mask(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n testw %2,%2\n cmovew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("tst %w1,65535\n csetm %w0,eq" : "=r"(crypto_uint16_z) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#else
return ~crypto_uint16_nonzero_mask(crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_zero_01(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n testw %2,%2\n cmovew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("tst %w1,65535\n cset %w0,eq" : "=r"(crypto_uint16_z) : "r"(crypto_uint16_x) : "cc");
return crypto_uint16_z;
#else
return 1-crypto_uint16_nonzero_01(crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_unequal_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovnew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,ne" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return crypto_uint16_nonzero_mask(crypto_uint16_x ^ crypto_uint16_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_unequal_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovnew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,ne" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return crypto_uint16_nonzero_01(crypto_uint16_x ^ crypto_uint16_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_equal_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,eq" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return ~crypto_uint16_unequal_mask(crypto_uint16_x,crypto_uint16_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_equal_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,eq" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return 1-crypto_uint16_unequal_01(crypto_uint16_x,crypto_uint16_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_min(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpw %1,%0\n cmovaw %1,%0" : "+r"(crypto_uint16_x) : "r"(crypto_uint16_y) : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,65535\n cmp %w0,%w1,uxth\n csel %w0,%w0,%w1,lo" : "+&r"(crypto_uint16_x) : "r"(crypto_uint16_y) : "cc");
return crypto_uint16_x;
#else
crypto_uint16 crypto_uint16_r = crypto_uint16_y ^ crypto_uint16_x;
crypto_uint16 crypto_uint16_z = crypto_uint16_y - crypto_uint16_x;
crypto_uint16_z ^= crypto_uint16_r & (crypto_uint16_z ^ crypto_uint16_y ^ (((crypto_uint16) 1) << (16-1)));
crypto_uint16_z = crypto_uint16_signed_negative_mask(crypto_uint16_z);
crypto_uint16_z &= crypto_uint16_r;
return crypto_uint16_x ^ crypto_uint16_z;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_max(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpw %1,%0\n cmovbw %1,%0" : "+r"(crypto_uint16_x) : "r"(crypto_uint16_y) : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,65535\n cmp %w0,%w1,uxth\n csel %w0,%w1,%w0,lo" : "+&r"(crypto_uint16_x) : "r"(crypto_uint16_y) : "cc");
return crypto_uint16_x;
#else
crypto_uint16 crypto_uint16_r = crypto_uint16_y ^ crypto_uint16_x;
crypto_uint16 crypto_uint16_z = crypto_uint16_y - crypto_uint16_x;
crypto_uint16_z ^= crypto_uint16_r & (crypto_uint16_z ^ crypto_uint16_y ^ (((crypto_uint16) 1) << (16-1)));
crypto_uint16_z = crypto_uint16_signed_negative_mask(crypto_uint16_z);
crypto_uint16_z &= crypto_uint16_r;
return crypto_uint16_y ^ crypto_uint16_z;
#endif
}
__attribute__((unused))
static inline
void crypto_uint16_minmax(crypto_uint16 *crypto_uint16_p,crypto_uint16 *crypto_uint16_q) {
crypto_uint16 crypto_uint16_x = *crypto_uint16_p;
crypto_uint16 crypto_uint16_y = *crypto_uint16_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("cmpw %2,%1\n movw %1,%0\n cmovaw %2,%1\n cmovaw %0,%2" : "=&r"(crypto_uint16_z), "+&r"(crypto_uint16_x), "+r"(crypto_uint16_y) : : "cc");
*crypto_uint16_p = crypto_uint16_x;
*crypto_uint16_q = crypto_uint16_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_r, crypto_uint16_s;
__asm__ ("and %w0,%w0,65535\n cmp %w0,%w3,uxth\n csel %w1,%w0,%w3,lo\n csel %w2,%w3,%w0,lo" : "+&r"(crypto_uint16_x), "=&r"(crypto_uint16_r), "=r"(crypto_uint16_s) : "r"(crypto_uint16_y) : "cc");
*crypto_uint16_p = crypto_uint16_r;
*crypto_uint16_q = crypto_uint16_s;
#else
crypto_uint16 crypto_uint16_r = crypto_uint16_y ^ crypto_uint16_x;
crypto_uint16 crypto_uint16_z = crypto_uint16_y - crypto_uint16_x;
crypto_uint16_z ^= crypto_uint16_r & (crypto_uint16_z ^ crypto_uint16_y ^ (((crypto_uint16) 1) << (16-1)));
crypto_uint16_z = crypto_uint16_signed_negative_mask(crypto_uint16_z);
crypto_uint16_z &= crypto_uint16_r;
crypto_uint16_x ^= crypto_uint16_z;
crypto_uint16_y ^= crypto_uint16_z;
*crypto_uint16_p = crypto_uint16_x;
*crypto_uint16_q = crypto_uint16_y;
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_smaller_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovbw %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,lo" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
crypto_uint16 crypto_uint16_r = crypto_uint16_x ^ crypto_uint16_y;
crypto_uint16 crypto_uint16_z = crypto_uint16_x - crypto_uint16_y;
crypto_uint16_z ^= crypto_uint16_r & (crypto_uint16_z ^ crypto_uint16_x ^ (((crypto_uint16) 1) << (16-1)));
return crypto_uint16_signed_negative_mask(crypto_uint16_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_smaller_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovbw %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,lo" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
crypto_uint16 crypto_uint16_r = crypto_uint16_x ^ crypto_uint16_y;
crypto_uint16 crypto_uint16_z = crypto_uint16_x - crypto_uint16_y;
crypto_uint16_z ^= crypto_uint16_r & (crypto_uint16_z ^ crypto_uint16_x ^ (((crypto_uint16) 1) << (16-1)));
return crypto_uint16_topbit_01(crypto_uint16_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_leq_mask(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $-1,%1\n cmpw %3,%2\n cmovbew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n csetm %w0,ls" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return ~crypto_uint16_smaller_mask(crypto_uint16_y,crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint16 crypto_uint16_leq_01(crypto_uint16 crypto_uint16_x,crypto_uint16 crypto_uint16_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 crypto_uint16_q,crypto_uint16_z;
__asm__ ("xorw %0,%0\n movw $1,%1\n cmpw %3,%2\n cmovbew %1,%0" : "=&r"(crypto_uint16_z), "=&r"(crypto_uint16_q) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint16 crypto_uint16_z;
__asm__ ("and %w0,%w1,65535\n cmp %w0,%w2,uxth\n cset %w0,ls" : "=&r"(crypto_uint16_z) : "r"(crypto_uint16_x), "r"(crypto_uint16_y) : "cc");
return crypto_uint16_z;
#else
return 1-crypto_uint16_smaller_01(crypto_uint16_y,crypto_uint16_x);
#endif
}
__attribute__((unused))
static inline
int crypto_uint16_ones_num(crypto_uint16 crypto_uint16_x) {
crypto_uint16 crypto_uint16_y = crypto_uint16_x;
const crypto_uint16 C0 = 0x5555;
const crypto_uint16 C1 = 0x3333;
const crypto_uint16 C2 = 0x0f0f;
crypto_uint16_y -= ((crypto_uint16_y >> 1) & C0);
crypto_uint16_y = (crypto_uint16_y & C1) + ((crypto_uint16_y >> 2) & C1);
crypto_uint16_y = (crypto_uint16_y + (crypto_uint16_y >> 4)) & C2;
crypto_uint16_y = (crypto_uint16_y + (crypto_uint16_y >> 8)) & 0xff;
return crypto_uint16_y;
}
__attribute__((unused))
static inline
int crypto_uint16_bottomzeros_num(crypto_uint16 crypto_uint16_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint16 fallback = 16;
__asm__ ("bsfw %0,%0\n cmovew %1,%0" : "+&r"(crypto_uint16_x) : "r"(fallback) : "cc");
return crypto_uint16_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_uint16_y;
__asm__ ("orr %w0,%w1,-65536\n rbit %w0,%w0\n clz %w0,%w0" : "=r"(crypto_uint16_y) : "r"(crypto_uint16_x) : );
return crypto_uint16_y;
#else
crypto_uint16 crypto_uint16_y = crypto_uint16_x ^ (crypto_uint16_x-1);
crypto_uint16_y = ((crypto_uint16_signed) crypto_uint16_y) >> 1;
crypto_uint16_y &= ~(crypto_uint16_x & (((crypto_uint16) 1) << (16-1)));
return crypto_uint16_ones_num(crypto_uint16_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_uint32.h 0000664 0000000 0000000 00000051141 14747360755 0020424 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_uint32_h
#define crypto_uint32_h
#include
#define crypto_uint32 uint32_t
#define crypto_uint32_signed int32_t
#define crypto_uint32_signed_optblocker tinyssh_uint32_signed_optblocker
extern volatile crypto_uint32_signed crypto_uint32_signed_optblocker;
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_load(const unsigned char *crypto_uint32_s) {
crypto_uint32 crypto_uint32_z = 0;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 0;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 8;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 16;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 24;
return crypto_uint32_z;
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_load_bigendian(const unsigned char *crypto_uint32_s) {
crypto_uint32 crypto_uint32_z = 0;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 24;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 16;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 8;
crypto_uint32_z |= ((crypto_uint32) (*crypto_uint32_s++)) << 0;
return crypto_uint32_z;
}
__attribute__((unused))
static inline
void crypto_uint32_store(unsigned char *crypto_uint32_s,crypto_uint32 crypto_uint32_x) {
*crypto_uint32_s++ = crypto_uint32_x >> 0;
*crypto_uint32_s++ = crypto_uint32_x >> 8;
*crypto_uint32_s++ = crypto_uint32_x >> 16;
*crypto_uint32_s++ = crypto_uint32_x >> 24;
}
__attribute__((unused))
static inline
void crypto_uint32_store_bigendian(unsigned char *crypto_uint32_s,crypto_uint32 crypto_uint32_x) {
*crypto_uint32_s++ = crypto_uint32_x >> 24;
*crypto_uint32_s++ = crypto_uint32_x >> 16;
*crypto_uint32_s++ = crypto_uint32_x >> 8;
*crypto_uint32_s++ = crypto_uint32_x >> 0;
}
__attribute__((unused))
static inline
crypto_uint32_signed crypto_uint32_signed_negative_mask(crypto_uint32_signed crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarl $31,%0" : "+r"(crypto_uint32_x) : : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32_signed crypto_uint32_y;
__asm__ ("asr %w0,%w1,31" : "=r"(crypto_uint32_y) : "r"(crypto_uint32_x) : );
return crypto_uint32_y;
#else
crypto_uint32_x >>= 32-6;
crypto_uint32_x += crypto_uint32_signed_optblocker;
crypto_uint32_x >>= 5;
return crypto_uint32_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_topbit_01(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrl $31,%0" : "+r"(crypto_uint32_x) : : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32_signed crypto_uint32_y;
__asm__ ("lsr %w0,%w1,31" : "=r"(crypto_uint32_y) : "r"(crypto_uint32_x) : );
return crypto_uint32_y;
#else
crypto_uint32_x >>= 32-6;
crypto_uint32_x += crypto_uint32_signed_optblocker;
crypto_uint32_x >>= 5;
return crypto_uint32_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_topbit_mask(crypto_uint32 crypto_uint32_x) {
return crypto_uint32_signed_negative_mask(crypto_uint32_x);
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bottombit_mask(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andl $1,%0" : "+r"(crypto_uint32_x) : : "cc");
return -crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_uint32_y) : "r"(crypto_uint32_x) : );
return crypto_uint32_y;
#else
crypto_uint32_x &= 1 + crypto_uint32_signed_optblocker;
return -crypto_uint32_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bottombit_01(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andl $1,%0" : "+r"(crypto_uint32_x) : : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_uint32_y) : "r"(crypto_uint32_x) : );
return crypto_uint32_y;
#else
crypto_uint32_x &= 1 + crypto_uint32_signed_optblocker;
return crypto_uint32_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bitinrangepublicpos_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrl %%cl,%0" : "+r"(crypto_uint32_x) : "c"(crypto_uint32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %w0,%w0,%w1" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_s) : );
#else
crypto_uint32_x >>= crypto_uint32_s ^ crypto_uint32_signed_optblocker;
#endif
return crypto_uint32_bottombit_mask(crypto_uint32_x);
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bitinrangepublicpos_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrl %%cl,%0" : "+r"(crypto_uint32_x) : "c"(crypto_uint32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %w0,%w0,%w1" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_s) : );
#else
crypto_uint32_x >>= crypto_uint32_s ^ crypto_uint32_signed_optblocker;
#endif
return crypto_uint32_bottombit_01(crypto_uint32_x);
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_shlmod(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shll %%cl,%0" : "+r"(crypto_uint32_x) : "c"(crypto_uint32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsl %w0,%w0,%w1" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_s) : );
#else
int crypto_uint32_k, crypto_uint32_l;
for (crypto_uint32_l = 0,crypto_uint32_k = 1;crypto_uint32_k < 32;++crypto_uint32_l,crypto_uint32_k *= 2)
crypto_uint32_x ^= (crypto_uint32_x ^ (crypto_uint32_x << crypto_uint32_k)) & crypto_uint32_bitinrangepublicpos_mask(crypto_uint32_s,crypto_uint32_l);
#endif
return crypto_uint32_x;
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_shrmod(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrl %%cl,%0" : "+r"(crypto_uint32_x) : "c"(crypto_uint32_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %w0,%w0,%w1" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_s) : );
#else
int crypto_uint32_k, crypto_uint32_l;
for (crypto_uint32_l = 0,crypto_uint32_k = 1;crypto_uint32_k < 32;++crypto_uint32_l,crypto_uint32_k *= 2)
crypto_uint32_x ^= (crypto_uint32_x ^ (crypto_uint32_x >> crypto_uint32_k)) & crypto_uint32_bitinrangepublicpos_mask(crypto_uint32_s,crypto_uint32_l);
#endif
return crypto_uint32_x;
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bitmod_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
crypto_uint32_x = crypto_uint32_shrmod(crypto_uint32_x,crypto_uint32_s);
return crypto_uint32_bottombit_mask(crypto_uint32_x);
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_bitmod_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_s) {
crypto_uint32_x = crypto_uint32_shrmod(crypto_uint32_x,crypto_uint32_s);
return crypto_uint32_bottombit_01(crypto_uint32_x);
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_nonzero_mask(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testl %2,%2\n cmovnel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,0\n csetm %w0,ne" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#else
crypto_uint32_x |= -crypto_uint32_x;
return crypto_uint32_signed_negative_mask(crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_nonzero_01(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n testl %2,%2\n cmovnel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,0\n cset %w0,ne" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#else
crypto_uint32_x |= -crypto_uint32_x;
return crypto_uint32_topbit_01(crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_zero_mask(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testl %2,%2\n cmovel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,0\n csetm %w0,eq" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#else
return ~crypto_uint32_nonzero_mask(crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_zero_01(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n testl %2,%2\n cmovel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,0\n cset %w0,eq" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x) : "cc");
return crypto_uint32_z;
#else
return 1-crypto_uint32_nonzero_01(crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_unequal_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovnel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,ne" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return crypto_uint32_nonzero_mask(crypto_uint32_x ^ crypto_uint32_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_unequal_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovnel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,ne" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return crypto_uint32_nonzero_01(crypto_uint32_x ^ crypto_uint32_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_equal_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,eq" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return ~crypto_uint32_unequal_mask(crypto_uint32_x,crypto_uint32_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_equal_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,eq" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return 1-crypto_uint32_unequal_01(crypto_uint32_x,crypto_uint32_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_min(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpl %1,%0\n cmoval %1,%0" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_y) : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %w0,%w1\n csel %w0,%w0,%w1,lo" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_y) : "cc");
return crypto_uint32_x;
#else
crypto_uint32 crypto_uint32_r = crypto_uint32_y ^ crypto_uint32_x;
crypto_uint32 crypto_uint32_z = crypto_uint32_y - crypto_uint32_x;
crypto_uint32_z ^= crypto_uint32_r & (crypto_uint32_z ^ crypto_uint32_y ^ (((crypto_uint32) 1) << (32-1)));
crypto_uint32_z = crypto_uint32_signed_negative_mask(crypto_uint32_z);
crypto_uint32_z &= crypto_uint32_r;
return crypto_uint32_x ^ crypto_uint32_z;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_max(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpl %1,%0\n cmovbl %1,%0" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_y) : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %w0,%w1\n csel %w0,%w1,%w0,lo" : "+r"(crypto_uint32_x) : "r"(crypto_uint32_y) : "cc");
return crypto_uint32_x;
#else
crypto_uint32 crypto_uint32_r = crypto_uint32_y ^ crypto_uint32_x;
crypto_uint32 crypto_uint32_z = crypto_uint32_y - crypto_uint32_x;
crypto_uint32_z ^= crypto_uint32_r & (crypto_uint32_z ^ crypto_uint32_y ^ (((crypto_uint32) 1) << (32-1)));
crypto_uint32_z = crypto_uint32_signed_negative_mask(crypto_uint32_z);
crypto_uint32_z &= crypto_uint32_r;
return crypto_uint32_y ^ crypto_uint32_z;
#endif
}
__attribute__((unused))
static inline
void crypto_uint32_minmax(crypto_uint32 *crypto_uint32_p,crypto_uint32 *crypto_uint32_q) {
crypto_uint32 crypto_uint32_x = *crypto_uint32_p;
crypto_uint32 crypto_uint32_y = *crypto_uint32_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmpl %2,%1\n movl %1,%0\n cmoval %2,%1\n cmoval %0,%2" : "=&r"(crypto_uint32_z), "+&r"(crypto_uint32_x), "+r"(crypto_uint32_y) : : "cc");
*crypto_uint32_p = crypto_uint32_x;
*crypto_uint32_q = crypto_uint32_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_r, crypto_uint32_s;
__asm__ ("cmp %w2,%w3\n csel %w0,%w2,%w3,lo\n csel %w1,%w3,%w2,lo" : "=&r"(crypto_uint32_r), "=r"(crypto_uint32_s) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
*crypto_uint32_p = crypto_uint32_r;
*crypto_uint32_q = crypto_uint32_s;
#else
crypto_uint32 crypto_uint32_r = crypto_uint32_y ^ crypto_uint32_x;
crypto_uint32 crypto_uint32_z = crypto_uint32_y - crypto_uint32_x;
crypto_uint32_z ^= crypto_uint32_r & (crypto_uint32_z ^ crypto_uint32_y ^ (((crypto_uint32) 1) << (32-1)));
crypto_uint32_z = crypto_uint32_signed_negative_mask(crypto_uint32_z);
crypto_uint32_z &= crypto_uint32_r;
crypto_uint32_x ^= crypto_uint32_z;
crypto_uint32_y ^= crypto_uint32_z;
*crypto_uint32_p = crypto_uint32_x;
*crypto_uint32_q = crypto_uint32_y;
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_smaller_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovbl %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,lo" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
crypto_uint32 crypto_uint32_r = crypto_uint32_x ^ crypto_uint32_y;
crypto_uint32 crypto_uint32_z = crypto_uint32_x - crypto_uint32_y;
crypto_uint32_z ^= crypto_uint32_r & (crypto_uint32_z ^ crypto_uint32_x ^ (((crypto_uint32) 1) << (32-1)));
return crypto_uint32_signed_negative_mask(crypto_uint32_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_smaller_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovbl %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,lo" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
crypto_uint32 crypto_uint32_r = crypto_uint32_x ^ crypto_uint32_y;
crypto_uint32 crypto_uint32_z = crypto_uint32_x - crypto_uint32_y;
crypto_uint32_z ^= crypto_uint32_r & (crypto_uint32_z ^ crypto_uint32_x ^ (((crypto_uint32) 1) << (32-1)));
return crypto_uint32_topbit_01(crypto_uint32_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_leq_mask(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpl %3,%2\n cmovbel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n csetm %w0,ls" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return ~crypto_uint32_smaller_mask(crypto_uint32_y,crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint32 crypto_uint32_leq_01(crypto_uint32 crypto_uint32_x,crypto_uint32 crypto_uint32_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 crypto_uint32_q,crypto_uint32_z;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpl %3,%2\n cmovbel %1,%0" : "=&r"(crypto_uint32_z), "=&r"(crypto_uint32_q) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint32 crypto_uint32_z;
__asm__ ("cmp %w1,%w2\n cset %w0,ls" : "=r"(crypto_uint32_z) : "r"(crypto_uint32_x), "r"(crypto_uint32_y) : "cc");
return crypto_uint32_z;
#else
return 1-crypto_uint32_smaller_01(crypto_uint32_y,crypto_uint32_x);
#endif
}
__attribute__((unused))
static inline
int crypto_uint32_ones_num(crypto_uint32 crypto_uint32_x) {
crypto_uint32 crypto_uint32_y = crypto_uint32_x;
const crypto_uint32 C0 = 0x55555555;
const crypto_uint32 C1 = 0x33333333;
const crypto_uint32 C2 = 0x0f0f0f0f;
crypto_uint32_y -= ((crypto_uint32_y >> 1) & C0);
crypto_uint32_y = (crypto_uint32_y & C1) + ((crypto_uint32_y >> 2) & C1);
crypto_uint32_y = (crypto_uint32_y + (crypto_uint32_y >> 4)) & C2;
crypto_uint32_y += crypto_uint32_y >> 8;
crypto_uint32_y = (crypto_uint32_y + (crypto_uint32_y >> 16)) & 0xff;
return crypto_uint32_y;
}
__attribute__((unused))
static inline
int crypto_uint32_bottomzeros_num(crypto_uint32 crypto_uint32_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint32 fallback = 32;
__asm__ ("bsfl %0,%0\n cmovel %1,%0" : "+&r"(crypto_uint32_x) : "r"(fallback) : "cc");
return crypto_uint32_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_uint32_y;
__asm__ ("rbit %w0,%w1\n clz %w0,%w0" : "=r"(crypto_uint32_y) : "r"(crypto_uint32_x) : );
return crypto_uint32_y;
#else
crypto_uint32 crypto_uint32_y = crypto_uint32_x ^ (crypto_uint32_x-1);
crypto_uint32_y = ((crypto_uint32_signed) crypto_uint32_y) >> 1;
crypto_uint32_y &= ~(crypto_uint32_x & (((crypto_uint32) 1) << (32-1)));
return crypto_uint32_ones_num(crypto_uint32_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_uint64.h 0000664 0000000 0000000 00000052743 14747360755 0020442 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_uint64_h
#define crypto_uint64_h
#include
#define crypto_uint64 uint64_t
#define crypto_uint64_signed int64_t
#define crypto_uint64_signed_optblocker tinyssh_uint64_signed_optblocker
extern volatile crypto_uint64_signed crypto_uint64_signed_optblocker;
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_load(const unsigned char *crypto_uint64_s) {
crypto_uint64 crypto_uint64_z = 0;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 0;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 8;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 16;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 24;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 32;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 40;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 48;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 56;
return crypto_uint64_z;
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_load_bigendian(const unsigned char *crypto_uint64_s) {
crypto_uint64 crypto_uint64_z = 0;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 56;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 48;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 40;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 32;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 24;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 16;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 8;
crypto_uint64_z |= ((crypto_uint64) (*crypto_uint64_s++)) << 0;
return crypto_uint64_z;
}
__attribute__((unused))
static inline
void crypto_uint64_store(unsigned char *crypto_uint64_s,crypto_uint64 crypto_uint64_x) {
*crypto_uint64_s++ = crypto_uint64_x >> 0;
*crypto_uint64_s++ = crypto_uint64_x >> 8;
*crypto_uint64_s++ = crypto_uint64_x >> 16;
*crypto_uint64_s++ = crypto_uint64_x >> 24;
*crypto_uint64_s++ = crypto_uint64_x >> 32;
*crypto_uint64_s++ = crypto_uint64_x >> 40;
*crypto_uint64_s++ = crypto_uint64_x >> 48;
*crypto_uint64_s++ = crypto_uint64_x >> 56;
}
__attribute__((unused))
static inline
void crypto_uint64_store_bigendian(unsigned char *crypto_uint64_s,crypto_uint64 crypto_uint64_x) {
*crypto_uint64_s++ = crypto_uint64_x >> 56;
*crypto_uint64_s++ = crypto_uint64_x >> 48;
*crypto_uint64_s++ = crypto_uint64_x >> 40;
*crypto_uint64_s++ = crypto_uint64_x >> 32;
*crypto_uint64_s++ = crypto_uint64_x >> 24;
*crypto_uint64_s++ = crypto_uint64_x >> 16;
*crypto_uint64_s++ = crypto_uint64_x >> 8;
*crypto_uint64_s++ = crypto_uint64_x >> 0;
}
__attribute__((unused))
static inline
crypto_uint64_signed crypto_uint64_signed_negative_mask(crypto_uint64_signed crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarq $63,%0" : "+r"(crypto_uint64_x) : : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64_signed crypto_uint64_y;
__asm__ ("asr %0,%1,63" : "=r"(crypto_uint64_y) : "r"(crypto_uint64_x) : );
return crypto_uint64_y;
#else
crypto_uint64_x >>= 64-6;
crypto_uint64_x += crypto_uint64_signed_optblocker;
crypto_uint64_x >>= 5;
return crypto_uint64_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_topbit_01(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrq $63,%0" : "+r"(crypto_uint64_x) : : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64_signed crypto_uint64_y;
__asm__ ("lsr %0,%1,63" : "=r"(crypto_uint64_y) : "r"(crypto_uint64_x) : );
return crypto_uint64_y;
#else
crypto_uint64_x >>= 64-6;
crypto_uint64_x += crypto_uint64_signed_optblocker;
crypto_uint64_x >>= 5;
return crypto_uint64_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_topbit_mask(crypto_uint64 crypto_uint64_x) {
return crypto_uint64_signed_negative_mask(crypto_uint64_x);
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bottombit_mask(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andq $1,%0" : "+r"(crypto_uint64_x) : : "cc");
return -crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_y;
__asm__ ("sbfx %0,%1,0,1" : "=r"(crypto_uint64_y) : "r"(crypto_uint64_x) : );
return crypto_uint64_y;
#else
crypto_uint64_x &= 1 + crypto_uint64_signed_optblocker;
return -crypto_uint64_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bottombit_01(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andq $1,%0" : "+r"(crypto_uint64_x) : : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_y;
__asm__ ("ubfx %0,%1,0,1" : "=r"(crypto_uint64_y) : "r"(crypto_uint64_x) : );
return crypto_uint64_y;
#else
crypto_uint64_x &= 1 + crypto_uint64_signed_optblocker;
return crypto_uint64_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bitinrangepublicpos_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrq %%cl,%0" : "+r"(crypto_uint64_x) : "c"(crypto_uint64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %0,%0,%1" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_s) : );
#else
crypto_uint64_x >>= crypto_uint64_s ^ crypto_uint64_signed_optblocker;
#endif
return crypto_uint64_bottombit_mask(crypto_uint64_x);
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bitinrangepublicpos_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrq %%cl,%0" : "+r"(crypto_uint64_x) : "c"(crypto_uint64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %0,%0,%1" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_s) : );
#else
crypto_uint64_x >>= crypto_uint64_s ^ crypto_uint64_signed_optblocker;
#endif
return crypto_uint64_bottombit_01(crypto_uint64_x);
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_shlmod(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shlq %%cl,%0" : "+r"(crypto_uint64_x) : "c"(crypto_uint64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsl %0,%0,%1" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_s) : );
#else
int crypto_uint64_k, crypto_uint64_l;
for (crypto_uint64_l = 0,crypto_uint64_k = 1;crypto_uint64_k < 64;++crypto_uint64_l,crypto_uint64_k *= 2)
crypto_uint64_x ^= (crypto_uint64_x ^ (crypto_uint64_x << crypto_uint64_k)) & crypto_uint64_bitinrangepublicpos_mask(crypto_uint64_s,crypto_uint64_l);
#endif
return crypto_uint64_x;
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_shrmod(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrq %%cl,%0" : "+r"(crypto_uint64_x) : "c"(crypto_uint64_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("lsr %0,%0,%1" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_s) : );
#else
int crypto_uint64_k, crypto_uint64_l;
for (crypto_uint64_l = 0,crypto_uint64_k = 1;crypto_uint64_k < 64;++crypto_uint64_l,crypto_uint64_k *= 2)
crypto_uint64_x ^= (crypto_uint64_x ^ (crypto_uint64_x >> crypto_uint64_k)) & crypto_uint64_bitinrangepublicpos_mask(crypto_uint64_s,crypto_uint64_l);
#endif
return crypto_uint64_x;
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bitmod_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
crypto_uint64_x = crypto_uint64_shrmod(crypto_uint64_x,crypto_uint64_s);
return crypto_uint64_bottombit_mask(crypto_uint64_x);
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_bitmod_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_s) {
crypto_uint64_x = crypto_uint64_shrmod(crypto_uint64_x,crypto_uint64_s);
return crypto_uint64_bottombit_01(crypto_uint64_x);
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_nonzero_mask(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n testq %2,%2\n cmovneq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,0\n csetm %0,ne" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#else
crypto_uint64_x |= -crypto_uint64_x;
return crypto_uint64_signed_negative_mask(crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_nonzero_01(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n testq %2,%2\n cmovneq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,0\n cset %0,ne" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#else
crypto_uint64_x |= -crypto_uint64_x;
return crypto_uint64_topbit_01(crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_zero_mask(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n testq %2,%2\n cmoveq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,0\n csetm %0,eq" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#else
return ~crypto_uint64_nonzero_mask(crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_zero_01(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n testq %2,%2\n cmoveq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,0\n cset %0,eq" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x) : "cc");
return crypto_uint64_z;
#else
return 1-crypto_uint64_nonzero_01(crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_unequal_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovneq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n csetm %0,ne" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return crypto_uint64_nonzero_mask(crypto_uint64_x ^ crypto_uint64_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_unequal_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovneq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n cset %0,ne" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return crypto_uint64_nonzero_01(crypto_uint64_x ^ crypto_uint64_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_equal_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmoveq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n csetm %0,eq" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return ~crypto_uint64_unequal_mask(crypto_uint64_x,crypto_uint64_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_equal_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmoveq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n cset %0,eq" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return 1-crypto_uint64_unequal_01(crypto_uint64_x,crypto_uint64_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_min(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpq %1,%0\n cmovaq %1,%0" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_y) : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %0,%1\n csel %0,%0,%1,lo" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_y) : "cc");
return crypto_uint64_x;
#else
crypto_uint64 crypto_uint64_r = crypto_uint64_y ^ crypto_uint64_x;
crypto_uint64 crypto_uint64_z = crypto_uint64_y - crypto_uint64_x;
crypto_uint64_z ^= crypto_uint64_r & (crypto_uint64_z ^ crypto_uint64_y ^ (((crypto_uint64) 1) << (64-1)));
crypto_uint64_z = crypto_uint64_signed_negative_mask(crypto_uint64_z);
crypto_uint64_z &= crypto_uint64_r;
return crypto_uint64_x ^ crypto_uint64_z;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_max(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("cmpq %1,%0\n cmovbq %1,%0" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_y) : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("cmp %0,%1\n csel %0,%1,%0,lo" : "+r"(crypto_uint64_x) : "r"(crypto_uint64_y) : "cc");
return crypto_uint64_x;
#else
crypto_uint64 crypto_uint64_r = crypto_uint64_y ^ crypto_uint64_x;
crypto_uint64 crypto_uint64_z = crypto_uint64_y - crypto_uint64_x;
crypto_uint64_z ^= crypto_uint64_r & (crypto_uint64_z ^ crypto_uint64_y ^ (((crypto_uint64) 1) << (64-1)));
crypto_uint64_z = crypto_uint64_signed_negative_mask(crypto_uint64_z);
crypto_uint64_z &= crypto_uint64_r;
return crypto_uint64_y ^ crypto_uint64_z;
#endif
}
__attribute__((unused))
static inline
void crypto_uint64_minmax(crypto_uint64 *crypto_uint64_p,crypto_uint64 *crypto_uint64_q) {
crypto_uint64 crypto_uint64_x = *crypto_uint64_p;
crypto_uint64 crypto_uint64_y = *crypto_uint64_q;
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmpq %2,%1\n movq %1,%0\n cmovaq %2,%1\n cmovaq %0,%2" : "=&r"(crypto_uint64_z), "+&r"(crypto_uint64_x), "+r"(crypto_uint64_y) : : "cc");
*crypto_uint64_p = crypto_uint64_x;
*crypto_uint64_q = crypto_uint64_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_r, crypto_uint64_s;
__asm__ ("cmp %2,%3\n csel %0,%2,%3,lo\n csel %1,%3,%2,lo" : "=&r"(crypto_uint64_r), "=r"(crypto_uint64_s) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
*crypto_uint64_p = crypto_uint64_r;
*crypto_uint64_q = crypto_uint64_s;
#else
crypto_uint64 crypto_uint64_r = crypto_uint64_y ^ crypto_uint64_x;
crypto_uint64 crypto_uint64_z = crypto_uint64_y - crypto_uint64_x;
crypto_uint64_z ^= crypto_uint64_r & (crypto_uint64_z ^ crypto_uint64_y ^ (((crypto_uint64) 1) << (64-1)));
crypto_uint64_z = crypto_uint64_signed_negative_mask(crypto_uint64_z);
crypto_uint64_z &= crypto_uint64_r;
crypto_uint64_x ^= crypto_uint64_z;
crypto_uint64_y ^= crypto_uint64_z;
*crypto_uint64_p = crypto_uint64_x;
*crypto_uint64_q = crypto_uint64_y;
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_smaller_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovbq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n csetm %0,lo" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
crypto_uint64 crypto_uint64_r = crypto_uint64_x ^ crypto_uint64_y;
crypto_uint64 crypto_uint64_z = crypto_uint64_x - crypto_uint64_y;
crypto_uint64_z ^= crypto_uint64_r & (crypto_uint64_z ^ crypto_uint64_x ^ (((crypto_uint64) 1) << (64-1)));
return crypto_uint64_signed_negative_mask(crypto_uint64_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_smaller_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovbq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n cset %0,lo" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
crypto_uint64 crypto_uint64_r = crypto_uint64_x ^ crypto_uint64_y;
crypto_uint64 crypto_uint64_z = crypto_uint64_x - crypto_uint64_y;
crypto_uint64_z ^= crypto_uint64_r & (crypto_uint64_z ^ crypto_uint64_x ^ (((crypto_uint64) 1) << (64-1)));
return crypto_uint64_topbit_01(crypto_uint64_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_leq_mask(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $-1,%1\n cmpq %3,%2\n cmovbeq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n csetm %0,ls" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return ~crypto_uint64_smaller_mask(crypto_uint64_y,crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint64 crypto_uint64_leq_01(crypto_uint64 crypto_uint64_x,crypto_uint64 crypto_uint64_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 crypto_uint64_q,crypto_uint64_z;
__asm__ ("xorq %0,%0\n movq $1,%1\n cmpq %3,%2\n cmovbeq %1,%0" : "=&r"(crypto_uint64_z), "=&r"(crypto_uint64_q) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint64 crypto_uint64_z;
__asm__ ("cmp %1,%2\n cset %0,ls" : "=r"(crypto_uint64_z) : "r"(crypto_uint64_x), "r"(crypto_uint64_y) : "cc");
return crypto_uint64_z;
#else
return 1-crypto_uint64_smaller_01(crypto_uint64_y,crypto_uint64_x);
#endif
}
__attribute__((unused))
static inline
int crypto_uint64_ones_num(crypto_uint64 crypto_uint64_x) {
crypto_uint64 crypto_uint64_y = crypto_uint64_x;
const crypto_uint64 C0 = 0x5555555555555555;
const crypto_uint64 C1 = 0x3333333333333333;
const crypto_uint64 C2 = 0x0f0f0f0f0f0f0f0f;
crypto_uint64_y -= ((crypto_uint64_y >> 1) & C0);
crypto_uint64_y = (crypto_uint64_y & C1) + ((crypto_uint64_y >> 2) & C1);
crypto_uint64_y = (crypto_uint64_y + (crypto_uint64_y >> 4)) & C2;
crypto_uint64_y += crypto_uint64_y >> 8;
crypto_uint64_y += crypto_uint64_y >> 16;
crypto_uint64_y = (crypto_uint64_y + (crypto_uint64_y >> 32)) & 0xff;
return crypto_uint64_y;
}
__attribute__((unused))
static inline
int crypto_uint64_bottomzeros_num(crypto_uint64 crypto_uint64_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint64 fallback = 64;
__asm__ ("bsfq %0,%0\n cmoveq %1,%0" : "+&r"(crypto_uint64_x) : "r"(fallback) : "cc");
return crypto_uint64_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_uint64_y;
__asm__ ("rbit %0,%1\n clz %0,%0" : "=r"(crypto_uint64_y) : "r"(crypto_uint64_x) : );
return crypto_uint64_y;
#else
crypto_uint64 crypto_uint64_y = crypto_uint64_x ^ (crypto_uint64_x-1);
crypto_uint64_y = ((crypto_uint64_signed) crypto_uint64_y) >> 1;
crypto_uint64_y &= ~(crypto_uint64_x & (((crypto_uint64) 1) << (64-1)));
return crypto_uint64_ones_num(crypto_uint64_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_uint8.h 0000664 0000000 0000000 00000053167 14747360755 0020361 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_uint8_h
#define crypto_uint8_h
#include
#define crypto_uint8 uint8_t
#define crypto_uint8_signed int8_t
#define crypto_uint8_signed_optblocker tinyssh_uint8_signed_optblocker
extern volatile crypto_uint8_signed crypto_uint8_signed_optblocker;
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_load(const unsigned char *crypto_uint8_s) {
crypto_uint8 crypto_uint8_z = 0;
crypto_uint8_z |= ((crypto_uint8) (*crypto_uint8_s++)) << 0;
return crypto_uint8_z;
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_load_bigendian(const unsigned char *crypto_uint8_s) {
crypto_uint8 crypto_uint8_z = 0;
crypto_uint8_z |= ((crypto_uint8) (*crypto_uint8_s++)) << 0;
return crypto_uint8_z;
}
__attribute__((unused))
static inline
void crypto_uint8_store(unsigned char *crypto_uint8_s,crypto_uint8 crypto_uint8_x) {
*crypto_uint8_s++ = crypto_uint8_x >> 0;
}
__attribute__((unused))
static inline
void crypto_uint8_store_bigendian(unsigned char *crypto_uint8_s,crypto_uint8 crypto_uint8_x) {
*crypto_uint8_s++ = crypto_uint8_x >> 0;
}
__attribute__((unused))
static inline
crypto_uint8_signed crypto_uint8_signed_negative_mask(crypto_uint8_signed crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("sarb $7,%0" : "+r"(crypto_uint8_x) : : "cc");
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8_signed crypto_uint8_y;
__asm__ ("sbfx %w0,%w1,7,1" : "=r"(crypto_uint8_y) : "r"(crypto_uint8_x) : );
return crypto_uint8_y;
#else
crypto_uint8_x >>= 8-6;
crypto_uint8_x += crypto_uint8_signed_optblocker;
crypto_uint8_x >>= 5;
return crypto_uint8_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_topbit_01(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrb $7,%0" : "+r"(crypto_uint8_x) : : "cc");
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8_signed crypto_uint8_y;
__asm__ ("ubfx %w0,%w1,7,1" : "=r"(crypto_uint8_y) : "r"(crypto_uint8_x) : );
return crypto_uint8_y;
#else
crypto_uint8_x >>= 8-6;
crypto_uint8_x += crypto_uint8_signed_optblocker;
crypto_uint8_x >>= 5;
return crypto_uint8_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_topbit_mask(crypto_uint8 crypto_uint8_x) {
return crypto_uint8_signed_negative_mask(crypto_uint8_x);
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bottombit_mask(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andb $1,%0" : "+r"(crypto_uint8_x) : : "cc");
return -crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_y;
__asm__ ("sbfx %w0,%w1,0,1" : "=r"(crypto_uint8_y) : "r"(crypto_uint8_x) : );
return crypto_uint8_y;
#else
crypto_uint8_x &= 1 + crypto_uint8_signed_optblocker;
return -crypto_uint8_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bottombit_01(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("andb $1,%0" : "+r"(crypto_uint8_x) : : "cc");
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_y;
__asm__ ("ubfx %w0,%w1,0,1" : "=r"(crypto_uint8_y) : "r"(crypto_uint8_x) : );
return crypto_uint8_y;
#else
crypto_uint8_x &= 1 + crypto_uint8_signed_optblocker;
return crypto_uint8_x;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bitinrangepublicpos_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrb %%cl,%0" : "+r"(crypto_uint8_x) : "c"(crypto_uint8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,255\n lsr %w0,%w0,%w1" : "+&r"(crypto_uint8_x) : "r"(crypto_uint8_s) : );
#else
crypto_uint8_x >>= crypto_uint8_s ^ crypto_uint8_signed_optblocker;
#endif
return crypto_uint8_bottombit_mask(crypto_uint8_x);
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bitinrangepublicpos_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
__asm__ ("shrb %%cl,%0" : "+r"(crypto_uint8_x) : "c"(crypto_uint8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,255\n lsr %w0,%w0,%w1" : "+&r"(crypto_uint8_x) : "r"(crypto_uint8_s) : );
#else
crypto_uint8_x >>= crypto_uint8_s ^ crypto_uint8_signed_optblocker;
#endif
return crypto_uint8_bottombit_01(crypto_uint8_x);
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_shlmod(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8_s &= 7;
__asm__ ("shlb %%cl,%0" : "+r"(crypto_uint8_x) : "c"(crypto_uint8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,7\n and %w1,%w1,255\n lsl %w1,%w1,%w0" : "+&r"(crypto_uint8_s), "+r"(crypto_uint8_x) : : );
#else
int crypto_uint8_k, crypto_uint8_l;
for (crypto_uint8_l = 0,crypto_uint8_k = 1;crypto_uint8_k < 8;++crypto_uint8_l,crypto_uint8_k *= 2)
crypto_uint8_x ^= (crypto_uint8_x ^ (crypto_uint8_x << crypto_uint8_k)) & crypto_uint8_bitinrangepublicpos_mask(crypto_uint8_s,crypto_uint8_l);
#endif
return crypto_uint8_x;
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_shrmod(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8_s &= 7;
__asm__ ("shrb %%cl,%0" : "+r"(crypto_uint8_x) : "c"(crypto_uint8_s) : "cc");
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,7\n and %w1,%w1,255\n lsr %w1,%w1,%w0" : "+&r"(crypto_uint8_s), "+r"(crypto_uint8_x) : : );
#else
int crypto_uint8_k, crypto_uint8_l;
for (crypto_uint8_l = 0,crypto_uint8_k = 1;crypto_uint8_k < 8;++crypto_uint8_l,crypto_uint8_k *= 2)
crypto_uint8_x ^= (crypto_uint8_x ^ (crypto_uint8_x >> crypto_uint8_k)) & crypto_uint8_bitinrangepublicpos_mask(crypto_uint8_s,crypto_uint8_l);
#endif
return crypto_uint8_x;
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bitmod_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
crypto_uint8_x = crypto_uint8_shrmod(crypto_uint8_x,crypto_uint8_s);
return crypto_uint8_bottombit_mask(crypto_uint8_x);
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_bitmod_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_s) {
crypto_uint8_x = crypto_uint8_shrmod(crypto_uint8_x,crypto_uint8_s);
return crypto_uint8_bottombit_01(crypto_uint8_x);
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_nonzero_mask(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testb %b2,%b2\n cmovnel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("tst %w1,255\n csetm %w0,ne" : "=r"(crypto_uint8_z) : "r"(crypto_uint8_x) : "cc");
return crypto_uint8_z;
#else
crypto_uint8_x |= -crypto_uint8_x;
return crypto_uint8_signed_negative_mask(crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_nonzero_01(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n testb %b2,%b2\n cmovnel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("tst %w1,255\n cset %w0,ne" : "=r"(crypto_uint8_z) : "r"(crypto_uint8_x) : "cc");
return crypto_uint8_z;
#else
crypto_uint8_x |= -crypto_uint8_x;
return crypto_uint8_topbit_01(crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_zero_mask(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n testb %b2,%b2\n cmovel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("tst %w1,255\n csetm %w0,eq" : "=r"(crypto_uint8_z) : "r"(crypto_uint8_x) : "cc");
return crypto_uint8_z;
#else
return ~crypto_uint8_nonzero_mask(crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_zero_01(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n testb %b2,%b2\n cmovel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("tst %w1,255\n cset %w0,eq" : "=r"(crypto_uint8_z) : "r"(crypto_uint8_x) : "cc");
return crypto_uint8_z;
#else
return 1-crypto_uint8_nonzero_01(crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_unequal_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovnel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,ne" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return crypto_uint8_nonzero_mask(crypto_uint8_x ^ crypto_uint8_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_unequal_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovnel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,ne" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return crypto_uint8_nonzero_01(crypto_uint8_x ^ crypto_uint8_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_equal_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,eq" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return ~crypto_uint8_unequal_mask(crypto_uint8_x,crypto_uint8_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_equal_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,eq" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return 1-crypto_uint8_unequal_01(crypto_uint8_x,crypto_uint8_y);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_min(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
uint32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y;
__asm__ ("cmpb %b1,%b0\n cmoval %1,%0" : "+q"(crypto_uint8_x32) : "q"(crypto_uint8_y32) : "cc");
crypto_uint8_x = crypto_uint8_x32;
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,255\n cmp %w0,%w1,uxtb\n csel %w0,%w0,%w1,lo" : "+&r"(crypto_uint8_x) : "r"(crypto_uint8_y) : "cc");
return crypto_uint8_x;
#else
crypto_uint8 crypto_uint8_r = crypto_uint8_y ^ crypto_uint8_x;
crypto_uint8 crypto_uint8_z = crypto_uint8_y - crypto_uint8_x;
crypto_uint8_z ^= crypto_uint8_r & (crypto_uint8_z ^ crypto_uint8_y ^ (((crypto_uint8) 1) << (8-1)));
crypto_uint8_z = crypto_uint8_signed_negative_mask(crypto_uint8_z);
crypto_uint8_z &= crypto_uint8_r;
return crypto_uint8_x ^ crypto_uint8_z;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_max(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
uint32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y;
__asm__ ("cmpb %b1,%b0\n cmovbl %1,%0" : "+q"(crypto_uint8_x32) : "q"(crypto_uint8_y32) : "cc");
crypto_uint8_x = crypto_uint8_x32;
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
__asm__ ("and %w0,%w0,255\n cmp %w0,%w1,uxtb\n csel %w0,%w1,%w0,lo" : "+&r"(crypto_uint8_x) : "r"(crypto_uint8_y) : "cc");
return crypto_uint8_x;
#else
crypto_uint8 crypto_uint8_r = crypto_uint8_y ^ crypto_uint8_x;
crypto_uint8 crypto_uint8_z = crypto_uint8_y - crypto_uint8_x;
crypto_uint8_z ^= crypto_uint8_r & (crypto_uint8_z ^ crypto_uint8_y ^ (((crypto_uint8) 1) << (8-1)));
crypto_uint8_z = crypto_uint8_signed_negative_mask(crypto_uint8_z);
crypto_uint8_z &= crypto_uint8_r;
return crypto_uint8_y ^ crypto_uint8_z;
#endif
}
__attribute__((unused))
static inline
void crypto_uint8_minmax(crypto_uint8 *crypto_uint8_p,crypto_uint8 *crypto_uint8_q) {
crypto_uint8 crypto_uint8_x = *crypto_uint8_p;
crypto_uint8 crypto_uint8_y = *crypto_uint8_q;
#if defined(__GNUC__) && defined(__x86_64__)
uint32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_z32;
__asm__ ("cmpb %b2,%b1\n movl %1,%0\n cmoval %2,%1\n cmoval %0,%2" : "=&r"(crypto_uint8_z32), "+&q"(crypto_uint8_x32), "+q"(crypto_uint8_y32) : : "cc");
crypto_uint8_x = crypto_uint8_x32; crypto_uint8_y = crypto_uint8_y32;
*crypto_uint8_p = crypto_uint8_x;
*crypto_uint8_q = crypto_uint8_y;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_r, crypto_uint8_s;
__asm__ ("and %w0,%w0,255\n cmp %w0,%w3,uxtb\n csel %w1,%w0,%w3,lo\n csel %w2,%w3,%w0,lo" : "+&r"(crypto_uint8_x), "=&r"(crypto_uint8_r), "=r"(crypto_uint8_s) : "r"(crypto_uint8_y) : "cc");
*crypto_uint8_p = crypto_uint8_r;
*crypto_uint8_q = crypto_uint8_s;
#else
crypto_uint8 crypto_uint8_r = crypto_uint8_y ^ crypto_uint8_x;
crypto_uint8 crypto_uint8_z = crypto_uint8_y - crypto_uint8_x;
crypto_uint8_z ^= crypto_uint8_r & (crypto_uint8_z ^ crypto_uint8_y ^ (((crypto_uint8) 1) << (8-1)));
crypto_uint8_z = crypto_uint8_signed_negative_mask(crypto_uint8_z);
crypto_uint8_z &= crypto_uint8_r;
crypto_uint8_x ^= crypto_uint8_z;
crypto_uint8_y ^= crypto_uint8_z;
*crypto_uint8_p = crypto_uint8_x;
*crypto_uint8_q = crypto_uint8_y;
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_smaller_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovbl %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,lo" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
crypto_uint8 crypto_uint8_r = crypto_uint8_x ^ crypto_uint8_y;
crypto_uint8 crypto_uint8_z = crypto_uint8_x - crypto_uint8_y;
crypto_uint8_z ^= crypto_uint8_r & (crypto_uint8_z ^ crypto_uint8_x ^ (((crypto_uint8) 1) << (8-1)));
return crypto_uint8_signed_negative_mask(crypto_uint8_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_smaller_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovbl %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,lo" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
crypto_uint8 crypto_uint8_r = crypto_uint8_x ^ crypto_uint8_y;
crypto_uint8 crypto_uint8_z = crypto_uint8_x - crypto_uint8_y;
crypto_uint8_z ^= crypto_uint8_r & (crypto_uint8_z ^ crypto_uint8_x ^ (((crypto_uint8) 1) << (8-1)));
return crypto_uint8_topbit_01(crypto_uint8_z);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_leq_mask(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $-1,%1\n cmpb %b3,%b2\n cmovbel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n csetm %w0,ls" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return ~crypto_uint8_smaller_mask(crypto_uint8_y,crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
crypto_uint8 crypto_uint8_leq_01(crypto_uint8 crypto_uint8_x,crypto_uint8 crypto_uint8_y) {
#if defined(__GNUC__) && defined(__x86_64__)
crypto_uint8 crypto_uint8_z;
int32_t crypto_uint8_x32 = crypto_uint8_x,crypto_uint8_y32 = crypto_uint8_y,crypto_uint8_q32,crypto_uint8_z32;
__asm__ ("xorl %0,%0\n movl $1,%1\n cmpb %b3,%b2\n cmovbel %1,%0" : "=&r"(crypto_uint8_z32), "=&r"(crypto_uint8_q32) : "q"(crypto_uint8_x32), "q"(crypto_uint8_y32) : "cc");
crypto_uint8_z = crypto_uint8_z32;
return crypto_uint8_z;
#elif defined(__GNUC__) && defined(__aarch64__)
crypto_uint8 crypto_uint8_z;
__asm__ ("and %w0,%w1,255\n cmp %w0,%w2,uxtb\n cset %w0,ls" : "=&r"(crypto_uint8_z) : "r"(crypto_uint8_x), "r"(crypto_uint8_y) : "cc");
return crypto_uint8_z;
#else
return 1-crypto_uint8_smaller_01(crypto_uint8_y,crypto_uint8_x);
#endif
}
__attribute__((unused))
static inline
int crypto_uint8_ones_num(crypto_uint8 crypto_uint8_x) {
crypto_uint8 crypto_uint8_y = crypto_uint8_x;
const crypto_uint8 C0 = 0x55;
const crypto_uint8 C1 = 0x33;
const crypto_uint8 C2 = 0x0f;
crypto_uint8_y -= ((crypto_uint8_y >> 1) & C0);
crypto_uint8_y = (crypto_uint8_y & C1) + ((crypto_uint8_y >> 2) & C1);
crypto_uint8_y = (crypto_uint8_y + (crypto_uint8_y >> 4)) & C2;
return crypto_uint8_y;
}
__attribute__((unused))
static inline
int crypto_uint8_bottomzeros_num(crypto_uint8 crypto_uint8_x) {
#if defined(__GNUC__) && defined(__x86_64__)
int32_t fallback = 8;
int32_t crypto_uint8_x32 = crypto_uint8_x;
__asm__ ("bsfl %0,%0\n cmovel %1,%0" : "+&r"(crypto_uint8_x32) : "r"(fallback) : "cc");
crypto_uint8_x = crypto_uint8_x32;
return crypto_uint8_x;
#elif defined(__GNUC__) && defined(__aarch64__)
int64_t crypto_uint8_y;
__asm__ ("orr %w0,%w1,-256\n rbit %w0,%w0\n clz %w0,%w0" : "=r"(crypto_uint8_y) : "r"(crypto_uint8_x) : );
return crypto_uint8_y;
#else
crypto_uint8 crypto_uint8_y = crypto_uint8_x ^ (crypto_uint8_x-1);
crypto_uint8_y = ((crypto_uint8_signed) crypto_uint8_y) >> 1;
crypto_uint8_y &= ~(crypto_uint8_x & (((crypto_uint8) 1) << (8-1)));
return crypto_uint8_ones_num(crypto_uint8_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/crypto_uintN.h 0000664 0000000 0000000 00000135507 14747360755 0020406 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#ifndef crypto_uintN_h
#define crypto_uintN_h
#include
#define crypto_uintN uintN_t
#define crypto_uintN_signed intN_t
#define crypto_uintN_signed_optblocker namespace_uintN_signed_optblocker
extern volatile crypto_uintN_signed crypto_uintN_signed_optblocker;
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_load(const unsigned char *crypto_uintN_s) {
crypto_uintN crypto_uintN_z = 0;
int crypto_uintN_k;
for (crypto_uintN_k = 0;crypto_uintN_k < N;crypto_uintN_k += 8)
crypto_uintN_z |= ((crypto_uintN) (*crypto_uintN_s++)) << crypto_uintN_k;
return crypto_uintN_z;
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_load_bigendian(const unsigned char *crypto_uintN_s) {
crypto_uintN crypto_uintN_z = 0;
int crypto_uintN_k;
for (crypto_uintN_k = N - 8;crypto_uintN_k >= 0;crypto_uintN_k -= 8)
crypto_uintN_z |= ((crypto_uintN) (*crypto_uintN_s++)) << crypto_uintN_k;
return crypto_uintN_z;
}
__attribute__((unused))
static inline
void crypto_uintN_store(unsigned char *crypto_uintN_s,crypto_uintN crypto_uintN_x) {
int crypto_uintN_k;
for (crypto_uintN_k = 0;crypto_uintN_k < N;crypto_uintN_k += 8)
*crypto_uintN_s++ = crypto_uintN_x >> crypto_uintN_k;
}
__attribute__((unused))
static inline
void crypto_uintN_store_bigendian(unsigned char *crypto_uintN_s,crypto_uintN crypto_uintN_x) {
int crypto_uintN_k;
for (crypto_uintN_k = N - 8;crypto_uintN_k >= 0;crypto_uintN_k -= 8)
*crypto_uintN_s++ = crypto_uintN_x >> crypto_uintN_k;
}
__attribute__((unused))
static inline
crypto_uintN_signed crypto_uintN_signed_negative_mask(crypto_uintN_signed crypto_uintN_x) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x; crypto_uintN_x signed>>= 7");
16: readasm("amd64; int16 crypto_uintN_x; crypto_uintN_x signed>>= 15");
32: readasm("amd64; int32 crypto_uintN_x; crypto_uintN_x signed>>= 31");
64: readasm("amd64; int64 crypto_uintN_x; crypto_uintN_x signed>>= 63");
return crypto_uintN_x;
#elif arm64
crypto_uintN_signed crypto_uintN_y;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 7))");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 15))");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x signed>> 31");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x signed>> 63");
return crypto_uintN_y;
#else
crypto_uintN_x >>= N-6;
crypto_uintN_x += crypto_uintN_signed_optblocker;
crypto_uintN_x >>= 5;
return crypto_uintN_x;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_topbit_01(crypto_uintN crypto_uintN_x) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x; crypto_uintN_x unsigned>>= 7");
16: readasm("amd64; int16 crypto_uintN_x; crypto_uintN_x unsigned>>= 15");
32: readasm("amd64; int32 crypto_uintN_x; crypto_uintN_x unsigned>>= 31");
64: readasm("amd64; int64 crypto_uintN_x; crypto_uintN_x unsigned>>= 63");
return crypto_uintN_x;
#elif arm64
crypto_uintN_signed crypto_uintN_y;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 7)");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 15)");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x unsigned>> 31");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x unsigned>> 63");
return crypto_uintN_y;
#else
crypto_uintN_x >>= N-6;
crypto_uintN_x += crypto_uintN_signed_optblocker;
crypto_uintN_x >>= 5;
return crypto_uintN_x;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_topbit_mask(crypto_uintN crypto_uintN_x) {
return crypto_uintN_signed_negative_mask(crypto_uintN_x);
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bottombit_mask(crypto_uintN crypto_uintN_x) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x; crypto_uintN_x &= 1");
16: readasm("amd64; int16 crypto_uintN_x; crypto_uintN_x &= 1");
32: readasm("amd64; int32 crypto_uintN_x; crypto_uintN_x &= 1");
64: readasm("amd64; int64 crypto_uintN_x; crypto_uintN_x &= 1");
return -crypto_uintN_x;
#elif arm64
crypto_uintN crypto_uintN_y;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 0))");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 0))");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 0))");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = -(1 & (crypto_uintN_x unsigned>> 0))");
return crypto_uintN_y;
#else
crypto_uintN_x &= 1 + crypto_uintN_signed_optblocker;
return -crypto_uintN_x;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bottombit_01(crypto_uintN crypto_uintN_x) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x; crypto_uintN_x &= 1");
16: readasm("amd64; int16 crypto_uintN_x; crypto_uintN_x &= 1");
32: readasm("amd64; int32 crypto_uintN_x; crypto_uintN_x &= 1");
64: readasm("amd64; int64 crypto_uintN_x; crypto_uintN_x &= 1");
return crypto_uintN_x;
#elif arm64
crypto_uintN crypto_uintN_y;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 0)");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 0)");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 0)");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = 1 & (crypto_uintN_x unsigned>> 0)");
return crypto_uintN_y;
#else
crypto_uintN_x &= 1 + crypto_uintN_signed_optblocker;
return crypto_uintN_x;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bitinrangepublicpos_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
#else
crypto_uintN_x >>= crypto_uintN_s ^ crypto_uintN_signed_optblocker;
#endif
return crypto_uintN_bottombit_mask(crypto_uintN_x);
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bitinrangepublicpos_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
#if amd64
8: readasm("amd64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
#else
crypto_uintN_x >>= crypto_uintN_s ^ crypto_uintN_signed_optblocker;
#endif
return crypto_uintN_bottombit_01(crypto_uintN_x);
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_shlmod(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
#if amd64
8: crypto_uintN_s &= 7;
8: readasm("amd64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x <<= crypto_uintN_s");
16: crypto_uintN_s &= 15;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x <<= crypto_uintN_s");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x <<= crypto_uintN_s");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x <<= crypto_uintN_s");
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_s = crypto_uintN_s & 7; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x << crypto_uintN_s");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_s = crypto_uintN_s & 15; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x << crypto_uintN_s");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x << crypto_uintN_s");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x << crypto_uintN_s");
#else
int crypto_uintN_k, crypto_uintN_l;
for (crypto_uintN_l = 0,crypto_uintN_k = 1;crypto_uintN_k < N;++crypto_uintN_l,crypto_uintN_k *= 2)
crypto_uintN_x ^= (crypto_uintN_x ^ (crypto_uintN_x << crypto_uintN_k)) & crypto_uintN_bitinrangepublicpos_mask(crypto_uintN_s,crypto_uintN_l);
#endif
return crypto_uintN_x;
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_shrmod(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
#if amd64
8: crypto_uintN_s &= 7;
8: readasm("amd64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
16: crypto_uintN_s &= 15;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x unsigned>>= crypto_uintN_s");
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_s; crypto_uintN_s = crypto_uintN_s & 7; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_s; crypto_uintN_s = crypto_uintN_s & 15; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_s; crypto_uintN_x = crypto_uintN_x unsigned>> crypto_uintN_s");
#else
int crypto_uintN_k, crypto_uintN_l;
for (crypto_uintN_l = 0,crypto_uintN_k = 1;crypto_uintN_k < N;++crypto_uintN_l,crypto_uintN_k *= 2)
crypto_uintN_x ^= (crypto_uintN_x ^ (crypto_uintN_x >> crypto_uintN_k)) & crypto_uintN_bitinrangepublicpos_mask(crypto_uintN_s,crypto_uintN_l);
#endif
return crypto_uintN_x;
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bitmod_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
crypto_uintN_x = crypto_uintN_shrmod(crypto_uintN_x,crypto_uintN_s);
return crypto_uintN_bottombit_mask(crypto_uintN_x);
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_bitmod_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_s) {
crypto_uintN_x = crypto_uintN_shrmod(crypto_uintN_x,crypto_uintN_s);
return crypto_uintN_bottombit_01(crypto_uintN_x);
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_nonzero_mask(crypto_uintN crypto_uintN_x) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 & (int8) crypto_uintN_x32; crypto_uintN_z32 = crypto_uintN_q32 if !=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 255; crypto_uintN_z = -1 if != else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 65535; crypto_uintN_z = -1 if != else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = -1 if != else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = -1 if != else 0");
return crypto_uintN_z;
#else
crypto_uintN_x |= -crypto_uintN_x;
return crypto_uintN_signed_negative_mask(crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_nonzero_01(crypto_uintN crypto_uintN_x) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 & (int8) crypto_uintN_x32; crypto_uintN_z32 = crypto_uintN_q32 if !=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if !=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 255; crypto_uintN_z = 1 if != else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 65535; crypto_uintN_z = 1 if != else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = 1 if != else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = 1 if != else 0");
return crypto_uintN_z;
#else
crypto_uintN_x |= -crypto_uintN_x;
return crypto_uintN_topbit_01(crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_zero_mask(crypto_uintN crypto_uintN_x) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 & (int8) crypto_uintN_x32; crypto_uintN_z32 = crypto_uintN_q32 if =");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 255; crypto_uintN_z = -1 if = else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 65535; crypto_uintN_z = -1 if = else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = -1 if = else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = -1 if = else 0");
return crypto_uintN_z;
#else
return ~crypto_uintN_nonzero_mask(crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_zero_01(crypto_uintN crypto_uintN_x) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 & (int8) crypto_uintN_x32; crypto_uintN_z32 = crypto_uintN_q32 if =");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x & crypto_uintN_x; crypto_uintN_z = crypto_uintN_q if =");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 255; crypto_uintN_z = 1 if = else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_z; crypto_uintN_x & 65535; crypto_uintN_z = 1 if = else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = 1 if = else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_z; crypto_uintN_x - 0; crypto_uintN_z = 1 if = else 0");
return crypto_uintN_z;
#else
return 1-crypto_uintN_nonzero_01(crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_unequal_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if !=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = -1 if != else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = -1 if != else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if != else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if != else 0");
return crypto_uintN_z;
#else
return crypto_uintN_nonzero_mask(crypto_uintN_x ^ crypto_uintN_y);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_unequal_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if !=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if !=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = 1 if != else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = 1 if != else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if != else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if != else 0");
return crypto_uintN_z;
#else
return crypto_uintN_nonzero_01(crypto_uintN_x ^ crypto_uintN_y);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_equal_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if =");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = -1 if = else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = -1 if = else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if = else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if = else 0");
return crypto_uintN_z;
#else
return ~crypto_uintN_unequal_mask(crypto_uintN_x,crypto_uintN_y);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_equal_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if =");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if =");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = 1 if = else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = 1 if = else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if = else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if = else 0");
return crypto_uintN_z;
#else
return 1-crypto_uintN_unequal_01(crypto_uintN_x,crypto_uintN_y);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_min(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: uint32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_y32; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_x32 = crypto_uintN_y32 if unsigned>");
8: crypto_uintN_x = crypto_uintN_x32;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned>");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned>");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned>");
return crypto_uintN_x;
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x - (uint8) crypto_uintN_y; crypto_uintN_x = crypto_uintN_x if unsigned< else crypto_uintN_y");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x - (uint16) crypto_uintN_y; crypto_uintN_x = crypto_uintN_x if unsigned< else crypto_uintN_y");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_x if unsigned< else crypto_uintN_y");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_x if unsigned< else crypto_uintN_y");
return crypto_uintN_x;
#else
crypto_uintN crypto_uintN_r = crypto_uintN_y ^ crypto_uintN_x;
crypto_uintN crypto_uintN_z = crypto_uintN_y - crypto_uintN_x;
crypto_uintN_z ^= crypto_uintN_r & (crypto_uintN_z ^ crypto_uintN_y ^ (((crypto_uintN) 1) << (N-1)));
crypto_uintN_z = crypto_uintN_signed_negative_mask(crypto_uintN_z);
crypto_uintN_z &= crypto_uintN_r;
return crypto_uintN_x ^ crypto_uintN_z;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_max(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: uint32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_y32; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_x32 = crypto_uintN_y32 if unsigned<");
8: crypto_uintN_x = crypto_uintN_x32;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned<");
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned<");
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned<");
return crypto_uintN_x;
#elif arm64
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x - (uint8) crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned< else crypto_uintN_x");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x - (uint16) crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned< else crypto_uintN_x");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned< else crypto_uintN_x");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_x - crypto_uintN_y; crypto_uintN_x = crypto_uintN_y if unsigned< else crypto_uintN_x");
return crypto_uintN_x;
#else
crypto_uintN crypto_uintN_r = crypto_uintN_y ^ crypto_uintN_x;
crypto_uintN crypto_uintN_z = crypto_uintN_y - crypto_uintN_x;
crypto_uintN_z ^= crypto_uintN_r & (crypto_uintN_z ^ crypto_uintN_y ^ (((crypto_uintN) 1) << (N-1)));
crypto_uintN_z = crypto_uintN_signed_negative_mask(crypto_uintN_z);
crypto_uintN_z &= crypto_uintN_r;
return crypto_uintN_y ^ crypto_uintN_z;
#endif
}
__attribute__((unused))
static inline
void crypto_uintN_minmax(crypto_uintN *crypto_uintN_p,crypto_uintN *crypto_uintN_q) {
crypto_uintN crypto_uintN_x = *crypto_uintN_p;
crypto_uintN crypto_uintN_y = *crypto_uintN_q;
#if amd64
8: uint32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_x32; crypto_uintN_x32 = crypto_uintN_y32 if unsigned>; crypto_uintN_y32 = crypto_uintN_z32 if unsigned>");
8: crypto_uintN_x = crypto_uintN_x32; crypto_uintN_y = crypto_uintN_y32;
16: crypto_uintN crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_x; crypto_uintN_x = crypto_uintN_y if unsigned>; crypto_uintN_y = crypto_uintN_z if unsigned>");
32: crypto_uintN crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_x; crypto_uintN_x = crypto_uintN_y if unsigned>; crypto_uintN_y = crypto_uintN_z if unsigned>");
64: crypto_uintN crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_x; crypto_uintN_x = crypto_uintN_y if unsigned>; crypto_uintN_y = crypto_uintN_z if unsigned>");
*crypto_uintN_p = crypto_uintN_x;
*crypto_uintN_q = crypto_uintN_y;
#elif arm64
crypto_uintN crypto_uintN_r, crypto_uintN_s;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_r crypto_uintN_s; crypto_uintN_x = (uint8) crypto_uintN_x; crypto_uintN_x - (uint8) crypto_uintN_y; crypto_uintN_r = crypto_uintN_x if unsigned< else crypto_uintN_y; crypto_uintN_s = crypto_uintN_y if unsigned< else crypto_uintN_x");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_r crypto_uintN_s; crypto_uintN_x = (uint16) crypto_uintN_x; crypto_uintN_x - (uint16) crypto_uintN_y; crypto_uintN_r = crypto_uintN_x if unsigned< else crypto_uintN_y; crypto_uintN_s = crypto_uintN_y if unsigned< else crypto_uintN_x");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_r crypto_uintN_s; crypto_uintN_x - crypto_uintN_y; crypto_uintN_r = crypto_uintN_x if unsigned< else crypto_uintN_y; crypto_uintN_s = crypto_uintN_y if unsigned< else crypto_uintN_x");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_r crypto_uintN_s; crypto_uintN_x - crypto_uintN_y; crypto_uintN_r = crypto_uintN_x if unsigned< else crypto_uintN_y; crypto_uintN_s = crypto_uintN_y if unsigned< else crypto_uintN_x");
*crypto_uintN_p = crypto_uintN_r;
*crypto_uintN_q = crypto_uintN_s;
#else
crypto_uintN crypto_uintN_r = crypto_uintN_y ^ crypto_uintN_x;
crypto_uintN crypto_uintN_z = crypto_uintN_y - crypto_uintN_x;
crypto_uintN_z ^= crypto_uintN_r & (crypto_uintN_z ^ crypto_uintN_y ^ (((crypto_uintN) 1) << (N-1)));
crypto_uintN_z = crypto_uintN_signed_negative_mask(crypto_uintN_z);
crypto_uintN_z &= crypto_uintN_r;
crypto_uintN_x ^= crypto_uintN_z;
crypto_uintN_y ^= crypto_uintN_z;
*crypto_uintN_p = crypto_uintN_x;
*crypto_uintN_q = crypto_uintN_y;
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_smaller_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if unsigned<");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = -1 if unsigned< else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = -1 if unsigned< else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if unsigned< else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if unsigned< else 0");
return crypto_uintN_z;
#else
crypto_uintN crypto_uintN_r = crypto_uintN_x ^ crypto_uintN_y;
crypto_uintN crypto_uintN_z = crypto_uintN_x - crypto_uintN_y;
crypto_uintN_z ^= crypto_uintN_r & (crypto_uintN_z ^ crypto_uintN_x ^ (((crypto_uintN) 1) << (N-1)));
return crypto_uintN_signed_negative_mask(crypto_uintN_z);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_smaller_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if unsigned<");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = 1 if unsigned< else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = 1 if unsigned< else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if unsigned< else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if unsigned< else 0");
return crypto_uintN_z;
#else
crypto_uintN crypto_uintN_r = crypto_uintN_x ^ crypto_uintN_y;
crypto_uintN crypto_uintN_z = crypto_uintN_x - crypto_uintN_y;
crypto_uintN_z ^= crypto_uintN_r & (crypto_uintN_z ^ crypto_uintN_x ^ (((crypto_uintN) 1) << (N-1)));
return crypto_uintN_topbit_01(crypto_uintN_z);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_leq_mask(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = -1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if unsigned<=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = -1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = -1 if unsigned<= else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = -1 if unsigned<= else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if unsigned<= else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = -1 if unsigned<= else 0");
return crypto_uintN_z;
#else
return ~crypto_uintN_smaller_mask(crypto_uintN_y,crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
crypto_uintN crypto_uintN_leq_01(crypto_uintN crypto_uintN_x,crypto_uintN crypto_uintN_y) {
#if amd64
8: crypto_uintN crypto_uintN_z;
8: int32_t crypto_uintN_x32 = crypto_uintN_x,crypto_uintN_y32 = crypto_uintN_y,crypto_uintN_q32,crypto_uintN_z32;
8: readasm("amd64; int32 crypto_uintN_x32 crypto_uintN_q32 crypto_uintN_y32 crypto_uintN_z32; crypto_uintN_z32 = 0; crypto_uintN_q32 = 1; crypto_uintN_x32 - (int8) crypto_uintN_y32; crypto_uintN_z32 = crypto_uintN_q32 if unsigned<=");
8: crypto_uintN_z = crypto_uintN_z32;
16: crypto_uintN crypto_uintN_q,crypto_uintN_z;
16: readasm("amd64; int16 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
32: crypto_uintN crypto_uintN_q,crypto_uintN_z;
32: readasm("amd64; int32 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
64: crypto_uintN crypto_uintN_q,crypto_uintN_z;
64: readasm("amd64; int64 crypto_uintN_x crypto_uintN_q crypto_uintN_y crypto_uintN_z; crypto_uintN_z = 0; crypto_uintN_q = 1; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = crypto_uintN_q if unsigned<=");
return crypto_uintN_z;
#elif arm64
crypto_uintN crypto_uintN_z;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint8) crypto_uintN_x; crypto_uintN_z - (uint8) crypto_uintN_y; crypto_uintN_z = 1 if unsigned<= else 0");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_z = (uint16) crypto_uintN_x; crypto_uintN_z - (uint16) crypto_uintN_y; crypto_uintN_z = 1 if unsigned<= else 0");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if unsigned<= else 0");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y crypto_uintN_z; crypto_uintN_x - crypto_uintN_y; crypto_uintN_z = 1 if unsigned<= else 0");
return crypto_uintN_z;
#else
return 1-crypto_uintN_smaller_01(crypto_uintN_y,crypto_uintN_x);
#endif
}
__attribute__((unused))
static inline
int crypto_uintN_ones_num(crypto_uintN crypto_uintN_x) {
crypto_uintN crypto_uintN_y = crypto_uintN_x;
8: const crypto_uintN C0 = 0x55;
16: const crypto_uintN C0 = 0x5555;
32: const crypto_uintN C0 = 0x55555555;
64: const crypto_uintN C0 = 0x5555555555555555;
8: const crypto_uintN C1 = 0x33;
16: const crypto_uintN C1 = 0x3333;
32: const crypto_uintN C1 = 0x33333333;
64: const crypto_uintN C1 = 0x3333333333333333;
8: const crypto_uintN C2 = 0x0f;
16: const crypto_uintN C2 = 0x0f0f;
32: const crypto_uintN C2 = 0x0f0f0f0f;
64: const crypto_uintN C2 = 0x0f0f0f0f0f0f0f0f;
crypto_uintN_y -= ((crypto_uintN_y >> 1) & C0);
crypto_uintN_y = (crypto_uintN_y & C1) + ((crypto_uintN_y >> 2) & C1);
crypto_uintN_y = (crypto_uintN_y + (crypto_uintN_y >> 4)) & C2;
16: crypto_uintN_y = (crypto_uintN_y + (crypto_uintN_y >> 8)) & 0xff;
32: crypto_uintN_y += crypto_uintN_y >> 8;
32: crypto_uintN_y = (crypto_uintN_y + (crypto_uintN_y >> 16)) & 0xff;
64: crypto_uintN_y += crypto_uintN_y >> 8;
64: crypto_uintN_y += crypto_uintN_y >> 16;
64: crypto_uintN_y = (crypto_uintN_y + (crypto_uintN_y >> 32)) & 0xff;
return crypto_uintN_y;
}
__attribute__((unused))
static inline
int crypto_uintN_bottomzeros_num(crypto_uintN crypto_uintN_x) {
#if amd64
8: int32_t fallback = N;
8: int32_t crypto_uintN_x32 = crypto_uintN_x;
8: readasm("amd64; int32 crypto_uintN_x32 fallback; crypto_uintN_x32 = numbottomzeros_tricky crypto_uintN_x32; crypto_uintN_x32 = fallback if =");
8: crypto_uintN_x = crypto_uintN_x32;
16: crypto_uintN fallback = N;
16: readasm("amd64; int16 crypto_uintN_x fallback; crypto_uintN_x = numbottomzeros_tricky crypto_uintN_x; crypto_uintN_x = fallback if =");
32: crypto_uintN fallback = N;
32: readasm("amd64; int32 crypto_uintN_x fallback; crypto_uintN_x = numbottomzeros_tricky crypto_uintN_x; crypto_uintN_x = fallback if =");
64: crypto_uintN fallback = N;
64: readasm("amd64; int64 crypto_uintN_x fallback; crypto_uintN_x = numbottomzeros_tricky crypto_uintN_x; crypto_uintN_x = fallback if =");
return crypto_uintN_x;
#elif arm64
int64_t crypto_uintN_y;
8: readasm("arm64; int8 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x | -256; crypto_uintN_y = bitrev32 crypto_uintN_y; crypto_uintN_y = numbottomzeros crypto_uintN_y");
16: readasm("arm64; int16 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = crypto_uintN_x | -65536; crypto_uintN_y = bitrev32 crypto_uintN_y; crypto_uintN_y = numbottomzeros crypto_uintN_y");
32: readasm("arm64; int32 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = bitrev32 crypto_uintN_x; crypto_uintN_y = numbottomzeros crypto_uintN_y");
64: readasm("arm64; int64 crypto_uintN_x crypto_uintN_y; crypto_uintN_y = bitrev64 crypto_uintN_x; crypto_uintN_y = numbottomzeros crypto_uintN_y");
return crypto_uintN_y;
#else
crypto_uintN crypto_uintN_y = crypto_uintN_x ^ (crypto_uintN_x-1);
crypto_uintN_y = ((crypto_uintN_signed) crypto_uintN_y) >> 1;
crypto_uintN_y &= ~(crypto_uintN_x & (((crypto_uintN) 1) << (N-1)));
return crypto_uintN_ones_num(crypto_uintN_y);
#endif
}
#endif
tinyssh-20250201/cryptoint/functions 0000664 0000000 0000000 00000077342 14747360755 0017475 0 ustar 00root root 0000000 0000000 TYPE TYPE_load(const unsigned char *S) {
TYPE Z = 0;
int K;
for (K = 0;K < N;K += 8)
Z |= ((TYPE) (*S++)) << K;
return Z;
}
TYPE TYPE_load_bigendian(const unsigned char *S) {
TYPE Z = 0;
int K;
for (K = N - 8;K >= 0;K -= 8)
Z |= ((TYPE) (*S++)) << K;
return Z;
}
void TYPE_store(unsigned char *S,TYPE X) {
int K;
for (K = 0;K < N;K += 8)
*S++ = X >> K;
}
void TYPE_store_bigendian(unsigned char *S,TYPE X) {
int K;
for (K = N - 8;K >= 0;K -= 8)
*S++ = X >> K;
}
# could instead use X >>= (N-1) ^ SIGNED_optblocker
SIGNED SIGNED_negative_mask(SIGNED X) {
#if amd64
8: readasm("amd64; int8 X; X signed>>= 7");
16: readasm("amd64; int16 X; X signed>>= 15");
32: readasm("amd64; int32 X; X signed>>= 31");
64: readasm("amd64; int64 X; X signed>>= 63");
return X;
#elif arm64
SIGNED Y;
8: readasm("arm64; int8 X Y; Y = -(1 & (X unsigned>> 7))");
16: readasm("arm64; int16 X Y; Y = -(1 & (X unsigned>> 15))");
32: readasm("arm64; int32 X Y; Y = X signed>> 31");
64: readasm("arm64; int64 X Y; Y = X signed>> 63");
return Y;
#else
X >>= N-6;
X += SIGNED_optblocker;
X >>= 5;
return X;
#endif
}
UNSIGNED UNSIGNED_topbit_01(UNSIGNED X) {
#if amd64
8: readasm("amd64; int8 X; X unsigned>>= 7");
16: readasm("amd64; int16 X; X unsigned>>= 15");
32: readasm("amd64; int32 X; X unsigned>>= 31");
64: readasm("amd64; int64 X; X unsigned>>= 63");
return X;
#elif arm64
SIGNED Y;
8: readasm("arm64; int8 X Y; Y = 1 & (X unsigned>> 7)");
16: readasm("arm64; int16 X Y; Y = 1 & (X unsigned>> 15)");
32: readasm("arm64; int32 X Y; Y = X unsigned>> 31");
64: readasm("arm64; int64 X Y; Y = X unsigned>> 63");
return Y;
#else
X >>= N-6;
X += SIGNED_optblocker;
X >>= 5;
return X;
#endif
}
SIGNED:
TYPE TYPE_negative_01(TYPE X) {
return UNSIGNED_topbit_01(X);
}
SIGNED:
TYPE TYPE_topbit_mask(TYPE X) {
return SIGNED_negative_mask(X);
}
SIGNED:
TYPE TYPE_topbit_01(TYPE X) {
return UNSIGNED_topbit_01(X);
}
UNSIGNED:
TYPE TYPE_topbit_mask(TYPE X) {
return SIGNED_negative_mask(X);
}
TYPE TYPE_bottombit_mask(TYPE X) {
#if amd64
8: readasm("amd64; int8 X; X &= 1");
16: readasm("amd64; int16 X; X &= 1");
32: readasm("amd64; int32 X; X &= 1");
64: readasm("amd64; int64 X; X &= 1");
return -X;
#elif arm64
TYPE Y;
8: readasm("arm64; int8 X Y; Y = -(1 & (X unsigned>> 0))");
16: readasm("arm64; int16 X Y; Y = -(1 & (X unsigned>> 0))");
32: readasm("arm64; int32 X Y; Y = -(1 & (X unsigned>> 0))");
64: readasm("arm64; int64 X Y; Y = -(1 & (X unsigned>> 0))");
return Y;
#else
X &= 1 + SIGNED_optblocker;
return -X;
#endif
}
TYPE TYPE_bottombit_01(TYPE X) {
#if amd64
8: readasm("amd64; int8 X; X &= 1");
16: readasm("amd64; int16 X; X &= 1");
32: readasm("amd64; int32 X; X &= 1");
64: readasm("amd64; int64 X; X &= 1");
return X;
#elif arm64
TYPE Y;
8: readasm("arm64; int8 X Y; Y = 1 & (X unsigned>> 0)");
16: readasm("arm64; int16 X Y; Y = 1 & (X unsigned>> 0)");
32: readasm("arm64; int32 X Y; Y = 1 & (X unsigned>> 0)");
64: readasm("arm64; int64 X Y; Y = 1 & (X unsigned>> 0)");
return Y;
#else
X &= 1 + SIGNED_optblocker;
return X;
#endif
}
# without optblocker here, seems possible that compiler will cause trouble,
# especially if S is compile-time constant N-1
SIGNED:
TYPE TYPE_bitinrangepublicpos_mask(TYPE X,TYPE S) {
#if amd64
8: readasm("amd64; int8 X S; X signed>>= S");
16: readasm("amd64; int16 X S; X signed>>= S");
32: readasm("amd64; int32 X S; X signed>>= S");
64: readasm("amd64; int64 X S; X signed>>= S");
#elif arm64
8: readasm("arm64; int8 X S; X = (int8) X; X = X signed>> S");
16: readasm("arm64; int16 X S; X = (int16) X; X = X signed>> S");
32: readasm("arm64; int32 X S; X = X signed>> S");
64: readasm("arm64; int64 X S; X = X signed>> S");
#else
X >>= S ^ SIGNED_optblocker;
#endif
return TYPE_bottombit_mask(X);
}
# without optblocker here, seems possible that compiler will cause trouble,
# especially if S is compile-time constant N-1
SIGNED:
TYPE TYPE_bitinrangepublicpos_01(TYPE X,TYPE S) {
#if amd64
8: readasm("amd64; int8 X S; X signed>>= S");
16: readasm("amd64; int16 X S; X signed>>= S");
32: readasm("amd64; int32 X S; X signed>>= S");
64: readasm("amd64; int64 X S; X signed>>= S");
#elif arm64
8: readasm("arm64; int8 X S; X = (int8) X; X = X signed>> S");
16: readasm("arm64; int16 X S; X = (int16) X; X = X signed>> S");
32: readasm("arm64; int32 X S; X = X signed>> S");
64: readasm("arm64; int64 X S; X = X signed>> S");
#else
X >>= S ^ SIGNED_optblocker;
#endif
return TYPE_bottombit_01(X);
}
# without optblocker here, seems possible that compiler will cause trouble,
# especially if S is compile-time constant N-1
UNSIGNED:
TYPE TYPE_bitinrangepublicpos_mask(TYPE X,TYPE S) {
#if amd64
8: readasm("amd64; int8 X S; X unsigned>>= S");
16: readasm("amd64; int16 X S; X unsigned>>= S");
32: readasm("amd64; int32 X S; X unsigned>>= S");
64: readasm("amd64; int64 X S; X unsigned>>= S");
#elif arm64
8: readasm("arm64; int8 X S; X = (uint8) X; X = X unsigned>> S");
16: readasm("arm64; int16 X S; X = (uint16) X; X = X unsigned>> S");
32: readasm("arm64; int32 X S; X = X unsigned>> S");
64: readasm("arm64; int64 X S; X = X unsigned>> S");
#else
X >>= S ^ SIGNED_optblocker;
#endif
return TYPE_bottombit_mask(X);
}
# without optblocker here, seems possible that compiler will cause trouble,
# especially if S is compile-time constant N-1
UNSIGNED:
TYPE TYPE_bitinrangepublicpos_01(TYPE X,TYPE S) {
#if amd64
8: readasm("amd64; int8 X S; X unsigned>>= S");
16: readasm("amd64; int16 X S; X unsigned>>= S");
32: readasm("amd64; int32 X S; X unsigned>>= S");
64: readasm("amd64; int64 X S; X unsigned>>= S");
#elif arm64
8: readasm("arm64; int8 X S; X = (uint8) X; X = X unsigned>> S");
16: readasm("arm64; int16 X S; X = (uint16) X; X = X unsigned>> S");
32: readasm("arm64; int32 X S; X = X unsigned>> S");
64: readasm("arm64; int64 X S; X = X unsigned>> S");
#else
X >>= S ^ SIGNED_optblocker;
#endif
return TYPE_bottombit_01(X);
}
# same as (X << (S % N)) but without assuming barrel shifter
# for amd64, assumes constant-time barrel shifter
TYPE TYPE_shlmod(TYPE X,TYPE S) {
#if amd64
8: S &= 7;
8: readasm("amd64; int8 X S; X <<= S");
16: S &= 15;
16: readasm("amd64; int16 X S; X <<= S");
32: readasm("amd64; int32 X S; X <<= S");
64: readasm("amd64; int64 X S; X <<= S");
#elif arm64
8: readasm("arm64; int8 X S; S = S & 7; X = (uint8) X; X = X << S");
16: readasm("arm64; int16 X S; S = S & 15; X = (uint16) X; X = X << S");
32: readasm("arm64; int32 X S; X = X << S");
64: readasm("arm64; int64 X S; X = X << S");
#else
int K, L;
for (L = 0,K = 1;K < N;++L,K *= 2)
X ^= (X ^ (X << K)) & TYPE_bitinrangepublicpos_mask(S,L);
#endif
return X;
}
# same as (X >> (S % N)) but without assuming barrel shifter
SIGNED:
TYPE TYPE_shrmod(TYPE X,TYPE S) {
#if amd64
8: S &= 7;
8: readasm("amd64; int8 X S; X signed>>= S");
16: S &= 15;
16: readasm("amd64; int16 X S; X signed>>= S");
32: readasm("amd64; int32 X S; X signed>>= S");
64: readasm("amd64; int64 X S; X signed>>= S");
#elif arm64
8: readasm("arm64; int8 X S; S = S & 7; X = (int8) X; X = X signed>> S");
16: readasm("arm64; int16 X S; S = S & 15; X = (int16) X; X = X signed>> S");
32: readasm("arm64; int32 X S; X = X signed>> S");
64: readasm("arm64; int64 X S; X = X signed>> S");
#else
int K, L;
for (L = 0,K = 1;K < N;++L,K *= 2)
X ^= (X ^ (X >> K)) & TYPE_bitinrangepublicpos_mask(S,L);
#endif
return X;
}
# same as (X >> (S % N)) but without assuming barrel shifter
UNSIGNED:
TYPE TYPE_shrmod(TYPE X,TYPE S) {
#if amd64
8: S &= 7;
8: readasm("amd64; int8 X S; X unsigned>>= S");
16: S &= 15;
16: readasm("amd64; int16 X S; X unsigned>>= S");
32: readasm("amd64; int32 X S; X unsigned>>= S");
64: readasm("amd64; int64 X S; X unsigned>>= S");
#elif arm64
8: readasm("arm64; int8 X S; S = S & 7; X = (uint8) X; X = X unsigned>> S");
16: readasm("arm64; int16 X S; S = S & 15; X = (uint16) X; X = X unsigned>> S");
32: readasm("arm64; int32 X S; X = X unsigned>> S");
64: readasm("arm64; int64 X S; X = X unsigned>> S");
#else
int K, L;
for (L = 0,K = 1;K < N;++L,K *= 2)
X ^= (X ^ (X >> K)) & TYPE_bitinrangepublicpos_mask(S,L);
#endif
return X;
}
TYPE TYPE_bitmod_mask(TYPE X,TYPE S) {
X = TYPE_shrmod(X,S);
return TYPE_bottombit_mask(X);
}
TYPE TYPE_bitmod_01(TYPE X,TYPE S) {
X = TYPE_shrmod(X,S);
return TYPE_bottombit_01(X);
}
TYPE TYPE_nonzero_mask(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = -1; X32 & (int8) X32; Z32 = Q32 if !=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = -1; X & X; Z = Q if !=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = -1; X & X; Z = Q if !=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = -1; X & X; Z = Q if !=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; X & 255; Z = -1 if != else 0");
16: readasm("arm64; int16 X Z; X & 65535; Z = -1 if != else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = -1 if != else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = -1 if != else 0");
return Z;
#else
X |= -X;
return SIGNED_negative_mask(X);
#endif
}
# XXX: for amd64, use set instead of cmov
TYPE TYPE_nonzero_01(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = 1; X32 & (int8) X32; Z32 = Q32 if !=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = 1; X & X; Z = Q if !=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = 1; X & X; Z = Q if !=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = 1; X & X; Z = Q if !=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; X & 255; Z = 1 if != else 0");
16: readasm("arm64; int16 X Z; X & 65535; Z = 1 if != else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = 1 if != else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = 1 if != else 0");
return Z;
#else
X |= -X;
return UNSIGNED_topbit_01(X);
#endif
}
SIGNED:
TYPE TYPE_positive_mask(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = -1; X32 & (int8) X32; Z32 = Q32 if signed>");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = -1; X & X; Z = Q if signed>");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = -1; X & X; Z = Q if signed>");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = -1; X & X; Z = Q if signed>");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; Z = (int8) X; Z - 0; Z = -1 if signed> else 0");
16: readasm("arm64; int16 X Z; Z = (int16) X; Z - 0; Z = -1 if signed> else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = -1 if signed> else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = -1 if signed> else 0");
return Z;
#else
TYPE Z = -X;
Z ^= X & Z;
return TYPE_negative_mask(Z);
#endif
}
SIGNED:
TYPE TYPE_positive_01(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = 1; X32 & (int8) X32; Z32 = Q32 if signed>");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = 1; X & X; Z = Q if signed>");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = 1; X & X; Z = Q if signed>");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = 1; X & X; Z = Q if signed>");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; Z = (int8) X; Z - 0; Z = 1 if signed> else 0");
16: readasm("arm64; int16 X Z; Z = (int16) X; Z - 0; Z = 1 if signed> else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = 1 if signed> else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = 1 if signed> else 0");
return Z;
#else
TYPE Z = -X;
Z ^= X & Z;
return UNSIGNED_topbit_01(Z);
#endif
}
TYPE TYPE_zero_mask(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = -1; X32 & (int8) X32; Z32 = Q32 if =");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = -1; X & X; Z = Q if =");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = -1; X & X; Z = Q if =");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = -1; X & X; Z = Q if =");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; X & 255; Z = -1 if = else 0");
16: readasm("arm64; int16 X Z; X & 65535; Z = -1 if = else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = -1 if = else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = -1 if = else 0");
return Z;
#else
return ~TYPE_nonzero_mask(X);
#endif
}
TYPE TYPE_zero_01(TYPE X) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Z32; Z32 = 0; Q32 = 1; X32 & (int8) X32; Z32 = Q32 if =");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Z; Z = 0; Q = 1; X & X; Z = Q if =");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Z; Z = 0; Q = 1; X & X; Z = Q if =");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Z; Z = 0; Q = 1; X & X; Z = Q if =");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Z; X & 255; Z = 1 if = else 0");
16: readasm("arm64; int16 X Z; X & 65535; Z = 1 if = else 0");
32: readasm("arm64; int32 X Z; X - 0; Z = 1 if = else 0");
64: readasm("arm64; int64 X Z; X - 0; Z = 1 if = else 0");
return Z;
#else
return 1-TYPE_nonzero_01(X);
#endif
}
TYPE TYPE_unequal_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if !=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if !=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if !=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if !=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = -1 if != else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = -1 if != else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if != else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if != else 0");
return Z;
#else
return TYPE_nonzero_mask(X ^ Y);
#endif
}
TYPE TYPE_unequal_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if !=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if !=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if !=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if !=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = 1 if != else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = 1 if != else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if != else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if != else 0");
return Z;
#else
return TYPE_nonzero_01(X ^ Y);
#endif
}
TYPE TYPE_equal_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if =");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if =");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if =");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if =");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = -1 if = else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = -1 if = else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if = else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if = else 0");
return Z;
#else
return ~TYPE_unequal_mask(X,Y);
#endif
}
TYPE TYPE_equal_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if =");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if =");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if =");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if =");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = 1 if = else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = 1 if = else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if = else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if = else 0");
return Z;
#else
return 1-TYPE_unequal_01(X,Y);
#endif
}
SIGNED:
TYPE TYPE_min(TYPE X,TYPE Y) {
#if amd64
8: int32_t X32 = X,Y32 = Y;
8: readasm("amd64; int32 X32 Y32; X32 - (int8) Y32; X32 = Y32 if signed>");
8: X = X32;
16: readasm("amd64; int16 X Y; X - Y; X = Y if signed>");
32: readasm("amd64; int32 X Y; X - Y; X = Y if signed>");
64: readasm("amd64; int64 X Y; X - Y; X = Y if signed>");
return X;
#elif arm64
8: readasm("arm64; int8 X Y; X = (int8) X; X - (int8) Y; X = X if signed< else Y");
16: readasm("arm64; int16 X Y; X = (int16) X; X - (int16) Y; X = X if signed< else Y");
32: readasm("arm64; int32 X Y; X - Y; X = X if signed< else Y");
64: readasm("arm64; int64 X Y; X - Y; X = X if signed< else Y");
return X;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y);
Z = TYPE_negative_mask(Z);
Z &= R;
return X ^ Z;
#endif
}
UNSIGNED:
TYPE TYPE_min(TYPE X,TYPE Y) {
#if amd64
8: uint32_t X32 = X,Y32 = Y;
8: readasm("amd64; int32 X32 Y32; X32 - (int8) Y32; X32 = Y32 if unsigned>");
8: X = X32;
16: readasm("amd64; int16 X Y; X - Y; X = Y if unsigned>");
32: readasm("amd64; int32 X Y; X - Y; X = Y if unsigned>");
64: readasm("amd64; int64 X Y; X - Y; X = Y if unsigned>");
return X;
#elif arm64
8: readasm("arm64; int8 X Y; X = (uint8) X; X - (uint8) Y; X = X if unsigned< else Y");
16: readasm("arm64; int16 X Y; X = (uint16) X; X - (uint16) Y; X = X if unsigned< else Y");
32: readasm("arm64; int32 X Y; X - Y; X = X if unsigned< else Y");
64: readasm("arm64; int64 X Y; X - Y; X = X if unsigned< else Y");
return X;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y ^ (((TYPE) 1) << (N-1)));
Z = SIGNED_negative_mask(Z);
Z &= R;
return X ^ Z;
#endif
}
SIGNED:
TYPE TYPE_max(TYPE X,TYPE Y) {
#if amd64
8: int32_t X32 = X,Y32 = Y;
8: readasm("amd64; int32 X32 Y32; X32 - (int8) Y32; X32 = Y32 if signed<");
8: X = X32;
16: readasm("amd64; int16 X Y; X - Y; X = Y if signed<");
32: readasm("amd64; int32 X Y; X - Y; X = Y if signed<");
64: readasm("amd64; int64 X Y; X - Y; X = Y if signed<");
return X;
#elif arm64
8: readasm("arm64; int8 X Y; X = (int8) X; X - (int8) Y; X = Y if signed< else X");
16: readasm("arm64; int16 X Y; X = (int16) X; X - (int16) Y; X = Y if signed< else X");
32: readasm("arm64; int32 X Y; X - Y; X = Y if signed< else X");
64: readasm("arm64; int64 X Y; X - Y; X = Y if signed< else X");
return X;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y);
Z = TYPE_negative_mask(Z);
Z &= R;
return Y ^ Z;
#endif
}
UNSIGNED:
TYPE TYPE_max(TYPE X,TYPE Y) {
#if amd64
8: uint32_t X32 = X,Y32 = Y;
8: readasm("amd64; int32 X32 Y32; X32 - (int8) Y32; X32 = Y32 if unsigned<");
8: X = X32;
16: readasm("amd64; int16 X Y; X - Y; X = Y if unsigned<");
32: readasm("amd64; int32 X Y; X - Y; X = Y if unsigned<");
64: readasm("amd64; int64 X Y; X - Y; X = Y if unsigned<");
return X;
#elif arm64
8: readasm("arm64; int8 X Y; X = (uint8) X; X - (uint8) Y; X = Y if unsigned< else X");
16: readasm("arm64; int16 X Y; X = (uint16) X; X - (uint16) Y; X = Y if unsigned< else X");
32: readasm("arm64; int32 X Y; X - Y; X = Y if unsigned< else X");
64: readasm("arm64; int64 X Y; X - Y; X = Y if unsigned< else X");
return X;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y ^ (((TYPE) 1) << (N-1)));
Z = SIGNED_negative_mask(Z);
Z &= R;
return Y ^ Z;
#endif
}
SIGNED:
void TYPE_minmax(TYPE *P,TYPE *Q) {
TYPE X = *P;
TYPE Y = *Q;
#if amd64
8: int32_t X32 = X,Y32 = Y,Z32;
8: readasm("amd64; int32 X32 Y32 Z32; X32 - (int8) Y32; Z32 = X32; X32 = Y32 if signed>; Y32 = Z32 if signed>");
8: X = X32; Y = Y32;
16: TYPE Z;
16: readasm("amd64; int16 X Y Z; X - Y; Z = X; X = Y if signed>; Y = Z if signed>");
32: TYPE Z;
32: readasm("amd64; int32 X Y Z; X - Y; Z = X; X = Y if signed>; Y = Z if signed>");
64: TYPE Z;
64: readasm("amd64; int64 X Y Z; X - Y; Z = X; X = Y if signed>; Y = Z if signed>");
*P = X;
*Q = Y;
#elif arm64
TYPE R, S;
8: readasm("arm64; int8 X Y R S; X = (int8) X; X - (int8) Y; R = X if signed< else Y; S = Y if signed< else X");
16: readasm("arm64; int16 X Y R S; X = (int16) X; X - (int16) Y; R = X if signed< else Y; S = Y if signed< else X");
32: readasm("arm64; int32 X Y R S; X - Y; R = X if signed< else Y; S = Y if signed< else X");
64: readasm("arm64; int64 X Y R S; X - Y; R = X if signed< else Y; S = Y if signed< else X");
*P = R;
*Q = S;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y);
Z = TYPE_negative_mask(Z);
Z &= R;
X ^= Z;
Y ^= Z;
*P = X;
*Q = Y;
#endif
}
UNSIGNED:
void TYPE_minmax(TYPE *P,TYPE *Q) {
TYPE X = *P;
TYPE Y = *Q;
#if amd64
8: uint32_t X32 = X,Y32 = Y,Z32;
8: readasm("amd64; int32 X32 Y32 Z32; X32 - (int8) Y32; Z32 = X32; X32 = Y32 if unsigned>; Y32 = Z32 if unsigned>");
8: X = X32; Y = Y32;
16: TYPE Z;
16: readasm("amd64; int16 X Y Z; X - Y; Z = X; X = Y if unsigned>; Y = Z if unsigned>");
32: TYPE Z;
32: readasm("amd64; int32 X Y Z; X - Y; Z = X; X = Y if unsigned>; Y = Z if unsigned>");
64: TYPE Z;
64: readasm("amd64; int64 X Y Z; X - Y; Z = X; X = Y if unsigned>; Y = Z if unsigned>");
*P = X;
*Q = Y;
#elif arm64
TYPE R, S;
8: readasm("arm64; int8 X Y R S; X = (uint8) X; X - (uint8) Y; R = X if unsigned< else Y; S = Y if unsigned< else X");
16: readasm("arm64; int16 X Y R S; X = (uint16) X; X - (uint16) Y; R = X if unsigned< else Y; S = Y if unsigned< else X");
32: readasm("arm64; int32 X Y R S; X - Y; R = X if unsigned< else Y; S = Y if unsigned< else X");
64: readasm("arm64; int64 X Y R S; X - Y; R = X if unsigned< else Y; S = Y if unsigned< else X");
*P = R;
*Q = S;
#else
TYPE R = Y ^ X;
TYPE Z = Y - X;
Z ^= R & (Z ^ Y ^ (((TYPE) 1) << (N-1)));
Z = SIGNED_negative_mask(Z);
Z &= R;
X ^= Z;
Y ^= Z;
*P = X;
*Q = Y;
#endif
}
SIGNED:
TYPE TYPE_smaller_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if signed<");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (int8) X; Z - (int8) Y; Z = -1 if signed< else 0");
16: readasm("arm64; int16 X Y Z; Z = (int16) X; Z - (int16) Y; Z = -1 if signed< else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if signed< else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if signed< else 0");
return Z;
#else
TYPE R = X ^ Y;
TYPE Z = X - Y;
Z ^= R & (Z ^ X);
return TYPE_negative_mask(Z);
#endif
}
SIGNED:
TYPE TYPE_smaller_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if signed<");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (int8) X; Z - (int8) Y; Z = 1 if signed< else 0");
16: readasm("arm64; int16 X Y Z; Z = (int16) X; Z - (int16) Y; Z = 1 if signed< else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if signed< else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if signed< else 0");
return Z;
#else
TYPE R = X ^ Y;
TYPE Z = X - Y;
Z ^= R & (Z ^ X);
return UNSIGNED_topbit_01(Z);
#endif
}
UNSIGNED:
TYPE TYPE_smaller_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if unsigned<");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = -1 if unsigned< else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = -1 if unsigned< else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if unsigned< else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if unsigned< else 0");
return Z;
#else
TYPE R = X ^ Y;
TYPE Z = X - Y;
Z ^= R & (Z ^ X ^ (((TYPE) 1) << (N-1)));
return SIGNED_negative_mask(Z);
#endif
}
UNSIGNED:
TYPE TYPE_smaller_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if unsigned<");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = 1 if unsigned< else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = 1 if unsigned< else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if unsigned< else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if unsigned< else 0");
return Z;
#else
TYPE R = X ^ Y;
TYPE Z = X - Y;
Z ^= R & (Z ^ X ^ (((TYPE) 1) << (N-1)));
return UNSIGNED_topbit_01(Z);
#endif
}
SIGNED:
TYPE TYPE_leq_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if signed<=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if signed<=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (int8) X; Z - (int8) Y; Z = -1 if signed<= else 0");
16: readasm("arm64; int16 X Y Z; Z = (int16) X; Z - (int16) Y; Z = -1 if signed<= else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if signed<= else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if signed<= else 0");
return Z;
#else
return ~TYPE_smaller_mask(Y,X);
#endif
}
SIGNED:
TYPE TYPE_leq_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if signed<=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if signed<=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (int8) X; Z - (int8) Y; Z = 1 if signed<= else 0");
16: readasm("arm64; int16 X Y Z; Z = (int16) X; Z - (int16) Y; Z = 1 if signed<= else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if signed<= else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if signed<= else 0");
return Z;
#else
return 1-TYPE_smaller_01(Y,X);
#endif
}
UNSIGNED:
TYPE TYPE_leq_mask(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = -1; X32 - (int8) Y32; Z32 = Q32 if unsigned<=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = -1; X - Y; Z = Q if unsigned<=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = -1 if unsigned<= else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = -1 if unsigned<= else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = -1 if unsigned<= else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = -1 if unsigned<= else 0");
return Z;
#else
return ~TYPE_smaller_mask(Y,X);
#endif
}
UNSIGNED:
TYPE TYPE_leq_01(TYPE X,TYPE Y) {
#if amd64
8: TYPE Z;
8: int32_t X32 = X,Y32 = Y,Q32,Z32;
8: readasm("amd64; int32 X32 Q32 Y32 Z32; Z32 = 0; Q32 = 1; X32 - (int8) Y32; Z32 = Q32 if unsigned<=");
8: Z = Z32;
16: TYPE Q,Z;
16: readasm("amd64; int16 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<=");
32: TYPE Q,Z;
32: readasm("amd64; int32 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<=");
64: TYPE Q,Z;
64: readasm("amd64; int64 X Q Y Z; Z = 0; Q = 1; X - Y; Z = Q if unsigned<=");
return Z;
#elif arm64
TYPE Z;
8: readasm("arm64; int8 X Y Z; Z = (uint8) X; Z - (uint8) Y; Z = 1 if unsigned<= else 0");
16: readasm("arm64; int16 X Y Z; Z = (uint16) X; Z - (uint16) Y; Z = 1 if unsigned<= else 0");
32: readasm("arm64; int32 X Y Z; X - Y; Z = 1 if unsigned<= else 0");
64: readasm("arm64; int64 X Y Z; X - Y; Z = 1 if unsigned<= else 0");
return Z;
#else
return 1-TYPE_smaller_01(Y,X);
#endif
}
# XXX: consider *0x...10101 for the denouement _if_ mul is constant-time
# XXX: use popcnt if __SSE4_2__
# XXX: use cnt if arm64 cssc
# XXX: maybe use neon cnt if arm64
int TYPE_ones_num(TYPE X) {
UNSIGNED Y = X;
8: const TYPE C0 = 0x55;
16: const TYPE C0 = 0x5555;
32: const TYPE C0 = 0x55555555;
64: const TYPE C0 = 0x5555555555555555;
8: const TYPE C1 = 0x33;
16: const TYPE C1 = 0x3333;
32: const TYPE C1 = 0x33333333;
64: const TYPE C1 = 0x3333333333333333;
8: const TYPE C2 = 0x0f;
16: const TYPE C2 = 0x0f0f;
32: const TYPE C2 = 0x0f0f0f0f;
64: const TYPE C2 = 0x0f0f0f0f0f0f0f0f;
Y -= ((Y >> 1) & C0);
Y = (Y & C1) + ((Y >> 2) & C1);
Y = (Y + (Y >> 4)) & C2;
16: Y = (Y + (Y >> 8)) & 0xff;
32: Y += Y >> 8;
32: Y = (Y + (Y >> 16)) & 0xff;
64: Y += Y >> 8;
64: Y += Y >> 16;
64: Y = (Y + (Y >> 32)) & 0xff;
return Y;
}
# XXX: use tzcnt if amd64 bmi1
# XXX: use ctz if arm64 cssc
int TYPE_bottomzeros_num(TYPE X) {
#if amd64
8: int32_t fallback = N;
8: int32_t X32 = X;
8: readasm("amd64; int32 X32 fallback; X32 = numbottomzeros_tricky X32; X32 = fallback if =");
8: X = X32;
16: TYPE fallback = N;
16: readasm("amd64; int16 X fallback; X = numbottomzeros_tricky X; X = fallback if =");
32: TYPE fallback = N;
32: readasm("amd64; int32 X fallback; X = numbottomzeros_tricky X; X = fallback if =");
64: TYPE fallback = N;
64: readasm("amd64; int64 X fallback; X = numbottomzeros_tricky X; X = fallback if =");
return X;
#elif arm64
int64_t Y;
8: readasm("arm64; int8 X Y; Y = X | -256; Y = bitrev32 Y; Y = numbottomzeros Y");
16: readasm("arm64; int16 X Y; Y = X | -65536; Y = bitrev32 Y; Y = numbottomzeros Y");
32: readasm("arm64; int32 X Y; Y = bitrev32 X; Y = numbottomzeros Y");
64: readasm("arm64; int64 X Y; Y = bitrev64 X; Y = numbottomzeros Y");
return Y;
#else
TYPE Y = X ^ (X-1);
Y = ((SIGNED) Y) >> 1;
Y &= ~(X & (((TYPE) 1) << (N-1)));
return TYPE_ones_num(Y);
#endif
}
tinyssh-20250201/cryptoint/int16_optblocker.c 0000664 0000000 0000000 00000000225 14747360755 0021055 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_int16.h"
volatile crypto_int16 crypto_int16_optblocker = 0;
tinyssh-20250201/cryptoint/int32_optblocker.c 0000664 0000000 0000000 00000000225 14747360755 0021053 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_int32.h"
volatile crypto_int32 crypto_int32_optblocker = 0;
tinyssh-20250201/cryptoint/int64_optblocker.c 0000664 0000000 0000000 00000000225 14747360755 0021060 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_int64.h"
volatile crypto_int64 crypto_int64_optblocker = 0;
tinyssh-20250201/cryptoint/int8_optblocker.c 0000664 0000000 0000000 00000000222 14747360755 0020773 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_int8.h"
volatile crypto_int8 crypto_int8_optblocker = 0;
tinyssh-20250201/cryptoint/intN_optblocker.c 0000664 0000000 0000000 00000000222 14747360755 0021021 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_intN.h"
volatile crypto_intN crypto_intN_optblocker = 0;
tinyssh-20250201/cryptoint/namespace 0000664 0000000 0000000 00000000010 14747360755 0017373 0 ustar 00root root 0000000 0000000 tinyssh
tinyssh-20250201/cryptoint/readasm.py 0000775 0000000 0000000 00000044663 14747360755 0017533 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
import re
import sys
machinedesc = {}
# note for qhasm users:
# the machine descriptions here have, e.g.,
# int8 meaning where the C ABI stores an int8,
# such as a 64-bit integer register on amd64
# ===== amd64
machinedesc['amd64'] = r'''
int8 r:var/r=int8:
int16 r:var/r=int16:
int32 r:var/r=int32:
int64 r:var/r=int64:
int8 r s:var/r=int8:var/s=int8:
int16 r s:var/r=int16:var/s=int16:
int32 r s:var/r=int32:var/s=int32:
int64 r s:var/r=int64:var/s=int64:
int8 r s t:var/r=int8:var/s=int8:var/t=int8:
int16 r s t:var/r=int16:var/s=int16:var/t=int16:
int32 r s t:var/r=int32:var/s=int32:var/t=int32:
int64 r s t:var/r=int64:var/s=int64:var/t=int64:
int8 r s t u:var/r=int8:var/s=int8:var/t=int8:var/u=int8:
int16 r s t u:var/r=int16:var/s=int16:var/t=int16:var/u=int16:
int32 r s t u:var/r=int32:var/s=int32:var/t=int32:var/u=int32:
int64 r s t u:var/r=int64:var/s=int64:var/t=int64:var/u=int64:
r = 0:>r=int8:asm/xorb >r,>r:>?cc:
r = 0:>r=int16:asm/xorw >r,>r:>?cc:
r = 0:>r=int32:asm/xorl >r,>r:>?cc:
r = 0:>r=int64:asm/xorq >r,>r:>?cc:
r = n:>r=int8:#n:asm/movb $#n,>r:
r = n:>r=int16:#n:asm/movw $#n,>r:
r = n:>r=int32:#n:asm/movl $#n,>r:
r = n:>r=int64:#n:asm/movq $#n,>r:
r = -n:>r=int8:#n:asm/movb $-#n,>r:
r = -n:>r=int16:#n:asm/movw $-#n,>r:
r = -n:>r=int32:#n:asm/movl $-#n,>r:
r = -n:>r=int64:#n:asm/movq $-#n,>r:
r signed>>= n:+r=int8:#n:asm/sarb $#n,+r:>?cc:
r signed>>= n:+r=int16:#n:asm/sarw $#n,+r:>?cc:
r signed>>= n:+r=int32:#n:asm/sarl $#n,+r:>?cc:
r signed>>= n:+r=int64:#n:asm/sarq $#n,+r:>?cc:
r signed>>= s:+r=int8:?cc:
r signed>>= s:+r=int16:?cc:
r signed>>= s:+r=int32:?cc:
r signed>>= s:+r=int64:?cc:
r unsigned>>= n:+r=int8:#n:asm/shrb $#n,+r:>?cc:
r unsigned>>= n:+r=int16:#n:asm/shrw $#n,+r:>?cc:
r unsigned>>= n:+r=int32:#n:asm/shrl $#n,+r:>?cc:
r unsigned>>= n:+r=int64:#n:asm/shrq $#n,+r:>?cc:
r unsigned>>= s:+r=int8:?cc:
r unsigned>>= s:+r=int16:?cc:
r unsigned>>= s:+r=int32:?cc:
r unsigned>>= s:+r=int64:?cc:
r <<= n:+r=int8:#n:asm/shlb $#n,+r:>?cc:
r <<= n:+r=int16:#n:asm/shlw $#n,+r:>?cc:
r <<= n:+r=int32:#n:asm/shll $#n,+r:>?cc:
r <<= n:+r=int64:#n:asm/shlq $#n,+r:>?cc:
r <<= s:+r=int8:?cc:
r <<= s:+r=int16:?cc:
r <<= s:+r=int32:?cc:
r <<= s:+r=int64:?cc:
r &= n:+r=int8:#n:asm/andb $#n,+r:>?cc:
r &= n:+r=int16:#n:asm/andw $#n,+r:>?cc:
r &= n:+r=int32:#n:asm/andl $#n,+r:>?cc:
r &= n:+r=int64:#n:asm/andq $#n,+r:>?cc:
r & (int8) s:?cc:
r & s:?cc:
r & s:?cc:
r & s:?cc:
r - (int8) s:?cc:
r - s:?cc:
r - s:?cc:
r - s:?cc:
r = s:>r=int16:r:
r = s:>r=int32:r:
r = s:>r=int64:r:
r = s if signed<:+r=int16::+r=int16::+r=int32::+r=int64::+r=int16::+r=int32::+r=int64:r=int16:?cc:asm/bsfw r:
r = numbottomzeros_tricky s:>r=int32:?cc:asm/bsfl r:
r = numbottomzeros_tricky s:>r=int64:?cc:asm/bsfq r:
'''
# ===== arm64
machinedesc['arm64'] = r'''
int8 r:var/r=int8:
int16 r:var/r=int16:
int32 r:var/r=int32:
int64 r:var/r=int64:
int8 r s:var/r=int8:var/s=int8:
int16 r s:var/r=int16:var/s=int16:
int32 r s:var/r=int32:var/s=int32:
int64 r s:var/r=int64:var/s=int64:
int8 r s t:var/r=int8:var/s=int8:var/t=int8:
int16 r s t:var/r=int16:var/s=int16:var/t=int16:
int32 r s t:var/r=int32:var/s=int32:var/t=int32:
int64 r s t:var/r=int64:var/s=int64:var/t=int64:
int8 r s t u:var/r=int8:var/s=int8:var/t=int8:var/u=int8:
int16 r s t u:var/r=int16:var/s=int16:var/t=int16:var/u=int16:
int32 r s t u:var/r=int32:var/s=int32:var/t=int32:var/u=int32:
int64 r s t u:var/r=int64:var/s=int64:var/t=int64:var/u=int64:
r = s signed>> n:>r=int32:r,> n:>r=int64:r,> n:>r=int32:r,> n:>r=int64:r,> t:>r=int8:r,> t:>r=int16:r,> t:>r=int32:r,> t:>r=int64:r,> t:>r=int8:r,> t:>r=int16:r,> t:>r=int32:r,> t:>r=int64:r,r=int8:r,r=int16:r,r=int32:r,r=int64:r,r=int8:r,r=int16:r,r=int8:r,r=int16:r,r=int8:r,r=int8:r,r=int16:r,r=int16:r,r=int8:r,r=int16:r,?cc:
r & n:?cc:
r - n:?cc:
r - n:?cc:
r - n:?cc:
r - n:?cc:
r - s:?cc:
r - s:?cc:
r - s:?cc:
r - s:?cc:
r - (int8) s:?cc:
r - (uint8) s:?cc:
r - (int16) s:?cc:
r - (uint16) s:?cc:
r = -1 if != else 0:>r=int8:r,ne:
r = -1 if != else 0:>r=int16:r,ne:
r = -1 if != else 0:>r=int32:r,ne:
r = -1 if != else 0:>r=int64:r,ne:
r = -1 if = else 0:>r=int8:r,eq:
r = -1 if = else 0:>r=int16:r,eq:
r = -1 if = else 0:>r=int32:r,eq:
r = -1 if = else 0:>r=int64:r,eq:
r = -1 if signed< else 0:>r=int8:r,lt:
r = -1 if signed< else 0:>r=int16:r,lt:
r = -1 if signed< else 0:>r=int32:r,lt:
r = -1 if signed< else 0:>r=int64:r,lt:
r = -1 if signed> else 0:>r=int8:r,gt:
r = -1 if signed> else 0:>r=int16:r,gt:
r = -1 if signed> else 0:>r=int32:r,gt:
r = -1 if signed> else 0:>r=int64:r,gt:
r = -1 if signed<= else 0:>r=int8:r,le:
r = -1 if signed<= else 0:>r=int16:r,le:
r = -1 if signed<= else 0:>r=int32:r,le:
r = -1 if signed<= else 0:>r=int64:r,le:
r = -1 if unsigned< else 0:>r=int8:r,lo:
r = -1 if unsigned< else 0:>r=int16:r,lo:
r = -1 if unsigned< else 0:>r=int32:r,lo:
r = -1 if unsigned< else 0:>r=int64:r,lo:
r = -1 if unsigned<= else 0:>r=int8:r,ls:
r = -1 if unsigned<= else 0:>r=int16:r,ls:
r = -1 if unsigned<= else 0:>r=int32:r,ls:
r = -1 if unsigned<= else 0:>r=int64:r,ls:
r = 1 if != else 0:>r=int8:r,ne:
r = 1 if != else 0:>r=int16:r,ne:
r = 1 if != else 0:>r=int32:r,ne:
r = 1 if != else 0:>r=int64:r,ne:
r = 1 if = else 0:>r=int8:r,eq:
r = 1 if = else 0:>r=int16:r,eq:
r = 1 if = else 0:>r=int32:r,eq:
r = 1 if = else 0:>r=int64:r,eq:
r = 1 if signed< else 0:>r=int8:r,lt:
r = 1 if signed< else 0:>r=int16:r,lt:
r = 1 if signed< else 0:>r=int32:r,lt:
r = 1 if signed< else 0:>r=int64:r,lt:
r = 1 if signed> else 0:>r=int8:r,gt:
r = 1 if signed> else 0:>r=int16:r,gt:
r = 1 if signed> else 0:>r=int32:r,gt:
r = 1 if signed> else 0:>r=int64:r,gt:
r = 1 if signed<= else 0:>r=int8:r,le:
r = 1 if signed<= else 0:>r=int16:r,le:
r = 1 if signed<= else 0:>r=int32:r,le:
r = 1 if signed<= else 0:>r=int64:r,le:
r = 1 if unsigned< else 0:>r=int8:r,lo:
r = 1 if unsigned< else 0:>r=int16:r,lo:
r = 1 if unsigned< else 0:>r=int32:r,lo:
r = 1 if unsigned< else 0:>r=int64:r,lo:
r = 1 if unsigned<= else 0:>r=int8:r,ls:
r = 1 if unsigned<= else 0:>r=int16:r,ls:
r = 1 if unsigned<= else 0:>r=int32:r,ls:
r = 1 if unsigned<= else 0:>r=int64:r,ls:
r = s if signed< else t:>r=int8:r,r=int16:r,r=int32:r,r=int64:r,r=int8:r,r=int16:r,r=int32:r,r=int64:r,r=int8:r,r=int16:r,r=int32:r,r=int64:r,r=int8:r,r=int16:r,r=int32:r,r=int64:r,> n)):>r=int8:r,> n)):>r=int16:r,> n)):>r=int32:r,> n)):>r=int64:r,> n):>r=int8:r,> n):>r=int16:r,> n):>r=int32:r,> n):>r=int64:r,'):
if x[1:] == '?cc':
if x[0] != '<': insnwrite += ['?cc']
if x[0] != '>': insnread += ['?cc']
continue
if x[0] != '<': insnwrite += [x[1]]
if x[0] != '>': insnread += [x[1]]
insnvars += [x[1]]
assert x[2] == '='
insnvartype[x[1]] = x[3:].split('#')[0]
if len(x[3:].split('#')) > 1:
insnvarpos[x[1]] = int(x[3:].split('#')[1])
continue
if x.startswith('var/'):
insnvars += [x[4]]
assert x[5] == '='
insnvartype[x[4]] = x[6:]
insnmakevars += [x[4]]
continue
if x.startswith('asm/'):
insnasm += [x[4:]]
continue
raise Exception(x)
insn = tokens(insndesc[0])
insnpos = 0
linepos = 0
while True:
if insnpos == len(insn) and linepos == len(line):
foundinsn = True
if insnpos == len(insn) or linepos == len(line):
break
x = insn[insnpos]
y = line[linepos]
if x in insnvars:
if y in vartype:
if vartype[y] != insnvartype[x]:
break # line and insn both have variables, but different types
if x in insnvar2line:
if insnvar2line[x] != y:
break # insn variable already assigned to something different in line
else:
insnvar2line[x] = y
else:
if not isvarname(y):
break # not an acceptable variable name
insnvar2line[x] = y
else:
if y in vartype:
break # XXX: but maybe sometimes want to allow variable in line to match literal in insn
if y != x:
break # non-matching literals
insnpos += 1
linepos += 1
if foundinsn: break
if not foundinsn: print(line)
assert foundinsn
insnvar2line['?cc'] = '?cc'
for v in insnmakevars:
w = insnvar2line[v]
vartype[w] = insnvartype[v]
for v in insnvar2line:
if v == '?cc': continue
if insnvartype[v] == '#': continue
w = insnvar2line[v]
if w not in vartype:
raise Exception(f'undefined variable {w}')
for v in insnread:
w = insnvar2line[v]
if v in insnvarpos:
assert insnvarpos[v] == 4
assert machine == 'amd64'
rcxvars.add(w)
if w not in outputvars:
if w not in inputvars:
inputvars += [w]
for z in outputvars:
earlyclobber.add(z)
for v in insnwrite:
w = insnvar2line[v]
if w not in outputvars:
outputvars += [w]
for asm in insnasm:
todo += [(asm,insnvar2line)]
need8 = set()
todo2 = []
for asm,insnvar2line in todo:
todo2 += [('asm',)]
while len(asm) > 0:
if asm[0] in ('<','+','>'):
if asm[2:].startswith('%8'):
todo2 += [('var8',insnvar2line[asm[1]])]
need8.add(insnvar2line[asm[1]])
asm = asm[4:]
else:
todo2 += [('var',insnvar2line[asm[1]])]
asm = asm[2:]
elif asm[0] == '#':
todo2 += [('str',insnvar2line[asm[1]])]
asm = asm[2:]
else:
todo2 += [('str',asm[0])]
asm = asm[1:]
varnextpos = 0
var2name = {}
outputs = []
for w in outputvars:
if w == '?cc': continue
if machine == 'arm64' and vartype[w] != 'int64': # XXX: abstract this
var2name[w] = f'%w{varnextpos}'
else:
var2name[w] = f'%{varnextpos}'
varnextpos += 1
regtype = 'r'
if w in need8: regtype = 'q'
if w in rcxvars: regtype = 'c'
if w in earlyclobber: regtype = '&'+regtype
if w in inputvars:
outputs += [f'"+{regtype}"({w})']
else:
outputs += [f'"={regtype}"({w})']
inputs = []
for w in inputvars:
if w in outputvars: continue
assert w != '?cc'
if machine == 'arm64' and vartype[w] != 'int64': # XXX: abstract this
var2name[w] = f'%w{varnextpos}'
else:
var2name[w] = f'%{varnextpos}'
varnextpos += 1
regtype = 'r'
if w in need8: regtype = 'q'
if w in rcxvars: regtype = 'c'
inputs += [f'"{regtype}"({w})']
clobbers = []
for w in outputvars:
if w != '?cc': continue
clobbers += ['"cc"']
result = ''
for T in todo2:
if T[0] == 'asm':
if result != '': result += '\\n '
elif T[0] == 'var8':
result += var2name[T[1]].replace('%','%b')
elif T[0] == 'var':
result += var2name[T[1]]
else:
assert T[0] == 'str'
result += T[1]
outputs = ', '.join(outputs)
if len(outputs) > 0: outputs += ' '
inputs = ', '.join(inputs)
if len(inputs) > 0: inputs += ' '
clobbers = ', '.join(clobbers)
result = f'__asm__ ("{result}" : {outputs}: {inputs}: {clobbers})'
return result
def substitute(program):
result = ''
for line in program.splitlines():
m = re.fullmatch(r'(.*)\breadasm\("([^"]*)"\)(.*)',line)
if m:
result += m.group(1)+process(m.group(2))+m.group(3)+'\n'
else:
result += line+'\n'
return result
def test():
print(process('amd64; int64 X; X signed>>= 63'))
print(process('arm64; int8 X; int8 Y; X = (int8) X; Y = (int8) Y; X - Y; X = Y if signed< else X'))
print(process('arm64; int8 X; int8 Y; int8 Z; Z = (uint8) X; Z - (uint8) Y; Z = -1 if unsigned<= else 0'))
print(process('arm64; int64 X; int64 Y; int64 R; int64 S; X - Y; R = X if unsigned< else Y; S = Y if unsigned< else X'))
if __name__ == '__main__':
test()
tinyssh-20250201/cryptoint/specialize.py 0000775 0000000 0000000 00000005063 14747360755 0020236 0 ustar 00root root 0000000 0000000 #!/usr/bin/env python3
import os
import readasm
with open('namespace') as f:
projectnamespace = f.readline().strip()
with open('crypto_intN.h') as f:
intN = f.read()
with open('crypto_uintN.h') as f:
uintN = f.read()
for bits in 8,16,32,64:
for ui in 'int','uint':
TYPE = f'crypto_{ui}{bits}'
with open(f'{TYPE}.h','w') as f:
contents = intN if ui == 'int' else uintN
contents = contents.replace('N',str(bits))
contents = contents.replace('namespace',projectnamespace)
contents = readasm.substitute(contents)
contents = contents.replace('amd64','defined(__GNUC__) && defined(__x86_64__)')
contents = contents.replace('arm64','defined(__GNUC__) && defined(__aarch64__)')
newcontents = ''
for line in contents.splitlines():
if ':' in line:
condbits = line.split(':')[0].strip()
if condbits.isnumeric():
if int(condbits) != bits:
continue
line = ':'.join(line.split(':')[1:])
newcontents += line+'\n'
contents = newcontents
tounroll = f' int {TYPE}_k;\n for ({TYPE}_k = 0;{TYPE}_k < {bits};{TYPE}_k += 8)\n {TYPE}_z |= (({TYPE}) (*{TYPE}_s++)) << {TYPE}_k;'
unrolled = '\n'.join(f' {TYPE}_z |= (({TYPE}) (*{TYPE}_s++)) << {k};' for k in range(0,bits,8))
contents = contents.replace(tounroll,unrolled)
tounroll = f' int {TYPE}_k;\n for ({TYPE}_k = {bits} - 8;{TYPE}_k >= 0;{TYPE}_k -= 8)\n {TYPE}_z |= (({TYPE}) (*{TYPE}_s++)) << {TYPE}_k;'
unrolled = '\n'.join(f' {TYPE}_z |= (({TYPE}) (*{TYPE}_s++)) << {k};' for k in reversed(range(0,bits,8)))
contents = contents.replace(tounroll,unrolled)
tounroll = f' int {TYPE}_k;\n for ({TYPE}_k = 0;{TYPE}_k < {bits};{TYPE}_k += 8)\n *{TYPE}_s++ = {TYPE}_x >> {TYPE}_k;'
unrolled = '\n'.join(f' *{TYPE}_s++ = {TYPE}_x >> {k};' for k in range(0,bits,8))
contents = contents.replace(tounroll,unrolled)
tounroll = f' int {TYPE}_k;\n for ({TYPE}_k = {bits} - 8;{TYPE}_k >= 0;{TYPE}_k -= 8)\n *{TYPE}_s++ = {TYPE}_x >> {TYPE}_k;'
unrolled = '\n'.join(f' *{TYPE}_s++ = {TYPE}_x >> {k};' for k in reversed(range(0,bits,8)))
contents = contents.replace(tounroll,unrolled)
f.write(contents)
for intc in sorted(os.listdir('.')):
if not intc.endswith('.c'): continue
if not (intc.startswith('int') or intc.startswith('uint')): continue
targetintc = intc.replace('N',str(bits))
with open(intc) as f:
contents = f.read()
with open(targetintc,'w') as f:
f.write(contents.replace('N',str(bits)))
tinyssh-20250201/cryptoint/uint16_optblocker.c 0000664 0000000 0000000 00000000246 14747360755 0021245 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_uint16.h"
volatile crypto_uint16_signed crypto_uint16_signed_optblocker = 0;
tinyssh-20250201/cryptoint/uint32_optblocker.c 0000664 0000000 0000000 00000000246 14747360755 0021243 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_uint32.h"
volatile crypto_uint32_signed crypto_uint32_signed_optblocker = 0;
tinyssh-20250201/cryptoint/uint64_optblocker.c 0000664 0000000 0000000 00000000246 14747360755 0021250 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_uint64.h"
volatile crypto_uint64_signed crypto_uint64_signed_optblocker = 0;
tinyssh-20250201/cryptoint/uint8_optblocker.c 0000664 0000000 0000000 00000000243 14747360755 0021163 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_uint8.h"
volatile crypto_uint8_signed crypto_uint8_signed_optblocker = 0;
tinyssh-20250201/cryptoint/uintN_optblocker.c 0000664 0000000 0000000 00000000243 14747360755 0021211 0 ustar 00root root 0000000 0000000 /* auto-generated: cd cryptoint; ./autogen */
/* cryptoint 20241003 */
#include "crypto_uintN.h"
volatile crypto_uintN_signed crypto_uintN_signed_optblocker = 0;
tinyssh-20250201/cryptoint/version 0000664 0000000 0000000 00000000023 14747360755 0017130 0 ustar 00root root 0000000 0000000 cryptoint 20241003
tinyssh-20250201/die.c 0000664 0000000 0000000 00000001032 14747360755 0014373 0 ustar 00root root 0000000 0000000 #include "global.h"
#include "log.h"
#include "die.h"
void die_usage(const char *x) {
log_u1(x);
global_die(100);
}
void die_fatal_(const char *fn, unsigned long long line, const char *trouble,
const char *d, const char *f) {
if (d) {
if (f)
log_9_(1, 0, fn, line, trouble, " ", d, "/", f, 0, 0, 0, 0);
else
log_9_(1, 0, fn, line, trouble, " ", d, 0, 0, 0, 0, 0, 0);
}
else { log_9_(1, 0, fn, line, trouble, 0, 0, 0, 0, 0, 0, 0, 0); }
global_die(111);
}
tinyssh-20250201/die.h 0000664 0000000 0000000 00000000430 14747360755 0014401 0 ustar 00root root 0000000 0000000 #ifndef DIE_H____
#define DIE_H____
extern void die_usage(const char *);
extern void die_fatal_(const char *, unsigned long long, const char *,
const char *, const char *);
#define die_fatal(a, b, cc) die_fatal_(__FILE__, __LINE__, (a), (b), (cc))
#endif
tinyssh-20250201/dropuidgid.c 0000664 0000000 0000000 00000001654 14747360755 0015776 0 ustar 00root root 0000000 0000000 /*
20140420
Jan Mojzis
Public domain.
*/
#include
#include