|
|
@@ -125,11 +125,14 @@ static inline void sha1_block_pad(sha1_block *blk, BinarySink *bs)
|
|
|
size_t pad = 1 + (63 & (55 - blk->used));
|
|
|
|
|
|
put_byte(bs, 0x80);
|
|
|
- for (size_t i = 1; i < pad; i++)
|
|
|
+ { // WINSCP
|
|
|
+ size_t i;
|
|
|
+ for (i = 1; i < pad; i++)
|
|
|
put_byte(bs, 0);
|
|
|
put_uint64(bs, final_len);
|
|
|
|
|
|
assert(blk->used == 0 && "Should have exactly hit a block boundary");
|
|
|
+ } // WINSCP
|
|
|
}
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
@@ -138,7 +141,7 @@ static inline void sha1_block_pad(sha1_block *blk, BinarySink *bs)
|
|
|
|
|
|
static inline uint32_t rol(uint32_t x, unsigned y)
|
|
|
{
|
|
|
- return (x << (31 & y)) | (x >> (31 & -y));
|
|
|
+ return (x << (31 & y)) | (x >> (31 & (uint32_t)(-(int32_t)y))); // WINSCP
|
|
|
}
|
|
|
|
|
|
static inline uint32_t Ch(uint32_t ctrl, uint32_t if1, uint32_t if0)
|
|
|
@@ -170,38 +173,41 @@ static void sha1_sw_block(uint32_t *core, const uint8_t *block)
|
|
|
uint32_t w[SHA1_ROUNDS];
|
|
|
uint32_t a,b,c,d,e;
|
|
|
|
|
|
- for (size_t t = 0; t < 16; t++)
|
|
|
+ size_t t; // WINSCP
|
|
|
+ for (t = 0; t < 16; t++)
|
|
|
w[t] = GET_32BIT_MSB_FIRST(block + 4*t);
|
|
|
|
|
|
- for (size_t t = 16; t < SHA1_ROUNDS; t++)
|
|
|
+ for (t = 16; t < SHA1_ROUNDS; t++) // WINSCP
|
|
|
w[t] = rol(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1);
|
|
|
|
|
|
a = core[0]; b = core[1]; c = core[2]; d = core[3];
|
|
|
e = core[4];
|
|
|
|
|
|
- size_t t = 0;
|
|
|
- for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
+ t = 0;
|
|
|
+ { // WINSCP
|
|
|
+ size_t u; // WINSCP
|
|
|
+ for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Ch(b,c,d), SHA1_STAGE0_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Ch(a,b,c), SHA1_STAGE0_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Ch(e,a,b), SHA1_STAGE0_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Ch(d,e,a), SHA1_STAGE0_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Ch(c,d,e), SHA1_STAGE0_CONSTANT);
|
|
|
}
|
|
|
- for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
+ for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Par(b,c,d), SHA1_STAGE1_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Par(a,b,c), SHA1_STAGE1_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Par(e,a,b), SHA1_STAGE1_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Par(d,e,a), SHA1_STAGE1_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Par(c,d,e), SHA1_STAGE1_CONSTANT);
|
|
|
}
|
|
|
- for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
+ for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Maj(b,c,d), SHA1_STAGE2_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Maj(a,b,c), SHA1_STAGE2_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Maj(e,a,b), SHA1_STAGE2_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &c,&d,&e,&a,&b, Maj(d,e,a), SHA1_STAGE2_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &b,&c,&d,&e,&a, Maj(c,d,e), SHA1_STAGE2_CONSTANT);
|
|
|
}
|
|
|
- for (size_t u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
+ for (u = 0; u < SHA1_ROUNDS_PER_STAGE/5; u++) {
|
|
|
sha1_sw_round(t++,w, &a,&b,&c,&d,&e, Par(b,c,d), SHA1_STAGE3_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &e,&a,&b,&c,&d, Par(a,b,c), SHA1_STAGE3_CONSTANT);
|
|
|
sha1_sw_round(t++,w, &d,&e,&a,&b,&c, Par(e,a,b), SHA1_STAGE3_CONSTANT);
|
|
|
@@ -212,6 +218,7 @@ static void sha1_sw_block(uint32_t *core, const uint8_t *block)
|
|
|
core[0] += a; core[1] += b; core[2] += c; core[3] += d; core[4] += e;
|
|
|
|
|
|
smemclr(w, sizeof(w));
|
|
|
+ } // WINSCP
|
|
|
}
|
|
|
|
|
|
typedef struct sha1_sw {
|
|
|
@@ -271,9 +278,12 @@ static void sha1_sw_final(ssh_hash *hash, uint8_t *digest)
|
|
|
sha1_sw *s = container_of(hash, sha1_sw, hash);
|
|
|
|
|
|
sha1_block_pad(&s->blk, BinarySink_UPCAST(s));
|
|
|
- for (size_t i = 0; i < 5; i++)
|
|
|
+ { // WINSCP
|
|
|
+ size_t i; // WINSCP
|
|
|
+ for (i = 0; i < 5; i++)
|
|
|
PUT_32BIT_MSB_FIRST(digest + 4*i, s->core[i]);
|
|
|
sha1_sw_free(hash);
|
|
|
+ } // WINSCP
|
|
|
}
|
|
|
|
|
|
const ssh_hashalg ssh_sha1_sw = {
|