| 1 |
|
| MODULE = CryptX PACKAGE = Crypt::Digest::SHAKE |
| 2 |
|
| |
| 3 |
|
| PROTOTYPES: DISABLE |
| 4 |
|
| |
| 5 |
|
| #define CRYPTX_DIGEST_SHAKE_MAX_OUTPUT_LEN 1000000000UL |
| 6 |
|
| |
| 7 |
|
| Crypt::Digest::SHAKE |
| 8 |
|
| new(Class, int num) |
| 9 |
|
| CODE: |
| 10 |
|
| { |
| 11 |
|
| int rv; |
| 12 |
|
| |
| 13 |
35 |
| Newz(0, RETVAL, 1, struct digest_shake_struct); |
| 14 |
35 |
▶ | if (!RETVAL) croak("FATAL: Newz failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) croak("FATAL: Newz failed"); |
0 |
35 |
35 |
|
| 15 |
|
| |
| 16 |
35 |
| RETVAL->num = num; |
| 17 |
35 |
| RETVAL->squeezing = 0; |
| 18 |
35 |
| rv = sha3_shake_init(&RETVAL->state, RETVAL->num); |
| 19 |
35 |
▶ | if (rv != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { |
0 |
35 |
35 |
|
| 20 |
0 |
| Safefree(RETVAL); |
| 21 |
0 |
| croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv)); |
| 22 |
|
| } |
| 23 |
|
| } |
| 24 |
|
| OUTPUT: |
| 25 |
|
| RETVAL |
| 26 |
|
| |
| 27 |
|
| void |
| 28 |
|
| DESTROY(Crypt::Digest::SHAKE self) |
| 29 |
|
| CODE: |
| 30 |
35 |
| zeromem(self, sizeof(*self)); |
| 31 |
35 |
| Safefree(self); |
| 32 |
|
| |
| 33 |
|
| void |
| 34 |
|
| reset(Crypt::Digest::SHAKE self) |
| 35 |
|
| PPCODE: |
| 36 |
|
| { |
| 37 |
|
| int rv; |
| 38 |
1 |
| rv = sha3_shake_init(&self->state, self->num); |
| 39 |
1 |
▶ | if (rv != CRYPT_OK) croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: sha3_shake_init failed: %s", error_to_string(rv)); |
0 |
1 |
1 |
|
| 40 |
1 |
| self->squeezing = 0; |
| 41 |
1 |
▶ | XPUSHs(ST(0)); /* return self */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(ST(0)); /* return self */ |
0 |
1 |
1 |
|
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
|
| Crypt::Digest::SHAKE |
| 45 |
|
| clone(Crypt::Digest::SHAKE self) |
| 46 |
|
| CODE: |
| 47 |
0 |
| Newz(0, RETVAL, 1, struct digest_shake_struct); |
| 48 |
0 |
▶ | if (!RETVAL) croak("FATAL: Newz failed"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!RETVAL) croak("FATAL: Newz failed"); |
0 |
0 |
0 |
|
| 49 |
0 |
| Copy(self, RETVAL, 1, struct digest_shake_struct); |
| 50 |
|
| OUTPUT: |
| 51 |
|
| RETVAL |
| 52 |
|
| |
| 53 |
|
| void |
| 54 |
|
| add(Crypt::Digest::SHAKE self, ...) |
| 55 |
|
| PPCODE: |
| 56 |
|
| { |
| 57 |
|
| STRLEN inlen; |
| 58 |
|
| int rv, i; |
| 59 |
|
| unsigned char *in; |
| 60 |
|
| |
| 61 |
36 |
▶ | if (self->squeezing) croak("FATAL: cannot add after done; call reset first"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (self->squeezing) croak("FATAL: cannot add after done; call reset first"); |
1 |
35 |
36 |
|
| 62 |
|
| |
| 63 |
70 |
▶ | for(i=1; i<items; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1; i<items; i++) { |
35 |
35 |
70 |
|
| 64 |
35 |
| in = (unsigned char *)SvPVbyte(ST(i), inlen); |
| 65 |
35 |
▶ | if (inlen>0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (inlen>0) { |
33 |
2 |
35 |
|
| 66 |
33 |
| rv = sha3_shake_process(&self->state, in, (unsigned long)inlen); |
| 67 |
33 |
▶ | if (rv != CRYPT_OK) croak("FATAL: sha3_shake_process failed: %s", error_to_string(rv)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) croak("FATAL: sha3_shake_process failed: %s", error_to_string(rv)); |
0 |
33 |
33 |
|
| 68 |
|
| } |
| 69 |
|
| } |
| 70 |
35 |
▶ | XPUSHs(ST(0)); /* return self */ |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(ST(0)); /* return self */ |
0 |
35 |
35 |
|
| 71 |
|
| } |
| 72 |
|
| |
| 73 |
|
| SV * |
| 74 |
|
| done(Crypt::Digest::SHAKE self, unsigned long out_len) |
| 75 |
|
| CODE: |
| 76 |
|
| { |
| 77 |
|
| int rv; |
| 78 |
|
| unsigned char *out_data; |
| 79 |
|
| |
| 80 |
38 |
▶ | if (out_len == 0) croak("FATAL: invalid output length"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_len == 0) croak("FATAL: invalid output length"); |
1 |
37 |
38 |
|
| 81 |
37 |
▶ | if (out_len > CRYPTX_DIGEST_SHAKE_MAX_OUTPUT_LEN) croak("FATAL: output length too large"); |
Branch: 1 branch
| Branch | True | False | Total |
| if (out_len > CRYPTX_DIGEST_SHAKE_MAX_OUTPUT_LEN) croak("FATAL: output length too large"); |
3 |
34 |
37 |
|
| 82 |
34 |
| RETVAL = NEWSV(0, out_len); /* avoid zero! */ |
| 83 |
34 |
| SvPOK_only(RETVAL); |
| 84 |
34 |
| SvCUR_set(RETVAL, out_len); |
| 85 |
34 |
| *SvEND(RETVAL) = '\0'; |
| 86 |
34 |
| out_data = (unsigned char *)SvPVX(RETVAL); |
| 87 |
34 |
| rv = sha3_shake_done(&self->state, out_data, out_len); |
| 88 |
34 |
▶ | if (rv != CRYPT_OK) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv != CRYPT_OK) { |
0 |
34 |
34 |
|
| 89 |
0 |
| SvREFCNT_dec(RETVAL); |
| 90 |
0 |
| croak("FATAL: sha3_shake_done failed: %s", error_to_string(rv)); |
| 91 |
|
| } |
| 92 |
34 |
| self->squeezing = 1; |
| 93 |
|
| } |
| 94 |
|
| OUTPUT: |
| 95 |
|
| RETVAL |