mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto.[md5/rc4/sha1]: remove extraneous casts
This commit is contained in:
parent
f1f720cc78
commit
c069525e8c
@ -45,7 +45,7 @@ fn (d mut Digest) reset() {
|
||||
d.s[2] = u32(Init2)
|
||||
d.s[3] = u32(Init3)
|
||||
d.nx = 0
|
||||
d.len = u64(0)
|
||||
d.len = 0
|
||||
}
|
||||
|
||||
// new returns a new Digest (implementing hash.Hash) computing the MD5 checksum.
|
||||
@ -104,10 +104,10 @@ pub fn (d mut Digest) checksum() []byte {
|
||||
//
|
||||
// 1 byte end marker :: 0-63 padding bytes :: 8 byte length
|
||||
// tmp := [1 + 63 + 8]byte{0x80}
|
||||
mut tmp := [byte(0); 1 + 63 + 8]
|
||||
mut tmp := [byte(0)].repeat(1 + 63 + 8)
|
||||
tmp[0] = 0x80
|
||||
pad := (55 - int(d.len)) % 64 // calculate number of padding bytes
|
||||
binary.little_endian_put_u64(mut tmp.right(1+pad), u64(d.len<<u64(3))) // append length in bits
|
||||
binary.little_endian_put_u64(mut tmp.right(1+pad), d.len<<u64(3)) // append length in bits
|
||||
d.write(tmp.left(1+pad+8))
|
||||
|
||||
// The previous write ensures that a whole number of
|
||||
|
@ -51,10 +51,10 @@ pub fn new_cipher(key []byte) ?Cipher {
|
||||
// the process's memory.
|
||||
pub fn (c mut Cipher) reset() {
|
||||
for i in c.s {
|
||||
c.s[i] = u32(0)
|
||||
c.s[i] = 0
|
||||
}
|
||||
c.i = byte(0)
|
||||
c.j = byte(0)
|
||||
c.i = 0
|
||||
c.j = 0
|
||||
}
|
||||
|
||||
// xor_key_stream sets dst to the result of XORing src with the key stream.
|
||||
|
@ -48,7 +48,7 @@ fn (d mut Digest) reset() {
|
||||
d.h[3] = u32(Init3)
|
||||
d.h[4] = u32(Init4)
|
||||
d.nx = 0
|
||||
d.len = u64(0)
|
||||
d.len = 0
|
||||
}
|
||||
|
||||
// new returns a new Digest (implementing hash.Hash) computing the SHA1 checksum.
|
||||
@ -115,7 +115,7 @@ fn (d mut Digest) checksum() []byte {
|
||||
}
|
||||
|
||||
// Length in bits.
|
||||
len <<= u64(3)
|
||||
len <<= 3
|
||||
binary.big_endian_put_u64(mut tmp, len)
|
||||
d.write(tmp.left(8))
|
||||
|
||||
|
@ -30,7 +30,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
||||
// rounds below if needed for speed.
|
||||
for i := 0; i < 16; i++ {
|
||||
j := i * 4
|
||||
w[i] = u32(u32(p[j])<<u32(24)) | u32(u32(p[j+1])<<u32(16)) | u32(u32(p[j+2])<<u32(8)) | u32(u32(p[j+3]))
|
||||
w[i] = u32(p[j]<<24) | u32(p[j+1]<<16) | u32(p[j+2]<<8) | u32(p[j+3])
|
||||
}
|
||||
|
||||
mut a := h0
|
||||
@ -44,7 +44,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
||||
// the choice of K (_K0, _K1, etc).
|
||||
mut i := 0
|
||||
for i < 16 {
|
||||
f := u32(b&c | (~b)&d)
|
||||
f := b&c | (~b)&d
|
||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_K0)
|
||||
e = d
|
||||
d = c
|
||||
@ -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] = u32(tmp<<u32(1)) | u32(tmp>>u32(32-1))
|
||||
w[i&0xf] = tmp<<1 | u32(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] = u32(tmp<<u32(1)) | u32(tmp>>u32(32-1))
|
||||
w[i&0xf] = tmp<<1 | u32(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] = u32(tmp<<u32(1)) | u32(tmp>>u32(32-1))
|
||||
w[i&0xf] = tmp<<1 | u32(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] = u32(tmp<<u32(1)) | u32(tmp>>u32(32-1))
|
||||
w[i&0xf] = tmp<<1 | u32(tmp>>(32-1))
|
||||
f := b ^ c ^ d
|
||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_K3)
|
||||
e = d
|
||||
|
Loading…
Reference in New Issue
Block a user