Showing posts with label CP-ABE. Show all posts
Showing posts with label CP-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);