{
    "content": [
        {
            "type": "text",
            "text": "# Crypt::AuthEnc::GCM (perldoc)\n\n## NAME\n\nCrypt::AuthEnc::GCM - Authenticated encryption in GCM mode\n\n## SYNOPSIS\n\n### OO interface\nuse Crypt::AuthEnc::GCM;\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\nmy $tag = $ae->encryptdone();\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\nmy $tag = $ae->decryptdone();\ndie \"decrypt failed\" unless $tag eq $expectedtag;\n#or\nmy $result = $ae->decryptdone($expectedtag); # 0 or 1\n### functional interface\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\nmy ($ciphertext, $tag) = gcmencryptauthenticate('AES', $key, $iv, $adata, $plaintext);\nmy $plaintext = gcmdecryptverify('AES', $key, $iv, $adata, $ciphertext, $tag);\n\n## DESCRIPTION\n\nGalois/Counter Mode (GCM) - provides encryption and authentication.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **EXPORT**\n- **FUNCTIONS**\n- **METHODS**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Crypt::AuthEnc::GCM",
        "section": "",
        "mode": "perldoc",
        "summary": "Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode",
        "synopsis": "### OO interface\nuse Crypt::AuthEnc::GCM;\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\nmy $tag = $ae->encryptdone();\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\nmy $tag = $ae->decryptdone();\ndie \"decrypt failed\" unless $tag eq $expectedtag;\n#or\nmy $result = $ae->decryptdone($expectedtag); # 0 or 1\n### functional interface\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\nmy ($ciphertext, $tag) = gcmencryptauthenticate('AES', $key, $iv, $adata, $plaintext);\nmy $plaintext = gcmdecryptverify('AES', $key, $iv, $adata, $ciphertext, $tag);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 31,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "EXPORT",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "FUNCTIONS",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 40,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Crypt::AuthEnc::GCM - Authenticated encryption in GCM mode\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "### OO interface\nuse Crypt::AuthEnc::GCM;\n\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\nmy $tag = $ae->encryptdone();\n\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::GCM->new(\"AES\", $key, $iv);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\nmy $tag = $ae->decryptdone();\ndie \"decrypt failed\" unless $tag eq $expectedtag;\n\n#or\nmy $result = $ae->decryptdone($expectedtag); # 0 or 1\n\n### functional interface\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\n\nmy ($ciphertext, $tag) = gcmencryptauthenticate('AES', $key, $iv, $adata, $plaintext);\nmy $plaintext = gcmdecryptverify('AES', $key, $iv, $adata, $ciphertext, $tag);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Galois/Counter Mode (GCM) - provides encryption and authentication.\n",
                "subsections": []
            },
            "EXPORT": {
                "content": "Nothing is exported by default.\n\nYou can export selected functions:\n\nuse Crypt::AuthEnc::GCM qw(gcmencryptauthenticate gcmdecryptverify);\n",
                "subsections": []
            },
            "FUNCTIONS": {
                "content": "gcmencryptauthenticate\nmy ($ciphertext, $tag) = gcmencryptauthenticate($cipher, $key, $iv, $adata, $plaintext);\n\n# $cipher .. 'AES' or name of any other cipher with 16-byte block len\n# $key ..... AES key of proper length (128/192/256bits)\n# $iv ...... initialization vector\n# $adata ... additional authenticated data\n\ngcmdecryptverify\nmy $plaintext = gcmdecryptverify($cipher, $key, $iv, $adata, $ciphertext, $tag);\n# on error returns undef\n",
                "subsections": []
            },
            "METHODS": {
                "content": "new\nmy $ae = Crypt::AuthEnc::GCM->new($cipher, $key);\n#or\nmy $ae = Crypt::AuthEnc::GCM->new($cipher, $key, $iv);\n\n# $cipher .. 'AES' or name of any other cipher\n# $key ..... encryption key of proper length\n# $iv ...... initialization vector (optional, you can set it later via ivadd method)\n\nivadd\nSet initialization vector (IV).\n\n$ae->ivadd($ivdata);                        #can be called multiple times\n\nadataadd\nAdd additional authenticated data. Can be called after all \"ivadd\" calls but before the first\n\"encryptadd\" or \"decryptadd\".\n\n$ae->adataadd($aaddata);                    # can be called multiple times\n\nencryptadd\n$ciphertext = $ae->encryptadd($data);        # can be called multiple times\n\nencryptdone\n$tag = $ae->encryptdone();                   # returns $tag value\n\ndecryptadd\n$plaintext = $ae->decryptadd($ciphertext);   # can be called multiple times\n\ndecryptdone\nmy $tag = $ae->decryptdone;           # returns $tag value\n#or\nmy $result = $ae->decryptdone($tag);  # returns 1 (success) or 0 (failure)\n\nreset\n$ae->reset;\n\nclone\nmy $aenew = $ae->clone;\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "*   CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::EAX, Crypt::AuthEnc::OCB\n\n*   <https://en.wikipedia.org/wiki/Galois/CounterMode>\n",
                "subsections": []
            }
        }
    }
}