Documentation ¶
Overview ¶
Package padding adds or removes padding to a plaintext slice.
Index ¶
Constants ¶
const ( Running chunktype = '\x00' // a common chunk which is followed by many like itself ... Unpadded chunktype = '\x01' // a final chunk that fits right inside and needs no padding Padded chunktype = '\x02' // a final chunk that requires padding )
The possible final bytes to indicate the type of this chunk.
const ErrOneByte = "must have exactly one byte free"
const ErrSize = "must have at least one byte free"
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add appends one or more padding bytes at the end of the slice, depending on whether it is a running or a final chunk from a given sequence. If padding is needed, the following rules apply:
the last data byte is NOT \x00 --> pad with \x00 bytes the last data byte is \x00 --> pad with \x01 bytes
The very last appended byte indicates the type of chunk and wether padding was applied or not. See https://rwc.iacr.org/2018/Slides/Hansen.pdf, page 10 for details.
! WARNING: not constant time, might open up side-channels
func Remove ¶
Remove removes padding which was previously added with Add(). The last byte indicates the padding to be expected and wether it was a final chunk of a sequence. This information is returned as `final`. See Add() comment for further specifications.
! WARNING: This is my best-effor attempt of creating a constant-time function. Tests with https://github.com/oreparaz/dudect do look promising though.
When used with authenticated encryption this might not even be necessary anyway.
Types ¶
This section is empty.