1Crypt::AuthEnc::ChaCha2U0sPeorlyC1o3n0t5r(i3b)uted PerlCDroycputm:e:nAtuatthiEonnc::ChaCha20Poly1305(3)
2
3
4

NAME

6       Crypt::AuthEnc::ChaCha20Poly1305 - Authenticated encryption in
7       ChaCha20Poly1305 mode
8

SYNOPSIS

10        ### OO interface
11        use Crypt::AuthEnc::ChaCha20Poly1305;
12
13        # encrypt and authenticate
14        my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
15        $ae->adata_add('additional_authenticated_data1');
16        $ae->adata_add('additional_authenticated_data2');
17        $ct = $ae->encrypt_add('data1');
18        $ct = $ae->encrypt_add('data2');
19        $ct = $ae->encrypt_add('data3');
20        $tag = $ae->encrypt_done();
21
22        # decrypt and verify
23        my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
24        $ae->adata_add('additional_authenticated_data1');
25        $ae->adata_add('additional_authenticated_data2');
26        $pt = $ae->decrypt_add('ciphertext1');
27        $pt = $ae->decrypt_add('ciphertext2');
28        $pt = $ae->decrypt_add('ciphertext3');
29        $tag = $ae->decrypt_done();
30        die "decrypt failed" unless $tag eq $expected_tag;
31
32        #or
33        my $result = $ae->decrypt_done($expected_tag) die "decrypt failed";
34
35        ### functional interface
36        use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
37
38        my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
39        my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
40

DESCRIPTION

42       Provides encryption and authentication based on ChaCha20 + Poly1305 as
43       defined in RFC 7539 - <https://tools.ietf.org/html/rfc7539>
44

EXPORT

46       Nothing is exported by default.
47
48       You can export selected functions:
49
50         use Crypt::AuthEnc::ChaCha20Poly1305 qw(chacha20poly1305_encrypt_authenticate chacha20poly1305_decrypt_verify);
51

FUNCTIONS

53   chacha20poly1305_encrypt_authenticate
54        my ($ciphertext, $tag) = chacha20poly1305_encrypt_authenticate($key, $iv, $adata, $plaintext);
55
56        # $key ..... key of proper length (128 or 256 bits / 16 or 32 bytes)
57        # $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
58        # $adata ... additional authenticated data (optional)
59
60   chacha20poly1305_decrypt_verify
61        my $plaintext = chacha20poly1305_decrypt_verify($key, $iv, $adata, $ciphertext, $tag);
62
63        # on error returns undef
64

METHODS

66   new
67        my $ae = Crypt::AuthEnc::ChaCha20Poly1305->new($key, $iv);
68
69        # $key ..... encryption key of proper length (128 or 256 bits / 16 or 32 bytes)
70        # $iv ...... initialization vector (64 or 96 bits / 8 or 12 bytes)
71
72   adata_add
73       Add additional authenticated data.  Can be called before the first
74       "encrypt_add" or "decrypt_add";
75
76        $ae->adata_add($aad_data);                       #can be called multiple times
77
78   encrypt_add
79        $ciphertext = $ae->encrypt_add($data);         #can be called multiple times
80
81   encrypt_done
82        $tag = $ae->encrypt_done();
83
84   decrypt_add
85        $plaintext = $ae->decrypt_add($ciphertext);    #can be called multiple times
86
87   decrypt_done
88        my $result = $ae->decrypt_done($tag);  # returns 1 (success) or 0 (failure)
89        #or
90        my $tag = $ae->decrypt_done;           # returns $tag value
91
92   clone
93        my $ae_new = $ae->clone;
94
95   set_iv
96        $ae->set_iv($iv);
97
98   set_iv_rfc7905
99        $ae->set_iv_rfc7905($iv, $seqnum);
100

SEE ALSO

102       ·   CryptX, Crypt::AuthEnc::GCM, Crypt::AuthEnc::CCM,
103           Crypt::AuthEnc::EAX, Crypt::AuthEnc::OCB
104
105       ·   <https://tools.ietf.org/html/rfc7539>
106
107
108
109perl v5.32.1                      2021-03-30Crypt::AuthEnc::ChaCha20Poly1305(3)
Impressum