لا تستخدم في الإنتاج ، وهذا في حالة 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-shamirs-secret-sharing-scheme/
https://www.geeksforgeeks.org/shamirs-secret-lgorithm-cryptography/
https://ericrafaloff.com/shamirs-secret-sharing-scheme/
يقدم مخطط مشاركة Sharmir Secret Scheme أمنًا نظرية للمعلومات ، مما يعني أن الرياضيات التي استكشفناها قد أثبتت أنها غير قابلة للكسر ، حتى ضد مهاجم يتمتع بسلطة حوسبة غير محدودة. ومع ذلك ، لا يزال المخطط يحتوي على اثنين من القضايا المعروفة.
على سبيل المثال ، لا ينتج مخطط شامير أسهمًا قابلة للتحقق ، مما يعني أن الأفراد أحرار في تقديم أسهم وهمية ومنع إعادة بناء السر الصحيح. يمكن أن ينتج عن حامل مشاركة الخصومة مع معلومات كافية حتى حصة مختلفة بحيث يتم إعادة بناء SS إلى قيمة من اختيارهم. تتم معالجة هذه القضية من خلال مخططات المشاركة السرية التي يمكن التحقق منها مثل مخطط Feldman.
القضية الأخرى هي أنه نظرًا لأن طول أي حصة معينة يساوي طول السر المرتبط ، يتم تسريب طول السر بسهولة. هذه المشكلة تافهة لإصلاح ببساطة عن طريق حشوة السر بطول ثابت يجب القيام به مع الصوديوم كما هو موضح في الأمثلة.
أخيرًا ، من المهم أن نلاحظ أن مخاوفنا بشأن الأمن قد تمتد إلى ما وراء المخطط نفسه فقط. بالنسبة لتطبيقات التشفير في العالم الحقيقي ، غالبًا ما يكون هناك تهديد لهجمات القناة الجانبية ، حيث يحاول المهاجم استخراج معلومات مفيدة من توقيت التطبيق ، والتخزين المؤقت ، والخطأ ، والمزيد. إذا كان هذا مصدر قلق ، فيجب تقديم اعتبارات دقيقة أثناء التطوير ، مثل استخدام وظائف الوقت الثابتة والبحث ، ومنع الذاكرة من الترحيل إلى القرص ، ومجموعة من الأشياء الأخرى التي تتجاوز نطاق هذه المكتبة.