【Miracl密碼庫(kù)】AKE密碼分析(Authenticated key exchange)
復(fù)制到這里排版有些混亂,可在公眾號(hào)查看原文。
【Miracl密碼庫(kù)】AKE的實(shí)現(xiàn)(ake.cpp)
上一篇已經(jīng)分析了ake.cpp文件的測(cè)試,這一篇繼續(xù)分析AKE的原理,以及在Miracl密碼庫(kù)上實(shí)現(xiàn)的過(guò)程。
@misc{cryptoeprint:2002/164,
? ? ?author = {Mike Scott},
? ? ?title = {Authenticated ID-based Key Exchange and remote log-in with simple token and PIN number},
? ? ?howpublished = {Cryptology ePrint Archive, Paper 2002/164},
? ? ?year = {2002},
? ? ?note = {\url{https://eprint.iacr.org/2002/164}},
? ? ?url = {https://eprint.iacr.org/2002/164}
}
下面來(lái)分析文章
Authenticated ID-based Key Exchange and remote log-in with simple token and PIN

AKE一般基于token或者密碼實(shí)現(xiàn),基于token的方案一般基于昂貴的智能卡,但基于密鑰的方案要求通信雙方共用一把獨(dú)一無(wú)二的密鑰。本文借助磁條卡與PIN設(shè)計(jì)AKE。
協(xié)議方案

密鑰的構(gòu)成包括token中的N和PIN,密鑰D本身是一個(gè)集合中的大數(shù)。

認(rèn)證方有master secret --> s
H(ID) --> EC
Alice --> (H(ID),EC(A)) 也即Alice有ID在EC上的映射點(diǎn)A
Alice有A和PIN(a)
Alice發(fā)送ID到認(rèn)證方注冊(cè),接收認(rèn)證方返回的A和sA,Alice計(jì)算aA,存儲(chǔ)A和(s-a)A,通過(guò)sA=(s-a)A+aA求出來(lái)。在DL問(wèn)題下,Alice是不能通過(guò)sA求出s的。
在這個(gè)過(guò)程中,Alice用自己的ID在認(rèn)證方完成注冊(cè),得到與ID相關(guān)的哈希值A(chǔ)。同時(shí),認(rèn)證方用密鑰s對(duì)A進(jìn)行加密。Alice可以自己選擇一個(gè)PIN值a,然后計(jì)算aA,作為混淆的因子。Alice并沒(méi)有直接將sA存儲(chǔ)在硬件中,而是存儲(chǔ)帶有PIN的差值(s-a)A,其中a是Alice自己能夠記住的PIN值。

需要注意的是,為a設(shè)置一個(gè)增量,不會(huì)影響sA=(s-a)A+aA的驗(yàn)證。
(s + δ)A = (s ? α)A + (α + δ)A
這也就意味著,即使攻擊者能夠產(chǎn)生很多的token,但與Alice擁有的PIN(a)不同,攻擊者依然不能區(qū)分PIN。
密鑰交換協(xié)議

認(rèn)證方生成一個(gè)512位的質(zhì)數(shù)p,使得p ≡ 3 mod 4,其中p + 1 = c.r,其中 r 為160位的質(zhì)數(shù),選擇一個(gè)合適的哈希函數(shù)H,將ID通過(guò)哈希函數(shù)H映射到EC上,公布公共參數(shù){p,r,H},s為160位的密鑰。

對(duì)于用戶方,需要在認(rèn)證方注冊(cè),注冊(cè)的時(shí)候,提供用戶ID。注冊(cè)之后,用戶能夠獲得認(rèn)證方提供的token和密鑰,其中token為I,密鑰為sI。用戶在硬件上存儲(chǔ)token和(s ? ρ)I,其中ρ是用戶自己選擇的PIN值。
模擬一個(gè)密鑰交互協(xié)議

Alice和Bob分別選擇一個(gè)隨機(jī)值,交換雙方的ID,哈希對(duì)方的ID。
Alice用自己的 αA 映射對(duì)方ID的哈希值到EC,Bob同樣操作,然后交換
在EC上校驗(yàn)雙方ID的哈希值
AKE協(xié)議實(shí)現(xiàn)分析
【Miracl密碼庫(kù)】AKE的實(shí)現(xiàn)(ake.cpp)
上一篇復(fù)現(xiàn)了AKE源碼,沒(méi)有對(duì)源碼進(jìn)行分析,下面來(lái)看AKE實(shí)現(xiàn)的過(guò)程。
在 ake.cpp 中,實(shí)現(xiàn)了5種不同 EC 上的 AKE,以 MR_PAIRING_BLS 為例進(jìn)行分析。
// #define MR_PAIRING_CP ? ? ?// AES-80 security ?
// #define AES_SECURITY 80
// #define MR_PAIRING_MNT ?// AES-80 security
// #define AES_SECURITY 80
// #define MR_PAIRING_BN ? ?// AES-128 or AES-192 security
// #define AES_SECURITY 128
// #define AES_SECURITY 192
// #define MR_PAIRING_KSS ? ?// AES-192 security
// #define AES_SECURITY 192
#define MR_PAIRING_BLS ? ?// AES-256 security
#define AES_SECURITY 256
1、包含 pairing_3.h 頭文件,表示用的是 Type 3?pairings。在?pairing_3.h 中,包含相應(yīng)的頭文件和定義相應(yīng)的常量
#include "ecn.h" ?// G1
// k=24 BLS curve
#ifdef MR_PAIRING_BLS
#include "ecn4.h" ?// G2
#include "zzn24.h" ?// GT
#define WINDOW_SIZE 8 // window size for precomputation
#define G2_TYPE ECn4
#define G2_SUBTYPE ZZn4
#define GT_TYPE ZZn24
#define FROB_TYPE ZZn2
#endif
2、源碼分析
// 初始化一個(gè)PFC (pairing-friendly curve) 對(duì)象 pfc
?PFC pfc(AES_SECURITY); ?// initialise pairing-friendly curve
?time_t seed; // 臨時(shí)變量
?G1 Alice,Bob,sA,sB;
? ?G2 B6,Server,sS;
?GT res,sp,ap,bp;
?Big ss,s,a,b;
? ?time(&seed); // 獲得一個(gè)時(shí)間,作為種子
? ?irand((long)seed); // 以時(shí)間作為種子,生成隨機(jī)數(shù)
? ?// 生成一個(gè) Big 類型的隨機(jī)數(shù)作為 TA 的密鑰
? ?pfc.random(ss); ? ?// TA's super-secret ss
? ?// 將 Server 的信息映射到群 G2 上
? ?cout << "Mapping Server ID to point" << endl;
?pfc.hash_and_map(Server,(char *)"Server"); // S = Server = H("")
?// 將 Alice 和 Bob 的 ID 都映射到 G1 上
? ?cout << "Mapping Alice & Bob ID's to points" << endl;
? ?pfc.hash_and_map(Alice,(char *)"Alice"); // A = Alice = H("")
? ?pfc.hash_and_map(Bob,(char *)"Robert"); // B = Bob = H("")
? ?cout << "Alice, Bob and the Server visit Trusted Authority" << endl;
? ?// sS = ss * S, sA = ss * A, sB = ss * B
? ?sS=pfc.mult(Server,ss); // G2 mult(const G2&,const Big&);
?sA=pfc.mult(Alice,ss); // G1 mult(const G1&,const Big&);
? ?sB=pfc.mult(Bob,ss);
? ?cout << "Alice and Server Key Exchange" << endl;
? ?pfc.random(a); ?// Alice's random number PIN(a)
? ?pfc.random(s); ? // Server's random number PIN(s)
? ?// e(S, ss * A)
? ?// Server 的 S 與 Alice 的 sA 在 EC 上的映射
?res=pfc.pairing(Server,sA); // GT pairing(const G2&,const G1&);
?// 如果配對(duì)結(jié)果為 0,則表示群的階數(shù)不對(duì)
?if (!pfc.member(res))
? ?{
? ? ? ?cout << "Wrong group order - aborting" << endl;
? ? ? ?exit(0);
? ?}
?// ap = e(S, ss * A)^a
?ap=pfc.power(res,a); // GT power(const GT&,const Big&);
?// e(ss * S, A)
?res=pfc.pairing(sS,Alice);
? ? if (!pfc.member(res))
? ?{
? ? ? ?cout << "Wrong group order - aborting" << endl;
? ? ? ?exit(0);
? ?}
? ?// sp = e(ss * S, A)^s
?sp=pfc.power(res,s);
?// e(ss * S, A)^sa
? ?cout << "Alice ?Key= " << pfc.hash_to_aes_key(pfc.power(sp,a)) << endl;
? ?// e(S, ss * A)^as
? ?cout << "Server Key= " << pfc.hash_to_aes_key(pfc.power(ap,s)) << endl;
? ?cout << "Bob and Server Key Exchange" << endl;
? ?pfc.random(b); ? // Bob's random number
? ?pfc.random(s); ? // Server's random number
?res=pfc.pairing(Server,sB);
? ?if (!pfc.member(res))
? ?{
? ? ? ?cout << "Wrong group order - aborting" << endl;
? ? ? ?exit(0);
? ?}
? ?bp=pfc.power(res,b);
?res=pfc.pairing(sS,Bob);
? ?if (!pfc.member(res))
? ?{
? ? ? ?cout << "Wrong group order - aborting" << endl;
? ? ? ?exit(0);
? ?}
? ?sp=pfc.power(res,s);
? ?cout << "Bob's ?Key= " << pfc.hash_to_aes_key(pfc.power(sp,b)) << endl;
? ?cout << "Server Key= " << pfc.hash_to_aes_key(pfc.power(bp,s)) << endl;
2-1、初始化一個(gè)橢圓曲線
PFC pfc(AES_SECURITY); ?// initialise pairing-friendly curve
2-2、初始化一個(gè)系統(tǒng)密鑰ss
time_t seed;
time(&seed);
irand((long)seed);
pfc.random(ss);
2-3、對(duì)Server的ID哈希,并對(duì)Server的ID的哈希值加密sS = ss * S,Server生成一個(gè)PIN值s,用自己的sS與Alice的sA做橢圓曲線上的映射e(ss * S, A)
pfc.hash_and_map(Server,(char *)"Server");
sS=pfc.mult(Server,ss);
pfc.random(s);
res=pfc.pairing(sS,Alice);
2-4、Alice做同樣的操作,這個(gè)過(guò)程中,雙方交換了ID
pfc.hash_and_map(Alice,(char *)"Alice");
sA=pfc.mult(Alice,ss);
pfc.random(a);
res=pfc.pairing(Server,sA);
2-5、Server與Alice校驗(yàn)雙方的信息
// e(ss * S, A)^sa
cout?<<?"Alice??Key=?"?<<?pfc.hash_to_aes_key(pfc.power(sp,a))?<<?endl;
// e(S, ss * A)^as
cout << "Server Key= " << pfc.hash_to_aes_key(pfc.power(ap,s)) << endl;
2-6、Server與Bob完成相同的操作
2-7、測(cè)試
% ./ake
Mapping Server ID to point
Mapping Alice & Bob ID's to points
Alice, Bob and the Server visit Trusted Authority
Alice and Server Key Exchange
Alice ?Key= 586308FF2AAEB5CCFE49E7BAF1DE93A62E0CFCA1F7EC07444116B93812B7EC64
Server Key= 586308FF2AAEB5CCFE49E7BAF1DE93A62E0CFCA1F7EC07444116B93812B7EC64
Bob and Server Key Exchange
Bob's ?Key= 9240B8A3170C8F830385FEB5065F4D4EE47762D6BEF36C7634D62F3884F3CBE5
Server Key= 9240B8A3170C8F830385FEB5065F4D4EE47762D6BEF36C7634D62F3884F3CBE5
從測(cè)試結(jié)果可知,Alice與Server的密鑰是相同的,Server與Bob的密鑰是相同的。
函數(shù)說(shuō)明
1、將一個(gè)字符串哈希到群上,H(string)
void hash_and_map(G1&,char *);
void hash_and_map(G2&,char *);
2、群上的元素做乘法運(yùn)算,sA,A為群上的元素,調(diào)用pfc.mult()
G1 mult(const G1&,const Big&);
G2 mult(const G2&,const Big&);
3、生成隨機(jī)元,調(diào)用pfc.random(a)
void random(Big&);
?void random(G1&);
?void random(G2&);
4、雙線性映射,e(A,B),調(diào)用pfc.pairing()
GT pairing(const G2&,const G1&);
5、橢圓曲線上點(diǎn)的加法,e(A,B)^x,調(diào)用pfc.power()
GT power(const GT&,const Big&);
6、將群上的點(diǎn)映射為哈希值
Big hash_to_aes_key(const GT&);
歡迎留言討論