crypto: remove extraneous casts & rename rand_lin to rand_linux

pull/3554/head
joe-conigliaro 2020-01-24 08:49:13 +11:00 committed by Alexander Medvednikov
parent dd61a22367
commit 2897bac549
8 changed files with 10 additions and 10 deletions

View File

@ -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.

View File

@ -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).

View File

@ -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<<u64(3)) // append length in bits
d.write(tmp[..1+pad+8])

View File

@ -49,7 +49,7 @@ fn bytes_to_u64(b []byte) []u64 {
if i > 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

View File

@ -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

View File

@ -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

View File

@ -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]