我编写了一些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,但我听不懂。
请问有人可以解释一下吗?
答案 0 :(得分:0)
加密/解密以这种方式发生:
设置1 :您的rsa_pub_enc
可以指向RSA_public_encrypt
的实现,而rsa_priv_dec
可以指向RSA_private_decrypt
设置2 :您的rsa_priv_enc
可以指向RSA_private_encrypt
的实现,而rsa_pub_dec
可以指向RSA_public_decrypt
用户设置1 ,因为始终可以保护私钥安全