nse

package
v0.0.0-...-f17855a Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToInt64

func BytesToInt64(data []byte) (int64, int, error)

BytesToInt64 converts byte array into int64. It returns converted integer, bytes read and err. err != nil if and only if binary.Varint returns an error.

func BytesToInt64FromReader

func BytesToInt64FromReader(reader io.Reader) (int64, int, error)

BytesToInt64FromReader converts few first bytes into int64. It returns converted integer, bytes read and err. err != nil if and only if binary.Varint returns an error or given reader doesn't have that many bytes to read.

func BytesToInt64s

func BytesToInt64s(data []byte) ([]int64, error)

BytesToInt64s converts result of Int64sToBytes back into []int64. It returns errors.WrongDataFormatError as an error when data doesn't appear to be a result of Int64sToBytes.

func BytesToInt8s

func BytesToInt8s(data []byte) []int8

BytesToInt8s converts []byte into []int8. Every byte in the slice is treated like it would be signed.

func Decrypt

func Decrypt(encryptedData []int64, IV []int8, key *NSEKey) (decryptedData []byte, err error)

Decrypt decrypts encryptedData using NSE algorithm with given IV and key derived using DeriveKey function. It returns decryptedData and err. err != nil if len(data) < 1, len(data) != len(IV).

func Encrypt

func Encrypt(data []byte, key *NSEKey) (encryptedData []int64, IV []int8, err error)

Encrypt encrypts data using NSE algorithm with given key derived using DeriveKey function. It returns encryptedData, IV and err. err != nil if len(data) < 1 or if GenerateIV function returned an error.

func GenerateIV

func GenerateIV(length int, rotatedData []int8, key *NSEKey) ([]int8, error)

GenerateIV generates IV of given length for NSE algorithm. It returns an error if length < 1 or if crypto.rand.Read returns an error.

func Int64ToBytes

func Int64ToBytes(integer int64) []byte

Int64ToBytes converts integer into byte array. It ignores padding, result is as short as possible. First byte is length of the rest.

func Int64sToBytes

func Int64sToBytes(data []int64) []byte

Int64sToBytes converts []int64 into []byte. For each int64 in the slice there is one byte indicating how many bytes to read next and those bytes.

func Int8sToBytes

func Int8sToBytes(data []int8) []byte

Int8sToBytes converts []int8 into []byte. Every int8 in the slice is treated like it would be unsigned.

Types

type NSEKey

type NSEKey struct {
	Data          []uint16
	BitsToRotate  byte
	BytesToRotate int
}

func DeriveKey

func DeriveKey(key *big.Int, salt []byte, dataLength int) (derivedKey *NSEKey, err error)

DeriveKey derives key from given big integer key, salt. DerivedKey has the same length as data, so it is dataLength. It returns derived key as struct NSEKey and err, err != nil if and only if given key is not positive or hkdf returns an error.

Jump to

Keyboard shortcuts

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