Hi, first of all, great job !!
I am interfacing with a C program which uses WolfSSL, but I obtain different result with the same inputs:
The C code:
#define HashDefinitions_HashType__HASH_TYPE_SHA512 5
int32_t main(int32_t argc, char *(argv[]))
{
uint8_t salt[32] = {
0x10u, 0x20u, 0x30u, 0x40u, 0x50u, 0x60u, 0x70u, 0x80u, 0x90u, 0x93u, 0x96u,
0x11u, 0x21u, 0x31u, 0x41u, 0x51u, 0x61u, 0x71u, 0x81u, 0x91u, 0x94u, 0x97u,
0x12u, 0x22u, 0x32u, 0x42u, 0x52u, 0x62u, 0x72u, 0x82u, 0x92u, 0x95u };
uint8_t sharedSecret[32] = {
0xE8u, 0xEDu, 0x47u, 0xCEu, 0x79u, 0x3Fu, 0x6Bu, 0xE8u, 0x5Du, 0xF5u, 0x96u,
0xB6u, 0x59u, 0xB1u, 0x7Au, 0x0Eu, 0x0Au, 0xB7u, 0xD5u, 0xCCu, 0x43u, 0xDCu,
0x45u, 0x49u, 0x2Cu, 0xC6u, 0x97u, 0x05u, 0x75u, 0xC3u, 0xB3u, 0x68u };
uint8_t derivedKey1[32];
int32_t ret = wc_HKDF(HashDefinitions_HashType__HASH_TYPE_SHA512, sharedSecret, sizeof(sharedSecret), salt, sizeof(salt), NULL, 0, derivedKey1, 32);
Main_printData("Result", derivedKey1, 32);
// Result: b7986122a3974da0bdb542f8a5df6ec2b2d45bfcbf9c67bef1188d764cc9066d
return ret;
}
void Main_printData(char *msg, uint8_t *data, uint32_t len)
{
printf(msg);
printf(": ");
for ( int64_t __i = 0 ; __i < len; __i++ )
{
printf("%02x", data[__i]);
}
printf("\n");
}
And my Kotlin program (sorry it's not Java, but it is almost the same)
fun main(args: Array<String>) {
val salt=ByteUtil.byteArrayOfInts(0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80,0x90,0x93,0x96,0x11,
0x21,0x31,0x41,0x51,0x61,0x71,0x81,0x91,0x94,0x97,0x12,0x22,0x32,0x42,0x52,0x62,0x72,0x82,0x92,0x95);
val sharedSecret =ByteUtil.byteArrayOfInts(0xE8, 0xED, 0x47, 0xCE, 0x79, 0x3F, 0x6B, 0xE8, 0x5D,
0xF5, 0x96, 0xB6, 0x59, 0xB1, 0x7A, 0x0E, 0x0A, 0xB7, 0xD5, 0xCC, 0x43, 0xDC, 0x45, 0x49, 0x2C, 0xC6, 0x97,
0x05, 0x75, 0xC3, 0xB3, 0x68
);
println("Salt: "+format(salt));
println("Shared Secret: "+format(sharedSecret));
val hkdf = HKDF.fromHmacSha512();
val pseudoRandomKey = hkdf.extract(salt, sharedSecret)
val expand = hkdf.expand(pseudoRandomKey, null, 32)
println("Derived Key 1: " + format(expand));
// Result is 1b01b30e3afb8369a7be2c3362dac46185ee7d0c4494a66770d49d424e6b8fa8
}
fun format(ba: ByteArray): String {
return ba.joinToString("") { String.format("%02x", it) };
}
Am I missing something there? Is it something that deals with indianness or displaying values? Or is there some difference in the implementation which doesn't matter in the end?