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 $ct = $ae->encrypt_add('data1');
17 $ct = $ae->encrypt_add('data2');
18 $ct = $ae->encrypt_add('data3');
19 $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 $pt = $ae->decrypt_add('ciphertext1');
26 $pt = $ae->decrypt_add('ciphertext2');
27 $pt = $ae->decrypt_add('ciphertext3');
28 $tag = $ae->decrypt_done();
29 die "decrypt failed" unless $tag eq $expected_tag;
30
31 #or
32 my $result = $ae->decrypt_done($expected_tag) die "decrypt failed";
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
65 # on error returns undef
66
68 new
69 my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv);
70 #or
71 my $ae = Crypt::AuthEnc::EAX->new($cipher, $key, $iv, $adata);
72
73 # $cipher .. 'AES' or name of any other cipher with 16-byte block len
74 # $key ..... AES key of proper length (128/192/256bits)
75 # $iv ...... unique initialization vector (no need to keep it secret)
76 # $adata ... additional authenticated data (optional)
77
78 adata_add
79 $ae->adata_add($adata); #can be called multiple times
80
81 encrypt_add
82 $ciphertext = $ae->encrypt_add($data); #can be called multiple times
83
84 encrypt_done
85 $tag = $ae->encrypt_done();
86
87 decrypt_add
88 $plaintext = $ae->decrypt_add($ciphertext); #can be called multiple times
89
90 decrypt_done
91 my $result = $ae->decrypt_done($tag); # returns 1 (success) or 0 (failure)
92 #or
93 my $tag = $ae->decrypt_done; # returns $tag value
94
95 clone
96 my $ae_new = $ae->clone;
97
99 · CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::GCM,
100 Crypt::AuthEnc::OCB
101
102 · <https://en.wikipedia.org/wiki/EAX_mode>
103
104
105
106perl v5.30.0 2019-07-26 Crypt::AuthEnc::EAX(3)