0

I'm trying to compare two techniques for generating an OAuth 2 PKCE code_verifier.

  • For each character, get a random byte and "mod 66" to map to one of the 66 valid characters.
  • For each character, get a random byte and "mod 64" to map to a subset of the valid characters. (We could also use 6 random bits per character instead of 8.)

It appears that the min-entropy of both techniques is the same (answer). Are there any other security-related factors I should consider?

Note: for the purposes of this question, I'm only worried about the security of the secret. Let's ignore the efficiency and/or potential timing side-channels of the secret generation code for now.

  • 33 bytes read from /dev/urandom and then encoded using url-safe base64 should be exactly what you need. – Z.T. May 28 at 0:14
  • Clarification: I'm not looking for advice on how to generate the secret. I'm just trying to compare the security of the secret generated by the two above techniques. – Kannan Goundan May 28 at 19:33
  • See stackoverflow.com/a/10984975/481815 I think that in the "mod 66" method you get modulo bias, so you're supposed to only use bytes with values 0..197 (inclusive), so you need more random bytes. In the "mod 64" method, you can use any random bytes. Of course the base64 method is the obviously correct method, I don't understand why you care how much better or worse the mod 66 method is - it's not bad enough to hurt your security, it's just inefficient. – Z.T. May 28 at 20:01
  • Yes, there is bias but the min-entropy calculation conservatively takes that into account (see the answer linked in my question) and the min-entropy of both techniques is the same. I care about how much better or worse the "mod 66" technique is because I want to get a deeper understanding of the underlying theory. That understanding is both interesting and might be useful in a future situation. – Kannan Goundan May 28 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.