Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3453312
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:21:35+00:00 2026-05-18T09:21:35+00:00

I have a pool of immutable encryption helper objects which contain instances of the

  • 0

I have a pool of immutable encryption helper objects which contain instances of the java JCA Cipher and MessageDigest objects:

AlgorithmInstance( Cipher encCipher, Cipher decCipher, MessageDigest digest ) { ... }
private BlockingQueue< AlgorithmInstance > pool = new ArrayBlockingQueue< AlgorithmInstance >(poolSize);

Various threads in my application, needing encryption or decryption, contend for AlgorithmInstance objects by accessing a pool. Each thread uses them to encrypt or decrypt, and then returns them to the pool when they are done. Threads don’t synchronize on any of JCA objects since there is no concurrent access. Decrypt works roughly the same way.

public byte[] encryptMessage( byte data[] ) { ...
 try {
  AlgorithmInstance inst = pool.take();

  inst.digest.reset(); 
  byte[] digest = inst.digest.digest(message);

  inst.encryptCipher.init( Cipher.ENCRYPT_MODE, m_currentKey, ivParams );
  inst.encryptCipher.doFinal( messageBuffer );
 }
 finally {
  pool.put(inst)
 }
}

This works 99.99% of the time; and 100% of the time in unit tests. However, once in a blue moon, I get a message whose computed digest does not come out right — normally this indicates message tampering or network errors; but sender and receiver are on the same machine (in different processes).

Q: Is there some internal state for a Cipher or Digest which can suffer from memory consistency effects — I’m on a 2 core windows box so I don’t see how I could even suffer from memory consistency effects. I re-initialize the cipher and digest each call so it should not matter.

Q: Is there any way I could have ended up with a padding mode that sometimes fails based on the message length? The decryptor and encryptor use exactly the same algorithms (AES/CBC/Pkcs5Padding + SHA-256, and a key size of 128).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:21:36+00:00Added an answer on May 18, 2026 at 9:21 am

    I changed the code so that I synchronize on the AlgorithmInstance while I use any of its contained objects. I have not seen this problem since; however its not clear why; since the queue.put() and queue.take() operations should form EXACTLY the same happens-before relationship formed by the monitor unlock:

    synchronized (inst) {
     ...
     // do crypto opperations
    }
    

    The only other possibility I can come up with is that the IVParamSpec is modified during the Cipher.init() computation and then restored at the end. Since the ivParams are assumed read only and shared across all objects in the pool, if true, this could lead to un-synchronized access and possibly MCE.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a connection pool setup. Which is great and all since I
Preliminary : I have an application which maintains a thread pool of about 100
I have a pool of threads which are working independently. Basically these threads are
I have a large pool of objects with starting number and ending number. For
i have big pool of core date objects (around 10000) and there is too
I have a pool of items in the drag list which is connected to
I'm writing a load-testing application in Java, and have a thread pool that executes
I have a pool of threads which are fed tasks from a queue. Generally,
I have a thread pool (executor) which I would like to monitor for excessive
I have a condor pool which consist of 4 dedicated machine one is set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.