/* Psuedo-random function. TLS uses this for key generation and hashing */ int32_t prf(const unsigned char *sec, uint16_t secLen, const unsigned char *seed, uint16_t seedLen, unsigned char *out, uint16_t outLen) { const unsigned char *s1, *s2; unsigned char md5out[SSL_MAX_KEY_BLOCK_SIZE]; unsigned char sha1out[SSL_MAX_KEY_BLOCK_SIZE]; int32_t rc = PS_FAIL; uint16_t sLen, i; psAssert(outLen <= SSL_MAX_KEY_BLOCK_SIZE); sLen = (secLen / 2) + (secLen % 2); s1 = sec; s2 = (sec + sLen) - (secLen % 2); if ((rc = pMd5(s1, sLen, seed, seedLen, md5out, outLen)) < 0) { goto L_RETURN; } if ((rc = pSha1(s2, sLen, seed, seedLen, sha1out, outLen)) < 0) { goto L_RETURN; } for (i = 0; i < outLen; i++) { out[i] = md5out[i] ^ sha1out[i]; } rc = outLen; L_RETURN: memzero_s(md5out, SSL_MAX_KEY_BLOCK_SIZE); memzero_s(sha1out, SSL_MAX_KEY_BLOCK_SIZE); return rc; }
/* Psuedo-random function. TLS uses this for key generation and hashing */ static int32 prf(unsigned char *sec, uint32 secLen, unsigned char *seed, uint32 seedLen, unsigned char *out, uint32 outLen) { unsigned char *s1, *s2; unsigned char md5out[SSL_MAX_KEY_BLOCK_SIZE]; unsigned char sha1out[SSL_MAX_KEY_BLOCK_SIZE]; uint32 sLen, i; psAssert(outLen <= SSL_MAX_KEY_BLOCK_SIZE); sLen = (secLen / 2) + (secLen % 2); s1 = sec; s2 = (sec + sLen) - (secLen % 2); pMd5(s1, sLen, seed, seedLen, md5out, outLen); pSha1(s2, sLen, seed, seedLen, sha1out, outLen); for (i = 0; i < outLen; i++) { out[i] = md5out[i] ^ sha1out[i]; } return outLen; }