9front - general discussion about 9front
 help / color / mirror / Atom feed
From: umbraticus@prosimetrum.com
To: 9front@9front.org
Subject: Re: [9front] Re: memory(2): mention tsmemcmp
Date: Tue, 04 May 2021 22:40:14 +1200	[thread overview]
Message-ID: <4B6A5210DBF8C513DFF99DAF6C3684A2@prosimetrum.com> (raw)
In-Reply-To: <CABO6shcsCHzF1St2f4WPy0_7Te5Ggumk0MHQFt5SVfeAYzR28g@mail.gmail.com>

Thanks.  Just fixed your itses and suggested some
mild improvements to the wording below.

diff -r 47a307f91238 sys/man/2/memory
--- a/sys/man/2/memory	Fri Apr 30 00:20:39 2021 +0200
+++ b/sys/man/2/memory	Sun May 02 17:20:35 2021 +0300
@@ -1,6 +1,6 @@
 .TH MEMORY 2
 .SH NAME
-memccpy, memchr, memcmp, memcpy, memmove, memset \- memory operations
+memccpy, memchr, memcmp, memcpy, memmove, memset, tsmemcmp \- memory operations
 .SH SYNOPSIS
 .B #include <u.h>
 .br
@@ -24,6 +24,11 @@
 .PP
 .B
 void*	memset(void *s, int c, ulong n)
+.PP
+.B #include <libsec.h>
+.PP
+.B
+int	tsmemcmp(void *s1, void *s2, ulong n)
 .SH DESCRIPTION
 These functions operate efficiently on memory areas
 (arrays of bytes bounded by a count, not terminated by a zero byte).
@@ -103,11 +108,22 @@
 .IR c .
 It returns
 .IR s .
+.PP
+.I Tsmemcmp
+is a variant of
+.I memcmp
+that is safe against timing attacks.
+It does not stop when it sees a difference,
+so that its runtime is a function of
+.I n
+and not something that can give an attacker clues.
 .SH SOURCE
 All these routines have portable C implementations in
 .BR /sys/src/libc/port .
 Most also have machine-dependent assembly language implementations in
 .BR /sys/src/libc/$objtype .
+.I Tsmemcmp
+is found at
+.BR /sys/src/libsec/port/tsmemcmp.c .
 .SH SEE ALSO
 .IR strcat (2)
 .SH BUGS
@@ -124,3 +140,8 @@
 and
 .I memmove
 are handed a negative count, they abort.
+.PP
+.I Memcmp
+should not be used to compare sensitive data,
+as it is vulnerable to timing attacks.
+Instead,
+.I tsmemcmp
+should be used.

  reply	other threads:[~2021-05-04 10:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-29 11:40 [9front] " kemal
2021-04-29 16:32 ` [9front] " kemal
2021-05-02 10:51   ` cinap_lenrek
2021-05-02 14:21     ` kemal
2021-05-04 10:40       ` umbraticus [this message]
2021-05-09 13:10         ` cinap_lenrek
2021-05-09 15:25           ` kemal
2021-05-09 16:10             ` hiro
2021-05-09 19:17               ` kemal
2021-05-15 10:40                 ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B6A5210DBF8C513DFF99DAF6C3684A2@prosimetrum.com \
    --to=umbraticus@prosimetrum.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).