Documentation
¶
Index ¶
Examples ¶
Constants ¶
const MaxFeistelWord = ^FeistelWord(0)
MaxFeistelWord is the maximum possible value of the FesitelWord type.
Variables ¶
This section is empty.
Functions ¶
func Shuffle ¶
func Shuffle(min, max FeistelWord, cipher *Feistel) (<-chan FeistelWord, error)
Shuffle creates a channel that stream shuffled values from a given minimum and maximum. If max is 0 then max act as the FesitelWord max value +1.
Example ¶
This example will output the shuffled set of range [1000, 1020)
s, _ := Shuffle(1000, 1020, NewFeistel(keys, roundFunction))
for v := range s {
fmt.Println(v)
}
Output: 1003 1005 1006 1009 1004 1011 1008 1016 1010 1001 1017 1000 1013 1012 1015 1014 1007 1002 1018 1019
Types ¶
type Feistel ¶
type Feistel struct {
// contains filtered or unexported fields
}
Feistel is where the state of Feistel network is stored, contains the keys to be applied on each round and a function of type FeistelFunc.
func NewFeistel ¶
func NewFeistel(keys []FeistelWord, f FeistelFunc) *Feistel
NewFeistel constructs a new Feistel context with the given keys and FeistelFunc.
func NewFeistelDefault ¶
func NewFeistelDefault(keys []FeistelWord) *Feistel
NewFeistelDefault constructs a new Feistel context with the given keys and using a default FeistelFunc.
func (*Feistel) Cipher ¶
func (f *Feistel) Cipher(left, right, mask FeistelWord) (FeistelWord, FeistelWord)
Cipher applys the Feistel cipher step to a word described in its left and right parts.
func (*Feistel) Decipher ¶
func (f *Feistel) Decipher(left, right, mask FeistelWord) (FeistelWord, FeistelWord)
Decipher applys the Fesitel decipher step to a word described in its left and right parts.
type FeistelFunc ¶
type FeistelFunc func(FeistelWord, FeistelWord) FeistelWord
A FeistelFunc is the type that define a function to be used in each round of the Feistel application.
type FeistelWord ¶
type FeistelWord uint64
A FeistelWord abstract the underlying unsigned type to represent a word in the Feistel context.
func GetIndex ¶
func GetIndex(permutation, max FeistelWord, cipher *Feistel) (FeistelWord, error)
GetIndex returns the unshuffled index of a given shuffle index and the higher bound of the shuffled set. If max is 0 then max act as the FesitelWord max value +1.
func RandomIndex ¶
func RandomIndex(idx, max FeistelWord, cipher *Feistel) (FeistelWord, error)
RandomIndex returns the shuffled index of a given index and the higher bound of the set to be shuffled. If max is 0 then max act as the FesitelWord max value +1.