Add the CRC32 compensation attack detector that all other SSH
[u/mdw/putty] / ssh.h
diff --git a/ssh.h b/ssh.h
index 2406bd6..7857f15 100644 (file)
--- a/ssh.h
+++ b/ssh.h
@@ -2,6 +2,7 @@
 
 #include "puttymem.h"
 #include "network.h"
+#include "int64.h"
 
 struct ssh_channel;
 
@@ -48,6 +49,10 @@ struct RSAKey {
     char *comment;
 };
 
+struct dss_key {
+    Bignum p, q, g, y, x;
+};
+
 int makekey(unsigned char *data, struct RSAKey *result,
            unsigned char **keystr, int order);
 int makeprivate(unsigned char *data, struct RSAKey *result);
@@ -59,12 +64,18 @@ int rsastr_len(struct RSAKey *key);
 void rsastr_fmt(char *str, struct RSAKey *key);
 void rsa_fingerprint(char *str, int len, struct RSAKey *key);
 int rsa_verify(struct RSAKey *key);
+unsigned char *rsa_public_blob(struct RSAKey *key, int *len);
+int rsa_public_blob_len(void *data);
 void freersakey(struct RSAKey *key);
 
 typedef unsigned int word32;
 typedef unsigned int uint32;
 
 unsigned long crc32(const void *s, size_t len);
+unsigned long crc32_update(unsigned long crc_input, const void *s, size_t len);
+
+/* SSH CRC compensation attack detector */
+int detect_attack(unsigned char *buf, uint32 len, unsigned char *IV);
 
 typedef struct {
     uint32 h[4];
@@ -92,12 +103,25 @@ typedef struct {
     int blkused;
     uint32 lenhi, lenlo;
 } SHA_State;
-
 void SHA_Init(SHA_State * s);
 void SHA_Bytes(SHA_State * s, void *p, int len);
 void SHA_Final(SHA_State * s, unsigned char *output);
 void SHA_Simple(void *p, int len, unsigned char *output);
 
+void hmac_sha1_simple(void *key, int keylen, void *data, int datalen,
+                     unsigned char *output);
+
+typedef struct {
+    uint64 h[8];
+    unsigned char block[128];
+    int blkused;
+    uint32 len[4];
+} SHA512_State;
+void SHA512_Init(SHA512_State * s);
+void SHA512_Bytes(SHA512_State * s, const void *p, int len);
+void SHA512_Final(SHA512_State * s, unsigned char *output);
+void SHA512_Simple(const void *p, int len, unsigned char *output);
+
 struct ssh_cipher {
     void (*sesskey) (unsigned char *key);      /* for ssh 1 */
     void (*encrypt) (unsigned char *blk, int len);
@@ -182,6 +206,7 @@ extern const struct ssh_cipher ssh_3des;
 extern const struct ssh_cipher ssh_des;
 extern const struct ssh_cipher ssh_blowfish_ssh1;
 extern const struct ssh2_ciphers ssh2_3des;
+extern const struct ssh2_ciphers ssh2_des;
 extern const struct ssh2_ciphers ssh2_aes;
 extern const struct ssh2_ciphers ssh2_blowfish;
 extern const struct ssh_kex ssh_diffiehellman;
@@ -219,7 +244,7 @@ void ssh_send_port_open(void *channel, char *hostname, int port, char *org);
 Bignum copybn(Bignum b);
 Bignum bn_power_2(int n);
 void bn_restore_invariant(Bignum b);
-Bignum bignum_from_short(unsigned short n);
+Bignum bignum_from_long(unsigned long n);
 void freebn(Bignum b);
 Bignum modpow(Bignum base, Bignum exp, Bignum mod);
 Bignum modmul(Bignum a, Bignum b, Bignum mod);
@@ -238,6 +263,9 @@ Bignum biggcd(Bignum a, Bignum b);
 unsigned short bignum_mod_short(Bignum number, unsigned short modulus);
 Bignum bignum_add_long(Bignum number, unsigned long addend);
 Bignum bigmul(Bignum a, Bignum b);
+Bignum bigmuladd(Bignum a, Bignum b, Bignum addend);
+Bignum bigdiv(Bignum a, Bignum b);
+Bignum bigmod(Bignum a, Bignum b);
 Bignum modinv(Bignum number, Bignum modulus);
 Bignum bignum_bitmask(Bignum number);
 Bignum bignum_rshift(Bignum number, int shift);
@@ -252,6 +280,7 @@ Bignum dh_find_K(Bignum f);
 
 int loadrsakey(char *filename, struct RSAKey *key, char *passphrase);
 int rsakey_encrypted(char *filename, char **comment);
+int rsakey_pubblob(char *filename, void **blob, int *bloblen);
 
 int saversakey(char *filename, struct RSAKey *key, char *passphrase);
 
@@ -280,12 +309,20 @@ void aes256_decrypt_pubkey(unsigned char *key, unsigned char *blk,
 /*
  * For progress updates in the key generation utility.
  */
-typedef void (*progfn_t) (void *param, int phase, int progress);
+#define PROGFN_INITIALISE 1
+#define PROGFN_LIN_PHASE 2
+#define PROGFN_EXP_PHASE 3
+#define PROGFN_PHASE_EXTENT 4
+#define PROGFN_READY 5
+#define PROGFN_PROGRESS 6
+typedef void (*progfn_t) (void *param, int action, int phase, int progress);
 
 int rsa_generate(struct RSAKey *key, int bits, progfn_t pfn,
                 void *pfnparam);
-Bignum primegen(int bits, int modulus, int residue, int phase,
-               progfn_t pfn, void *pfnparam);
+int dsa_generate(struct dss_key *key, int bits, progfn_t pfn,
+                void *pfnparam);
+Bignum primegen(int bits, int modulus, int residue, Bignum factor,
+               int phase, progfn_t pfn, void *pfnparam);
 
 
 /*
@@ -325,3 +362,9 @@ int zlib_decompress_block(unsigned char *block, int len,
 #define SSH2_AGENTC_ADD_IDENTITY                17
 #define SSH2_AGENTC_REMOVE_IDENTITY             18
 #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES       19
+
+/*
+ * Need this to warn about support for the original SSH2 keyfile
+ * format.
+ */
+void old_keyfile_warning(void);