bcrypt and null kdf done, work on ciphers next (then keytypes)

This commit is contained in:
2022-04-25 04:27:24 -04:00
parent 91d5e99404
commit ff3f8243d1
43 changed files with 755 additions and 423 deletions

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package cbc
const (
Name string = "aes128-cbc"
)

View File

@@ -0,0 +1,10 @@
package aes128
import (
`r00t2.io/sshkeys/cipher/aes`
)
const (
KeySize int = 16 // in bytes; AES128 is so named for its 128-bit key, thus: 128 / 8 = 16
KdfKeySize int = KeySize + aes.IvSize
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package ctr
const (
Name string = "aes128-ctr"
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package gcm
const (
Name string = "aes128-gcm@openssh.com"
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package cbc
const (
Name string = "aes192-cbc"
)

View File

@@ -0,0 +1,10 @@
package aes192
import (
`r00t2.io/sshkeys/cipher/aes`
)
const (
KeySize int = 24 // in bytes; AES182 is so named for its 192-bit key, thus: 192 / 8 = 24
KdfKeySize int = KeySize + aes.IvSize
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package ctr
const (
Name string = "aes192-ctr"
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package gcm
const (
Name string = "aes192-gcm@openssh.com"
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package cbc
const (
Name string = "aes256-cbc"
)

View File

@@ -0,0 +1,10 @@
package aes256
import (
`r00t2.io/sshkeys/cipher/aes`
)
const (
KeySize int = 32 // in bytes; AES256 is so named for its 256-bit key, thus: 256 / 8 = 32
KdfKeySize int = KeySize + aes.IvSize
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package ctr
const (
Name string = "aes256-ctr"
)

View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1,5 @@
package gcm
const (
Name string = "aes256-gcm@openssh.com"
)

10
cipher/aes/consts.go Normal file
View File

@@ -0,0 +1,10 @@
package aes
import (
`crypto/aes`
)
const (
BlockSize int = aes.BlockSize
IvSize int = aes.BlockSize
)

View File

@@ -0,0 +1 @@
TODO

1
cipher/null/TODO Normal file
View File

@@ -0,0 +1 @@
TODO

View File

@@ -0,0 +1 @@
TODO

50
cipher/types.go Normal file
View File

@@ -0,0 +1,50 @@
package cipher
import (
`bytes`
)
type Cipher interface {
// Name returns the string form of the cipher name.
Name() (name string)
// NameBytes returns the Name result but in bytes, with a leading uint32 bytecount packed in.
NameBytes() (name []byte)
// BlockSize returns the blocksize of the cipher.Cipher. This is used for externally padding data for Cipher.Encrypt and Cipher.AllocateEncrypt.
BlockSize() (size int)
// KdfKeySize returns the desired/needed key size for use with kdf.KDF.
KdfKeySize() (size int)
// Setup initializes the Cipher with a given key.
Setup(key []byte) (err error)
/*
Encrypt takes plain data, either a:
- string
- raw byte slice ([]byte or []uint8)
- single byte (byte or uint8)
- *bytes.Buffer
and returns an encrypted *bytes.Buffer of data.
*/
Encrypt(data interface{}) (encrypted *bytes.Reader, err error)
// AllocateEncrypt is exactly like cipher.Cipher.Encrypt except that it includes a (NON-encrypted) uint32 prefix of byte allocation.
AllocateEncrypt(data interface{}) (encrypted *bytes.Reader, err error)
/*
Decrypt takes encrypted data, either a:
- raw byte slice ([]byte or []uint8)
- *bytes.Buffer
and returns a plain/decrypted *bytes.Buffer of data.
*/
Decrypt(data interface{}) (decrypted *bytes.Reader, err error)
// AllocatedDecrypt is exactly like cipher.Cipher.Decrypt except that it assumes that data includes a (NON-encrypted) uint32 prefix of byte allocation.
AllocatedDecrypt(data interface{}) (decrypted *bytes.Reader, err error)
// IsPlain returns true if this is a "null" cipher; i.e. no encryption is actually performed.
IsPlain() (plain bool)
/*
Pad returns padded bytes in a *bytes.Buffer according to the cipher's padding specification.
data can be one of either:
- string
- raw byte slice ([]byte or []uint8)
- single byte (byte or uint8)
- *bytes.Buffer
This is a prerequisite in some ciphers, and must be performed BEFORE encrypting.
*/
Pad(data interface{}) (paddedBuf *bytes.Reader, err error)
}