Browse Source

stupidgcm: normalize constructor naming

New() -> NewAES256GCM()

Also add missing NewChacha20poly1305
constructor in without_openssl.go.
master
Jakob Unterwurzacher 10 months ago
parent
commit
85c2beccaf
  1. 2
      internal/cryptocore/cryptocore.go
  2. 2
      internal/speed/speed.go
  3. 2
      internal/speed/speed_test.go
  4. 2
      internal/stupidgcm/chacha.go
  5. 4
      internal/stupidgcm/gcm.go
  6. 2
      internal/stupidgcm/gcm_test.go
  7. 11
      internal/stupidgcm/without_openssl.go
  8. 4
      internal/stupidgcm/xchacha.go

2
internal/cryptocore/cryptocore.go

@ -120,7 +120,7 @@ func New(key []byte, aeadType AEADTypeEnum, IVBitLen int, useHKDF bool, forceDec
if IVBitLen != 128 {
log.Panicf("stupidgcm only supports 128-bit IVs, you wanted %d", IVBitLen)
}
aeadCipher = stupidgcm.New(gcmKey, forceDecode)
aeadCipher = stupidgcm.NewAES256GCM(gcmKey, forceDecode)
case BackendGoGCM:
goGcmBlockCipher, err := aes.NewCipher(gcmKey)
if err != nil {

2
internal/speed/speed.go

@ -116,7 +116,7 @@ func bStupidGCM(b *testing.B) {
if stupidgcm.BuiltWithoutOpenssl {
b.Skip("openssl has been disabled at compile-time")
}
bEncrypt(b, stupidgcm.New(randBytes(32), false))
bEncrypt(b, stupidgcm.NewAES256GCM(randBytes(32), false))
}
// bGoGCM benchmarks Go stdlib GCM

2
internal/speed/speed_test.go

@ -31,7 +31,7 @@ func BenchmarkStupidGCMDecrypt(b *testing.B) {
if stupidgcm.BuiltWithoutOpenssl {
b.Skip("openssl has been disabled at compile-time")
}
bDecrypt(b, stupidgcm.New(randBytes(32), false))
bDecrypt(b, stupidgcm.NewAES256GCM(randBytes(32), false))
}
func BenchmarkGoGCM(b *testing.B) {

2
internal/stupidgcm/chacha.go

@ -37,7 +37,7 @@ func init() {
// block by XChaCha20-Poly1305.
//
// Only 32-bytes keys and 12-byte IVs are supported.
func NewChacha20poly1305(key []byte) *stupidChacha20poly1305 {
func NewChacha20poly1305(key []byte) cipher.AEAD {
if len(key) != chacha20poly1305.KeySize {
log.Panicf("Only %d-byte keys are supported, you passed %d bytes", chacha20poly1305.KeySize, len(key))
}

4
internal/stupidgcm/gcm.go

@ -23,10 +23,10 @@ type stupidGCM struct {
stupidAEADCommon
}
// New returns a new AES-GCM-256 cipher that satisfies the cipher.AEAD interface.
// NewAES256GCM returns a new AES-256-GCM cipher that satisfies the cipher.AEAD interface.
//
// Only 32-bytes keys and 16-byte IVs are supported.
func New(keyIn []byte, forceDecode bool) cipher.AEAD {
func NewAES256GCM(keyIn []byte, forceDecode bool) cipher.AEAD {
if len(keyIn) != keyLen {
log.Panicf("Only %d-byte keys are supported", keyLen)
}

2
internal/stupidgcm/gcm_test.go

@ -13,7 +13,7 @@ import (
func TestStupidGCM(t *testing.T) {
key := randBytes(32)
sGCM := New(key, false)
sGCM := NewAES256GCM(key, false)
gAES, err := aes.NewCipher(key)
if err != nil {

11
internal/stupidgcm/without_openssl.go

@ -11,19 +11,22 @@ import (
"github.com/rfjakob/gocryptfs/v2/internal/exitcodes"
)
type StupidGCM struct{}
const (
// BuiltWithoutOpenssl indicates if openssl been disabled at compile-time
BuiltWithoutOpenssl = true
)
func errExit() {
fmt.Fprintln(os.Stderr, "gocryptfs has been compiled without openssl support but you are still trying to use openssl")
fmt.Fprintln(os.Stderr, "I have been compiled without openssl support but you are still trying to use openssl")
os.Exit(exitcodes.OpenSSL)
}
func New(_ []byte, _ bool) cipher.AEAD {
func NewAES256GCM(_ []byte, _ bool) cipher.AEAD {
errExit()
return nil
}
func NewChacha20poly1305(_ []byte) cipher.AEAD {
errExit()
return nil
}

4
internal/stupidgcm/xchacha.go

@ -70,7 +70,7 @@ func (x *stupidXchacha20poly1305) Seal(dst, nonce, plaintext, additionalData []b
}
hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16])
c := NewChacha20poly1305(hKey)
c := NewChacha20poly1305(hKey).(*stupidChacha20poly1305)
defer c.Wipe()
// The first 4 bytes of the final nonce are unused counter space.
@ -95,7 +95,7 @@ func (x *stupidXchacha20poly1305) Open(dst, nonce, ciphertext, additionalData []
}
hKey, _ := chacha20.HChaCha20(x.key[:], nonce[0:16])
c := NewChacha20poly1305(hKey)
c := NewChacha20poly1305(hKey).(*stupidChacha20poly1305)
defer c.Wipe()
// The first 4 bytes of the final nonce are unused counter space.

Loading…
Cancel
Save