@@ -13,6 +13,8 @@ please reference the appropriate Security Policy or contact
[email protected] .
1313| --- | --- | --- | --- |
1414| ` wolfjce.wks.iterationCount ` | 210,000 | 10,000 | PBKDF2 iteration count |
1515| ` wolfjce.wks.maxCertChainLength ` | 100 | N/A | Max cert chain length |
16+ | ` wolfjce.keystore.kekCacheEnabled ` | false | N/A | Enable KEK caching |
17+ | ` wolfjce.keystore.kekCacheTtlSec ` | 300 | 1 | Cache TTL in seconds |
1618
1719## Notes on Algorithm and Security Properties
1820
@@ -229,6 +231,88 @@ there is no certificate so no certifiate or private key sanity checks are done.
229231The same encrypt/decrypt process is shared between PrivateKey and SecretKey
230232protection.
231233
234+ ## KEK Caching for Performance
235+
236+ ### Overview
237+
238+ Repeated calls to ` getKey() ` on the same KeyStore can be slow due to PBKDF2
239+ happening on each call to derive the Key Encryption Key (KEK) from the user
240+ password. PBKDF2 on each ` getKey() ` operation ensures that neither password
241+ nor KEK are stored in memory for more time that is needed to derive the KEK and
242+ decrypt the key entry. Although this is the most secure approach, PBKDF2 on
243+ each ` getKey() ` can be too performance expensive for some use cases.
244+
245+ The WKS KeyStore includes an optional KEK (Key Encryption Key) cache that
246+ stores derived keys in memory to avoid repeated PBKDF2 computations for the
247+ same password/salt combination. With KEK caching enabled, follow up calls
248+ to ` getKey() ` are much faster.
249+
250+ ### Cache Design
251+
252+ The cache uses the following design:
253+
254+ - ** Cache Key:** ` SHA-256(passwordHash + kdfSalt + kdfIterations) `
255+ - ` passwordHash ` = ` SHA-256(password) ` - avoids storing plaintext passwords
256+ - Including ` kdfSalt ` and ` kdfIterations ` ensures different entries with
257+ the same password but different PBKDF2 parameters have separate cache keys
258+ - ** Cache Entry:** Stores the derived key (KEK + HMAC key), password hash for
259+ verification, and TTL expiry timestamp
260+ - ** Password Verification:** On cache hit, the provided password is hashed and
261+ compared against the stored hash.
262+ - ** HMAC Verification:** Caching only occurs after successful HMAC verification
263+ to ensure data integrity is maintained.
264+
265+ ### Security Properties
266+
267+ | Property | Default | Description |
268+ | --- | --- | --- |
269+ | ` wolfjce.keystore.kekCacheEnabled ` | ` false ` | Set to ` "true" ` to enable caching |
270+ | ` wolfjce.keystore.kekCacheTtlSec ` | ` 300 ` | Cache entry TTL in seconds (5 min) |
271+
272+ Example usage:
273+
274+ ``` java
275+ /* Enable KEK caching with 10 minute TTL */
276+ Security . setProperty(" wolfjce.keystore.kekCacheEnabled" , " true" );
277+ Security . setProperty(" wolfjce.keystore.kekCacheTtlSec" , " 600" );
278+ ```
279+
280+ ### Cache Lifecycle
281+
282+ The cache is cleared in the following scenarios:
283+ - ** Entry deletion:** When ` deleteEntry() ` is called on an encrypted entry
284+ - ** Entry overwrite:** When ` setKeyEntry() ` overwrites an existing encrypted
285+ entry
286+ - ** KeyStore reload:** When ` load() ` is called to load a new KeyStore
287+ - ** TTL expiration:** Individual entries are removed when their TTL expires
288+ - ** Explicit clear:** When ` clearCache() ` is called on the KeyStore instance
289+ - ** Garbage collection:** Automatically when the KeyStore object is finalized
290+
291+ For deterministic cleanup of sensitive cached data, explicitly call
292+ ` clearCache() ` when the KeyStore is no longer needed:
293+
294+ ``` java
295+ KeyStore store = KeyStore . getInstance(" WKS" , " wolfJCE" );
296+ /* ... use the KeyStore ... */
297+
298+ /* Explicitly clear cached keys before discarding */
299+ if (store instanceof com.wolfssl.provider.jce. WolfSSLKeyStore ) {
300+ ((com.wolfssl.provider.jce. WolfSSLKeyStore ) store). clearCache();
301+ }
302+ ```
303+
304+ ### Security Considerations
305+
306+ 1 . ** Memory exposure:** Cached derived keys remain in memory for the TTL
307+ duration. Only enable in trusted environments where performance benefits
308+ outweigh the increased memory exposure window.
309+
310+ ### Performance Characteristics
311+
312+ - ** First call:** Full PBKDF2 derivation to generate KEK from password
313+ - ** Subsequent calls:** Cache lookup and verification
314+ - ** Cache overhead:** ~ 1-2 SHA-256 operations per call for cache key computation
315+
232316## Certificate Protection
233317
234318A Certificate entry is stored into the KeyStore with the
0 commit comments