From 621d83a6f114ead4a31214a0cd870893b5243a0a Mon Sep 17 00:00:00 2001 From: Jianwei Mao Date: Sun, 31 Dec 2023 08:59:13 +0800 Subject: [PATCH 1/3] allow to use input iv. Signed-off-by: Jianwei Mao --- sm4/sm4.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sm4/sm4.go b/sm4/sm4.go index 0e301deb..1778795b 100644 --- a/sm4/sm4.go +++ b/sm4/sm4.go @@ -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))) } @@ -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 { From 95cd236e1dca172d950cde21fc81fdd25de6840f Mon Sep 17 00:00:00 2001 From: Jianwei Mao Date: Sat, 1 Mar 2025 23:42:33 +0800 Subject: [PATCH 2/3] Create go.yml --- .github/workflows/go.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/go.yml diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 00000000..cdf5597a --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,33 @@ +# 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: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Build + run: go build -v ./... + + - name: Test + run: go test -v ./... From 24ab19f6732b2d3eec1cb9c8818aaa127c7b2d7a Mon Sep 17 00:00:00 2001 From: Jianwei Mao Date: Sat, 1 Mar 2025 23:44:21 +0800 Subject: [PATCH 3/3] Update go.yml --- .github/workflows/go.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cdf5597a..968ba538 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -17,14 +17,19 @@ on: jobs: build: - runs-on: ubuntu-latest + 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@v4 + uses: actions/setup-go@v5 with: - go-version: '1.20' + go-version: ${{ matrix.go-version }} - name: Build run: go build -v ./...