1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 01:18:00 +00:00
putty-source/crypto/ntru.h
Simon Tatham faf1601a55 Implement OpenSSH 9.x's NTRU Prime / Curve25519 kex.
This consists of DJB's 'Streamlined NTRU Prime' quantum-resistant
cryptosystem, currently in round 3 of the NIST post-quantum key
exchange competition; it's run in parallel with ordinary Curve25519,
and generates a shared secret combining the output of both systems.

(Hence, even if you don't trust this newfangled NTRU Prime thing at
all, it's at least no _less_ secure than the kex you were using
already.)

As the OpenSSH developers point out, key exchange is the most urgent
thing to make quantum-resistant, even before working quantum computers
big enough to break crypto become available, because a break of the
kex algorithm can be applied retroactively to recordings of your past
sessions. By contrast, authentication is a real-time protocol, and can
only be broken by a quantum computer if there's one available to
attack you _already_.

I've implemented both sides of the mechanism, so that PuTTY and Uppity
both support it. In my initial testing, the two sides can both
interoperate with the appropriate half of OpenSSH, and also (of
course, but it would be embarrassing to mess it up) with each other.
2022-04-15 17:46:06 +01:00

54 lines
2.4 KiB
C

/*
* Internal functions for the NTRU cryptosystem, exposed in a header
* that is expected to be included only by ntru.c and test programs.
*/
#ifndef PUTTY_CRYPTO_NTRU_H
#define PUTTY_CRYPTO_NTRU_H
unsigned ntru_ring_invert(uint16_t *out, const uint16_t *in,
unsigned p, unsigned q);
void ntru_ring_multiply(uint16_t *out, const uint16_t *a, const uint16_t *b,
unsigned p, unsigned q);
void ntru_mod3(uint16_t *out, const uint16_t *in, unsigned p, unsigned q);
void ntru_round3(uint16_t *out, const uint16_t *in, unsigned p, unsigned q);
void ntru_bias(uint16_t *out, const uint16_t *in, unsigned bias,
unsigned p, unsigned q);
void ntru_scale(uint16_t *out, const uint16_t *in, uint16_t scale,
unsigned p, unsigned q);
NTRUEncodeSchedule *ntru_encode_schedule(const uint16_t *ms_in, size_t n);
void ntru_encode_schedule_free(NTRUEncodeSchedule *sched);
size_t ntru_encode_schedule_length(NTRUEncodeSchedule *sched);
size_t ntru_encode_schedule_nvals(NTRUEncodeSchedule *sched);
void ntru_encode(NTRUEncodeSchedule *sched, const uint16_t *rs_in,
BinarySink *bs);
void ntru_decode(NTRUEncodeSchedule *sched, uint16_t *rs_out, ptrlen data);
void ntru_gen_short(uint16_t *v, unsigned p, unsigned w);
NTRUKeyPair *ntru_keygen_attempt(unsigned p, unsigned q, unsigned w);
NTRUKeyPair *ntru_keygen(unsigned p, unsigned q, unsigned w);
void ntru_keypair_free(NTRUKeyPair *keypair);
void ntru_encrypt(uint16_t *ciphertext, const uint16_t *plaintext,
uint16_t *pubkey, unsigned p, unsigned q);
void ntru_decrypt(uint16_t *plaintext, const uint16_t *ciphertext,
NTRUKeyPair *keypair);
void ntru_encode_pubkey(const uint16_t *pubkey, unsigned p, unsigned q,
BinarySink *bs);
ptrlen ntru_decode_pubkey(uint16_t *pubkey, unsigned p, unsigned q,
BinarySource *src);
void ntru_encode_ciphertext(const uint16_t *ciphertext, unsigned p, unsigned q,
BinarySink *bs);
ptrlen ntru_decode_ciphertext(uint16_t *ct, NTRUKeyPair *keypair,
BinarySource *src);
void ntru_encode_plaintext(const uint16_t *plaintext, unsigned p,
BinarySink *bs);
unsigned ntru_keypair_p(NTRUKeyPair *keypair);
const uint16_t *ntru_pubkey(NTRUKeyPair *keypair);
#endif /* PUTTY_CRYPTO_NTRU_H */