=pod

=encoding utf-8

=head1 NAME

Net::BitTorrent::DHT::Security - BEP 42 security extensions for BitTorrent DHT

=head1 SYNOPSIS

    use Net::BitTorrent::DHT::Security;
    my $sec = Net::BitTorrent::DHT::Security->new;

    my $id = $sec->generate_node_id("127.0.0.1");
    if ($sec->validate_node_id($id, "127.0.0.1")) {
        say "Node ID is valid for this IP";
    }

=head1 DESCRIPTION

This class implements the security extensions defined in BEP 42. It provides methods for generating and validating Node
IDs based on the node's IP address to prevent Sybil attacks and routing table poisoning.

=head2 CRC32c Implementation

This module includes a pure-Perl implementation of the CRC32c (Castagnoli) polynomial (0x82F63B78), which is required
by BEP 42 for Node ID calculation.

=head1 METHODS

=head2 generate_node_id( $ip, $seed? )

Generates a 20-byte Node ID compliant with BEP 42 for the given IP address. An optional 1-byte seed (0-255) can be
provided.

=head2 validate_node_id( $id, $ip )

Returns true if the provided Node ID is valid for the given IP address according to the BEP 42 criteria (matching the
first 21 bits of the ID).

=head1 SEE ALSO

BEP 42: L<http://www.bittorrent.org/beps/bep_0042.html>

=head1 AUTHOR

Sanko Robinson E<lt>sanko@cpan.orgE<gt>

=head1 COPYRIGHT

Copyright (C) 2008-2026 by Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.

=cut
