sm3

package
v0.26.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 5 Imported by: 17

Documentation

Overview

Package sm3 implements ShangMi(SM) sm3 hash algorithm.

Index

Examples

Constants

View Source
const BlockSize int = 64

BlockSize the blocksize of SM3 in bytes.

View Source
const Size int = 32

Size the size of a SM3 checksum in bytes.

View Source
const SizeBitSize = 5

SizeBitSize the bit size of Size.

Variables

This section is empty.

Functions

func New

func New() hash.Hash

New returns a new hash.Hash computing the SM3 checksum. The Hash also implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler to marshal and unmarshal the internal state of the hash.

Example
package main

import (
	"fmt"

	"github.com/emmansun/gmsm/sm3"
)

func main() {
	h := sm3.New()
	h.Write([]byte("hello world\n"))
	fmt.Printf("%x", h.Sum(nil))
}
Output:

4cc2036b86431b5d2685a04d289dfe140a36baa854b01cb39fcd6009638e4e7a
Example (File)
package main

import (
	"fmt"
	"io"
	"log"
	"os"

	"github.com/emmansun/gmsm/sm3"
)

func main() {
	f, err := os.Open("file.txt")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	h := sm3.New()
	if _, err := io.Copy(h, f); err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%x", h.Sum(nil))
}
Output:

func Sum

func Sum(data []byte) [Size]byte

Sum returns the SM3 checksum of the data.

Example
package main

import (
	"fmt"

	"github.com/emmansun/gmsm/sm3"
)

func main() {
	sum := sm3.Sum([]byte("hello world\n"))
	fmt.Printf("%x", sum)
}
Output:

4cc2036b86431b5d2685a04d289dfe140a36baa854b01cb39fcd6009638e4e7a

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL