library: crypto/md5
This commit is contained in:
@@ -297,6 +297,7 @@ Here are the Go packages that can be imported correctly:
|
|||||||
* [encoding/base32](https://pkg.go.dev/encoding/base32)
|
* [encoding/base32](https://pkg.go.dev/encoding/base32)
|
||||||
* [encoding/base64](https://pkg.go.dev/encoding/base64)
|
* [encoding/base64](https://pkg.go.dev/encoding/base64)
|
||||||
* [encoding/csv](https://pkg.go.dev/encoding/csv)
|
* [encoding/csv](https://pkg.go.dev/encoding/csv)
|
||||||
|
* [crypto/md5](https://pkg.go.dev/crypto/md5)
|
||||||
* [regexp](https://pkg.go.dev/regexp)
|
* [regexp](https://pkg.go.dev/regexp)
|
||||||
* [regexp/syntax](https://pkg.go.dev/regexp/syntax)
|
* [regexp/syntax](https://pkg.go.dev/regexp/syntax)
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ func main() {
|
|||||||
md5.Init()
|
md5.Init()
|
||||||
md5.UpdateString("The fog is getting thicker!")
|
md5.UpdateString("The fog is getting thicker!")
|
||||||
md5.UpdateString("And Leon's getting laaarger!")
|
md5.UpdateString("And Leon's getting laaarger!")
|
||||||
md5.Final(unsafe.Pointer(unsafe.SliceData(h)))
|
md5.Final(unsafe.SliceData(h))
|
||||||
fmt.Printf("%x", h)
|
fmt.Printf("%x", h)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,22 +61,22 @@ func (c *MD5_CTX) UpdateString(data string) c.Int {
|
|||||||
// OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
|
// OSSL_DEPRECATEDIN_3_0 int MD5_Final(unsigned char *md, MD5_CTX *c);
|
||||||
//
|
//
|
||||||
//go:linkname md5Final C.MD5_Final
|
//go:linkname md5Final C.MD5_Final
|
||||||
func md5Final(md unsafe.Pointer, c *MD5_CTX) c.Int
|
func md5Final(md *byte, c *MD5_CTX) c.Int
|
||||||
|
|
||||||
func (c *MD5_CTX) Final(md unsafe.Pointer) c.Int {
|
func (c *MD5_CTX) Final(md *byte) c.Int {
|
||||||
return md5Final(md, c)
|
return md5Final(md, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSSL_DEPRECATEDIN_3_0 unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
|
// OSSL_DEPRECATEDIN_3_0 unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md);
|
||||||
//
|
//
|
||||||
//go:linkname MD5 C.MD5
|
//go:linkname MD5 C.MD5
|
||||||
func MD5(data unsafe.Pointer, n uintptr, md unsafe.Pointer) unsafe.Pointer
|
func MD5(data unsafe.Pointer, n uintptr, md *byte) *byte
|
||||||
|
|
||||||
func MD5Bytes(data []byte, md unsafe.Pointer) unsafe.Pointer {
|
func MD5Bytes(data []byte, md *byte) *byte {
|
||||||
return MD5(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
return MD5(unsafe.Pointer(unsafe.SliceData(data)), uintptr(len(data)), md)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MD5String(data string, md unsafe.Pointer) unsafe.Pointer {
|
func MD5String(data string, md *byte) *byte {
|
||||||
return MD5(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
return MD5(unsafe.Pointer(unsafe.StringData(data)), uintptr(len(data)), md)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -590,9 +590,8 @@ func ignoreName(name string) bool {
|
|||||||
*/
|
*/
|
||||||
const internal = "internal/"
|
const internal = "internal/"
|
||||||
return (strings.HasPrefix(name, internal) && !supportedInternal(name[len(internal):])) ||
|
return (strings.HasPrefix(name, internal) && !supportedInternal(name[len(internal):])) ||
|
||||||
strings.HasPrefix(name, "crypto/") || strings.HasPrefix(name, "runtime/") ||
|
strings.HasPrefix(name, "runtime/") || strings.HasPrefix(name, "arena.") ||
|
||||||
strings.HasPrefix(name, "arena.") || strings.HasPrefix(name, "maps.") ||
|
strings.HasPrefix(name, "maps.") || strings.HasPrefix(name, "plugin.")
|
||||||
strings.HasPrefix(name, "plugin.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func supportedInternal(name string) bool {
|
func supportedInternal(name string) bool {
|
||||||
|
|||||||
@@ -755,6 +755,7 @@ func findDylibDep(exe, lib string) string {
|
|||||||
type none struct{}
|
type none struct{}
|
||||||
|
|
||||||
var hasAltPkg = map[string]none{
|
var hasAltPkg = map[string]none{
|
||||||
|
"crypto/md5": {},
|
||||||
"fmt": {},
|
"fmt": {},
|
||||||
"internal/abi": {},
|
"internal/abi": {},
|
||||||
"internal/bytealg": {},
|
"internal/bytealg": {},
|
||||||
|
|||||||
66
internal/lib/crypto/md5/md5.go
Normal file
66
internal/lib/crypto/md5/md5.go
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
|
||||||
|
*
|
||||||
|
* 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 md5
|
||||||
|
|
||||||
|
// llgo:skipall
|
||||||
|
import (
|
||||||
|
"hash"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/goplus/llgo/c"
|
||||||
|
"github.com/goplus/llgo/c/openssl"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The blocksize of MD5 in bytes.
|
||||||
|
const BlockSize = 64
|
||||||
|
|
||||||
|
// The size of an MD5 checksum in bytes.
|
||||||
|
const Size = 16
|
||||||
|
|
||||||
|
type digest struct {
|
||||||
|
ctx openssl.MD5_CTX
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *digest) Size() int { return Size }
|
||||||
|
|
||||||
|
func (d *digest) BlockSize() int { return BlockSize }
|
||||||
|
|
||||||
|
func (d *digest) Reset() {
|
||||||
|
d.ctx.Init()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *digest) Write(p []byte) (nn int, err error) {
|
||||||
|
d.ctx.UpdateBytes(p)
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *digest) Sum(in []byte) []byte {
|
||||||
|
hash := (*[Size]byte)(c.Alloca(Size))
|
||||||
|
d.ctx.Final((*byte)(unsafe.Pointer(hash)))
|
||||||
|
return append(in, hash[:]...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() hash.Hash {
|
||||||
|
d := new(digest)
|
||||||
|
d.ctx.Init()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
func Sum(data []byte) (ret [Size]byte) {
|
||||||
|
openssl.MD5Bytes(data, &ret[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user