-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from zuoyebang/dev
v6.0.0
- Loading branch information
Showing
168 changed files
with
5,398 additions
and
4,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
// Copyright 2019-2024 Xu Ruibo ([email protected]) and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package md5hash | ||
|
||
import ( | ||
|
@@ -6,10 +20,10 @@ import ( | |
"hash" | ||
) | ||
|
||
// Size The size of an MD5 checksum in bytes. | ||
// The size of an MD5 checksum in bytes. | ||
const Size = 16 | ||
|
||
// BlockSize The blocksize of MD5 in bytes. | ||
// The blocksize of MD5 in bytes. | ||
const BlockSize = 64 | ||
|
||
const ( | ||
|
@@ -184,10 +198,12 @@ func MD5Hash(data []byte) (h []byte, hi, lo uint64) { | |
} | ||
|
||
//go:inline | ||
func MD5Sum(p []byte) (h []byte, hi, lo uint64) { | ||
var d = digest{s: [4]uint32{init0, init1, init2, init3}} | ||
func MD5Sum(p []byte, h []byte) (hi, lo uint64) { | ||
var d = digest{ | ||
s: [4]uint32{init0, init1, init2, init3}, | ||
len: uint64(len(p)), | ||
} | ||
// Write | ||
d.len += uint64(len(p)) | ||
if d.nx > 0 { | ||
n := copy(d.x[d.nx:], p) | ||
d.nx += n | ||
|
@@ -251,7 +267,6 @@ func MD5Sum(p []byte) (h []byte, hi, lo uint64) { | |
panic("d.nx != 0") | ||
} | ||
|
||
h = make([]byte, Size) | ||
binary.LittleEndian.PutUint32(h[0:], d.s[0]) | ||
binary.LittleEndian.PutUint32(h[4:], d.s[1]) | ||
binary.LittleEndian.PutUint32(h[8:], d.s[2]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
// Copyright 2009 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
// Copyright 2019-2024 Xu Ruibo ([email protected]) and Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package md5hash | ||
|
||
|
@@ -228,9 +238,10 @@ func TestAllocations(t *testing.T) { | |
func TestMD5Hash(t *testing.T) { | ||
in := []byte("hello, world!") | ||
h, hi, lo := MD5Hash(in) | ||
h2, hi2, lo2 := MD5Sum(in) | ||
var h2 [Size]byte | ||
hi2, lo2 := MD5Sum(in, h2[:]) | ||
|
||
if !bytes.Equal(h, h2) { | ||
if !bytes.Equal(h, h2[:]) { | ||
t.Errorf("MD5Hash(in) = %x, want %x", h, h2) | ||
} | ||
if hi != hi2 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.