diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/string/timingsafe_bcmp.3 | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/lib/libc/string/timingsafe_bcmp.3 b/src/lib/libc/string/timingsafe_bcmp.3 new file mode 100644 index 0000000000..0886731ce7 --- /dev/null +++ b/src/lib/libc/string/timingsafe_bcmp.3 | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | .\" $OpenBSD: timingsafe_bcmp.3,v 1.1 2014/06/13 02:12:17 matthew Exp $ | ||
| 2 | .\" | ||
| 3 | .\" Copyright (c) 2014 Google Inc. | ||
| 4 | .\" | ||
| 5 | .\" Permission to use, copy, modify, and distribute this software for any | ||
| 6 | .\" purpose with or without fee is hereby granted, provided that the above | ||
| 7 | .\" copyright notice and this permission notice appear in all copies. | ||
| 8 | .\" | ||
| 9 | .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | .Dd $Mdocdate: June 13 2014 $ | ||
| 17 | .Dt TIMINGSAFE_BCMP 3 | ||
| 18 | .Os | ||
| 19 | .Sh NAME | ||
| 20 | .Nm timingsafe_bcmp , | ||
| 21 | .Nm timingsafe_memcmp | ||
| 22 | .Nd timing-safe byte sequence comparisons | ||
| 23 | .Sh SYNOPSIS | ||
| 24 | .In string.h | ||
| 25 | .Ft int | ||
| 26 | .Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len" | ||
| 27 | .Ft int | ||
| 28 | .Fn timingsafe_memcmp "const void *b1" "const void *b2" "size_t len" | ||
| 29 | .Sh DESCRIPTION | ||
| 30 | The | ||
| 31 | .Fn timingsafe_bcmp | ||
| 32 | and | ||
| 33 | .Fn timingsafe_memcmp | ||
| 34 | functions lexicographically compare the first | ||
| 35 | .Fa len | ||
| 36 | bytes (each interpreted as an | ||
| 37 | .Vt unsigned char ) | ||
| 38 | pointed to by | ||
| 39 | .Fa b1 | ||
| 40 | and | ||
| 41 | .Fa b2 . | ||
| 42 | .Pp | ||
| 43 | Additionally, their running times are independent of the byte sequences compared, | ||
| 44 | making them safe to use for comparing secret values such as cryptographic MACs. | ||
| 45 | In contrast, | ||
| 46 | .Xr bcmp 3 | ||
| 47 | and | ||
| 48 | .Xr memcmp 3 | ||
| 49 | may short-circuit after finding the first differing byte. | ||
| 50 | .Sh RETURN VALUES | ||
| 51 | The | ||
| 52 | .Fn timingsafe_bcmp | ||
| 53 | function returns 0 or 1 if the byte sequence pointed to by | ||
| 54 | .Fa b1 | ||
| 55 | compares equal to or not equal to (respectively) | ||
| 56 | the byte sequence pointed to by | ||
| 57 | .Fa b2 . | ||
| 58 | .Pp | ||
| 59 | The | ||
| 60 | .Fn timingsafe_memcmp | ||
| 61 | function returns \-1, 0, or 1 if the byte sequence pointed to by | ||
| 62 | .Fa b1 | ||
| 63 | compares less than, equal to, or greater than (respectively) | ||
| 64 | the byte sequence pointed to by | ||
| 65 | .Fa b2 . | ||
| 66 | .Pp | ||
| 67 | Note that these return values are compatible with, but stricter than, | ||
| 68 | the ones specified for | ||
| 69 | .Xr bcmp 3 | ||
| 70 | and | ||
| 71 | .Xr memcmp 3 . | ||
| 72 | .Sh SEE ALSO | ||
| 73 | .Xr bcmp 3 , | ||
| 74 | .Xr memcmp 3 | ||
| 75 | .Sh STANDARDS | ||
| 76 | The | ||
| 77 | .Fn timingsafe_bcmp | ||
| 78 | and | ||
| 79 | .Fn timingsafe_memcmp | ||
| 80 | functions are | ||
| 81 | .Ox | ||
| 82 | extensions. | ||
| 83 | .Sh HISTORY | ||
| 84 | The | ||
| 85 | .Fn timingsafe_bcmp | ||
| 86 | function first appeared in | ||
| 87 | .Ox 4.9 . | ||
| 88 | .Pp | ||
| 89 | The | ||
| 90 | .Fn timingsafe_memcmp | ||
| 91 | function first appeared in | ||
| 92 | .Ox 5.6 . | ||
