From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 319E41FF16F
	for <inbox@lore.proxmox.com>; Tue, 10 Jun 2025 16:04:00 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 297EF1DDD4;
	Tue, 10 Jun 2025 16:04:21 +0200 (CEST)
Message-ID: <1474d1cb-cdf2-41a1-8fff-841c7f5c1cfc@proxmox.com>
Date: Tue, 10 Jun 2025 16:03:47 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
References: <20250603075558.627850-1-alexandre.derumier@groupe-cyllene.com>
 <mailman.237.1748948724.395.pve-devel@lists.proxmox.com>
Content-Language: en-US
From: Fiona Ebner <f.ebner@proxmox.com>
In-Reply-To: <mailman.237.1748948724.395.pve-devel@lists.proxmox.com>
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.032 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: Re: [pve-devel] [PATCH qemu-server 01/13] blockdev: cmdline: add
 blockdev syntax support
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

The way the node name encoding is implemented is problematic as we
operate outside of integer ranges:

[I] febner@dev8 ~/repos/pve/qemu-server (qemu-blockdev-options)> cat asdf.pm
use strict;
use warnings;

use Digest::SHA;

sub encode_base62 {
    my ($input) = @_;

    my @chars = ('0'..'9', 'A'..'Z', 'a'..'z');
    my $base = 62;
    my $value = 0;

    my $result = '';
    for my $byte (unpack('C*', $input)) {
	$value = $value * 256 + $byte;
	print "$value\n";
    }
}

encode_base62(Digest::SHA::sha1("foo"));
[I] febner@dev8 ~/repos/pve/qemu-server (qemu-blockdev-options)> perl
asdf.pm
11
3054
782023
200198069
51250705898
13120180709951
3358766261747471
859844163007352795
2.20120105729882e+20
5.63507470668499e+22
1.44257912491136e+25
3.69300255977307e+27
9.45408655301907e+29
2.42024615757288e+32
6.19583016338658e+34
1.58613252182696e+37
4.06049925587703e+39
1.03948780950452e+42
2.66108879233157e+44
6.81238730836881e+46

Also, while the use case here shouldn't be cryptographically sensitive,
you never know, so I'll just use a different hash function than sha1.
I'll cut off the result from that hash to 30 hex digits. Then we still
have one letter for the prefix of the node name.

As for collision probability, that will be 120 bits and should be more
than enough, even 2^50 nodes have a very small probability to collide
with that:

>>> math.log2(16**30)
120.0
>>> d=2**120
>>> n=2**50
>>> 1 - math.exp(-(n*n)/(2*d))
4.768370445162873e-07



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel