From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 19518 invoked from network); 2 May 2021 15:29:46 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 2 May 2021 15:29:46 -0000 Received: from mail-yb1-f178.google.com ([209.85.219.178]) by 1ess; Sun May 2 11:24:41 -0400 2021 Received: by mail-yb1-f178.google.com with SMTP id 82so4326843yby.7 for <9front@9front.org>; Sun, 02 May 2021 08:24:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=oK7A2MqWgcZYV0iJHtK8dIMK02qsvt7fsx0GCY0cPyU=; b=THUlQeAs+/D0+hc6PP6Ko328NOFfynzhFzn7PAThHWkuRH4NvoWkwdldz1gxKvRWEK f2wddww2tZ4DFchYJXYm2aiaxBHdFrcTu8dHYjTU5g0GMoVXkLTff8jiC168iE2pFlIF Lkl+vnROgwEEni5B4ffOEfbHEwq27gwSIhuUa4BMq4V6nNhRFn5eu+9+RIl4INm037tj oqRIckN5qPFQYJsemx2UG1AMh05lU/8SIinnIfN3P9B1+L0IjZ3nO37Au9jPVd7uPg2T 4MN+5x4CuOnp4YixTLZyjhNWK/tDMfOccE00aXiugnw65PE5F24lVzw1kftfKtQ4s2bz ptoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=oK7A2MqWgcZYV0iJHtK8dIMK02qsvt7fsx0GCY0cPyU=; b=RBUwvV23lywsY9WIiXk75HhINSKJq/0uHlvisprJswLji1eOtOEofKuEuA+tY8wGli 9SH+DbCc0k7+ga+FIj1esA3HgaTpt9DRDjFtkaix34H6kzdkiRMHsErWnssRfqhJ3Ez+ huwbvJCdKuHfNGijMzl9oFqgBNi6MWP6ORGWXZVNeRMc21hwIY3DUaff9lf5XFX5aF8Z FqRsJLHvbrxLjYIoEpIZu6tVxeDs4YnlvP6UbmS1LXqdsSVusp8y89aD8cmQQascJ/m6 of2C1TatwGPy/TYjQ/vxqNwoSEXRQAWXERSOhqqF/Q00N9VtwNmq0WF4+6noupLreQuU 8LVg== X-Gm-Message-State: AOAM530olxg4l+JOflBLfyJW4a/DGUqN4efriXMIdJEBQGR9tnXkx9G0 l9BJlHCtHQRimwFeLXBPsXSez/X5DmfSkdzVCMzmGzsmJqw= X-Google-Smtp-Source: ABdhPJzaZlWBsGvZX5OjU1eBjZps3VMI2BJiWHZSyrvDMg/AM0HzSkl2yviRDyoyhT1iS6SNUv+ThVcVgHIxYoDIQ8I= X-Received: by 2002:a9d:6d1a:: with SMTP id o26mr11692223otp.122.1619965290751; Sun, 02 May 2021 07:21:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:3041:0:0:0:0:0 with HTTP; Sun, 2 May 2021 07:21:30 -0700 (PDT) In-Reply-To: <4AD2CDAB319DDBA8AC51728729CBF224@felloff.net> References: <4AD2CDAB319DDBA8AC51728729CBF224@felloff.net> From: kemal Date: Sun, 2 May 2021 14:21:30 +0000 Message-ID: To: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: component-scale hosting DOM API-oriented framework Subject: [9front] Re: memory(2): mention tsmemcmp Reply-To: 9front@9front.org Precedence: bulk OK, added an explanation. 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 .br @@ -24,6 +24,11 @@ .PP .B void* memset(void *s, int c, ulong n) +.PP +.B #include +.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, this way it's runtime is function of +.I n +and not something that can lead clues to attackers. .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 on +.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's vulnerable to timing attacks. Instead, +.I tsmemcmp +should be used.