LCOV - code coverage report
Current view: top level - src/port - timingsafe_bcmp.c (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 2 2 100.0 %
Date: 2025-04-24 12:15:10 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * src/port/timingsafe_bcmp.c
       3             :  *
       4             :  *  $OpenBSD: timingsafe_bcmp.c,v 1.3 2015/08/31 02:53:57 guenther Exp $
       5             :  */
       6             : 
       7             : /*
       8             :  * Copyright (c) 2010 Damien Miller.  All rights reserved.
       9             :  *
      10             :  * Permission to use, copy, modify, and distribute this software for any
      11             :  * purpose with or without fee is hereby granted, provided that the above
      12             :  * copyright notice and this permission notice appear in all copies.
      13             :  *
      14             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      15             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      16             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      17             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      18             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      19             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      20             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      21             :  */
      22             : 
      23             : #include "c.h"
      24             : 
      25             : #ifdef USE_SSL
      26             : #include <openssl/crypto.h>
      27             : #endif
      28             : 
      29             : int
      30          32 : timingsafe_bcmp(const void *b1, const void *b2, size_t n)
      31             : {
      32             : #ifdef USE_SSL
      33          32 :     return CRYPTO_memcmp(b1, b2, n);
      34             : #else
      35             :     const unsigned char *p1 = b1,
      36             :                *p2 = b2;
      37             :     int         ret = 0;
      38             : 
      39             :     for (; n > 0; n--)
      40             :         ret |= *p1++ ^ *p2++;
      41             :     return (ret != 0);
      42             : #endif
      43             : }

Generated by: LCOV version 1.14