diff options
Diffstat (limited to 'src/lib/libc/string/bcmp.3')
| -rw-r--r-- | src/lib/libc/string/bcmp.3 | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/src/lib/libc/string/bcmp.3 b/src/lib/libc/string/bcmp.3 index 118c55c579..1660b4356b 100644 --- a/src/lib/libc/string/bcmp.3 +++ b/src/lib/libc/string/bcmp.3 | |||
| @@ -11,11 +11,7 @@ | |||
| 11 | .\" 2. Redistributions in binary form must reproduce the above copyright | 11 | .\" 2. Redistributions in binary form must reproduce the above copyright |
| 12 | .\" notice, this list of conditions and the following disclaimer in the | 12 | .\" notice, this list of conditions and the following disclaimer in the |
| 13 | .\" documentation and/or other materials provided with the distribution. | 13 | .\" documentation and/or other materials provided with the distribution. |
| 14 | .\" 3. All advertising materials mentioning features or use of this software | 14 | .\" 3. Neither the name of the University nor the names of its contributors |
| 15 | .\" must display the following acknowledgement: | ||
| 16 | .\" This product includes software developed by the University of | ||
| 17 | .\" California, Berkeley and its contributors. | ||
| 18 | .\" 4. Neither the name of the University nor the names of its contributors | ||
| 19 | .\" may be used to endorse or promote products derived from this software | 15 | .\" may be used to endorse or promote products derived from this software |
| 20 | .\" without specific prior written permission. | 16 | .\" without specific prior written permission. |
| 21 | .\" | 17 | .\" |
| @@ -31,24 +27,25 @@ | |||
| 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 32 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 33 | .\" | 29 | .\" |
| 34 | .\" from: @(#)bcmp.3 5.4 (Berkeley) 4/19/91 | 30 | .\" $OpenBSD: bcmp.3,v 1.9 2011/07/25 00:38:52 schwarze Exp $ |
| 35 | .\" $Id: bcmp.3,v 1.1.1.1 1995/10/18 08:42:20 deraadt Exp $ | ||
| 36 | .\" | 31 | .\" |
| 37 | .Dd April 19, 1991 | 32 | .Dd $Mdocdate: July 25 2011 $ |
| 38 | .Dt BCMP 3 | 33 | .Dt BCMP 3 |
| 39 | .Os BSD 4.2 | 34 | .Os |
| 40 | .Sh NAME | 35 | .Sh NAME |
| 41 | .Nm bcmp | 36 | .Nm bcmp , |
| 37 | .Nm timingsafe_bcmp | ||
| 42 | .Nd compare byte string | 38 | .Nd compare byte string |
| 43 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
| 44 | .Fd #include <string.h> | 40 | .Fd #include <string.h> |
| 45 | .Ft int | 41 | .Ft int |
| 46 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" | 42 | .Fn bcmp "const void *b1" "const void *b2" "size_t len" |
| 43 | .Ft int | ||
| 44 | .Fn timingsafe_bcmp "const void *b1" "const void *b2" "size_t len" | ||
| 47 | .Sh DESCRIPTION | 45 | .Sh DESCRIPTION |
| 48 | The | 46 | The |
| 49 | .Fn bcmp | 47 | .Fn bcmp |
| 50 | function | 48 | function compares byte string |
| 51 | compares byte string | ||
| 52 | .Fa b1 | 49 | .Fa b1 |
| 53 | against byte string | 50 | against byte string |
| 54 | .Fa b2 , | 51 | .Fa b2 , |
| @@ -59,6 +56,20 @@ bytes long. | |||
| 59 | Zero-length strings are always identical. | 56 | Zero-length strings are always identical. |
| 60 | .Pp | 57 | .Pp |
| 61 | The strings may overlap. | 58 | The strings may overlap. |
| 59 | .Pp | ||
| 60 | The | ||
| 61 | .Fn timingsafe_bcmp | ||
| 62 | function has the same semantics as | ||
| 63 | .Fn bcmp , | ||
| 64 | but its running time is independent of the contents of | ||
| 65 | .Fa b1 | ||
| 66 | and | ||
| 67 | .Fa b2 , | ||
| 68 | making it safe to use for comparing secret values such as cryptographic MACs. | ||
| 69 | In contrast, | ||
| 70 | .Fn bcmp | ||
| 71 | returns after finding the first differing byte, | ||
| 72 | making it vulnerable to timing attacks. | ||
| 62 | .Sh SEE ALSO | 73 | .Sh SEE ALSO |
| 63 | .Xr memcmp 3 , | 74 | .Xr memcmp 3 , |
| 64 | .Xr strcasecmp 3 , | 75 | .Xr strcasecmp 3 , |
| @@ -66,7 +77,12 @@ The strings may overlap. | |||
| 66 | .Xr strcoll 3 , | 77 | .Xr strcoll 3 , |
| 67 | .Xr strxfrm 3 | 78 | .Xr strxfrm 3 |
| 68 | .Sh HISTORY | 79 | .Sh HISTORY |
| 69 | A | 80 | The |
| 70 | .Fn bcmp | 81 | .Fn bcmp |
| 71 | function first appeared in | 82 | function first appeared in |
| 72 | .Bx 4.2 . | 83 | .Bx 4.2 . |
| 84 | .Pp | ||
| 85 | The | ||
| 86 | .Fn timingsafe_bcmp | ||
| 87 | function first appeared in | ||
| 88 | .Ox 4.9 . | ||
