Skip to content

Commit

Permalink
Merge pull request #13 from dongbeiouba/examples/sm3
Browse files Browse the repository at this point in the history
Add example for SM3
  • Loading branch information
InfoHunter committed Oct 12, 2023
2 parents a71884e + 007f8f6 commit 8c4fc8f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crypto/sm3/sm3.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
package sm3

// #include "../../shim.h"
// #cgo linux CFLAGS: -Wno-deprecated-declarations -I/opt/tongsuo/include
// #cgo linux LDFLAGS: -L/opt/tongsuo/lib -lssl -lcrypto
// #cgo darwin CFLAGS: -I/opt/tongsuo/include -Wno-deprecated-declarations
// #cgo darwin LDFLAGS: -L/opt/tongsuo/lib -lssl -lcrypto
// #cgo windows CFLAGS: -DWIN32_LEAN_AND_MEAN
// #cgo windows pkg-config: libssl libcrypto
import "C"

import (
Expand Down
35 changes: 35 additions & 0 deletions examples/sm3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 The Tongsuo Project Authors. All Rights Reserved.
//
// Licensed under the Apache License 2.0 (the "License"). You may not use
// this file except in compliance with the License. You can obtain a copy
// in the file LICENSE in the source distribution or at
// https://github.com/Tongsuo-Project/tongsuo-go-sdk/blob/main/LICENSE

package main

import (
"fmt"
"github.com/tongsuo-project/tongsuo-go-sdk/crypto/sm3"
"os"
)

func main() {
msg := "hello world"
fmt.Printf("%x\n", sm3.SM3Sum([]byte(msg)))

h, err := sm3.New()
if err != nil {
os.Exit(1)
}

if _, err := h.Write([]byte("hello")); err != nil {
os.Exit(1)
}
if _, err := h.Write([]byte(" world")); err != nil {
os.Exit(1)
}

var res [sm3.SM3_DIGEST_LENGTH]byte

fmt.Printf("%x\n", h.Sum(res[:0]))
}

0 comments on commit 8c4fc8f

Please sign in to comment.