Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "*" ]
# Build semver tags as releases.
tags: [ '*' ]
pull_request:
branches: [ "*" ]
# Build semver tags as releases.
tags: [ '*' ]
workflow_dispatch:

jobs:

build:
strategy:
fail-fast: false
matrix:
os: ["windows-latest", "ubuntu-latest", "ubuntu-22.04", "ubuntu-20.04", "macos-latest"]
go-version: ["1.24", "1.23", "1.22", "1.21", "1.20", "1.19", "1.18"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
11 changes: 9 additions & 2 deletions sm4/sm4.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func SetIV(iv []byte) error {
return nil
}

func Sm4Cbc(key []byte, in []byte, mode bool) (out []byte, err error) {
func Sm4Cbc(key []byte, in []byte, mode bool, ivInput ...[]byte) (out []byte, err error) {
if len(key) != BlockSize {
return nil, errors.New("SM4: invalid key size " + strconv.Itoa(len(key)))
}
Expand All @@ -310,7 +310,14 @@ func Sm4Cbc(key []byte, in []byte, mode bool) (out []byte, err error) {
inData = in
}
iv := make([]byte, BlockSize)
copy(iv, IV)
if ivInput != nil {
if len(ivInput[0]) != BlockSize {
return nil, errors.New("SM4: invalid iv size")
}
copy(iv, ivInput[0])
} else {
copy(iv, IV)
}
out = make([]byte, len(inData))
c, err := NewCipher(key)
if err != nil {
Expand Down