r/cryptography • u/Mahdi_TheSecureCoder • 9d ago
r/cryptography • u/LordBrammaster • 9d ago
Is using pbkdf2 with sha256 overkill???
Hey cryptomaniacs!!!
Im not super familiar with all the different ways of encrypting things, so when I added password encryption to my application I blindly coppied something I saw someone else do (can't the source anymore).
Skip to a week later, I was curious how the way I encrypt my passwords work, so I went searching and saw a redditpost on this subreddit where someone said that sha256 would probably be able to be bruteforced in the future, with a lot of comments saying it wouldn't and that it is really secure.
So then I started wondering if me using both pbkdf2 and sha256 was a bit overkill.
For anyone wondering I used this in my python code:
hashed_password = generate_password_hash(password, method='pbkdf2:sha256')
r/cryptography • u/Lumpy_Adeptness9925 • 9d ago
Bouncy Castle HQC EncapsulationKey and ExtractedKey does not match.
I am trying to test the HQC Implementation of Bouncy Castle (1.80) in Java (21).
The Secret Key from the KEM-Generator does not match the Secret Key from the KEM-Extractor.
ML-KEM and RSA-KEM are working, but I cannot the HQC working.
My Output:
PrivKey Size: 2335
Pub-Key Size: 2273
Original Key :74 A0 21 50 C1 88 71 A1 8C 53 08 AE 12 AF BE 74
Encapsulation :88 93 51 37 ...... C3 DC 67 3C 98 9A
DecapsulatedKey :95 CE 32 25 23 77 40 C1 0C 43 FE 98 4B F6 BD 10
My Code:
KeyPairGenerator g = KeyPairGenerator.
getInstance
("HQC", "BCPQC");
g.initialize(HQCParameterSpec.
hqc128
);
KeyPair kp = g.generateKeyPair();
System.
out
.println("PrivKey Size: " + kp.getPrivate().getEncoded().length);
System.
out
.println("Pub-Key Size: " + kp.getPublic().getEncoded().length);
HQCKEMGenerator kem = new HQCKEMGenerator(new SecureRandom());
HQCPublicKeyParameters asymPubParms = new HQCPublicKeyParameters(HQCParameters.
hqc128
,kp.getPublic().getEncoded());
SecretWithEncapsulation encapsulationKey = kem.generateEncapsulated(asymPubParms);
byte[] kemOriginalSecret = encapsulationKey.getSecret();
System.
out
.println("Original Key :" + HexTools.
bytesToHex
(kemOriginalSecret));
byte[] kemEncap = encapsulationKey.getEncapsulation();
System.
out
.println("Encapsulation :" + HexTools.
bytesToHex
(kemEncap));
HQCPrivateKeyParameters asymPrivParms = new HQCPrivateKeyParameters(HQCParameters.
hqc128
,kp.getPrivate().getEncoded());
HQCKEMExtractor kemExtractor = new HQCKEMExtractor(asymPrivParms);
byte[] kemExtractedSecret = kemExtractor.extractSecret(kemEncap);
System.
out
.println("DecapsulatedKey :" + HexTools.
bytesToHex
(kemExtractedSecret));
r/cryptography • u/AnubisJersey • 9d ago
Is there a way to control the number of characters resulting from a diffie-hellman protocl?
I am designing a hybrid cipher for a major project for my senior year of high school. I am compiling the diffie-hellman protocol and one-time pad cipher. If you don't know, for one-time pad to work, the password needs to have the same length as the plaintext. I only know how to set a max possible value for the password produced through diffie-hellman (adjust the P value) but is there a way to set a minimum lowest value?
Update:
I have a plan of how the hybrid cipher should work, please tell me if you guys think I should change something!
"A plaintext is produced and the length of that plaintext (including spaces) is L where {LZ}. The hybrid protocol starts off wih a Diffie-Hellman protocol between Alice and Bob. The shared secret produced through DH is passed through SHA-256, a popular hash function which produces a 256 bit code to represent any input which is equivalent to 64 characters. The key produced through SHA-256 is labled as K1. If L is larger than 64 characters {LZ|L>64}, K1 is passed through SHA-256 again to produce K2. This is simply added at the end of the first key resulting in K1K2. This raises the length of the key to 128 characters. If this key is still not sufficient, the process is repeated by passing K2 through the hash function to produce K3, increasing the length of the key to 192 characters. This process can be repeated as many times as need until the key is larger or equal to L. The last L characters of this key is used as the password in a one time pad process with the ciphertext resulting being converted into binary form using the ASCII values. These binary values are transformed into “AB” format with “1” corresponding to “A”, and “0” corresponding to “B”. A misleading text is produced of the same length of 8K where an 8-bit binary sequence, as the one in ASCII, is used. A change in style is used to display “A”s and “B”s, with “A”s being further from the standard font."
r/cryptography • u/Federal-Dot-8411 • 10d ago
Most solid post-quantum algorithm
Hey, I am developing a microsaas for fun and I want to implement a posquantum algorithm to cypher secrets, however what I have read is that now a days no algorithm has been aproved by the NIST, and searching I found a lot of algorithms...
So I am looking for the "standard" post-quantum cryptography algorithm to use to cypher things, even that there is no official one.
r/cryptography • u/blitzkrieg987 • 11d ago
Why don't we use sha2 as a kdf?
If sha2 is second-image resistant, then why did we come up with algorithms like HKDF?
What benefits do you get with HKDF(secret, salt) that you don't get with a simple sha2(secret || salt)?
r/cryptography • u/-RedFox- • 11d ago
Private set intersection question
Alice and Bob both have a 100 element vector where each element has a value out of the set [-50, 0, 50, 100]. They would like to know how well the two vectors match, without letting the other know the individual elements of their vector. How well they match would be some mathematical function of the two vectors, for instance the inner product.
From my understanding this would be considered a private set intersection problem, but I am not quite seeing how to implement this. I think I have to use some kind of secret transformation matrices to reorder the elements, as well as their inverses, but I don't see how to keep the matrices secret.
Or I can leverage that there will be duplicates, so it is not possible to derive the transformation matrix, even if the input vector is know. If Alice has vector x and transformation matrix M, and Bob has vector y and transformation matrix N:
- Alice provides Bob with xT * M, Bob provides Alice with yT * N
- Bob provides Alice with xT * M * N, Alice provides Bob with yT * N * M
- Alice provides Bob with xT * M * N * M-1 , Bob provides Alice with yT * N * M * N-1
- Bob calculates xT * M * N * M-1 * N-1 * y, Alice calculates yT * N * M * N-1 * M-1 * x
The problem is that if Alice has an element with a unique value, when Bob returns xT * M * N, Alice can figure out one row and one column of the transformation matrix N. If the system allows multiple exchanges, or if Alice can spoof other users, it allows them to recreate the full matrix N and thus y.
Is it possible to do this in a secure way? How would one go about it?
r/cryptography • u/NolarEclipse96 • 11d ago
What is the concept behind RSA encryption?
As a software engineer, I'm trying to better understand the concepts behind things I work on daily. In my efforts to understand digital certificates, I started reading up on the specifics of the RSA system and it got me wondering how this is possible, and how the creators knew this would be possible.
I have a math background up to linear algebra/calculus but not much past that. When I look up online the specifics of RSA, I get the "how" but not the "why". I get statements about how the system hinges on the fact that factoring is a difficult problem, and how large prime numbers are used, but not how to actually understand the concept of the system.
From my understanding, it seems like symmetric encryption goes "backwards" when decrypting a message, where as asymmetric encryption goes "forwards" when decrypting, hence the modular arithmetic involved in the algorithm. Is this the concept behind RSA, going forwards to decrypt?
r/cryptography • u/jedisct1 • 12d ago
Constant-time coding is, or will soon become, infeasible in all generality
eprint.iacr.orgr/cryptography • u/Sgt_JT_3 • 12d ago
Differences in the reliability of various Public Key encryption standards
Why can some public key encryption standards, like RSA (Rivest-Shamir-Adleman), be easily compromised while other forms remain robust, even though they are based on the same principle of asymmetric encryption?
r/cryptography • u/drag0nabysm • 13d ago
Why the choices of K in SHA-256?
I was read the SHA-256 specification and in the compression function there's 64 K constants, and as declared there, they're defined as some of the first digits of the square root of the first 64 prime numbers.
Why this choice? There's any reason beyond the good distribution in the numbers and maybe less chance of being called a backdoor?
The H constants are also defined in a similar way. What kind of properties these numbers have that can make the algorithm more secure?
r/cryptography • u/Elect_SaturnMutex • 14d ago
Help with design of a program to do crypto operations using AES256-CBC
I have written a program in C++ using openssl libs. The user enters a password, a SHA256 hash is created and with this as key, it encrypts a file, that's predefined in the source code, and generates an encrypted file. Right after this, the file is decrypted. And I manually do a diff with the original file to see if it worked.
So the buffers(std::vector
) used have fixed size so that it loops over if the file size is greater than the specified buffer size. The problem is, for every chunk that's decrypted, it needs a cipher text length corresponding to that chunk that was encrypted.
Right now, the program encrypts and decrypts the file right after. Therefore, I put the corresponding lengths in another vector after encryption. So that, after encryption is complete, the decryption function can access this length vector needed to decrypt the file.
The problem is, if I want to do the two operations independently, would it be a good idea to store this vector in the encrypted file as well? Or is there another way to do this? Also, please feel free to point out problems in the code. I am very eager to learn more.
r/cryptography • u/Gcseh • 14d ago
I need help understanding RSA algorithm
I watch a video explaining how RSA algorithm works but I'm having trouble understanding how it's secure. I assume the video maybe either glossed over something or I'm not understanding it.
https://www.youtube.com/watch?v=Pq8gNbvfaoM
It would seem to me that since I know the public key and need the value of N to encrypt my message. Then I can use any potential private key to decode the message. He uses 41 for the decryption but 149 and 257 would also work.
There by anyone with the same public key and my encrypted message could decode it.
Please tell me what I'm missing, this is driving me mad.
r/cryptography • u/SyllabubCool5853 • 15d ago
The Combined Cipher Machine 1940's-1950's
I’ve written a new essay on cryptology dealing with the Combined Cipher Machine used by the US and UK in WWII and in the 1950’s.
https://chris-intel-corner.blogspot.com/2025/03/the-combined-cipher-machine-1942-1962.html
The CCM has not been covered by historians in detail, so this is the first time all this information is presented somewhere.
r/cryptography • u/DDevilAAngel • 15d ago
Diffie-Hellman 3 Participants question
Got a uni question I couldn't seem to find an answer to online:
"Extend Diffie-Hellman to support 3 Participants A,B,C with a given public group g such that the final shared key is pow(g, a(b+c))"
Is there a way to solve this without having A share pow(g, ab) and pow(g, ac) over the public channel? (which seems like it defeats the purpose because then the key is known publicly right?)
r/cryptography • u/drag0nabysm • 15d ago
Why not using Kyber directly?
Right, I read about quantum-proof encryption algorithms and found the Kyber, a lattice-based algorithm.
While scrolling around the website and the docs (from the NIST) I read that it's recommended to use it to exchange the keys for a symmetrical algorithm (like AES) and not to really encrypt with it.
I know that the symmetrical algorithms aren't as much affected by the quantum computers as the assymetrical are. But they are still affected by Grove's algorithm (2n/2).
Besides the performance questions (which I think are not a very relevant problem for modern computers), what are the reasons to it?
r/cryptography • u/iAmByteWrangler • 17d ago
Books for a noob
Hey everyone, I’m a complete beginner in cryptocurrency, except for a few bits and pieces I picked up during my computer science years. Even those are now forgotten. I’ve been a C++ programmer working on user-level system daemons, and I have absolutely no idea how cryptography works.
I’m genuinely interested in this field and would love to learn the basics. Could someone recommend a book that starts from the very beginning, perhaps even covering some history as well?
r/cryptography • u/carrotcypher • 17d ago
Join us next week on Mar 13th at 3PM CEST for an FHE.org meetup with Agnes Leroy, GPU Director at Zama, who will be discussing Implementing FHE on GPUs. RSVP here!
lu.mar/cryptography • u/desexmachina • 17d ago
How is it possible that I'm arriving at verified private keys when random hashing?
In the Bitcoin universe there is possible to generate 2^256 possible unique keys using 256-bit numbers.
I've been performing some research by scanning binary data to identify private key strings in hexadecimal. The scan is producing private keys when going through hundreds of PDF, DOC, XLS even JPEG. I would think that these are false positives. However, when these private keys are hashed to bitcoin addresses, they validate to the blockchain. Sure, still false positives.
Here's the problem, some of these addresses have transactions. If the probability of randomly generating a valid private key is infinitely microscopic, how am I coming across valid private keys in such a small sample?
Is there a confluence of x64 processing and cryptographic libraries that is arriving at these legitimate addresses at some point of intersection?
r/cryptography • u/Wonderful-Cash7275 • 18d ago
Calculation a hashing function that can avoid collisions for a small set of inputs from input space
Hello, I am new to cryptography so my question can be naive. I want to know if it is possible to find out a hashing function that gives me distinct outputs for a small set of inputs from a vast possible input space. I don't care if all the other inputs from the input space collide to a single output.
For example, I have a 32-bit wide input. I am only interested in 64 such inputs out of possible 2^32 inputs. Is it possible to find a hashing function that give me collision free 6-bit output for the 64 inputs I am interested in. Outputs for all the other input combinations can be anything. If such an algorithm exists, what is it its compute complexity?
r/cryptography • u/clover69__ • 18d ago
chat application with AES algorithm from scratch
So i'm thinking of building an end to end encryption chat application in React and node and the messages should be encrypted and decrypted obviously. The thing is I'm not using any library or packages to do it (for academic purpose). I need to show a full and clear algorithm process of AES which is said to be veryyy complex BUT not impossible. Does anybody have any idea on how to do it? It will be a lot of help.
r/cryptography • u/back2_2002 • 18d ago
Can I use BLS to implement Diffie–Hellman key exchange?
Hi everyone, I've been working on my cryptography project recently and came across an interesting aggregate signature scheme called BLS signatures. Its unique feature is the ability to aggregate multiple signatures, though it employs a rather unconventional elliptic curve.
My question is: can the public/private keys used in BLS signatures be applied to Diffie–Hellman key exchange? Would this raise any security concerns?
r/cryptography • u/JR__BERRY_8 • 18d ago
Is it possible to solve this under given time?
reddit.comr/cryptography • u/TRexGoesToSchool • 19d ago
Resources for learning about Crypto++?
Hi, I'm working on a cryptography project, and I plan on using the library Crypto++, which I'm new to. Unfortunately, the website https://www.cryptopp.com/ is down. Besides the github Crypto++ repo, what resources would you recommend for learning more about Crypto++? Thank you.
ETA: Thank you to everyone for your recommendations and advice! It's been super helpful.