diff options
author | Karel Miko <karel.miko@gmail.com> | 2023-10-02 09:43:13 +0200 |
---|---|---|
committer | Karel Miko <karel.miko@gmail.com> | 2023-10-02 09:43:13 +0200 |
commit | 0565d535b21a14bbf9fe5613df5a8394b6579cd5 (patch) | |
tree | d3030d53656008a860a3f39f5a626299488ee658 | |
parent | 461b19e3296f7f8182760533068a99b7239400fd (diff) |
fix AES-NI troubles on MS Windows (gcc compiler)
-rw-r--r-- | CryptX.xs | 8 | ||||
-rw-r--r-- | _generators/Mac.xs.inc.tt | 18 | ||||
-rw-r--r-- | _generators/Mode.xs.inc.tt | 8 | ||||
-rw-r--r-- | _generators/Mode_p.xs.inc.tt | 8 | ||||
-rw-r--r-- | inc/CryptX_AuthEnc_CCM.xs.inc | 16 | ||||
-rw-r--r-- | inc/CryptX_AuthEnc_EAX.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_AuthEnc_GCM.xs.inc | 14 | ||||
-rw-r--r-- | inc/CryptX_AuthEnc_OCB.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Cipher.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_Mac_BLAKE2b.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_BLAKE2s.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_F9.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_HMAC.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_OMAC.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_PMAC.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_Pelican.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_Poly1305.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mac_XCBC.xs.inc | 12 | ||||
-rw-r--r-- | inc/CryptX_Mode_CBC.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_Mode_CFB.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_Mode_CTR.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_Mode_ECB.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_Mode_OFB.xs.inc | 8 | ||||
-rw-r--r-- | inc/CryptX_PRNG.xs.inc | 18 |
24 files changed, 139 insertions, 131 deletions
@@ -22,6 +22,14 @@ #include "tomcrypt.h" #include "tommath.h" +#if defined(_WIN32) +# define AlignedNewx(v,n,t,a) (v = _aligned_malloc((MEM_SIZE)((n)*sizeof(t)),a)) +# define AlignedSafefree(v) _aligned_free(v) +#else +# define AlignedNewx(v,n,t,a) Newx(v,n,t) +# define AlignedSafefree(v) Safefree(v) +#endif + typedef adler32_state *Crypt__Checksum__Adler32; typedef crc32_state *Crypt__Checksum__CRC32; diff --git a/_generators/Mac.xs.inc.tt b/_generators/Mac.xs.inc.tt index 8562a5f3..7fe7619a 100644 --- a/_generators/Mac.xs.inc.tt +++ b/_generators/Mac.xs.inc.tt @@ -37,11 +37,11 @@ new(Class, char * cipher_name, SV * key) k = (unsigned char *) SvPVbyte(key, k_len); [%-IF lc_name == 'blake2s' || lc_name == 'blake2b' %] - Newz(0, RETVAL, 1, [%lc_name%]mac_state); + AlignedNewx(RETVAL, 1, [%lc_name%]mac_state, 16); [%-ELSE%] - Newz(0, RETVAL, 1, [%lc_name%]_state); + AlignedNewx(RETVAL, 1, [%lc_name%]_state, 16); [%-END%] - if (!RETVAL) croak("FATAL: Newz failed"); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); [%-IF lc_name == 'pelican' || lc_name == 'poly1305' %] rv = [%lc_name%]_init(RETVAL, k, (unsigned long)k_len); @@ -51,7 +51,7 @@ new(Class, char * cipher_name, SV * key) rv = [%lc_name%]_init(RETVAL, id, k, (unsigned long)k_len); [%-END%] if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: [%lc_name%]_init failed: %s", error_to_string(rv)); } } @@ -61,18 +61,18 @@ new(Class, char * cipher_name, SV * key) void DESTROY(Crypt::Mac::[%orig_name%] self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::[%orig_name%] clone(Crypt::Mac::[%orig_name%] self) CODE: [%-IF lc_name == 'blake2s' || lc_name == 'blake2b' %] - Newz(0, RETVAL, 1, [%lc_name%]mac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, [%lc_name%]mac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, [%lc_name%]mac_state); [%-ELSE%] - Newz(0, RETVAL, 1, [%lc_name%]_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, [%lc_name%]_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, [%lc_name%]_state); [%-END%] OUTPUT: diff --git a/_generators/Mode.xs.inc.tt b/_generators/Mode.xs.inc.tt index 1e18b8b2..b24807a9 100644 --- a/_generators/Mode.xs.inc.tt +++ b/_generators/Mode.xs.inc.tt @@ -12,13 +12,13 @@ new(Class, char * cipher_name, int rounds=0) [%-END%] CODE: { - Newz(0, RETVAL, 1, struct [%lc_name%]_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct [%lc_name%]_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } [%-IF lc_name == 'ctr' %] @@ -35,7 +35,7 @@ new(Class, char * cipher_name, int rounds=0) void DESTROY(Crypt::Mode::[%orig_name%] self) CODE: - Safefree(self); + AlignedSafefree(self); void [%-IF lc_name == 'xts' %] diff --git a/_generators/Mode_p.xs.inc.tt b/_generators/Mode_p.xs.inc.tt index e22d2f10..c5f08a11 100644 --- a/_generators/Mode_p.xs.inc.tt +++ b/_generators/Mode_p.xs.inc.tt @@ -8,15 +8,15 @@ Crypt::Mode::[%orig_name%] new(Class, char * cipher_name, int padding=1, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct [%lc_name%]_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct [%lc_name%]_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->padding_mode = padding; RETVAL->padlen = 0; RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } } @@ -26,7 +26,7 @@ new(Class, char * cipher_name, int padding=1, int rounds=0) void DESTROY(Crypt::Mode::[%orig_name%] self) CODE: - Safefree(self); + AlignedSafefree(self); void [%-IF lc_name == 'cbc' %] diff --git a/inc/CryptX_AuthEnc_CCM.xs.inc b/inc/CryptX_AuthEnc_CCM.xs.inc index 84a3e9cf..be67bf93 100644 --- a/inc/CryptX_AuthEnc_CCM.xs.inc +++ b/inc/CryptX_AuthEnc_CCM.xs.inc @@ -26,22 +26,22 @@ new(Class, char * cipher_name, SV * key, SV * nonce, SV * adata, int tag_len, in id = cryptx_internal_find_cipher(cipher_name); if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name); - Newz(0, RETVAL, 1, ccm_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, ccm_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = ccm_init(RETVAL, id, k, (int)k_len, (int)pt_len, (int)tag_len, (int)h_len); /* XXX-TODO why int? */ if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: ccm_init failed: %s", error_to_string(rv)); } rv = ccm_add_nonce(RETVAL, n, (unsigned long)n_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: ccm_add_nonce failed: %s", error_to_string(rv)); } rv = ccm_add_aad(RETVAL, h, (unsigned long)h_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: ccm_add_aad failed: %s", error_to_string(rv)); } } @@ -51,13 +51,13 @@ new(Class, char * cipher_name, SV * key, SV * nonce, SV * adata, int tag_len, in void DESTROY(Crypt::AuthEnc::CCM self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::AuthEnc::CCM clone(Crypt::AuthEnc::CCM self) CODE: - Newz(0, RETVAL, 1, ccm_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, ccm_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, ccm_state); OUTPUT: RETVAL diff --git a/inc/CryptX_AuthEnc_EAX.xs.inc b/inc/CryptX_AuthEnc_EAX.xs.inc index 01fae988..6c66bf11 100644 --- a/inc/CryptX_AuthEnc_EAX.xs.inc +++ b/inc/CryptX_AuthEnc_EAX.xs.inc @@ -26,12 +26,12 @@ new(Class, char * cipher_name, SV * key, SV * nonce, SV * adata=&PL_sv_undef) id = cryptx_internal_find_cipher(cipher_name); if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name); - Newz(0, RETVAL, 1, eax_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, eax_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = eax_init(RETVAL, id, k, (unsigned long)k_len, n, (unsigned long)n_len, h, (unsigned long)h_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: eax setup failed: %s", error_to_string(rv)); } } @@ -41,13 +41,13 @@ new(Class, char * cipher_name, SV * key, SV * nonce, SV * adata=&PL_sv_undef) void DESTROY(Crypt::AuthEnc::EAX self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::AuthEnc::EAX clone(Crypt::AuthEnc::EAX self) CODE: - Newz(0, RETVAL, 1, eax_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, eax_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, eax_state); OUTPUT: RETVAL diff --git a/inc/CryptX_AuthEnc_GCM.xs.inc b/inc/CryptX_AuthEnc_GCM.xs.inc index a1c419be..e0472dca 100644 --- a/inc/CryptX_AuthEnc_GCM.xs.inc +++ b/inc/CryptX_AuthEnc_GCM.xs.inc @@ -20,19 +20,19 @@ new(Class, char * cipher_name, SV * key, SV * nonce = NULL) id = cryptx_internal_find_cipher(cipher_name); if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name); - Newz(0, RETVAL, 1, gcm_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, gcm_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = gcm_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: gcm_init failed: %s", error_to_string(rv)); } if (iv && iv_len > 0) { rv = gcm_add_iv(RETVAL, iv, (unsigned long)iv_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: gcm_add_iv failed: %s", error_to_string(rv)); } } @@ -43,13 +43,13 @@ new(Class, char * cipher_name, SV * key, SV * nonce = NULL) void DESTROY(Crypt::AuthEnc::GCM self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::AuthEnc::GCM clone(Crypt::AuthEnc::GCM self) CODE: - Newz(0, RETVAL, 1, gcm_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, gcm_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, gcm_state); OUTPUT: RETVAL diff --git a/inc/CryptX_AuthEnc_OCB.xs.inc b/inc/CryptX_AuthEnc_OCB.xs.inc index d318d78b..baec3b4f 100644 --- a/inc/CryptX_AuthEnc_OCB.xs.inc +++ b/inc/CryptX_AuthEnc_OCB.xs.inc @@ -20,12 +20,12 @@ new(Class, char * cipher_name, SV * key, SV * nonce, unsigned long taglen) id = cryptx_internal_find_cipher(cipher_name); if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name); - Newz(0, RETVAL, 1, ocb3_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, ocb3_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = ocb3_init(RETVAL, id, k, (unsigned long)k_len, n, (unsigned long)n_len, taglen); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: ocb setup failed: %s", error_to_string(rv)); } } @@ -35,13 +35,13 @@ new(Class, char * cipher_name, SV * key, SV * nonce, unsigned long taglen) void DESTROY(Crypt::AuthEnc::OCB self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::AuthEnc::OCB clone(Crypt::AuthEnc::OCB self) CODE: - Newz(0, RETVAL, 1, ocb3_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, ocb3_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, ocb3_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Cipher.xs.inc b/inc/CryptX_Cipher.xs.inc index 103ac690..7330f31d 100644 --- a/inc/CryptX_Cipher.xs.inc +++ b/inc/CryptX_Cipher.xs.inc @@ -28,13 +28,13 @@ new(char * class, ...) id = cryptx_internal_find_cipher(cipher_name); if (id == -1) croak("FATAL: find_cipfer failed for '%s'", cipher_name); - Newz(0, RETVAL, 1, struct cipher_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct cipher_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->desc = &cipher_descriptor[id]; rv = RETVAL->desc->setup(key_data, (int)key_len, rounds, &RETVAL->skey); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: cipher setup failed: %s", error_to_string(rv)); } } @@ -44,7 +44,7 @@ new(char * class, ...) void DESTROY(Crypt::Cipher self) CODE: - Safefree(self); + AlignedSafefree(self); SV * encrypt(Crypt::Cipher self, SV * data) diff --git a/inc/CryptX_Mac_BLAKE2b.xs.inc b/inc/CryptX_Mac_BLAKE2b.xs.inc index b8093294..ed2cb061 100644 --- a/inc/CryptX_Mac_BLAKE2b.xs.inc +++ b/inc/CryptX_Mac_BLAKE2b.xs.inc @@ -15,12 +15,12 @@ new(Class, unsigned long size, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, blake2bmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, blake2bmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = blake2bmac_init(RETVAL, size, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: blake2b_init failed: %s", error_to_string(rv)); } } @@ -30,13 +30,13 @@ new(Class, unsigned long size, SV * key) void DESTROY(Crypt::Mac::BLAKE2b self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::BLAKE2b clone(Crypt::Mac::BLAKE2b self) CODE: - Newz(0, RETVAL, 1, blake2bmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, blake2bmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, blake2bmac_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_BLAKE2s.xs.inc b/inc/CryptX_Mac_BLAKE2s.xs.inc index a3d42b74..a205999c 100644 --- a/inc/CryptX_Mac_BLAKE2s.xs.inc +++ b/inc/CryptX_Mac_BLAKE2s.xs.inc @@ -15,12 +15,12 @@ new(Class, unsigned long size, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, blake2smac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, blake2smac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = blake2smac_init(RETVAL, size, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: blake2s_init failed: %s", error_to_string(rv)); } } @@ -30,13 +30,13 @@ new(Class, unsigned long size, SV * key) void DESTROY(Crypt::Mac::BLAKE2s self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::BLAKE2s clone(Crypt::Mac::BLAKE2s self) CODE: - Newz(0, RETVAL, 1, blake2smac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, blake2smac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, blake2smac_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_F9.xs.inc b/inc/CryptX_Mac_F9.xs.inc index eb70e10c..c0c5ebbf 100644 --- a/inc/CryptX_Mac_F9.xs.inc +++ b/inc/CryptX_Mac_F9.xs.inc @@ -19,12 +19,12 @@ new(Class, char * cipher_name, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, f9_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, f9_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = f9_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: f9_init failed: %s", error_to_string(rv)); } } @@ -34,13 +34,13 @@ new(Class, char * cipher_name, SV * key) void DESTROY(Crypt::Mac::F9 self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::F9 clone(Crypt::Mac::F9 self) CODE: - Newz(0, RETVAL, 1, f9_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, f9_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, f9_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_HMAC.xs.inc b/inc/CryptX_Mac_HMAC.xs.inc index b87b1267..6f67be07 100644 --- a/inc/CryptX_Mac_HMAC.xs.inc +++ b/inc/CryptX_Mac_HMAC.xs.inc @@ -19,12 +19,12 @@ new(Class, char * hash_name, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, hmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, hmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = hmac_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: hmac_init failed: %s", error_to_string(rv)); } } @@ -34,13 +34,13 @@ new(Class, char * hash_name, SV * key) void DESTROY(Crypt::Mac::HMAC self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::HMAC clone(Crypt::Mac::HMAC self) CODE: - Newz(0, RETVAL, 1, hmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, hmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, hmac_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_OMAC.xs.inc b/inc/CryptX_Mac_OMAC.xs.inc index 7ac72cce..1eeb3b54 100644 --- a/inc/CryptX_Mac_OMAC.xs.inc +++ b/inc/CryptX_Mac_OMAC.xs.inc @@ -19,12 +19,12 @@ new(Class, char * cipher_name, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, omac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, omac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = omac_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: omac_init failed: %s", error_to_string(rv)); } } @@ -34,13 +34,13 @@ new(Class, char * cipher_name, SV * key) void DESTROY(Crypt::Mac::OMAC self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::OMAC clone(Crypt::Mac::OMAC self) CODE: - Newz(0, RETVAL, 1, omac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, omac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, omac_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_PMAC.xs.inc b/inc/CryptX_Mac_PMAC.xs.inc index b924479f..04807d80 100644 --- a/inc/CryptX_Mac_PMAC.xs.inc +++ b/inc/CryptX_Mac_PMAC.xs.inc @@ -19,12 +19,12 @@ new(Class, char * cipher_name, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, pmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, pmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = pmac_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: pmac_init failed: %s", error_to_string(rv)); } } @@ -34,13 +34,13 @@ new(Class, char * cipher_name, SV * key) void DESTROY(Crypt::Mac::PMAC self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::PMAC clone(Crypt::Mac::PMAC self) CODE: - Newz(0, RETVAL, 1, pmac_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, pmac_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, pmac_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_Pelican.xs.inc b/inc/CryptX_Mac_Pelican.xs.inc index 7bb0943d..05d825d5 100644 --- a/inc/CryptX_Mac_Pelican.xs.inc +++ b/inc/CryptX_Mac_Pelican.xs.inc @@ -15,12 +15,12 @@ new(Class, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, pelican_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, pelican_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = pelican_init(RETVAL, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: pelican_init failed: %s", error_to_string(rv)); } } @@ -30,13 +30,13 @@ new(Class, SV * key) void DESTROY(Crypt::Mac::Pelican self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::Pelican clone(Crypt::Mac::Pelican self) CODE: - Newz(0, RETVAL, 1, pelican_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, pelican_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, pelican_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_Poly1305.xs.inc b/inc/CryptX_Mac_Poly1305.xs.inc index 79e5e4ae..74456675 100644 --- a/inc/CryptX_Mac_Poly1305.xs.inc +++ b/inc/CryptX_Mac_Poly1305.xs.inc @@ -15,12 +15,12 @@ new(Class, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, poly1305_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, poly1305_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = poly1305_init(RETVAL, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: poly1305_init failed: %s", error_to_string(rv)); } } @@ -30,13 +30,13 @@ new(Class, SV * key) void DESTROY(Crypt::Mac::Poly1305 self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::Poly1305 clone(Crypt::Mac::Poly1305 self) CODE: - Newz(0, RETVAL, 1, poly1305_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, poly1305_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, poly1305_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mac_XCBC.xs.inc b/inc/CryptX_Mac_XCBC.xs.inc index 98131ced..1a898321 100644 --- a/inc/CryptX_Mac_XCBC.xs.inc +++ b/inc/CryptX_Mac_XCBC.xs.inc @@ -19,12 +19,12 @@ new(Class, char * cipher_name, SV * key) if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar"); k = (unsigned char *) SvPVbyte(key, k_len); - Newz(0, RETVAL, 1, xcbc_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, xcbc_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); rv = xcbc_init(RETVAL, id, k, (unsigned long)k_len); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: xcbc_init failed: %s", error_to_string(rv)); } } @@ -34,13 +34,13 @@ new(Class, char * cipher_name, SV * key) void DESTROY(Crypt::Mac::XCBC self) CODE: - Safefree(self); + AlignedSafefree(self); Crypt::Mac::XCBC clone(Crypt::Mac::XCBC self) CODE: - Newz(0, RETVAL, 1, xcbc_state); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, xcbc_state, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); Copy(self, RETVAL, 1, xcbc_state); OUTPUT: RETVAL diff --git a/inc/CryptX_Mode_CBC.xs.inc b/inc/CryptX_Mode_CBC.xs.inc index 301cd5e3..b323e571 100644 --- a/inc/CryptX_Mode_CBC.xs.inc +++ b/inc/CryptX_Mode_CBC.xs.inc @@ -8,15 +8,15 @@ Crypt::Mode::CBC new(Class, char * cipher_name, int padding=1, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct cbc_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct cbc_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->padding_mode = padding; RETVAL->padlen = 0; RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } } @@ -26,7 +26,7 @@ new(Class, char * cipher_name, int padding=1, int rounds=0) void DESTROY(Crypt::Mode::CBC self) CODE: - Safefree(self); + AlignedSafefree(self); void start_decrypt(Crypt::Mode::CBC self, SV * key, SV * iv) diff --git a/inc/CryptX_Mode_CFB.xs.inc b/inc/CryptX_Mode_CFB.xs.inc index 840a679e..b2681270 100644 --- a/inc/CryptX_Mode_CFB.xs.inc +++ b/inc/CryptX_Mode_CFB.xs.inc @@ -8,13 +8,13 @@ Crypt::Mode::CFB new(Class, char * cipher_name, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct cfb_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct cfb_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } } @@ -24,7 +24,7 @@ new(Class, char * cipher_name, int rounds=0) void DESTROY(Crypt::Mode::CFB self) CODE: - Safefree(self); + AlignedSafefree(self); void start_decrypt(Crypt::Mode::CFB self, SV * key, SV * iv) diff --git a/inc/CryptX_Mode_CTR.xs.inc b/inc/CryptX_Mode_CTR.xs.inc index 97804936..ea471f4e 100644 --- a/inc/CryptX_Mode_CTR.xs.inc +++ b/inc/CryptX_Mode_CTR.xs.inc @@ -8,13 +8,13 @@ Crypt::Mode::CTR new(Class, char * cipher_name, int ctr_mode=0, int ctr_width=0, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct ctr_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct ctr_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } if (ctr_mode == 0) RETVAL->ctr_mode_param = CTR_COUNTER_LITTLE_ENDIAN; @@ -29,7 +29,7 @@ new(Class, char * cipher_name, int ctr_mode=0, int ctr_width=0, int rounds=0) void DESTROY(Crypt::Mode::CTR self) CODE: - Safefree(self); + AlignedSafefree(self); void start_decrypt(Crypt::Mode::CTR self, SV * key, SV * iv) diff --git a/inc/CryptX_Mode_ECB.xs.inc b/inc/CryptX_Mode_ECB.xs.inc index 7ad32e2f..f60eb9f3 100644 --- a/inc/CryptX_Mode_ECB.xs.inc +++ b/inc/CryptX_Mode_ECB.xs.inc @@ -8,15 +8,15 @@ Crypt::Mode::ECB new(Class, char * cipher_name, int padding=1, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct ecb_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct ecb_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->padding_mode = padding; RETVAL->padlen = 0; RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } } @@ -26,7 +26,7 @@ new(Class, char * cipher_name, int padding=1, int rounds=0) void DESTROY(Crypt::Mode::ECB self) CODE: - Safefree(self); + AlignedSafefree(self); void start_decrypt(Crypt::Mode::ECB self, SV * key) diff --git a/inc/CryptX_Mode_OFB.xs.inc b/inc/CryptX_Mode_OFB.xs.inc index 21ea53b3..de972303 100644 --- a/inc/CryptX_Mode_OFB.xs.inc +++ b/inc/CryptX_Mode_OFB.xs.inc @@ -8,13 +8,13 @@ Crypt::Mode::OFB new(Class, char * cipher_name, int rounds=0) CODE: { - Newz(0, RETVAL, 1, struct ofb_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct ofb_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); RETVAL->direction = 0; RETVAL->cipher_rounds = rounds; RETVAL->cipher_id = cryptx_internal_find_cipher(cipher_name); if (RETVAL->cipher_id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_cipfer failed for '%s'", cipher_name); } } @@ -24,7 +24,7 @@ new(Class, char * cipher_name, int rounds=0) void DESTROY(Crypt::Mode::OFB self) CODE: - Safefree(self); + AlignedSafefree(self); void start_decrypt(Crypt::Mode::OFB self, SV * key, SV * iv) diff --git a/inc/CryptX_PRNG.xs.inc b/inc/CryptX_PRNG.xs.inc index aa6e536e..d3e2f0ae 100644 --- a/inc/CryptX_PRNG.xs.inc +++ b/inc/CryptX_PRNG.xs.inc @@ -22,12 +22,12 @@ new(char * class, ...) if (idx + 1 <= items) prng_name = SvPVX(ST(idx)); if (idx + 2 <= items) entropy = ST(idx + 1); - Newz(0, RETVAL, 1, struct prng_struct); - if (!RETVAL) croak("FATAL: Newz failed"); + AlignedNewx(RETVAL, 1, struct prng_struct, 16); + if (!RETVAL) croak("FATAL: AlignedNewx failed"); id = cryptx_internal_find_prng(prng_name); if (id == -1) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: find_prng failed for '%s'", prng_name); } RETVAL->last_pid = curpid; @@ -35,7 +35,7 @@ new(char * class, ...) rv = RETVAL->desc->start(&RETVAL->state); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: PRNG_start failed: %s", error_to_string(rv)); } @@ -43,24 +43,24 @@ new(char * class, ...) ent = (unsigned char *) SvPVbyte(entropy, ent_len); rv = RETVAL->desc->add_entropy(ent, (unsigned long)ent_len, &RETVAL->state); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); } } else { if (rng_get_bytes(entropy_buf, 40, NULL) != 40) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: rng_get_bytes failed: %s", error_to_string(rv)); } rv = RETVAL->desc->add_entropy(entropy_buf, 40, &RETVAL->state); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: PRNG_add_entropy failed: %s", error_to_string(rv)); } } rv = RETVAL->desc->ready(&RETVAL->state); if (rv != CRYPT_OK) { - Safefree(RETVAL); + AlignedSafefree(RETVAL); croak("FATAL: PRNG_ready failed: %s", error_to_string(rv)); } } @@ -70,7 +70,7 @@ new(char * class, ...) void DESTROY(Crypt::PRNG self) CODE: - Safefree(self); + AlignedSafefree(self); void add_entropy(Crypt::PRNG self, SV * entropy=&PL_sv_undef) |