From 2897bac54977591e010cff8c9904debb479dc169 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Fri, 24 Jan 2020 08:49:13 +1100 Subject: [PATCH] crypto: remove extraneous casts & rename rand_lin to rand_linux --- vlib/crypto/aes/block_generic.v | 2 +- vlib/crypto/aes/const.v | 2 +- vlib/crypto/md5/md5.v | 2 +- vlib/crypto/rand/{rand_lin.v => rand_linux.v} | 0 vlib/crypto/rand/utils.v | 2 +- vlib/crypto/rc4/rc4.v | 2 +- vlib/crypto/sha1/sha1block_generic.v | 8 ++++---- vlib/crypto/sha512/sha512block_generic.v | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename vlib/crypto/rand/{rand_lin.v => rand_linux.v} (100%) diff --git a/vlib/crypto/aes/block_generic.v b/vlib/crypto/aes/block_generic.v index b921501eb8..0f1706bce0 100644 --- a/vlib/crypto/aes/block_generic.v +++ b/vlib/crypto/aes/block_generic.v @@ -154,7 +154,7 @@ fn subw(w u32) u32 { } // Rotate -fn rotw(w u32) u32 { return u32(w<<8) | u32(w>>24) } +fn rotw(w u32) u32 { return (w<<8) | (w>>24) } // Key expansion algorithm. See FIPS-197, Figure 11. // Their rcon[i] is our powx[i-1] << 24. diff --git a/vlib/crypto/aes/const.v b/vlib/crypto/aes/const.v index fc0c26d8c6..f3dc076532 100644 --- a/vlib/crypto/aes/const.v +++ b/vlib/crypto/aes/const.v @@ -23,7 +23,7 @@ module aes // Reducing mod poly corresponds to binary xor with poly every // time a 0x100 bit appears. const ( - poly = int(1<<8) | int(1<<4) | int(1<<3) | int(1<<1) | int(1<<0) // x⁸ + x⁴ + x³ + x + 1 + poly = (1<<8) | (1<<4) | (1<<3) | (1<<1) | (1<<0) // x⁸ + x⁴ + x³ + x + 1 ) // Powers of x mod poly in GF(2). diff --git a/vlib/crypto/md5/md5.v b/vlib/crypto/md5/md5.v index b47c453f65..1d90da7d12 100644 --- a/vlib/crypto/md5/md5.v +++ b/vlib/crypto/md5/md5.v @@ -107,7 +107,7 @@ pub fn (d mut Digest) checksum() []byte { // tmp := [1 + 63 + 8]byte{0x80} mut tmp := [byte(0)].repeat(1 + 63 + 8) tmp[0] = 0x80 - pad := int((55 - int(d.len)) % u64(64)) // calculate number of padding bytes + pad := ((55 - int(d.len)) % u64(64)) // calculate number of padding bytes binary.little_endian_put_u64(mut tmp[1+pad..], d.len< 0 { mut d := u64(0) for s := u64(0); i > 0; s += u64(8) { - d |= u64(u64(b[i-1]) << s) + d |= u64(b[i-1]) << s i-- } z[z.len-1] = d diff --git a/vlib/crypto/rc4/rc4.v b/vlib/crypto/rc4/rc4.v index 22873db0a4..3d318e105a 100644 --- a/vlib/crypto/rc4/rc4.v +++ b/vlib/crypto/rc4/rc4.v @@ -37,7 +37,7 @@ pub fn new_cipher(key []byte) ?Cipher { } mut j := byte(0) for i := 0; i < 256; i++ { - j += byte(c.s[i]) + byte(key[i%key.len]) + j += byte(c.s[i]) + key[i%key.len] tmp := c.s[i] c.s[i] = c.s[j] c.s[j] = tmp diff --git a/vlib/crypto/sha1/sha1block_generic.v b/vlib/crypto/sha1/sha1block_generic.v index 33cf25ded2..d21d6d1826 100644 --- a/vlib/crypto/sha1/sha1block_generic.v +++ b/vlib/crypto/sha1/sha1block_generic.v @@ -55,7 +55,7 @@ fn block_generic(dig mut Digest, p_ []byte) { } for i < 20 { tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] - w[i&0xf] = tmp<<1 | u32(tmp>>(32-1)) + w[i&0xf] = tmp<<1 | (tmp>>(32-1)) f := b&c | (~b)&d t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k0) e = d @@ -67,7 +67,7 @@ fn block_generic(dig mut Digest, p_ []byte) { } for i < 40 { tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] - w[i&0xf] = tmp<<1 | u32(tmp>>(32-1)) + w[i&0xf] = tmp<<1 | (tmp>>(32-1)) f := b ^ c ^ d t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k1) e = d @@ -79,7 +79,7 @@ fn block_generic(dig mut Digest, p_ []byte) { } for i < 60 { tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] - w[i&0xf] = tmp<<1 | u32(tmp>>(32-1)) + w[i&0xf] = tmp<<1 | (tmp>>(32-1)) f := ((b | c) & d) | (b & c) t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k2) e = d @@ -91,7 +91,7 @@ fn block_generic(dig mut Digest, p_ []byte) { } for i < 80 { tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf] - w[i&0xf] = tmp<<1 | u32(tmp>>(32-1)) + w[i&0xf] = tmp<<1 | (tmp>>(32-1)) f := b ^ c ^ d t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k3) e = d diff --git a/vlib/crypto/sha512/sha512block_generic.v b/vlib/crypto/sha512/sha512block_generic.v index 8f77167906..8a7a4ac9a7 100644 --- a/vlib/crypto/sha512/sha512block_generic.v +++ b/vlib/crypto/sha512/sha512block_generic.v @@ -107,7 +107,7 @@ fn block_generic(dig mut Digest, p_ []byte) { for p.len >= Chunk { for i := 0; i < 16; i++ { j := i * 8 - w[i] = ((u64(p[j])<<56) | (u64(p[j + 1])<<48) | (u64(p[j + 2])<<40) | (u64(p[j + 3])<<32) | (u64(p[j + 4])<<24) | (u64(p[j + 5])<<16) | (u64(p[j + 6])<<8) | (p[j + 7])) + w[i] = (u64(p[j])<<56) | (u64(p[j + 1])<<48) | (u64(p[j + 2])<<40) | (u64(p[j + 3])<<32) | (u64(p[j + 4])<<24) | (u64(p[j + 5])<<16) | (u64(p[j + 6])<<8) | u64(p[j + 7]) } for i := 16; i < 80; i++ { v1 := w[i - 2]