Skip to content

Commit 5dda9f0

Browse files
committed
tkn20: change seed size for MAC key from 128->448 bits in accordance with BK paper
1 parent 7cdab52 commit 5dda9f0

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

abe/cpabe/tkn20/internal/tkn/bk.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
// https://www.iacr.org/archive/pkc2011/65710074/65710074.pdf that
1414
// apply the Boneh-Katz transform to Attribute based encryption.
1515

16+
const macKeySeedSize = 56
17+
1618
func blakeEncrypt(key []byte, msg []byte) ([]byte, error) {
1719
xof, err := blake2b.NewXOF(blake2b.OutputLengthUnknown, key)
1820
if err != nil {
@@ -70,7 +72,7 @@ func DeriveAttributeKeysCCA(rand io.Reader, sp *SecretParams, attrs *Attributes)
7072
}
7173

7274
func EncryptCCA(rand io.Reader, public *PublicParams, policy *Policy, msg []byte) ([]byte, error) {
73-
seed := make([]byte, 16)
75+
seed := make([]byte, macKeySeedSize)
7476
_, err := rand.Read(seed)
7577
if err != nil {
7678
return nil, err
@@ -173,12 +175,12 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) {
173175
if err != nil {
174176
return nil, err
175177
}
176-
if len(decEnv) < 16 {
178+
if len(decEnv) < macKeySeedSize {
177179
return nil, fmt.Errorf("envelope too short")
178180
}
179181

180-
seed := decEnv[0:16]
181-
ptx := make([]byte, len(decEnv)-16)
182+
seed := decEnv[0:macKeySeedSize]
183+
ptx := make([]byte, len(decEnv)-macKeySeedSize)
182184
compID, macKey, err := expandSeed(seed)
183185
if err != nil {
184186
return nil, err
@@ -194,7 +196,7 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) {
194196
idMatch := subtle.ConstantTimeCompare(compID, id)
195197
check := tagMatch & idMatch
196198
if check == 1 {
197-
copy(ptx, decEnv[16:])
199+
copy(ptx, decEnv[macKeySeedSize:])
198200
return ptx, nil
199201
}
200202
return nil, fmt.Errorf("failure of decryption")

abe/cpabe/tkn20/testdata/attributeKey

0 Bytes
Binary file not shown.

abe/cpabe/tkn20/testdata/ciphertext

40 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)