Showing posts with label ABE. Show all posts
Showing posts with label ABE. Show all posts

Thursday, December 19, 2019

在 Mac OS X Catalina 下運行 FAME

FAME (Fast Attribute-based Message Encryption) 是由 Visa 及 Microsoft 的研究人員發表的 ABE (Attribute-based Encryption) 。不論加密速度,解密速度,以及私鑰大小,均比最主流的 BSW (John Bethencourt,  Amit Sahai,  Brent Waters) 所發布的方法更快 [1]。而近年來,隨著 Functional Encryption 的概念越來越流行,FAME 的作者也使用 Charm Crypto Framework [2] 來實作了 FAME 的雛型。

由於 Charm 的範例中已經包含 FAME 的演示源碼,故以下簡介 Charm 的安裝步驟:

1. 下載 Charm Crypto 的源碼  
網址: https://github.com/JHUISI/charm

2. 安裝 OpenSSL 及 LibreSSL
輸入 brew install openssl 及 brew install libressl
再將 LibreSSL 或 OpenSSL 放入 .zshrc 中:
export LDFLAGS="-L/usr/local/opt/libressl/lib"
export CPPFLAGS="-I/usr/local/opt/libressl/include"
echo 'export PATH="/usr/local/opt/libressl/bin:$PATH"' >> ~/.zshrc

3. 按指示安裝 Charm
先 checkout dev branch,執行 ./configure --enable-darwin,再 make install 及 make test

4. 下載 FAME 原作者的 main example
https://github.com/sagrawal87/ABE

5. 執行原作者的 example
python main.py 或 python3 main.py
如果發現有問題,可改一下 ac17.py 中的第 19 行:
-from msp import MSP
+from charm.toolbox.msp import MSP
儲存後重試即可。你也可修改 debug = True ,查看詳細運作原理。


---
參考:

[1]: FAME - https://dl.acm.org/citation.cfm?doid=3133956.3134014
[2]: Charm: a framework for rapidly prototyping cryptosystems - https://link.springer.com/article/10.1007/s13389-013-0057-3

Functional Encryption 初探

近年來,Functional Encryption 越來越引起大眾的關注。不同的 Libraries 也開始以 Functional Encryption 作為構思藍本,包括 CiFErGoFE 等等。事實上,FE 的概念,早在 2005 年左右就已經出現,而 Dan Boneh 在 2010 年發布的一篇論文「Functional Encryption: Definitions and Challenges」[1] 則正式地對這個詞語下了一些定義。

Functional Encryption 的定義,主要包括以下數項 [2]:
  • 它是 Public Key Encryption 的一種(也就是非對稱加密)
  • 「滿足既定條件,就能知道內容」
    • 在傳統的 Public Key Encryption 中,「條件」只有一個,就是持有私鑰。
      而在 Functional Encryption 中, 加密者持有的,並非一對一的公鑰。
      而解密者即使持有的私鑰,也未必等於可以解開內容。

      例如 IBE 中,加密者可以根據受眾的名稱加密,
      而解密者只能解出以自己的名稱加密的內容。
      每個解密者會有不同的私鑰,但加密者卻只需要持有一套公鑰。
  • 整個加密系統可以分成四個部分:Setup / Keygen / Encrypt / Decrypt
    • Setup 是指由系統管理員產生 Public Key Parameters 及 Master Key。
      Public Key Parameters 可以公開,但 Master Key 只有系統管理員知道。
    • Keygen(或者稱為 Extract)是指使用者向系統管理員索取 Secret Key。
      管理員會按著使用者的名稱、身分等不同屬性,用 Master Key 產生一條獨特的 Secret Key 給用家。
    • Encrypt 是指加密,運用 Public Key Parameters 加上不同的屬性來加密內容。
    • Decrypt 是指解密,以私鑰來解開內容。
      只有當 Secret Key 符合 Encrypt 時的屬性,密文才能解開。
典型例子:包括 IBE,ABE 及 CP-ABE 等。

有部分人會將 FE 跟 Fully Homomorphic Encryption (FHE) 混為一談 [3] 。
事實上,兩者不互相衝突,技術上也可以同時存在,只是學者們仍未提出具體的演算法。

---
參考:

[1]: Functional Encryption: Definitions and Challenges - https://eprint.iacr.org/2010/543.pdf
[2]: Functional Encryption - http://cryptowiki.net/index.php?title=Functional_encryption
[3]: Forget Homomorphic Encryption, Here Comes Functional Encryption - https://research.kudelskisecurity.com/2019/11/25/forget-homomorphic-encryption-here-comes-functional-encryption/

Thursday, December 5, 2019

Compile CPABE Toolkit in Mac OS X 10.15.1 (Catalina)

CPABE Toolkit 是一套由 John Bethencourt 開發的 CLI 加密小工具,
主要可以用作演示和了解 CP-ABE 的運作模式。

1. 下載以下兩個 Package:
網站: http://acsc.cs.utexas.edu/cpabe/index.html
主程式: cpabe-0.11.tar.gz
函數庫: libbswabe-0.9.tar.gz

2. 確保已經安裝 OpenSSL, NTL Library, GLib:
OpenSSL 可以通過 brew install openssl 安裝。
GLib 則可以通過 brew install glib 安裝。
NTL 可以由 https://www.shoup.net/ntl/download.html 下載。
NTL 安裝教學: https://www.shoup.net/ntl/doc/tour-unix.html (很簡單的)

3. 編譯及安裝 PBC:
https://crypto.stanford.edu/pbc/files/pbc-0.5.14.tar.gz 下載 PBC
執行 tar zxf pbc-0.5.14.tar.gz 解開封包,然後 cd pbc-0.5.14
然後執行  ./configure ,make 和 sudo make install

3. 編譯及安裝 libbswabe:
執行 tar zxf libbswabe-0.9.tar.gz 解開封包,然後 cd libbswabe-0.9 
執行 ./configure CFLAGS="-I/usr/local/opt/openssl@1.1/include" LIBS="-L/usr/local/opt/openssl@1.1/lib"
執行 make CFLAGS="-I/usr/local/opt/glib/include/glib-2.0 -I/usr/local/opt/glib/lib/glib-2.0/include -I/usr/local/include/pbc"
最後 sudo make install

4. 編譯及安裝 cpabe:
執行 tar zxf cpabe-0.11.tar.gz,然後 cd pbc-0.5.14
執行 ./configure CFLAGS="-I/usr/local/opt/openssl@1.1/include -I/usr/local/include" LIBS="-L/usr/local/opt/openssl@1.1/lib -L/usr/local/lib"
最後執行 make 及 sudo make install

如果一切順利,可以 Cmd+N 開一個新的 Terminal,然後查看 which cpabe-setup。
成功的話,會看到它返回 /usr/local/bin/cpabe-setup

5. 小記
在 Catalina 中,這個 Project 需要更改以下兩行:
diff --git a/policy_lang.c b/policy_lang.c
index 7b7672a..2351ea9 100644
--- a/policy_lang.c
+++ b/policy_lang.c
@@ -1942,14 +1942,14 @@ cmp_policy( sized_integer_t* n, int gt, char* attr )

     /* some error checking */

-    if( gt && n->value >= ((uint64_t)1<<(n->bits ? n->bits : 64)) - 1 )
+    if( gt && n->value >= (n->bits ? (((uint64_t)1<<(n->bits))-1) : UINT64_MAX) )
         die("error parsing policy: unsatisfiable integer comparison %s > %llu\n"
                 "(%d-bits are insufficient to satisfy)\n", attr, n->value,
                 n->bits ? n->bits : 64);
     else if( !gt && n->value == 0 )
         die("error parsing policy: unsatisfiable integer comparison %s < 0\n"
                 "(all numerical attributes are unsigned)\n", attr);
-    else if( !gt && n->value > ((uint64_t)1<<(n->bits ? n->bits : 64)) - 1 )
+    else if( !gt && n->value > (n->bits ? (((uint64_t)1<<(n->bits))-1) : UINT64_MAX) )
         die("error parsing policy: trivially satisfied integer comparison %s < %llu\n"
                 "(any %d-bit number will satisfy)\n", attr, n->value,
                 n->bits ? n->bits : 64);

Monday, November 18, 2019

初探 KP-ABE 和 CP-ABE

ABE (Attribute Based Encryption) 是在大約 2000 年左右冒起的新寵。
基本運作原理,是利用 IBE 的方法,以一堆不同的 attributes 去加密文件。
而近年有兩大分類,主要是 KP-ABE 和 CP-ABE:

---

"In a key-policy attribute-based encryption (KP-ABE) system, ciphertexts are labeled by the sender with a set of descriptive attributes, while user's private key is issued by the trusted attribute authority captures an policy (also called the access structure) that specifies which type of ciphertexts the key can decrypt. KP-ABE schemes are suitable for structured organizations with rules about who may read particular documents. Typical applications of KP-ABE include secure forensic analysis and target broadcast [5]. For example, in a secure forensic analysis system, audit log entries could be annotated with attributes such as the name of the user, the date and time of the user action, and the type of data modified or accessed by the user action. While a forensic analyst charged with some investigation would be issued a private key that associated with a particular access structure. The private key would only open audit log records whose attributes satisfied the access policy associated with the private key.

In a ciphertext-policy attribute-based encryption (CP-ABE) system, when a sender encrypts a message, they specify a specific access policy in terms of access structure over attributes in the ciphertext, stating what kind of receivers will be able to decrypt the ciphertext. Users possess sets of attributes and obtain corresponding secret attribute keys from the attribute authority. Such a user can decrypt a ciphertext if his/her attributes satisfy the access policy associated with the ciphertext. Thus, CP-ABE mechanism is conceptually closer to traditional role-based access control method." [1]

---

換句話說,KP-ABE (Key Policy) 的加密者,用一堆 attributes 去加密文件,
然後有個中間人會訂立 policy,再分發具 policy 的 private keys 給不同人。
例如加密者用 "pay_user" 這個 attribute 去加密,然後 policy 可以是 {pay_user, free_user, tom...} 等等,任由中間人決定。
加密者只知道符合 attributes 的人可以解密,但不能預知解密者的全個 policy + attributes 是什麼。

KP-ABE 密文中會有 attributes [2],
所以如果解密者見到密文,而手中沒有符合該 attributes 的 private key 的話,就解都廢事了。

這種加密法,較常在付費服務等情況應用。

---

而 CP-ABE 則不同。加密者定義了整個 access structure (policy + attributes),
中間人的作用只是 based on the policy,分發不同 private keys 給不同人。
情況有點像建立一棵 private key tree,不同 matching 會有不同 private keys。
換句話說,加密者基本上預知到,有什麼種類的人,而且當中有誰可以解密文件。

CP-ABE 密文 (Cipher Text) 中會有整個 access structure [3],
所以如果解密者見到密文,而手中沒有符合該 structure + attributes 的 private key 的話,就解都廢事了。

這種加密法,較常在文件分享等情況應用。

---

Reference:
[1] Changji Wang and Jianfa Luo, “An Efficient Key-Policy Attribute-Based Encryption Scheme with Constant Ciphertext Length,” Mathematical Problems in Engineering, vol. 2013, Article ID 810969, 7 pages, 2013. https://doi.org/10.1155/2013/810969.

[2] https://eprint.iacr.org/2006/309.pdf

[3] https://hal.archives-ouvertes.fr/hal-01788815/document

https://asecuritysite.com/public/cpabe.pdf