static int cipher_desx_cbc_code(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) { int ret = DESX_CBCUpdate(data(ctx), out, (unsigned char *)in, inl); switch (ret) { case RE_LEN: RSAREFerr(RSAREF_F_CIPHER_DES_CBC_CODE,RSAREF_R_LENGTH_NOT_BLOCK_ALIGNED); break; case 0: break; default: RSAREFerr(RSAREF_F_CIPHER_DES_CBC_CODE,RSAREF_R_UNKNOWN_FAULT); } return !ret; }
static int rsaref_public_encrypt(int len, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) { int outlen= -1; int i; R_RSA_PUBLIC_KEY RSAkey; R_RANDOM_STRUCT rnd; unsigned char buf[16]; if (padding != RSA_PKCS1_PADDING && padding != RSA_SSLV23_PADDING) { RSAREFerr(RSAREF_F_RSAREF_PUBLIC_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE); goto err; } R_RandomInit(&rnd); R_GetRandomBytesNeeded((unsigned int *)&i,&rnd); while (i > 0) { if (RAND_bytes(buf,16) <= 0) goto err; R_RandomUpdate(&rnd,buf,(unsigned int)((i>16)?16:i)); i-=16; } if (!RSAref_Public_eay2ref(rsa,&RSAkey)) goto err; if ((i=RSAPublicEncrypt(to,(unsigned int *)&outlen,(unsigned char *)from,len,&RSAkey,&rnd)) != 0) { RSAREFerr(RSAREF_F_RSAREF_PUBLIC_ENCRYPT,i); outlen= -1; goto err; } err: memset(&RSAkey,0,sizeof(RSAkey)); R_RandomFinal(&rnd); memset(&rnd,0,sizeof(rnd)); return(outlen); }
static int rsaref_private_encrypt(int len, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) { int i,outlen= -1; R_RSA_PRIVATE_KEY RSAkey; if (padding != RSA_PKCS1_PADDING) { RSAREFerr(RSAREF_F_RSAREF_PRIVATE_ENCRYPT, RSA_R_UNKNOWN_PADDING_TYPE); goto err; } if (!RSAref_Private_eay2ref(rsa,&RSAkey)) goto err; if ((i=RSAPrivateEncrypt(to,(unsigned int *)&outlen,(unsigned char *)from,len,&RSAkey)) != 0) { RSAREFerr(RSAREF_F_RSAREF_PRIVATE_ENCRYPT,i); outlen= -1; } err: memset(&RSAkey,0,sizeof(RSAkey)); return(outlen); }
/* unsigned char *to: [max] */ static int RSAref_bn2bin(BIGNUM *from, unsigned char *to, int max) { int i; i = BN_num_bytes(from); if (i > max) { RSAREFerr(RSAREF_F_RSAREF_BN2BIN, RSAREF_R_LEN); return (0); } memset(to, 0, (unsigned int)max); if (!BN_bn2bin(from, &(to[max - i]))) return (0); return (1); }
static int rsaref_public_decrypt(int len, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) { int i,outlen= -1; R_RSA_PUBLIC_KEY RSAkey; if (!RSAref_Public_eay2ref(rsa,&RSAkey)) goto err; if ((i=RSAPublicDecrypt(to,(unsigned int *)&outlen,(unsigned char *)from,len,&RSAkey)) != 0) { RSAREFerr(RSAREF_F_RSAREF_PUBLIC_DECRYPT,i); outlen= -1; } err: memset(&RSAkey,0,sizeof(RSAkey)); return(outlen); }
static int bnref_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx) { RSAREFerr(RSAREF_F_BNREF_MOD_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return(0); }
static int rsaref_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa) { RSAREFerr(RSAREF_F_RSAREF_MOD_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return(0); }