1. 引言
使用 CP-ABE(Cipher Policy — Attributed-Based Encryption,密文策略-基于属性的加密),可以根据策略和一组属性生成加密密钥。Shashank Agrawal 和 Melissa Chase 2017年论文《FAME: Fast Attribute-based Message Encryption》(发表于 2017 ACM SIGSAC Conference)中所提出的FAME算法,就是一种CP-ABE。
FAME 使用Type-III pairing groups(如 BNS256),这是最有效的密码学配对。FAME具有以下主要特点:
- 对策略或属性集的大小没有限制。
- 允许将任意字符串用作属性。
- 仅需少量的配对即可解密。
- 在标准硬度假设下满足自然安全性要求。
通过FAME,可创建一个密文策略以及一个公钥对:
a := abe.NewFAME ( )
// 密钥对
pk, sk, err := a.GenerateMasterKeys ( )
接下来,可实施策略来生成 MSP(monotone span programs,单调跨度程序):
policy:="((Edinburgh AND NHS) OR (Glasgow AND SOCIAL)) AND GOV"
msp, err := abe.BooleanToMSP(policy, false)
在这种情况下,需要证明是“Edinburgh and part of the NHS”,或者“ Glasgow and part of social care (SOCIAL)”。除此之外,还需要证明“part of the government (GOV)”。然后可以使用该公钥和该策略加密一条消息 (msg):
cipher, err := a.Encrypt(msg, msp, pk)
该密文只能使用私钥和正确的属性才能解密:
gamma := strings.Split(attributes, " ")
keys, err := a.GenerateAttribKeys(gamma, sk)
msgCheck, err := a.Decrypt(cipher, keys, pk)
完整代码见https://asecuritysite.com/abe/go_abe02:
package main
import (
"fmt"
"os"
"github.com/fentec-project/gofe/abe"
"strings"
)
func main() {
policy:="((Edinburgh AND NHS) OR (Glasgow AND SOCIAL)) AND GOV"
attributes:="Edinburgh NHS Glasgow GOV"
msg:="Hello"
argCount := len(os.Args[1:])
if (argCount>0) { msg= (os.Args[1]) }
if (argCount>1) { policy= (os.Args[2]) }
if (argCount>2) { attributes= (os.Args[3]) }
a := abe.NewFAME()
// Key Pair
pk, sk, err := a.GenerateMasterKeys()
if err != nil {
fmt.Printf("Failed to generate master keys: %v", err)
}
msp, err := abe.BooleanToMSP(policy, false)
if err != nil {
fmt.Printf("Failed to generate the policy: %v", err)
}
cipher, err := a.Encrypt(msg, msp, pk)
if err != nil {
fmt.Printf("Failed to encrypt: %v", err)
}
gamma := strings.Split(attributes, " ")
// generate keys for decryption for an entity with attributes
keys, err := a.GenerateAttribKeys(gamma, sk)
if err != nil {
fmt.Printf("Failed to generate keys: %v", err)
}
// decrypt the ciphertext
msgRecovered, err := a.Decrypt(cipher, keys, pk)
if err != nil {
fmt.Printf("Failed to decrypt: %v", err)
}
fmt.Printf("Attributes: %v\nPolicy %v\n\n",attributes,policy)
fmt.Printf("Message: %v\nRecovered %v",msg, msgRecovered)
}
对于正确的属性,有:
Attributes: Edinburgh Glasgow GOV
Policy (Edinburgh OR Glasgow) AND GOV
Message: Hello
Recovered Hello
对于不正确的属性,有:
Failed to decrypt: provided key is not sufficient for decryption
Attributes: Edinburgh Glasgow
Policy (Edinburgh OR Glasgow) AND GOV
Message: Hello
Recovered
其它示例有:
- 消息:“Hello”。属性:[Edinburgh Glasgow GOV]。策略:(Edinburgh OR Glasgow) AND GOV。
- 消息:“Hello”。属性:[Edinburgh Glasgow]。策略:(Edinburgh OR Glasgow) AND GOV。
- 消息:“Hello”。属性:[Bob Production]。策略:(Bob AND Production) OR (Alice AND SALES)。
- 消息:“Hello”。属性:[Bob SALES]。策略:(Bob AND Production) OR (Alice AND SALES)。
- 消息:“Hello”。属性:[Alice SALES]。策略:(Bob AND Production) OR (Alice AND SALES)。
参考资料
[1] Prof Bill Buchanan OBE FRSE 2024年11月18日博客 FAME and Enhanced Attributed-Based Security