Lines Matching refs:rsa
1 /* $NetBSD: rsa.c,v 1.2 2017/01/28 21:31:47 christos Exp $ */
43 #include <rsa.h>
57 * same rsa keys (1024 and 2048)
101 RSA *rsa;
103 rsa = calloc(1, sizeof(*rsa));
104 if (rsa == NULL)
107 rsa->references = 1;
111 rsa->engine = engine;
113 rsa->engine = ENGINE_get_default_RSA();
116 if (rsa->engine) {
117 rsa->meth = ENGINE_get_RSA(rsa->engine);
118 if (rsa->meth == NULL) {
120 free(rsa);
125 if (rsa->meth == NULL)
126 rsa->meth = rk_UNCONST(RSA_get_default_method());
128 (*rsa->meth->init)(rsa);
130 return rsa;
136 * @param rsa the RSA object to free.
141 RSA_free(RSA *rsa)
143 if (rsa->references <= 0)
146 if (--rsa->references > 0)
149 (*rsa->meth->finish)(rsa);
151 if (rsa->engine)
152 ENGINE_finish(rsa->engine);
155 free_if(rsa->n);
156 free_if(rsa->e);
157 free_if(rsa->d);
158 free_if(rsa->p);
159 free_if(rsa->q);
160 free_if(rsa->dmp1);
161 free_if(rsa->dmq1);
162 free_if(rsa->iqmp);
165 memset(rsa, 0, sizeof(*rsa));
166 free(rsa);
173 * @param rsa the object to add reference counting too.
182 RSA_up_ref(RSA *rsa)
184 return ++rsa->references;
190 * @param rsa the object to get the method from.
198 RSA_get_method(const RSA *rsa)
200 return rsa->meth;
206 * @param rsa rsa parameter.
215 RSA_set_method(RSA *rsa, const RSA_METHOD *method)
217 (*rsa->meth->finish)(rsa);
219 if (rsa->engine) {
220 ENGINE_finish(rsa->engine);
221 rsa->engine = NULL;
224 rsa->meth = method;
225 (*rsa->meth->init)(rsa);
232 * @param rsa the rsa object to set the parameter for
241 RSA_set_app_data(RSA *rsa, void *arg)
243 rsa->ex_data.sk = arg;
250 * @param rsa the rsa object to get the parameter for
258 RSA_get_app_data(const RSA *rsa)
260 return rsa->ex_data.sk;
267 RSA *rsa = rk_UNCONST(key);
277 if ((rsa->d == NULL || rsa->n == NULL) &&
278 (rsa->p == NULL || rsa->q || rsa->dmp1 == NULL || rsa->dmq1 == NULL || rsa->iqmp == NULL))
281 buffer = malloc(RSA_size(rsa));
286 rsa, RSA_PKCS1_PADDING);
293 rsa, RSA_PKCS1_PADDING);
308 RSA_size(const RSA *rsa)
310 return BN_num_bytes(rsa->n);
342 unsigned char *to, unsigned int *tlen, RSA *rsa)
344 if (rsa->meth->rsa_sign)
345 return rsa->meth->rsa_sign(type, from, flen, to, tlen, rsa);
347 if (rsa->meth->rsa_priv_enc) {
378 ret = rsa->meth->rsa_priv_enc(indata.length, indata.data, to,
379 rsa, RSA_PKCS1_PADDING);
395 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
397 if (rsa->meth->rsa_verify)
398 return rsa->meth->rsa_verify(type, from, flen, sigbuf, siglen, rsa);
400 if (rsa->meth->rsa_pub_dec) {
407 data = malloc(RSA_size(rsa));
413 ret = rsa->meth->rsa_pub_dec(siglen, sigbuf, data, rsa, RSA_PKCS1_PADDING);
485 null_rsa_init(RSA *rsa)
491 null_rsa_finish(RSA *rsa)
542 d2i_RSAPrivateKey(RSA *rsa, const unsigned char **pp, size_t len)
545 RSA *k = rsa;
584 i2d_RSAPrivateKey(RSA *rsa, unsigned char **pp)
590 if (rsa->n == NULL || rsa->e == NULL || rsa->d == NULL || rsa->p == NULL ||
591 rsa->q == NULL || rsa->dmp1 == NULL || rsa->dmq1 == NULL ||
592 rsa->iqmp == NULL)
597 ret = _hc_BN_to_integer(rsa->n, &data.modulus);
598 ret |= _hc_BN_to_integer(rsa->e, &data.publicExponent);
599 ret |= _hc_BN_to_integer(rsa->d, &data.privateExponent);
600 ret |= _hc_BN_to_integer(rsa->p, &data.prime1);
601 ret |= _hc_BN_to_integer(rsa->q, &data.prime2);
602 ret |= _hc_BN_to_integer(rsa->dmp1, &data.exponent1);
603 ret |= _hc_BN_to_integer(rsa->dmq1, &data.exponent2);
604 ret |= _hc_BN_to_integer(rsa->iqmp, &data.coefficient);
634 i2d_RSAPublicKey(RSA *rsa, unsigned char **pp)
642 if (_hc_BN_to_integer(rsa->n, &data.modulus) ||
643 _hc_BN_to_integer(rsa->e, &data.publicExponent))
673 d2i_RSAPublicKey(RSA *rsa, const unsigned char **pp, size_t len)
676 RSA *k = rsa;