|
7 | 7 |
|
8 | 8 | #include <errno.h> |
9 | 9 | #include <limits.h> |
10 | | -#ifdef PHP_WIN32 |
11 | | -# define __alignof__ __alignof |
12 | | -#else |
13 | | -# ifndef HAVE_ALIGNOF |
14 | | -# include <stddef.h> |
15 | | -# define __alignof__(type) offsetof (struct { char c; type member;}, member) |
16 | | -# endif |
17 | | -#endif |
18 | 10 |
|
19 | 11 | #include <stdio.h> |
20 | 12 | #include <stdlib.h> |
| 13 | +#include <stdalign.h> |
21 | 14 |
|
22 | 15 | #ifdef PHP_WIN32 |
23 | 16 | # include <string.h> |
@@ -294,14 +287,7 @@ sha512_process_bytes(const void *buffer, size_t len, struct sha512_ctx *ctx) { |
294 | 287 | /* Process available complete blocks. */ |
295 | 288 | if (len >= 128) { |
296 | 289 | #ifndef _STRING_ARCH_unaligned |
297 | | -/* To check alignment gcc has an appropriate operator. Other |
298 | | - compilers don't. */ |
299 | | -# if __GNUC__ >= 2 |
300 | | -# define UNALIGNED_P(p) (((uintptr_t) p) % __alignof__ (uint64_t) != 0) |
301 | | -# else |
302 | | -# define UNALIGNED_P(p) (((uintptr_t) p) % sizeof(uint64_t) != 0) |
303 | | -# endif |
304 | | - if (UNALIGNED_P(buffer)) |
| 290 | + if ((uintptr_t)buffer % alignof(uint64_t) != 0) |
305 | 291 | while (len > 128) { |
306 | 292 | sha512_process_block(memcpy(ctx->buffer, buffer, 128), 128, ctx); |
307 | 293 | buffer = (const char *) buffer + 128; |
@@ -355,13 +341,8 @@ static const char b64t[64] ZEND_NONSTRING = |
355 | 341 |
|
356 | 342 | char * |
357 | 343 | php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) { |
358 | | -#ifdef PHP_WIN32 |
359 | | - ZEND_SET_ALIGNED(64, unsigned char alt_result[64]); |
360 | | - ZEND_SET_ALIGNED(64, unsigned char temp_result[64]); |
361 | | -#else |
362 | | - ZEND_SET_ALIGNED(__alignof__ (uint64_t), unsigned char alt_result[64]); |
363 | | - ZEND_SET_ALIGNED(__alignof__ (uint64_t), unsigned char temp_result[64]); |
364 | | -#endif |
| 344 | + ZEND_SET_ALIGNED(alignof(uint64_t), unsigned char alt_result[64]); |
| 345 | + ZEND_SET_ALIGNED(alignof(uint64_t), unsigned char temp_result[64]); |
365 | 346 | struct sha512_ctx ctx; |
366 | 347 | struct sha512_ctx alt_ctx; |
367 | 348 | size_t salt_len; |
@@ -409,15 +390,15 @@ php_sha512_crypt_r(const char *key, const char *salt, char *buffer, int buflen) |
409 | 390 | SET_ALLOCA_FLAG(use_heap_key); |
410 | 391 | SET_ALLOCA_FLAG(use_heap_salt); |
411 | 392 |
|
412 | | - if ((uintptr_t)key % __alignof__ (uint64_t) != 0) { |
413 | | - tmp_key = (char *) do_alloca(key_len + __alignof__ (uint64_t), use_heap_key); |
| 393 | + if ((uintptr_t)key % alignof(uint64_t) != 0) { |
| 394 | + tmp_key = (char *) do_alloca(key_len + alignof(uint64_t), use_heap_key); |
414 | 395 | key = copied_key = |
415 | | - memcpy(tmp_key + __alignof__(uint64_t) - (uintptr_t)tmp_key % __alignof__(uint64_t), key, key_len); |
| 396 | + memcpy(tmp_key + alignof(uint64_t) - (uintptr_t)tmp_key % alignof(uint64_t), key, key_len); |
416 | 397 | } |
417 | 398 |
|
418 | | - if ((uintptr_t)salt % __alignof__ (uint64_t) != 0) { |
419 | | - tmp_salt = (char *) do_alloca(salt_len + 1 + __alignof__(uint64_t), use_heap_salt); |
420 | | - salt = copied_salt = memcpy(tmp_salt + __alignof__(uint64_t) - (uintptr_t)tmp_salt % __alignof__(uint64_t), salt, salt_len); |
| 399 | + if ((uintptr_t)salt % alignof(uint64_t) != 0) { |
| 400 | + tmp_salt = (char *) do_alloca(salt_len + 1 + alignof(uint64_t), use_heap_salt); |
| 401 | + salt = copied_salt = memcpy(tmp_salt + alignof(uint64_t) - (uintptr_t)tmp_salt % alignof(uint64_t), salt, salt_len); |
421 | 402 | copied_salt[salt_len] = 0; |
422 | 403 | } |
423 | 404 |
|
|
0 commit comments