lib/Net/SSH/Perl/Key/Ed25519.xs

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 70 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/Net/SSH/Perl/Cipher/ChachaPoly.xs ↑ Summary src/blowfish/blowfish.c »
1 #include "src/blowfish/blowfish.c"
2 #include "src/ed25519/keypair.c"
3 #include "src/ed25519/sign.c"
4 #include "src/ed25519/verify.c"
5 #include "src/ed25519/sha512.c"
6 #define select(a,b,c) ed25519_select (a, b, c)
7 #include "src/ed25519/ge.c"
8 #include "src/ed25519/fe.c"
9 #define load_3(x) sc_load_3(x)
10 #define load_4(x) sc_load_4(x)
11 #include "src/ed25519/sc.c"
12  
13 MODULE = Net::SSH::Perl PACKAGE = Net::SSH::Perl::Key::Ed25519
14  
15 PROTOTYPES: ENABLE
16  
17 blf_ctx *
18 bf_init()
19 CODE:
20 {
21 0 Newxz(RETVAL, 1, blf_ctx);
22 0 Blowfish_initstate(RETVAL);
23 }
24 OUTPUT:
25 RETVAL
26  
27 void
28 bf_expandstate(ctx, sv_data, sv_key)
29 blf_ctx *ctx
30 SV *sv_data
31 SV *sv_key
32 CODE:
33 {
34 0 ▶ STRLEN datalen; unsigned char *data = (unsigned char *) SvPVbyte(sv_data,datalen);
Branch: 1 branch
BranchTrueFalseTotal
STRLEN datalen; unsigned char *data = (unsigned char *) SvPVbyte(sv_data,datalen); 0 0 0
35 0 STRLEN keylen; unsigned char *key = (unsigned char *) SvPVbyte(sv_key,keylen);
36 0 Blowfish_expandstate(ctx, data, datalen, key, keylen);
37 }
38  
39 void
40 bf_expand0state(ctx,sv_key)
41 blf_ctx *ctx
42 SV *sv_key
43 CODE:
44 {
45 STRLEN keylen;
46 0 unsigned char *key = (unsigned char *) SvPVbyte(sv_key,keylen);
47 0 Blowfish_expand0state(ctx,key,keylen);
48 }
49  
50 SV *
51 bf_encrypt_iterate(ctx, sv_data, sv_rounds)
52 blf_ctx *ctx
53 SV *sv_data
54 SV *sv_rounds
55 CODE:
56 0 {
57 STRLEN datalen;
58 0 unsigned char *data = (unsigned char *) SvPVbyte(sv_mortalcopy(sv_data),datalen);
59 0 ▶ if (datalen % 8)
Branch: 1 branch
BranchTrueFalseTotal
if (datalen % 8) 0 0 0
60 0 croak("data must be in 8-byte chunks");
61
62 0 uint16_t words = datalen / 4;
63 0 uint32_t cdata[words];
64 0 uint16_t j = 0;
65 int i;
66 0 int rounds = SvIVx(sv_rounds);
67  
68 0 ▶ for (i=0; i<words; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<words; i++) 0 0 0
69 0 cdata[i] = Blowfish_stream2word(data, datalen, &j);
70 0 ▶ for (i=0; i<rounds; i++)
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<rounds; i++) 0 0 0
71 0 blf_enc(ctx, cdata, sizeof(cdata) / sizeof(uint64_t));
72  
73 0 ▶ for (i=0; i<words; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<words; i++) { 0 0 0
74 0 data[4 * i + 3] = (cdata[i] >> 24) & 0xff;
75 0 data[4 * i + 2] = (cdata[i] >> 16) & 0xff;
76 0 data[4 * i + 1] = (cdata[i] >> 8) & 0xff;
77 0 data[4 * i ] = cdata[i] & 0xff;
78 }
79 0 RETVAL = newSVpvn ((char *) data, datalen);
80 }
81 OUTPUT:
82 RETVAL
83  
84 void
85 ed25519_generate_keypair (secret)
86 SV *secret
87 PPCODE:
88 {
89 STRLEN secret_l; unsigned char *secret_p;
90  
91 unsigned char public_key[32];
92 unsigned char private_key[64];
93  
94 0 secret_p = (unsigned char *)SvPVbyte (secret, secret_l);
95  
96 0 ▶ if (secret_l != 32)
Branch: 1 branch
BranchTrueFalseTotal
if (secret_l != 32) 0 0 0
97 0 croak ("secret has wrong length (!= 32)");
98  
99 0 ed25519_create_keypair (public_key, private_key, (unsigned char *)secret_p);
100  
101 0 ▶ EXTEND (SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND (SP, 2); 0 0 0
102 0 PUSHs (sv_2mortal (newSVpvn ((char *)public_key, sizeof public_key)));
103 0 PUSHs (sv_2mortal (newSVpvn ((char *)private_key, sizeof private_key)));
104 }
105  
106 SV *
107 ed25519_sign_message (message, private_key)
108 SV *message;
109 SV *private_key;
110 CODE:
111 {
112 unsigned char signature[64];
113  
114 0 ▶ STRLEN message_l ; char *message_p = SvPVbyte (message , message_l );
Branch: 1 branch
BranchTrueFalseTotal
STRLEN message_l ; char *message_p = SvPVbyte (message , message_l ); 0 0 0
115 0 STRLEN private_key_l; char *private_key_p = SvPVbyte (private_key, private_key_l);
116  
117 0 ▶ if (private_key_l != 64)
Branch: 1 branch
BranchTrueFalseTotal
if (private_key_l != 64) 0 0 0
118 0 croak ("private key has wrong length (!= 64)");
119  
120 0 ed25519_sign (signature, (unsigned char *)message_p, message_l, (unsigned char *)private_key_p);
121  
122 0 RETVAL = newSVpvn ((char *)signature, sizeof signature);
123 }
124 OUTPUT:
125 RETVAL
126  
127 bool
128 ed25519_verify_message (SV *message, SV *public_key, SV *signature)
129 CODE:
130 {
131 0 ▶ STRLEN signature_l ; char *signature_p = SvPVbyte (signature , signature_l );
Branch: 1 branch
BranchTrueFalseTotal
STRLEN signature_l ; char *signature_p = SvPVbyte (signature , signature_l ); 0 0 0
132 0 ▶ STRLEN message_l ; char *message_p = SvPVbyte (message , message_l );
Branch: 1 branch
BranchTrueFalseTotal
STRLEN message_l ; char *message_p = SvPVbyte (message , message_l ); 0 0 0
133 0 STRLEN public_key_l; char *public_key_p = SvPVbyte (public_key, public_key_l);
134  
135 0 ▶ if (public_key_l != 32)
Branch: 1 branch
BranchTrueFalseTotal
if (public_key_l != 32) 0 0 0
136 0 croak ("public key has wrong length (!= 32)");
137  
138 0 ▶ RETVAL = ed25519_verify ((unsigned char *)signature_p, (unsigned char *)message_p, message_l, (unsigned char *)public_key_p);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ed25519_verify ((unsigned char *)signature_p, (unsigned char *)message_p, message_l, (unsigned char *)public_key_p); 0 0 0
139 }
140 OUTPUT:
141 RETVAL
« lib/Net/SSH/Perl/Cipher/ChachaPoly.xs ↑ Summary src/blowfish/blowfish.c »