man-pages/man3/des_crypt.3.html
2021-03-31 01:06:50 +01:00

251 lines
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of DES_CRYPT</TITLE>
</HEAD><BODY>
<H1>DES_CRYPT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
des_crypt, ecb_crypt, cbc_crypt, des_setparity, DES_FAILED - fast
DES encryption
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/rpc/des_crypt.h">rpc/des_crypt.h</A>&gt;</B>
<B>int ecb_crypt(char *</B><I>key</I><B>, char *</B><I>data</I><B>, unsigned </B><I>datalen</I><B>,</B>
<B> unsigned </B><I>mode</I><B>);</B>
<B>int cbc_crypt(char *</B><I>key</I><B>, char *</B><I>data</I><B>, unsigned </B><I>datalen</I><B>,</B>
<B> unsigned </B><I>mode</I><B>, char *</B><I>ivec</I><B>);</B>
<B>void des_setparity(char *</B><I>key</I><B>);</B>
<B>int DES_FAILED(int </B><I>status</I><B>);</B>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<B>ecb_crypt</B>()
and
<B>cbc_crypt</B>()
implement the
NBS
DES
(Data Encryption Standard).
These routines are faster and more general purpose than
<B><A HREF="/cgi-bin/man/man2html?3+crypt">crypt</A></B>(3).
They also are able to utilize
DES
hardware if it is available.
<B>ecb_crypt</B>()
encrypts in
ECB
(Electronic Code Book)
mode, which encrypts blocks of data independently.
<B>cbc_crypt</B>()
encrypts in
CBC
(Cipher Block Chaining)
mode, which chains together
successive blocks.
CBC
mode protects against insertions, deletions and
substitutions of blocks.
Also, regularities in the clear text will
not appear in the cipher text.
<P>
Here is how to use these routines.
The first argument,
<I>key</I>,
is the 8-byte encryption key with parity.
To set the key's parity, which for
DES
is in the low bit of each byte, use
<B>des_setparity</B>().
The second argument,
<I>data</I>,
contains the data to be encrypted or decrypted.
The
third argument,
<I>datalen</I>,
is the length in bytes of
<I>data</I>,
which must be a multiple of 8.
The fourth argument,
<I>mode</I>,
is formed by ORing together some things.
For the encryption direction OR in either
<B>DES_ENCRYPT</B>
or
<B>DES_DECRYPT</B>.
For software versus hardware
encryption, OR in either
<B>DES_HW</B>
or
<B>DES_SW</B>.
If
<B>DES_HW</B>
is specified, and there is no hardware, then the encryption is performed
in software and the routine returns
<B>DESERR_NOHWDEVICE</B>.
For
<B>cbc_crypt</B>(),
the argument
<I>ivec</I>
is the 8-byte initialization
vector for the chaining.
It is updated to the next initialization
vector upon return.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
<DL COMPACT>
<DT id="1"><B>DESERR_NONE</B>
<DD>
No error.
<DT id="2"><B>DESERR_NOHWDEVICE</B>
<DD>
Encryption succeeded, but done in software instead of the requested hardware.
<DT id="3"><B>DESERR_HWERROR</B>
<DD>
An error occurred in the hardware or driver.
<DT id="4"><B>DESERR_BADPARAM</B>
<DD>
Bad argument to routine.
</DL>
<P>
Given a result status
<I>stat</I>,
the macro
<B>DES_FAILED(</B><I>stat</I><B>)</B>
is false only for the first two statuses.
<A NAME="lbAF">&nbsp;</A>
<H2>VERSIONS</H2>
These functions are present in
glibc 2.1 and later.
<A NAME="lbAG">&nbsp;</A>
<H2>VERSIONS</H2>
Because they employ the DES block cipher,
which is no longer considered secure,
<B>ecb_crypt</B>(),
<B>ecb_crypt</B>(),
<B>crypt_r</B>(),
and
<B>des_setparity</B>()
were removed in glibc 2.28.
Applications should switch to a modern cryptography library, such as
<B>libgcrypt</B>.
<A NAME="lbAH">&nbsp;</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>ecb_crypt</B>(),
<B>cbc_crypt</B>(),
<B>des_setparity</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<A NAME="lbAI">&nbsp;</A>
<H2>CONFORMING TO</H2>
4.3BSD.
Not in POSIX.1.
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?1+des">des</A></B>(1),
<B><A HREF="/cgi-bin/man/man2html?3+crypt">crypt</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?3+xcrypt">xcrypt</A></B>(3)
<A NAME="lbAK">&nbsp;</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">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="5"><A HREF="#lbAB">NAME</A><DD>
<DT id="6"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="7"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="8"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="9"><A HREF="#lbAF">VERSIONS</A><DD>
<DT id="10"><A HREF="#lbAG">VERSIONS</A><DD>
<DT id="11"><A HREF="#lbAH">ATTRIBUTES</A><DD>
<DT id="12"><A HREF="#lbAI">CONFORMING TO</A><DD>
<DT id="13"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="14"><A HREF="#lbAK">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:38 GMT, March 31, 2021
</BODY>
</HTML>