Name

encrypt, setkey
- encrypt 64-bit messages

Library

libcrypt.lib

Synopsis

  #include <unistd.h>
  void encrypt (char block[64], int edflag);
  #include <stdlib.h>
  void setkey (const char *key);

Return values

The encrypt and setkey functions do not return any value.

Detailed description

encrypt() function encrypts and decrypts 64-bit messages. The algorithm used to perform encryption/decryption is Data Encryption Standard (DES).

setkey() is invoked to set the key for the DES machine. setkey()’ s key parameter is an array of 64 bytes, and the numerical value of each byte in this array is either 0 or 1. The 56-bit key for the DES algorithm is computed from the key parameter.

encrypt function either encrypts or decrypts the data block. The exact operation depends on the value of edflag parameter. block is encrypted if edflag parameter is 0, and decrypted if 1 is being passed as the value of edflag parameter. block is an array of 64 bytes, wherein the numerical value of each byte is either 0 or 1. Like the setkey’ s key parameter, block is a bit vector representation of the actual value that is encoded. It is modified in place to return the result.

encrypt and setkey are not reentrant as the key is stored statically.


Errors

errno should be set to zero prior to calling any of the above functions. The behavior of encrypt will be undefined if size of block argument is not 64.

Example

#include <stdlib.h>
#include <unistd.h>
void encrypt_user()
{
        /* bit vector containing the key */
        char key[64] =
        {
                        0, 0, 0, 0, 0, 0, 0, 1,
                        0, 0, 1, 1, 0, 0, 0, 1,
                        1, 1, 0, 1, 1, 0, 0, 1,
                        0, 1, 1, 0, 0, 0, 0, 1,
                        1, 0, 0, 1, 1, 1, 0, 1,
                        1, 1, 0, 0, 0, 0, 0, 1,
                        0, 0, 1, 1, 0, 1, 1, 1,
                        0, 1, 1, 0, 1, 1, 1, 0
        };
        /* bit vector containing the data block to be encrypted */
        char block[64] =
        {
                0, 1, 0, 1, 1, 1, 0, 0,
                1, 1, 0, 1, 0, 1, 0, 1,
                0, 1, 0, 0, 1, 1, 0, 0,
                1, 0, 1, 0, 1, 0, 0, 0,
                0, 0, 1, 1, 1, 1, 0, 1,
                1, 1, 1, 0, 1, 1, 1, 1,
                0, 1, 0, 1, 0, 1, 1, 1,
                1, 1, 0, 1, 1, 0, 1, 0
        };
        setkey(key);            /* Set the key for DES encryption */
        
        /* Perform encryption/decryption of the message block */
        encrypt(block, 0);      /* Encryption. The input block is modified in place
                                         * to return the output to the user
                                         */
        encrypt(block, 1);      /* Decryption. The input block is modified in place
                                         * to return the result of the decryption operation
                                         */
}

         


See also


Bugs

If encrypt is called without priorly invoking setkey the implementation assumes a bit vector consisting of all zeroes as the key for the DES algorithm. In this scenaro the outcome of encrypt function is different from that of Linux’s.

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top