mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto: remove extraneous casts & rename rand_lin to rand_linux
This commit is contained in:
parent
dd61a22367
commit
2897bac549
@ -154,7 +154,7 @@ fn subw(w u32) u32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rotate
|
// 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.
|
// Key expansion algorithm. See FIPS-197, Figure 11.
|
||||||
// Their rcon[i] is our powx[i-1] << 24.
|
// Their rcon[i] is our powx[i-1] << 24.
|
||||||
|
@ -23,7 +23,7 @@ module aes
|
|||||||
// Reducing mod poly corresponds to binary xor with poly every
|
// Reducing mod poly corresponds to binary xor with poly every
|
||||||
// time a 0x100 bit appears.
|
// time a 0x100 bit appears.
|
||||||
const (
|
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).
|
// Powers of x mod poly in GF(2).
|
||||||
|
@ -107,7 +107,7 @@ pub fn (d mut Digest) checksum() []byte {
|
|||||||
// tmp := [1 + 63 + 8]byte{0x80}
|
// tmp := [1 + 63 + 8]byte{0x80}
|
||||||
mut tmp := [byte(0)].repeat(1 + 63 + 8)
|
mut tmp := [byte(0)].repeat(1 + 63 + 8)
|
||||||
tmp[0] = 0x80
|
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
|
binary.little_endian_put_u64(mut tmp[1+pad..], d.len<<u64(3)) // append length in bits
|
||||||
d.write(tmp[..1+pad+8])
|
d.write(tmp[..1+pad+8])
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ fn bytes_to_u64(b []byte) []u64 {
|
|||||||
if i > 0 {
|
if i > 0 {
|
||||||
mut d := u64(0)
|
mut d := u64(0)
|
||||||
for s := u64(0); i > 0; s += u64(8) {
|
for s := u64(0); i > 0; s += u64(8) {
|
||||||
d |= u64(u64(b[i-1]) << s)
|
d |= u64(b[i-1]) << s
|
||||||
i--
|
i--
|
||||||
}
|
}
|
||||||
z[z.len-1] = d
|
z[z.len-1] = d
|
||||||
|
@ -37,7 +37,7 @@ pub fn new_cipher(key []byte) ?Cipher {
|
|||||||
}
|
}
|
||||||
mut j := byte(0)
|
mut j := byte(0)
|
||||||
for i := 0; i < 256; i++ {
|
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]
|
tmp := c.s[i]
|
||||||
c.s[i] = c.s[j]
|
c.s[i] = c.s[j]
|
||||||
c.s[j] = tmp
|
c.s[j] = tmp
|
||||||
|
@ -55,7 +55,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
|||||||
}
|
}
|
||||||
for i < 20 {
|
for i < 20 {
|
||||||
tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf]
|
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
|
f := b&c | (~b)&d
|
||||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k0)
|
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k0)
|
||||||
e = d
|
e = d
|
||||||
@ -67,7 +67,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
|||||||
}
|
}
|
||||||
for i < 40 {
|
for i < 40 {
|
||||||
tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf]
|
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
|
f := b ^ c ^ d
|
||||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k1)
|
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k1)
|
||||||
e = d
|
e = d
|
||||||
@ -79,7 +79,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
|||||||
}
|
}
|
||||||
for i < 60 {
|
for i < 60 {
|
||||||
tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf]
|
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)
|
f := ((b | c) & d) | (b & c)
|
||||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k2)
|
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k2)
|
||||||
e = d
|
e = d
|
||||||
@ -91,7 +91,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
|||||||
}
|
}
|
||||||
for i < 80 {
|
for i < 80 {
|
||||||
tmp := w[(i-3)&0xf] ^ w[(i-8)&0xf] ^ w[(i-14)&0xf] ^ w[(i)&0xf]
|
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
|
f := b ^ c ^ d
|
||||||
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k3)
|
t := bits.rotate_left_32(a, 5) + f + e + w[i&0xf] + u32(_k3)
|
||||||
e = d
|
e = d
|
||||||
|
@ -107,7 +107,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
|
|||||||
for p.len >= Chunk {
|
for p.len >= Chunk {
|
||||||
for i := 0; i < 16; i++ {
|
for i := 0; i < 16; i++ {
|
||||||
j := i * 8
|
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++ {
|
for i := 16; i < 80; i++ {
|
||||||
v1 := w[i - 2]
|
v1 := w[i - 2]
|
||||||
|
Loading…
Reference in New Issue
Block a user