660b443c |
1 | # ---?--- |
2 | # |
a1a90aaf |
3 | # $Id$ |
660b443c |
4 | # |
5 | # Interface to crypto algorithms |
6 | # |
7 | # (c) 2001 Straylight/Edgeware |
8 | # |
9 | |
10 | #----- Licensing notice ----------------------------------------------------- |
11 | # |
12 | # This file is part of the Perl interface to Catacomb. |
13 | # |
14 | # Catacomb/Perl is free software; you can redistribute it and/or modify |
15 | # it under the terms of the GNU General Public License as published by |
16 | # the Free Software Foundation; either version 2 of the License, or |
17 | # (at your option) any later version. |
18 | # |
19 | # Catacomb/Perl is distributed in the hope that it will be useful, |
20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | # GNU General Public License for more details. |
23 | # |
24 | # You should have received a copy of the GNU General Public License |
25 | # along with Catacomb/Perl; if not, write to the Free Software Foundation, |
26 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
27 | |
660b443c |
28 | MODULE = Catacomb PACKAGE = Catacomb::CipherClass |
29 | |
30 | PROTOTYPES: DISABLE |
31 | |
32 | gccipher * |
33 | find(me, name) |
34 | SV *me |
35 | char *name |
660b443c |
36 | CODE: |
a1a90aaf |
37 | RETVAL = (gccipher *)gcipher_byname(name); |
660b443c |
38 | OUTPUT: |
39 | RETVAL |
40 | |
41 | SV * |
42 | list(me) |
43 | SV *me |
44 | PREINIT: |
a1a90aaf |
45 | const gccipher *const *cc; |
660b443c |
46 | SV *sv; |
47 | PPCODE: |
a1a90aaf |
48 | for (cc = gciphertab; *cc; cc++) |
49 | XPUSHs(RET((gccipher *)*cc, "Catacomb::CipherClass")); |
660b443c |
50 | |
51 | keysize * |
52 | keysz(cc) |
53 | gccipher *cc |
54 | CODE: |
55 | RETVAL = cc->keysz; |
56 | OUTPUT: |
57 | RETVAL |
58 | |
59 | char * |
60 | name(cc) |
61 | gccipher *cc |
62 | CODE: |
63 | RETVAL = (char *)cc->name; |
64 | OUTPUT: |
65 | RETVAL |
66 | |
67 | size_t |
68 | blksz(cc) |
69 | gccipher *cc |
70 | CODE: |
71 | RETVAL = cc->blksz; |
72 | OUTPUT: |
73 | RETVAL |
74 | |
75 | gcipher * |
76 | init(cc, k) |
77 | gccipher *cc |
78 | SV *k |
79 | PREINIT: |
80 | STRLEN len; |
81 | char *p; |
82 | CODE: |
83 | p = SvPV(k, len); |
84 | if (keysz(len, cc->keysz) != len) { |
85 | croak("bad key size %lu for cipher `%s'", |
86 | (unsigned long)len, cc->name); |
87 | } |
88 | RETVAL = cc->init(p, len); |
89 | OUTPUT: |
90 | RETVAL |
91 | |
92 | MODULE = Catacomb PACKAGE = Catacomb::Cipher |
93 | |
94 | SV * |
95 | DESTROY(c) |
96 | gcipher *c |
97 | CODE: |
98 | c->ops->destroy(c); |
99 | XSRETURN_UNDEF; |
100 | |
101 | SV * |
102 | encrypt(c, plain) |
103 | gcipher *c |
104 | SV *plain |
105 | PREINIT: |
106 | STRLEN len; |
107 | char *p; |
108 | CODE: |
109 | p = SvPV(plain, len); |
110 | RETVAL = NEWSV(0, len ? len : 1); |
111 | c->ops->encrypt(c, p, SvPVX(RETVAL), len); |
112 | SvCUR_set(RETVAL, len); |
113 | SvPOK_on(RETVAL); |
114 | OUTPUT: |
115 | RETVAL |
116 | |
117 | SV * |
118 | decrypt(c, cipher) |
119 | gcipher *c |
120 | SV *cipher |
121 | PREINIT: |
122 | STRLEN len; |
123 | char *p; |
124 | CODE: |
125 | p = SvPV(cipher, len); |
126 | RETVAL = NEWSV(0, len ? len : 1); |
127 | c->ops->decrypt(c, p, SvPVX(RETVAL), len); |
128 | SvCUR_set(RETVAL, len); |
129 | SvPOK_on(RETVAL); |
130 | OUTPUT: |
131 | RETVAL |
132 | |
133 | SV * |
134 | setiv(c, iv) |
135 | gcipher *c |
136 | SV *iv |
137 | PREINIT: |
138 | STRLEN len; |
139 | char *p; |
140 | CODE: |
141 | p = SvPV(iv, len); |
142 | if (c->ops->c->blksz && len != c->ops->c->blksz) { |
143 | croak("IV for block cipher `%s' must be %lu", |
144 | c->ops->c->name, (unsigned long)c->ops->c->blksz); |
145 | } |
146 | c->ops->setiv(c, p); |
147 | XSRETURN_UNDEF; |
148 | |
149 | SV * |
150 | bdry(c) |
151 | gcipher *c |
152 | CODE: |
153 | c->ops->bdry(c); |
154 | XSRETURN_UNDEF; |
155 | |
156 | gccipher * |
157 | class(c) |
158 | gcipher *c |
159 | CODE: |
160 | RETVAL = (gccipher *)c->ops->c; |
161 | OUTPUT: |
162 | RETVAL |
163 | |
164 | MODULE = Catacomb PACKAGE = Catacomb::HashClass |
165 | |
166 | gchash * |
167 | find(me, name) |
168 | SV *me |
169 | char *name |
660b443c |
170 | CODE: |
a1a90aaf |
171 | RETVAL = (gchash *)ghash_byname(name); |
660b443c |
172 | OUTPUT: |
173 | RETVAL |
174 | |
175 | SV * |
176 | list(me) |
177 | SV *me |
178 | PREINIT: |
a1a90aaf |
179 | const gchash *const *hc; |
660b443c |
180 | SV *sv; |
181 | PPCODE: |
a1a90aaf |
182 | for (hc = ghashtab; *hc; hc++) |
183 | XPUSHs(RET((gchash *)*hc, "Catacomb::HashClass")); |
660b443c |
184 | |
185 | size_t |
186 | hashsz(hc) |
187 | gchash *hc |
188 | CODE: |
189 | RETVAL = hc->hashsz; |
190 | OUTPUT: |
191 | RETVAL |
192 | |
193 | char * |
194 | name(hc) |
195 | gchash *hc |
196 | CODE: |
197 | RETVAL = (char *)hc->name; |
198 | OUTPUT: |
199 | RETVAL |
200 | |
201 | ghash * |
202 | init(hc) |
203 | gchash *hc |
204 | CODE: |
205 | RETVAL = hc->init(); |
206 | OUTPUT: |
207 | RETVAL |
208 | |
209 | MODULE = Catacomb PACKAGE = Catacomb::Hash |
210 | |
211 | SV * |
212 | DESTROY(h) |
213 | ghash *h |
214 | CODE: |
215 | h->ops->destroy(h); |
216 | XSRETURN_UNDEF; |
217 | |
218 | SV * |
219 | hash(h, sv) |
220 | ghash *h |
221 | SV *sv |
222 | PREINIT: |
223 | STRLEN len; |
224 | char *p; |
225 | CODE: |
226 | p = SvPV(sv, len); |
227 | h->ops->hash(h, p, len); |
228 | XSRETURN_UNDEF; |
229 | |
230 | SV * |
231 | done(h) |
232 | ghash *h |
233 | CODE: |
234 | RETVAL = NEWSV(0, h->ops->c->hashsz); |
235 | h->ops->done(h, SvPVX(RETVAL)); |
236 | SvCUR_set(RETVAL, h->ops->c->hashsz); |
237 | SvPOK_on(RETVAL); |
238 | OUTPUT: |
239 | RETVAL |
240 | |
241 | ghash * |
242 | copy(h) |
243 | ghash *h |
244 | CODE: |
245 | RETVAL = h->ops->copy(h); |
246 | OUTPUT: |
247 | RETVAL |
248 | |
249 | gchash * |
250 | class(h) |
251 | ghash *h |
252 | CODE: |
253 | RETVAL = (gchash *)h->ops->c; |
254 | OUTPUT: |
255 | RETVAL |
256 | |
257 | MODULE = Catacomb PACKAGE = Catacomb::MACClass |
258 | |
259 | gcMAC * |
260 | find(me, name) |
261 | SV *me |
262 | char *name |
660b443c |
263 | CODE: |
a1a90aaf |
264 | RETVAL = (gcMAC *)gmac_byname(name); |
660b443c |
265 | OUTPUT: |
266 | RETVAL |
267 | |
268 | SV * |
269 | list(me) |
270 | SV *me |
271 | PREINIT: |
a1a90aaf |
272 | const gcMAC *const *mc; |
660b443c |
273 | SV *sv; |
274 | PPCODE: |
a1a90aaf |
275 | for (mc = gmactab; *mc; mc++) |
276 | XPUSHs(RET((gcMAC *)*mc, "Catacomb::MACClass")); |
660b443c |
277 | |
278 | size_t |
279 | hashsz(mc) |
280 | gcMAC *mc |
281 | CODE: |
282 | RETVAL = mc->hashsz; |
283 | OUTPUT: |
284 | RETVAL |
285 | |
286 | keysize * |
287 | keysz(mc) |
288 | gcMAC *mc |
289 | CODE: |
290 | RETVAL = mc->keysz; |
291 | OUTPUT: |
292 | RETVAL |
293 | |
294 | char * |
295 | name(mc) |
296 | gcMAC *mc |
297 | CODE: |
298 | RETVAL = (char *)mc->name; |
299 | OUTPUT: |
300 | RETVAL |
301 | |
302 | gMAC * |
303 | key(mc, k) |
304 | gcMAC *mc |
305 | SV *k |
306 | PREINIT: |
307 | STRLEN len; |
308 | char *p; |
309 | CODE: |
310 | p = SvPV(k, len); |
311 | if (keysz(len, mc->keysz) != len) { |
312 | croak("bad key size %lu for mac `%s'", |
313 | (unsigned long)len, mc->name); |
314 | } |
315 | RETVAL = mc->key(p, len); |
316 | OUTPUT: |
317 | RETVAL |
318 | |
319 | MODULE = Catacomb PACKAGE = Catacomb::MAC |
320 | |
321 | SV * |
322 | DESTROY(m) |
323 | gMAC *m |
324 | CODE: |
325 | m->ops->destroy(m); |
326 | XSRETURN_UNDEF; |
327 | |
328 | ghash * |
329 | init(m) |
330 | gMAC *m |
331 | CODE: |
332 | RETVAL = m->ops->init(m); |
333 | OUTPUT: |
334 | RETVAL |
335 | |
336 | gcMAC * |
337 | class(m) |
338 | gMAC *m |
339 | CODE: |
340 | RETVAL = (gcMAC *)m->ops->c; |
341 | OUTPUT: |
342 | RETVAL |
343 | |
344 | MODULE = Catacomb PACKAGE = Catacomb::Rand |
345 | |
346 | SV * |
347 | seedint(r, seed) |
348 | grand *r |
349 | U32 seed |
350 | CODE: |
351 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDUINT32)) |
352 | croak("rng `%s' doesn't support `seedint'", r->ops->name); |
353 | r->ops->misc(r, GRAND_SEEDUINT32, seed); |
354 | XSRETURN_UNDEF; |
355 | |
356 | SV * |
357 | seedblock(r, seed) |
358 | grand *r |
359 | SV *seed |
360 | PREINIT: |
361 | STRLEN len; |
362 | char *p; |
363 | CODE: |
364 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDBLOCK)) |
365 | croak("rng `%s' doesn't support `seedblock'", r->ops->name); |
366 | p = SvPV(seed, len); |
367 | r->ops->misc(r, GRAND_SEEDBLOCK, p, len); |
368 | XSRETURN_UNDEF; |
369 | |
370 | SV * |
371 | seedmp(r, seed) |
372 | grand *r |
373 | mp *seed |
374 | CODE: |
375 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDMP)) |
376 | croak("rng `%s' doesn't support `seedmp'", r->ops->name); |
377 | r->ops->misc(r, GRAND_SEEDMP, seed); |
378 | XSRETURN_UNDEF; |
379 | |
380 | SV * |
381 | seedrand(r, seed) |
382 | grand *r |
383 | grand *seed |
384 | CODE: |
385 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDRAND)) |
386 | croak("rng `%s' doesn't support `seedrand'", r->ops->name); |
387 | r->ops->misc(r, GRAND_SEEDRAND, seed); |
388 | XSRETURN_UNDEF; |
389 | |
390 | U32 |
391 | raw(r) |
392 | grand *r |
393 | CODE: |
394 | RETVAL = r->ops->raw(r); |
395 | OUTPUT: |
396 | RETVAL |
397 | |
398 | U32 |
399 | word(r) |
400 | grand *r |
401 | CODE: |
402 | RETVAL = r->ops->word(r); |
403 | OUTPUT: |
404 | RETVAL |
405 | |
406 | U8 |
407 | byte(r) |
408 | grand *r |
409 | CODE: |
410 | RETVAL = r->ops->byte(r); |
411 | OUTPUT: |
412 | RETVAL |
413 | |
414 | char |
415 | char(r) |
416 | grand *r |
417 | CODE: |
418 | RETVAL = r->ops->byte(r); |
419 | OUTPUT: |
420 | RETVAL |
421 | |
422 | U32 |
423 | range(r, limit) |
424 | grand *r |
425 | U32 limit |
426 | CODE: |
427 | RETVAL = r->ops->range(r, limit); |
428 | OUTPUT: |
429 | RETVAL |
430 | |
431 | mp * |
432 | mp(r, bits, or = 0) |
433 | grand *r |
434 | unsigned or |
435 | unsigned bits |
436 | CODE: |
437 | RETVAL = mprand(MP_NEW, bits, r, or); |
438 | OUTPUT: |
439 | RETVAL |
440 | |
441 | mp * |
442 | mprange(r, limit) |
443 | grand *r |
444 | mp *limit |
445 | CODE: |
446 | RETVAL = mprand_range(MP_NEW, limit, r, 0); |
447 | OUTPUT: |
448 | RETVAL |
449 | |
450 | SV * |
451 | fill(r, n) |
452 | grand *r |
453 | size_t n |
454 | CODE: |
455 | RETVAL = NEWSV(0, n ? n : 1); |
456 | r->ops->fill(r, SvPVX(RETVAL), n); |
457 | SvCUR_set(RETVAL, n); |
458 | SvPOK_on(RETVAL); |
459 | OUTPUT: |
460 | RETVAL |
461 | |
462 | char * |
463 | name(r) |
464 | grand *r |
465 | CODE: |
466 | RETVAL = (char *)r->ops->name; |
467 | OUTPUT: |
468 | RETVAL |
469 | |
470 | U32 |
471 | flags(r) |
472 | grand *r |
473 | CODE: |
474 | RETVAL = r->ops->f; |
475 | OUTPUT: |
476 | RETVAL |
477 | |
478 | U32 |
479 | max(r) |
480 | grand *r |
481 | CODE: |
482 | RETVAL = r->ops->max; |
483 | OUTPUT: |
484 | RETVAL |
485 | |
486 | MODULE = Catacomb PACKAGE = Catacomb::Rand::True |
487 | |
488 | Rand_True * |
489 | _global(me) |
490 | SV *me |
491 | CODE: |
492 | RETVAL = &rand_global; |
493 | OUTPUT: |
494 | RETVAL |
495 | |
496 | Rand_True * |
497 | rand(me) |
498 | SV *me |
499 | CODE: |
500 | RETVAL = rand_create(); |
501 | OUTPUT: |
502 | RETVAL |
503 | |
504 | SV * |
505 | gate(r) |
506 | Rand_True *r |
507 | CODE: |
508 | r->ops->misc(r, RAND_GATE); |
509 | XSRETURN_UNDEF; |
510 | |
511 | SV * |
512 | stretch(r) |
513 | Rand_True *r |
514 | CODE: |
515 | r->ops->misc(r, RAND_STRETCH); |
516 | XSRETURN_UNDEF; |
517 | |
518 | SV * |
519 | key(r, k) |
520 | Rand_True *r |
521 | SV *k |
522 | PREINIT: |
523 | STRLEN len; |
524 | char *p; |
525 | CODE: |
526 | p = SvPV(k, len); |
527 | r->ops->misc(r, RAND_KEY, p, len); |
528 | XSRETURN_UNDEF; |
529 | |
530 | SV * |
531 | noisesrc(r) |
532 | Rand_True *r |
533 | CODE: |
534 | r->ops->misc(r, RAND_NOISESRC, &noise_source); |
535 | XSRETURN_UNDEF; |
536 | |
537 | SV * |
538 | seed(r, bits = 160) |
539 | Rand_True *r |
540 | int bits |
541 | CODE: |
542 | r->ops->misc(r, RAND_SEED, bits); |
543 | XSRETURN_UNDEF; |
544 | |
545 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Fib |
546 | |
547 | SV * |
548 | new(me, seed) |
549 | SV *me |
550 | U32 seed |
551 | CODE: |
552 | RETVAL = MAKE(fibrand_create(seed), "Catacomb::Rand::Fib"); |
553 | OUTPUT: |
554 | RETVAL |
555 | |
556 | MODULE = Catacomb PACKAGE = Catacomb::Rand::LC |
557 | |
558 | SV * |
559 | new(me, seed) |
560 | SV *me |
561 | U32 seed |
562 | CODE: |
563 | RETVAL = MAKE(lcrand_create(seed), "Catacomb::Rand::LC"); |
564 | OUTPUT: |
565 | RETVAL |
566 | |
567 | MODULE = Catacomb PACKAGE = Catacomb::Rand::DSA |
568 | |
569 | Rand_DSA * |
570 | new(me, k) |
571 | SV *me |
572 | SV *k |
573 | PREINIT: |
574 | STRLEN len; |
575 | char *p; |
576 | CODE: |
577 | p = SvPV(k, len); |
578 | RETVAL = dsarand_create(p, len); |
579 | OUTPUT: |
580 | RETVAL |
581 | |
582 | SV * |
583 | passes(r, n) |
584 | Rand_DSA *r |
585 | unsigned n |
586 | CODE: |
587 | r->ops->misc(r, DSARAND_PASSES, n); |
588 | XSRETURN_UNDEF; |
589 | |
590 | SV * |
591 | seed(r) |
592 | Rand_DSA *r |
593 | PREINIT: |
594 | size_t sz; |
595 | CODE: |
596 | sz = r->ops->misc(r, DSARAND_SEEDSZ); |
597 | RETVAL = NEWSV(0, sz ? sz : 1); |
598 | r->ops->misc(r, DSARAND_GETSEED, SvPVX(RETVAL)); |
599 | SvCUR_set(RETVAL, sz); |
600 | SvPOK_on(RETVAL); |
601 | OUTPUT: |
602 | RETVAL |
603 | |
604 | MODULE = Catacomb PACKAGE = Catacomb::Rand::RC4 |
605 | |
606 | SV * |
607 | new(me, k) |
608 | SV *me |
609 | SV *k |
610 | PREINIT: |
611 | STRLEN len; |
612 | char *p; |
613 | CODE: |
614 | p = SvPV(k, len); |
615 | RETVAL = MAKE(rc4_rand(p, len), "Catacomb::Rand::RC4"); |
616 | OUTPUT: |
617 | RETVAL |
618 | |
619 | MODULE = Catacomb PACKAGE = Catacomb::Rand::SEAL |
620 | |
621 | SV * |
622 | new(me, k, n = 0) |
623 | SV *me |
624 | SV *k |
625 | U32 n |
626 | PREINIT: |
627 | STRLEN len; |
628 | char *p; |
629 | CODE: |
630 | p = SvPV(k, len); |
631 | RETVAL = MAKE(seal_rand(p, len, n), "Catacomb::Rand::SEAL"); |
632 | OUTPUT: |
633 | RETVAL |
634 | |
635 | MODULE = Catacomb PACKAGE = Catacomb::Rand::MGF |
636 | |
637 | SV * |
638 | new(name, k) |
639 | char *name |
640 | SV *k |
641 | CODE: |
642 | RETVAL = findrand(mgftab, "Catacomb::Rand::MGF", name, k); |
643 | OUTPUT: |
644 | RETVAL |
645 | |
646 | void |
647 | list(me) |
648 | SV *me |
649 | PPCODE: |
650 | listrand(mgftab); |
651 | |
652 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Counter |
653 | |
654 | SV * |
655 | new(name, k) |
656 | char *name |
657 | SV *k |
658 | CODE: |
659 | RETVAL = findrand(ctrtab, "Catacomb::Rand::Counter", name, k); |
660 | OUTPUT: |
661 | RETVAL |
662 | |
663 | void |
664 | list(me) |
665 | SV *me |
666 | PPCODE: |
667 | listrand(ctrtab); |
668 | |
669 | MODULE = Catacomb PACKAGE = Catacomb::Rand::OFB |
670 | |
671 | SV * |
672 | new(name, k) |
673 | char *name |
674 | SV *k |
675 | CODE: |
676 | RETVAL = findrand(ofbtab, "Catacomb::Rand::OFB", name, k); |
677 | OUTPUT: |
678 | RETVAL |
679 | |
680 | void |
681 | list(me) |
682 | SV *me |
683 | PPCODE: |
684 | listrand(ofbtab); |
685 | |
686 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Magic |
687 | |
688 | SV * |
689 | DESTROY(r) |
690 | grand *r |
691 | CODE: |
692 | XSRETURN_UNDEF; |
693 | |
694 | #----- That's all, folks ---------------------------------------------------- |