# Bouncy Castle and Salsa 20 [closed]

I want to use Salsa 20 in Java, so I downloaded Bouncy Castle, and... it makes no sense to me. I've got it working, but most of my choices were essentially random. But I can't see there anything leading me to the right path. The interface CipherParameters accepts nearly any nonsense and a key size of 257 bits works perfectly.

private static StreamCipher newCipher(byte[] password, byte[] salt) {
int iterations = 50000; // really?
PBEParametersGenerator generator =
new PKCS5S2ParametersGenerator(); // really this one?
final CipherParameters cipherParameters =
generator.generateDerivedParameters(256, 64); // would 257 be better? :D
final StreamCipher result = new Salsa20Engine();
result.init(true, cipherParameters);
}


As I wrote, it works, but is this the right way? Especially,

• Is PKCS5S2 with 50000 iterations a good choice?
• The password gets stored nowhere, so I'm assuming, the only thread would be an attacker having access to both the plaintext and the ciphertext, xoring them together, and using it for verification of their password guesses. Am I right?
• Concerning the practical POV, is there a way how to verify I did nothing seriously wrong (like switching password and salt or using a inappropriate method)?

## closed as off-topic by CodesInChaos, DrLecter, yyyyyyy, otus, GillesJun 29 '15 at 22:01

• This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Downvoter, feel free to add an answer. If the code is crap... well, then I'm right as I expected it. – maaartinus Oct 13 '14 at 15:59
• The question is off topic for this site. – ddddavidee Oct 13 '14 at 17:08
• @ddddavidee How is it different from e.g. this one or this one? I just didn't ask explicitly about what key derivation algorithm should I use, etc., but the question is there. And assuming it's not appropriate here, where should it be? Buddhism? Pets? Just don't say SO or CR, as the kind of knowledge I need is not there. – maaartinus Oct 13 '14 at 17:18
• Maybe you should ask your question in the general way, without any bound to a particular library. (btw I'm not the downvoter) – ddddavidee Oct 13 '14 at 17:20
• I'm voting to close this question as off-topic because it is a programming problem, not a cryptography problem. – CodesInChaos Jun 29 '15 at 10:27

My code above is a fascinating huge damping pile of... you know.

generator.init(password, salt, iterations);


BC fails to copy the content of the password array, so my security "improvement" of clearing the password after use, clears it before use and leads to a password of all zeros.

Btw., the mailing list was no better than this site. No answer.

• @e-sushi While your suggestion helps to avoid close-votes, it won't help to get a sensible answer. Posting it on SO (which I know pretty well) is a sort of waste of time. See also my comments below my question. – maaartinus Jul 2 '15 at 16:56
• Honestly, looking at things again I´ve started to realize that too. Sorry for having bugged you with a comment which was (as it turns out) rather “superfluous” because you obviously seem to know your ways around the SE network already. Oh well, at least I was able to drop some benign votes while I was at it… – e-sushi Jul 2 '15 at 17:13