302 lines
9.1 KiB
HTML
302 lines
9.1 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of ENCRYPT</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>ENCRYPT</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2018-04-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
encrypt, setkey, encrypt_r, setkey_r - encrypt 64-bit messages
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#define _XOPEN_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>></B>
|
|
|
|
<B>void encrypt(char </B><I>block</I><B>[64], int </B><I>edflag</I><B>);</B>
|
|
|
|
<B>#define _XOPEN_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>></B>
|
|
|
|
<B>void setkey(const char *</B><I>key</I><B>);</B>
|
|
|
|
<B>#define _GNU_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
<B>#include <<A HREF="file:///usr/include/crypt.h">crypt.h</A>></B>
|
|
|
|
<B>void setkey_r(const char *</B><I>key</I><B>, struct crypt_data *</B><I>data</I><B>);</B>
|
|
<B>void encrypt_r(char *</B><I>block</I><B>, int </B><I>edflag</I><B>, struct crypt_data *</B><I>data</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
Each of these requires linking with <I>-lcrypt</I>.
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
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>
|
|
|
|
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>
|
|
|
|
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>
|
|
|
|
|
|
|
|
struct crypt_data {
|
|
<BR> char keysched[16 * 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 int current_saltbits;
|
|
<BR> int direction;
|
|
<BR> int initialized;
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
Before calling
|
|
<B>setkey_r</B>()
|
|
|
|
set
|
|
<I>data->initialized</I>
|
|
|
|
to zero.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
These functions do not return any value.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ERRORS</H2>
|
|
|
|
Set
|
|
<I>errno</I>
|
|
|
|
to zero before calling the above functions.
|
|
On success, it is unchanged.
|
|
<DL COMPACT>
|
|
<DT id="1"><B>ENOSYS</B>
|
|
|
|
<DD>
|
|
The function is not provided.
|
|
(For example because of former USA export restrictions.)
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
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>.
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>encrypt</B>(),
|
|
|
|
<B>setkey</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:crypt<BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>encrypt_r</B>(),
|
|
|
|
<B>setkey_r</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
<B>encrypt</B>(),
|
|
|
|
<B>setkey</B>():
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SUS, SVr4.
|
|
<P>
|
|
|
|
The functions
|
|
<B>encrypt_r</B>()
|
|
|
|
and
|
|
<B>setkey_r</B>()
|
|
|
|
are GNU extensions.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Availability in glibc</H3>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?3+crypt">crypt</A></B>(3).
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Features in glibc</H3>
|
|
|
|
In glibc 2.2, these functions use the DES algorithm.
|
|
<A NAME="lbAM"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
|
|
#define _XOPEN_SOURCE
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/unistd.h">unistd.h</A>>
|
|
#include <<A HREF="file:///usr/include/crypt.h">crypt.h</A>>
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> char key[64];
|
|
<BR> char orig[9] = "eggplant";
|
|
<BR> char buf[64];
|
|
<BR> char txt[9];
|
|
<BR> int i, j;
|
|
<P>
|
|
<BR> for (i = 0; i < 64; i++) {
|
|
<BR> key[i] = rand() & 1;
|
|
<BR> }
|
|
<P>
|
|
<BR> for (i = 0; i < 8; i++) {
|
|
<BR> for (j = 0; j < 8; j++) {
|
|
<BR> buf[i * 8 + j] = orig[i] >> j & 1;
|
|
<BR> }
|
|
<BR> setkey(key);
|
|
<BR> }
|
|
<BR> printf("Before encrypting: %s\n", orig);
|
|
<P>
|
|
<BR> encrypt(buf, 0);
|
|
<BR> for (i = 0; i < 8; i++) {
|
|
<BR> for (j = 0, txt[i] = '\0'; j < 8; j++) {
|
|
<BR> txt[i] |= buf[i * 8 + j] << j;
|
|
<BR> }
|
|
<BR> txt[8] = '\0';
|
|
<BR> }
|
|
<BR> printf("After encrypting: %s\n", txt);
|
|
<P>
|
|
<BR> encrypt(buf, 1);
|
|
<BR> for (i = 0; i < 8; i++) {
|
|
<BR> for (j = 0, txt[i] = '\0'; j < 8; j++) {
|
|
<BR> txt[i] |= buf[i * 8 + j] << j;
|
|
<BR> }
|
|
<BR> txt[8] = '\0';
|
|
<BR> }
|
|
<BR> printf("After decrypting: %s\n", txt);
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAN"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+cbc_crypt">cbc_crypt</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+crypt">crypt</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ecb_crypt">ecb_crypt</A></B>(3),
|
|
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 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
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="2"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="3"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="4"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="5"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="6"><A HREF="#lbAF">ERRORS</A><DD>
|
|
<DT id="7"><A HREF="#lbAG">VERSIONS</A><DD>
|
|
<DT id="8"><A HREF="#lbAH">ATTRIBUTES</A><DD>
|
|
<DT id="9"><A HREF="#lbAI">CONFORMING TO</A><DD>
|
|
<DT id="10"><A HREF="#lbAJ">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="11"><A HREF="#lbAK">Availability in glibc</A><DD>
|
|
<DT id="12"><A HREF="#lbAL">Features in glibc</A><DD>
|
|
</DL>
|
|
<DT id="13"><A HREF="#lbAM">EXAMPLE</A><DD>
|
|
<DT id="14"><A HREF="#lbAN">SEE ALSO</A><DD>
|
|
<DT id="15"><A HREF="#lbAO">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:39 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|