File: Whirlpool.xs

package info (click to toggle)
libdigest-whirlpool-perl 1.09-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 448 kB
  • sloc: ansic: 1,646; perl: 175; makefile: 51
file content (99 lines) | stat: -rw-r--r-- 2,184 bytes parent folder | download | duplicates (4)
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
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "ppport.h"
#include "_whirlpool.c"

typedef struct whirlpool {
    NESSIEstruct state;
}* Digest__Whirlpool;

MODULE = Digest::Whirlpool		PACKAGE = Digest::Whirlpool
PROTOTYPES: DISABLE

SV *
new(SV * class)
CODE:
    Digest__Whirlpool self;
    const char * pkg;

    /* Figure out what class we're supposed to bless into, handle
       $obj->new (for completeness) and Class->new  */
    if (SvROK(class)) {
        /* An object, get is type */
        pkg = sv_reftype(SvRV(class), TRUE);
    } else {
        /* If this function gets called as Pkg->new the value being passed is
         * a READONLY SV so we'll need a copy
         */
        pkg = SvPV(class, PL_na);
    }

    /* Allocate memory for Whirlpool's store and create an IV ref
       containing its memory location */
    Newz(0, self, 1, struct whirlpool);
    NESSIEinit(&self->state);

    RETVAL = newSV(0); /* This gets mortalized automagically */
    sv_setref_pv(RETVAL, pkg, (void*)self);
OUTPUT:
    RETVAL

Digest::Whirlpool
clone(self)
    Digest::Whirlpool self
    CODE:
        Newz(0, RETVAL, 1, struct whirlpool);
        Copy(&self->state, &RETVAL->state, 1, struct whirlpool);
    OUTPUT:
        RETVAL

int
hashsize(...)
    CODE:
        RETVAL = 512;
    OUTPUT:
        RETVAL

Digest::Whirlpool
reset(self)
    Digest::Whirlpool self
    CODE:
        NESSIEinit(&self->state);
        
Digest::Whirlpool
add(self, ...)
    Digest::Whirlpool self
    CODE:
    {
        STRLEN len;
        unsigned char* data;
        unsigned int i;

        for (i = 1; i < items; i++) {
            data = (unsigned char*)(SvPV(ST(i), len));
            NESSIEadd(data, len << 3, &self->state);
        }
    }

SV*
digest(self)
    Digest::Whirlpool self
    CODE:
    {
        /* A bit (tr)?icky, makes sure the SvPV is 64 bytes then grabs
           its char* part and writes directly to it */
        RETVAL = newSVpvn("", 64);
        NESSIEfinalize(&self->state, SvPVX(RETVAL));
        NESSIEinit(&self->state);
    }

    OUTPUT:
        RETVAL

void
DESTROY(self)
    Digest::Whirlpool self
    CODE:
        Safefree(self);