PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/hash - hash_joaat.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 23 23 100.0 %
Date: 2022-01-29 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 7                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 1997-2018 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Author: Martin Jansen <mj@php.net>                                   |
      16             :   +----------------------------------------------------------------------+
      17             : */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : /* Implements Jenkins's one-at-a-time hashing algorithm as presented on
      22             :  * http://www.burtleburtle.net/bob/hash/doobs.html.
      23             :  */
      24             : 
      25             : #include "php_hash.h"
      26             : #include "php_hash_joaat.h"
      27             : 
      28             : const php_hash_ops php_hash_joaat_ops = {
      29             :         (php_hash_init_func_t) PHP_JOAATInit,
      30             :         (php_hash_update_func_t) PHP_JOAATUpdate,
      31             :         (php_hash_final_func_t) PHP_JOAATFinal,
      32             :         (php_hash_copy_func_t) php_hash_copy,
      33             :         4,
      34             :         4,
      35             :         sizeof(PHP_JOAAT_CTX),
      36             :         0
      37             : };
      38             : 
      39          13 : PHP_HASH_API void PHP_JOAATInit(PHP_JOAAT_CTX *context)
      40             : {
      41          13 :         context->state = 0;
      42          13 : }
      43             : 
      44          11 : PHP_HASH_API void PHP_JOAATUpdate(PHP_JOAAT_CTX *context, const unsigned char *input, unsigned int inputLen)
      45             : {
      46          11 :         context->state = joaat_buf((void *)input, inputLen, context->state);
      47          11 : }
      48             : 
      49          13 : PHP_HASH_API void PHP_JOAATFinal(unsigned char digest[4], PHP_JOAAT_CTX * context)
      50             : {
      51             : #ifdef WORDS_BIGENDIAN
      52             :         memcpy(digest, &context->state, 4);
      53             : #else
      54          13 :         int i = 0;
      55          13 :         unsigned char *c = (unsigned char *) &context->state;
      56             : 
      57          65 :         for (i = 0; i < 4; i++) {
      58          52 :                 digest[i] = c[3 - i];
      59             :         }
      60             : #endif
      61          13 :     context->state = 0;
      62          13 : }
      63             : 
      64             : /*
      65             :  * joaat_buf - perform a Jenkins's one-at-a-time hash on a buffer
      66             :  *
      67             :  * input:
      68             :  *  buf - start of buffer to hash
      69             :  *  len - length of buffer in octets
      70             :  *
      71             :  * returns:
      72             :  *  32 bit hash as a static hash type
      73             :  */
      74             : static uint32_t
      75          11 : joaat_buf(void *buf, size_t len, uint32_t hval)
      76             : {
      77             :     size_t i;
      78          11 :     unsigned char *input = (unsigned char *)buf;
      79             : 
      80         199 :     for (i = 0; i < len; i++) {
      81         188 :         hval += input[i];
      82         188 :         hval += (hval << 10);
      83         188 :         hval ^= (hval >> 6);
      84             :     }
      85             : 
      86          11 :     hval += (hval << 3);
      87          11 :     hval ^= (hval >> 11);
      88          11 :     hval += (hval << 15);
      89             : 
      90          11 :     return hval;
      91             : }
      92             : 
      93             : /*
      94             :  * Local variables:
      95             :  * tab-width: 4
      96             :  * c-basic-offset: 4
      97             :  * End:
      98             :  * vim600: noet sw=4 ts=4 fdm=marker
      99             :  * vim<600: noet sw=4 ts=4
     100             :  */

Generated by: LCOV version 1.10

Generated at Sat, 29 Jan 2022 07:14:32 +0000 (57 minutes ago)

Copyright © 2005-2022 The PHP Group
All rights reserved.