Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp333539pxb; Mon, 25 Apr 2022 10:51:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZZJ4PKJsBIrMdZU1oO7tBw88hJxqnQ6A9AJGqww0rrlr2T9zPbwwNpLQFMm3RDtXH5/NA X-Received: by 2002:a17:907:d09:b0:6e8:3eef:3192 with SMTP id gn9-20020a1709070d0900b006e83eef3192mr16904128ejc.122.1650909080335; Mon, 25 Apr 2022 10:51:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650909080; cv=none; d=google.com; s=arc-20160816; b=dZI4eH4nyYUEn7UMuJDQp5/bD676ZPRVG+svIjDowUh1dOmyyVFX4hZA0ZHqNrDQXQ 2XkiNZax7PYT2lJoSf51Xmj7t96eiSav9jSuwU0ACuSQwyC/yGlgFxtrgnD4oY0wRH5p fXVmLceU/2iDBL42UAyj5hpndl+MHojjZPzZSyE5mDHlmHPiS6DYOy+yxvtuHcUlL+eb GhPizjvgeLnyTbntL0wWv9i7tKdVZ5SlXkMO843tjSKMhl+Xw+TOar/36bKIT4UEVYyH U1leLwCdQnLPreJd4wOnVFvaL2/G5JyM8Vk4vGN/Xdb3tTF0/qsm0G8UPlg16iJ4aE00 RR3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=wILZ7CotWfpcpyiMP4HlmOVKNPpwxnFkTAevaPptan8=; b=en5JctuyXC40o9XCaFcJVum5X/Rd2IMpFEWiKXtSK12o+f0YKMJsef3aRZ75YOBUh/ sn98OZH8LwpQRBUrpkCHIX0ig6TuM3OIVf0DAzrxbs7qRuHixWl+5Bh2eD0EYqT3CnTa WAIhPSAb2pv+GNNl3l3cHz0dU029s4v4OVkYEoFaOuVRCwITG0kOpbsxCQw3djErsypR vHeKhT4vwgNfacK/DCxu4zd252DNoB3A1SjbtXcFgnxB60ra3KNjXvlX5jpgdBeBTvRM TdTj40TDSGvVexsbG08I9GS5aN4kxhF34+BcY2ppAZLjVFLt4ENAy1E/LcaSy5fIY3gb zEwA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n26-20020a50935a000000b00423e1efca48si4290146eda.198.2022.04.25.10.50.41; Mon, 25 Apr 2022 10:51:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235871AbiDYNCi convert rfc822-to-8bit (ORCPT + 99 others); Mon, 25 Apr 2022 09:02:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238944AbiDYNCb (ORCPT ); Mon, 25 Apr 2022 09:02:31 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 235C213F11 for ; Mon, 25 Apr 2022 05:59:26 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-246-RsRt4rMLMJSg1HNL0-UwSg-1; Mon, 25 Apr 2022 13:59:24 +0100 X-MC-Unique: RsRt4rMLMJSg1HNL0-UwSg-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Mon, 25 Apr 2022 13:59:23 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.033; Mon, 25 Apr 2022 13:59:23 +0100 From: David Laight To: 'Mikulas Patocka' CC: 'Linus Torvalds' , Andy Shevchenko , device-mapper development , "Linux Kernel Mailing List" , Linux Crypto Mailing List , Herbert Xu , "David S. Miller" , Mike Snitzer , Mimi Zohar , Milan Broz Subject: RE: [PATCH] hex2bin: make the function hex_to_bin constant-time Thread-Topic: [PATCH] hex2bin: make the function hex_to_bin constant-time Thread-Index: AQHYWCRFXKVloRHnAkSgNzNf81l36q0AX1CggAAH/4CAAC5kEA== Date: Mon, 25 Apr 2022 12:59:23 +0000 Message-ID: References: <789f0463ce974e90a93f4dbf8c471156@AcuMS.aculab.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Mikulas Patocka > Sent: 25 April 2022 12:04 > > On Mon, 25 Apr 2022, David Laight wrote: > > > From: Linus Torvalds > > > Sent: 24 April 2022 22:42 > > > > > > On Sun, Apr 24, 2022 at 2:37 PM Linus Torvalds > > > wrote: > > > > > > > > Finally, for the same reason - please don't use ">> 8". Because I do > > > > not believe that bit 8 is well-defined in your arithmetic. The *sign* > > > > bit will be, but I'm not convinced bit 8 is. > > > > > > Hmm.. I think it's ok. It can indeed overflow in 'char' and change the > > > sign in bit #7, but I suspect bit #8 is always fine. > > > > > > Still, If you want to just extend the sign bit, ">> 31" _is_ the > > > obvious thing to use (yeah, yeah, properly "sizeof(int)*8-1" or > > > whatever, you get my drift). > > > > Except that right shifts of signed values are UB. > > In particular it has always been valid to do an unsigned > > shift right on a 2's compliment negative number. > > > > David > > Yes. All the standard versions (C89, C99, C11, C2X) say that right shift > of a negative value is implementation-defined. > > So, we should cast it to "unsigned" before shifting it. Except that the intent appears to be to replicate the sign bit. If it is 'implementation defined' (rather than suddenly being UB) it might be that the linux kernel requires sign propagating right shifts of negative values. This is typically what happens on 2's compliment systems. But not all small cpu have the required shift instruction. OTOH all the ones bit enough to run Linux probably do. (And gcc doesn't support '1's compliment' or 'sign overpunch' cpus.) The problem is that the compiler writers seem to be entering a mindset where they are optimising code based on UB behaviour. So given: void foo(int x) { if (x >> 1 < 0) return; do_something(); } they decide the test is UB, so can always be assumed to be true and thus do_something() is compiled away. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)