{
    "mode": "perldoc",
    "parameter": "Crypt::AuthEnc::OCB",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Crypt%3A%3AAuthEnc%3A%3AOCB/json",
    "generated": "2026-10-05T17:44:53Z",
    "synopsis": "### OO interface\nuse Crypt::AuthEnc::OCB;\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::OCB->new(\"AES\", $key, $nonce, $taglen);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\n$ct .= $ae->encryptlast('rest of data');\nmy $tag = $ae->encryptdone();\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::OCB->new(\"AES\", $key, $nonce, $taglen);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\n$pt .= $ae->decryptlast('rest of data');\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::OCB qw(ocbencryptauthenticate ocbdecryptverify);\nmy ($ciphertext, $tag) = ocbencryptauthenticate('AES', $key, $nonce, $adata, $taglen, $plaintext);\nmy $plaintext = ocbdecryptverify('AES', $key, $nonce, $adata, $ciphertext, $tag);",
    "sections": {
        "NAME": {
            "content": "Crypt::AuthEnc::OCB - Authenticated encryption in OCBv3 mode\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "### OO interface\nuse Crypt::AuthEnc::OCB;\n\n# encrypt and authenticate\nmy $ae = Crypt::AuthEnc::OCB->new(\"AES\", $key, $nonce, $taglen);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $ct = $ae->encryptadd('data1');\n$ct .= $ae->encryptadd('data2');\n$ct .= $ae->encryptadd('data3');\n$ct .= $ae->encryptlast('rest of data');\nmy $tag = $ae->encryptdone();\n\n# decrypt and verify\nmy $ae = Crypt::AuthEnc::OCB->new(\"AES\", $key, $nonce, $taglen);\n$ae->adataadd('additionalauthenticateddata1');\n$ae->adataadd('additionalauthenticateddata2');\nmy $pt = $ae->decryptadd('ciphertext1');\n$pt .= $ae->decryptadd('ciphertext2');\n$pt .= $ae->decryptadd('ciphertext3');\n$pt .= $ae->decryptlast('rest of data');\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::OCB qw(ocbencryptauthenticate ocbdecryptverify);\n\nmy ($ciphertext, $tag) = ocbencryptauthenticate('AES', $key, $nonce, $adata, $taglen, $plaintext);\nmy $plaintext = ocbdecryptverify('AES', $key, $nonce, $adata, $ciphertext, $tag);\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module implements OCB v3 according to <https://tools.ietf.org/html/rfc7253>\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "Nothing is exported by default.\n\nYou can export selected functions:\n\nuse Crypt::AuthEnc::OCB qw(ocbencryptauthenticate ocbdecryptverify);\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "ocbencryptauthenticate\nmy ($ciphertext, $tag) = ocbencryptauthenticate($cipher, $key, $nonce, $adata, $taglen, $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# $nonce ... unique nonce/salt (no need to keep it secret)\n# $adata ... additional authenticated data\n# $taglen . required length of output tag\n\nocbdecryptverify\nmy $plaintext = ocbdecryptverify($cipher, $key, $nonce, $adata, $ciphertext, $tag);\n# on error returns undef\n",
            "subsections": []
        },
        "METHODS": {
            "content": "new\nmy $ae = Crypt::AuthEnc::OCB->new($cipher, $key, $nonce, $taglen);\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# $nonce ... unique nonce/salt (no need to keep it secret)\n# $taglen . required length of output tag\n\nadataadd\n$ae->adataadd($adata);                        #can be called multiple times\n\nencryptadd\n$ciphertext = $ae->encryptadd($data);         # can be called multiple times\n\n#BEWARE: size of $data has to be multiple of blocklen (16 for AES)\n\nencryptlast\n$ciphertext = $ae->encryptlast($data);\n\nencryptdone\n$tag = $ae->encryptdone();                    # returns $tag value\n\ndecryptadd\n$plaintext = $ae->decryptadd($ciphertext);    # can be called multiple times\n\n#BEWARE: size of $ciphertext has to be multiple of blocklen (16 for AES)\n\ndecryptlast\n$plaintext = $ae->decryptlast($data);\n\ndecryptdone\nmy $tag = $ae->decryptdone;           # returns $tag value\n#or\nmy $result = $ae->decryptdone($tag);  # returns 1 (success) or 0 (failure)\n\nclone\nmy $aenew = $ae->clone;\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   CryptX, Crypt::AuthEnc::CCM, Crypt::AuthEnc::GCM, Crypt::AuthEnc::EAX\n\n*   <https://en.wikipedia.org/wiki/OCBmode>\n\n*   <https://tools.ietf.org/html/rfc7253>\n",
            "subsections": []
        }
    },
    "summary": "Crypt::AuthEnc::OCB - Authenticated encryption in OCBv3 mode",
    "flags": [],
    "examples": [],
    "see_also": []
}