aboutsummaryrefslogblamecommitdiff
path: root/helper.go
blob: 8fc8ccbb5c39ac413e6096db4004054bc50cfe27 (plain) (tree)


































                                                        
package rabaead

import (
	"encoding/binary"

	"snix.ir/poly1305"
)

func headtail(in []byte, n int) (head, tail []byte) {
	total := len(in) + n

	if cap(in) >= total {
		head = in[:total]
	} else {
		head = make([]byte, total)
		copy(head, in)
	}
	tail = head[len(in):]
	return
}

func writePadding(p *poly1305.MAC, b []byte) {
	p.Write(b)
	if rem := len(b) % 16; rem != 0 {
		var buf [16]byte
		padLen := 16 - rem
		p.Write(buf[:padLen])
	}
}

func writeUint64(p *poly1305.MAC, n int) {
	var buf [8]byte
	binary.LittleEndian.PutUint64(buf[:], uint64(n))
	p.Write(buf[:])
}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR