Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/ntp/ntpd/ntp_crypto.c
Show First 20 Lines • Show All 858 Lines • ▼ Show 20 Lines | case CRYPTO_COOK | CRYPTO_RESP: | ||||
peer)) != XEVNT_OK) | peer)) != XEVNT_OK) | ||||
break; | break; | ||||
/* | /* | ||||
* Decrypt the cookie, hunting all the time for | * Decrypt the cookie, hunting all the time for | ||||
* errors. | * errors. | ||||
*/ | */ | ||||
if (vallen == (u_int) EVP_PKEY_size(host_pkey)) { | if (vallen == (u_int) EVP_PKEY_size(host_pkey)) { | ||||
RSA_private_decrypt(vallen, | u_int32 *cookiebuf = malloc( | ||||
RSA_size(host_pkey->pkey.rsa)); | |||||
if (cookiebuf == NULL) { | |||||
rval = XEVNT_CKY; | |||||
break; | |||||
} | |||||
if (RSA_private_decrypt(vallen, | |||||
(u_char *)ep->pkt, | (u_char *)ep->pkt, | ||||
(u_char *)&temp32, | (u_char *)cookiebuf, | ||||
host_pkey->pkey.rsa, | host_pkey->pkey.rsa, | ||||
RSA_PKCS1_OAEP_PADDING); | RSA_PKCS1_OAEP_PADDING) != 4) { | ||||
cookie = ntohl(temp32); | rval = XEVNT_CKY; | ||||
free(cookiebuf); | |||||
break; | |||||
} else { | } else { | ||||
cookie = ntohl(*cookiebuf); | |||||
free(cookiebuf); | |||||
} | |||||
} else { | |||||
rval = XEVNT_CKY; | rval = XEVNT_CKY; | ||||
break; | break; | ||||
} | } | ||||
/* | /* | ||||
* Install cookie values and light the cookie | * Install cookie values and light the cookie | ||||
* bit. If this is not broadcast client mode, we | * bit. If this is not broadcast client mode, we | ||||
* are done here. | * are done here. | ||||
▲ Show 20 Lines • Show All 3,027 Lines • ▼ Show 20 Lines | if (rand_file == NULL) { | ||||
exit (-1); | exit (-1); | ||||
} | } | ||||
if ((bytes = RAND_load_file(rand_file, -1)) == 0) { | if ((bytes = RAND_load_file(rand_file, -1)) == 0) { | ||||
msyslog(LOG_ERR, | msyslog(LOG_ERR, | ||||
"crypto_setup: random seed file %s not found\n", | "crypto_setup: random seed file %s not found\n", | ||||
rand_file); | rand_file); | ||||
exit (-1); | exit (-1); | ||||
} | } | ||||
get_systime(&seed); | arc4random_buf(&seed, sizeof(l_fp)); | ||||
RAND_seed(&seed, sizeof(l_fp)); | RAND_seed(&seed, sizeof(l_fp)); | ||||
RAND_write_file(rand_file); | RAND_write_file(rand_file); | ||||
OpenSSL_add_all_algorithms(); | OpenSSL_add_all_algorithms(); | ||||
#ifdef DEBUG | #ifdef DEBUG | ||||
if (debug) | if (debug) | ||||
printf( | printf( | ||||
"crypto_setup: OpenSSL version %lx random seed file %s bytes read %d\n", | "crypto_setup: OpenSSL version %lx random seed file %s bytes read %d\n", | ||||
SSLeay(), rand_file, bytes); | SSLeay(), rand_file, bytes); | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |