20 #include <openssl/rand.h> 
   21 #include <openssl/bio.h> 
   22 #include <openssl/pem.h> 
   23 #include <openssl/err.h> 
   37 #error HAVE_OPENSSL not defines, this file should not be included 
   40 static inline const BIGNUM*
 
   41 rsa_get_n(
const RSA *rsa)
 
   44     const BIGNUM *n, *e, *d;
 
   45     RSA_get0_key(rsa, &n, &e, &d);
 
   53 tds5_rsa_encrypt(
const void *key, 
size_t key_len, 
const void *nonce, 
size_t nonce_len, 
const char *pwd, 
size_t *em_size)
 
   58     uint8_t *message = NULL;
 
   59     size_t message_len, pwd_len;
 
   64     keybio = BIO_new_mem_buf((
void*) key, key_len);
 
   68     rsa = PEM_read_bio_RSAPublicKey(keybio, &rsa, NULL, NULL);
 
   72     pwd_len = strlen(pwd);
 
   73     message_len = nonce_len + pwd_len;
 
   74     message = tds_new(uint8_t, message_len);
 
   77     memcpy(message, nonce, nonce_len);
 
   78     memcpy(message + nonce_len, pwd, pwd_len);
 
   80     em = tds_new(uint8_t, BN_num_bytes(rsa_get_n(rsa)));
 
   84     result = RSA_public_encrypt(message_len, message, em, rsa, RSA_PKCS1_OAEP_PADDING);