Coverage report for dbus/dbus-sha.c.gcov

        -:    0:Source:dbus-sha.c
        -:    0:Graph:.libs/dbus-sha.gcno
        -:    0:Data:.libs/dbus-sha.gcda
        -:    0:Runs:11811
        -:    0:Programs:5
        -:    1:/* -*- mode: C; c-file-style: "gnu" -*- */
        -:    2:/* dbus-sha.c SHA-1 implementation
        -:    3: *
        -:    4: * Copyright (C) 2003 Red Hat Inc.
        -:    5: * Copyright (C) 1995 A. M. Kuchling
        -:    6: *
        -:    7: * Licensed under the Academic Free License version 2.1
        -:    8: *
        -:    9: * This program is free software; you can redistribute it and/or modify
        -:   10: * it under the terms of the GNU General Public License as published by
        -:   11: * the Free Software Foundation; either version 2 of the License, or
        -:   12: * (at your option) any later version.
        -:   13: *
        -:   14: * This program is distributed in the hope that it will be useful,
        -:   15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   17: * GNU General Public License for more details.
        -:   18: *
        -:   19: * You should have received a copy of the GNU General Public License
        -:   20: * along with this program; if not, write to the Free Software
        -:   21: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        -:   22: *
        -:   23: */
        -:   24:
        -:   25:#include "dbus-internals.h"
        -:   26:#include "dbus-sha.h"
        -:   27:#include "dbus-marshal-basic.h" /* for byteswap routines */
        -:   28:#include <string.h>
        -:   29:
        -:   30:/* The following comments have the history of where this code
        -:   31: * comes from. I actually copied it from GNet in GNOME CVS.
        -:   32: * - hp@redhat.com
        -:   33: */
        -:   34:
        -:   35:/*
        -:   36: *  sha.h : Implementation of the Secure Hash Algorithm
        -:   37: *
        -:   38: * Part of the Python Cryptography Toolkit, version 1.0.0
        -:   39: *
        -:   40: * Copyright (C) 1995, A.M. Kuchling
        -:   41: *
        -:   42: * Distribute and use freely; there are no restrictions on further
        -:   43: * dissemination and usage except those imposed by the laws of your
        -:   44: * country of residence.
        -:   45: *
        -:   46: */
        -:   47:
        -:   48:/* SHA: NIST's Secure Hash Algorithm */
        -:   49:
        -:   50:/* Based on SHA code originally posted to sci.crypt by Peter Gutmann
        -:   51:   in message <30ajo5$oe8@ccu2.auckland.ac.nz>.
        -:   52:   Modified to test for endianness on creation of SHA objects by AMK.
        -:   53:   Also, the original specification of SHA was found to have a weakness
        -:   54:   by NSA/NIST.  This code implements the fixed version of SHA.
        -:   55:*/
        -:   56:
        -:   57:/* Here's the first paragraph of Peter Gutmann's posting:
        -:   58:
        -:   59:The following is my SHA (FIPS 180) code updated to allow use of the "fixed"
        -:   60:SHA, thanks to Jim Gillogly and an anonymous contributor for the information on
        -:   61:what's changed in the new version.  The fix is a simple change which involves
        -:   62:adding a single rotate in the initial expansion function.  It is unknown
        -:   63:whether this is an optimal solution to the problem which was discovered in the
        -:   64:SHA or whether it's simply a bandaid which fixes the problem with a minimum of
        -:   65:effort (for example the reengineering of a great many Capstone chips).
        -:   66:*/
        -:   67:
        -:   68:/**
        -:   69: * @defgroup DBusSHA SHA implementation
        -:   70: * @ingroup  DBusInternals
        -:   71: * @brief SHA-1 hash
        -:   72: *
        -:   73: * Types and functions related to computing SHA-1 hash.
        -:   74: */
        -:   75:
        -:   76:/**
        -:   77: * @defgroup DBusSHAInternals SHA implementation details
        -:   78: * @ingroup  DBusInternals
        -:   79: * @brief Internals of SHA implementation.
        -:   80: *
        -:   81: * The implementation of SHA-1 (see http://www.itl.nist.gov/fipspubs/fip180-1.htm).
        -:   82: * This SHA implementation was written by A.M. Kuchling
        -:   83: *
        -:   84: * @{
        -:   85: */
        -:   86:
        -:   87:#ifndef DOXYGEN_SHOULD_SKIP_THIS
        -:   88:
        -:   89:/* The SHA block size and message digest sizes, in bytes */
        -:   90:
        -:   91:#define SHA_DATASIZE    64
        -:   92:#define SHA_DIGESTSIZE  20
        -:   93:
        -:   94:/* The SHA f()-functions.  The f1 and f3 functions can be optimized to
        -:   95:   save one boolean operation each - thanks to Rich Schroeppel,
        -:   96:   rcs@cs.arizona.edu for discovering this */
        -:   97:
        -:   98:/*#define f1(x,y,z) ( ( x & y ) | ( ~x & z ) )          // Rounds  0-19 */
        -:   99:#define f1(x,y,z)  ( z ^ ( x & ( y ^ z ) ) )           /* Rounds  0-19 */
        -:  100:#define f2(x,y,z)  ( x ^ y ^ z )                       /* Rounds 20-39 */
        -:  101:/*#define f3(x,y,z) ( ( x & y ) | ( x & z ) | ( y & z ) )   // Rounds 40-59 */
        -:  102:#define f3(x,y,z)  ( ( x & y ) | ( z & ( x | y ) ) )   /* Rounds 40-59 */
        -:  103:#define f4(x,y,z)  ( x ^ y ^ z )                       /* Rounds 60-79 */
        -:  104:
        -:  105:/* The SHA Mysterious Constants */
        -:  106:
        -:  107:#define K1  0x5A827999L                                 /* Rounds  0-19 */
        -:  108:#define K2  0x6ED9EBA1L                                 /* Rounds 20-39 */
        -:  109:#define K3  0x8F1BBCDCL                                 /* Rounds 40-59 */
        -:  110:#define K4  0xCA62C1D6L                                 /* Rounds 60-79 */
        -:  111:
        -:  112:/* SHA initial values */
        -:  113:
        -:  114:#define h0init  0x67452301L
        -:  115:#define h1init  0xEFCDAB89L
        -:  116:#define h2init  0x98BADCFEL
        -:  117:#define h3init  0x10325476L
        -:  118:#define h4init  0xC3D2E1F0L
        -:  119:
        -:  120:/* Note that it may be necessary to add parentheses to these macros if they
        -:  121:   are to be called with expressions as arguments */
        -:  122:/* 32-bit rotate left - kludged with shifts */
        -:  123:
        -:  124:#define ROTL(n,X) ( ( ( X ) << n ) | ( ( X ) >> ( 32 - n ) ) )
        -:  125:
        -:  126:/* The initial expanding function.  The hash function is defined over an
        -:  127:   80-word expanded input array W, where the first 16 are copies of the input
        -:  128:   data, and the remaining 64 are defined by
        -:  129:
        -:  130:        W[ i ] = W[ i - 16 ] ^ W[ i - 14 ] ^ W[ i - 8 ] ^ W[ i - 3 ]
        -:  131:
        -:  132:   This implementation generates these values on the fly in a circular
        -:  133:   buffer - thanks to Colin Plumb, colin@nyx10.cs.du.edu for this
        -:  134:   optimization.
        -:  135:
        -:  136:   The updated SHA changes the expanding function by adding a rotate of 1
        -:  137:   bit.  Thanks to Jim Gillogly, jim@rand.org, and an anonymous contributor
        -:  138:   for this information */
        -:  139:
        -:  140:#define expand(W,i) ( W[ i & 15 ] = ROTL( 1, ( W[ i & 15 ] ^ W[ (i - 14) & 15 ] ^ \
        -:  141:                                                 W[ (i - 8) & 15 ] ^ W[ (i - 3) & 15 ] ) ) )
        -:  142:
        -:  143:
        -:  144:/* The prototype SHA sub-round.  The fundamental sub-round is:
        -:  145:
        -:  146:        a' = e + ROTL( 5, a ) + f( b, c, d ) + k + data;
        -:  147:        b' = a;
        -:  148:        c' = ROTL( 30, b );
        -:  149:        d' = c;
        -:  150:        e' = d;
        -:  151:
        -:  152:   but this is implemented by unrolling the loop 5 times and renaming the
        -:  153:   variables ( e, a, b, c, d ) = ( a', b', c', d', e' ) each iteration.
        -:  154:   This code is then replicated 20 times for each of the 4 functions, using
        -:  155:   the next 20 values from the W[] array each time */
        -:  156:
        -:  157:#define subRound(a, b, c, d, e, f, k, data) \
        -:  158:   ( e += ROTL( 5, a ) + f( b, c, d ) + k + data, b = ROTL( 30, b ) )
        -:  159:
        -:  160:#endif /* DOXYGEN_SHOULD_SKIP_THIS */
        -:  161:
        -:  162:/* Perform the SHA transformation.  Note that this code, like MD5, seems to
        -:  163:   break some optimizing compilers due to the complexity of the expressions
        -:  164:   and the size of the basic block.  It may be necessary to split it into
        -:  165:   sections, e.g. based on the four subrounds
        -:  166:
        -:  167:   Note that this corrupts the context->data area */
        -:  168:
        -:  169:static void
        -:  170:SHATransform(dbus_uint32_t *digest, dbus_uint32_t *data)
function SHATransform called 21231 returned 100% blocks executed 100%
    21231:  171:{
        -:  172:  dbus_uint32_t A, B, C, D, E;     /* Local vars */
        -:  173:  dbus_uint32_t eData[16];       /* Expanded data */
        -:  174:
        -:  175:  /* Set up first buffer and local data buffer */
    21231:  176:  A = digest[0];
    21231:  177:  B = digest[1];
    21231:  178:  C = digest[2];
    21231:  179:  D = digest[3];
    21231:  180:  E = digest[4];
    21231:  181:  memmove (eData, data, SHA_DATASIZE);
call    0 returned 100%
        -:  182:
        -:  183:  /* Heavy mangling, in 4 sub-rounds of 20 interations each. */
    21231:  184:  subRound (A, B, C, D, E, f1, K1, eData[0]);
    21231:  185:  subRound (E, A, B, C, D, f1, K1, eData[1]);
    21231:  186:  subRound (D, E, A, B, C, f1, K1, eData[2]);
    21231:  187:  subRound (C, D, E, A, B, f1, K1, eData[3]);
    21231:  188:  subRound (B, C, D, E, A, f1, K1, eData[4]);
    21231:  189:  subRound (A, B, C, D, E, f1, K1, eData[5]);
    21231:  190:  subRound (E, A, B, C, D, f1, K1, eData[6]);
    21231:  191:  subRound (D, E, A, B, C, f1, K1, eData[7]);
    21231:  192:  subRound (C, D, E, A, B, f1, K1, eData[8]);
    21231:  193:  subRound (B, C, D, E, A, f1, K1, eData[9]);
    21231:  194:  subRound (A, B, C, D, E, f1, K1, eData[10]);
    21231:  195:  subRound (E, A, B, C, D, f1, K1, eData[11]);
    21231:  196:  subRound (D, E, A, B, C, f1, K1, eData[12]);
    21231:  197:  subRound (C, D, E, A, B, f1, K1, eData[13]);
    21231:  198:  subRound (B, C, D, E, A, f1, K1, eData[14]);
    21231:  199:  subRound (A, B, C, D, E, f1, K1, eData[15]);
    21231:  200:  subRound (E, A, B, C, D, f1, K1, expand ( eData, 16) );
    21231:  201:  subRound (D, E, A, B, C, f1, K1, expand ( eData, 17) );
    21231:  202:  subRound (C, D, E, A, B, f1, K1, expand ( eData, 18) );
    21231:  203:  subRound (B, C, D, E, A, f1, K1, expand ( eData, 19) );
        -:  204:
    21231:  205:  subRound (A, B, C, D, E, f2, K2, expand ( eData, 20) );
    21231:  206:  subRound (E, A, B, C, D, f2, K2, expand ( eData, 21) );
    21231:  207:  subRound (D, E, A, B, C, f2, K2, expand ( eData, 22) );
    21231:  208:  subRound (C, D, E, A, B, f2, K2, expand ( eData, 23) );
    21231:  209:  subRound (B, C, D, E, A, f2, K2, expand ( eData, 24) );
    21231:  210:  subRound (A, B, C, D, E, f2, K2, expand ( eData, 25) );
    21231:  211:  subRound (E, A, B, C, D, f2, K2, expand ( eData, 26) );
    21231:  212:  subRound (D, E, A, B, C, f2, K2, expand ( eData, 27) );
    21231:  213:  subRound (C, D, E, A, B, f2, K2, expand ( eData, 28) );
    21231:  214:  subRound (B, C, D, E, A, f2, K2, expand ( eData, 29) );
    21231:  215:  subRound (A, B, C, D, E, f2, K2, expand ( eData, 30) );
    21231:  216:  subRound (E, A, B, C, D, f2, K2, expand ( eData, 31) );
    21231:  217:  subRound (D, E, A, B, C, f2, K2, expand ( eData, 32) );
    21231:  218:  subRound (C, D, E, A, B, f2, K2, expand ( eData, 33) );
    21231:  219:  subRound (B, C, D, E, A, f2, K2, expand ( eData, 34) );
    21231:  220:  subRound (A, B, C, D, E, f2, K2, expand ( eData, 35) );
    21231:  221:  subRound (E, A, B, C, D, f2, K2, expand ( eData, 36) );
    21231:  222:  subRound (D, E, A, B, C, f2, K2, expand ( eData, 37) );
    21231:  223:  subRound (C, D, E, A, B, f2, K2, expand ( eData, 38) );
    21231:  224:  subRound (B, C, D, E, A, f2, K2, expand ( eData, 39) );
        -:  225:
    21231:  226:  subRound (A, B, C, D, E, f3, K3, expand ( eData, 40) );
    21231:  227:  subRound (E, A, B, C, D, f3, K3, expand ( eData, 41) );
    21231:  228:  subRound (D, E, A, B, C, f3, K3, expand ( eData, 42) );
    21231:  229:  subRound (C, D, E, A, B, f3, K3, expand ( eData, 43) );
    21231:  230:  subRound (B, C, D, E, A, f3, K3, expand ( eData, 44) );
    21231:  231:  subRound (A, B, C, D, E, f3, K3, expand ( eData, 45) );
    21231:  232:  subRound (E, A, B, C, D, f3, K3, expand ( eData, 46) );
    21231:  233:  subRound (D, E, A, B, C, f3, K3, expand ( eData, 47) );
    21231:  234:  subRound (C, D, E, A, B, f3, K3, expand ( eData, 48) );
    21231:  235:  subRound (B, C, D, E, A, f3, K3, expand ( eData, 49) );
    21231:  236:  subRound (A, B, C, D, E, f3, K3, expand ( eData, 50) );
    21231:  237:  subRound (E, A, B, C, D, f3, K3, expand ( eData, 51) );
    21231:  238:  subRound (D, E, A, B, C, f3, K3, expand ( eData, 52) );
    21231:  239:  subRound (C, D, E, A, B, f3, K3, expand ( eData, 53) );
    21231:  240:  subRound (B, C, D, E, A, f3, K3, expand ( eData, 54) );
    21231:  241:  subRound (A, B, C, D, E, f3, K3, expand ( eData, 55) );
    21231:  242:  subRound (E, A, B, C, D, f3, K3, expand ( eData, 56) );
    21231:  243:  subRound (D, E, A, B, C, f3, K3, expand ( eData, 57) );
    21231:  244:  subRound (C, D, E, A, B, f3, K3, expand ( eData, 58) );
    21231:  245:  subRound (B, C, D, E, A, f3, K3, expand ( eData, 59) );
        -:  246:
    21231:  247:  subRound (A, B, C, D, E, f4, K4, expand ( eData, 60) );
    21231:  248:  subRound (E, A, B, C, D, f4, K4, expand ( eData, 61) );
    21231:  249:  subRound (D, E, A, B, C, f4, K4, expand ( eData, 62) );
    21231:  250:  subRound (C, D, E, A, B, f4, K4, expand ( eData, 63) );
    21231:  251:  subRound (B, C, D, E, A, f4, K4, expand ( eData, 64) );
    21231:  252:  subRound (A, B, C, D, E, f4, K4, expand ( eData, 65) );
    21231:  253:  subRound (E, A, B, C, D, f4, K4, expand ( eData, 66) );
    21231:  254:  subRound (D, E, A, B, C, f4, K4, expand ( eData, 67) );
    21231:  255:  subRound (C, D, E, A, B, f4, K4, expand ( eData, 68) );
    21231:  256:  subRound (B, C, D, E, A, f4, K4, expand ( eData, 69) );
    21231:  257:  subRound (A, B, C, D, E, f4, K4, expand ( eData, 70) );
    21231:  258:  subRound (E, A, B, C, D, f4, K4, expand ( eData, 71) );
    21231:  259:  subRound (D, E, A, B, C, f4, K4, expand ( eData, 72) );
    21231:  260:  subRound (C, D, E, A, B, f4, K4, expand ( eData, 73) );
    21231:  261:  subRound (B, C, D, E, A, f4, K4, expand ( eData, 74) );
    21231:  262:  subRound (A, B, C, D, E, f4, K4, expand ( eData, 75) );
    21231:  263:  subRound (E, A, B, C, D, f4, K4, expand ( eData, 76) );
    21231:  264:  subRound (D, E, A, B, C, f4, K4, expand ( eData, 77) );
    21231:  265:  subRound (C, D, E, A, B, f4, K4, expand ( eData, 78) );
    21231:  266:  subRound (B, C, D, E, A, f4, K4, expand ( eData, 79) );
        -:  267:
        -:  268:  /* Build message digest */
    21231:  269:  digest[0] += A;
    21231:  270:  digest[1] += B;
    21231:  271:  digest[2] += C;
    21231:  272:  digest[3] += D;
    21231:  273:  digest[4] += E;
    21231:  274:}
        -:  275:
        -:  276:/* When run on a little-endian CPU we need to perform byte reversal on an
        -:  277:   array of longwords. */
        -:  278:
        -:  279:#ifdef WORDS_BIGENDIAN
        -:  280:#define swap_words(buffer, byte_count)
        -:  281:#else
        -:  282:static void
        -:  283:swap_words (dbus_uint32_t *buffer,
        -:  284:            int            byte_count)
function swap_words called 26869 returned 100% blocks executed 100%
    26869:  285:{
    26869:  286:  byte_count /= sizeof (dbus_uint32_t);
   410348:  287:  while (byte_count--)
branch  0 taken 93%
branch  1 taken 7% (fallthrough)
        -:  288:    {
   356610:  289:      *buffer = DBUS_UINT32_SWAP_LE_BE (*buffer);
   356610:  290:      ++buffer;
        -:  291:    }
    26869:  292:}
        -:  293:#endif
        -:  294:
        -:  295:static void
        -:  296:sha_init (DBusSHAContext *context)
function sha_init called 5642 returned 100% blocks executed 100%
     5642:  297:{
        -:  298:  /* Set the h-vars to their initial values */
     5642:  299:  context->digest[0] = h0init;
     5642:  300:  context->digest[1] = h1init;
     5642:  301:  context->digest[2] = h2init;
     5642:  302:  context->digest[3] = h3init;
     5642:  303:  context->digest[4] = h4init;
        -:  304:
        -:  305:  /* Initialise bit count */
     5642:  306:  context->count_lo = context->count_hi = 0;
     5642:  307:}
        -:  308:
        -:  309:static void
        -:  310:sha_append (DBusSHAContext      *context,
        -:  311:            const unsigned char *buffer,
        -:  312:            unsigned int         count)
function sha_append called 5642 returned 100% blocks executed 56%
     5642:  313:{
        -:  314:  dbus_uint32_t tmp;
        -:  315:  unsigned int dataCount;
        -:  316:
        -:  317:  /* Update bitcount */
     5642:  318:  tmp = context->count_lo;
     5642:  319:  if (( context->count_lo = tmp + ( ( dbus_uint32_t) count << 3) ) < tmp)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  320:    context->count_hi++;             /* Carry from low to high */
     5642:  321:  context->count_hi += count >> 29;
        -:  322:
        -:  323:  /* Get count of bytes already in data */
     5642:  324:  dataCount = (int) (tmp >> 3) & 0x3F;
        -:  325:
        -:  326:  /* Handle any leading odd-sized chunks */
     5642:  327:  if (dataCount)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
        -:  328:    {
    #####:  329:      unsigned char *p = (unsigned char *) context->data + dataCount;
        -:  330:
    #####:  331:      dataCount = SHA_DATASIZE - dataCount;
    #####:  332:      if (count < dataCount)
branch  0 never executed
branch  1 never executed
        -:  333:        {
    #####:  334:          memmove (p, buffer, count);
call    0 never executed
    #####:  335:          return;
        -:  336:        }
    #####:  337:      memmove (p, buffer, dataCount);
call    0 never executed
    #####:  338:      swap_words (context->data, SHA_DATASIZE);
call    0 never executed
    #####:  339:      SHATransform (context->digest, context->data);
call    0 never executed
    #####:  340:      buffer += dataCount;
    #####:  341:      count -= dataCount;
        -:  342:    }
        -:  343:
        -:  344:  /* Process data in SHA_DATASIZE chunks */
    26860:  345:  while (count >= SHA_DATASIZE)
branch  0 taken 73%
branch  1 taken 27% (fallthrough)
        -:  346:    {
    15576:  347:      memmove (context->data, buffer, SHA_DATASIZE);
call    0 returned 100%
    15576:  348:      swap_words (context->data, SHA_DATASIZE);
call    0 returned 100%
    15576:  349:      SHATransform (context->digest, context->data);
call    0 returned 100%
    15576:  350:      buffer += SHA_DATASIZE;
    15576:  351:      count -= SHA_DATASIZE;
        -:  352:    }
        -:  353:
        -:  354:  /* Handle any remaining bytes of data. */
     5642:  355:  memmove (context->data, buffer, count);
call    0 returned 100%
        -:  356:}
        -:  357:
        -:  358:
        -:  359:/* Final wrapup - pad to SHA_DATASIZE-byte boundary with the bit pattern
        -:  360:   1 0* (64-bit count of bits processed, MSB-first) */
        -:  361:
        -:  362:static void
        -:  363:sha_finish (DBusSHAContext *context, unsigned char digest[20])
function sha_finish called 5638 returned 100% blocks executed 100%
     5638:  364:{
        -:  365:  int count;
        -:  366:  unsigned char *data_p;
        -:  367:
        -:  368:  /* Compute number of bytes mod 64 */
     5638:  369:  count = (int) context->count_lo;
     5638:  370:  count = (count >> 3) & 0x3F;
        -:  371:
        -:  372:  /* Set the first char of padding to 0x80.  This is safe since there is
        -:  373:     always at least one byte free */
     5638:  374:  data_p = (unsigned char *) context->data + count;
     5638:  375:  *data_p++ = 0x80;
        -:  376:
        -:  377:  /* Bytes of padding needed to make 64 bytes */
     5638:  378:  count = SHA_DATASIZE - 1 - count;
        -:  379:
        -:  380:  /* Pad out to 56 mod 64 */
     5638:  381:  if (count < 8)
branch  0 taken 1% (fallthrough)
branch  1 taken 99%
        -:  382:    {
        -:  383:      /* Two lots of padding:  Pad the first block to 64 bytes */
       17:  384:      memset (data_p, 0, count);
call    0 returned 100%
       17:  385:      swap_words (context->data, SHA_DATASIZE);
call    0 returned 100%
       17:  386:      SHATransform (context->digest, context->data);
call    0 returned 100%
        -:  387:
        -:  388:      /* Now fill the next block with 56 bytes */
       17:  389:      memset (context->data, 0, SHA_DATASIZE - 8);
call    0 returned 100%
        -:  390:    }
        -:  391:  else
        -:  392:    /* Pad block to 56 bytes */
     5621:  393:    memset (data_p, 0, count - 8);
call    0 returned 100%
        -:  394:
        -:  395:  /* Append length in bits and transform */
     5638:  396:  context->data[14] = context->count_hi;
     5638:  397:  context->data[15] = context->count_lo;
        -:  398:
     5638:  399:  swap_words (context->data, SHA_DATASIZE - 8);
call    0 returned 100%
     5638:  400:  SHATransform (context->digest, context->data);
call    0 returned 100%
     5638:  401:  swap_words (context->digest, SHA_DIGESTSIZE);
call    0 returned 100%
     5638:  402:  memmove (digest, context->digest, SHA_DIGESTSIZE);
call    0 returned 100%
     5638:  403:}
        -:  404:
        -:  405:/** @} */ /* End of internals */
        -:  406:
        -:  407:/**
        -:  408: * @addtogroup DBusSHA
        -:  409: *
        -:  410: * @{
        -:  411: */
        -:  412:
        -:  413:/**
        -:  414: * Initializes the SHA context.
        -:  415: *
        -:  416: * @param context an uninitialized context, typically on the stack.
        -:  417: */
        -:  418:void
        -:  419:_dbus_sha_init (DBusSHAContext *context)
function _dbus_sha_init called 5642 returned 100% blocks executed 100%
     5642:  420:{
     5642:  421:  sha_init (context);
call    0 returned 100%
     5642:  422:}
        -:  423:
        -:  424:/**
        -:  425: * Feeds more data into an existing shasum computation.
        -:  426: *
        -:  427: * @param context the SHA context
        -:  428: * @param data the additional data to hash
        -:  429: */
        -:  430:void
        -:  431:_dbus_sha_update (DBusSHAContext   *context,
        -:  432:                  const DBusString *data)
function _dbus_sha_update called 5642 returned 100% blocks executed 100%
     5642:  433:{
        -:  434:  unsigned int inputLen;
        -:  435:  const unsigned char *input;
        -:  436:
     5642:  437:  input = (const unsigned char*) _dbus_string_get_const_data (data);
call    0 returned 100%
     5642:  438:  inputLen = _dbus_string_get_length (data);
call    0 returned 100%
        -:  439:
     5642:  440:  sha_append (context, input, inputLen);
call    0 returned 100%
     5642:  441:}
        -:  442:
        -:  443:/**
        -:  444: * SHA finalization. Ends an SHA message-digest operation, writing the
        -:  445: * the message digest and zeroing the context.  The results are
        -:  446: * returned as a raw 20-byte digest, not as the ascii-hex-digits
        -:  447: * string form of the digest.
        -:  448: *
        -:  449: * @param context the SHA context
        -:  450: * @param results string to append the 20-byte SHA digest to
        -:  451: * @returns #FALSE if not enough memory to append the digest
        -:  452: *
        -:  453: */
        -:  454:dbus_bool_t
        -:  455:_dbus_sha_final (DBusSHAContext   *context,
        -:  456:                 DBusString       *results)
function _dbus_sha_final called 5638 returned 100% blocks executed 100%
     5638:  457:{
        -:  458:  unsigned char digest[20];
        -:  459:
     5638:  460:  sha_finish (context, digest);
call    0 returned 100%
        -:  461:
     5638:  462:  if (!_dbus_string_append_len (results, digest, 20))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        4:  463:    return FALSE;
        -:  464:
        -:  465:  /* some kind of security paranoia, though it seems pointless
        -:  466:   * to me given the nonzeroed stuff flying around
        -:  467:   */
     5634:  468:  memset ((void*)context, '\0', sizeof (DBusSHAContext));
call    0 returned 100%
        -:  469:
     5634:  470:  return TRUE;
        -:  471:}
        -:  472:
        -:  473:/**
        -:  474: * Computes the ASCII hex-encoded shasum of the given data and
        -:  475: * appends it to the output string.
        -:  476: *
        -:  477: * @param data input data to be hashed
        -:  478: * @param ascii_output string to append ASCII shasum to
        -:  479: * @returns #FALSE if not enough memory
        -:  480: */
        -:  481:dbus_bool_t
        -:  482:_dbus_sha_compute (const DBusString *data,
        -:  483:                   DBusString       *ascii_output)
function _dbus_sha_compute called 5642 returned 100% blocks executed 100%
     5642:  484:{
        -:  485:  DBusSHAContext context;
        -:  486:  DBusString digest;
        -:  487:
     5642:  488:  _dbus_sha_init (&context);
call    0 returned 100%
        -:  489:
     5642:  490:  _dbus_sha_update (&context, data);
call    0 returned 100%
        -:  491:
     5642:  492:  if (!_dbus_string_init (&digest))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        4:  493:    return FALSE;
        -:  494:
     5638:  495:  if (!_dbus_sha_final (&context, &digest))
call    0 returned 100%
branch  1 taken 99% (fallthrough)
branch  2 taken 1%
        4:  496:    goto error;
        -:  497:
     5634:  498:  if (!_dbus_string_hex_encode (&digest, 0, ascii_output,
call    0 returned 100%
call    1 returned 100%
branch  2 taken 3% (fallthrough)
branch  3 taken 97%
        -:  499:                                _dbus_string_get_length (ascii_output)))
      164:  500:    goto error;
        -:  501:
     5470:  502:  _dbus_string_free (&digest);
call    0 returned 100%
        -:  503:  
     5470:  504:  return TRUE;
        -:  505:
      168:  506: error:
      168:  507:  _dbus_string_free (&digest);
call    0 returned 100%
      168:  508:  return FALSE;
        -:  509:}
        -:  510:
        -:  511:/** @} */ /* end of exported functions */
        -:  512:
        -:  513:#ifdef DBUS_BUILD_TESTS
        -:  514:#include "dbus-test.h"
        -:  515:#include <stdio.h>
        -:  516:
        -:  517:static dbus_bool_t
        -:  518:check_sha_binary (const unsigned char *input,
        -:  519:                  int                  input_len,
        -:  520:                  const char          *expected)
function check_sha_binary called 8 returned 100% blocks executed 65%
        8:  521:{
        -:  522:  DBusString input_str;
        -:  523:  DBusString expected_str;
        -:  524:  DBusString results;
        -:  525:
        8:  526:  _dbus_string_init_const_len (&input_str, input, input_len);
call    0 returned 100%
        8:  527:  _dbus_string_init_const (&expected_str, expected);
call    0 returned 100%
        -:  528:
        8:  529:  if (!_dbus_string_init (&results))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  530:    _dbus_assert_not_reached ("no memory for SHA-1 results");
call    0 never executed
        -:  531:
        8:  532:  if (!_dbus_sha_compute (&input_str, &results))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  533:    _dbus_assert_not_reached ("no memory for SHA-1 results");
call    0 never executed
        -:  534:
        8:  535:  if (!_dbus_string_equal (&expected_str, &results))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  536:    {
    #####:  537:      _dbus_warn ("Expected hash %s got %s for SHA-1 sum\n",
call    0 never executed
call    1 never executed
        -:  538:                  expected,
        -:  539:                  _dbus_string_get_const_data (&results));
    #####:  540:      _dbus_string_free (&results);
call    0 never executed
    #####:  541:      return FALSE;
        -:  542:    }
        -:  543:
        8:  544:  _dbus_string_free (&results);
call    0 returned 100%
        8:  545:  return TRUE;
        -:  546:}
        -:  547:
        -:  548:static dbus_bool_t
        -:  549:check_sha_str (const char *input,
        -:  550:               const char *expected)
function check_sha_str called 7 returned 100% blocks executed 100%
        7:  551:{
        7:  552:  return check_sha_binary (input, strlen (input), expected);
call    0 returned 100%
call    1 returned 100%
        -:  553:}
        -:  554:
        -:  555:static dbus_bool_t
        -:  556:decode_compact_string (const DBusString *line,
        -:  557:                       DBusString       *decoded)
function decode_compact_string called 229 returned 100% blocks executed 69%
      229:  558:{
        -:  559:  int n_bits;
        -:  560:  dbus_bool_t current_b;
        -:  561:  int offset;
        -:  562:  int next;
        -:  563:  long val;
        -:  564:  int length_bytes;
        -:  565:  
      229:  566:  offset = 0;
      229:  567:  next = 0;
        -:  568:
      229:  569:  if (!_dbus_string_parse_int (line, offset, &val, &next))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  570:    {
    #####:  571:      fprintf (stderr, "could not parse length at start of compact string: %s\n",
call    0 never executed
call    1 never executed
        -:  572:               _dbus_string_get_const_data (line));
    #####:  573:      return FALSE;
        -:  574:    }
        -:  575:
      229:  576:  _dbus_string_skip_blank (line, next, &next);
call    0 returned 100%
        -:  577:  
      229:  578:  offset = next;
      229:  579:  if (!_dbus_string_parse_int (line, offset, &val, &next))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  580:    {
    #####:  581:      fprintf (stderr, "could not parse start bit 'b' in compact string: %s\n",
call    0 never executed
call    1 never executed
        -:  582:               _dbus_string_get_const_data (line));
    #####:  583:      return FALSE;
        -:  584:    }
        -:  585:  
      229:  586:  if (!(val == 0 || val == 1))
branch  0 taken 50% (fallthrough)
branch  1 taken 50%
branch  2 taken 0% (fallthrough)
branch  3 taken 100%
        -:  587:    {
    #####:  588:      fprintf (stderr, "the value 'b' must be 0 or 1, see sha-1/Readme.txt\n");
call    0 never executed
    #####:  589:      return FALSE;
        -:  590:    }
        -:  591:
      229:  592:  _dbus_string_skip_blank (line, next, &next);
call    0 returned 100%
        -:  593:  
      229:  594:  current_b = val;
      229:  595:  n_bits = 0;
        -:  596:  
    50494:  597:  while (next < _dbus_string_get_length (line))
call    0 returned 100%
branch  1 taken 100%
branch  2 taken 0% (fallthrough)
        -:  598:    {
        -:  599:      int total_bits;
        -:  600:      
    50265:  601:      offset = next;
        -:  602:
    50265:  603:      if (_dbus_string_get_byte (line, offset) == '^')
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
      229:  604:        break;
        -:  605:      
    50036:  606:      if (!_dbus_string_parse_int (line, offset, &val, &next))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  607:        {
    #####:  608:          fprintf (stderr, "could not parse bit count in compact string\n");
call    0 never executed
    #####:  609:          return FALSE;
        -:  610:        }
        -:  611:
        -:  612:      /* We now append "val" copies of "current_b" bits to the string */
    50036:  613:      total_bits = n_bits + val;
  5338120:  614:      while (n_bits < total_bits)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  615:        {
  5238048:  616:          int byte_containing_next_bit = n_bits / 8;
  5238048:  617:          int bit_containing_next_bit = 7 - (n_bits % 8);
        -:  618:          unsigned char old_byte;
        -:  619:          
  5238048:  620:          if (byte_containing_next_bit >= _dbus_string_get_length (decoded))
call    0 returned 100%
branch  1 taken 13% (fallthrough)
branch  2 taken 88%
        -:  621:            {
   654756:  622:              if (!_dbus_string_set_length (decoded, byte_containing_next_bit + 1))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  623:                _dbus_assert_not_reached ("no memory to extend to next byte");
call    0 never executed
        -:  624:            }
        -:  625:
  5238048:  626:          old_byte = _dbus_string_get_byte (decoded, byte_containing_next_bit);
call    0 returned 100%
  5238048:  627:          old_byte |= current_b << bit_containing_next_bit;
        -:  628:
        -:  629:#if 0
        -:  630:          printf ("Appending bit %d to byte %d at bit %d resulting in byte 0x%x\n",
        -:  631:                  current_b, byte_containing_next_bit,
        -:  632:                  bit_containing_next_bit, old_byte);
        -:  633:#endif
        -:  634:          
  5238048:  635:          _dbus_string_set_byte (decoded, byte_containing_next_bit, old_byte);
call    0 returned 100%
        -:  636:          
  5238048:  637:          ++n_bits;
        -:  638:        }
        -:  639:
    50036:  640:      _dbus_string_skip_blank (line, next, &next);
call    0 returned 100%
        -:  641:          
    50036:  642:      current_b = !current_b;
        -:  643:    }
        -:  644:
      229:  645:  length_bytes = (n_bits / 8 + ((n_bits % 8) ? 1 : 0));
        -:  646:  
      229:  647:  if (_dbus_string_get_length (decoded) != length_bytes)
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  648:    {
    #####:  649:      fprintf (stderr, "Expected length %d bytes %d bits for compact string, got %d bytes\n",
call    0 never executed
call    1 never executed
        -:  650:               length_bytes, n_bits, _dbus_string_get_length (decoded));
    #####:  651:      return FALSE;
        -:  652:    }
        -:  653:  else
      229:  654:    return TRUE;
        -:  655:}
        -:  656:
        -:  657:static dbus_bool_t
        -:  658:get_next_expected_result (DBusString *results,
        -:  659:                          DBusString *result)
function get_next_expected_result called 229 returned 100% blocks executed 96%
      229:  660:{
        -:  661:  DBusString line;
        -:  662:  dbus_bool_t retval;
        -:  663:
      229:  664:  retval = FALSE;
        -:  665:  
      229:  666:  if (!_dbus_string_init (&line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  667:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  668:  
      235:  669: next_iteration:
      472:  670:  while (_dbus_string_pop_line (results, &line))
call    0 returned 100%
branch  1 taken 100%
branch  2 taken 0% (fallthrough)
        -:  671:    {
      237:  672:      _dbus_string_delete_leading_blanks (&line);
call    0 returned 100%
        -:  673:
      237:  674:      if (_dbus_string_get_length (&line) == 0)
call    0 returned 100%
branch  1 taken 1%
branch  2 taken 99% (fallthrough)
        1:  675:        goto next_iteration;
      236:  676:      else if (_dbus_string_starts_with_c_str (&line, "#"))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        2:  677:        goto next_iteration;
      234:  678:      else if (_dbus_string_starts_with_c_str (&line, "H>"))
call    0 returned 100%
branch  1 taken 99% (fallthrough)
branch  2 taken 1%
        -:  679:        {
        -:  680:          /* don't print */
        -:  681:        }
      232:  682:      else if (_dbus_string_starts_with_c_str (&line, "D>") ||
call    0 returned 100%
branch  1 taken 1%
branch  2 taken 99% (fallthrough)
call    3 returned 100%
branch  4 taken 1%
branch  5 taken 99% (fallthrough)
        -:  683:               _dbus_string_starts_with_c_str (&line, "<D"))
        -:  684:        goto next_iteration;
        -:  685:      else
        -:  686:        {
        -:  687:          int i;
        -:  688:          
      229:  689:          if (!_dbus_string_move (&line, 0, result, 0))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  690:            _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  691:
      229:  692:          i = 0;
    10076:  693:          while (i < _dbus_string_get_length (result))
call    0 returned 100%
branch  1 taken 98%
branch  2 taken 2% (fallthrough)
        -:  694:            {
     9618:  695:              switch (_dbus_string_get_byte (result, i))
call    0 returned 100%
branch  1 taken 6%
branch  2 taken 6%
branch  3 taken 6%
branch  4 taken 6%
branch  5 taken 6%
branch  6 taken 6%
branch  7 taken 5%
branch  8 taken 59%
        -:  696:                {
        -:  697:                case 'A':
      561:  698:                  _dbus_string_set_byte (result, i, 'a');
call    0 returned 100%
      561:  699:                  break;
        -:  700:                case 'B':
      596:  701:                  _dbus_string_set_byte (result, i, 'b');
call    0 returned 100%
      596:  702:                  break;
        -:  703:                case 'C':
      576:  704:                  _dbus_string_set_byte (result, i, 'c');
call    0 returned 100%
      576:  705:                  break;
        -:  706:                case 'D':
      567:  707:                  _dbus_string_set_byte (result, i, 'd');
call    0 returned 100%
      567:  708:                  break;
        -:  709:                case 'E':
      581:  710:                  _dbus_string_set_byte (result, i, 'e');
call    0 returned 100%
      581:  711:                  break;
        -:  712:                case 'F':
      601:  713:                  _dbus_string_set_byte (result, i, 'f');
call    0 returned 100%
      601:  714:                  break;
        -:  715:                case '^':
        -:  716:                case ' ':
      458:  717:                  _dbus_string_delete (result, i, 1);
call    0 returned 100%
      458:  718:                  --i; /* to offset ++i below */
        -:  719:                  break;
        -:  720:                }
        -:  721:
     9618:  722:              ++i;
        -:  723:            }
        -:  724:          
      229:  725:          break;
        -:  726:        }
        -:  727:    }
        -:  728:  
      229:  729:  retval = TRUE;
        -:  730:  
        -:  731:  /* out: */
      229:  732:  _dbus_string_free (&line);
call    0 returned 100%
      229:  733:  return retval;
        -:  734:}
        -:  735:
        -:  736:static dbus_bool_t
        -:  737:process_test_data (const char *test_data_dir)
function process_test_data called 1 returned 100% blocks executed 73%
        1:  738:{
        -:  739:  DBusString tests_file;
        -:  740:  DBusString results_file;
        -:  741:  DBusString tests;
        -:  742:  DBusString results;
        -:  743:  DBusString line;
        -:  744:  DBusString tmp;
        -:  745:  int line_no;
        -:  746:  dbus_bool_t retval;
        -:  747:  int success_count;
        -:  748:  DBusError error;
        -:  749:  
        1:  750:  retval = FALSE;
        -:  751:  
        1:  752:  if (!_dbus_string_init (&tests_file))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  753:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  754:
        1:  755:  if (!_dbus_string_init (&results_file))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  756:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  757:
        1:  758:  if (!_dbus_string_init (&tests))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  759:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  760:
        1:  761:  if (!_dbus_string_init (&results))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  762:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  763:
        1:  764:  if (!_dbus_string_init (&line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  765:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  766:  
        1:  767:  if (!_dbus_string_append (&tests_file, test_data_dir))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  768:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  769:
        1:  770:  if (!_dbus_string_append (&results_file, test_data_dir))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  771:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  772:
        1:  773:  _dbus_string_init_const (&tmp, "sha-1/byte-messages.sha1");
call    0 returned 100%
        1:  774:  if (!_dbus_concat_dir_and_file (&tests_file, &tmp))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  775:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  776:
        1:  777:  _dbus_string_init_const (&tmp, "sha-1/byte-hashes.sha1");
call    0 returned 100%
        1:  778:  if (!_dbus_concat_dir_and_file (&results_file, &tmp))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  779:    _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  780:
        1:  781:  dbus_error_init (&error);
call    0 returned 100%
        1:  782:  if (!_dbus_file_get_contents (&tests, &tests_file, &error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  783:    {
    #####:  784:      fprintf (stderr, "could not load test data file %s: %s\n",
call    0 never executed
call    1 never executed
        -:  785:               _dbus_string_get_const_data (&tests_file),
        -:  786:               error.message);
    #####:  787:      dbus_error_free (&error);
call    0 never executed
    #####:  788:      goto out;
        -:  789:    }
        -:  790:
        1:  791:  if (!_dbus_file_get_contents (&results, &results_file, &error))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  792:    {
    #####:  793:      fprintf (stderr, "could not load results data file %s: %s\n",
call    0 never executed
call    1 never executed
        -:  794:               _dbus_string_get_const_data (&results_file), error.message);
    #####:  795:      dbus_error_free (&error);
call    0 never executed
    #####:  796:      goto out;
        -:  797:    }
        -:  798:
        1:  799:  success_count = 0;
        1:  800:  line_no = 0;
        9:  801: next_iteration:
      249:  802:  while (_dbus_string_pop_line (&tests, &line))
call    0 returned 100%
branch  1 taken 100%
branch  2 taken 0% (fallthrough)
        -:  803:    {
      240:  804:      line_no += 1;
        -:  805:
      240:  806:      _dbus_string_delete_leading_blanks (&line);
call    0 returned 100%
        -:  807:
      240:  808:      if (_dbus_string_get_length (&line) == 0)
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        2:  809:        goto next_iteration;
      238:  810:      else if (_dbus_string_starts_with_c_str (&line, "#"))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        2:  811:        goto next_iteration;
      236:  812:      else if (_dbus_string_starts_with_c_str (&line, "H>"))
call    0 returned 100%
branch  1 taken 1% (fallthrough)
branch  2 taken 99%
        -:  813:        {
        3:  814:          printf ("SHA-1: %s\n", _dbus_string_get_const_data (&line));
call    0 returned 100%
call    1 returned 100%
        -:  815:
        3:  816:          if (_dbus_string_find (&line, 0, "Type 3", NULL))
call    0 returned 100%
branch  1 taken 33% (fallthrough)
branch  2 taken 67%
        -:  817:            {
        -:  818:              /* See sha-1/Readme.txt - the "Type 3" tests are
        -:  819:               * random seeds, rather than data to be hashed.
        -:  820:               * we'd have to do a little bit more implementation
        -:  821:               * to use those tests.
        -:  822:               */
        -:  823:              
        1:  824:              printf (" (ending tests due to Type 3 tests seen - this is normal)\n");
call    0 returned 100%
        1:  825:              break;
        -:  826:            }
        -:  827:        }
      233:  828:      else if (_dbus_string_starts_with_c_str (&line, "D>") ||
call    0 returned 100%
branch  1 taken 1%
branch  2 taken 99% (fallthrough)
call    3 returned 100%
branch  4 taken 1%
branch  5 taken 99% (fallthrough)
        -:  829:               _dbus_string_starts_with_c_str (&line, "<D"))
        -:  830:        goto next_iteration;
        -:  831:      else
        -:  832:        {
        -:  833:          DBusString test;
        -:  834:          DBusString result;
        -:  835:          DBusString next_line;
        -:  836:          DBusString expected;
        -:  837:          dbus_bool_t success;
        -:  838:
      229:  839:          success = FALSE;
        -:  840:          
      229:  841:          if (!_dbus_string_init (&next_line))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  842:            _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  843:
      229:  844:          if (!_dbus_string_init (&expected))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  845:            _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  846:          
      229:  847:          if (!_dbus_string_init (&test))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  848:            _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  849:
      229:  850:          if (!_dbus_string_init (&result))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  851:            _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  852:
        -:  853:          /* the "compact strings" are "^"-terminated not
        -:  854:           * newline-terminated so readahead to find the
        -:  855:           * "^"
        -:  856:           */
     2507:  857:          while (!_dbus_string_find (&line, 0, "^", NULL) &&
call    0 returned 100%
branch  1 taken 90% (fallthrough)
branch  2 taken 10%
call    3 returned 100%
branch  4 taken 100%
branch  5 taken 0% (fallthrough)
        -:  858:                 _dbus_string_pop_line (&tests, &next_line))
        -:  859:            {
     2049:  860:              if (!_dbus_string_append_byte (&line, ' ') ||
call    0 returned 100%
branch  1 taken 100% (fallthrough)
branch  2 taken 0%
call    3 returned 100%
call    4 returned 100%
branch  5 taken 0% (fallthrough)
branch  6 taken 100%
        -:  861:                  !_dbus_string_move (&next_line, 0, &line,
        -:  862:                                      _dbus_string_get_length (&line)))
    #####:  863:                _dbus_assert_not_reached ("no memory");
call    0 never executed
        -:  864:            }
        -:  865:          
      229:  866:          if (!decode_compact_string (&line, &test))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  867:            {
    #####:  868:              fprintf (stderr, "Failed to decode line %d as a compact string\n",
call    0 never executed
        -:  869:                       line_no);
    #####:  870:              goto failure;
        -:  871:            }
        -:  872:          
      229:  873:          if (!_dbus_sha_compute (&test, &result))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  874:            _dbus_assert_not_reached ("no memory for SHA-1 result");
call    0 never executed
        -:  875:
      229:  876:          if (!get_next_expected_result (&results, &expected))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  877:            {
    #####:  878:              fprintf (stderr, "Failed to read an expected result\n");
call    0 never executed
    #####:  879:              goto failure;
        -:  880:            }
        -:  881:          
      229:  882:          if (!_dbus_string_equal (&result, &expected))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  883:            {              
    #####:  884:              fprintf (stderr, " for line %d got hash %s expected %s\n",
call    0 never executed
call    1 never executed
call    2 never executed
        -:  885:                       line_no,
        -:  886:                       _dbus_string_get_const_data (&result),
        -:  887:                       _dbus_string_get_const_data (&expected));
    #####:  888:              goto failure;
        -:  889:            }
        -:  890:          else
        -:  891:            {
      229:  892:              success_count += 1;
        -:  893:            }
        -:  894:
      229:  895:          success = TRUE;
        -:  896:
      229:  897:        failure:
      229:  898:          _dbus_string_free (&test);
call    0 returned 100%
      229:  899:          _dbus_string_free (&result);
call    0 returned 100%
      229:  900:          _dbus_string_free (&next_line);
call    0 returned 100%
      229:  901:          _dbus_string_free (&expected);
call    0 returned 100%
        -:  902:
      229:  903:          if (!success)
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
    #####:  904:            goto out;
        -:  905:        }
        -:  906:    }
        -:  907:
        1:  908:  retval = TRUE;
        -:  909:
        1:  910:  printf ("Passed the %d SHA-1 tests in the test file\n",
call    0 returned 100%
        -:  911:          success_count);
        -:  912:  
        1:  913: out:
        1:  914:  _dbus_string_free (&tests_file);
call    0 returned 100%
        1:  915:  _dbus_string_free (&results_file);
call    0 returned 100%
        1:  916:  _dbus_string_free (&tests);
call    0 returned 100%
        1:  917:  _dbus_string_free (&results);
call    0 returned 100%
        1:  918:  _dbus_string_free (&line);
call    0 returned 100%
        -:  919:
        1:  920:  return retval;
        -:  921:}
        -:  922:
        -:  923:/**
        -:  924: * @ingroup DBusSHAInternals
        -:  925: * Unit test for SHA computation.
        -:  926: *
        -:  927: * @returns #TRUE on success.
        -:  928: */
        -:  929:dbus_bool_t
        -:  930:_dbus_sha_test (const char *test_data_dir)
function _dbus_sha_test called 1 returned 100% blocks executed 71%
        1:  931:{
        -:  932:  unsigned char all_bytes[256];
        -:  933:  int i;
        -:  934:
        1:  935:  if (test_data_dir != NULL)
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
        -:  936:    {
        1:  937:      if (!process_test_data (test_data_dir))
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
    #####:  938:        return FALSE;
        -:  939:    }
        -:  940:  else
    #####:  941:    printf ("No test data dir\n");
call    0 never executed
        -:  942:  
        1:  943:  i = 0;
      258:  944:  while (i < 256)
branch  0 taken 99%
branch  1 taken 1% (fallthrough)
        -:  945:    {
      256:  946:      all_bytes[i] = i;
      256:  947:      ++i;
        -:  948:    }
        -:  949:
        1:  950:  if (!check_sha_binary (all_bytes, 256,
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  951:                         "4916d6bdb7f78e6803698cab32d1586ea457dfc8"))
    #####:  952:    return FALSE;
        -:  953:
        -:  954:#define CHECK(input,expected) if (!check_sha_str (input, expected)) return FALSE
        -:  955:
        1:  956:  CHECK ("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        1:  957:  CHECK ("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        1:  958:  CHECK ("abc", "a9993e364706816aba3e25717850c26c9cd0d89d");
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        1:  959:  CHECK ("message digest", "c12252ceda8be8994d5fa0290a47231c1d16aae3");
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        1:  960:  CHECK ("abcdefghijklmnopqrstuvwxyz", "32d10c7b8cf96570ca04ce37f2a19d84240d3a89");
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        1:  961:  CHECK ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  962:         "761c457bf73b14d27e9e9265c46f4b4dda11f940");
        1:  963:  CHECK ("12345678901234567890123456789012345678901234567890123456789012345678901234567890",
call    0 returned 100%
branch  1 taken 0% (fallthrough)
branch  2 taken 100%
        -:  964:         "50abf5706a150990a08b2c5ea40fa0e585554732");
        -:  965:
        1:  966:  return TRUE;
        -:  967:}
        -:  968:
        -:  969:#endif /* DBUS_BUILD_TESTS */