| 1 | # ---?--- |
| 2 | # |
| 3 | # $Id$ |
| 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 | |
| 28 | MODULE = Catacomb PACKAGE = Catacomb::PRPClass |
| 29 | |
| 30 | PRPClass * |
| 31 | find(me, name) |
| 32 | SV *me |
| 33 | char *name |
| 34 | PREINIT: |
| 35 | int i; |
| 36 | CODE: |
| 37 | RETVAL = 0; |
| 38 | for (i = 0; prptab[i]; i++) { |
| 39 | if (strcmp(name, prptab[i]->name) == 0) { |
| 40 | RETVAL = prptab[i]; |
| 41 | break; |
| 42 | } |
| 43 | } |
| 44 | OUTPUT: |
| 45 | RETVAL |
| 46 | |
| 47 | SV * |
| 48 | list(me) |
| 49 | SV *me |
| 50 | PREINIT: |
| 51 | int i; |
| 52 | PPCODE: |
| 53 | for (i = 0; prptab[i]; i++) |
| 54 | XPUSHs(RET(prptab[i], "Catacomb::PRPClass")); |
| 55 | |
| 56 | keysize * |
| 57 | keysz(p) |
| 58 | PRPClass *p |
| 59 | CODE: |
| 60 | RETVAL = p->ksz; |
| 61 | OUTPUT: |
| 62 | RETVAL |
| 63 | |
| 64 | char * |
| 65 | name(p) |
| 66 | PRPClass *p |
| 67 | CODE: |
| 68 | RETVAL = p->name; |
| 69 | OUTPUT: |
| 70 | RETVAL |
| 71 | |
| 72 | UV |
| 73 | blksz(p) |
| 74 | PRPClass *p |
| 75 | CODE: |
| 76 | RETVAL = p->blksz; |
| 77 | OUTPUT: |
| 78 | RETVAL |
| 79 | |
| 80 | PRP * |
| 81 | init(p, k) |
| 82 | PRPClass *p |
| 83 | SV *k |
| 84 | PREINIT: |
| 85 | char *pp; |
| 86 | STRLEN len; |
| 87 | CODE: |
| 88 | pp = SvPV(k, len); |
| 89 | if (keysz(len, p->ksz) != len) |
| 90 | croak("key size mismatch"); |
| 91 | RETVAL = sub_alloc(sizeof(PRP) + p->ctxsz); |
| 92 | RETVAL->c = p; |
| 93 | p->init(RETVAL + 1, pp, len); |
| 94 | OUTPUT: |
| 95 | RETVAL |
| 96 | |
| 97 | MODULE = Catacomb PACKAGE = Catacomb::PRP |
| 98 | |
| 99 | SV * |
| 100 | DESTROY(p) |
| 101 | PRP *p |
| 102 | CODE: |
| 103 | sub_free(p, sizeof(PRP) + p->c->ctxsz); |
| 104 | XSRETURN_YES; |
| 105 | |
| 106 | SV * |
| 107 | eblk(p, x) |
| 108 | PRP *p |
| 109 | SV *x |
| 110 | PREINIT: |
| 111 | char *pp; |
| 112 | STRLEN len; |
| 113 | CODE: |
| 114 | pp = SvPV(x, len); |
| 115 | if (len != p->c->blksz) |
| 116 | croak("block size mismatch"); |
| 117 | RETVAL = NEWSV(0, p->c->blksz); |
| 118 | p->c->eblk(p + 1, pp, SvPVX(RETVAL)); |
| 119 | SvPOK_on(RETVAL); |
| 120 | SvCUR_set(RETVAL, p->c->blksz); |
| 121 | OUTPUT: |
| 122 | RETVAL |
| 123 | |
| 124 | SV * |
| 125 | dblk(p, x) |
| 126 | PRP *p |
| 127 | SV *x |
| 128 | PREINIT: |
| 129 | char *pp; |
| 130 | STRLEN len; |
| 131 | CODE: |
| 132 | pp = SvPV(x, len); |
| 133 | if (len != p->c->blksz) |
| 134 | croak("block size mismatch"); |
| 135 | RETVAL = NEWSV(0, p->c->blksz); |
| 136 | p->c->dblk(p + 1, pp, SvPVX(RETVAL)); |
| 137 | SvPOK_on(RETVAL); |
| 138 | SvCUR_set(RETVAL, p->c->blksz); |
| 139 | OUTPUT: |
| 140 | RETVAL |
| 141 | |
| 142 | PRPClass * |
| 143 | class(p) |
| 144 | PRP *p |
| 145 | CODE: |
| 146 | RETVAL = p->c; |
| 147 | OUTPUT: |
| 148 | RETVAL |
| 149 | |
| 150 | MODULE = Catacomb PACKAGE = Catacomb::CipherClass |
| 151 | |
| 152 | PROTOTYPES: DISABLE |
| 153 | |
| 154 | gccipher * |
| 155 | find(me, name) |
| 156 | SV *me |
| 157 | char *name |
| 158 | CODE: |
| 159 | RETVAL = (gccipher *)gcipher_byname(name); |
| 160 | OUTPUT: |
| 161 | RETVAL |
| 162 | |
| 163 | keysize * |
| 164 | keysz(cc) |
| 165 | gccipher *cc |
| 166 | CODE: |
| 167 | RETVAL = cc->keysz; |
| 168 | OUTPUT: |
| 169 | RETVAL |
| 170 | |
| 171 | char * |
| 172 | name(cc) |
| 173 | gccipher *cc |
| 174 | CODE: |
| 175 | RETVAL = (char *)cc->name; |
| 176 | OUTPUT: |
| 177 | RETVAL |
| 178 | |
| 179 | size_t |
| 180 | blksz(cc) |
| 181 | gccipher *cc |
| 182 | CODE: |
| 183 | RETVAL = cc->blksz; |
| 184 | OUTPUT: |
| 185 | RETVAL |
| 186 | |
| 187 | gcipher * |
| 188 | init(cc, k) |
| 189 | gccipher *cc |
| 190 | SV *k |
| 191 | PREINIT: |
| 192 | STRLEN len; |
| 193 | char *p; |
| 194 | CODE: |
| 195 | p = SvPV(k, len); |
| 196 | if (keysz(len, cc->keysz) != len) { |
| 197 | croak("bad key size %lu for cipher `%s'", |
| 198 | (unsigned long)len, cc->name); |
| 199 | } |
| 200 | RETVAL = cc->init(p, len); |
| 201 | OUTPUT: |
| 202 | RETVAL |
| 203 | |
| 204 | MODULE = Catacomb PACKAGE = Catacomb::Cipher |
| 205 | |
| 206 | SV * |
| 207 | DESTROY(c) |
| 208 | gcipher *c |
| 209 | CODE: |
| 210 | c->ops->destroy(c); |
| 211 | XSRETURN_YES; |
| 212 | |
| 213 | SV * |
| 214 | encrypt(c, plain) |
| 215 | gcipher *c |
| 216 | SV *plain |
| 217 | PREINIT: |
| 218 | STRLEN len; |
| 219 | char *p; |
| 220 | CODE: |
| 221 | p = SvPV(plain, len); |
| 222 | RETVAL = NEWSV(0, len ? len : 1); |
| 223 | c->ops->encrypt(c, p, SvPVX(RETVAL), len); |
| 224 | SvCUR_set(RETVAL, len); |
| 225 | SvPOK_on(RETVAL); |
| 226 | OUTPUT: |
| 227 | RETVAL |
| 228 | |
| 229 | SV * |
| 230 | decrypt(c, cipher) |
| 231 | gcipher *c |
| 232 | SV *cipher |
| 233 | PREINIT: |
| 234 | STRLEN len; |
| 235 | char *p; |
| 236 | CODE: |
| 237 | p = SvPV(cipher, len); |
| 238 | RETVAL = NEWSV(0, len ? len : 1); |
| 239 | c->ops->decrypt(c, p, SvPVX(RETVAL), len); |
| 240 | SvCUR_set(RETVAL, len); |
| 241 | SvPOK_on(RETVAL); |
| 242 | OUTPUT: |
| 243 | RETVAL |
| 244 | |
| 245 | SV * |
| 246 | setiv(c, iv) |
| 247 | gcipher *c |
| 248 | SV *iv |
| 249 | PREINIT: |
| 250 | STRLEN len; |
| 251 | char *p; |
| 252 | CODE: |
| 253 | p = SvPV(iv, len); |
| 254 | if (c->ops->c->blksz && len != c->ops->c->blksz) { |
| 255 | croak("IV for block cipher `%s' must be %lu", |
| 256 | c->ops->c->name, (unsigned long)c->ops->c->blksz); |
| 257 | } |
| 258 | c->ops->setiv(c, p); |
| 259 | XSRETURN_YES; |
| 260 | |
| 261 | SV * |
| 262 | bdry(c) |
| 263 | gcipher *c |
| 264 | CODE: |
| 265 | c->ops->bdry(c); |
| 266 | XSRETURN_YES; |
| 267 | |
| 268 | gccipher * |
| 269 | class(c) |
| 270 | gcipher *c |
| 271 | CODE: |
| 272 | RETVAL = (gccipher *)c->ops->c; |
| 273 | OUTPUT: |
| 274 | RETVAL |
| 275 | |
| 276 | MODULE = Catacomb PACKAGE = Catacomb::HashClass |
| 277 | |
| 278 | gchash * |
| 279 | find(me, name) |
| 280 | SV *me |
| 281 | char *name |
| 282 | CODE: |
| 283 | RETVAL = (gchash *)ghash_byname(name); |
| 284 | OUTPUT: |
| 285 | RETVAL |
| 286 | |
| 287 | size_t |
| 288 | hashsz(hc) |
| 289 | gchash *hc |
| 290 | CODE: |
| 291 | RETVAL = hc->hashsz; |
| 292 | OUTPUT: |
| 293 | RETVAL |
| 294 | |
| 295 | char * |
| 296 | name(hc) |
| 297 | gchash *hc |
| 298 | CODE: |
| 299 | RETVAL = (char *)hc->name; |
| 300 | OUTPUT: |
| 301 | RETVAL |
| 302 | |
| 303 | ghash * |
| 304 | init(hc) |
| 305 | gchash *hc |
| 306 | CODE: |
| 307 | RETVAL = hc->init(); |
| 308 | OUTPUT: |
| 309 | RETVAL |
| 310 | |
| 311 | MODULE = Catacomb PACKAGE = Catacomb::Hash |
| 312 | |
| 313 | SV * |
| 314 | DESTROY(h) |
| 315 | ghash *h |
| 316 | CODE: |
| 317 | h->ops->destroy(h); |
| 318 | XSRETURN_YES; |
| 319 | |
| 320 | SV * |
| 321 | hash(h, sv) |
| 322 | ghash *h |
| 323 | SV *sv |
| 324 | PREINIT: |
| 325 | STRLEN len; |
| 326 | char *p; |
| 327 | CODE: |
| 328 | p = SvPV(sv, len); |
| 329 | h->ops->hash(h, p, len); |
| 330 | XSRETURN_YES; |
| 331 | |
| 332 | SV * |
| 333 | done(h) |
| 334 | ghash *h |
| 335 | CODE: |
| 336 | RETVAL = NEWSV(0, h->ops->c->hashsz); |
| 337 | h->ops->done(h, SvPVX(RETVAL)); |
| 338 | SvCUR_set(RETVAL, h->ops->c->hashsz); |
| 339 | SvPOK_on(RETVAL); |
| 340 | OUTPUT: |
| 341 | RETVAL |
| 342 | |
| 343 | ghash * |
| 344 | copy(h) |
| 345 | ghash *h |
| 346 | CODE: |
| 347 | RETVAL = h->ops->copy(h); |
| 348 | OUTPUT: |
| 349 | RETVAL |
| 350 | |
| 351 | gchash * |
| 352 | class(h) |
| 353 | ghash *h |
| 354 | CODE: |
| 355 | RETVAL = (gchash *)h->ops->c; |
| 356 | OUTPUT: |
| 357 | RETVAL |
| 358 | |
| 359 | MODULE = Catacomb PACKAGE = Catacomb::MACClass |
| 360 | |
| 361 | gcMAC * |
| 362 | find(me, name) |
| 363 | SV *me |
| 364 | char *name |
| 365 | CODE: |
| 366 | RETVAL = (gcMAC *)gmac_byname(name); |
| 367 | OUTPUT: |
| 368 | RETVAL |
| 369 | |
| 370 | SV * |
| 371 | list(me) |
| 372 | SV *me |
| 373 | PREINIT: |
| 374 | const gcMAC *const *mc; |
| 375 | PPCODE: |
| 376 | for (mc = gmactab; *mc; mc++) |
| 377 | XPUSHs(RET((gcMAC *)*mc, "Catacomb::MACClass")); |
| 378 | |
| 379 | size_t |
| 380 | hashsz(mc) |
| 381 | gcMAC *mc |
| 382 | CODE: |
| 383 | RETVAL = mc->hashsz; |
| 384 | OUTPUT: |
| 385 | RETVAL |
| 386 | |
| 387 | keysize * |
| 388 | keysz(mc) |
| 389 | gcMAC *mc |
| 390 | CODE: |
| 391 | RETVAL = mc->keysz; |
| 392 | OUTPUT: |
| 393 | RETVAL |
| 394 | |
| 395 | char * |
| 396 | name(mc) |
| 397 | gcMAC *mc |
| 398 | CODE: |
| 399 | RETVAL = (char *)mc->name; |
| 400 | OUTPUT: |
| 401 | RETVAL |
| 402 | |
| 403 | gMAC * |
| 404 | key(mc, k) |
| 405 | gcMAC *mc |
| 406 | SV *k |
| 407 | PREINIT: |
| 408 | STRLEN len; |
| 409 | char *p; |
| 410 | CODE: |
| 411 | p = SvPV(k, len); |
| 412 | if (keysz(len, mc->keysz) != len) { |
| 413 | croak("bad key size %lu for mac `%s'", |
| 414 | (unsigned long)len, mc->name); |
| 415 | } |
| 416 | RETVAL = mc->key(p, len); |
| 417 | OUTPUT: |
| 418 | RETVAL |
| 419 | |
| 420 | MODULE = Catacomb PACKAGE = Catacomb::MAC |
| 421 | |
| 422 | SV * |
| 423 | DESTROY(m) |
| 424 | gMAC *m |
| 425 | CODE: |
| 426 | m->ops->destroy(m); |
| 427 | XSRETURN_YES; |
| 428 | |
| 429 | ghash * |
| 430 | init(m) |
| 431 | gMAC *m |
| 432 | CODE: |
| 433 | RETVAL = m->ops->init(m); |
| 434 | OUTPUT: |
| 435 | RETVAL |
| 436 | |
| 437 | gcMAC * |
| 438 | class(m) |
| 439 | gMAC *m |
| 440 | CODE: |
| 441 | RETVAL = (gcMAC *)m->ops->c; |
| 442 | OUTPUT: |
| 443 | RETVAL |
| 444 | |
| 445 | MODULE = Catacomb PACKAGE = Catacomb::Rand |
| 446 | |
| 447 | SV * |
| 448 | seedint(r, seed) |
| 449 | grand *r |
| 450 | U32 seed |
| 451 | CODE: |
| 452 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDUINT32)) |
| 453 | croak("rng `%s' doesn't support `seedint'", r->ops->name); |
| 454 | r->ops->misc(r, GRAND_SEEDUINT32, seed); |
| 455 | XSRETURN_YES; |
| 456 | |
| 457 | SV * |
| 458 | seedblock(r, seed) |
| 459 | grand *r |
| 460 | SV *seed |
| 461 | PREINIT: |
| 462 | STRLEN len; |
| 463 | char *p; |
| 464 | CODE: |
| 465 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDBLOCK)) |
| 466 | croak("rng `%s' doesn't support `seedblock'", r->ops->name); |
| 467 | p = SvPV(seed, len); |
| 468 | r->ops->misc(r, GRAND_SEEDBLOCK, p, len); |
| 469 | XSRETURN_YES; |
| 470 | |
| 471 | SV * |
| 472 | seedmp(r, seed) |
| 473 | grand *r |
| 474 | mp *seed |
| 475 | CODE: |
| 476 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDMP)) |
| 477 | croak("rng `%s' doesn't support `seedmp'", r->ops->name); |
| 478 | r->ops->misc(r, GRAND_SEEDMP, seed); |
| 479 | XSRETURN_YES; |
| 480 | |
| 481 | SV * |
| 482 | seedrand(r, seed) |
| 483 | grand *r |
| 484 | grand *seed |
| 485 | CODE: |
| 486 | if (!r->ops->misc(r, GRAND_CHECK, GRAND_SEEDRAND)) |
| 487 | croak("rng `%s' doesn't support `seedrand'", r->ops->name); |
| 488 | r->ops->misc(r, GRAND_SEEDRAND, seed); |
| 489 | XSRETURN_YES; |
| 490 | |
| 491 | U32 |
| 492 | raw(r) |
| 493 | grand *r |
| 494 | CODE: |
| 495 | RETVAL = r->ops->raw(r); |
| 496 | OUTPUT: |
| 497 | RETVAL |
| 498 | |
| 499 | U32 |
| 500 | word(r) |
| 501 | grand *r |
| 502 | CODE: |
| 503 | RETVAL = r->ops->word(r); |
| 504 | OUTPUT: |
| 505 | RETVAL |
| 506 | |
| 507 | U8 |
| 508 | byte(r) |
| 509 | grand *r |
| 510 | CODE: |
| 511 | RETVAL = r->ops->byte(r); |
| 512 | OUTPUT: |
| 513 | RETVAL |
| 514 | |
| 515 | char |
| 516 | char(r) |
| 517 | grand *r |
| 518 | CODE: |
| 519 | RETVAL = r->ops->byte(r); |
| 520 | OUTPUT: |
| 521 | RETVAL |
| 522 | |
| 523 | U32 |
| 524 | range(r, limit) |
| 525 | grand *r |
| 526 | U32 limit |
| 527 | CODE: |
| 528 | RETVAL = r->ops->range(r, limit); |
| 529 | OUTPUT: |
| 530 | RETVAL |
| 531 | |
| 532 | mp * |
| 533 | mp(r, bits, or = 0) |
| 534 | grand *r |
| 535 | unsigned or |
| 536 | unsigned bits |
| 537 | CODE: |
| 538 | RETVAL = mprand(MP_NEW, bits, r, or); |
| 539 | OUTPUT: |
| 540 | RETVAL |
| 541 | |
| 542 | mp * |
| 543 | mprange(r, limit) |
| 544 | grand *r |
| 545 | mp *limit |
| 546 | CODE: |
| 547 | RETVAL = mprand_range(MP_NEW, limit, r, 0); |
| 548 | OUTPUT: |
| 549 | RETVAL |
| 550 | |
| 551 | SV * |
| 552 | fill(r, n) |
| 553 | grand *r |
| 554 | size_t n |
| 555 | CODE: |
| 556 | RETVAL = NEWSV(0, n ? n : 1); |
| 557 | r->ops->fill(r, SvPVX(RETVAL), n); |
| 558 | SvCUR_set(RETVAL, n); |
| 559 | SvPOK_on(RETVAL); |
| 560 | OUTPUT: |
| 561 | RETVAL |
| 562 | |
| 563 | char * |
| 564 | name(r) |
| 565 | grand *r |
| 566 | CODE: |
| 567 | RETVAL = (char *)r->ops->name; |
| 568 | OUTPUT: |
| 569 | RETVAL |
| 570 | |
| 571 | U32 |
| 572 | flags(r) |
| 573 | grand *r |
| 574 | CODE: |
| 575 | RETVAL = r->ops->f; |
| 576 | OUTPUT: |
| 577 | RETVAL |
| 578 | |
| 579 | U32 |
| 580 | max(r) |
| 581 | grand *r |
| 582 | CODE: |
| 583 | RETVAL = r->ops->max; |
| 584 | OUTPUT: |
| 585 | RETVAL |
| 586 | |
| 587 | MODULE = Catacomb PACKAGE = Catacomb::Rand::True |
| 588 | |
| 589 | Rand_True * |
| 590 | _global(me) |
| 591 | SV *me |
| 592 | CODE: |
| 593 | RETVAL = &rand_global; |
| 594 | OUTPUT: |
| 595 | RETVAL |
| 596 | |
| 597 | Rand_True * |
| 598 | rand(me) |
| 599 | SV *me |
| 600 | CODE: |
| 601 | RETVAL = rand_create(); |
| 602 | OUTPUT: |
| 603 | RETVAL |
| 604 | |
| 605 | SV * |
| 606 | gate(r) |
| 607 | Rand_True *r |
| 608 | CODE: |
| 609 | r->ops->misc(r, RAND_GATE); |
| 610 | XSRETURN_YES; |
| 611 | |
| 612 | SV * |
| 613 | stretch(r) |
| 614 | Rand_True *r |
| 615 | CODE: |
| 616 | r->ops->misc(r, RAND_STRETCH); |
| 617 | XSRETURN_YES; |
| 618 | |
| 619 | SV * |
| 620 | key(r, k) |
| 621 | Rand_True *r |
| 622 | SV *k |
| 623 | PREINIT: |
| 624 | STRLEN len; |
| 625 | char *p; |
| 626 | CODE: |
| 627 | p = SvPV(k, len); |
| 628 | r->ops->misc(r, RAND_KEY, p, len); |
| 629 | XSRETURN_YES; |
| 630 | |
| 631 | SV * |
| 632 | noisesrc(r) |
| 633 | Rand_True *r |
| 634 | CODE: |
| 635 | r->ops->misc(r, RAND_NOISESRC, &noise_source); |
| 636 | XSRETURN_YES; |
| 637 | |
| 638 | SV * |
| 639 | seed(r, bits = 160) |
| 640 | Rand_True *r |
| 641 | int bits |
| 642 | CODE: |
| 643 | r->ops->misc(r, RAND_SEED, bits); |
| 644 | XSRETURN_YES; |
| 645 | |
| 646 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Fib |
| 647 | |
| 648 | SV * |
| 649 | new(me, seed) |
| 650 | SV *me |
| 651 | U32 seed |
| 652 | CODE: |
| 653 | RETVAL = MAKE(fibrand_create(seed), "Catacomb::Rand::Fib"); |
| 654 | OUTPUT: |
| 655 | RETVAL |
| 656 | |
| 657 | MODULE = Catacomb PACKAGE = Catacomb::Rand::LC |
| 658 | |
| 659 | SV * |
| 660 | new(me, seed) |
| 661 | SV *me |
| 662 | U32 seed |
| 663 | CODE: |
| 664 | RETVAL = MAKE(lcrand_create(seed), "Catacomb::Rand::LC"); |
| 665 | OUTPUT: |
| 666 | RETVAL |
| 667 | |
| 668 | MODULE = Catacomb PACKAGE = Catacomb::Rand::DSA |
| 669 | |
| 670 | Rand_DSA * |
| 671 | new(me, k) |
| 672 | SV *me |
| 673 | SV *k |
| 674 | PREINIT: |
| 675 | STRLEN len; |
| 676 | char *p; |
| 677 | CODE: |
| 678 | p = SvPV(k, len); |
| 679 | RETVAL = dsarand_create(p, len); |
| 680 | OUTPUT: |
| 681 | RETVAL |
| 682 | |
| 683 | SV * |
| 684 | passes(r, n) |
| 685 | Rand_DSA *r |
| 686 | unsigned n |
| 687 | CODE: |
| 688 | r->ops->misc(r, DSARAND_PASSES, n); |
| 689 | XSRETURN_YES; |
| 690 | |
| 691 | SV * |
| 692 | seed(r) |
| 693 | Rand_DSA *r |
| 694 | PREINIT: |
| 695 | size_t sz; |
| 696 | CODE: |
| 697 | sz = r->ops->misc(r, DSARAND_SEEDSZ); |
| 698 | RETVAL = NEWSV(0, sz ? sz : 1); |
| 699 | r->ops->misc(r, DSARAND_GETSEED, SvPVX(RETVAL)); |
| 700 | SvCUR_set(RETVAL, sz); |
| 701 | SvPOK_on(RETVAL); |
| 702 | OUTPUT: |
| 703 | RETVAL |
| 704 | |
| 705 | MODULE = Catacomb PACKAGE = Catacomb::Rand::RC4 |
| 706 | |
| 707 | SV * |
| 708 | new(me, k) |
| 709 | SV *me |
| 710 | SV *k |
| 711 | PREINIT: |
| 712 | STRLEN len; |
| 713 | char *p; |
| 714 | CODE: |
| 715 | p = SvPV(k, len); |
| 716 | RETVAL = MAKE(rc4_rand(p, len), "Catacomb::Rand::RC4"); |
| 717 | OUTPUT: |
| 718 | RETVAL |
| 719 | |
| 720 | MODULE = Catacomb PACKAGE = Catacomb::Rand::SEAL |
| 721 | |
| 722 | SV * |
| 723 | new(me, k, n = 0) |
| 724 | SV *me |
| 725 | SV *k |
| 726 | U32 n |
| 727 | PREINIT: |
| 728 | STRLEN len; |
| 729 | char *p; |
| 730 | CODE: |
| 731 | p = SvPV(k, len); |
| 732 | RETVAL = MAKE(seal_rand(p, len, n), "Catacomb::Rand::SEAL"); |
| 733 | OUTPUT: |
| 734 | RETVAL |
| 735 | |
| 736 | MODULE = Catacomb PACKAGE = Catacomb::Rand::MGF |
| 737 | |
| 738 | SV * |
| 739 | new(me, name, k) |
| 740 | SV *me |
| 741 | char *name |
| 742 | SV *k |
| 743 | CODE: |
| 744 | RETVAL = findrand(mgftab, "Catacomb::Rand::MGF", name, k); |
| 745 | OUTPUT: |
| 746 | RETVAL |
| 747 | |
| 748 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Counter |
| 749 | |
| 750 | SV * |
| 751 | new(me, name, k) |
| 752 | SV *me |
| 753 | char *name |
| 754 | SV *k |
| 755 | CODE: |
| 756 | RETVAL = findrand(ctrtab, "Catacomb::Rand::Counter", name, k); |
| 757 | OUTPUT: |
| 758 | RETVAL |
| 759 | |
| 760 | MODULE = Catacomb PACKAGE = Catacomb::Rand::OFB |
| 761 | |
| 762 | SV * |
| 763 | new(me, name, k) |
| 764 | SV *me |
| 765 | char *name |
| 766 | SV *k |
| 767 | CODE: |
| 768 | RETVAL = findrand(ofbtab, "Catacomb::Rand::OFB", name, k); |
| 769 | OUTPUT: |
| 770 | RETVAL |
| 771 | |
| 772 | MODULE = Catacomb PACKAGE = Catacomb::Rand::Magic |
| 773 | |
| 774 | SV * |
| 775 | DESTROY(r) |
| 776 | grand *r |
| 777 | CODE: |
| 778 | XSRETURN_YES; |
| 779 | |
| 780 | #----- That's all, folks ---------------------------------------------------- |