mirror of
https://github.com/emmansun/gmsm.git
synced 2025-10-14 07:10:45 +08:00
![github-actions[bot]](/assets/img/avatar_default.png)
* build(deps): bump github/codeql-action from 3.29.11 to 3.30.0 (#361) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.29.11 to 3.30.0. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](3c3833e0f8...2d92b76c45
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump codecov/codecov-action from 5.5.0 to 5.5.1 (#362) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.5.0 to 5.5.1. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](fdcc847654...5a1091511a
) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-version: 5.5.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump actions/setup-go from 5.5.0 to 6.0.0 (#363) Bumps [actions/setup-go](https://github.com/actions/setup-go) from 5.5.0 to 6.0.0. - [Release notes](https://github.com/actions/setup-go/releases) - [Commits](d35c59abb0...4469467582
) --- updated-dependencies: - dependency-name: actions/setup-go dependency-version: 6.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 3.30.0 to 3.30.1 (#364) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.0 to 3.30.1. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](2d92b76c45...f1f6e5f6af
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump step-security/harden-runner from 2.13.0 to 2.13.1 (#367) Bumps [step-security/harden-runner](https://github.com/step-security/harden-runner) from 2.13.0 to 2.13.1. - [Release notes](https://github.com/step-security/harden-runner/releases) - [Commits](ec9f2d5744...f4a75cfd61
) --- updated-dependencies: - dependency-name: step-security/harden-runner dependency-version: 2.13.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump github/codeql-action from 3.30.1 to 3.30.2 (#368) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.1 to 3.30.2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](f1f6e5f6af...d3678e237b
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(mlkem): initialize mlkem from golang standard library * chore(mlkem): refactoring, reduce alloc times * build(deps): bump github/codeql-action from 3.30.2 to 3.30.3 (#369) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.2 to 3.30.3. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](d3678e237b...192325c861
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * doc(README): include MLKEM * mldsa: refactor the implementation of key and sign/verify * mldsa,slhdsa: crypto.Signer assertion * fix(slhdsa): GenerateKey slice issue #72 * fix(slhdsa): copy/paste issue * slhdsa: supplements package level document * internal/zuc: eea supports encoding.BinaryMarshaler & encoding.BinaryUnmarshaler interfaces * mlkem: use clear built-in * build(deps): bump github/codeql-action from 3.30.3 to 3.30.4 (#376) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.3 to 3.30.4. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](192325c861...303c0aef88
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * cipher: initial support gxm & mur modes * cipher: update comments * build(deps): bump github/codeql-action from 3.30.4 to 3.30.5 (#377) Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.30.4 to 3.30.5. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](303c0aef88...3599b3baa1
) --- updated-dependencies: - dependency-name: github/codeql-action dependency-version: 3.30.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 增加了DRBG销毁内部状态的方法 (#378) * 增加了DRBG销毁内部状态的方法 * 统一前缀 * 修改随机数长度 * 分组和注释 * 错误函数描述 * zuc: expose methods to support encoding.BinaryMarshaler and encoding.BinaryUnmarshaler * drbg: align comments style * internal/zuc: support fast forward * internal/zuc: supplement comments --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sun Yimin <emmansun@users.noreply.github.com> Co-authored-by: Guanyu Quan <quanguanyu@qq.com>
139 lines
4.1 KiB
Go
139 lines
4.1 KiB
Go
// Copyright 2025 Sun Yimin. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package cipher_test
|
|
|
|
import (
|
|
"bytes"
|
|
_cipher "crypto/cipher"
|
|
"encoding/hex"
|
|
"testing"
|
|
|
|
"github.com/emmansun/gmsm/cipher"
|
|
"github.com/emmansun/gmsm/zuc"
|
|
)
|
|
|
|
var murTestCases = []struct {
|
|
iv string
|
|
h string
|
|
k1 string
|
|
k2 string
|
|
a string
|
|
p string
|
|
result string
|
|
tagSize int
|
|
}{
|
|
// GM/T 0001.4 - 2024 Appendix C.3
|
|
{
|
|
iv: "bb8b76cfe5f0d9335029008b2a3b2b21",
|
|
h: "ee767d503bb3d5d1b585f57a0418c673",
|
|
k1: "e4b5c1f8578034ce6424f58c675597ac",
|
|
k2: "608053f6af9efda562d95dc013bea6b5",
|
|
a: "fcdd4cb97995da30efd957194eac4d2a8610470f99c88657f462f68dff7561a5",
|
|
p: "5fee5517627f17b22a96caf97b77ec7f667cc47d13c34923be2441300066a6c150b24d66c947ca7b2e708eb62bb352",
|
|
result: "cf5594bd30c0da0fb41fa6054e534d0494c9d6c4f132fc85771a473458b09583b825c662bfd82278178a845e281e5415c5d1a78a42c4dcd67db05fa1a640a0",
|
|
tagSize: 16,
|
|
},
|
|
{
|
|
iv: "2923be84e16cd6ae529049f1f1bbe9eb",
|
|
h: "27bede74018082da87d4e5b69f18bf66",
|
|
k1: "32070e0f39b7b692b4673edc3184a48e",
|
|
k2: "27636f4414510d62cc15cfe194ec4f6d",
|
|
a: "",
|
|
p: "",
|
|
result: "c0016e0772c9983d0fd9fd8c1b012845",
|
|
tagSize: 16,
|
|
},
|
|
{
|
|
iv: "2d2086832cc2fe3fd18cb51d6c5e99a5",
|
|
h: "9d6cb51623fd847f2e45d7f52f900db8",
|
|
k1: "56131c03e457f6226b5477633b873984",
|
|
k2: "a88981534db331a386de3e52fb46029b",
|
|
a: "",
|
|
p: "ffffffffffffffffffffffffffffff",
|
|
result: "234c2d51eaa582da9be3cc3828aa670a7afb7d817efa0777826f1e33a53cf3",
|
|
tagSize: 16,
|
|
},
|
|
{
|
|
iv: "b3a6db3c870c3e99245e0d1c06b747de",
|
|
h: "6db45e4f9572f4e6fe0d91acda6801d5",
|
|
k1: "edbe06afed8075576aad04afdec91d32",
|
|
k2: "61d4fca6b2c2bb48b4b1172531333620",
|
|
a: "9de18b1fdab0ca9902b9729d492c807ec599d5",
|
|
p: "",
|
|
result: "8213c29606d02bba10f13ffad1d26a42",
|
|
tagSize: 16,
|
|
},
|
|
{
|
|
iv: "b3a6db3c870c3e99245e0d1c06b747de",
|
|
h: "6db45e4f9572f4e6fe0d91acda6801d5",
|
|
k1: "edbe06afed8075576aad04afdec91d32",
|
|
k2: "61d4fca6b2c2bb48b4b1172531333620",
|
|
a: "9de18b1fdab0ca9902b9729d492c807ec599d5e980b2eac9cc53bf67d6bf14d67e2ddc8e6683ef574961ff698f61cdd1",
|
|
p: "b3124dc843bb8ba61f035a7d0938251f5dd4cbfc96f5453b130d890a1cdbae32",
|
|
result: "dabbbe23d8f0ea42e31a9bdd9706a4275d8aacd2cf27c4a4c0d0ba6fb8f31da7a276827b74509357",
|
|
tagSize: 8,
|
|
},
|
|
}
|
|
|
|
func TestMurSeal(t *testing.T) {
|
|
zucCipherCreator := func(key, iv []byte) (_cipher.Stream, error) {
|
|
return zuc.NewCipher(key, iv)
|
|
}
|
|
for i, tc := range murTestCases {
|
|
iv, _ := hex.DecodeString(tc.iv)
|
|
h, _ := hex.DecodeString(tc.h)
|
|
k1, _ := hex.DecodeString(tc.k1)
|
|
k2, _ := hex.DecodeString(tc.k2)
|
|
a, _ := hex.DecodeString(tc.a)
|
|
p, _ := hex.DecodeString(tc.p)
|
|
result, _ := hex.DecodeString(tc.result)
|
|
|
|
g, err := cipher.NewMURWithTagSize(zucCipherCreator, h, tc.tagSize)
|
|
if err != nil {
|
|
t.Errorf("case %d: NewMURWithTagSize error: %s", i, err)
|
|
continue
|
|
}
|
|
c, err := g.Seal(iv, k1, k2, nil, p, a)
|
|
if err != nil {
|
|
t.Errorf("case %d: Seal error: %s", i, err)
|
|
continue
|
|
}
|
|
if !bytes.Equal(c, result) {
|
|
t.Errorf("case %d: Seal mismatch\ngot: %x\nwant: %x", i, c, result)
|
|
continue
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestMurOpen(t *testing.T) {
|
|
zucCipherCreator := func(key, iv []byte) (_cipher.Stream, error) {
|
|
return zuc.NewCipher(key, iv)
|
|
}
|
|
for i, tc := range murTestCases {
|
|
iv, _ := hex.DecodeString(tc.iv)
|
|
h, _ := hex.DecodeString(tc.h)
|
|
k1, _ := hex.DecodeString(tc.k1)
|
|
k2, _ := hex.DecodeString(tc.k2)
|
|
a, _ := hex.DecodeString(tc.a)
|
|
p, _ := hex.DecodeString(tc.p)
|
|
result, _ := hex.DecodeString(tc.result)
|
|
|
|
g, err := cipher.NewMURWithTagSize(zucCipherCreator, h, tc.tagSize)
|
|
if err != nil {
|
|
t.Errorf("case %d: NewMURWithTagSize error: %s", i, err)
|
|
continue
|
|
}
|
|
out, err := g.Open(iv, k1, k2, nil, result, a)
|
|
if err != nil {
|
|
t.Errorf("case %d: Open error: %s", i, err)
|
|
continue
|
|
}
|
|
if !bytes.Equal(out, p) {
|
|
t.Errorf("case %d: Open mismatch\ngot: %x\nwant: %x", i, out, p)
|
|
continue
|
|
}
|
|
}
|
|
}
|