مترجم+مفسّر: عشوائي_آمن CSPRNG حقيقيّ عبر نظام التشغيل (مرحلة ٠ من RFC توسيع مكتبة التشفير)#214
Merged
Merged
Conversation
…C توسيع مكتبة التشفير) يستبدل sad_security_secure_random ونِتر شفّر/فك_تشفير (sad_crypto_random_u64) في sad_embedded_runtime.c من srand(time(NULL))+rand() القابل للتنبّؤ بالكامل إلى CSPRNG حقيقيّ (BCryptGenRandom عبر تحميل ديناميكيّ على Windows، /dev/urandom على POSIX)، مقصورًا على الأهداف المستضافة عبر SAD_FREESTANDING (الهدف الحرّ قد لا يوجد تحته نظام تشغيل مضيف أصلًا). يكشف الفحص أيضًا علّتين حقيقيّتين منفصلتين في مسار المترجم لعشوائي_آمن نفسه كانتا موجودتين قبل هذه الجولة: نداء مباشر لِـBCryptGenRandom في LLVM IR دون ربط bcrypt.lib في أيّ من مسارات الربط الثلاثة (فشل ربط دائم على Windows)، وتجاهل تامّ لمعاملَي الحدّ الأدنى/الأقصى. يُصلَحان معًا بجعل المترجم يستدعي sad_security_secure_random من وقت التشغيل المضمَّن، بنفس نمط بقيّة عائلة الأمن المستضافة (هاش/شفّر/فك_تشفير). يحدّث Android linker بنفس CSPRNG (/dev/urandom، أندرويد نظام تشغيل مضيف دائمًا). يثري وصف SECURE_RANDOM في SoT، ويضيف اختبار تراجع (154) يتحقّق من التزام المدى وعدم التكرار الحتميّ عبر 10 جولات burn-in.
|
📚 تذكير مزامنة دليل المطوّرين هذا الـPR يلمس مصادر موثَّقة في دليل المطوّرين. راجع الفصول الآتية وحدّثها إن تغيّر سلوكها، ثم ثبّت البصمات هناك (
بندٌ في معيار الإنجاز. تذكيرٌ آليّ — لا يحجب الدمج. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
الملخّص
المرحلة ٠ من RFC توسيع مكتبة التشفير:
عشوائي_آمنكانت تعتمدsrand(time(NULL))+rand()القابل للتنبّؤ بالكامل فيوقت تشغيل المترجم — يُصلَح الآن بـCSPRNG حقيقيّ (BCryptGenRandom عبر تحميل
ديناميكيّ على Windows،
/dev/urandomعلى POSIX)، مقصورًا على الأهدافالمستضافة (
SAD_FREESTANDINGيُبقي المسار القديم لهدف الوضع الحرّ الذي قدلا يوجد تحته نظام تشغيل مضيف أصلًا).
علّتان إضافيّتان مكتشَفتان أثناء الفحص (مُصلَحتان معًا)
مسار المترجم لِـ
عشوائي_آمن(emitBuiltinSecuritySecureRandom) كان معطوبًافعليًّا قبل هذا الـPR بعلّتين منفصلتين تمامًا عمّا وصفه RFC الأصليّ:
BCryptGenRandomفي LLVM IR دون ربطbcrypt.libفي أيّ منمسارات الربط الثلاثة — فشل ربط دائم على أيّ برنامج
.صمُترجَم علىWindows يستدعي
عشوائي_آمن(أُعيد إنتاجه حيًّا وتأكَّد قبل الإصلاح).قيمة ضمن المدى المطلوب.
الإصلاح: المترجم يستدعي الآن
sad_security_secure_randomمن وقت التشغيلالمضمَّن، بنفس نمط بقيّة عائلة الأمن المستضافة (هاش/شفّر/فك_تشفير).
التغييرات
tools/compiler/runtime/sad_embedded_runtime.c—sad_crypto_os_random(CSPRNG حقيقيّ)، يُستعمَل في نِترشفّر/فك_تشفيروعشوائي_آمنكليهما.tools/compiler/compiler_driver_build_utils.cpp— يمرّرSAD_FREESTANDINGعند--freestanding.compiler/src/backend/llvm/builders/builtins/security_builtins_ops.cpp— إعادة كتابةemitBuiltinSecuritySecureRandom.tools/compiler/compiler_driver_android_linker.cpp— تحديث نسخة أندرويد المنفصلة (/dev/urandom، لا حاجة لحراسة حرّ — أندرويد مستضاف دومًا).language-truth/builtins/assertions.yaml+ التوليد — إثراء وصفSECURE_RANDOM.tests/behavior/sections/09_المكتبة_القياسية/04_تشفير/154_stdlib_security_secure_random.ص— شعاع تراجع للعلّتين (التزام المدى + عدم تكرار حتميّ).COVERAGE.md.خطة الاختبار
python x.py build --config Debugنجح.04_تشفير/كاملًا (5 ملفّات) 100% تكافؤ مزدوج (مفسّر+مترجم).python x.py gen --checkنظيف (كل حرّاس SoT خضراء).01_مدمج/(21 ملفًّا) بلا انحدار.