diff --git a/abe/cpabe/tkn20/internal/tkn/bk.go b/abe/cpabe/tkn20/internal/tkn/bk.go index 20604a08..9be630a0 100644 --- a/abe/cpabe/tkn20/internal/tkn/bk.go +++ b/abe/cpabe/tkn20/internal/tkn/bk.go @@ -13,6 +13,8 @@ import ( // https://www.iacr.org/archive/pkc2011/65710074/65710074.pdf that // apply the Boneh-Katz transform to Attribute based encryption. +const macKeySeedSize = 72 + func blakeEncrypt(key []byte, msg []byte) ([]byte, error) { xof, err := blake2b.NewXOF(blake2b.OutputLengthUnknown, key) if err != nil { @@ -70,7 +72,7 @@ func DeriveAttributeKeysCCA(rand io.Reader, sp *SecretParams, attrs *Attributes) } func EncryptCCA(rand io.Reader, public *PublicParams, policy *Policy, msg []byte) ([]byte, error) { - seed := make([]byte, 16) + seed := make([]byte, macKeySeedSize) _, err := rand.Read(seed) if err != nil { return nil, err @@ -173,12 +175,12 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) { if err != nil { return nil, err } - if len(decEnv) < 16 { + if len(decEnv) < macKeySeedSize { return nil, fmt.Errorf("envelope too short") } - seed := decEnv[0:16] - ptx := make([]byte, len(decEnv)-16) + seed := decEnv[0:macKeySeedSize] + ptx := make([]byte, len(decEnv)-macKeySeedSize) compID, macKey, err := expandSeed(seed) if err != nil { return nil, err @@ -194,7 +196,7 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) { idMatch := subtle.ConstantTimeCompare(compID, id) check := tagMatch & idMatch if check == 1 { - copy(ptx, decEnv[16:]) + copy(ptx, decEnv[macKeySeedSize:]) return ptx, nil } return nil, fmt.Errorf("failure of decryption") diff --git a/abe/cpabe/tkn20/testdata/attributeKey b/abe/cpabe/tkn20/testdata/attributeKey index 4b37c6f0..4658f656 100644 Binary files a/abe/cpabe/tkn20/testdata/attributeKey and b/abe/cpabe/tkn20/testdata/attributeKey differ diff --git a/abe/cpabe/tkn20/testdata/ciphertext b/abe/cpabe/tkn20/testdata/ciphertext index a7404fe1..922cf191 100644 Binary files a/abe/cpabe/tkn20/testdata/ciphertext and b/abe/cpabe/tkn20/testdata/ciphertext differ