As per Java Card v3.1 new package is defined javacardx.security.derivation
KDF X9.63 works on three inputs: input secret, counter and shared info. Depends on length of generated key material, multiple rounds on hash is carried out to generated final output.
I am using this KDF via JC API to generated 64 bytes of output (which is carried out by 2 rounds of SHA-256) for a 16 bytes-Encryption Key, a 16 bytes-IV, and a 32 bytes-MAC Key.
Note: This is just pseudo code to put my question with necessary details.
DerivationFunction df = DerivationFunction.getInstance(DerivationFunction.ALG_KDF_ANSI_X9_63, false);
df.init(KDFAnsiX963Spec(MessageDigest.ALG_SHA_256, input, sharedInfo, (short) 64);
SecretKey encKey = KeyBuilder.buildKey(KeyBuilder.TYPE_AES, (short)16, false);
SecretKey macKey = KeyBuilder.buildKey(KeyBuilder.TYPE_HMAC, (short)32, false);
df.nextBytes(encKey);
df.nextBytes(IVBuffer, (short)0, (short)16);
df.lastBytes(macKey);
I have the following questions:
When rounds of KDF are performed? Are these performed during df.init() or during
df.nextBytes()
&df.lastBytes()
?One KDF round will generate 32 bytes output (considering SHA-256 algorithm) then how API's
df.nextBytes()
&df.lastBytes()
will work with any output expected length < 32 bytes?In this KDF counter is incremented in every next round then how counter will be managed between
df.nextBytes()
&df.lastBytes()
API's?