Skip to content

ServiceId is too short #2

@jedisct1

Description

@jedisct1

Hi,

And congrats for that nice project!

Just glancing at the source code:

// Generate service ID from name using cryptographic hash to prevent collisions
fn generateServiceId(name: []const u8) tunnel.ServiceId {
    var hasher = std.crypto.hash.Blake3.init(.{});
    hasher.update(name);
    var hash: [32]u8 = undefined;
    hasher.final(&hash);

    // Use first 2 bytes of hash, ensure non-zero
    const id = std.mem.readInt(u16, hash[0..2], .little);
    return if (id == 0) 1 else id;
}

2 bytes is not enough to prevent collisions. And if you really want a short identifier (like 2, 4 or 8 bytes) on short text inputs, std.hash.crc, std.hash.fnv or std.hash.xxhash.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions