Update go-hpke-compact

This commit is contained in:
Frank Denis 2021-06-07 18:11:58 +02:00
parent 45d3afc8f9
commit 72a354caf9
6 changed files with 30 additions and 8 deletions

View file

@ -126,4 +126,10 @@ secret1, err := clientCtx.Export("description 1")
secret2, err := serverCtx.Export("description 2");
```
### Access the raw cipher interface
```go
cipher, err := suite.NewRawCipher(key)
```
## That's it!

View file

@ -4,5 +4,5 @@ go 1.16
require (
github.com/powerman/check v1.3.1
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a
)

View file

@ -508,6 +508,22 @@ func (suite *Suite) NewAuthenticatedServerContext(clientPk []byte, enc []byte, s
return ServerContext{inner: context}, nil
}
// NewRawCipher - Access the raw cipher interface
func (suite *Suite) NewRawCipher(key []byte) (cipher.AEAD, error) {
switch suite.AeadID {
case AeadAes128Gcm, AeadAes256Gcm:
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
return cipher.NewGCM(block)
case AeadChaCha20Poly1305:
return chacha20poly1305.New(key)
default:
return nil, errors.New("externally defined cipher")
}
}
func (state *aeadState) incrementCounter() error {
carry := uint16(1)
for i := len(state.counter); ; {
@ -624,11 +640,11 @@ type aeadAesImpl struct {
func newAesAead(key []byte) (aeadAesImpl, error) {
block, err := aes.NewCipher(key)
if err != nil {
return aeadAesImpl{}, nil
return aeadAesImpl{}, err
}
aesGcm, err := cipher.NewGCM(block)
if err != nil {
return aeadAesImpl{}, nil
return aeadAesImpl{}, err
}
aead := aeadAesImpl{impl: aesGcm}
return aead, nil
@ -645,7 +661,7 @@ type aeadChaChaPolyImpl struct {
func newChaChaPolyAead(key []byte) (aeadChaChaPolyImpl, error) {
impl, err := chacha20poly1305.New(key)
if err != nil {
return aeadChaChaPolyImpl{}, nil
return aeadChaChaPolyImpl{}, err
}
aead := aeadChaChaPolyImpl{impl: impl}
return aead, nil