diff options
| author | Ben Fuhrmannek | 2016-10-12 14:57:47 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2016-10-12 14:57:47 +0200 |
| commit | 1a3fd5eeb9a5859aefedb9302adb6ecd6a1873a7 (patch) | |
| tree | a8925768de344632ec89e051a3c71a3c7c61ffd3 /sha256.c | |
| parent | 2e4fbdbdd8ff3b1d1a0edb579392506ef3ed98e2 (diff) | |
comments and whitespace cleanup
Diffstat (limited to 'sha256.c')
| -rw-r--r-- | sha256.c | 18 |
1 files changed, 8 insertions, 10 deletions
| @@ -17,12 +17,10 @@ | |||
| 17 | +----------------------------------------------------------------------+ | 17 | +----------------------------------------------------------------------+ |
| 18 | */ | 18 | */ |
| 19 | 19 | ||
| 20 | /* $Id: sha256.c $ */ | ||
| 21 | |||
| 22 | #include <stdio.h> | 20 | #include <stdio.h> |
| 23 | #include "php.h" | 21 | #include "php.h" |
| 24 | 22 | ||
| 25 | /* This code is heavily based on the PHP md5/sha1 implementations */ | 23 | /* This code is heavily based on the PHP md5/sha1 implementations */ |
| 26 | 24 | ||
| 27 | #include "sha256.h" | 25 | #include "sha256.h" |
| 28 | 26 | ||
| @@ -48,7 +46,7 @@ static PHP_FUNCTION(suhosin_sha256) | |||
| 48 | char sha256str[65]; | 46 | char sha256str[65]; |
| 49 | suhosin_SHA256_CTX context; | 47 | suhosin_SHA256_CTX context; |
| 50 | unsigned char digest[32]; | 48 | unsigned char digest[32]; |
| 51 | 49 | ||
| 52 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &arg, &arg_len, &raw_output) == FAILURE) { | 50 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|b", &arg, &arg_len, &raw_output) == FAILURE) { |
| 53 | return; | 51 | return; |
| 54 | } | 52 | } |
| @@ -141,7 +139,7 @@ static unsigned char PADDING[64] = | |||
| 141 | */ | 139 | */ |
| 142 | #define W(i) ( tmp1=ROTATE_RIGHT(x[(i-15)&15],7)^ROTATE_RIGHT(x[(i-15)&15],18)^(x[(i-15)&15] >> 3), \ | 140 | #define W(i) ( tmp1=ROTATE_RIGHT(x[(i-15)&15],7)^ROTATE_RIGHT(x[(i-15)&15],18)^(x[(i-15)&15] >> 3), \ |
| 143 | tmp2=ROTATE_RIGHT(x[(i-2)&15],17)^ROTATE_RIGHT(x[(i-2)&15],19)^(x[(i-2)&15] >> 10), \ | 141 | tmp2=ROTATE_RIGHT(x[(i-2)&15],17)^ROTATE_RIGHT(x[(i-2)&15],19)^(x[(i-2)&15] >> 10), \ |
| 144 | (x[i&15]=x[i&15] + tmp1 + x[(i-7)&15] + tmp2) ) | 142 | (x[i&15]=x[i&15] + tmp1 + x[(i-7)&15] + tmp2) ) |
| 145 | 143 | ||
| 146 | /* ROUND function of sha256 | 144 | /* ROUND function of sha256 |
| 147 | */ | 145 | */ |
| @@ -150,8 +148,8 @@ static unsigned char PADDING[64] = | |||
| 150 | t1 = (h) + H((e)) + I((e), (f), (g)) + (k) + (php_uint32)(w); \ | 148 | t1 = (h) + H((e)) + I((e), (f), (g)) + (k) + (php_uint32)(w); \ |
| 151 | (h) = F((a)) + G((a), (b), (c)) + t1; \ | 149 | (h) = F((a)) + G((a), (b), (c)) + t1; \ |
| 152 | (d) += t1; \ | 150 | (d) += t1; \ |
| 153 | } | 151 | } |
| 154 | 152 | ||
| 155 | 153 | ||
| 156 | /* {{{ suhosin_SHA256Init | 154 | /* {{{ suhosin_SHA256Init |
| 157 | * SHA256 initialization. Begins an SHA256 operation, writing a new context. | 155 | * SHA256 initialization. Begins an SHA256 operation, writing a new context. |
| @@ -168,7 +166,7 @@ void suhosin_SHA256Init(suhosin_SHA256_CTX * context) | |||
| 168 | context->state[4] = 0x510e527f; | 166 | context->state[4] = 0x510e527f; |
| 169 | context->state[5] = 0x9b05688c; | 167 | context->state[5] = 0x9b05688c; |
| 170 | context->state[6] = 0x1f83d9ab; | 168 | context->state[6] = 0x1f83d9ab; |
| 171 | context->state[7] = 0x5be0cd19; | 169 | context->state[7] = 0x5be0cd19; |
| 172 | } | 170 | } |
| 173 | /* }}} */ | 171 | /* }}} */ |
| 174 | 172 | ||
| @@ -232,7 +230,7 @@ void suhosin_SHA256Final(unsigned char digest[32], suhosin_SHA256_CTX * context) | |||
| 232 | bits[2] = (context->count[1] >> 8) & 0xFF; | 230 | bits[2] = (context->count[1] >> 8) & 0xFF; |
| 233 | bits[1] = (context->count[1] >> 16) & 0xFF; | 231 | bits[1] = (context->count[1] >> 16) & 0xFF; |
| 234 | bits[0] = (context->count[1] >> 24) & 0xFF; | 232 | bits[0] = (context->count[1] >> 24) & 0xFF; |
| 235 | 233 | ||
| 236 | /* Pad out to 56 mod 64. | 234 | /* Pad out to 56 mod 64. |
| 237 | */ | 235 | */ |
| 238 | index = (unsigned int) ((context->count[0] >> 3) & 0x3f); | 236 | index = (unsigned int) ((context->count[0] >> 3) & 0x3f); |
| @@ -397,7 +395,7 @@ void suhosin_hook_sha256() | |||
| 397 | if (zend_hash_str_find(CG(function_table), ZEND_STRL("sha256"))) { | 395 | if (zend_hash_str_find(CG(function_table), ZEND_STRL("sha256"))) { |
| 398 | return; | 396 | return; |
| 399 | } | 397 | } |
| 400 | 398 | ||
| 401 | /* add the sha256 functions */ | 399 | /* add the sha256 functions */ |
| 402 | zend_register_functions(NULL, suhosin_sha256_functions, NULL, MODULE_PERSISTENT); | 400 | zend_register_functions(NULL, suhosin_sha256_functions, NULL, MODULE_PERSISTENT); |
| 403 | } | 401 | } |
