Skip to content

Commit

Permalink
AEAD ciphers follow IANA scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
riobard committed Mar 10, 2017
1 parent 38373ac commit 6dfc567
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
35 changes: 22 additions & 13 deletions core/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ var aeadList = map[string]struct {
KeySize int
New func([]byte) (shadowaead.Cipher, error)
}{
"aes-128-gcm": {16, shadowaead.AESGCM},
"aes-192-gcm": {24, shadowaead.AESGCM},
"aes-256-gcm": {32, shadowaead.AESGCM},
"chacha20-ietf-poly1305": {32, shadowaead.Chacha20IETFPoly1305},
"AEAD_AES_128_GCM": {16, shadowaead.AESGCM},
"AEAD_AES_192_GCM": {24, shadowaead.AESGCM},
"AEAD_AES_256_GCM": {32, shadowaead.AESGCM},
"AEAD_CHACHA20_POLY1305": {32, shadowaead.Chacha20Poly1305},
}

// List of stream ciphers: key size in bytes and constructor
var streamList = map[string]struct {
KeySize int
New func(key []byte) (shadowstream.Cipher, error)
}{
"aes-128-ctr": {16, shadowstream.AESCTR},
"aes-192-ctr": {24, shadowstream.AESCTR},
"aes-256-ctr": {32, shadowstream.AESCTR},
"aes-128-cfb": {16, shadowstream.AESCFB},
"aes-192-cfb": {24, shadowstream.AESCFB},
"aes-256-cfb": {32, shadowstream.AESCFB},
"chacha20-ietf": {32, shadowstream.Chacha20IETF},
"AES-128-CTR": {16, shadowstream.AESCTR},
"AES-192-CTR": {24, shadowstream.AESCTR},
"AES-256-CTR": {32, shadowstream.AESCTR},
"AES-128-CFB": {16, shadowstream.AESCFB},
"AES-192-CFB": {24, shadowstream.AESCFB},
"AES-256-CFB": {32, shadowstream.AESCFB},
"CHACHA20-IETF": {32, shadowstream.Chacha20IETF},
}

// ListCipher returns a list of available cipher names sorted alphabetically.
Expand All @@ -67,10 +67,19 @@ func ListCipher() []string {

// PickCipher returns a Cipher of the given name. Derive key from password if given key is empty.
func PickCipher(name string, key []byte, password string) (Cipher, error) {
name = strings.ToLower(name)
name = strings.ToUpper(name)

if name == "dummy" {
switch name {
case "DUMMY":
return &dummy{}, nil
case "CHACHA20-IETF-POLY1305":
name = "AEAD_CHACHA20_POLY1305"
case "AES-128-GCM":
name = "AEAD_AES_128_GCM"
case "AES-196-GCM":
name = "AEAD_AES_196_GCM"
case "AES-256-GCM":
name = "AEAD_AES_256_GCM"
}

if choice, ok := aeadList[name]; ok {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func main() {
}

flag.BoolVar(&config.Verbose, "verbose", false, "verbose mode")
flag.StringVar(&flags.Cipher, "cipher", "chacha20-ietf-poly1305", "available ciphers: "+strings.Join(core.ListCipher(), " "))
flag.StringVar(&flags.Cipher, "cipher", "AEAD_CHACHA20_POLY1305", "available ciphers: "+strings.Join(core.ListCipher(), " "))
flag.StringVar(&flags.Key, "key", "", "base64url-encoded key (derive from password if empty)")
flag.IntVar(&flags.Keygen, "keygen", 0, "generate a base64url-encoded random key of given length in byte")
flag.StringVar(&flags.Password, "password", "", "password")
Expand Down
4 changes: 2 additions & 2 deletions shadowaead/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func AESGCM(psk []byte) (Cipher, error) {
return &metaCipher{psk: psk, makeAEAD: aesGCM}, nil
}

// Chacha20IETFPoly1305 creates a new Cipher with a pre-shared key. len(psk)
// Chacha20Poly1305 creates a new Cipher with a pre-shared key. len(psk)
// must be 32.
func Chacha20IETFPoly1305(psk []byte) (Cipher, error) {
func Chacha20Poly1305(psk []byte) (Cipher, error) {
if len(psk) != chacha20poly1305.KeySize {
return nil, KeySizeError(chacha20poly1305.KeySize)
}
Expand Down

0 comments on commit 6dfc567

Please sign in to comment.