1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

lower/snake case consts & enums

This commit is contained in:
joe-conigliaro
2019-10-24 22:48:20 +11:00
committed by Alexander Medvednikov
parent fe17dd9a7e
commit 580abe0de4
20 changed files with 301 additions and 308 deletions

View File

@@ -16,18 +16,18 @@ import encoding.binary
const(
// The size of a SHA-1 checksum in bytes.
Size = 20
size = 20
// The blocksize of SHA-1 in bytes.
BlockSize = 64
block_size = 64
)
const (
Chunk = 64
Init0 = 0x67452301
Init1 = 0xEFCDAB89
Init2 = 0x98BADCFE
Init3 = 0x10325476
Init4 = 0xC3D2E1F0
chunk = 64
init0 = 0x67452301
init1 = 0xEFCDAB89
init2 = 0x98BADCFE
init3 = 0x10325476
init4 = 0xC3D2E1F0
)
// digest represents the partial evaluation of a checksum.
@@ -40,13 +40,13 @@ mut:
}
fn (d mut Digest) reset() {
d.x = [byte(0)].repeat(Chunk)
d.x = [byte(0)].repeat(chunk)
d.h = [u32(0)].repeat(5)
d.h[0] = u32(Init0)
d.h[1] = u32(Init1)
d.h[2] = u32(Init2)
d.h[3] = u32(Init3)
d.h[4] = u32(Init4)
d.h[0] = u32(init0)
d.h[1] = u32(init1)
d.h[2] = u32(init2)
d.h[3] = u32(init3)
d.h[4] = u32(init4)
d.nx = 0
d.len = 0
}
@@ -66,7 +66,7 @@ pub fn (d mut Digest) write(p_ []byte) ?int {
if d.nx > 0 {
n := copy(d.x.right(d.nx), p)
d.nx += n
if d.nx == Chunk {
if d.nx == chunk {
block(d, d.x)
d.nx = 0
}
@@ -76,8 +76,8 @@ pub fn (d mut Digest) write(p_ []byte) ?int {
p = p.right(n)
}
}
if p.len >= Chunk {
n := p.len &~ (Chunk - 1)
if p.len >= chunk {
n := p.len &~ (chunk - 1)
block(d, p.left(n))
if n >= p.len {
p = []byte
@@ -120,7 +120,7 @@ fn (d mut Digest) checksum() []byte {
binary.big_endian_put_u64(mut tmp, len)
d.write(tmp.left(8))
mut digest := [byte(0)].repeat(Size)
mut digest := [byte(0)].repeat(size)
binary.big_endian_put_u32(mut digest, d.h[0])
binary.big_endian_put_u32(mut digest.right(4), d.h[1])
@@ -144,8 +144,8 @@ fn block(dig &Digest, p []byte) {
block_generic(mut dig, p)
}
pub fn (d &Digest) size() int { return Size }
pub fn (d &Digest) size() int { return size }
pub fn (d &Digest) block_size() int { return BlockSize }
pub fn (d &Digest) block_size() int { return block_size }
pub fn hexhash(s string) string { return sum(s.bytes()).hex() }

View File

@@ -11,10 +11,10 @@ module sha1
import math.bits
const (
_K0 = 0x5A827999
_K1 = 0x6ED9EBA1
_K2 = 0x8F1BBCDC
_K3 = 0xCA62C1D6
_k0 = 0x5A827999
_k1 = 0x6ED9EBA1
_k2 = 0x8F1BBCDC
_k3 = 0xCA62C1D6
)
fn block_generic(dig mut Digest, p_ []byte) {
@@ -25,7 +25,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
mut h2 := dig.h[2]
mut h3 := dig.h[3]
mut h4 := dig.h[4]
for p.len >= Chunk {
for p.len >= chunk {
// Can interlace the computation of w with the
// rounds below if needed for speed.
for i := 0; i < 16; i++ {
@@ -41,11 +41,11 @@ fn block_generic(dig mut Digest, p_ []byte) {
// Each of the four 20-iteration rounds
// differs only in the computation of f and
// the choice of K (_K0, _K1, etc).
// the choice of K (_k0, _k1, etc).
mut i := 0
for i < 16 {
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
d = c
c = bits.rotate_left_32(b, 30)
@@ -57,7 +57,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
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))
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
d = c
c = bits.rotate_left_32(b, 30)
@@ -69,7 +69,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
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))
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
d = c
c = bits.rotate_left_32(b, 30)
@@ -81,7 +81,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
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))
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
d = c
c = bits.rotate_left_32(b, 30)
@@ -93,7 +93,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
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))
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
d = c
c = bits.rotate_left_32(b, 30)
@@ -108,10 +108,10 @@ fn block_generic(dig mut Digest, p_ []byte) {
h3 += d
h4 += e
if Chunk >= p.len {
if chunk >= p.len {
p = []byte
} else {
p = p.right(Chunk)
p = p.right(chunk)
}
}