internal

package
v0.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBlockSize   = errors.New("error padding. invalid block size")
	ErrDataLength  = errors.New("error padding. invalid data length")
	ErrPaddingSize = errors.New("error padding. invalid padding size")
)

Functions

func Copy

func Copy(s cipher.Stream, dst io.Writer, src io.Reader) error

Copy copies from src to dst. If src is encrypted, then decrypted bytes are written into the dst. If src is not encrypted, then encrypted bytes are written into the dst. It uses 1 kiB internal buffer. s, dst, src must not be nil, otherwise it panics.

func PadISO10126

func PadISO10126(blockSize int, data []byte) ([]byte, error)

PadISO10126 appends padding bytes to given data and returns resulting slice. The given blockSize must be in a range of 1-255, otherwise ErrBlockSize is returned. For example, when blockSize is 6 and the input data is {0x61, 0x61, 0x63}, then returned data will be {0x61, 0x61, 0x63, 0xAA, 0xBB, 0x03}. The last byte (0x03) represents the length of the padding, and the preceding padding bytes (0xAA, 0xBB) are random.

func PadISO7816

func PadISO7816(blockSize int, data []byte) ([]byte, error)

PadISO7816 appends padding bytes to the given data and returns the resulting slice. The given blockSize must be in the range 1–255; otherwise, ErrBlockSize is returned. For example, when blockSize is 6 and the input data is {0x61, 0x61, 0x63}, the returned data will be {0x61, 0x61, 0x63, 0x80, 0x00, 0x00}. The byte 0x80 marks the end of the actual data, and the remaining bytes (0x00) are padding.

func PadPKCS7

func PadPKCS7(blockSize int, data []byte) ([]byte, error)

PadPKCS7 appends padding bytes to the given data and returns the resulting slice. This function can also be used for PKCS#5 padding, as PKCS#5 is a subset of PKCS#7. PKCS#7 padding values range from 0x01 to 0x10 (1 to 16 in decimal), while PKCS#5 is defined specifically for a block size of 8 bytes (0x08). The given blockSize must be in the range 1–255; otherwise, ErrBlockSize is returned. For example, when blockSize is 6 and the input data is {0x61, 0x61, 0x63}, the returned data will be {0x61, 0x61, 0x63, 0x03, 0x03, 0x03}.

func UnpadISO10126

func UnpadISO10126(blockSize int, data []byte) ([]byte, error)

UnpadISO10126 removes ISO10126 padding from the given data. It may return the following errors:

  • ErrBlockSize: the given blockSize is not in the range 1–255.
  • ErrDataLength: the length of the input data is invalid; it must be a multiple of blockSize.
  • ErrPaddingSize: the padding size embedded in the data is invalid.

func UnpadISO7816

func UnpadISO7816(blockSize int, data []byte) ([]byte, error)

UnpadISO7816 removes ISO7816 padding from the given data. It may return the following errors:

  • ErrBlockSize: the given blockSize is not in the range 1–255.
  • ErrDataLength: the length of the input data is invalid; it must be a multiple of blockSize.
  • ErrPaddingSize: the padding size in the data is invalid.

func UnpadPKCS7

func UnpadPKCS7(blockSize int, data []byte) ([]byte, error)

UnpadPKCS7 removes PKCS7 padding from the given data. It may return the following errors:

  • ErrBlockSize: the given blockSize is not in the range 1–255.
  • ErrDataLength: the length of the input data is invalid; it must be a multiple of blockSize.
  • ErrPaddingSize: the padding size in the data is invalid.

Types

type DecryptFunc

type DecryptFunc func(key []byte, ciphertext []byte) (plaintext []byte, err error)

DecryptFunc is the type of function that decrypts the given ciphertext.

type EncryptFunc

type EncryptFunc func(key []byte, plaintext []byte) (ciphertext []byte, err error)

EncryptFunc is the type of function that encrypts the given plaintext.

Jump to

Keyboard shortcuts

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