mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
crypto.sha512
This commit is contained in:

committed by
Alexander Medvednikov

parent
bdf1717703
commit
55b8a9acb9
@ -48,7 +48,7 @@ fn (d mut Digest) reset() {
|
||||
d.len = u64(0)
|
||||
}
|
||||
|
||||
// New returns a new hash.Hash computing the MD5 checksum.
|
||||
// new returns a new hash.Hash computing the MD5 checksum.
|
||||
pub fn new() *Digest {
|
||||
mut d := &Digest{}
|
||||
d.reset()
|
||||
@ -65,7 +65,7 @@ pub fn (d mut Digest) write(p []byte) ?int {
|
||||
}
|
||||
d.nx += n
|
||||
if d.nx == BlockSize {
|
||||
block_generic(d, d.x)
|
||||
block(d, d.x)
|
||||
d.nx = 0
|
||||
}
|
||||
if n >= p.len {
|
||||
@ -76,7 +76,7 @@ pub fn (d mut Digest) write(p []byte) ?int {
|
||||
}
|
||||
if p.len >= BlockSize {
|
||||
n := p.len &~ (BlockSize - 1)
|
||||
block_generic(d, p.left(n))
|
||||
block(d, p.left(n))
|
||||
if n >= p.len {
|
||||
p = []byte
|
||||
} else {
|
||||
@ -130,14 +130,19 @@ pub fn (d mut Digest) checksum() []byte {
|
||||
return digest
|
||||
}
|
||||
|
||||
// Sum returns the MD5 checksum of the data.
|
||||
// pub fn Sum(data []byte) [Size]byte {
|
||||
// sum returns the MD5 checksum of the data.
|
||||
pub fn sum(data []byte) []byte {
|
||||
mut d := new()
|
||||
d.write(data)
|
||||
return d.checksum()
|
||||
}
|
||||
|
||||
fn block(dig &Digest, p []byte) {
|
||||
// For now just use block_generic until we have specific
|
||||
// architecture optimized versions
|
||||
block_generic(dig, p)
|
||||
}
|
||||
|
||||
pub fn (d &Digest) size() int { return Size }
|
||||
|
||||
pub fn (d &Digest) block_size() int { return BlockSize }
|
@ -2,7 +2,9 @@
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
// This is a generic implementation with no arch optimizations
|
||||
// This is the generic version with no architecture optimizations.
|
||||
// In its own file so that an architecture
|
||||
// optimized verision can be substituted
|
||||
|
||||
module md5
|
||||
|
||||
@ -126,4 +128,4 @@ fn block_generic(dig &Digest, p []byte) {
|
||||
dig.s[1] = b
|
||||
dig.s[2] = c
|
||||
dig.s[3] = d
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user