LCOV - code coverage report
Current view: top level - tests - crypto.c (source / functions) Hit Total Coverage
Test: GNU SASL Lines: 32 43 74.4 %
Date: 2012-05-28 Functions: 1 1 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 22 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* crypto.c --- Test the crypto related SASL functions.
       2                 :            :  * Copyright (C) 2009-2012 Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of GNU SASL.
       5                 :            :  *
       6                 :            :  * This program is free software: you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation, either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18                 :            :  *
      19                 :            :  */
      20                 :            : 
      21                 :            : #ifdef HAVE_CONFIG_H
      22                 :            : #include "config.h"
      23                 :            : #endif
      24                 :            : 
      25                 :            : #include <stdio.h>
      26                 :            : #include <stdlib.h>
      27                 :            : #include <string.h>
      28                 :            : #include <gsasl.h>
      29                 :            : 
      30                 :            : #include "utils.h"
      31                 :            : 
      32                 :            : void
      33                 :          1 : doit (void)
      34                 :            : {
      35                 :            : #define SIZE 10
      36                 :            :   char tmp[SIZE];
      37                 :            :   char savetmp[SIZE];
      38                 :            :   char *hash;
      39                 :            :   size_t tmplen;
      40                 :            :   int rc;
      41                 :            :   Gsasl *ctx;
      42                 :            : 
      43                 :          1 :   rc = gsasl_init (&ctx);
      44         [ -  + ]:          1 :   if (rc != GSASL_OK)
      45                 :          0 :     fail ("gsasl_init %d: %s\n", rc, gsasl_strerror (rc));
      46                 :            : 
      47                 :          1 :   memset (tmp, 42, SIZE);
      48                 :          1 :   memcpy (savetmp, tmp, SIZE);
      49                 :          1 :   tmplen = sizeof (tmp);
      50                 :          1 :   rc = gsasl_nonce (tmp, tmplen);
      51         [ -  + ]:          1 :   if (rc != GSASL_OK)
      52                 :          0 :     fail ("gsasl_nonce %d: %s\n", rc, gsasl_strerror (rc));
      53         [ -  + ]:          1 :   if (memcmp (savetmp, tmp, SIZE) == 0)
      54                 :          0 :     fail ("gsasl_nonce memcmp fail\n");
      55                 :          1 :   success ("gsasl_nonce\n");
      56                 :            : 
      57                 :            : #if 0
      58                 :            :   /* This often times out on build machines. */
      59                 :            :   memcpy (savetmp, tmp, SIZE);
      60                 :            :   tmplen = sizeof (tmp);
      61                 :            :   rc = gsasl_random (tmp, tmplen);
      62                 :            :   if (rc != GSASL_OK)
      63                 :            :     fail ("gsasl_random %d: %s\n", rc, gsasl_strerror (rc));
      64                 :            :   if (memcmp (savetmp, tmp, SIZE) == 0)
      65                 :            :     fail ("gsasl_random memcmp fail\n");
      66                 :            :   success ("gsasl_random\n");
      67                 :            : #endif
      68                 :            : 
      69                 :          1 :   rc = gsasl_md5 ("abc", 3, &hash);
      70         [ -  + ]:          1 :   if (rc != GSASL_OK)
      71                 :          0 :     fail ("gsasl_md5 %d: %s\n", rc, gsasl_strerror (rc));
      72         [ -  + ]:          1 :   if (memcmp (hash, "\x90\x01\x50\x98\x3C\xD2\x4F\xB0"
      73                 :            :               "\xD6\x96\x3F\x7D\x28\xE1\x7F\x72", 16) != 0)
      74                 :          0 :     fail ("gsasl_md5 memcmp fail\n");
      75                 :          1 :   success ("gsasl_md5\n");
      76                 :          1 :   gsasl_free (hash);
      77                 :            : 
      78                 :          1 :   rc = gsasl_hmac_md5 ("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
      79                 :            :                        "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16,
      80                 :            :                        "Hi There", 8, &hash);
      81         [ -  + ]:          1 :   if (rc != GSASL_OK)
      82                 :          0 :     fail ("gsasl_hmac_md5 %d: %s\n", rc, gsasl_strerror (rc));
      83         [ -  + ]:          1 :   if (memcmp (hash, "\x92\x94\x72\x7a\x36\x38\xbb\x1c"
      84                 :            :               "\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d", 16) != 0)
      85                 :          0 :     fail ("gsasl_hmac_md5 memcmp fail\n");
      86                 :          1 :   success ("gsasl_hmac_md5\n");
      87                 :          1 :   gsasl_free (hash);
      88                 :            : 
      89                 :          1 :   rc = gsasl_sha1 ("abc", 3, &hash);
      90         [ -  + ]:          1 :   if (rc != GSASL_OK)
      91                 :          0 :     fail ("gsasl_sha1 %d: %s\n", rc, gsasl_strerror (rc));
      92         [ -  + ]:          1 :   if (memcmp (hash, "\xa9\x99\x3e\x36\x47\x06\x81\x6a\xba\x3e\x25"
      93                 :            :               "\x71\x78\x50\xc2\x6c\x9c\xd0\xd8\x9d", 20) != 0)
      94                 :          0 :     fail ("gsasl_sha1 memcmp fail\n");
      95                 :          1 :   success ("gsasl_sha1\n");
      96                 :          1 :   gsasl_free (hash);
      97                 :            : 
      98                 :          1 :   rc = gsasl_hmac_sha1 ("\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
      99                 :            :                         "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b", 16,
     100                 :            :                         "Hi There", 8, &hash);
     101         [ -  + ]:          1 :   if (rc != GSASL_OK)
     102                 :          0 :     fail ("gsasl_hmac_sha1 %d: %s\n", rc, gsasl_strerror (rc));
     103         [ -  + ]:          1 :   if (memcmp (hash, "\x67\x5b\x0b\x3a\x1b\x4d\xdf\x4e\x12\x48\x72"
     104                 :            :               "\xda\x6c\x2f\x63\x2b\xfe\xd9\x57\xe9", 20) != 0)
     105                 :          0 :     fail ("gsasl_hmac_sha1 memcmp fail\n");
     106                 :          1 :   success ("gsasl_hmac_sha1\n");
     107                 :          1 :   gsasl_free (hash);
     108                 :            : 
     109                 :          1 :   gsasl_done (ctx);
     110                 :          1 : }

Generated by: LCOV version 1.9