1Crypt::AuthEnc::EAX(3)User Contributed Perl DocumentationCrypt::AuthEnc::EAX(3)
2
3
4
6 Crypt::AuthEnc::EAX - Authenticated encryption in EAX mode
7
9 ### OO interface
10 use Crypt::AuthEnc::EAX;
11
12 # encrypt and authenticate
13 my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
14 $ae->adata_add('additional_authenticated_data1');
15 $ae->adata_add('additional_authenticated_data2');
16 my $ct = $ae->encrypt_add('data1');
17 $ct .= $ae->encrypt_add('data2');
18 $ct .= $ae->encrypt_add('data3');
19 my $tag = $ae->encrypt_done();
20
21 # decrypt and verify
22 my $ae = Crypt::AuthEnc::EAX->new("AES", $key, $iv);
23 $ae->adata_add('additional_authenticated_data1');
24 $ae->adata_add('additional_authenticated_data2');
25 my $pt = $ae->decrypt_add('ciphertext1');
26 $pt .= $ae->decrypt_add('ciphertext2');
27 $pt .= $ae->decrypt_add('ciphertext3');
28 my $tag = $ae->decrypt_done();
29 die "decrypt failed" unless $tag eq $expected_tag;
30
31 #or
32 my $result = $ae->decrypt_done($expected_tag); # 0 or 1
33
34 ### functional interface
35 use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
36
37 my ($ciphertext, $tag) = eax_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
38 my $plaintext = eax_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
39
41 EAX is a mode that requires a cipher, CTR and OMAC support and provides
42 encryption and authentication. It is initialized with a random IV that
43 can be shared publicly, additional authenticated data which can be
44 fixed and public, and a random secret symmetric key.
45
47 Nothing is exported by default.
48
49 You can export selected functions:
50
51 use Crypt::AuthEnc::EAX qw(eax_encrypt_authenticate eax_decrypt_verify);
52
54 eax_encrypt_authenticate
55 my ($ciphertext, $tag) = eax_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
56
57 # $cipher .. 'AES' or name of any other cipher with 16-byte block len
58 # $key ..... AES key of proper length (128/192/256bits)
59 # $iv ...... unique initialization vector (no need to keep it secret)
60 # $adata ... additional authenticated data
61
62 eax_decrypt_verify
63 my $plaintext = eax_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
64 # on error returns undef
65
67 new
68 my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv);
69 #or
70 my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv, $adata);
71
72 # $cipher .. 'AES' or name of any other cipher with 16-byte block len
73 # $key ..... AES key of proper length (128/192/256bits)
74 # $iv ...... unique initialization vector (no need to keep it secret)
75 # $adata ... additional authenticated data (optional)
76
77 adata_add
78 $ae->adata_add($adata); # can be called multiple times
79
80 encrypt_add
81 $ciphertext = $ae->encrypt_add($data); # can be called multiple times
82
83 encrypt_done
84 $tag = $ae->encrypt_done(); # returns $tag value
85
86 decrypt_add
87 $plaintext = $ae->decrypt_add($ciphertext); # can be called multiple times
88
89 decrypt_done
90 my $tag = $ae->decrypt_done; # returns $tag value
91 #or
92 my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
93
94 clone
95 my $ae_new = $ae->clone;
96
98 • CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::GCM,
99 Crypt::AuthEnc::OCB
100
101 • <https://en.wikipedia.org/wiki/EAX_mode>
102
103
104
105perl v5.34.0 2022-02-14 Crypt::AuthEnc::EAX(3)