/src/postgres/src/port/timingsafe_bcmp.c
Line | Count | Source (jump to first uncovered line) |
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 | | timingsafe_bcmp(const void *b1, const void *b2, size_t n) |
31 | 0 | { |
32 | | #ifdef USE_SSL |
33 | | return CRYPTO_memcmp(b1, b2, n); |
34 | | #else |
35 | 0 | const unsigned char *p1 = b1, |
36 | 0 | *p2 = b2; |
37 | 0 | int ret = 0; |
38 | |
|
39 | 0 | for (; n > 0; n--) |
40 | 0 | ret |= *p1++ ^ *p2++; |
41 | 0 | return (ret != 0); |
42 | 0 | #endif |
43 | 0 | } |