{"id":6928,"date":"2022-12-20T19:34:22","date_gmt":"2022-12-20T22:34:22","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/encrypt-man3\/"},"modified":"2022-12-20T19:34:22","modified_gmt":"2022-12-20T22:34:22","slug":"encrypt-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/encrypt-man3\/","title":{"rendered":"ENCRYPT (man3)"},"content":{"rendered":"<h1 align=\"center\">ENCRYPT<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#VERSIONS\">VERSIONS<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">encrypt, setkey, encrypt_r, setkey_r \u2212 encrypt 64-bit messages<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#define _XOPEN_SOURCE<\/b> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var See feature_test_macros(7) bodies\/ usr\/ <b><br \/> #include <unistd.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>void encrypt(char<\/b> <i>block<\/i><b>[64], int<\/b> <i>edflag<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#define _XOPEN_SOURCE<\/b> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var See feature_test_macros(7) bodies\/ usr\/ <b><br \/> #include <stdlib.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>void setkey(const char *<\/b><i>key<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#define _GNU_SOURCE<\/b> \/bin \/boot \/dead.letter \/dev \/etc \/home \/initrd \/lib \/lib64 \/lost+found \/media \/mnt \/opt \/proc \/release-notes.html \/release-notes.txt \/root \/run \/sbin \/srv \/sys \/tmp \/usr \/var See feature_test_macros(7) bodies\/ usr\/ <b><br \/> #include <crypt.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>void setkey_r(const char *<\/b><i>key<\/i><b>, struct crypt_data *<\/b><i>data<\/i><b>); <br \/> void encrypt_r(char *<\/b><i>block<\/i><b>, int<\/b> <i>edflag<\/i><b>, struct crypt_data *<\/b><i>data<\/i><b>);<\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Each of these requires linking with <i>\u2212lcrypt<\/i>.<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions encrypt and decrypt 64-bit messages. The <b>setkey<\/b>() function sets the key used by <b>encrypt<\/b>(). The <i>key<\/i> argument used here is an array of 64 bytes, each of which has numerical value 1 or 0. The bytes key[n] where n=8*i-1 are ignored, so that the effective key length is 56 bits.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>encrypt<\/b>() function modifies the passed buffer, encoding if <i>edflag<\/i> is 0, and decoding if 1 is being passed. Like the <i>key<\/i> argument, also <i>block<\/i> is a bit vector representation of the actual value that is encoded. The result is returned in that same vector.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">These two functions are not reentrant, that is, the key data is kept in static storage. The functions <b>setkey_r<\/b>() and <b>encrypt_r<\/b>() are the reentrant versions. They use the following structure to hold the key data:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">struct crypt_data { <br \/> char keysched[16 bodies manpages.csv script_extrae_body.sh script.sh usr 8]; <br \/> char sb0[32768]; <br \/> char sb1[32768]; <br \/> char sb2[32768]; <br \/> char sb3[32768]; <br \/> char crypt_3_buf[14]; <br \/> char current_salt[2]; <br \/> long current_saltbits; <br \/> int direction; <br \/> int initialized; <br \/> };<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Before calling <b>setkey_r<\/b>() set <i>data\u2212>initialized<\/i> to zero.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions do not return any value.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Set <i>errno<\/i> to zero before calling the above functions. On success, it is unchanged.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOSYS<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The function is not provided. (For example because of former USA export restrictions.)<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<h2>VERSIONS <a name=\"VERSIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Because they employ the DES block cipher, which is no longer considered secure, <b>crypt<\/b>(), <b>crypt_r<\/b>(), <b>setkey<\/b>(), and <b>setkey_r<\/b>() were removed in glibc 2.28. Applications should switch to a modern cryptography library, such as <b>libgcrypt<\/b>.<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-1615551.png\" alt=\"Image grohtml-1615551.png\"><\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>encrypt<\/b>(), <b>setkey<\/b>(): POSIX.1-2001, POSIX.1-2008, SUS, SVr4.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The functions <b>encrypt_r<\/b>() and <b>setkey_r<\/b>() are GNU extensions.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Availability in glibc<\/b> <br \/> See <b>crypt<\/b>(3).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Features in glibc<\/b> <br \/> In glibc 2.2, these functions use the DES algorithm.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#define _XOPEN_SOURCE <br \/> #include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <unistd.h> <br \/> #include <crypt.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(void) <br \/> { <br \/> char key[64]; <br \/> char orig[9] = &#8220;eggplant&#8221;; <br \/> char buf[64]; <br \/> char txt[9];<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < 64; i++) { <br \/> key[i] = rand() &#038; 1; <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">for (int i = 0; i < 8; i++) { <br \/> for (int j = 0; j < 8; j++) { <br \/> buf[i bodies manpages.csv script_extrae_body.sh script.sh usr 8 + j] = orig[i] >> j &#038; 1; <br \/> } <br \/> setkey(key); <br \/> } <br \/> printf(&#8220;Before encrypting: %sn&#8221;, orig);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">encrypt(buf, 0); <br \/> for (int i = 0; i < 8; i++) { <br \/> for (int j = 0, txt[i] = &#8216;\u0000&#8217;; j < 8; j++) { <br \/> txt[i] |= buf[i bodies manpages.csv script_extrae_body.sh script.sh usr 8 + j] << j; <br \/> } <br \/> txt[8] = &#8216;\u0000&#8217;; <br \/> } <br \/> printf(&#8220;After encrypting: %sn&#8221;, txt);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">encrypt(buf, 1); <br \/> for (int i = 0; i < 8; i++) { <br \/> for (int j = 0, txt[i] = &#8216;\u0000&#8217;; j < 8; j++) { <br \/> txt[i] |= buf[i bodies manpages.csv script_extrae_body.sh script.sh usr 8 + j] << j; <br \/> } <br \/> txt[8] = &#8216;\u0000&#8217;; <br \/> } <br \/> printf(&#8220;After decrypting: %sn&#8221;, txt); <br \/> exit(EXIT_SUCCESS); <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>cbc_crypt<\/b>(3), <b>crypt<\/b>(3), <b>ecb_crypt<\/b>(3),<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  encrypt, setkey, encrypt_r, setkey_r \u2212 encrypt 64-bit messages <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,1777,3007],"class_list":["post-6928","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-encrypt","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=6928"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/6928\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=6928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=6928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=6928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}