I have been trying to calculate the master secret used to encrypt some data using the client public key B
, the server private key a
and the client and server random values. I have calculated k=B^a
, which to my understanding gives me the premaster secret. I then input this together with the random values into the following PRF function (page 15 of this pdf):
def prf(secret,label,seed,numblocks):
seed=label+seed
output = ''
a=hmac.new(secret,msg=seed,digestmod=hashlib.sha256).digest()
for j in range(numblocks):
output += hmac.new(secret,msg=a+seed,digestmod=hashlib.sha256).digest()
a=hmac.new(secret,msg=a,digestmod=hashlib.sha256).digest()
return output
def master_secret(pms,client_random,server_random):
out=prf(pms,"master secret",client_random+server_random,2)
return out[:48]
According to the RFC specification for TLS1.2, this should output the master secret, but when verifying it with the data I have, it is wrong. Where is my mistake?