Browse Source

Resetting WinSCP-specific changes committed by mistake to the thirdparty (dev) branch in d7a42c81

Source commit: 148b1e007f87da247955fdf63400c1ebff71314a
Martin Prikryl 4 years ago
parent
commit
b5f61c2f2f
3 changed files with 65 additions and 140 deletions
  1. 12 40
      source/putty/sshargon2.c
  2. 19 38
      source/putty/sshblake2.c
  3. 34 62
      source/putty/sshsha3.c

+ 12 - 40
source/putty/sshargon2.c

@@ -86,11 +86,9 @@ strbuf *argon2_long_hash(unsigned length, ptrlen data)
 {
     ssh_hash *h = hprime_new(length);
     put_datapl(h, data);
-    { // WINSCP
     strbuf *out = strbuf_new();
     hprime_final(h, length, strbuf_append(out, length));
     return out;
-    } // WINSCP
 }
 
 /* ----------------------------------------------------------------------
@@ -104,9 +102,7 @@ strbuf *argon2_long_hash(unsigned length, ptrlen data)
 
 static inline uint64_t ror(uint64_t x, unsigned rotation)
 {
-#pragma option push -w-ngu // WINSCP
     unsigned lshift = 63 & -rotation, rshift = 63 & rotation;
-#pragma option pop // WINSCP
     return (x << lshift) | (x >> rshift);
 }
 
@@ -139,8 +135,7 @@ static inline void GB(uint64_t *a, uint64_t *b, uint64_t *c, uint64_t *d)
 static inline void P(uint64_t *out, unsigned outstep,
                      uint64_t *in, unsigned instep)
 {
-    unsigned i; // WINSCP
-    for (i = 0; i < 8; i++) {
+    for (unsigned i = 0; i < 8; i++) {
         out[i*outstep] = in[i*instep];
         out[i*outstep+1] = in[i*instep+1];
     }
@@ -164,17 +159,16 @@ static void G_xor(uint8_t *out, const uint8_t *X, const uint8_t *Y)
 {
     uint64_t R[128], Q[128], Z[128];
 
-    unsigned i; // WINSCP
-    for (i = 0; i < 128; i++)
+    for (unsigned i = 0; i < 128; i++)
         R[i] = GET_64BIT_LSB_FIRST(X + 8*i) ^ GET_64BIT_LSB_FIRST(Y + 8*i);
 
-    for (i = 0; i < 8; i++) // WINSCP
+    for (unsigned i = 0; i < 8; i++)
         P(Q+16*i, 2, R+16*i, 2);
 
-    for (i = 0; i < 8; i++) // WINSCP
+    for (unsigned i = 0; i < 8; i++)
         P(Z+2*i, 16, Q+2*i, 16);
 
-    for (i = 0; i < 128; i++) // WINSCP
+    for (unsigned i = 0; i < 128; i++)
         PUT_64BIT_LSB_FIRST(out + 8*i,
                             GET_64BIT_LSB_FIRST(out + 8*i) ^ R[i] ^ Z[i]);
 
@@ -216,7 +210,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
         ssh_hash_final(h, h0);
     }
 
-    { // WINSCP
     struct blk { uint8_t data[1024]; };
 
     /*
@@ -249,16 +242,14 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
      * the long-output hash function H' to hash h0 itself plus the block's
      * coordinates in the array.
      */
-    { // WINSCP
-    size_t i; // WINSCP
-    for (i = 0; i < p; i++) {
+    for (size_t i = 0; i < p; i++) {
         ssh_hash *h = hprime_new(1024);
         put_data(h, h0, 64);
         put_uint32_le(h, 0);
         put_uint32_le(h, i);
         hprime_final(h, 1024, B[i].data);
     }
-    for (i = 0; i < p; i++) { // WINSCP
+    for (size_t i = 0; i < p; i++) {
         ssh_hash *h = hprime_new(1024);
         put_data(h, h0, 64);
         put_uint32_le(h, 1);
@@ -283,18 +274,15 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
      * independent, and then once we've mixed things up enough, switch over to
      * dependent mode to force long serial chains of computation.
      */
-    { // WINSCP
     size_t jstart = 2;
     bool d_mode = (y == 0);
     struct blk out2i, tmp2i, in2i;
 
     /* Outermost loop: t whole passes from left to right over the array */
-    size_t pass; // WINSCP
-    for (pass = 0; pass < t; pass++) {
+    for (size_t pass = 0; pass < t; pass++) {
 
         /* Within that, we process the array in its four main slices */
-        unsigned slice; // WINSCP
-        for (slice = 0; slice < 4; slice++) {
+        for (unsigned slice = 0; slice < 4; slice++) {
 
             /* In Argon2id mode, if we're half way through the first pass,
              * this is the moment to switch d_mode from false to true */
@@ -303,15 +291,12 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
 
             /* Loop over every segment in the slice (i.e. every row). So i is
              * the y-coordinate of each block we process. */
-            { // WINSCP
-            size_t i; // WINSCP
-            for (i = 0; i < p; i++) {
+            for (size_t i = 0; i < p; i++) {
 
                 /* And within that segment, process the blocks from left to
                  * right, starting at 'jstart' (usually 0, but 2 in the first
                  * slice). */
-                size_t jpre; // WINSCP
-                for (jpre = jstart; jpre < SL; jpre++) {
+                for (size_t jpre = jstart; jpre < SL; jpre++) {
 
                     /* j is the x-coordinate of each block we process, made up
                      * of the slice number and the index 'jpre' within the
@@ -406,7 +391,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
                      * because it's already massively randomised from the real
                      * inputs).
                      */
-                    { // WINSCP
                     uint32_t index_l = (pass == 0 && slice == 0) ? i : J2 % p;
 
                     /*
@@ -463,7 +447,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
                     }
 
                     /* Total number of blocks available to choose from */
-                    { // WINSCP
                     uint32_t Wsize = (Wend + q - Wstart) % q;
 
                     /* Fiddly computation from the spec that chooses from the
@@ -483,8 +466,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
                      * in our current output block. */
                     G_xor(B[i + p * j].data, B[i + p * jm1].data,
                           B[index_l + p * index_z].data);
-                    } // WINSCP
-                    } // WINSCP
                 }
             }
 
@@ -493,7 +474,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
              * case it still had its initial value of 2 to avoid the starting
              * data. */
             jstart = 0;
-            } // WINSCP
         }
     }
 
@@ -504,10 +484,8 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
      * deliver to the caller.
      */
 
-    { // WINSCP
     struct blk C = B[p * (q-1)];
-    size_t i; // WINSCP
-    for (i = 1; i < p; i++)
+    for (size_t i = 1; i < p; i++)
         memxor(C.data, C.data, B[i + p * (q-1)].data, 1024);
 
     {
@@ -525,10 +503,6 @@ static void argon2_internal(uint32_t p, uint32_t T, uint32_t m, uint32_t t,
     smemclr(C.data, sizeof(C.data));
     smemclr(B, mprime * sizeof(struct blk));
     sfree(B);
-    } // WINSCP
-    } // WINSCP
-    } // WINSCP
-    } // WINSCP
 }
 
 /*
@@ -571,7 +545,6 @@ void argon2_choose_passes(
     while (true) {
         unsigned long start_time = GETTICKCOUNT();
         argon2(flavour, mem, b, parallel, taglen, P, S, K, X, out);
-        { // WINSCP
         unsigned long ticks = GETTICKCOUNT() - start_time;
 
         /* But just in case computers get _too_ fast, we have to cap
@@ -588,6 +561,5 @@ void argon2_choose_passes(
             b += a;
             a = b - a;
         }
-        } // WINSCP
     }
 }

+ 19 - 38
source/putty/sshblake2.c

@@ -11,9 +11,7 @@
 
 static inline uint64_t ror(uint64_t x, unsigned rotation)
 {
-#pragma option push -w-ngu // WINSCP
     unsigned lshift = 63 & -rotation, rshift = 63 & rotation;
-#pragma option pop // WINSCP
     return (x << lshift) | (x >> rshift);
 }
 
@@ -22,15 +20,14 @@ enum { R1 = 32, R2 = 24, R3 = 16, R4 = 63 };
 
 /* RFC 7693 section 2.6 */
 static const uint64_t iv[] = {
-    // WINSCP (ULL)
-    0x6a09e667f3bcc908ULL,                /* floor(2^64 * frac(sqrt(2)))  */
-    0xbb67ae8584caa73bULL,                /* floor(2^64 * frac(sqrt(3)))  */
-    0x3c6ef372fe94f82bULL,                /* floor(2^64 * frac(sqrt(5)))  */
-    0xa54ff53a5f1d36f1ULL,                /* floor(2^64 * frac(sqrt(7)))  */
-    0x510e527fade682d1ULL,                /* floor(2^64 * frac(sqrt(11))) */
-    0x9b05688c2b3e6c1fULL,                /* floor(2^64 * frac(sqrt(13))) */
-    0x1f83d9abfb41bd6bULL,                /* floor(2^64 * frac(sqrt(17))) */
-    0x5be0cd19137e2179ULL,                /* floor(2^64 * frac(sqrt(19))) */
+    0x6a09e667f3bcc908,                /* floor(2^64 * frac(sqrt(2)))  */
+    0xbb67ae8584caa73b,                /* floor(2^64 * frac(sqrt(3)))  */
+    0x3c6ef372fe94f82b,                /* floor(2^64 * frac(sqrt(5)))  */
+    0xa54ff53a5f1d36f1,                /* floor(2^64 * frac(sqrt(7)))  */
+    0x510e527fade682d1,                /* floor(2^64 * frac(sqrt(11))) */
+    0x9b05688c2b3e6c1f,                /* floor(2^64 * frac(sqrt(13))) */
+    0x1f83d9abfb41bd6b,                /* floor(2^64 * frac(sqrt(17))) */
+    0x5be0cd19137e2179,                /* floor(2^64 * frac(sqrt(19))) */
 };
 
 /* RFC 7693 section 2.7 */
@@ -78,9 +75,7 @@ static inline void f(uint64_t h[8], uint64_t m[16], uint64_t offset_hi,
     v[12] ^= offset_lo;
     v[13] ^= offset_hi;
     v[14] ^= -(uint64_t)final;
-    { // WINSCP
-    unsigned round; // WINSCP
-    for (round = 0; round < 12; round++) {
+    for (unsigned round = 0; round < 12; round++) {
         const unsigned char *s = sigma[round];
         g(v,  0,  4,  8, 12, m[s[ 0]], m[s[ 1]]);
         g(v,  1,  5,  9, 13, m[s[ 2]], m[s[ 3]]);
@@ -91,21 +86,16 @@ static inline void f(uint64_t h[8], uint64_t m[16], uint64_t offset_hi,
         g(v,  2,  7,  8, 13, m[s[12]], m[s[13]]);
         g(v,  3,  4,  9, 14, m[s[14]], m[s[15]]);
     }
-    { // WINSCP
-    unsigned i; // WINSCP
-    for (i = 0; i < 8; i++)
+    for (unsigned i = 0; i < 8; i++)
         h[i] ^= v[i] ^ v[i+8];
     smemclr(v, sizeof(v));
-    } // WINSCP
-    } // WINSCP
 }
 
 static inline void f_outer(uint64_t h[8], uint8_t blk[128], uint64_t offset_hi,
                            uint64_t offset_lo, unsigned final)
 {
     uint64_t m[16];
-    unsigned i; // WINSCP
-    for (i = 0; i < 16; i++)
+    for (unsigned i = 0; i < 16; i++)
         m[i] = GET_64BIT_LSB_FIRST(blk + 8*i);
     f(h, m, offset_hi, offset_lo, final);
     smemclr(m, sizeof(m));
@@ -129,14 +119,12 @@ static ssh_hash *blake2b_new_inner(unsigned hashlen)
 {
     assert(hashlen <= ssh_blake2b.hlen);
 
-    { // WINSCP
     blake2b *s = snew(blake2b);
     s->hash.vt = &ssh_blake2b;
     s->hashlen = hashlen;
     BinarySink_INIT(s, blake2b_write);
     BinarySink_DELEGATE_INIT(&s->hash, s);
     return &s->hash;
-    } // WINSCP
 }
 
 static ssh_hash *blake2b_new(const ssh_hashalg *alg)
@@ -195,7 +183,6 @@ static void blake2b_write(BinarySink *bs, const void *vp, size_t len)
             s->used = 0;
         }
 
-        { // WINSCP
         size_t chunk = sizeof(s->block) - s->used;
         if (chunk > len)
             chunk = len;
@@ -207,7 +194,6 @@ static void blake2b_write(BinarySink *bs, const void *vp, size_t len)
 
         s->lenlo += chunk;
         s->lenhi += (s->lenlo < chunk);
-        } // WINSCP
     }
 }
 
@@ -218,25 +204,20 @@ static void blake2b_digest(ssh_hash *hash, uint8_t *digest)
     memset(s->block + s->used, 0, sizeof(s->block) - s->used);
     f_outer(s->h, s->block, s->lenhi, s->lenlo, 1);
 
-    { // WINSCP
     uint8_t hash_pre[128];
-    unsigned i; // WINSCP
-    for (i = 0; i < 8; i++)
+    for (unsigned i = 0; i < 8; i++)
         PUT_64BIT_LSB_FIRST(hash_pre + 8*i, s->h[i]);
     memcpy(digest, hash_pre, s->hashlen);
     smemclr(hash_pre, sizeof(hash_pre));
-    } // WINSCP
 }
 
 const ssh_hashalg ssh_blake2b = {
-    // WINSCP
-    /*.new =*/ blake2b_new,
-    /*.reset =*/ blake2b_reset,
-    /*.copyfrom =*/ blake2b_copyfrom,
-    /*.digest =*/ blake2b_digest,
-    /*.free =*/ blake2b_free,
-    /*.hlen =*/ 64,
-    /*.blocklen =*/ 128,
+    .new = blake2b_new,
+    .reset = blake2b_reset,
+    .copyfrom = blake2b_copyfrom,
+    .digest = blake2b_digest,
+    .free = blake2b_free,
+    .hlen = 64,
+    .blocklen = 128,
     HASHALG_NAMES_BARE("BLAKE2b-64"),
-    NULL, // WINSCP
 };

+ 34 - 62
source/putty/sshsha3.c

@@ -9,9 +9,7 @@
 static inline uint64_t rol(uint64_t x, unsigned shift)
 {
     unsigned L = (+shift) & 63;
-#pragma option push -w-ngu // WINSCP
     unsigned R = (-shift) & 63;
-#pragma option pop // WINSCP
     return (x << L) | (x >> R);
 }
 
@@ -39,36 +37,25 @@ static void keccak_transform(keccak_core_state A)
         uint64_t B[5][5];
     } u;
 
-    unsigned round; // WINSCP
-    for (round = 0; round < NROUNDS; round++) {
+    for (unsigned round = 0; round < NROUNDS; round++) {
         /* theta step */
-        unsigned x; // WINSCP
-        for (x = 0; x < 5; x++)
+        for (unsigned x = 0; x < 5; x++)
             u.C[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4];
-        for (x = 0; x < 5; x++) { // WINSCP
+        for (unsigned x = 0; x < 5; x++) {
             uint64_t D = rol(u.C[(x+1) % 5], 1) ^ u.C[(x+4) % 5];
-            { // WINSCP
-            unsigned y; // WINSCP
-            for (y = 0; y < 5; y++)
+            for (unsigned y = 0; y < 5; y++)
                 A[x][y] ^= D;
-            } // WINSCP
         }
 
         /* rho and pi steps */
-        for (x = 0; x < 5; x++) // WINSCP
-        { // WINSCP
-            unsigned y; // WINSCP
-            for (y = 0; y < 5; y++)
+        for (unsigned x = 0; x < 5; x++)
+            for (unsigned y = 0; y < 5; y++)
                 u.B[y][(2*x+3*y) % 5] = rol(A[x][y], rotation_counts[x][y]);
-        } // WINSCP
 
         /* chi step */
-        for (x = 0; x < 5; x++) // WINSCP
-        { // WINSCP
-            unsigned y; // WINSCP
-            for (y = 0; y < 5; y++)
+        for (unsigned x = 0; x < 5; x++)
+            for (unsigned y = 0; y < 5; y++)
                 A[x][y] = u.B[x][y] ^ (u.B[(x+2)%5][y] & ~u.B[(x+1)%5][y]);
-        } // WINSCP
 
         /* iota step */
         A[0][0] ^= round_constants[round];
@@ -98,12 +85,9 @@ static void keccak_accumulate(keccak_state *s, const void *vdata, size_t len)
         len -= b;
         data += b;
 
-        { // WINSCP
         size_t n = 0;
-        unsigned y; // WINSCP
-        for (y = 0; y < 5; y++) {
-            unsigned x; // WINSCP
-            for (x = 0; x < 5; x++) {
+        for (unsigned y = 0; y < 5; y++) {
+            for (unsigned x = 0; x < 5; x++) {
                 if (n >= s->bytes_wanted)
                     break;
 
@@ -114,7 +98,6 @@ static void keccak_accumulate(keccak_state *s, const void *vdata, size_t len)
         keccak_transform(s->A);
 
         s->bytes_got = 0;
-        } // WINSCP
     }
 
     memcpy(s->bytes + s->bytes_got, data, len);
@@ -142,26 +125,20 @@ static void keccak_output(keccak_state *s, void *voutput)
         keccak_accumulate(s, padding, len);
     }
 
-    { // WINSCP
     size_t n = 0;
-    unsigned y; // WINSCP
-    for (y = 0; y < 5; y++) {
-        unsigned x; // WINSCP
-        for (x = 0; x < 5; x++) {
+    for (unsigned y = 0; y < 5; y++) {
+        for (unsigned x = 0; x < 5; x++) {
             size_t to_copy = s->hash_bytes - n;
             if (to_copy == 0)
                 break;
             if (to_copy > 8)
                 to_copy = 8;
-            { // WINSCP
             unsigned char outbytes[8];
             PUT_64BIT_LSB_FIRST(outbytes, s->A[x][y]);
             memcpy(output + n, outbytes, to_copy);
             n += to_copy;
-            } // WINSCP
         }
     }
-    } // WINSCP
 }
 
 static void keccak_init(keccak_state *s, unsigned hashbits, unsigned ratebits,
@@ -217,15 +194,14 @@ print(textwrap.indent("\n".join(textwrap.wrap(", ".join(
 */
 
 static const uint64_t round_constants[24] = {
-    // WINSCP (ULL)
-    0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL,
-    0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL,
-    0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL,
-    0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL,
-    0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL,
-    0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL,
-    0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL,
-    0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL
+    0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
+    0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
+    0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
+    0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
+    0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
+    0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
+    0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
+    0x8000000000008080, 0x0000000080000001, 0x8000000080008008
 };
 
 /*
@@ -306,16 +282,14 @@ static void sha3_reset(ssh_hash *hash)
 
 #define DEFINE_SHA3(bits)                       \
     const ssh_hashalg ssh_sha3_##bits = {       \
-        /* WINSCP */ \
-        /*.new =*/ keccak_new,                      \
-        /*.reset =*/ sha3_reset,                    \
-        /*.copyfrom =*/ keccak_copyfrom,            \
-        /*.digest =*/ keccak_digest,                \
-        /*.free =*/ keccak_free,                    \
-        /*.hlen =*/ bits/8,                         \
-        /*.blocklen =*/ 200 - 2*(bits/8),           \
+        .new = keccak_new,                      \
+        .reset = sha3_reset,                    \
+        .copyfrom = keccak_copyfrom,            \
+        .digest = keccak_digest,                \
+        .free = keccak_free,                    \
+        .hlen = bits/8,                         \
+        .blocklen = 200 - 2*(bits/8),           \
         HASHALG_NAMES_BARE("SHA3-" #bits),      \
-        NULL, /* WINSCP */ \
     }
 
 DEFINE_SHA3(224);
@@ -342,16 +316,14 @@ static void shake256_reset(ssh_hash *hash)
 
 #define DEFINE_SHAKE(param, hashbytes)                          \
     const ssh_hashalg ssh_shake##param##_##hashbytes##bytes = { \
-        /* WINSCP */ \
-        /*.new =*/ keccak_new,                                      \
-        /*.reset =*/ shake##param##_reset,                          \
-        /*.copyfrom =*/ keccak_copyfrom,                            \
-        /*.digest =*/ keccak_digest,                                \
-        /*.free =*/ keccak_free,                                    \
-        /*.hlen =*/ hashbytes,                                      \
-        /*.blocklen =*/ 0,                                          \
+        .new = keccak_new,                                      \
+        .reset = shake##param##_reset,                          \
+        .copyfrom = keccak_copyfrom,                            \
+        .digest = keccak_digest,                                \
+        .free = keccak_free,                                    \
+        .hlen = hashbytes,                                      \
+        .blocklen = 0,                                          \
         HASHALG_NAMES_BARE("SHAKE" #param),                     \
-        NULL, /*NULL*/ \
     }
 
 DEFINE_SHAKE(256, 114);