line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* $Id: SipHash.xs,v 0.7 2020/12/11 18:06:57 dankogai Exp dankogai $ |
3
|
|
|
|
|
|
|
*/ |
4
|
|
|
|
|
|
|
#include "EXTERN.h" |
5
|
|
|
|
|
|
|
#include "perl.h" |
6
|
|
|
|
|
|
|
#include "XSUB.h" |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "csiphash.c" |
9
|
|
|
|
|
|
|
|
10
|
11
|
|
|
|
|
|
uint64_t siphash24_sv(SV *src, SV *seed) { |
11
|
|
|
|
|
|
|
STRLEN src_len; |
12
|
11
|
100
|
|
|
|
|
char * src_pv= SvPV(src,src_len); |
13
|
|
|
|
|
|
|
STRLEN seed_len; |
14
|
11
|
50
|
|
|
|
|
char *seed_pv= SvPV(seed,seed_len); |
15
|
|
|
|
|
|
|
assert(seed_len>=16); |
16
|
11
|
|
|
|
|
|
return siphash24(src_pv, src_len, seed_pv); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
static SV * |
20
|
10
|
|
|
|
|
|
siphash_as_av(SV *src, SV *seed) { |
21
|
10
|
|
|
|
|
|
uint64_t hash = siphash24_sv(src,seed); |
22
|
|
|
|
|
|
|
|
23
|
10
|
|
|
|
|
|
AV *av = newAV(); |
24
|
10
|
|
|
|
|
|
av_extend(av, 1); |
25
|
10
|
|
|
|
|
|
av_store(av, 0, newSVuv(hash & 0xffffffff)); |
26
|
10
|
|
|
|
|
|
av_store(av, 1, newSVuv(hash >> 32)); |
27
|
10
|
|
|
|
|
|
return newRV_noinc((SV *)av); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
MODULE = Digest::SipHash PACKAGE = Digest::SipHash |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
UV |
33
|
|
|
|
|
|
|
_xs_siphash64(src, seed) |
34
|
|
|
|
|
|
|
SV *src; |
35
|
|
|
|
|
|
|
SV *seed; |
36
|
|
|
|
|
|
|
CODE: |
37
|
1
|
|
|
|
|
|
RETVAL = (UV)siphash24_sv(src, seed); |
38
|
|
|
|
|
|
|
OUTPUT: |
39
|
|
|
|
|
|
|
RETVAL |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
SV * |
42
|
|
|
|
|
|
|
_xs_siphash_av(src, seed) |
43
|
|
|
|
|
|
|
SV *src; |
44
|
|
|
|
|
|
|
SV *seed; |
45
|
|
|
|
|
|
|
CODE: |
46
|
10
|
|
|
|
|
|
RETVAL = siphash_as_av(src, seed); |
47
|
|
|
|
|
|
|
OUTPUT: |
48
|
|
|
|
|
|
|
RETVAL |