Skip to content

Commit 74436aa

Browse files
authored
tkn20: change seed size for MAC key from 128->576 bits in accordance with BK paper (#394)
1 parent 7cdab52 commit 74436aa

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

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

16+
// Seed size is chosen based on the proof for BK transform
17+
// (https://eprint.iacr.org/2004/261.pdf - page 12, theorem 2) to maintain the
18+
// statistical hiding property. Their input is 448 bits -> 128 bits,
19+
// whereas we require a seed size of 576 bits to ensure a 2^(-65) statistical difference
20+
// for our output size of 256 bits.
21+
const macKeySeedSize = 72
22+
1623
func blakeEncrypt(key []byte, msg []byte) ([]byte, error) {
1724
xof, err := blake2b.NewXOF(blake2b.OutputLengthUnknown, key)
1825
if err != nil {
@@ -70,7 +77,7 @@ func DeriveAttributeKeysCCA(rand io.Reader, sp *SecretParams, attrs *Attributes)
7077
}
7178

7279
func EncryptCCA(rand io.Reader, public *PublicParams, policy *Policy, msg []byte) ([]byte, error) {
73-
seed := make([]byte, 16)
80+
seed := make([]byte, macKeySeedSize)
7481
_, err := rand.Read(seed)
7582
if err != nil {
7683
return nil, err
@@ -173,12 +180,12 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) {
173180
if err != nil {
174181
return nil, err
175182
}
176-
if len(decEnv) < 16 {
183+
if len(decEnv) < macKeySeedSize {
177184
return nil, fmt.Errorf("envelope too short")
178185
}
179186

180-
seed := decEnv[0:16]
181-
ptx := make([]byte, len(decEnv)-16)
187+
seed := decEnv[0:macKeySeedSize]
188+
ptx := make([]byte, len(decEnv)-macKeySeedSize)
182189
compID, macKey, err := expandSeed(seed)
183190
if err != nil {
184191
return nil, err
@@ -194,7 +201,7 @@ func DecryptCCA(ciphertext []byte, key *AttributesKey) ([]byte, error) {
194201
idMatch := subtle.ConstantTimeCompare(compID, id)
195202
check := tagMatch & idMatch
196203
if check == 1 {
197-
copy(ptx, decEnv[16:])
204+
copy(ptx, decEnv[macKeySeedSize:])
198205
return ptx, nil
199206
}
200207
return nil, fmt.Errorf("failure of decryption")

abe/cpabe/tkn20/testdata/attributeKey

0 Bytes
Binary file not shown.

abe/cpabe/tkn20/testdata/ciphertext

56 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)