Can anyone help me by providing me a website link or source code of twofish cryptography other than schneier website where the code consist of input of plaintext and output of ciphertext in C++ language. I want to parallelize the twofish code with openmp and i can't find the twofish code with input and output. Thanks for the help!!!

Dani AI

Generated

Quick answer for : use a maintained C++ crypto library (for example Crypto++ or Botan) for ready-to-run Twofish code that reads plaintext and writes ciphertext. Those libraries include examples and are safer than random GitHub snippets. Also useful background is the Twofish algorithm page on Wikipedia for block/key sizes and design notes.

Practical notes for OpenMP parallelization

  • Twofish is a 128-bit block cipher (keys up to 256 bits). Encryption parallelizes at the block level only if the mode of operation allows it. ECB and CTR/stream-style modes let each block be processed independently; CBC encryption does not (CBC decryption can be parallelized). For secure, parallel encryptions prefer CTR, XTS, or another parallel-friendly mode instead of ECB.
  • Precompute the expanded key / key schedule once and reuse it across threads. Key expansion is relatively expensive; do not recompute per block.
  • Many library cipher objects are not safe for concurrent mutation. Either build one read-only key schedule that all threads use, or create a per-thread cipher instance using the same expanded key.

Minimal OpenMP pattern (pseudocode)

KeySchedule ks = expand_key(key);   // do once

#pragma omp parallel for schedule(static)
for (size_t i = 0; i < nblocks; ++i) {
    uint8_t counter[16] = make_counter(iv, i);   // CTR mode
    uint8_t keystream[16];
    twofish_encrypt_block(&ks, counter, keystream); // read-only ks
    xor_block(output + i*16, input + i*16, keystream);
}

Troubleshooting and perf tips

  • Ensure buffers are contiguous and aligned, avoid per-block allocations, and tune schedule(...) chunk sizes to reduce overhead.
  • Watch for false sharing: give threads separate output ranges or pad to cache-line boundaries.
  • If using a library, read its docs about thread safety; if uncertain, create one cipher instance per thread (cheap after key expansion).
  • Validate with known test vectors after porting.

As reminded, search existing threads first (as noted) to avoid duplicates.

Recommended Answers

All 2 Replies

ANSWERED AGAIN in your other threads, just stop spamming the board.

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.