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

sha512: make it work with the new parser

This commit is contained in:
Alexander Medvednikov 2020-03-10 15:47:18 +01:00
parent bc184a9f02
commit 324a48bc64
3 changed files with 9 additions and 9 deletions

View File

@ -126,7 +126,7 @@ pub fn cmp(a Number, b Number) int {
return C.bignum_cmp(&a,&b)
}
pub fn (a Number) is_zero() bool {
return int(C.bignum_is_zero(&a)) != 0
return C.bignum_is_zero(&a) != 0
}
pub fn (a mut Number) inc() {
C.bignum_inc(a)

View File

@ -27,7 +27,7 @@ pub const (
)
const (
Chunk = 128
chunk = 128
init0 = 0x6a09e667f3bcc908
init1 = 0xbb67ae8584caa73b
init2 = 0x3c6ef372fe94f82b
@ -73,7 +73,7 @@ mut:
fn (d mut Digest) reset() {
d.h = [u64(0)].repeat(8)
d.x = [byte(0)].repeat(Chunk)
d.x = [byte(0)].repeat(chunk)
match d.function {
.sha384 {
d.h[0] = init0_384
@ -155,7 +155,7 @@ fn (d mut Digest) write(p_ []byte) int {
if d.nx > 0 {
n := copy(d.x[d.nx..], p)
d.nx += n
if d.nx == Chunk {
if d.nx == chunk{
block(mut d, d.x)
d.nx = 0
}
@ -166,8 +166,8 @@ fn (d mut Digest) write(p_ []byte) int {
p = p[n..]
}
}
if p.len >= Chunk {
n := p.len & ~(Chunk - 1)
if p.len >= chunk{
n := p.len & ~(chunk- 1)
block(mut d, p[..n])
if n >= p.len {
p = []

View File

@ -104,7 +104,7 @@ fn block_generic(dig mut Digest, p_ []byte) {
mut h5 := dig.h[5]
mut h6 := dig.h[6]
mut h7 := dig.h[7]
for p.len >= Chunk {
for p.len >= chunk {
for i in 0..16 {
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) | u64(p[j + 7])
@ -144,11 +144,11 @@ fn block_generic(dig mut Digest, p_ []byte) {
h5 += f
h6 += g
h7 += h
if Chunk >= p.len {
if chunk >= p.len {
p = []
}
else {
p = p[Chunk..]
p = p[chunk..]
}
}
dig.h[0] = h0