不要在生產中使用,這是在POC狀態
examples目錄中可用基本示例。
<?php
declare (strict_types= 1 );
require ' ../vendor/autoload.php ' ;
use Gheb ShamirSecretSharingScheme SodiumHelper ;
use Gheb ShamirSecretSharingScheme ShamirSecretSharingHelper ;
$ secretKey = SodiumHelper:: generateKey (); // this will be stored in shares.
$ nonce = SodiumHelper:: generateNonce (); // this could be part of your app configuration
$ secret = ' Sensitive information ' ;
var_dump ( " secret : $ secret " );
// symmetric key encryption with padded message to hide it's length. This does not matter, it's for show !
$ encryptedMessage = SodiumHelper:: encrypt ( $ secret , $ secretKey , $ nonce );
// This is the best part !
// It splits the secret key into 3 shares. (but it could be more)
// initialisation of modulo value, addressing insecure integer arithmetic.
// this would be part of your app configuration or stored elsewhere.
$ m = " 997 " ; // chose any prime number (here around 1000)
$ points = ShamirSecretSharingHelper:: getShareablePoints ( $ secretKey , $ m , 3 );
var_dump ( $ points );
// there you can store your points at different locations.
// and later get them back to get your secret back
// reconstructing and decrypting
// to reconstruct the secretKey the 3 points are needed along the
$ decryptedSecretKey = ShamirSecretSharingHelper:: reconstructSecret ( $ points , $ m );
$ decryptedSecret = SodiumHelper:: decrypt ( $ encryptedMessage , $ nonce , $ decryptedSecretKey );
var_dump ( " decrypted secret : $ decryptedSecret " );https://en.wikipedia.org/wiki/homomorphic_secret_sharing
https://en.wikipedia.org/wiki/shamir%27s_secret_sharing
https://wiki.owasp.org/index.php/security_by_design_principles
https://kariera.future-processing.pl/blog/splitting-your-secrets-with-secrets-secret-secret-sharing-scheme/
https://www.geeksforgeeks.org/shamirs-secret-secret-secret-algorithm-cryptography/
https://ericrafaloff.com/shamirs-secret-sharing-scheme/
Sharmir的秘密共享方案提供了信息理論安全性,這意味著我們探索的數學已被證明是牢不可破的,即使是針對具有無限計算能力的攻擊者。但是,該計劃仍然包含一些已知問題。
例如,Shamir的計劃不會產生可驗證的股份,這意味著個人可以自由提交假股份並防止正確的秘密重建。具有足夠信息的對手共享持有人甚至可以產生不同的份額,以便將SS重建為他們選擇的價值。該問題是通過Feldman計劃等可驗證的秘密共享方案來解決的。
另一個問題是,由於任何給定股份的長度等於相關秘密的長度,因此很容易洩漏一個秘密的長度。通過簡單地將秘密填充固定長度,該問題可以解決這個問題,該固定長度應如示例所示。
最後,重要的是要注意,我們對安全性的擔憂可能超出了計劃本身。對於現實世界加密應用程序,通常存在側渠道攻擊的威脅,其中攻擊者試圖從應用程序時間,緩存,故障等中提取有用的信息。如果這是一個問題,則應在開發過程中進行仔細的考慮,例如使用恆定的時間功能和查找,防止記憶到磁盤進行分頁,以及許多其他內容超出了該庫的範圍。