不要在生产中使用,这是在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计划等可验证的秘密共享方案来解决的。
另一个问题是,由于任何给定股份的长度等于相关秘密的长度,因此很容易泄漏一个秘密的长度。通过简单地将秘密填充固定长度,该问题可以解决这个问题,该固定长度应如示例所示。
最后,重要的是要注意,我们对安全性的担忧可能超出了计划本身。对于现实世界加密应用程序,通常存在侧渠道攻击的威胁,其中攻击者试图从应用程序时间,缓存,故障等中提取有用的信息。如果这是一个问题,则应在开发过程中进行仔细的考虑,例如使用恒定的时间功能和查找,防止记忆到磁盘进行分页,以及许多其他内容超出了该库的范围。