padding

package
v0.0.0-...-e73c711 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package padding adds or removes padding to a plaintext slice.

Index

Constants

View Source
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.

View Source
const ErrOneByte = "must have exactly one byte free"
View Source
const ErrSize = "must have at least one byte free"

Variables

This section is empty.

Functions

func Add

func Add(slice *[]byte, final bool, capacity int) (err error)

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

func Remove(chunk *[]byte) (final bool)

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.

Jump to

Keyboard shortcuts

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