sm4

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Overview

Copyright Hyperledger-TWGC All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

writed by Zhiwei Yan, 2020 Oct

Index

Constants

View Source
const BlockSize = 16

Variables

This section is empty.

Functions

func GCMDecrypt added in v1.4.0

func GCMDecrypt(K, IV, C, A []byte) (P, _T []byte)

func GCMEncrypt added in v1.4.0

func GCMEncrypt(K, IV, P, A []byte) (C, T []byte)

func GHASH added in v1.4.0

func GHASH(H []byte, A []byte, C []byte) (X []byte)

func GetH added in v1.4.0

func GetH(key []byte) (H []byte)

func GetY0 added in v1.4.0

func GetY0(H, IV []byte) []byte

func MSB added in v1.4.0

func MSB(len int, S []byte) (out []byte)

func NewCipher

func NewCipher(key []byte) (cipher.Block, error)

NewCipher creates and returns a new cipher.Block.

func Rightshift added in v1.4.0

func Rightshift(V []byte)

func Sm4CFB added in v1.4.0

func Sm4CFB(key []byte, in []byte, mode bool) (out []byte, err error)

密码反馈模式(Cipher FeedBack (CFB)) https://blog.csdn.net/zy_strive_2012/article/details/102520356 https://blog.csdn.net/sinat_23338865/article/details/72869841

func Sm4Cbc added in v1.4.0

func Sm4Cbc(key []byte, in []byte, mode bool) (out []byte, err error)

func Sm4Ecb added in v1.4.0

func Sm4Ecb(key []byte, in []byte, mode bool) (out []byte, err error)

func Sm4GCM added in v1.4.0

func Sm4GCM(key []byte, IV, in, A []byte, mode bool) ([]byte, []byte, error)

Paper: The Galois/Counter Mode of Operation (GCM) David A. Mcgrew,John Viega .2004.

func Sm4OFB added in v1.4.0

func Sm4OFB(key []byte, in []byte, mode bool) (out []byte, err error)

输出反馈模式(Output feedback, OFB) https://blog.csdn.net/chengqiuming/article/details/82390910 https://blog.csdn.net/sinat_23338865/article/details/72869841

func WriteKeyToPem

func WriteKeyToPem(key SM4Key, pwd []byte) ([]byte, error)

WriteKeyToPem will convert SM4Key to PEM format data and return it.

func WriteKeyToPemFile added in v1.4.0

func WriteKeyToPemFile(FileName string, key SM4Key, pwd []byte) error

WriteKeyToPemFile will convert SM4Key to PEM format data, then write it into the input filename.

Types

type SM4Key

type SM4Key []byte

func ReadKeyFromPem

func ReadKeyFromPem(data []byte, pwd []byte) (SM4Key, error)

ReadKeyFromPem will return SM4Key from PEM format data.

func ReadKeyFromPemFile added in v1.4.0

func ReadKeyFromPemFile(FileName string, pwd []byte) (SM4Key, error)

ReadKeyFromPemFile will return SM4Key from filename that saved PEM format data.

type Sm4Cipher

type Sm4Cipher struct {
	// contains filtered or unexported fields
}

Cipher is an instance of SM4 encryption.

func (*Sm4Cipher) BlockSize

func (c *Sm4Cipher) BlockSize() int

func (*Sm4Cipher) Decrypt

func (c *Sm4Cipher) Decrypt(dst, src []byte)

func (*Sm4Cipher) Encrypt

func (c *Sm4Cipher) Encrypt(dst, src []byte)

Jump to

Keyboard shortcuts

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