views:

31

answers:

2

Question says it all really. Code can be found at the following link -> http://www.mindrot.org/projects/jBCrypt/

+1  A: 

First, it's not documented as thread-safe, so for all intents and purposes, it's not. And, on further investigation, it's definitely not: An instance of BCrypt has mutable private fields P[] and S[] that represent the present keys, which are touched by multiple methods. It turns out that, while there are some instance fields, there is no instance of BCrypt exposed; it tries to do everything through static methods. It may not thread safe. It's small enough that, assuming you care and the author would accept, you could offer a patch to trivially convert it to provide separate, safe instances (edit to add: I have scrubbed it carefully and prepared a cleaner version, which I will send to the author...)

Second, in what manner do you want to use this in a multithreaded environment? It's not clear to me what you'd want to do in separate threads.

andersoj
When hashing the passwords for users in a web app. Each user logging in/creating a password is going to spawn a new thread
McGin
Well, it looks like separate *instances* of BCrypt could be used in separate threads. As Stephen C notes, it's pretty badly designed, so it's not even clear that separate instances wouldn't interact via static accesses. I'd look for a better implementation...
andersoj
@McGin: PM me at andersoj at NO andersoj SPAM dot org to get a cleaner, refactored version. I spent too much time on this, mostly out of curiosity about blowfish.
andersoj
+1  A: 

Jbcrpyt has a really poorly designed API, IMO. Everything done using static methods? You've got to be kidding!

In the light of the quality of the API design, I would be surprised if the author bothered to make the implementation thread-safe.

Stephen C
Heh, he didn't ask for a code critique! But +1, bad API design suggests extreme suspicion about thread-safety... if it was, by accident, the next "bug fix" might break it.
andersoj