120 static int RSA_eay_public_encrypt(
int flen,
const unsigned char *from,
121 unsigned char *to,
RSA *rsa,
int padding);
122 static int RSA_eay_private_encrypt(
int flen,
const unsigned char *from,
123 unsigned char *to,
RSA *rsa,
int padding);
124 static int RSA_eay_public_decrypt(
int flen,
const unsigned char *from,
125 unsigned char *to,
RSA *rsa,
int padding);
126 static int RSA_eay_private_decrypt(
int flen,
const unsigned char *from,
127 unsigned char *to,
RSA *rsa,
int padding);
129 static int RSA_eay_init(
RSA *rsa);
130 static int RSA_eay_finish(
RSA *rsa);
132 "Eric Young's PKCS#1 RSA",
133 RSA_eay_public_encrypt,
134 RSA_eay_public_decrypt,
135 RSA_eay_private_encrypt,
136 RSA_eay_private_decrypt,
150 return(&rsa_pkcs1_eay_meth);
153 static int RSA_eay_public_encrypt(
int flen,
const unsigned char *from,
154 unsigned char *to,
RSA *rsa,
int padding)
157 int i,j,
k,
num=0,r= -1;
158 unsigned char *buf=NULL;
189 if (!f || !ret || !buf)
200 #ifndef OPENSSL_NO_SHA
215 if (i <= 0)
goto err;
217 if (
BN_bin2bn(buf,num,f) == NULL)
goto err;
237 for (k=0; k<(num-i); k++)
258 int got_write_lock = 0;
350 static int RSA_eay_private_encrypt(
int flen,
const unsigned char *from,
351 unsigned char *to,
RSA *rsa,
int padding)
354 int i,j,k,num=0,r= -1;
355 unsigned char *buf=NULL;
357 int local_blinding = 0;
370 if(!f || !ret || !buf)
392 if (i <= 0)
goto err;
394 if (
BN_bin2bn(buf,num,f) == NULL)
goto err;
405 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
406 if (blinding == NULL)
413 if (blinding != NULL)
415 if (!local_blinding && ((unblind =
BN_CTX_get(ctx)) == NULL))
420 if (!rsa_blinding_convert(blinding, f, unblind, ctx))
427 (rsa->
dmp1 != NULL) &&
428 (rsa->
dmq1 != NULL) &&
429 (rsa->
iqmp != NULL)) )
456 if (!rsa_blinding_invert(blinding, ret, unblind, ctx))
474 for (k=0; k<(num-i); k++)
492 static int RSA_eay_private_decrypt(
int flen,
const unsigned char *from,
493 unsigned char *to,
RSA *rsa,
int padding)
498 unsigned char *buf=NULL;
500 int local_blinding = 0;
513 if(!f || !ret || !buf)
528 if (
BN_bin2bn(from,(
int)flen,f) == NULL)
goto err;
538 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
539 if (blinding == NULL)
546 if (blinding != NULL)
548 if (!local_blinding && ((unblind =
BN_CTX_get(ctx)) == NULL))
553 if (!rsa_blinding_convert(blinding, f, unblind, ctx))
561 (rsa->
dmp1 != NULL) &&
562 (rsa->
dmq1 != NULL) &&
563 (rsa->
iqmp != NULL)) )
589 if (!rsa_blinding_invert(blinding, ret, unblind, ctx))
600 #ifndef OPENSSL_NO_SHA
633 static int RSA_eay_public_decrypt(
int flen,
const unsigned char *from,
634 unsigned char *to,
RSA *rsa,
int padding)
639 unsigned char *buf=NULL;
670 if(!f || !ret || !buf)
684 if (
BN_bin2bn(from,flen,f) == NULL)
goto err;
700 if (!
BN_sub(ret, rsa->
n, ret))
goto err;
740 BIGNUM local_dmp1,local_dmq1,local_c,local_r1;
790 if (!
BN_mod(r1,c,rsa->
q,ctx))
goto err;
794 if (!
BN_mod(r1,I,rsa->
q,ctx))
goto err;
813 if (!
BN_mod(r1,c,rsa->
p,ctx))
goto err;
817 if (!
BN_mod(r1,I,rsa->
p,ctx))
goto err;
831 if (!
BN_sub(r0,r0,m1))
goto err;
835 if (!
BN_add(r0,r0,rsa->
p))
goto err;
847 if (!
BN_mod(r0,pr1,rsa->
p,ctx))
goto err;
857 if (!
BN_add(r0,r0,rsa->
p))
goto err;
858 if (!
BN_mul(r1,r0,rsa->
q,ctx))
goto err;
859 if (!
BN_add(r0,r1,m1))
goto err;
861 if (rsa->
e && rsa->
n)
868 if (!
BN_sub(vrfy, vrfy, I))
goto err;
869 if (!
BN_mod(vrfy, vrfy, rsa->
n, ctx))
goto err;
871 if (!
BN_add(vrfy, vrfy, rsa->
n))
goto err;
898 static int RSA_eay_init(
RSA *rsa)
904 static int RSA_eay_finish(
RSA *rsa)