Skip to main content

簡介

  • 此repository密碼學部分沒有使用外部crypt library,在Evaluate使用matplotlib進行畫圖資料分析。
  • 此密碼學方法為我的碩士論文實作,source code有快比原始碼還長的註解可進行參考。
  • 此package比較著重在觀察密碼學運作流程,未進行完整優化和正規化,不建議使用在production環境當中。

注意事項

  • 開發版本:python 3.12.4
  • 外部引用:random、hashlib、base64、matplotlib

安裝方法

可以直接在cmd透過pip進行安裝:

>>> pip install ShiXunChameleon

SIS碰撞

此package包含基本的SIS碰撞函式,首先定義SIS基本參數n、q、sigma。其中n是向量維度、q是質數、l在實作SIS碰撞中不會用到隨意指定即可、sigma是取高斯矩陣時的標準差。經過實驗建議sigma取0.35。

config.set_parameter(n=3, q=13, l=len(ID), sigma=0.3)

使用gen_A_with_trapdoor生成帶有trapdoor的矩陣A:

A, R = BasicSIS.gen_A_with_trapdoor()

接著使用gen_x隨意舉任意短向量x,並且計算雜湊值u:

x = BasicSIS.gen_x()
u = (A * x) % para.q

若有trapdoor R,可以使用inverse_SIS算出另一個x2使得雜湊碰撞u=u2成立:

x2 = BasicSIS.inverse_SIS(A, u, R)
u2 = (A * x2) % para.q

ShiXunChameleon

1. setup phase

我的論文提出一種ID base的變色龍雜湊,首先定義基本參數,其中n是向量維度、q是質數、l是ID訊息的bit數、sigma是取高斯矩陣時的標準差,經過實驗建議sigma取0.35:

ID='101'
config.set_parameter(n=3, q=13, l=len(ID), sigma=0.3)

系統中包含一個CA以及多個User。首先CA必須生成其公、私鑰對MPK、MSK,生成後的公司鑰對儲存於該物件中:

CA_obj = SXchameleonCA()
CA_obj.generate_MPK_MSK()

物件中extract_master_key、extract_master_private_key方法分別回傳該物件中的公鑰以及私鑰.pem格式的字串,接著可以使用open方法將公、私鑰字串寫入.pem檔中進行儲存管理:

MPK_pem = CA_obj.extract_master_key()
with open('MPK.pem', 'wb') as f:
    f.write(MPK_pem)

MSK_pem = CA_obj.extract_master_private_key()
with open('MSK.pem', 'wb') as f:
    f.write(MSK_pem)

2. CA genegrate user SK phase

CA透過私鑰MSK可計算個別使用者的私鑰。若物件內未儲存私鑰的話,必須透過import_key方法將儲存在.pem中的私鑰載入物件中,再使用extract_user_private_key方法帶入user的身分訊息後回傳該user對應的pem格式密鑰:

# 讀取MPK
CA_obj = SXchameleonCA()
with open('MSK.pem', 'rb') as f:
    MSK_pem = f.read()
CA_obj.import_key(MSK_pem)

# 生成並保存R_ID
R_ID_pem= CA_obj.extract_user_private_key(ID)
with open('SK_{}.pem'.format(ID), 'wb') as f:
    f.write(R_ID_pem)

3. Hashing phase

使用SXchameleonUser類別定義個別的使用者,宣告時必須帶入使用者的ID身分訊息:

usr_obj = SXchameleonUser(ID)

使用import_MPK方法將CA公鑰匯入,該方法會自動的計算該使用者的公鑰並儲存於物件中。

with open('MPK.pem', 'rb') as f:
    MPK_pem = f.read()
usr_obj.import_MPK(MPK_pem)

相同於SIS碰撞中的過程,此class將雜湊過程包含入物件中,hashing方法即可回傳雜湊值u。

x = BasicSIS.gen_x()
u = usr_obj.hashing(x)

4. Forge phase

若擁有CA給出的私鑰,可以匯入CA給的私鑰後,計算x2使得雜湊碰撞u=u2成立:

# 讀取並載入R_ID
with open('SK_{}.pem'.format(ID), 'rb') as f:
    R_ID_pem = f.read()
usr_obj.import_key(R_ID_pem)

# 計算雜湊碰撞
x2 = usr_obj.forge(u)
u2 = usr_obj.hashing(x2)

Metadata

Release files for ShiXunChameleon 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ShiXunChameleon 1.0.1
File Size Uploaded Provenance
shixunchameleon-1.0.1.tar.gz 15.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ShiXunChameleon 1.0.1
File Interpreter ABI Platform
ShiXunChameleon-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.1 kB

Release files / shixunchameleon-1.0.1.tar.gz

Download URL shixunchameleon-1.0.1.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
434734ad4d360d266b49709ae4137d0c5d7c2dc44c0e1b9f0728f79cab83baa1
BLAKE2b-256 checksum
How to use checksums
bda5d18d8a608e6fb1af098a1fdd04de1c3e178640a345f107fcbaadded5180e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / ShiXunChameleon-1.0.1-py3-none-any.whl

Download URL ShiXunChameleon-1.0.1-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ab55901a6d939758e1ef68b0feaa43abd7bbb7edc34928f6ce1a9f2c789f095
BLAKE2b-256 checksum
How to use checksums
39adedf632f379966fb619778a1acbf62dcf37d7cebe2edf449d8660ea12a161
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Security for ShiXunChameleon 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page