diff options
author | root <sina@snix.ir> | 2022-07-24 04:38:03 +0000 |
---|---|---|
committer | root <sina@snix.ir> | 2022-07-24 04:38:03 +0000 |
commit | 1e8c539dba28f730ba01458bc4c8475a1cfc642f (patch) | |
tree | 5bc0d40b3f1a4be3a3fcbf524e4fa235f8691a7c /helper.go |
git add files
Diffstat (limited to 'helper.go')
-rw-r--r-- | helper.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/helper.go b/helper.go new file mode 100644 index 0000000..8fc8ccb --- /dev/null +++ b/helper.go @@ -0,0 +1,35 @@ +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[:]) +} |