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
41 tds5_rsa_encrypt(
const void *key,
size_t key_len,
const void *nonce,
size_t nonce_len,
const char *pwd,
size_t *em_size)
46 uint8_t *message = NULL;
47 size_t message_len, pwd_len;
52 keybio = BIO_new_mem_buf((
void*) key, key_len);
56 rsa = PEM_read_bio_RSAPublicKey(keybio, &rsa, NULL, NULL);
60 pwd_len = strlen(pwd);
61 message_len = nonce_len + pwd_len;
62 message = tds_new(uint8_t, message_len);
65 memcpy(message, nonce, nonce_len);
66 memcpy(message + nonce_len, pwd, pwd_len);
68 em = tds_new(uint8_t, BN_num_bytes(rsa->n));
72 result = RSA_public_encrypt(message_len, message, em, rsa, RSA_PKCS1_OAEP_PADDING);