1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
|
/*
* Copyright (c) 2006 - 2007, 2010 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <config.h>
#include <roken.h>
#include <krb5-types.h>
#include <assert.h>
#include <rsa.h>
#include "tommath.h"
#define CHECK(f) \
do { if (ret == MP_OKAY && ((ret = f)) != MP_OKAY) { goto out; } } while (0)
#define FIRST(e) do { ret = (e); } while (0)
#define FIRST_ALLOC(e) \
do { where = __LINE__; ret = ((e)) ? MP_OKAY : MP_MEM; } while (0)
#define THEN_MP(e) \
do { where = __LINE__ + 1; if (ret == MP_OKAY) ret = (e); } while (0)
#define THEN_IF_MP(cond, e) \
do { where = __LINE__ + 1; if (ret == MP_OKAY && (cond)) ret = (e); } while (0)
#define THEN_IF_VOID(cond, e) \
do { if (ret == MP_OKAY && (cond)) e; } while (0)
#define THEN_VOID(e) \
do { if (ret == MP_OKAY) e; } while (0)
#define THEN_ALLOC(e) \
do { where = __LINE__ + 1; if (ret == MP_OKAY) ret = ((e)) ? MP_OKAY : MP_MEM; } while (0)
static mp_err
random_num(mp_int *num, size_t len)
{
unsigned char *p;
mp_err ret = MP_MEM;
len = (len + 7) / 8; /* bits to bytes */
if ((p = malloc(len)) && RAND_bytes(p, len) != 1)
ret = MP_ERR;
if (p)
ret = mp_from_ubin(num, p, len);
free(p);
return ret;
}
static mp_err
BN2mpz(mp_int *s, const BIGNUM *bn)
{
size_t len;
mp_err ret = MP_MEM;
void *p;
len = BN_num_bytes(bn);
p = malloc(len);
if (p) {
BN_bn2bin(bn, p);
ret = mp_from_ubin(s, p, len);
}
free(p);
return ret;
}
static mp_err
setup_blind(mp_int *n, mp_int *b, mp_int *bi)
{
mp_err ret;
ret = random_num(b, mp_count_bits(n));
if (ret == MP_OKAY) ret = mp_mod(b, n, b);
if (ret == MP_OKAY) ret = mp_invmod(b, n, bi);
return ret;
}
static mp_err
blind(mp_int *in, mp_int *b, mp_int *e, mp_int *n)
{
mp_err ret;
mp_int t1;
ret = mp_init(&t1);
/* in' = (in * b^e) mod n */
if (ret == MP_OKAY) ret = mp_exptmod(b, e, n, &t1);
if (ret == MP_OKAY) ret = mp_mul(&t1, in, in);
if (ret == MP_OKAY) ret = mp_mod(in, n, in);
mp_clear(&t1);
return ret;
}
static mp_err
unblind(mp_int *out, mp_int *bi, mp_int *n)
{
mp_err ret;
/* out' = (out * 1/b) mod n */
ret = mp_mul(out, bi, out);
if (ret == MP_OKAY) ret = mp_mod(out, n, out);
return ret;
}
static mp_err
ltm_rsa_private_calculate(mp_int * in, mp_int * p, mp_int * q,
mp_int * dmp1, mp_int * dmq1, mp_int * iqmp,
mp_int * out)
{
mp_err ret;
mp_int vp, vq, u;
int where HEIMDAL_UNUSED_ATTRIBUTE = 0;
FIRST(mp_init_multi(&vp, &vq, &u, NULL));
/* vq = c ^ (d mod (q - 1)) mod q */
/* vp = c ^ (d mod (p - 1)) mod p */
THEN_MP(mp_mod(in, p, &u));
THEN_MP(mp_exptmod(&u, dmp1, p, &vp));
THEN_MP(mp_mod(in, q, &u));
THEN_MP(mp_exptmod(&u, dmq1, q, &vq));
/* C2 = 1/q mod p (iqmp) */
/* u = (vp - vq)C2 mod p. */
THEN_MP(mp_sub(&vp, &vq, &u));
THEN_IF_MP(mp_isneg(&u), mp_add(&u, p, &u));
THEN_MP(mp_mul(&u, iqmp, &u));
THEN_MP(mp_mod(&u, p, &u));
/* c ^ d mod n = vq + u q */
THEN_MP(mp_mul(&u, q, &u));
THEN_MP(mp_add(&u, &vq, out));
mp_clear_multi(&vp, &vq, &u, NULL);
return ret;
}
/*
*
*/
static int
ltm_rsa_public_encrypt(int flen, const unsigned char* from,
unsigned char* to, RSA* rsa, int padding)
{
unsigned char *p = NULL, *p0 = NULL;
size_t size, ssize, padlen;
mp_int enc, dec, n, e;
mp_err ret;
int where = __LINE__;
if (padding != RSA_PKCS1_PADDING)
return -1;
FIRST(mp_init_multi(&n, &e, &enc, &dec, NULL));
size = RSA_size(rsa);
THEN_IF_MP((size < RSA_PKCS1_PADDING_SIZE ||
size - RSA_PKCS1_PADDING_SIZE < flen),
MP_ERR);
THEN_MP(BN2mpz(&n, rsa->n));
THEN_MP(BN2mpz(&e, rsa->e));
THEN_IF_MP((mp_cmp_d(&e, 3) == MP_LT), MP_ERR);
THEN_ALLOC((p = p0 = malloc(size - 1)));
if (ret == MP_OKAY) {
padlen = size - flen - 3;
*p++ = 2;
}
THEN_IF_MP((RAND_bytes(p, padlen) != 1), MP_ERR);
if (ret == MP_OKAY) {
while (padlen) {
if (*p == 0)
*p = 1;
padlen--;
p++;
}
*p++ = 0;
memcpy(p, from, flen);
p += flen;
assert((p - p0) == size - 1);
}
THEN_MP(mp_from_ubin(&dec, p0, size - 1));
THEN_MP(mp_exptmod(&dec, &e, &n, &enc));
THEN_VOID(ssize = mp_ubin_size(&enc));
THEN_VOID(assert(size >= ssize));
THEN_MP(mp_to_ubin(&enc, to, SIZE_MAX, NULL));
THEN_VOID(size = ssize);
mp_clear_multi(&dec, &e, &n, NULL);
mp_clear(&enc);
free(p0);
return ret == MP_OKAY ? size : -where;
}
static int
ltm_rsa_public_decrypt(int flen, const unsigned char* from,
unsigned char* to, RSA* rsa, int padding)
{
unsigned char *p;
mp_err ret;
size_t size;
mp_int s, us, n, e;
int where = 0;
if (padding != RSA_PKCS1_PADDING)
return -1;
if (flen > RSA_size(rsa))
return -2;
FIRST(mp_init_multi(&e, &n, &s, &us, NULL));
THEN_MP(BN2mpz(&n, rsa->n));
THEN_MP(BN2mpz(&e, rsa->e));
THEN_MP((mp_cmp_d(&e, 3) == MP_LT) ? MP_ERR : MP_OKAY);
THEN_MP(mp_from_ubin(&s, rk_UNCONST(from), (size_t)flen));
THEN_MP((mp_cmp(&s, &n) >= 0) ? MP_ERR : MP_OKAY);
THEN_MP(mp_exptmod(&s, &e, &n, &us));
THEN_VOID(p = to);
THEN_VOID(size = mp_ubin_size(&us));
THEN_VOID(assert(size <= RSA_size(rsa)));
THEN_MP(mp_to_ubin(&us, p, SIZE_MAX, NULL));
mp_clear_multi(&e, &n, &s, NULL);
mp_clear(&us);
if (ret != MP_OKAY)
return -where;
/* head zero was skipped by mp_to_unsigned_bin */
if (*p == 0)
return -where;
if (*p != 1)
return -(where + 1);
size--; p++;
while (size && *p == 0xff) {
size--; p++;
}
if (size == 0 || *p != 0)
return -(where + 2);
size--; p++;
memmove(to, p, size);
return size;
}
static int
ltm_rsa_private_encrypt(int flen, const unsigned char* from,
unsigned char* to, RSA* rsa, int padding)
{
unsigned char *ptr, *ptr0 = NULL;
mp_err ret;
mp_int in, out, n, e;
mp_int bi, b;
size_t size;
int blinding = (rsa->flags & RSA_FLAG_NO_BLINDING) == 0;
int do_unblind = 0;
int where = 0;
if (padding != RSA_PKCS1_PADDING)
return -1;
FIRST(mp_init_multi(&e, &n, &in, &out, &b, &bi, NULL));
size = RSA_size(rsa);
if (size < RSA_PKCS1_PADDING_SIZE || size - RSA_PKCS1_PADDING_SIZE < flen)
return -2;
THEN_ALLOC((ptr0 = ptr = malloc(size)));
if (ret == MP_OKAY) {
*ptr++ = 0;
*ptr++ = 1;
memset(ptr, 0xff, size - flen - 3);
ptr += size - flen - 3;
*ptr++ = 0;
memcpy(ptr, from, flen);
ptr += flen;
assert((ptr - ptr0) == size);
}
THEN_MP(BN2mpz(&n, rsa->n));
THEN_MP(BN2mpz(&e, rsa->e));
THEN_IF_MP((mp_cmp_d(&e, 3) == MP_LT), MP_ERR);
THEN_MP(mp_from_ubin(&in, ptr0, size));
free(ptr0);
THEN_IF_MP((mp_isneg(&in) || mp_cmp(&in, &n) >= 0), MP_ERR);
if (blinding) {
THEN_MP(setup_blind(&n, &b, &bi));
THEN_MP(blind(&in, &b, &e, &n));
do_unblind = 1;
}
if (ret == MP_OKAY && rsa->p && rsa->q && rsa->dmp1 && rsa->dmq1 &&
rsa->iqmp) {
mp_int p, q, dmp1, dmq1, iqmp;
FIRST(mp_init_multi(&p, &q, &dmp1, &dmq1, &iqmp, NULL));
THEN_MP(BN2mpz(&p, rsa->p));
THEN_MP(BN2mpz(&q, rsa->q));
THEN_MP(BN2mpz(&dmp1, rsa->dmp1));
THEN_MP(BN2mpz(&dmq1, rsa->dmq1));
THEN_MP(BN2mpz(&iqmp, rsa->iqmp));
THEN_MP(ltm_rsa_private_calculate(&in, &p, &q, &dmp1, &dmq1, &iqmp,
&out));
mp_clear_multi(&p, &q, &dmp1, &dmq1, &iqmp, NULL);
if (ret != MP_OKAY) goto out;
} else if (ret == MP_OKAY) {
mp_int d;
THEN_MP(BN2mpz(&d, rsa->d));
THEN_MP(mp_exptmod(&in, &d, &n, &out));
mp_clear(&d);
if (ret != MP_OKAY) goto out;
}
if (do_unblind)
THEN_MP(unblind(&out, &bi, &n));
if (ret == MP_OKAY && size > 0) {
size_t ssize;
ssize = mp_ubin_size(&out);
assert(size >= ssize);
THEN_MP(mp_to_ubin(&out, to, SIZE_MAX, NULL));
size = ssize;
}
out:
mp_clear_multi(&e, &n, &in, &out, &b, &bi, NULL);
return ret == MP_OKAY ? size : -where;
}
static int
ltm_rsa_private_decrypt(int flen, const unsigned char* from,
unsigned char* to, RSA* rsa, int padding)
{
unsigned char *ptr;
size_t size;
mp_err ret;
mp_int in, out, n, e, b, bi;
int blinding = (rsa->flags & RSA_FLAG_NO_BLINDING) == 0;
int do_unblind = 0;
int where = 0;
if (padding != RSA_PKCS1_PADDING)
return -1;
size = RSA_size(rsa);
if (flen > size)
return -2;
FIRST(mp_init_multi(&in, &n, &e, &out, &b, &bi, NULL));
THEN_MP(BN2mpz(&n, rsa->n));
THEN_MP(BN2mpz(&e, rsa->e));
THEN_IF_MP((mp_cmp_d(&e, 3) == MP_LT), MP_ERR);
THEN_MP(mp_from_ubin(&in, rk_UNCONST(from), flen));
THEN_IF_MP((mp_isneg(&in) || mp_cmp(&in, &n) >= 0), MP_ERR);
if (blinding) {
THEN_MP(setup_blind(&n, &b, &bi));
THEN_MP(blind(&in, &b, &e, &n));
do_unblind = 1;
}
if (ret == MP_OKAY && rsa->p && rsa->q && rsa->dmp1 && rsa->dmq1 &&
rsa->iqmp) {
mp_int p, q, dmp1, dmq1, iqmp;
THEN_MP(mp_init_multi(&p, &q, &dmp1, &dmq1, &iqmp, NULL));
THEN_MP(BN2mpz(&p, rsa->p));
THEN_MP(BN2mpz(&q, rsa->q));
THEN_MP(BN2mpz(&dmp1, rsa->dmp1));
THEN_MP(BN2mpz(&dmq1, rsa->dmq1));
THEN_MP(BN2mpz(&iqmp, rsa->iqmp));
THEN_MP(ltm_rsa_private_calculate(&in, &p, &q, &dmp1, &dmq1, &iqmp, &out));
mp_clear_multi(&p, &q, &dmp1, &dmq1, &iqmp, NULL);
if (ret != MP_OKAY) goto out;
} else if (ret == MP_OKAY) {
mp_int d;
THEN_IF_MP((mp_isneg(&in) || mp_cmp(&in, &n) >= 0), MP_ERR);
THEN_MP(BN2mpz(&d, rsa->d));
THEN_MP(mp_exptmod(&in, &d, &n, &out));
mp_clear(&d);
if (ret != MP_OKAY) goto out;
}
if (do_unblind)
THEN_MP(unblind(&out, &bi, &n));
if (ret == MP_OKAY) {
size_t ssize;
ptr = to;
ssize = mp_ubin_size(&out);
assert(size >= ssize);
ret = mp_to_ubin(&out, ptr, SIZE_MAX, NULL);
if (ret != MP_OKAY) goto out;
size = ssize;
/* head zero was skipped by mp_int_to_unsigned */
if (*ptr != 2) {
where = __LINE__;
goto out;
}
size--; ptr++;
while (size && *ptr != 0) {
size--; ptr++;
}
if (size == 0) {
where = __LINE__;
goto out;
}
size--; ptr++;
memmove(to, ptr, size);
}
out:
mp_clear_multi(&e, &n, &in, &out, &b, &bi, NULL);
return (ret == MP_OKAY) ? size : -where;
}
static BIGNUM *
mpz2BN(mp_int *s)
{
size_t size;
BIGNUM *bn;
mp_err ret;
void *p;
size = mp_ubin_size(s);
if (size == 0)
return NULL;
p = malloc(size);
if (p == NULL)
return NULL;
ret = mp_to_ubin(s, p, SIZE_MAX, NULL);
if (ret == MP_OKAY)
bn = BN_bin2bn(p, size, NULL);
free(p);
return (ret == MP_OKAY) ? bn : NULL;
}
enum gen_pq_type { GEN_P, GEN_Q };
static int
gen_p(int bits, enum gen_pq_type pq_type, uint8_t nibble_pair, mp_int *p, mp_int *e, BN_GENCB *cb)
{
unsigned char *buf = NULL;
mp_bool res;
mp_err ret = MP_MEM;
mp_int t1, t2;
size_t len = (bits + 7) / 8;
int trials = mp_prime_rabin_miller_trials(bits);
int counter = 0;
int where HEIMDAL_UNUSED_ATTRIBUTE = 0;
FIRST(mp_init_multi(&t1, &t2, NULL));
if (ret == MP_OKAY && (buf = malloc(len))) do {
BN_GENCB_call(cb, 2, counter++);
/* random bytes */
ret = (RAND_bytes(buf, len) == 1) ? MP_OKAY : MP_ERR;
/* make it odd */
buf[len - 1] |= 1;
/* ensure the high nibble of the product is at least 128 */
if (pq_type == GEN_P)
buf[0] = (nibble_pair & 0xf0) | (buf[0] & 0x0f);
else
buf[0] = ((nibble_pair & 0x0f) << 4) | (buf[0] & 0x0f);
/* load number */
THEN_MP(mp_from_ubin(p, buf, len));
/* test primality; repeat if not */
THEN_MP(mp_prime_is_prime(p, trials, &res));
if (ret == MP_OKAY && res == MP_NO) continue;
/* check gcd(p - 1, e) == 1 */
THEN_MP(mp_sub_d(p, 1, &t1));
THEN_MP(mp_gcd(&t1, e, &t2));
} while (ret == MP_OKAY && mp_cmp_d(&t2, 1) != MP_EQ);
mp_clear_multi(&t1, &t2, NULL);
free(buf);
return ret;
}
static uint8_t pq_high_nibble_pairs[] = {
0x9f, 0xad, 0xae, 0xaf, 0xbc, 0xbd, 0xbe, 0xbf, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf9,
0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
static int
ltm_rsa_generate_key(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
{
mp_int el, p, q, n, d, dmp1, dmq1, iqmp, t1, t2, t3;
mp_err ret;
uint8_t high_nibbles = 0;
int bitsp;
int where = 0;
if (bits < 789)
return -1;
bitsp = (bits + 1) / 2;
FIRST(mp_init_multi(&el, &p, &q, &n, &d,
&dmp1, &dmq1, &iqmp,
&t1, &t2, &t3, NULL));
THEN_MP(BN2mpz(&el, e));
/*
* randomly pick a pair of high nibbles for p and q to ensure the product's
* high nibble is at least 128
*/
if (ret == MP_OKAY)
ret = (RAND_bytes(&high_nibbles, 1) == 1) ? MP_OKAY : MP_ERR;
high_nibbles %= sizeof(pq_high_nibble_pairs);
high_nibbles = pq_high_nibble_pairs[high_nibbles];
/* generate p and q so that p != q and bits(pq) ~ bits */
THEN_MP(gen_p(bitsp, GEN_P, high_nibbles, &p, &el, cb));
BN_GENCB_call(cb, 3, 0);
THEN_MP(gen_p(bitsp, GEN_Q, high_nibbles, &q, &el, cb));
/* make p > q */
if (mp_cmp(&p, &q) < 0) {
mp_int c;
c = p;
p = q;
q = c;
}
BN_GENCB_call(cb, 3, 1);
/* calculate n, n = p * q */
THEN_MP(mp_mul(&p, &q, &n));
/* calculate d, d = 1/e mod (p - 1)(q - 1) */
THEN_MP(mp_sub_d(&p, 1, &t1));
THEN_MP(mp_sub_d(&q, 1, &t2));
THEN_MP(mp_mul(&t1, &t2, &t3));
THEN_MP(mp_invmod(&el, &t3, &d));
/* calculate dmp1 dmp1 = d mod (p-1) */
THEN_MP(mp_mod(&d, &t1, &dmp1));
/* calculate dmq1 dmq1 = d mod (q-1) */
THEN_MP(mp_mod(&d, &t2, &dmq1));
/* calculate iqmp iqmp = 1/q mod p */
THEN_MP(mp_invmod(&q, &p, &iqmp));
/* fill in RSA key */
if (ret == MP_OKAY) {
rsa->e = mpz2BN(&el);
rsa->p = mpz2BN(&p);
rsa->q = mpz2BN(&q);
rsa->n = mpz2BN(&n);
rsa->d = mpz2BN(&d);
rsa->dmp1 = mpz2BN(&dmp1);
rsa->dmq1 = mpz2BN(&dmq1);
rsa->iqmp = mpz2BN(&iqmp);
}
mp_clear_multi(&el, &p, &q, &n, &d,
&dmp1, &dmq1, &iqmp,
&t1, &t2, &t3, NULL);
return (ret == MP_OKAY) ? 1 : -where;
}
static int
ltm_rsa_init(RSA *rsa)
{
return 1;
}
static int
ltm_rsa_finish(RSA *rsa)
{
return 1;
}
const RSA_METHOD hc_rsa_ltm_method = {
"hcrypto ltm RSA",
ltm_rsa_public_encrypt,
ltm_rsa_public_decrypt,
ltm_rsa_private_encrypt,
ltm_rsa_private_decrypt,
NULL,
NULL,
ltm_rsa_init,
ltm_rsa_finish,
0,
NULL,
NULL,
NULL,
ltm_rsa_generate_key
};
const RSA_METHOD *
RSA_ltm_method(void)
{
return &hc_rsa_ltm_method;
}
|