1Crypt::AuthEnc::GCM(3)User Contributed Perl DocumentationCrypt::AuthEnc::GCM(3)
2
3
4

NAME

6       Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode
7

SYNOPSIS

9        ### OO interface
10        use Crypt::AuthEnc::GCM;
11
12        # encrypt and authenticate
13        my $ae = Crypt::AuthEnc::GCM->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::GCM->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::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
36
37        my ($ciphertext, $tag) = gcm_encrypt_authenticate('AES', $key, $iv, $adata, $plaintext);
38        my $plaintext = gcm_decrypt_verify('AES', $key, $iv, $adata, $ciphertext, $tag);
39

DESCRIPTION

41       Galois/Counter Mode (GCM) - provides encryption and authentication.
42

EXPORT

44       Nothing is exported by default.
45
46       You can export selected functions:
47
48         use Crypt::AuthEnc::GCM qw(gcm_encrypt_authenticate gcm_decrypt_verify);
49

FUNCTIONS

51   gcm_encrypt_authenticate
52        my ($ciphertext, $tag) = gcm_encrypt_authenticate($cipher, $key, $iv, $adata, $plaintext);
53
54        # $cipher .. 'AES' or name of any other cipher with 16-byte block len
55        # $key ..... AES key of proper length (128/192/256bits)
56        # $iv ...... initialization vector
57        # $adata ... additional authenticated data
58
59   gcm_decrypt_verify
60        my $plaintext = gcm_decrypt_verify($cipher, $key, $iv, $adata, $ciphertext, $tag);
61
62        # on error returns undef
63

METHODS

65   new
66        my $ae = Crypt::AuthEnc::GCM->new($cipher, $key);
67        #or
68        my $ae = Crypt::AuthEnc::GCM->new($cipher, $key, $iv);
69
70        # $cipher .. 'AES' or name of any other cipher
71        # $key ..... encryption key of proper length
72        # $iv ...... initialization vector (optional, you can set it later via iv_add method)
73
74   iv_add
75       Set initialization vector (IV).
76
77        $ae->iv_add($iv_data);                        #can be called multiple times
78
79   adata_add
80       Add additional authenticated data.  Can be called after all "iv_add"
81       calls but before the first "encrypt_add" or "decrypt_add".
82
83        $ae->adata_add($aad_data);                    #can be called multiple times
84
85   encrypt_add
86        $ciphertext = $ae->encrypt_add($data);        #can be called multiple times
87
88   encrypt_done
89        $tag = $ae->encrypt_done();
90
91   decrypt_add
92        $plaintext = $ae->decrypt_add($ciphertext);   #can be called multiple times
93
94   decrypt_done
95        my $result = $ae->decrypt_done($tag);  # returns 1 (success) or 0 (failure)
96        #or
97        my $tag = $ae->decrypt_done;           # returns $tag value
98
99   reset
100        $ae->reset;
101
102   clone
103        my $ae_new = $ae->clone;
104

SEE ALSO

106       ·   CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::EAX,
107           Crypt::AuthEnc::OCB
108
109       ·   <https://en.wikipedia.org/wiki/Galois/Counter_Mode>
110
111
112
113perl v5.28.0                      2017-09-15            Crypt::AuthEnc::GCM(3)
Impressum