Can anyone help me by telling me where to find twofish source code other than from scheinier website?? I just want to find a sample source code of encrytion and decrytion using twofish algorithm. Thx a lot for the help..

Dani AI

Generated

Quick, practical checklist for anyone who lands here later (summary of the thread plus focused advice for parallelizing Twofish with OpenMP).

wanted a sample that accepts plaintext and produces ciphertext and to parallelize it; pointed toward the reference code. If a ready-made, maintained implementation would help you move faster, look at library codebases rather than the reference C only: Crypto++ (C++) has Twofish classes and sample programs, which are easy to adapt; Bouncy Castle provides a Java Twofish engine; Go’s x/crypto/twofish exposes a minimal block-cipher API for quick tests. (cryptopp.com)

What to parallelize (practical rules):

  • Twofish is a 128-bit block cipher with an explicit key schedule — do the key setup once, then reuse the schedule as read-only from all threads. Precomputing the schedule removes redundant work and is safe to share if you do not modify it. (schneier.com)
  • The mode of operation decides if block-level parallelism is possible. Counter (CTR), XTS and (for testing only) ECB let you encrypt independent blocks in parallel. CBC encryption creates a dependency chain (so it is serial); CBC decryption can be parallelized because each block’s decryption only needs the previous ciphertext block. Use the mode that fits your security model. (csrc.nist.gov)

Example pattern (pseudocode — keep key setup outside the loop):

TwofishKeySchedule ks;
Twofish_SetupKey(&ks, key, keylen);   // once, single-threaded

#pragma omp parallel for schedule(static)
for (size_t i = 0; i < nblocks; ++i) {
    twofish_encrypt_block(&ks, in + i*16, out + i*16);
}

Troubleshooting and tips: avoid parallelizing very small inputs (thread overhead kills gains); align buffers to cache lines and avoid false sharing; use per-thread output buffers if you see contention; verify against official test vectors after any change; profile (time key setup vs. per-block work) before optimizing inner rounds — often the fastest wins come from algorithmic changes (mode, buffering) rather than micro-parallelism. For production, prefer vetted library implementations (Crypto++, Bouncy Castle, Go packages) and AEAD modes rather than rolling your own framing or using ECB. (cryptopp.com)

Recommended Answers

All 7 Replies

Twofish is unpatented, and the source code is uncopyrighted and license-free

Gee, what more do you want?

commented: >"Gee, what more do you want" Haz you got winning lotto numberz lol 1? ;) +10

>> Gee, what more do you want?
A clickable link would be nice. I don't want to have to copy and paste again, Salem!

I want a source code which can be input with plaintext and output with ciphertext. The twofish source code in scheneier website do not provide an input but come out with a lot of txt file. I just want to parallelize the twofish source code with openmp. How for me to use the twofish code in schneier website cause it seems like do not provide any input of plaintext.

If you can't figure out from the first zip file that twofish.c is the algorithm, and tst2fish.c is a test wrapper with all the I/O you could ever need for it, then everything you plan seems beyond you.

commented: Good!! +3

If you can't figure out from the first zip file that twofish.c is the algorithm, and tst2fish.c is a test wrapper with all the I/O you could ever need for it, then everything you plan seems beyond you.

Thx a lot Salem!!!

Thx a lot Salem!!!

It had tried out the code but seems like i m blur of the code. Which part shuld be parallelize. Is there any others code beside this which is simpler..

Since that was the reference implementation, meaning it's written for clarity rather than performance, then I guess you're stuck.

IMO, you need to spend more time looking at the code you have, and really trying to understand how it works. If something seems especially complicated, try rewriting it, and then use the test suite to make sure it still works.

This is weeks of work, not come back within a day "is there something simpler".

> Which part shuld be parallelize.
I dunno, it's your idea - what did you have in mind when you started this plan in motion?

My guess would be to look for outer-most for loops which operate on independent blocks of data. If twofish uses one block as part of the seed for the next block, then I don't think this idea will work out. Again, do you know how twofish works for this to even be possible?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.