1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/crypto
Simon Tatham ab70bda4c7 ntru_gen_short: remove quadratic-time shuffle.
This function has to make an array containing a specific number of
random values that are +1 or -1, and all the rest zero. The simplest
way I could think of to do it at first was to make the array with all
the zeroes at the end and then shuffle the array.

But I couldn't think of a time-safe algorithm to shuffle an array in
such a way that all orders come out equiprobable, that was better than
quadratic time. In fact I still can't think of one. (Making a random
Benes network is the best idea I've come up with: it arranges that
every output order is _possible_, and runs in O(N log N) time, but it
skews the probabilities, which makes it unacceptable.)

However, there's no need to shuffle an array in this application
anyway: we're not actually trying to generate a random _permutation_,
only a random element of (n choose w). So we can just walk linearly
along the array remembering how many nonzero elements we have yet to
output, and using an appropriately chosen random number at each step
to decide whether this will be one of them.

This isn't a significant improvement in the performance of NTRU
overall, but it satisfies my sense of rightness a little, and at least
means I don't have to have a comment in the code apologising for the
terrible algorithm any more.
2022-05-07 12:02:23 +01:00
..
aes-common.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
aes-neon.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
aes-ni.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
aes-select.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
aes-sw.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
aes.h Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
arcfour.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
argon2.c Fix a batch of typos in comments and docs. 2022-01-03 06:40:51 +00:00
bcrypt.c Expose openssh_bcrypt() to testcrypt, and test it. 2021-12-24 10:13:28 +00:00
blake2.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
blowfish.c Move a few stray header files into the crypto subdir. 2021-04-22 17:57:56 +01:00
blowfish.h Update source file names in comments and docs. 2022-01-22 15:51:31 +00:00
chacha20-poly1305.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
CMakeLists.txt Family of key types for OpenSSH certificates. 2022-04-25 15:09:31 +01:00
crc32.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
des.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
diffie-hellman.c Use C99 named initialisers in all ssh_kex instances. 2022-04-15 17:46:06 +01:00
dsa.c Certificate-specific ssh_key method suite. 2022-04-25 15:09:31 +01:00
ecc-arithmetic.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
ecc-ssh.c Certificate-specific ssh_key method suite. 2022-04-25 15:09:31 +01:00
ecc.h testcrypt: adjust some function parameter names. 2021-11-21 22:19:01 +00:00
hash_simple.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
hmac.c Generalise strbuf_catf() into put_fmt(). 2021-11-19 11:32:47 +00:00
mac_simple.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
mac.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
md5.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
mpint_i.h Update source file names in comments and docs. 2022-01-22 15:51:31 +00:00
mpint.c Utility function mp_resize. 2022-04-15 17:46:06 +01:00
ntru.c ntru_gen_short: remove quadratic-time shuffle. 2022-05-07 12:02:23 +01:00
ntru.h Implement OpenSSH 9.x's NTRU Prime / Curve25519 kex. 2022-04-15 17:46:06 +01:00
openssh-certs.c Permit configuring RSA signature types in certificates. 2022-05-02 11:17:58 +01:00
prng.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
pubkey-pem.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
pubkey-ppk.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
pubkey-ssh1.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
rsa.c Certificate-specific ssh_key method suite. 2022-04-25 15:09:31 +01:00
sha1-common.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha1-neon.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha1-ni.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha1-select.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha1-sw.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha1.h Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha3.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00
sha256-common.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha256-neon.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha256-ni.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha256-select.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha256-sw.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha256.h Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha512-common.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha512-neon.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha512-select.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha512-sw.c Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
sha512.h Break up crypto modules containing HW acceleration. 2021-04-21 21:55:26 +01:00
xdmauth.c Move crypto into its own subdirectory. 2021-04-21 21:55:26 +01:00