Что я должен использовать в функциях OpenSSL rsa_pub_enc и rsa_pub_dec? - PullRequest
0 голосов
/ 19 сентября 2019

Я кодирую какой-нибудь ДВИГАТЕЛЬ OpenSSL.Он реализует другую реализацию RSA с помощью аппаратного обеспечения.

OpenSSL имеет функцию ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);.С помощью одного я могу установить мою новую реализацию.Тип RSA_METHOD содержит указатели на реализацию.

struct rsa_meth_st {
    const char *name;
    int (*rsa_pub_enc) (int flen, const unsigned char *from,
                        unsigned char *to, RSA *rsa, int padding);
    int (*rsa_pub_dec) (int flen, const unsigned char *from,
                        unsigned char *to, RSA *rsa, int padding);
    int (*rsa_priv_enc) (int flen, const unsigned char *from,
                         unsigned char *to, RSA *rsa, int padding);
    int (*rsa_priv_dec) (int flen, const unsigned char *from,
                         unsigned char *to, RSA *rsa, int padding);
    /* Can be null */
    int (*rsa_mod_exp) (BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
    /* Can be null */
    int (*bn_mod_exp) (BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
                       const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
    /* called at new */
    int (*init) (RSA *rsa);
    /* called at free */
    int (*finish) (RSA *rsa);
    /* RSA_METHOD_FLAG_* things */
    int flags;
    /* may be needed! */
    char *app_data;
    /*
     * New sign and verify functions: some libraries don't allow arbitrary
     * data to be signed/verified: this allows them to be used. Note: for
     * this to work the RSA_public_decrypt() and RSA_private_encrypt() should
     * *NOT* be used RSA_sign(), RSA_verify() should be used instead. Note:
     * for backwards compatibility this functionality is only enabled if the
     * RSA_FLAG_SIGN_VER option is set in 'flags'.
     */
    int (*rsa_sign) (int type,
                     const unsigned char *m, unsigned int m_length,
                     unsigned char *sigret, unsigned int *siglen,
                     const RSA *rsa);
    int (*rsa_verify) (int dtype, const unsigned char *m,
                       unsigned int m_length, const unsigned char *sigbuf,
                       unsigned int siglen, const RSA *rsa);
    /*
     * If this callback is NULL, the builtin software RSA key-gen will be
     * used. This is for behavioural compatibility whilst the code gets
     * rewired, but one day it would be nice to assume there are no such
     * things as "builtin software" implementations.
     */
    int (*rsa_keygen) (RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
};

Я не понимаю, что должны делать rsa_pub_enc и rsa_pub_dec.Должен ли он шифровать и дешифровать с помощью только PUBlic ключа?

И у меня тот же вопрос о rsa_priv_enc/rsa_priv_dec.Должен ли он шифровать и дешифровать только с помощью ключа PRIVate?

Я уже прочитал https://www.openssl.org/docs/manmaster/man3/RSA_public_encrypt.html и https://www.openssl.org/docs/man1.1.0/man3/RSA_public_decrypt.html,, но я не понял.

Может кто-нибудь объяснитьмне это, пожалуйста?

1 Ответ

0 голосов
/ 20 сентября 2019

Шифрование / дешифрование происходит следующим образом:

  1. Шифрование с использованием открытого ключа - Шифрование с использованием личного ключа (Предлагаемый и стандартный способ) или
  2. Шифрованиеиспользуя закрытый ключ - расшифруйте с помощью открытого ключа

Установите 1 : ваш rsa_pub_enc может указывать на реализацию RSA_public_encrypt, а rsa_priv_dec может указывать на RSA_private_decrypt

Set 2 : ваш rsa_priv_enc может указывать на реализацию RSA_private_encrypt, а rsa_pub_dec может указывать на RSA_public_decrypt

User Set 1 потому что всегда хорошо хранить секретный ключ в безопасности

...