Vikten av pseudoslumptalsgeneratorer (PRNG) inom kryptografi och deras säkerhetskonsekvenser: Säkerhetsbrister inom pseudoslumptalsgeneratorer
2025 (Swedish)Independent thesis Basic level (professional degree), 10 credits / 15 HE credits
Student thesisAlternative title
The Importance of Pseudorandom Number Generator (PRNGs) in Cryptography and Their Security Implications : Security Vulnerabilities in Pseudorandom Number Generators (English)
Abstract [en]
Pseudo-random number generators (PRNGs) are fundamental components in cryptographic systems, where secure and unpredictable randomness is essentialfor tasks such as key generation and authentication. However, developers often use PRNGs without a full understanding of their limitations and potential security vulnerabilities, which can result in critical weaknesses. This study aims to explore how developers can ensure the use of secure PRNGs, and to identify best practices and existing guidelines for avoiding weak implementations. To address this objective, the study combines a literature review with practical experiments. A selection of PRNG libraries available in Python was evaluated in terms of entropy and statistical randomness. All tests were carried out in controlled virtual environments with uniform system configurations. Two primary methods were employed: NIST SP 800-90B to assess entropy, and Dieharder to evaluate statistical properties. Generators like secrets, ssl_rand_bytes, and os.urandomyielded entropy values close to the theoretical maximum, while simpler libraries such as random and numpy.random produced results closer to the lower acceptable limit. Nonetheless, none of the tested generators passed the full battery of Dieharder tests.
The findings indicate that high entropy alone is not sufficient to ensure security. Even cryptographically secure PRNGs (CSPRNGs) may fail under comprehensive statistical testing, particularly under prolonged or intensive use. This underscores the importance of selecting the right PRNG based on the specific application and highlights the need for correct seed management and periodic entropy reseeding. To ensure robustness, developers should adhere to established standards like NIST SP 800-90A/B and comply with regulatory frameworks such as the NIS2 directive and recommendations from the Swedish Civil Contingencies Agency(MSB).
In conclusion, the most reliable approach involves combining a vetted CSPRNG with a validated entropy source. Generic PRNGs should be strictly avoided insecurity-sensitive scenarios.
Abstract [sv]
Pseudo-slumptalsgeneratorer (PRNG) utgör en grundläggande komponent i kryptografiska system, där behovet av säkra och förutsägbara tal är avgörande, till exempel vid nyckelgenerering och autentisering. Trots detta tenderar många utvecklare att använda PRNG utan tillräcklig förståelse för dess begränsningar och potentiella säkerhetsrisker, vilket kan leda till allvarliga sårbarheter. Denna studie syftar till att undersöka hur utvecklare kan försäkra sig om att använda säkra PRNG- lösningar, samt att identifiera etablerade riktlinjer och rekomendationer för att undvika svaga implementationer. För att bevara frågeställningen kombineras en litteraturstudie med praktiska experiment där olika PRNG- bibliotek i Python analyseras utifrån entropi och statisk slumpmässighet. Samtliga tester har utförts i kontrollerande virtuella miljöer med identiska systeminställningar.
Två analysmetoder användes: NIST SP 800-90B för att mäta entropinivåer, samt Dieharder-tester för att granska de statiska egenskaperna hos slumptalssekvenser. Resultatet visade att bibliotek som secrets, ssl_rand_bytes och os.urandom uppnådde entropivärden nära det teoretiska maximumet, medan enklare bibliotek som random och numpy.random låg närmare den nedre godkända gränsen. Dock misslyckades samtliga testade bibliotek att fullt ut uppfylla kraven i Diehardertestet. Studien visar att hög entropi i sig inte är en garanti för säkerhet. Även kryptografiskt säkra generatorer (CSPRNG) kan underprestera i avancerade tester, särskilt vid långvarig eller olämplig användning. Det är därför avgörande att välja PRNG utifrån det specifika säkerhetskravet, samt att hantera seedning och entropikällor korrekt.
För att uppnå robust säkerhet rekommenderas att följa riktlinjer från bland annat NIST SP 800-90A/B, NIS2-direktivet och MSB:s vägledningar. Slutsatsen är att det bästa skyddet uppnås genom att kombinera en godkänd CSPRNG med en tillförlitlig och validerad entropikälla. Generiska PRNG bör undvikas i säkerhetskritiska sammanhang.
Place, publisher, year, edition, pages
2025.
Keywords [en]
PRNG;Cryptography;Vulnerability;Attack;Secure
National Category
Computer Sciences
Identifiers
URN: urn:nbn:se:du-50753OAI: oai:DiVA.org:du-50753DiVA, id: diva2:1974462
Subject / course
Microdata Analysis
2025-06-232025-06-232025-10-09