Библиотека SSLeay. Модуль RSA. Как пользоваться API ?
RSA * RSA_new(void);
RSA * RSA_new_method(RSA_METHOD *method);
int RSA_size(RSA *);
RSA * RSA_generate_key(int bits, unsigned long e,void
(*callback)(int,int,char *),char *cb_arg);
/* next 4 return -1 on error */
int RSA_public_encrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
int RSA_private_encrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
int RSA_public_decrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
int RSA_private_decrypt(int flen, unsigned char *from,
unsigned char *to, RSA *rsa,int padding);
void RSA_free (RSA *r);
И что ? Как юзить то ????
Написал так:
RSA* rsa = RSA_new( );
RSA_public_encrypt( sizeof( buffer ), buffer, bufferEnc, rsa, 0 );
RSA_private_decrypt( sizeof( buffer ), bufferEnc, bufferDec, rsa, 0 );
Но падает по памяти на RSA_public_encrypt.
Структура RSA описана так:
typedef struct rsa_st
{
/* The first parameter is used to pickup errors where
* this is passed instead of aEVP_PKEY, it is set to 0 */
int pad;
int version;
RSA_METHOD *meth;
BIGNUM *n;
BIGNUM *e;
BIGNUM *d;
BIGNUM *p;
BIGNUM *q;
BIGNUM *dmp1;
BIGNUM *dmq1;
BIGNUM *iqmp;
/* be carefull using this if the RSA structure is shared */
CRYPTO_EX_DATA ex_data;
int references;
int flags;
/* Normally used to cached montgomery values */
char *method_mod_n;
char *method_mod_p;
char *method_mod_q;
BN_BLINDING *blinding;
} RSA;
Как я понимаю секретный ключ n и d, а открытый n и e. Правильно ?
Но кто мне их генерить то будет ? И какую ф-ю для этого вызывать ?
RSA_generate_key вообще не ясно что делает и что ей требуется. Что это за колбэк там такой ?
Вообщем полный трендец.
Кто уже юзел - отзовитесь !
Я понял !!! :)))10.10.01 11:26 Автор: PS <PS> Статус: Elderman
Вот собственно и все. Только надо исправить ошибку в SSleay:
rsa_eay.c line 305
Поменять
if(!rsa->meth->bn_mod_exp(ret,f,rsa->d,rsa->n,ctx))
На
if(!rsa->meth->bn_mod_exp(ret,f,rsa->d,rsa->n,ctx, NULL))
Они забыли последний параметр вписать :)
Полный текст программы!!14.10.01 15:24 Автор: emergenter Статус: Незарегистрированный пользователь