Hi,
ich muss für eine Entschlüsselung einen HKDFKey als SharedKey aus folgenden Werten berechnen:
Delphi-Quellcode:
echdSharedSecret:=$8F 81 9B C0 85 A9 CF 72 B4 15 67 16 BF A4 87 65 6C F7 A4 89 B4 F4 6A FC 67 48 03 8F 60 3E D6 2D
salt:=$70 2F A6 37 16 BB 17 61 3A A1 14 1A 25 F8 C7 63 7A 9B 67 28 B7 5E C4 C9 BD 04 60 C6 F4 5E 24 8A 1F 17 9F 6B B6 AD 2C CF C5 68 89 F6 6C 6B 68 52 BF D2 08 DE B8 BA F9 F7 28 6B 40 2D 5E 38 00 0F 1E 81 D6 E7 C5 18 23 06 E3 88 41 8C 4F 51 E6 F9 31 59 97 29 00 16 E8 98 9F 3A 6F F2 2C 0C E9 AC A6 86 F4 7C 88 60 5C 5C 47 35 A2 BD 29 E5 51 77 92 C4 9D E5 64 48 7C 1E C8 F1 A7 55 8A 6D 00 72
expected result: $AE FC 45
FB E4 9B 90 15 17 B1 4B C4 E7 83 D2 0E 43 74 D4 52 37 66 C7 CA 86 39 75 17 35 88 80 C8 23 99 CB A1
Ich habe es mit TMSCryptography-Pack ausprobiert, war aber noch nicht erfolgreich:
Delphi-Quellcode:
function getHKDFKey(echdSharedSecret,salt:
String):
String;
var hkdf: THKDFKeyDerivation;
ecdhSharedSecret,salt:
String;
PRK:
string;
begin
hkdf:= THKDFKeyDerivation.Create();
try
hkdf.Unicode:= TUnicode.yesUni;
hkdf.OutputFormat:= hexa;
hkdf.hashFunction := hsha2;
hkdf.hashSizeBits := 256;
//ECDH secret obtained in the previous step
//A Message Digest function (also known as Hash function), in this case is SHA256
//A key length, 36 bytes in this case
//A Salt value, which in this case is the concatenation of both public keys,
//the device public key material received and the local public key material, in that order
//• Constructor Create(AOwner: TComponent); overload; override; the default constructor from the TComponent class
//• Constructor Create; overload; the default constructor
//• Constructor Create(outputFormat: TConvertType; uni: TUnicode; hashF:THashFunction; hashSB: Integer); overload;
//• function Extract(s, salt: string): string; to generate a pseudo random key from a message s and a salt
//• function Expand(s, info: string; len: Integer): string; to generate a key of length len from the resulting key of Extract function, s, and an info string
//• property hashFunction: THashFunction read FHashFunction write FHashFunction; to read and write the hash function used into HKDF algorithm
//• property OutputFormat: TConvertType read FOutputFormat write FoutputFormat; to read and write the output format of the data (see Converter class section)
//• property hashSizeBits: Integer read FHashSizeBits write SetHashSizeBits; to read and write the number of output bits of the hash function used in HKDF algorithm
//• property Unicode: TUnicode read FUni write FUni; to indicate whether the input buffer has Unicode characters
PRK:= hkdf.Extract(ecdhSharedSecret, salt);
result:= hkdf.Expand(PRK, '
', 36);
finally
HKDF.Free;
end;
end;
Hat da jemand eine andere Idee? Gerne auch per
DEC, da ich diese schon im nächsten Schritt (erfolgreich) für die Entschlüsselung der eigentlichen Kommunikation nutze.
Grüße, Philipp
Grüße, Philipp