Documentation
¶
Index ¶
- Variables
- func Copy(s cipher.Stream, dst io.Writer, src io.Reader) error
- func MustNil(err error)
- func PadISO10126(blockSize int, data []byte) ([]byte, error)
- func PadISO7816(blockSize int, data []byte) ([]byte, error)
- func PadPKCS7(blockSize int, data []byte) ([]byte, error)
- func UnpadISO10126(blockSize int, data []byte) ([]byte, error)
- func UnpadISO7816(blockSize int, data []byte) ([]byte, error)
- func UnpadPKCS7(blockSize int, data []byte) ([]byte, error)
- type CompareSumFunc
- type DecryptFunc
- type EncryptFunc
- type EqualSumFunc
- type HMACCompareSumFunc
- type HMACEqualSumFunc
- type HMACSumFunc
- type PWHasher
- type SumFunc
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Copy ¶
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 MustNil ¶
func MustNil(err error)
MustNil panics if err is not nil. MustNil is a defensive assertion used primarily in security-sensitive areas. It ensures that an error, which "should never" occur, is truly absent. This acts as a safeguard against future changes in upstream APIs.
This is intended to be used with crypto/rand.Read. As noted in the documentation for crypto/rand.Read, it does not return a non-nil error. While we believe this interface will never change, we include this check just to be absolutely sure — for security reasons.
Example:
buf := make([]byte, 10) _, err := rand.Read(buf) // Never returns a non-nil error. internal.MustNil(err) // But we check anyway, just in case.
func PadISO10126 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 CompareSumFunc ¶
CompareSumFunc returns if the sum and the hash of b matches or not. If matches, it returns nil error. If not matches, it returns non-nil error.
type DecryptFunc ¶
DecryptFunc is the type of function that decrypts the given ciphertext.
type EncryptFunc ¶
EncryptFunc is the type of function that encrypts the given plaintext.
type EqualSumFunc ¶
EqualSumFunc returns if the sum and the hash of b matches or not. Unlike CompareSumFunc, it returns true or false.
type HMACCompareSumFunc ¶
HMACCompareSumFunc returns if the sum and the HMAC of msg matches or not. If matches, it returns nil error. If not matches, it returns non-nil error.
type HMACEqualSumFunc ¶
HMACEqualSumFunc returns if the sum and the HMAC of msg matches or not. Unlike HMACCompareSumFunc, it returns true or false.
type HMACSumFunc ¶
HMACSumFunc returns HMAC of the msg.