| 1 |
|
| MODULE = Crypt::Sodium::XS PACKAGE = Crypt::Sodium::XS::xof |
| 2 |
|
| |
| 3 |
|
| void _define_constants() |
| 4 |
|
| |
| 5 |
|
| PREINIT: |
| 6 |
1 |
| HV *stash = gv_stashpv("Crypt::Sodium::XS::xof", 0); |
| 7 |
|
| |
| 8 |
|
| PPCODE: |
| 9 |
|
| #ifdef SODIUM_HAS_XOF |
| 10 |
1 |
| newCONSTSUB(stash, "xof_shake128_BLOCKBYTES", |
| 11 |
|
| newSVuv(crypto_xof_shake128_BLOCKBYTES)); |
| 12 |
1 |
| newCONSTSUB(stash, "xof_shake128_STATEBYTES", |
| 13 |
|
| newSVuv(crypto_xof_shake128_STATEBYTES)); |
| 14 |
1 |
| newCONSTSUB(stash, "xof_shake128_DOMAIN_STANDARD", |
| 15 |
|
| newSVpvf("%c", crypto_xof_shake128_DOMAIN_STANDARD)); |
| 16 |
1 |
| newCONSTSUB(stash, "xof_shake256_BLOCKBYTES", |
| 17 |
|
| newSVuv(crypto_xof_shake256_BLOCKBYTES)); |
| 18 |
1 |
| newCONSTSUB(stash, "xof_shake256_STATEBYTES", |
| 19 |
|
| newSVuv(crypto_xof_shake256_STATEBYTES)); |
| 20 |
1 |
| newCONSTSUB(stash, "xof_shake256_DOMAIN_STANDARD", |
| 21 |
|
| newSVpvf("%c", crypto_xof_shake256_DOMAIN_STANDARD)); |
| 22 |
1 |
| newCONSTSUB(stash, "xof_turboshake128_BLOCKBYTES", |
| 23 |
|
| newSVuv(crypto_xof_turboshake128_BLOCKBYTES)); |
| 24 |
1 |
| newCONSTSUB(stash, "xof_turboshake128_STATEBYTES", |
| 25 |
|
| newSVuv(crypto_xof_turboshake128_STATEBYTES)); |
| 26 |
1 |
| newCONSTSUB(stash, "xof_turboshake128_DOMAIN_STANDARD", |
| 27 |
|
| newSVpvf("%c", crypto_xof_turboshake128_DOMAIN_STANDARD)); |
| 28 |
1 |
| newCONSTSUB(stash, "xof_turboshake256_BLOCKBYTES", |
| 29 |
|
| newSVuv(crypto_xof_turboshake256_BLOCKBYTES)); |
| 30 |
1 |
| newCONSTSUB(stash, "xof_turboshake256_STATEBYTES", |
| 31 |
|
| newSVuv(crypto_xof_turboshake256_STATEBYTES)); |
| 32 |
1 |
| newCONSTSUB(stash, "xof_turboshake256_DOMAIN_STANDARD", |
| 33 |
|
| newSVpvf("%c", crypto_xof_turboshake256_DOMAIN_STANDARD)); |
| 34 |
1 |
| newCONSTSUB(stash, "available", &PL_sv_yes); |
| 35 |
|
| #else |
| 36 |
|
| newCONSTSUB(stash, "available", &PL_sv_no); |
| 37 |
|
| #endif |
| 38 |
|
| |
| 39 |
|
| SV * xof_shake128(SV * msg, STRLEN out_len, SV * flags = &PL_sv_undef) |
| 40 |
|
| |
| 41 |
|
| ALIAS: |
| 42 |
|
| xof_shake256 = 1 |
| 43 |
|
| xof_turboshake128 = 2 |
| 44 |
|
| xof_turboshake256 = 3 |
| 45 |
|
| xof_shake128_key = 16 |
| 46 |
|
| xof_shake256_key = 17 |
| 47 |
|
| xof_turboshake128_key = 18 |
| 48 |
|
| xof_turboshake256_key = 19 |
| 49 |
|
| |
| 50 |
|
| PREINIT: |
| 51 |
4 |
| protmem *msg_pm = NULL, *out_pm = NULL; |
| 52 |
|
| unsigned char *msg_buf, *out_buf; |
| 53 |
|
| STRLEN msg_len; |
| 54 |
4 |
| unsigned int out_flags = g_protmem_default_flags_key; |
| 55 |
|
| |
| 56 |
|
| CODE: |
| 57 |
|
| #ifdef SODIUM_HAS_XOF |
| 58 |
4 |
| SvGETMAGIC(flags); |
| 59 |
4 |
▶ | if (SvOK(flags)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(flags)) |
0 |
4 |
4 |
|
| 60 |
0 |
| out_flags = SvUV_nomg(flags); |
| 61 |
|
| |
| 62 |
4 |
▶ | if (sv_derived_from(msg, MEMVAULT_CLASS)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_derived_from(msg, MEMVAULT_CLASS)) { |
0 |
4 |
4 |
|
| 63 |
0 |
| msg_pm = protmem_get(aTHX_ msg, MEMVAULT_CLASS); |
| 64 |
0 |
| msg_buf = msg_pm->pm_ptr; |
| 65 |
0 |
| msg_len = msg_pm->size; |
| 66 |
|
| } |
| 67 |
|
| else |
| 68 |
4 |
| msg_buf = (unsigned char *)SvPVbyte(msg, msg_len); |
| 69 |
|
| |
| 70 |
4 |
▶ | if (ix & 0x10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix & 0x10) { |
0 |
4 |
4 |
|
| 71 |
0 |
| out_pm = protmem_init(aTHX_ out_len, out_flags); |
| 72 |
0 |
▶ | if (out_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm == NULL) |
0 |
0 |
0 |
|
| 73 |
0 |
| croak("xof: Failed to allocate protmem"); |
| 74 |
0 |
| out_buf = out_pm->pm_ptr; |
| 75 |
|
| } |
| 76 |
|
| else { |
| 77 |
4 |
| Newx(out_buf, out_len + 1, unsigned char); |
| 78 |
4 |
▶ | if (out_buf == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_buf == NULL) |
0 |
4 |
4 |
|
| 79 |
0 |
| croak("xof: Failed to allocate memory"); |
| 80 |
4 |
| out_buf[out_len] = '\0'; |
| 81 |
|
| } |
| 82 |
|
| |
| 83 |
4 |
▶ | if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
4 |
4 |
| if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
0 |
0 |
|
| 84 |
0 |
▶ | if (out_pm) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm) |
0 |
0 |
0 |
|
| 85 |
0 |
| protmem_free(aTHX_ out_pm); |
| 86 |
|
| else |
| 87 |
0 |
| Safefree(out_buf); |
| 88 |
0 |
| croak("xof: Failed to grant msg protmem RO"); |
| 89 |
|
| } |
| 90 |
|
| |
| 91 |
4 |
| switch(ix & ~0x10) { |
| 92 |
1 |
| case 1: |
| 93 |
1 |
| crypto_xof_shake256(out_buf, out_len, msg_buf, msg_len); |
| 94 |
1 |
| break; |
| 95 |
1 |
| case 2: |
| 96 |
1 |
| crypto_xof_turboshake128(out_buf, out_len, msg_buf, msg_len); |
| 97 |
1 |
| break; |
| 98 |
1 |
| case 3: |
| 99 |
1 |
| crypto_xof_turboshake256(out_buf, out_len, msg_buf, msg_len); |
| 100 |
1 |
| break; |
| 101 |
1 |
| default: |
| 102 |
1 |
| crypto_xof_shake128(out_buf, out_len, msg_buf, msg_len); |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
4 |
▶ | if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
4 |
4 |
| if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
0 |
0 |
|
| 106 |
0 |
▶ | if (out_pm) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm) |
0 |
0 |
0 |
|
| 107 |
0 |
| protmem_free(aTHX_ out_pm); |
| 108 |
|
| else |
| 109 |
0 |
| Safefree(out_buf); |
| 110 |
0 |
| croak("xof: Failed to release msg protmem RO"); |
| 111 |
|
| } |
| 112 |
|
| |
| 113 |
4 |
▶ | if (ix & 0x10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix & 0x10) { |
0 |
4 |
4 |
|
| 114 |
0 |
▶ | if (protmem_release(aTHX_ out_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_release(aTHX_ out_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
0 |
0 |
0 |
|
| 115 |
0 |
| protmem_free(aTHX_ out_pm); |
| 116 |
0 |
| croak("xof: Failed to release out protmem RW"); |
| 117 |
|
| } |
| 118 |
0 |
| RETVAL = protmem_to_sv(aTHX_ out_pm, MEMVAULT_CLASS); |
| 119 |
|
| } |
| 120 |
|
| else { |
| 121 |
4 |
| RETVAL = newSV(0); |
| 122 |
4 |
| sv_usepvn_flags(RETVAL, (char *)out_buf, out_len, SV_HAS_TRAILING_NUL); |
| 123 |
|
| } |
| 124 |
|
| #else |
| 125 |
|
| croak("XOF not supported by this version of libsodium"); |
| 126 |
|
| #endif |
| 127 |
|
| |
| 128 |
|
| OUTPUT: |
| 129 |
|
| RETVAL |
| 130 |
|
| |
| 131 |
|
| SV * xof_shake128_init(unsigned char domain = 0x1f, SV * flags = &PL_sv_undef) |
| 132 |
|
| |
| 133 |
|
| ALIAS: |
| 134 |
|
| xof_shake256_init = 1 |
| 135 |
|
| xof_turboshake128_init = 2 |
| 136 |
|
| xof_turboshake256_init = 3 |
| 137 |
|
| |
| 138 |
|
| PREINIT: |
| 139 |
|
| protmem *state_pm; |
| 140 |
12 |
▶ | unsigned int state_flags = g_protmem_default_flags_state; |
Branch: 1 branch
| Branch | True | False | Total |
| unsigned int state_flags = g_protmem_default_flags_state; |
12 |
0 |
12 |
|
| 141 |
|
| |
| 142 |
|
| CODE: |
| 143 |
|
| #ifdef SODIUM_HAS_XOF |
| 144 |
12 |
▶ | if (domain < 1 || domain > 127) |
Branch: 2 branches
| Branch | True | False | Total |
| if (domain < 1 || domain > 127) |
12 |
0 |
12 |
| if (domain < 1 || domain > 127) |
0 |
12 |
12 |
|
| 145 |
0 |
| croak("xof_init: Invalid domain (must be 1-127)"); |
| 146 |
|
| |
| 147 |
12 |
| SvGETMAGIC(flags); |
| 148 |
12 |
▶ | if (SvOK(flags)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(flags)) |
0 |
12 |
12 |
|
| 149 |
0 |
| state_flags = SvUV_nomg(flags); |
| 150 |
|
| |
| 151 |
12 |
| switch(ix) { |
| 152 |
3 |
| case 1: |
| 153 |
3 |
| state_pm = protmem_init(aTHX_ sizeof(crypto_xof_shake256_state), state_flags); |
| 154 |
3 |
▶ | if (state_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (state_pm == NULL) |
0 |
3 |
3 |
|
| 155 |
0 |
| croak("xof_init: Failed to allocate protmem"); |
| 156 |
3 |
| crypto_xof_shake256_init_with_domain(state_pm->pm_ptr, domain); |
| 157 |
3 |
| break; |
| 158 |
3 |
| case 2: |
| 159 |
3 |
| state_pm = protmem_init(aTHX_ sizeof(crypto_xof_turboshake128_state), state_flags); |
| 160 |
3 |
▶ | if (state_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (state_pm == NULL) |
0 |
3 |
3 |
|
| 161 |
0 |
| croak("xof_init: Failed to allocate protmem"); |
| 162 |
3 |
| crypto_xof_turboshake128_init_with_domain(state_pm->pm_ptr, domain); |
| 163 |
3 |
| break; |
| 164 |
3 |
| case 3: |
| 165 |
3 |
| state_pm = protmem_init(aTHX_ sizeof(crypto_xof_turboshake256_state), state_flags); |
| 166 |
3 |
▶ | if (state_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (state_pm == NULL) |
0 |
3 |
3 |
|
| 167 |
0 |
| croak("xof_init: Failed to allocate protmem"); |
| 168 |
3 |
| crypto_xof_turboshake256_init_with_domain(state_pm->pm_ptr, domain); |
| 169 |
3 |
| break; |
| 170 |
3 |
| default: |
| 171 |
3 |
| state_pm = protmem_init(aTHX_ sizeof(crypto_xof_shake128_state), state_flags); |
| 172 |
3 |
▶ | if (state_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (state_pm == NULL) |
0 |
3 |
3 |
|
| 173 |
0 |
| croak("xof_init: Failed to allocate protmem"); |
| 174 |
3 |
| crypto_xof_shake128_init_with_domain(state_pm->pm_ptr, domain); |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
12 |
▶ | if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
0 |
12 |
12 |
|
| 178 |
0 |
| protmem_free(aTHX_ state_pm); |
| 179 |
0 |
| croak("xof_init: Failed to release protmem RW"); |
| 180 |
|
| } |
| 181 |
|
| |
| 182 |
12 |
| switch(ix) { |
| 183 |
3 |
| case 1: |
| 184 |
3 |
| RETVAL = protmem_to_sv(aTHX_ state_pm, "Crypt::Sodium::XS::xof::shake256_multi"); |
| 185 |
3 |
| break; |
| 186 |
3 |
| case 2: |
| 187 |
3 |
| RETVAL = protmem_to_sv(aTHX_ state_pm, "Crypt::Sodium::XS::xof::turboshake128_multi"); |
| 188 |
3 |
| break; |
| 189 |
3 |
| case 3: |
| 190 |
3 |
| RETVAL = protmem_to_sv(aTHX_ state_pm, "Crypt::Sodium::XS::xof::turboshake256_multi"); |
| 191 |
3 |
| break; |
| 192 |
3 |
| default: |
| 193 |
3 |
| RETVAL = protmem_to_sv(aTHX_ state_pm, "Crypt::Sodium::XS::xof::shake128_multi"); |
| 194 |
|
| } |
| 195 |
|
| #else |
| 196 |
|
| croak("XOF not supported by this version of libsodium"); |
| 197 |
|
| #endif |
| 198 |
|
| |
| 199 |
|
| OUTPUT: |
| 200 |
|
| RETVAL |
| 201 |
|
| |
| 202 |
|
| MODULE = Crypt::Sodium::XS PACKAGE = Crypt::Sodium::XS::xof::shake128_multi |
| 203 |
|
| |
| 204 |
|
| void DESTROY(SV * self) |
| 205 |
|
| |
| 206 |
|
| ALIAS: |
| 207 |
|
| Crypt::Sodium::XS::xof::shake256_multi::DESTROY = 1 |
| 208 |
|
| Crypt::Sodium::XS::xof::turboshake128_multi::DESTROY = 2 |
| 209 |
|
| Crypt::Sodium::XS::xof::turboshake256_multi::DESTROY = 3 |
| 210 |
|
| |
| 211 |
|
| PREINIT: |
| 212 |
|
| protmem *state_pm; |
| 213 |
|
| |
| 214 |
|
| CODE: |
| 215 |
16 |
| switch(ix) { |
| 216 |
4 |
| case 1: |
| 217 |
4 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake256_multi"); |
| 218 |
4 |
| break; |
| 219 |
4 |
| case 2: |
| 220 |
4 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake128_multi"); |
| 221 |
4 |
| break; |
| 222 |
4 |
| case 3: |
| 223 |
4 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake256_multi"); |
| 224 |
4 |
| break; |
| 225 |
4 |
| default: |
| 226 |
4 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake128_multi"); |
| 227 |
|
| } |
| 228 |
16 |
| protmem_free(aTHX_ state_pm); |
| 229 |
|
| |
| 230 |
|
| SV * clone(SV * self) |
| 231 |
|
| |
| 232 |
|
| ALIAS: |
| 233 |
|
| Crypt::Sodium::XS::xof::shake256_multi::clone = 1 |
| 234 |
|
| Crypt::Sodium::XS::xof::turboshake128_multi::clone = 2 |
| 235 |
|
| Crypt::Sodium::XS::xof::turboshake256_multi::clone = 3 |
| 236 |
|
| |
| 237 |
|
| CODE: |
| 238 |
4 |
| switch(ix) { |
| 239 |
1 |
| case 1: |
| 240 |
1 |
| RETVAL = protmem_clone_sv(aTHX_ self, "Crypt::Sodium::XS::xof::shake256_multi"); |
| 241 |
1 |
| break; |
| 242 |
1 |
| case 2: |
| 243 |
1 |
| RETVAL = protmem_clone_sv(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake128_multi"); |
| 244 |
1 |
| break; |
| 245 |
1 |
| case 3: |
| 246 |
1 |
| RETVAL = protmem_clone_sv(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake256_multi"); |
| 247 |
1 |
| break; |
| 248 |
1 |
| default: |
| 249 |
1 |
| RETVAL = protmem_clone_sv(aTHX_ self, "Crypt::Sodium::XS::xof::shake128_multi"); |
| 250 |
|
| } |
| 251 |
|
| |
| 252 |
|
| OUTPUT: |
| 253 |
|
| RETVAL |
| 254 |
|
| |
| 255 |
|
| SV * squeeze(SV * self, STRLEN out_len, SV * flags = &PL_sv_undef) |
| 256 |
|
| |
| 257 |
|
| ALIAS: |
| 258 |
|
| Crypt::Sodium::XS::xof::shake256_multi::squeeze = 1 |
| 259 |
|
| Crypt::Sodium::XS::xof::turboshake128_multi::squeeze = 2 |
| 260 |
|
| Crypt::Sodium::XS::xof::turboshake256_multi::squeeze = 3 |
| 261 |
|
| squeeze_key = 16 |
| 262 |
|
| Crypt::Sodium::XS::xof::shake256_multi::squeeze_key = 17 |
| 263 |
|
| Crypt::Sodium::XS::xof::turboshake128_multi::squeeze_key = 18 |
| 264 |
|
| Crypt::Sodium::XS::xof::turboshake256_multi::squeeze_key = 19 |
| 265 |
|
| |
| 266 |
|
| PREINIT: |
| 267 |
20 |
| protmem *out_pm = NULL, *state_pm; |
| 268 |
|
| unsigned char *out_buf; |
| 269 |
20 |
| unsigned int out_flags = g_protmem_default_flags_key; |
| 270 |
|
| |
| 271 |
|
| CODE: |
| 272 |
|
| #ifdef SODIUM_HAS_XOF |
| 273 |
20 |
| SvGETMAGIC(flags); |
| 274 |
20 |
▶ | if (SvOK(flags)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(flags)) |
0 |
20 |
20 |
|
| 275 |
0 |
| out_flags = SvUV_nomg(flags); |
| 276 |
|
| |
| 277 |
20 |
▶ | if (ix & 0x10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix & 0x10) { |
0 |
20 |
20 |
|
| 278 |
0 |
| out_pm = protmem_init(aTHX_ out_len, out_flags); |
| 279 |
0 |
▶ | if (out_pm == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm == NULL) |
0 |
0 |
0 |
|
| 280 |
0 |
| croak("squeeze: Failed to allocate protmem"); |
| 281 |
0 |
| out_buf = out_pm->pm_ptr; |
| 282 |
|
| } |
| 283 |
|
| else { |
| 284 |
20 |
| Newx(out_buf, out_len + 1, unsigned char); |
| 285 |
20 |
▶ | if (out_buf == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_buf == NULL) |
0 |
20 |
20 |
|
| 286 |
0 |
| croak("squeeze: Failed to allocate memory"); |
| 287 |
20 |
| out_buf[out_len] = '\0'; |
| 288 |
|
| } |
| 289 |
|
| |
| 290 |
20 |
| switch(ix & ~0x10) { |
| 291 |
5 |
| case 1: |
| 292 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake256_multi"); |
| 293 |
5 |
| break; |
| 294 |
5 |
| case 2: |
| 295 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake128_multi"); |
| 296 |
5 |
| break; |
| 297 |
5 |
| case 3: |
| 298 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake256_multi"); |
| 299 |
5 |
| break; |
| 300 |
5 |
| default: |
| 301 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake128_multi"); |
| 302 |
|
| } |
| 303 |
20 |
▶ | if (protmem_grant(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_grant(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
0 |
20 |
20 |
|
| 304 |
0 |
▶ | if (out_pm) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm) |
0 |
0 |
0 |
|
| 305 |
0 |
| protmem_free(aTHX_ out_pm); |
| 306 |
|
| else |
| 307 |
0 |
| Safefree(out_buf); |
| 308 |
0 |
| croak("squeeze: Failed to grant protmem RW"); |
| 309 |
|
| } |
| 310 |
|
| |
| 311 |
20 |
| switch(ix & ~0x10) { |
| 312 |
5 |
| case 1: |
| 313 |
5 |
| crypto_xof_shake256_squeeze(state_pm->pm_ptr, out_buf, out_len); |
| 314 |
5 |
| break; |
| 315 |
5 |
| case 2: |
| 316 |
5 |
| crypto_xof_turboshake128_squeeze(state_pm->pm_ptr, out_buf, out_len); |
| 317 |
5 |
| break; |
| 318 |
5 |
| case 3: |
| 319 |
5 |
| crypto_xof_turboshake256_squeeze(state_pm->pm_ptr, out_buf, out_len); |
| 320 |
5 |
| break; |
| 321 |
5 |
| default: |
| 322 |
5 |
| crypto_xof_shake128_squeeze(state_pm->pm_ptr, out_buf, out_len); |
| 323 |
|
| } |
| 324 |
|
| |
| 325 |
20 |
▶ | if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
0 |
20 |
20 |
|
| 326 |
0 |
▶ | if (out_pm) |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_pm) |
0 |
0 |
0 |
|
| 327 |
0 |
| protmem_free(aTHX_ out_pm); |
| 328 |
|
| else |
| 329 |
0 |
| Safefree(out_buf); |
| 330 |
0 |
| croak("squeeze: Failed to release state protmem RW"); |
| 331 |
|
| } |
| 332 |
|
| |
| 333 |
20 |
▶ | if (ix & 0x10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ix & 0x10) { |
0 |
20 |
20 |
|
| 334 |
0 |
▶ | if (protmem_release(aTHX_ out_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_release(aTHX_ out_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) { |
0 |
0 |
0 |
|
| 335 |
0 |
| protmem_free(aTHX_ state_pm); |
| 336 |
0 |
| croak("squeeze: Failed to release out protmem RW"); |
| 337 |
|
| } |
| 338 |
0 |
| RETVAL = protmem_to_sv(aTHX_ out_pm, MEMVAULT_CLASS); |
| 339 |
|
| } |
| 340 |
|
| else { |
| 341 |
20 |
| RETVAL = newSV(0); |
| 342 |
20 |
| sv_usepvn_flags(RETVAL, (char *)out_buf, out_len, SV_HAS_TRAILING_NUL); |
| 343 |
|
| } |
| 344 |
|
| #else |
| 345 |
|
| croak("XOF not supported by this version of libsodium"); |
| 346 |
|
| #endif |
| 347 |
|
| |
| 348 |
|
| OUTPUT: |
| 349 |
|
| RETVAL |
| 350 |
|
| |
| 351 |
|
| void update(SV * self, ...) |
| 352 |
|
| |
| 353 |
|
| ALIAS: |
| 354 |
|
| Crypt::Sodium::XS::xof::shake256_multi::update = 1 |
| 355 |
|
| Crypt::Sodium::XS::xof::turboshake128_multi::update = 2 |
| 356 |
|
| Crypt::Sodium::XS::xof::turboshake256_multi::update = 3 |
| 357 |
|
| |
| 358 |
|
| PREINIT: |
| 359 |
20 |
| protmem *state_pm, *msg_pm = NULL; |
| 360 |
|
| unsigned char *msg_buf; |
| 361 |
|
| STRLEN msg_len; |
| 362 |
|
| I32 i; |
| 363 |
|
| |
| 364 |
|
| PPCODE: |
| 365 |
|
| #ifdef SODIUM_HAS_XOF |
| 366 |
20 |
| switch(ix) { |
| 367 |
5 |
| case 1: |
| 368 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake256_multi"); |
| 369 |
5 |
| break; |
| 370 |
5 |
| case 2: |
| 371 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake128_multi"); |
| 372 |
5 |
| break; |
| 373 |
5 |
| case 3: |
| 374 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::turboshake256_multi"); |
| 375 |
5 |
| break; |
| 376 |
5 |
| default: |
| 377 |
5 |
| state_pm = protmem_get(aTHX_ self, "Crypt::Sodium::XS::xof::shake128_multi"); |
| 378 |
|
| } |
| 379 |
20 |
▶ | if (protmem_grant(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_grant(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) |
0 |
20 |
20 |
|
| 380 |
0 |
| croak("update: Failed to grant state protmem RW"); |
| 381 |
|
| |
| 382 |
64 |
▶ | for (i = 1; i < items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 1; i < items; i++) { |
44 |
20 |
64 |
|
| 383 |
44 |
▶ | if (sv_derived_from(ST(i), MEMVAULT_CLASS)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_derived_from(ST(i), MEMVAULT_CLASS)) { |
0 |
44 |
44 |
|
| 384 |
0 |
| msg_pm = protmem_get(aTHX_ ST(i), MEMVAULT_CLASS); |
| 385 |
0 |
| msg_buf = msg_pm->pm_ptr; |
| 386 |
0 |
| msg_len = msg_pm->size; |
| 387 |
|
| } |
| 388 |
|
| else |
| 389 |
88 |
| msg_buf = (unsigned char *)SvPVbyte(ST(i), msg_len); |
| 390 |
|
| |
| 391 |
44 |
▶ | if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
44 |
44 |
| if (msg_pm && protmem_grant(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
0 |
0 |
|
| 392 |
0 |
| protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW); |
| 393 |
0 |
| croak("update: Failed to grant msg protmem RO"); |
| 394 |
|
| } |
| 395 |
|
| |
| 396 |
44 |
| switch(ix) { |
| 397 |
11 |
| case 1: |
| 398 |
11 |
| crypto_xof_shake128_update(state_pm->pm_ptr, msg_buf, msg_len); |
| 399 |
11 |
| break; |
| 400 |
11 |
| case 2: |
| 401 |
11 |
| crypto_xof_turboshake128_update(state_pm->pm_ptr, msg_buf, msg_len); |
| 402 |
11 |
| break; |
| 403 |
11 |
| case 3: |
| 404 |
11 |
| crypto_xof_turboshake256_update(state_pm->pm_ptr, msg_buf, msg_len); |
| 405 |
11 |
| break; |
| 406 |
11 |
| default: |
| 407 |
11 |
| crypto_xof_shake128_update(state_pm->pm_ptr, msg_buf, msg_len); |
| 408 |
|
| } |
| 409 |
|
| |
| 410 |
44 |
▶ | if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
44 |
44 |
| if (msg_pm && protmem_release(aTHX_ msg_pm, PROTMEM_FLAG_MPROTECT_RO) != 0) { |
0 |
0 |
0 |
|
| 411 |
0 |
| protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW); |
| 412 |
0 |
| croak("update: Failed to release msg protmem RO"); |
| 413 |
|
| } |
| 414 |
|
| |
| 415 |
44 |
| msg_pm = NULL; |
| 416 |
|
| } |
| 417 |
|
| |
| 418 |
20 |
▶ | if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (protmem_release(aTHX_ state_pm, PROTMEM_FLAG_MPROTECT_RW) != 0) |
0 |
20 |
20 |
|
| 419 |
0 |
| croak("update: Failed to release state protmem RW"); |
| 420 |
|
| |
| 421 |
20 |
| XSRETURN(1); |
| 422 |
|
| #else |
| 423 |
|
| croak("XOF not supported by this version of libsodium"); |
| 424 |
|
| #endif |